提交 dc051665 编写于 作者: L luojing

适应平台新版本

上级 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);
}
public static class Wo extends WCrmConfig {
private static final long serialVersionUID = 7871578639804765941L;
static WrapCopier<WCrmConfig, Wo> copier = WrapCopierFactory.wo(WCrmConfig.class, Wo.class, null, JpaObject.FieldsUnmodify);
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.wcrm.assemble.control.service.ConfigQueryService;
import com.x.wcrm.assemble.control.service.RecordService;
public class BaseAction extends StandardJaxrsAction {
private final Logger logger = LoggerFactory.getLogger(BaseAction.class);
protected ConfigQueryService configQueryService = new ConfigQueryService();
RecordService recordService = new RecordService();
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
@Path("config")
@JaxrsDescribe("系统配置")
public class ConfigAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(ConfigAction.class);
@JaxrsMethodDescribe(value = "创建系统配置", action = ActionCreate.class)
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
@Path("create")
public void create(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<ActionCreate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionCreate().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "更新配置", action = ActionUpdate.class)
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
@Path("update/{id}")
public void update(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("配置ID") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionUpdate().execute(effectivePerson, id, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据配置id,删除配置", action = ActionDelete.class)
@DELETE
@Path("{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void delete(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("配置id") @PathParam("id") String id) {
ActionResult<ActionDelete.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionDelete().execute(effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据线索id,获取配置对象。单个", action = ActionGet.class)
@GET
@Path("get/{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void getById(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("任务标识") @PathParam("id") String leadsid) {
ActionResult<ActionGet.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGet().execute(effectivePerson, leadsid);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示配置信息,下一页.", action = ActionListNextWithFilter.class)
@PUT
@Path("list/{id}/next/{count}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listNextWithFilter(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("最后一条信息数据的ID") @PathParam( "id" ) String id,
@JaxrsParameterDescribe("每页显示的条目数量") @PathParam( "count" ) Integer count,
@JaxrsParameterDescribe("查询过滤条件") JsonElement jsonElement ) {
ActionResult<List<ActionListNextWithFilter.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionListNextWithFilter().execute(request, effectivePerson, id, count, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.project.exception.PromptException;
class ConfigQueryException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
ConfigQueryException(Throwable e ) {
super("系统在查询系统配置信息时发生异常。" , e );
}
ConfigQueryException(Throwable e, String message ) {
super("系统在查询系统配置信息时发生异常。Message:" + message, e );
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersist;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.wcrm.core.entity.WCrmConfig;
import com.x.wcrm.core.entity.tools.filter.QueryFilter;
import com.x.wcrm.core.entity.tools.filter.term.EqualsTerm;
import com.x.wcrm.core.entity.tools.filter.term.LikeTerm;
import org.apache.commons.lang3.StringUtils;
import org.apache.openjpa.persistence.jdbc.Index;
import javax.persistence.Column;
public class WrapInQueryConfig {
@FieldDescribe("配置模块")
private String configModule;
@FieldDescribe("配置类别")
private String configType;
@FieldDescribe("配置名称")
private String configName;
@FieldDescribe("配置编码")
private String configCode;
@FieldDescribe("用于排列的属性,非必填,默认为createTime.")
private String orderField = "createTime";
@FieldDescribe("排序方式:DESC | ASC,非必填, 默认为DESC.")
private String orderType = "DESC";
private Long rank = 0L;
public String getOrderField() {
return orderField;
}
public void setOrderField(String orderField) {
this.orderField = orderField;
}
public String getOrderType() {
return orderType;
}
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
public String getConfigModule() { return configModule; }
public void setConfigModule(String configModule) { this.configModule = configModule; }
public String getConfigType() { return configType; }
public void setConfigType(String configType) { this.configType = configType; }
public String getConfigName() { return configName; }
public void setConfigName(String configName) { this.configName = configName; }
public String getConfigCode() { return configCode; }
public void setConfigCode(String configCode) { this.configCode = configCode; }
/**
* 根据传入的查询参数,组织一个完整的QueryFilter对象
* @return
*/
public QueryFilter getQueryFilter() {
QueryFilter queryFilter = new QueryFilter();
queryFilter.setJoinType( "and" );
//组织查询条件对象
/*if( StringUtils.isNotEmpty( this.getTitle() )) {
queryFilter.addLikeTerm( new LikeTerm( "title", this.getTitle() ) );
}
if( StringUtils.isNotEmpty( this.getType())) {
queryFilter.addEqualsTerm( new EqualsTerm( "type", this.getType() ) );
}
if( StringUtils.isNotEmpty( this.getOwner())) {
queryFilter.addEqualsTerm( new EqualsTerm( "owner", this.getOwner() ) );
}
if( StringUtils.isNotEmpty( this.getDeleted() )) {
if( "true".equalsIgnoreCase( this.getDeleted() )) {
queryFilter.addEqualsTerm( new EqualsTerm( "deleted", true ) );
}else {
queryFilter.addEqualsTerm( new EqualsTerm( "deleted", false ) );
}
}*/
if( StringUtils.isNotEmpty( this.getConfigModule())) {
queryFilter.addLikeTerm( new LikeTerm( "configModule", this.getConfigModule() ) );
}
if( StringUtils.isNotEmpty( this.getConfigType())) {
queryFilter.addLikeTerm( new LikeTerm( "configType", this.getConfigType() ) );
}
if( StringUtils.isNotEmpty( this.getConfigName())) {
queryFilter.addLikeTerm( new LikeTerm( "configName", this.getConfigName() ) );
}
if( StringUtils.isNotEmpty( this.getConfigCode() )) {
queryFilter.addLikeTerm( new LikeTerm( "configCode", this.getConfigCode() ) );
}
return queryFilter;
}
}
package com.x.wcrm.assemble.control.service;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.http.EffectivePerson;
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 com.x.wcrm.core.entity.tools.filter.term.EqualsTerm;
import com.x.wcrm.core.entity.tools.filter.term.InTerm;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* 对配置信息查询的服务
*
* @author O2LJ
*/
public class ConfigQueryService {
private ConfigService configService = new ConfigService();
/**
* 根据配置的标识查询项目信息
* @param id
* @return
* @throws Exception
*/
public WCrmConfig get(String id ) throws Exception {
if ( StringUtils.isEmpty( id )) {
return null;
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
return configService.get(emc, id );
} catch (Exception e) {
throw e;
}
}
/**
* 根据ID列表查询项目模板信息列表
* @param ids
* @return
* @throws Exception
*/
public List<WCrmConfig> list(List<String> ids) throws Exception {
if (ListTools.isEmpty( ids )) {
return null;
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
return emc.list( WCrmConfig.class, ids );
} catch (Exception e) {
throw e;
}
}
/**
* 根据项目ID列表查询项目信息列表,根据上一条的sequnce查询指定数量的信息
* @param pageSize
* @param lastId
* @param orderField
* @param orderType
* @param projectIds
* @return
* @throws Exception
*/
public List<WCrmConfig> listWithConfigIdFilter( Integer pageSize, String lastId, String orderField, String orderType, List<String> projectIds ) throws Exception {
WCrmConfig project = null;
if( pageSize == 0 ) { pageSize = 20; }
if( StringUtils.isEmpty( orderField ) ) {
orderField = "createTime";
}
if( StringUtils.isEmpty( orderType ) ) {
orderType = "desc";
}
QueryFilter queryFilter = new QueryFilter();
queryFilter.addInTerm( new InTerm("id", new ArrayList<>(projectIds) ));
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
if( lastId != null ) {
project = emc.find( lastId, WCrmConfig.class );
}
if( project != null ) {
return configService.listWithFilter(emc, pageSize, project.getSequence(), orderField, orderType, null, null, null, null, queryFilter );
}else {
return configService.listWithFilter(emc, pageSize, null, orderField, orderType, null, null, null, null, queryFilter );
}
} catch (Exception e) {
throw e;
}
}
/**
* 根据条件查询配置ID列表,最大查询2000条,查询未删除
* @param effectivePerson
* @param queryFilter
* @return
* @throws Exception
*/
public List<String> listAllConfigIds(EffectivePerson effectivePerson, int maxCount, QueryFilter queryFilter) throws Exception {
String personName = effectivePerson.getDistinguishedName();
if( maxCount == 0) {
maxCount = 1000;
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
/*queryFilter.addEqualsTerm( new EqualsTerm( "deleted", false ) );*/
return configService.listAllConfigIds( emc, maxCount, personName, queryFilter );
} catch (Exception e) {
throw e;
}
}
}
package com.x.wcrm.assemble.control.service;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.entity.annotation.CheckRemoveType;
import com.x.base.core.project.tools.ListTools;
import com.x.wcrm.assemble.control.Business;
import com.x.wcrm.core.entity.*;
import com.x.wcrm.core.entity.tools.filter.QueryFilter;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
class ConfigService {
/**
* 根据项目的标识查询项目的信息
* @param emc
* @param flag 主要是ID
* @return
* @throws Exception
*/
protected WCrmConfig get(EntityManagerContainer emc, String flag) throws Exception {
Business business = new Business( emc );
return business.configFactory().get( flag );
}
/**
* 根据条件查询符合条件的项目模板信息ID,根据上一条的sequnce查询指定数量的信息
* @param emc
* @param maxCount
* @param sequnce
* @param orderField
* @param orderType
* @param personName
* @param identityNames
* @param unitNames
* @param groupNames
* @return
* @throws Exception
*/
protected List<WCrmConfig> listWithFilter( EntityManagerContainer emc, Integer maxCount, String sequnce, String orderField, String orderType, String personName, List<String> identityNames, List<String> unitNames, List<String> groupNames, QueryFilter queryFilter ) throws Exception {
Business business = new Business( emc );
return business.configFactory().listWithFilter(maxCount, sequnce, orderField, orderType, personName, queryFilter);
}
/**
* 根据条件查询配置ID列表,最大查询2000条
* @param emc
* @param maxCount
* @param personName
* @param queryFilter
* @return
* @throws Exception
*/
public List<String> listAllConfigIds(EntityManagerContainer emc, int maxCount, String personName, QueryFilter queryFilter) throws Exception {
Business business = new Business( emc );
return business.configFactory().listAllConfigIds(maxCount, personName, queryFilter);
}
}
package com.x.wcrm.assemble.control.service;
import com.google.gson.*;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
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.assemble.control.Business;
import com.x.wcrm.assemble.control.tools.ClassPathResource;
import com.x.wcrm.core.entity.WCrmConfig;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class SystemConfigPersistService {
private Logger logger = LoggerFactory.getLogger( SystemConfigPersistService.class );
/**
* 初始化所有的系统设置
* @throws Exception
*/
public void initSystemConfig() throws Exception {
Business business = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
business = new Business(emc);
List<WCrmConfig> configs = business.configFactory().ListConfigsWithType("线索");
if(ListTools.isEmpty(configs)){
logger.info("crm---系统检测到crm未初始化配置");
ClassPathResource resource = new ClassPathResource("/config.json");
InputStream in = resource.getInputStream();
if (in != null) {
String configStr = readToString(in);
JsonParser parser = new JsonParser();
JsonArray jsonArray = parser.parse(configStr).getAsJsonArray();
//logger.info("jsonArray============"+jsonArray.size());
Gson gson = new Gson();
List<WCrmConfig> configList = new ArrayList<>();
for (JsonElement o : jsonArray) {
//使用GSON,直接转成Bean对象
WCrmConfig wc = gson.fromJson(o, WCrmConfig.class);
configList.add(wc);
}
if(ListTools.isNotEmpty(configList)){
logger.info("crm---初始化配置开始");
emc.beginTransaction(WCrmConfig.class);
for(WCrmConfig wconfig : configList){
emc.persist(wconfig, CheckPersistType.all);
}
emc.commit();
logger.info("crm---初始化配置结束");
}
}
}
}catch ( Exception e ) {
throw e;
}
}
public String readToString(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return new String(output.toByteArray(), "UTF-8");
}
}
package com.x.wcrm.assemble.control.tools;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* @Author: LJ
* @Date: 2021/07/08
*/
public class ClassPathResource {
private final String path;
private ClassLoader classLoader;
private Class<?> clazz;
public ClassPathResource(String path, ClassLoader classLoader) {
if (path.startsWith("/")) {
path = path.substring(1);
}
this.path = path;
this.classLoader = (classLoader != null ? classLoader : getDefaultClassLoader());
}
public ClassPathResource(String path) {
this(path, (ClassLoader) null);
}
public final String getPath() {
return this.path;
}
public InputStream getInputStream() throws IOException {
InputStream is;
if (this.clazz != null) {
is = this.clazz.getResourceAsStream(this.path);
} else if (this.classLoader != null) {
is = this.classLoader.getResourceAsStream(this.path);
} else {
is = ClassLoader.getSystemResourceAsStream(this.path);
}
if (is == null) {
throw new FileNotFoundException(this.path+" 文件不存在");
}
return is;
}
public static ClassLoader getDefaultClassLoader() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (Throwable ex) {
// Cannot access thread context ClassLoader - falling back...
}
if (cl == null) {
// No thread context class loader -> use class loader of this class.
cl = ClassPathResource.class.getClassLoader();
if (cl == null) {
// getClassLoader() returning null indicates the bootstrap ClassLoader
try {
cl = ClassLoader.getSystemClassLoader();
} catch (Throwable ex) {
// Cannot access system ClassLoader - oh well, maybe the caller can live with null...
}
}
}
return cl;
}
}
此差异已折叠。
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);
}
public static class Wo extends WCrmConfig {
private static final long serialVersionUID = 7871578639804765941L;
static WrapCopier<WCrmConfig, Wo> copier = WrapCopierFactory.wo(WCrmConfig.class, Wo.class, null, JpaObject.FieldsUnmodify);
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.wcrm.assemble.control.service.ConfigQueryService;
import com.x.wcrm.assemble.control.service.RecordService;
public class BaseAction extends StandardJaxrsAction {
private final Logger logger = LoggerFactory.getLogger(BaseAction.class);
protected ConfigQueryService configQueryService = new ConfigQueryService();
RecordService recordService = new RecordService();
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List;
@Path("config")
@JaxrsDescribe("系统配置")
public class ConfigAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(ConfigAction.class);
@JaxrsMethodDescribe(value = "创建系统配置", action = ActionCreate.class)
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
@Path("create")
public void create(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<ActionCreate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionCreate().execute(effectivePerson, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "更新配置", action = ActionUpdate.class)
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
@Path("update/{id}")
public void update(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("配置ID") @PathParam("id") String id, JsonElement jsonElement) {
ActionResult<ActionUpdate.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionUpdate().execute(effectivePerson, id, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据配置id,删除配置", action = ActionDelete.class)
@DELETE
@Path("{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void delete(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("配置id") @PathParam("id") String id) {
ActionResult<ActionDelete.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionDelete().execute(effectivePerson, id);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "根据线索id,获取配置对象。单个", action = ActionGet.class)
@GET
@Path("get/{id}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void getById(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("任务标识") @PathParam("id") String leadsid) {
ActionResult<ActionGet.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGet().execute(effectivePerson, leadsid);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示配置信息,下一页.", action = ActionListNextWithFilter.class)
@PUT
@Path("list/{id}/next/{count}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listNextWithFilter(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("最后一条信息数据的ID") @PathParam( "id" ) String id,
@JaxrsParameterDescribe("每页显示的条目数量") @PathParam( "count" ) Integer count,
@JaxrsParameterDescribe("查询过滤条件") JsonElement jsonElement ) {
ActionResult<List<ActionListNextWithFilter.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionListNextWithFilter().execute(request, effectivePerson, id, count, jsonElement);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.project.exception.PromptException;
class ConfigQueryException extends PromptException {
private static final long serialVersionUID = 1859164370743532895L;
ConfigQueryException(Throwable e ) {
super("系统在查询系统配置信息时发生异常。" , e );
}
ConfigQueryException(Throwable e, String message ) {
super("系统在查询系统配置信息时发生异常。Message:" + message, e );
}
}
package com.x.wcrm.assemble.control.jaxrs.config;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersist;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.wcrm.core.entity.WCrmConfig;
import com.x.wcrm.core.entity.tools.filter.QueryFilter;
import com.x.wcrm.core.entity.tools.filter.term.EqualsTerm;
import com.x.wcrm.core.entity.tools.filter.term.LikeTerm;
import org.apache.commons.lang3.StringUtils;
import org.apache.openjpa.persistence.jdbc.Index;
import javax.persistence.Column;
public class WrapInQueryConfig {
@FieldDescribe("配置模块")
private String configModule;
@FieldDescribe("配置类别")
private String configType;
@FieldDescribe("配置名称")
private String configName;
@FieldDescribe("配置编码")
private String configCode;
@FieldDescribe("用于排列的属性,非必填,默认为createTime.")
private String orderField = "createTime";
@FieldDescribe("排序方式:DESC | ASC,非必填, 默认为DESC.")
private String orderType = "DESC";
private Long rank = 0L;
public String getOrderField() {
return orderField;
}
public void setOrderField(String orderField) {
this.orderField = orderField;
}
public String getOrderType() {
return orderType;
}
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public Long getRank() {
return rank;
}
public void setRank(Long rank) {
this.rank = rank;
}
public String getConfigModule() { return configModule; }
public void setConfigModule(String configModule) { this.configModule = configModule; }
public String getConfigType() { return configType; }
public void setConfigType(String configType) { this.configType = configType; }
public String getConfigName() { return configName; }
public void setConfigName(String configName) { this.configName = configName; }
public String getConfigCode() { return configCode; }
public void setConfigCode(String configCode) { this.configCode = configCode; }
/**
* 根据传入的查询参数,组织一个完整的QueryFilter对象
* @return
*/
public QueryFilter getQueryFilter() {
QueryFilter queryFilter = new QueryFilter();
queryFilter.setJoinType( "and" );
//组织查询条件对象
/*if( StringUtils.isNotEmpty( this.getTitle() )) {
queryFilter.addLikeTerm( new LikeTerm( "title", this.getTitle() ) );
}
if( StringUtils.isNotEmpty( this.getType())) {
queryFilter.addEqualsTerm( new EqualsTerm( "type", this.getType() ) );
}
if( StringUtils.isNotEmpty( this.getOwner())) {
queryFilter.addEqualsTerm( new EqualsTerm( "owner", this.getOwner() ) );
}
if( StringUtils.isNotEmpty( this.getDeleted() )) {
if( "true".equalsIgnoreCase( this.getDeleted() )) {
queryFilter.addEqualsTerm( new EqualsTerm( "deleted", true ) );
}else {
queryFilter.addEqualsTerm( new EqualsTerm( "deleted", false ) );
}
}*/
if( StringUtils.isNotEmpty( this.getConfigModule())) {
queryFilter.addLikeTerm( new LikeTerm( "configModule", this.getConfigModule() ) );
}
if( StringUtils.isNotEmpty( this.getConfigType())) {
queryFilter.addLikeTerm( new LikeTerm( "configType", this.getConfigType() ) );
}
if( StringUtils.isNotEmpty( this.getConfigName())) {
queryFilter.addLikeTerm( new LikeTerm( "configName", this.getConfigName() ) );
}
if( StringUtils.isNotEmpty( this.getConfigCode() )) {
queryFilter.addLikeTerm( new LikeTerm( "configCode", this.getConfigCode() ) );
}
return queryFilter;
}
}
package com.x.wcrm.assemble.control.jaxrs.leads;
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.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.wcrm.assemble.control.Business;
import com.x.wcrm.assemble.control.ThisApplication;
import com.x.wcrm.assemble.control.wrapin.ListPagingWi;
import com.x.wcrm.core.entity.Leads;
import java.util.List;
class ActionListMyNoTransform extends BaseAction {
// private static Logger logger = LoggerFactory.getLogger(ActionListMyHasTransform.class);
// 所有当前用户所有递归下级的已转化的线索,按照时间倒序排列。
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer adjustPage, Integer adjustPageSize, JsonElement jsonElement)
throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Business business = new Business(emc);
List<Leads> os = leadsPermissionService.getList_MyDuty_And_SubNestedDuty_NoTransform(ThisApplication.context(), business,
effectivePerson, adjustPage, adjustPageSize, wi.getKey(), wi.getOrderFieldName(), wi.getOrderType());
List<Wo> wos = Wo.copier.copy(os);
result.setData(wos);
long count = leadsPermissionService.getList_MyDuty_And_SubNestedDuty__NoTransform_Count(ThisApplication.context(), business,
effectivePerson, wi.getKey());
result.setCount(count);
return result;
}
}
public static class Wo extends Leads {
private static final long serialVersionUID = 5220686039082993620L;
static WrapCopier<Leads, Wo> copier = WrapCopierFactory.wo(Leads.class, Wo.class, null, JpaObject.FieldsInvisible, false);
}
public static class Wi extends ListPagingWi {
}
}
package com.x.wcrm.assemble.control.service;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.http.EffectivePerson;
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 com.x.wcrm.core.entity.tools.filter.term.EqualsTerm;
import com.x.wcrm.core.entity.tools.filter.term.InTerm;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* 对配置信息查询的服务
*
* @author O2LJ
*/
public class ConfigQueryService {
private ConfigService configService = new ConfigService();
/**
* 根据配置的标识查询项目信息
* @param id
* @return
* @throws Exception
*/
public WCrmConfig get(String id ) throws Exception {
if ( StringUtils.isEmpty( id )) {
return null;
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
return configService.get(emc, id );
} catch (Exception e) {
throw e;
}
}
/**
* 根据ID列表查询项目模板信息列表
* @param ids
* @return
* @throws Exception
*/
public List<WCrmConfig> list(List<String> ids) throws Exception {
if (ListTools.isEmpty( ids )) {
return null;
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
return emc.list( WCrmConfig.class, ids );
} catch (Exception e) {
throw e;
}
}
/**
* 根据项目ID列表查询项目信息列表,根据上一条的sequnce查询指定数量的信息
* @param pageSize
* @param lastId
* @param orderField
* @param orderType
* @param projectIds
* @return
* @throws Exception
*/
public List<WCrmConfig> listWithConfigIdFilter( Integer pageSize, String lastId, String orderField, String orderType, List<String> projectIds ) throws Exception {
WCrmConfig project = null;
if( pageSize == 0 ) { pageSize = 20; }
if( StringUtils.isEmpty( orderField ) ) {
orderField = "createTime";
}
if( StringUtils.isEmpty( orderType ) ) {
orderType = "desc";
}
QueryFilter queryFilter = new QueryFilter();
queryFilter.addInTerm( new InTerm("id", new ArrayList<>(projectIds) ));
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
if( lastId != null ) {
project = emc.find( lastId, WCrmConfig.class );
}
if( project != null ) {
return configService.listWithFilter(emc, pageSize, project.getSequence(), orderField, orderType, null, null, null, null, queryFilter );
}else {
return configService.listWithFilter(emc, pageSize, null, orderField, orderType, null, null, null, null, queryFilter );
}
} catch (Exception e) {
throw e;
}
}
/**
* 根据条件查询配置ID列表,最大查询2000条,查询未删除
* @param effectivePerson
* @param queryFilter
* @return
* @throws Exception
*/
public List<String> listAllConfigIds(EffectivePerson effectivePerson, int maxCount, QueryFilter queryFilter) throws Exception {
String personName = effectivePerson.getDistinguishedName();
if( maxCount == 0) {
maxCount = 1000;
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
/*queryFilter.addEqualsTerm( new EqualsTerm( "deleted", false ) );*/
return configService.listAllConfigIds( emc, maxCount, personName, queryFilter );
} catch (Exception e) {
throw e;
}
}
}
package com.x.wcrm.assemble.control.service;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.entity.annotation.CheckRemoveType;
import com.x.base.core.project.tools.ListTools;
import com.x.wcrm.assemble.control.Business;
import com.x.wcrm.core.entity.*;
import com.x.wcrm.core.entity.tools.filter.QueryFilter;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
class ConfigService {
/**
* 根据项目的标识查询项目的信息
* @param emc
* @param flag 主要是ID
* @return
* @throws Exception
*/
protected WCrmConfig get(EntityManagerContainer emc, String flag) throws Exception {
Business business = new Business( emc );
return business.configFactory().get( flag );
}
/**
* 根据条件查询符合条件的项目模板信息ID,根据上一条的sequnce查询指定数量的信息
* @param emc
* @param maxCount
* @param sequnce
* @param orderField
* @param orderType
* @param personName
* @param identityNames
* @param unitNames
* @param groupNames
* @return
* @throws Exception
*/
protected List<WCrmConfig> listWithFilter( EntityManagerContainer emc, Integer maxCount, String sequnce, String orderField, String orderType, String personName, List<String> identityNames, List<String> unitNames, List<String> groupNames, QueryFilter queryFilter ) throws Exception {
Business business = new Business( emc );
return business.configFactory().listWithFilter(maxCount, sequnce, orderField, orderType, personName, queryFilter);
}
/**
* 根据条件查询配置ID列表,最大查询2000条
* @param emc
* @param maxCount
* @param personName
* @param queryFilter
* @return
* @throws Exception
*/
public List<String> listAllConfigIds(EntityManagerContainer emc, int maxCount, String personName, QueryFilter queryFilter) throws Exception {
Business business = new Business( emc );
return business.configFactory().listAllConfigIds(maxCount, personName, queryFilter);
}
}
package com.x.wcrm.assemble.control.service;
import com.google.gson.*;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
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.assemble.control.Business;
import com.x.wcrm.assemble.control.tools.ClassPathResource;
import com.x.wcrm.core.entity.WCrmConfig;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class SystemConfigPersistService {
private Logger logger = LoggerFactory.getLogger( SystemConfigPersistService.class );
/**
* 初始化所有的系统设置
* @throws Exception
*/
public void initSystemConfig() throws Exception {
Business business = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
business = new Business(emc);
List<WCrmConfig> configs = business.configFactory().ListConfigsWithType("线索");
if(ListTools.isEmpty(configs)){
logger.info("crm---系统检测到crm未初始化配置");
ClassPathResource resource = new ClassPathResource("/config.json");
InputStream in = resource.getInputStream();
if (in != null) {
String configStr = readToString(in);
JsonParser parser = new JsonParser();
JsonArray jsonArray = parser.parse(configStr).getAsJsonArray();
//logger.info("jsonArray============"+jsonArray.size());
Gson gson = new Gson();
List<WCrmConfig> configList = new ArrayList<>();
for (JsonElement o : jsonArray) {
//使用GSON,直接转成Bean对象
WCrmConfig wc = gson.fromJson(o, WCrmConfig.class);
configList.add(wc);
}
if(ListTools.isNotEmpty(configList)){
logger.info("crm---初始化配置开始");
emc.beginTransaction(WCrmConfig.class);
for(WCrmConfig wconfig : configList){
emc.persist(wconfig, CheckPersistType.all);
}
emc.commit();
logger.info("crm---初始化配置结束");
}
}
}
}catch ( Exception e ) {
throw e;
}
}
public String readToString(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return new String(output.toByteArray(), "UTF-8");
}
}
package com.x.wcrm.assemble.control.tools;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**
* @Author: LJ
* @Date: 2021/07/08
*/
public class ClassPathResource {
private final String path;
private ClassLoader classLoader;
private Class<?> clazz;
public ClassPathResource(String path, ClassLoader classLoader) {
if (path.startsWith("/")) {
path = path.substring(1);
}
this.path = path;
this.classLoader = (classLoader != null ? classLoader : getDefaultClassLoader());
}
public ClassPathResource(String path) {
this(path, (ClassLoader) null);
}
public final String getPath() {
return this.path;
}
public InputStream getInputStream() throws IOException {
InputStream is;
if (this.clazz != null) {
is = this.clazz.getResourceAsStream(this.path);
} else if (this.classLoader != null) {
is = this.classLoader.getResourceAsStream(this.path);
} else {
is = ClassLoader.getSystemResourceAsStream(this.path);
}
if (is == null) {
throw new FileNotFoundException(this.path+" 文件不存在");
}
return is;
}
public static ClassLoader getDefaultClassLoader() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (Throwable ex) {
// Cannot access thread context ClassLoader - falling back...
}
if (cl == null) {
// No thread context class loader -> use class loader of this class.
cl = ClassPathResource.class.getClassLoader();
if (cl == null) {
// getClassLoader() returning null indicates the bootstrap ClassLoader
try {
cl = ClassLoader.getSystemClassLoader();
} catch (Throwable ex) {
// Cannot access system ClassLoader - oh well, maybe the caller can live with null...
}
}
}
return cl;
}
}
package com.x.wcrm.core.entity.tools;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.SliceJpaObject_;
import com.x.base.core.project.tools.ListTools;
import com.x.wcrm.core.entity.tools.filter.QueryFilter;
import com.x.wcrm.core.entity.tools.filter.term.*;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.criteria.*;
import java.lang.reflect.Field;
import java.util.List;
public class CriteriaBuilderTools {
public static Predicate predicate_or( CriteriaBuilder criteriaBuilder, Predicate predicate, Predicate predicate_target ) {
if( predicate == null ) {
return predicate_target;
}else {
if( predicate_target != null ) {
return criteriaBuilder.or( predicate, predicate_target );
}else {
return predicate;
}
}
}
public static Predicate predicate_and( CriteriaBuilder criteriaBuilder, Predicate predicate, Predicate predicate_target ) {
if( predicate == null ) {
return predicate_target;
}else {
if( predicate_target != null ) {
return criteriaBuilder.and( predicate, predicate_target );
}else {
return predicate;
}
}
}
/**
* 根据过滤条件组织查询语句
* @param cls -查询的实体类名
* @param cls_ -查询的实体类对应的StaticMetamodel
* @param em -EntityManager
* @param queryFilter -查询过滤条件
* @return
* @throws NoSuchFieldException
* @throws SecurityException
*/
public static <T extends JpaObject, T_ extends SliceJpaObject_> Predicate composePredicateWithQueryFilter(
Class<T> cls, Class<T_> cls_, EntityManager em, QueryFilter queryFilter ) throws NoSuchFieldException, SecurityException {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery( cls );
Root<T> root = cq.from( cls );
Predicate p = null;
return composePredicateWithQueryFilter( cls_, cb, p, root, queryFilter ) ;
}
/**
* 根据过滤条件组织查询语句
* @param cls_ -查询的实体类对应的StaticMetamodel
* @param cb -CriteriaBuilder
* @param p -Predicate
* @param root -查询根
* @param queryFilter -查询过滤条件
* @return
* @throws NoSuchFieldException
* @throws SecurityException
*/
public static <T extends JpaObject, T_ extends SliceJpaObject_> Predicate composePredicateWithQueryFilter(
Class<T_> cls_, CriteriaBuilder cb, Predicate p, Root<T> root, QueryFilter queryFilter ) throws NoSuchFieldException, SecurityException {
if( queryFilter == null ) {
queryFilter = new QueryFilter();
}
//组装条件
if( ListTools.isNotEmpty( queryFilter.getEqualsTerms() )) {
for( EqualsTerm term : queryFilter.getEqualsTerms() ) {
if( StringUtils.isEmpty( term.getName() ) || term.getValue() == null || StringUtils.isEmpty( term.getValue().toString() )) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.equal( root.get( term.getName() ), term.getValue() ));
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, cb.equal( root.get( term.getName() ), term.getValue() ) );
}
}
}
if( ListTools.isNotEmpty( queryFilter.getNotEqualsTerms() )) {
for( NotEqualsTerm term : queryFilter.getNotEqualsTerms() ) {
if( StringUtils.isEmpty( term.getName() ) || term.getValue() == null || StringUtils.isEmpty( term.getValue().toString() )) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.notEqual( root.get( term.getName() ), term.getValue() ));
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, cb.notEqual( root.get( term.getName() ), term.getValue() ) );
}
}
}
if( ListTools.isNotEmpty( queryFilter.getInTerms() )) {
for( InTerm term : queryFilter.getInTerms() ) {
if( StringUtils.isEmpty( term.getName() ) || ListTools.isEmpty( term.getValue())) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, root.get( term.getName() ).in( term.getValue() ));
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, root.get( term.getName() ).in( term.getValue() ) );
}
}
}
if( ListTools.isNotEmpty( queryFilter.getNotInTerms() )) {
for( NotInTerm term : queryFilter.getNotInTerms() ) {
if( StringUtils.isEmpty( term.getName() ) || ListTools.isEmpty( term.getValue())) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, root.get( term.getName() ).in( term.getValue() ).not());
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, root.get( term.getName() ).in( term.getValue() ).not() );
}
}
}
if( ListTools.isNotEmpty( queryFilter.getMemberTerms() )) {
for( MemberTerm term : queryFilter.getMemberTerms() ) {
if( StringUtils.isEmpty( term.getName() ) || term.getValue() == null || StringUtils.isEmpty( term.getValue().toString() )) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.isMember( term.getValue(), root.get( term.getName() ) ));
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, cb.isMember( term.getValue(), root.get( term.getName() ) ) );
}
}
}
if( ListTools.isNotEmpty( queryFilter.getNotMemberTerms() )) {
for( NotMemberTerm term : queryFilter.getNotMemberTerms() ) {
if( StringUtils.isEmpty( term.getName() ) || term.getValue() == null || StringUtils.isEmpty( term.getValue().toString() )) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.isNotMember( term.getValue(), root.get( term.getName() ) ));
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, cb.isNotMember( term.getValue(), root.get( term.getName() ) ) );
}
}
}
if( ListTools.isNotEmpty( queryFilter.getLikeTerms())) {
for( LikeTerm term : queryFilter.getLikeTerms() ) {
if( StringUtils.isEmpty( term.getName() ) || term.getValue() == null || StringUtils.isEmpty( term.getValue().toString() )) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.like( root.get( term.getName() ), term.getValue() ));
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, cb.like( root.get( term.getName() ), term.getValue() ));
}
}
}
if( ListTools.isNotEmpty( queryFilter.getIsTrueTerms())) {
for( IsTrueTerm term : queryFilter.getIsTrueTerms() ) {
if( StringUtils.isEmpty( term.getName() )) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.isTrue( root.get( term.getName() )));
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, cb.isTrue( root.get( term.getName() )));
}
}
}
if( ListTools.isNotEmpty( queryFilter.getIsFalseTerms())) {
for( IsFalseTerm term : queryFilter.getIsFalseTerms() ) {
if( StringUtils.isEmpty( term.getName() )) {
continue;
}
if( "and".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_and( cb, p, cb.isFalse( root.get( term.getName() )));
} else if( "or".equalsIgnoreCase( queryFilter.getJoinType() )) {
p = CriteriaBuilderTools.predicate_or( cb, p, cb.isFalse( root.get( term.getName() )));
}
}
}
//继续递归查询条件
if( queryFilter.getAnd() != null ) {
queryFilter.setJoinType( "and" );
composePredicateWithQueryFilter( cls_, cb, p, root, queryFilter.getAnd() ) ;
}
if( queryFilter.getOr() != null ) {
queryFilter.setJoinType( "or" );
composePredicateWithQueryFilter( cls_, cb, p, root, queryFilter.getOr() ) ;
}
return p;
}
/**
* 通用的分页查询
* @param em -EntityManager
* @param cls -查询的实体类名
* @param cls_ -查询的实体类对应的StaticMetamodel
* @param maxCount -输出最大条目数量
* @param queryFilter -查询过滤条件
* @param sequenceFieldValue -上一条的序列值
* @param orderField -排序列名,默认createTime
* @param order -排序方式,默认DESC
* @return
* @throws Exception
*/
public static <T extends JpaObject, T_ extends SliceJpaObject_> List<T> listNextWithCondition( EntityManager em, Class<T> cls, Class<T_> cls_, Integer maxCount,
QueryFilter queryFilter, Object sequenceFieldValue, String orderField, String order ) throws Exception {
if( order == null || order.isEmpty() ){
order = "DESC";
}
if( StringUtils.isEmpty( orderField )){
orderField = "sequence";
}
if( maxCount == null || maxCount == 0 ) {
maxCount = 20;
}
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery( cls );
Root<T> root = cq.from( cls );
Predicate p = null;
//根据序列来排序
if( sequenceFieldValue != null ){
if( "DESC".equalsIgnoreCase( order )){
p = predicate_and( cb, p, cb.lessThan( root.get( orderField ), sequenceFieldValue.toString() ));
}else{
p = predicate_and( cb, p, cb.greaterThan( root.get( orderField ), sequenceFieldValue.toString() ));
}
}
//根据过滤条件来组织查询语句
p = CriteriaBuilderTools.composePredicateWithQueryFilter( cls_, cb, p, root, queryFilter );
//按要求排序查询结果
if( "DESC".equalsIgnoreCase( order )){
cq.orderBy( cb.desc( root.get( orderField )));
}else{
cq.orderBy( cb.asc( root.get( orderField )) );
}
//System.out.println(">>>>>>>>>SQL:" + em.createQuery(cq.where(p).distinct(true)).setMaxResults( maxCount ).toString() );
return em.createQuery(cq.where(p).distinct(true)).setMaxResults( maxCount ).getResultList();
}
/**
* 根据条件组织一个排序的语句
* @param <T>
* @param <T_>
* @param cb
* @param root
* @param cls_
* @param fieldName
* @param orderType
* @return
*/
public static <T extends JpaObject, T_ extends SliceJpaObject_>Order getOrder( CriteriaBuilder cb, Root<T> root, Class<T_> cls_, String fieldName, String orderType ) {
Boolean fieldExists = false;
Field[] fields = cls_.getDeclaredFields();
for( Field field : fields ) {
if( field.getName().equalsIgnoreCase( fieldName ) ) {
fieldName = field.getName(); //校正排序列的名称
fieldExists = true;
}
}
if( !fieldExists ) { //如果排序列不存在,就直接返回空,不排序,让SQL可以正常执行
return null;
}
if( "desc".equalsIgnoreCase( orderType )) {
return cb.desc( root.get( fieldName ).as(String.class) );
}else {
return cb.asc( root.get( fieldName ).as(String.class) );
}
}
}
package com.x.wcrm.core.entity.tools.filter;
import com.x.base.core.project.tools.ListTools;
import com.x.wcrm.core.entity.tools.filter.term.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
public class QueryFilter{
private String joinType = "and";
private List<EqualsTerm> equalsTerms = null;
private List<IsTrueTerm> isTrueTerms = null;
private List<IsFalseTerm> isFalseTerms = null;
private List<InTerm> inTerms = null;
private List<LikeTerm> likeTerms = null;
private List<MemberTerm> memberTerms = null;
private List<NotEqualsTerm> notEqualsTerms = null;
private List<NotInTerm> notInTerms = null;
private List<NotMemberTerm> notMemberTerms = null;
private QueryFilter and = null;
private QueryFilter or = null;
public List<EqualsTerm> getEqualsTerms() {
return equalsTerms;
}
public List<InTerm> getInTerms() {
return inTerms;
}
public List<LikeTerm> getLikeTerms() {
return likeTerms;
}
public List<MemberTerm> getMemberTerms() {
return memberTerms;
}
public List<NotEqualsTerm> getNotEqualsTerms() {
return notEqualsTerms;
}
public List<NotInTerm> getNotInTerms() {
return notInTerms;
}
public List<NotMemberTerm> getNotMemberTerms() {
return notMemberTerms;
}
public QueryFilter getAnd() {
return and;
}
public QueryFilter getOr() {
return or;
}
public List<IsTrueTerm> getIsTrueTerms() {
return isTrueTerms;
}
public void setIsTrueTerms(List<IsTrueTerm> isTrueTerms) {
this.isTrueTerms = isTrueTerms;
}
public List<IsFalseTerm> getIsFalseTerms() {
return isFalseTerms;
}
public void setIsFalseTerms(List<IsFalseTerm> isFalseTerms) {
this.isFalseTerms = isFalseTerms;
}
public void addIsTrueTerm( IsTrueTerm term ) {
if( this.isTrueTerms == null ){ this.isTrueTerms = new ArrayList<>(); }
boolean exists = false;
for( IsTrueTerm _term : this.isTrueTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
}
}
if( !exists ) {
this.isTrueTerms.add( term );
}
}
public void addIsFalseTerm( IsFalseTerm term ) {
if( this.isFalseTerms == null ){ this.isFalseTerms = new ArrayList<>(); }
boolean exists = false;
for( IsFalseTerm _term : this.isFalseTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
}
}
if( !exists ) {
this.isFalseTerms.add( term );
}
}
public void addEqualsTerm( EqualsTerm term ) {
if( this.equalsTerms == null ){ this.equalsTerms = new ArrayList<>(); }
boolean exists = false;
for( EqualsTerm _term : this.equalsTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
//替换新的值
_term.setValue( term.getValue() );
}
}
if( !exists ) {
this.equalsTerms.add( term );
}
}
public void setEqualsTerms(List<EqualsTerm> equalsTerms) {
this.equalsTerms = equalsTerms;
}
public void addInTerm( InTerm term ) {
if( this.inTerms == null ){ this.inTerms = new ArrayList<>(); }
boolean exists = false;
for( InTerm _term : this.inTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
//替换新的值
_term.setValue( term.getValue() );
}
}
if( !exists ) {
this.inTerms.add( term );
}
}
public void setInTerms(List<InTerm> inTerms) {
this.inTerms = inTerms;
}
public void addLikeTerm( LikeTerm term ) {
if( this.likeTerms == null ){ this.likeTerms = new ArrayList<>(); }
boolean exists = false;
for( LikeTerm _term : this.likeTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
//替换新的值
_term.setValue( term.getValue() );
}
}
if( !exists ) {
this.likeTerms.add( term );
}
}
public void setLikeTerms(List<LikeTerm> likeTerms) {
this.likeTerms = likeTerms;
}
public void addMemberTerm( MemberTerm term ) {
if( this.memberTerms == null ){ this.memberTerms = new ArrayList<>(); }
boolean exists = false;
for( MemberTerm _term : this.memberTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
//替换新的值
_term.setValue( term.getValue() );
}
}
if( !exists ) {
this.memberTerms.add( term );
}
}
public void setMemberTerms(List<MemberTerm> memberTerms) {
this.memberTerms = memberTerms;
}
public void addNotEqualsTerm( NotEqualsTerm term ) {
if( this.notEqualsTerms == null ){ this.notEqualsTerms = new ArrayList<>(); }
boolean exists = false;
for( NotEqualsTerm _term : this.notEqualsTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
//替换新的值
_term.setValue( term.getValue() );
}
}
if( !exists ) {
this.notEqualsTerms.add( term );
}
}
public void setNotEqualsTerms(List<NotEqualsTerm> notEqualsTerms) {
this.notEqualsTerms = notEqualsTerms;
}
public void addNotInTerm( NotInTerm term ) {
if( this.notInTerms == null ){ this.notInTerms = new ArrayList<>(); }
boolean exists = false;
for( NotInTerm _term : this.notInTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
//替换新的值
_term.setValue( term.getValue() );
}
}
if( !exists ) {
this.notInTerms.add( term );
}
}
public void setNotInTerms(List<NotInTerm> notInTerms) {
this.notInTerms = notInTerms;
}
public void addNotMemberTerm( NotMemberTerm term ) {
if( this.notMemberTerms == null ){ this.notMemberTerms = new ArrayList<>(); }
boolean exists = false;
for( NotMemberTerm _term : this.notMemberTerms ) {
if ( _term.getName().equals( term.getName() )) {
exists = true;
//替换新的值
_term.setValue( term.getValue() );
}
}
if( !exists ) {
this.notMemberTerms.add( term );
}
}
public void setNotMemberTerms(List<NotMemberTerm> notMemberTerms) {
this.notMemberTerms = notMemberTerms;
}
public void setAnd(QueryFilter and) {
this.and = and;
}
public void setOr(QueryFilter or) {
this.or = or;
}
public String getJoinType() {
return joinType;
}
public void setJoinType(String joinType) {
this.joinType = joinType;
}
public String getQueryContent() {
StringBuffer content = new StringBuffer("query:");
content.append( "{" );
if( this.joinType != null ) {
content.append( "'joinType':'" + this.joinType.toString() + "'" );
}
if( this.and != null ) {
content.append( "'and':" +this.and.toString() );
}
if( this.or != null ) {
content.append( "'or':" +this.or.toString() );
}
content.append( "}" );
content.append( ",equalsTerms:[" );
if( ListTools.isNotEmpty( equalsTerms )) {
for( EqualsTerm term : equalsTerms ) {
content.append( "{" );
content.append( "'"+term.getName().toString() + "':" );
content.append( "'"+term.getValue().toString() + "'");
content.append( "}," );
}
}
content.append( "]" );
content.append( ",notEqualsTerms:[" );
if( ListTools.isNotEmpty( notEqualsTerms )) {
for( NotEqualsTerm term : notEqualsTerms ) {
content.append( "{" );
content.append( "'"+term.getName().toString() + "':" );
content.append( "'"+term.getValue().toString() + "'");
content.append( "}," );
}
}
content.append( "]" );
content.append( ",inTerms:[" );
if( ListTools.isNotEmpty( inTerms )) {
for( InTerm term : inTerms ) {
content.append( "{" );
content.append( "'"+term.getName().toString() + "':" );
if( ListTools.isNotEmpty( term.getValue() )) {
content.append( "[");
for( Object object : term.getValue() ) {
content.append( "'"+object.toString() + "', ");
}
content.append( "]");
}
content.append( "}," );
}
}
content.append( "]" );
content.append( ",notInTerms:[" );
if( ListTools.isNotEmpty( notInTerms )) {
for( NotInTerm term : notInTerms ) {
content.append( "{" );
content.append( "'"+term.getName().toString() + "':" );
if( ListTools.isNotEmpty( term.getValue() )) {
content.append( "[");
for( Object object : term.getValue() ) {
content.append( "'"+object.toString() + "', ");
}
content.append( "]");
}
content.append( "}," );
}
}
content.append( "]" );
content.append( ",likeTerms:[" );
if( ListTools.isNotEmpty( likeTerms )) {
for( LikeTerm term : likeTerms ) {
content.append( "{" );
content.append( "'"+term.getName().toString() + "':" );
content.append( "'"+term.getValue().toString() + "'");
content.append( "}," );
}
}
content.append( "]" );
content.append( ",memberTerms:[" );
if( ListTools.isNotEmpty( memberTerms )) {
for( MemberTerm term : memberTerms ) {
content.append( "{" );
content.append( "'"+term.getName().toString() + "':" );
content.append( "'"+term.getValue().toString() + "'");
content.append( "}," );
}
}
content.append( "]" );
content.append( ",notMemberTerms:[" );
if( ListTools.isNotEmpty( notMemberTerms )) {
for( NotMemberTerm term : notMemberTerms ) {
content.append( "{" );
content.append( "'"+term.getName().toString() + "':" );
content.append( "'"+term.getValue().toString() + "'");
content.append( "}," );
}
}
content.append( "]" );
return content.toString();
}
/**
* 将查询的所有内容组织成String,然后计算一个SHA1
* DigestUtils.sha1Hex(content)
* @return
*/
public String getContentSHA1() {
String content = getQueryContent();
if( StringUtils.isEmpty( content )) {
return DigestUtils.sha1Hex("null");
}else {
return DigestUtils.sha1Hex(content);
}
}
}
package com.x.wcrm.core.entity.tools.filter.term;
import java.util.Collection;
public class BetweenTerm{
private String name = null;
private Collection<Object> value = null;
public BetweenTerm() {}
public BetweenTerm( String name, Collection<Object> value ) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Collection<Object> getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(Collection<Object> value) {
this.value = value;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
public class EqualsTerm {
private String name = null;
private Object value = null;
public EqualsTerm() {}
public EqualsTerm( String name, Object value ) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Object getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(Object value) {
this.value = value;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
import java.util.List;
public class InTerm{
private String name = null;
private List<Object> value = null;
public InTerm() {}
public InTerm( String name, List<Object> value ) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public List<Object> getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(List<Object> value) {
this.value = value;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
public class IsFalseTerm {
private String name = null;
public IsFalseTerm() {}
public IsFalseTerm( String name ) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
public class IsTrueTerm {
private String name = null;
public IsTrueTerm() {}
public IsTrueTerm( String name ) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
public class LikeTerm{
private String name = null;
private String value = null;
public LikeTerm() {}
public LikeTerm( String name, String value ) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
public class MemberTerm {
private String name = null;
private String value = null;
public MemberTerm() {}
public MemberTerm( String name, String value ) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
public class NotEqualsTerm {
private String name = null;
private Object value = null;
public NotEqualsTerm() {}
public NotEqualsTerm( String name, Object value ) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Object getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(Object value) {
this.value = value;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
import java.util.List;
public class NotInTerm{
private String name = null;
private List<Object> value = null;
public NotInTerm() {}
public NotInTerm( String name, List<Object> value ) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public List<Object> getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(List<Object> value) {
this.value = value;
}
}
package com.x.wcrm.core.entity.tools.filter.term;
public class NotMemberTerm{
private String name = null;
private String value = null;
public NotMemberTerm() {}
public NotMemberTerm( String name, String value ) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setName(String name) {
this.name = name;
}
public void setValue(String value) {
this.value = value;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册