Commit dc051665 authored by luojing's avatar luojing
Browse files

适应平台新版本

parent 2083c17c
package com.x.wcrm.assemble.control.factory;
import com.x.base.core.project.exception.ExceptionWhen;
import com.x.base.core.project.tools.ListTools;
import com.x.wcrm.assemble.control.AbstractFactory;
import com.x.wcrm.assemble.control.Business;
import com.x.wcrm.core.entity.WCrmConfig;
import com.x.wcrm.core.entity.WCrmConfig_;
import com.x.wcrm.core.entity.tools.CriteriaBuilderTools;
import com.x.wcrm.core.entity.tools.filter.QueryFilter;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;
public class ConfigFactory extends AbstractFactory {
public ConfigFactory(Business business ) throws Exception {
super(business);
}
/**
* 获取指定Id的Project实体信息对象
* @param id
* @return
* @throws Exception
*/
public WCrmConfig get(String id ) throws Exception {
return this.entityManagerContainer().find( id, WCrmConfig.class, ExceptionWhen.none );
}
/*public ProjectDetail getDetail(String id) throws Exception {
return this.entityManagerContainer().find( id, ProjectDetail.class, ExceptionWhen.none );
}*/
/**
* 根据条件查询符合条件的项目信息ID,根据上一条的sequnce查询指定数量的信息
* @param maxCount
* @param sequenceFieldValue
* @param orderField
* @param orderType
* @param personName
* @param queryFilter
* @return
* @throws Exception
*/
public List<WCrmConfig> listWithFilter( Integer maxCount, Object sequenceFieldValue, String orderField, String orderType, String personName, QueryFilter queryFilter) throws Exception {
EntityManager em = this.entityManagerContainer().get( WCrmConfig.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<WCrmConfig> cq = cb.createQuery(WCrmConfig.class);
Root<WCrmConfig> root = cq.from(WCrmConfig.class);
Predicate p_permission = null;
/*if( StringUtils.isNotEmpty( personName )) {
//可以管理的栏目,肯定可以发布信息
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.isMember( personName, root.get( Project_.participantPersonList )) );
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.isMember( personName, root.get( Project_.manageablePersonList )) );
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.equal( root.get( Project_.creatorPerson ), personName ) );
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.equal( root.get( Project_.executor ), personName ) );
}*/
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( WCrmConfig_.class, cb, p_permission, root, queryFilter );
if( sequenceFieldValue != null && StringUtils.isNotEmpty( sequenceFieldValue.toString() )) {
Predicate p_seq = cb.isNotNull( root.get( WCrmConfig_.sequence ) );
if( "desc".equalsIgnoreCase( orderType )){
p_seq = cb.and( p_seq, cb.lessThan( root.get( WCrmConfig_.sequence ), sequenceFieldValue.toString() ));
}else{
p_seq = cb.and( p_seq, cb.greaterThan( root.get( WCrmConfig_.sequence ), sequenceFieldValue.toString() ));
}
p = cb.and( p, p_seq);
}
Order orderWithField = CriteriaBuilderTools.getOrder( cb, root, WCrmConfig_.class, orderField, orderType );
if( orderWithField != null ){
cq.orderBy( orderWithField );
}
System.out.println(">>>SQL:" + em.createQuery(cq.where(p)).setMaxResults( maxCount).toString() );
return em.createQuery(cq.where(p)).setMaxResults( maxCount).getResultList();
}
/**
* 根据条件查询所有符合条件的项目模板信息ID,项目信息不会很多 ,所以直接查询出来
* @param maxCount
* @param personName
* @param queryFilter
* @return
* @throws Exception
*/
public List<String> listAllConfigIds( Integer maxCount, String personName, QueryFilter queryFilter) throws Exception {
EntityManager em = this.entityManagerContainer().get( WCrmConfig.class );
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<WCrmConfig> root = cq.from(WCrmConfig.class);
Predicate p_permission = null;
/*if( StringUtils.isNotEmpty( personName )) {
//可以管理的栏目,肯定可以发布信息
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.isMember( personName, root.get( ProjectTemplate_.participantPersonList )) );
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.isMember( personName, root.get( Project_.manageablePersonList )) );
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.equal( root.get( ProjectTemplate_.creatorPerson ), personName ) );
p_permission = CriteriaBuilderTools.predicate_or( cb, p_permission, cb.equal( root.get( ProjectTemplate_.executor ), personName ) );
}*/
Predicate p = CriteriaBuilderTools.composePredicateWithQueryFilter( WCrmConfig_.class, cb, p_permission, root, queryFilter );
cq.distinct(true).select( root.get(WCrmConfig_.id) );
return em.createQuery(cq.where(p)).setMaxResults( maxCount).getResultList();
}
/**
* 根据配置类型列示配置信息
* @param configModule
* @return
* @throws Exception
*/
public List<WCrmConfig> ListConfigsWithType( String configModule ) throws Exception {
EntityManager em = this.entityManagerContainer().get(WCrmConfig.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<WCrmConfig> cq = cb.createQuery(WCrmConfig.class);
Root<WCrmConfig> root = cq.from(WCrmConfig.class);
Predicate p = cb.equal(root.get(WCrmConfig_.configModule), configModule);
return em.createQuery(cq.where(p)).getResultList();
}
}
package com.x.wcrm.assemble.control.jaxrs;
import com.x.base.core.project.jaxrs.CipherManagerUserJaxrsFilter;
import javax.servlet.annotation.WebFilter;
@WebFilter(urlPatterns = "/jaxrs/config/*", asyncSupported = true)
public class ConfigJaxrsFilter extends CipherManagerUserJaxrsFilter {
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.wcrm.assemble.control.jaxrs.record.BaseAction;
import com.x.wcrm.core.entity.Leads;
import com.x.wcrm.core.entity.WCrmConfig;
import org.apache.commons.lang3.StringUtils;
public class ActionCreate extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionCreate.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
WCrmConfig o = Wi.copier.copy(wi);
emc.beginTransaction(WCrmConfig.class);
emc.persist(o, CheckPersistType.all);
emc.commit();
Wo wo = new Wo();
wo.setId(o.getId());
result.setData(wo);
return result;
}
}
static class Wi extends WCrmConfig {
/**
*
*/
private static final long serialVersionUID = 7106839105196570589L;
static WrapCopier<Wi, WCrmConfig> copier = WrapCopierFactory.wi(Wi.class, WCrmConfig.class, null, JpaObject.FieldsUnmodify);
}
static class Wo extends WoId {
static WrapCopier<WCrmConfig, Wo> copier = WrapCopierFactory.wo(WCrmConfig.class, Wo.class, null, JpaObject.FieldsInvisible);
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckRemoveType;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.wcrm.core.entity.WCrmConfig;
//删除配置(管理员,crm管理员可以删除)
public class ActionDelete extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
WCrmConfig o = emc.find(id, WCrmConfig.class);
if (null == o) {
throw new ExceptionEntityNotExist(id, WCrmConfig.class);
}
emc.beginTransaction( WCrmConfig.class );
emc.remove( o , CheckRemoveType.all );
emc.commit();
Wo wo = new Wo();
result.setData(wo);
return result;
}
}
static class Wo extends WoId {
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.wcrm.assemble.control.Business;
import com.x.wcrm.core.entity.WCrmConfig;
class ActionGet extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
WCrmConfig config = emc.find(id, WCrmConfig.class);
if (null == config) {
throw new ExceptionEntityNotExist(id, WCrmConfig.class);
}
Wo wo = Wo.copier.copy(config);
result.setData(wo);
return result;
}
}
public static class Wo extends WCrmConfig {
private static final long serialVersionUID = 5661133561098715100L;
public static WrapCopier<WCrmConfig, Wo> copier = WrapCopierFactory.wo(WCrmConfig.class, Wo.class, null,
JpaObject.FieldsInvisible);
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.wcrm.assemble.control.Business;
import com.x.wcrm.assemble.control.jaxrs.record.BaseAction;
import com.x.wcrm.assemble.control.wrapout.WrapOutRecord;
import com.x.wcrm.core.entity.Record;
import java.util.List;
class ActionListByCrmId extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionListByCrmId.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, String crmId) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
Business business = new Business(emc);
List<Record> os = business.recordFactory().ListByCrmId(crmId);
List<Wo> wos = Wo.copier.copy(os);
Wo.setICONBase64_byCreateuser(business, wos); //设置人员信息,和人员头像
Wo.setAttachmentList(business, wos); //设置附件列表
result.setData(wos);
return result;
}
}
public static class Wo extends WrapOutRecord {
private static final long serialVersionUID = 1276641320278402941L;
static WrapCopier<Record, Wo> copier = WrapCopierFactory.wo(Record.class, Wo.class, null, JpaObject.FieldsInvisible);
}
// public static class Wo extends Record {
// private Person person;
//
// private String ICONBase64;
//
// private static final long serialVersionUID = 1276641320278402941L;
// static WrapCopier<Record, Wo> copier = WrapCopierFactory.wo(Record.class, Wo.class, null,
// JpaObject.FieldsInvisible);
//
// public Person getPerson() {
// return person;
// }
//
// public void setPerson(Person person) {
// this.person = person;
// }
//
// public String getICONBase64() {
// return ICONBase64;
// }
//
// public void setICONBase64(String iCONBase64) {
// ICONBase64 = iCONBase64;
// }
//
// public static List<Wo> setICONBase64_byCreateuser(Business business, List<Wo> wos) {
//
// List<Wo> result = new ArrayList<Wo>();
// if (null != wos) {
// wos.stream().forEach(t -> {
// try {
// com.x.organization.core.entity.Person entityPerson = business.crmPersonFactory()
// .pick(t.getCreateuser());
// if (null != entityPerson) {
// t.setICONBase64(entityPerson.getIcon());
// }
// if (null != t.getCreateuser() && StringUtils.isNoneBlank(t.getCreateuser())) {
// t.setPerson(business.personFactory().getObject(t.getCreateuser()));
// }
// result.add(t);
// } catch (Exception e) {
// e.printStackTrace();
// }
// });
// }
//
// return result;
// }
//
// }
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.google.gson.JsonElement;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.wcrm.core.entity.WCrmConfig;
import com.x.wcrm.core.entity.tools.filter.QueryFilter;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
public class ActionListNextWithFilter extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionListNextWithFilter.class);
protected ActionResult<List<Wo>> execute( HttpServletRequest request, EffectivePerson effectivePerson, String flag, Integer count, JsonElement jsonElement ) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
ResultObject resultObject = null;
List<Wo> wos = new ArrayList<>();
Wi wrapIn = null;
Boolean check = true;
QueryFilter queryFilter = null;
List<String> queryProjectIds = new ArrayList<>();
if ( StringUtils.isEmpty( flag ) || "(0)".equals(flag)) {
flag = null;
}
try {
wrapIn = this.convertToWrapIn(jsonElement, Wi.class);
} catch (Exception e) {
check = false;
Exception exception = new ConfigQueryException(e, "系统在将JSON信息转换为对象时发生异常。JSON:" + jsonElement.toString());
result.error(exception);
logger.error(e, effectivePerson, request, null);
}
if( Boolean.TRUE.equals( check ) ){
if( wrapIn == null ) {
wrapIn = new Wi();
}
queryFilter = wrapIn.getQueryFilter();
}
if( Boolean.TRUE.equals( check ) ){
try {
//获取用户能查看的所有的项目信息ID列表,最多查询2000条数据
List<String> projectIds = configQueryService.listAllConfigIds( effectivePerson, 2000, queryFilter );
if( ListTools.isNotEmpty( projectIds )) {
//直接根据可见项目ID列表进行分页查询
Long total = Long.parseLong( projectIds.size() + "" );
List<WCrmConfig> projectList = configQueryService.listWithConfigIdFilter( count, flag, wrapIn.getOrderField(), wrapIn.getOrderType(), projectIds );
if( ListTools.isNotEmpty( projectList )) {
for( WCrmConfig project : projectList ) {
Wo wo = Wo.copier.copy(project);
wos.add( wo );
}
}
resultObject = new ResultObject( total, wos );
//projectTemplateCache.put(new Element( cacheKey, resultObject ));
result.setCount( resultObject.getTotal() );
result.setData( resultObject.getWos() );
}
} catch (Exception e) {
check = false;
logger.warn("系统查询项目信息列表时发生异常!");
result.error(e);
logger.error(e, effectivePerson, request, null);
}
//}
}
return result;
}
public static class Wi extends WrapInQueryConfig{
}
public static class Wo extends WCrmConfig {
private static final long serialVersionUID = -5076990764713538973L;
public static List<String> Excludes = new ArrayList<String>();
static WrapCopier<WCrmConfig, Wo> copier = WrapCopierFactory.wo( WCrmConfig.class, Wo.class, null, ListTools.toList(JpaObject.FieldsInvisible));
}
public static class ResultObject {
private Long total;
private List<Wo> wos;
public ResultObject() {}
public ResultObject(Long count, List<Wo> data) {
this.total = count;
this.wos = data;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List<Wo> getWos() {
return wos;
}
public void setWos(List<Wo> wos) {
this.wos = wos;
}
}
}
\ No newline at end of file
package com.x.wcrm.assemble.control.jaxrs.config;
import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.wcrm.assemble.control.jaxrs.leads.BaseAction;
import com.x.wcrm.core.entity.WCrmConfig;
import org.apache.commons.lang3.StringUtils;
public class ActionUpdate extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionUpdate.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String id, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
WCrmConfig o = emc.find(id, WCrmConfig.class);
String _id = o.getId();
// 更新数据
Wi.copier.copy(wi, o);
if (null == o.getId() || StringUtils.isBlank(o.getId())) {
logger.info("ActionUpdate set id:" + _id);
o.setId(_id);
}
emc.beginTransaction(WCrmConfig.class);
emc.persist(o, CheckPersistType.all);
emc.commit();
Wo wo = new Wo();
Wo.copier.copy(o,wo);
wo.setId(o.getId());
result.setData(wo);
return result;
}
}
static class Wi extends WCrmConfig {
private static final long serialVersionUID = -4714395467753481398L;
static WrapCopier<Wi, WCrmConfig> copier = WrapCopierFactory.wi(Wi.class, WCrmConfig.class, null, JpaObject.FieldsUnmodify, true);
}