提交 9cce7285 编写于 作者: O o2null

Merge branch 'feature/personManageUnit' into 'develop'

增加查找人员在管理列表中的组织.

See merge request o2oa/o2oa!1372
......@@ -17,192 +17,192 @@ import com.x.base.core.project.tools.DefaultCharset;
public class General extends ConfigObject {
private static final long serialVersionUID = 4393280516414081348L;
private static final Boolean DEFAULT_WEBSOCKETENABLE = true;
private static final Boolean DEFAULT_CONFIGAPIENABLE = true;
private static final List<String> DEFAULT_SCRIPTINGBLOCKEDCLASSES = Arrays.asList(Runtime.class.getName(),
File.class.getName(), Path.class.getName(), java.lang.ProcessBuilder.class.getName());
private static final Boolean DEFAULT_REQUESTLOGENABLE = false;
private static final Integer DEFAULT_REQUESTLOGRETAINDAYS = 7;
private static final Boolean DEFAULT_REQUESTLOGBODYENABLE = false;
private static final Boolean DEFAULT_DEPLOYRESOURCEENABLE = false;
private static final Boolean DEFAULT_DEPLOYWARENABLE = false;
private static final Boolean DEFAULT_STATENABLE = false;
private static final String DEFAULT_STATEXCLUSIONS = "*.js,*.gif,*.jpg,*.png,*.css,*.ico";
private static final Boolean DEFAULT_EXPOSEJEST = true;
private static final String DEFAULT_REFERERHEADCHECKREGULAR = "";
private static final String DEFAULT_ACCESSCONTROLALLOWORIGIN = "";
private static final String DEFAULT_IDFORMATCHECKREGULAR = "";
public static General defaultInstance() {
General o = new General();
o.webSocketEnable = DEFAULT_WEBSOCKETENABLE;
o.configApiEnable = DEFAULT_CONFIGAPIENABLE;
o.scriptingBlockedClasses = DEFAULT_SCRIPTINGBLOCKEDCLASSES;
o.requestLogEnable = DEFAULT_REQUESTLOGENABLE;
o.requestLogRetainDays = DEFAULT_REQUESTLOGRETAINDAYS;
o.requestLogBodyEnable = DEFAULT_REQUESTLOGBODYENABLE;
o.deployResourceEnable = DEFAULT_DEPLOYRESOURCEENABLE;
o.deployWarEnable = DEFAULT_DEPLOYWARENABLE;
o.statEnable = DEFAULT_STATENABLE;
o.statExclusions = DEFAULT_STATEXCLUSIONS;
o.exposeJest = DEFAULT_EXPOSEJEST;
o.refererHeadCheckRegular = DEFAULT_REFERERHEADCHECKREGULAR;
o.accessControlAllowOrigin = DEFAULT_ACCESSCONTROLALLOWORIGIN;
o.idFormatCheckRegular = DEFAULT_IDFORMATCHECKREGULAR;
o.attachmentConfig = new AttachmentConfig();
return o;
}
@FieldDescribe("启用访问日志功能.")
private Boolean requestLogEnable;
@FieldDescribe("访问日志记录天数,默认7天.")
private Integer requestLogRetainDays;
@FieldDescribe("访问日志是否记录post或者put的body内容,只对content-type为application/json的请求有效.")
private Boolean requestLogBodyEnable;
@FieldDescribe("是否启用webSocket链接.")
private Boolean webSocketEnable;
private static final long serialVersionUID = 4393280516414081348L;
private static final Boolean DEFAULT_WEBSOCKETENABLE = true;
private static final Boolean DEFAULT_CONFIGAPIENABLE = true;
private static final List<String> DEFAULT_SCRIPTINGBLOCKEDCLASSES = Arrays.asList(Runtime.class.getName(),
File.class.getName(), Path.class.getName(), java.lang.ProcessBuilder.class.getName());
private static final Boolean DEFAULT_REQUESTLOGENABLE = false;
private static final Integer DEFAULT_REQUESTLOGRETAINDAYS = 7;
private static final Boolean DEFAULT_REQUESTLOGBODYENABLE = false;
private static final Boolean DEFAULT_DEPLOYRESOURCEENABLE = false;
private static final Boolean DEFAULT_DEPLOYWARENABLE = false;
private static final Boolean DEFAULT_STATENABLE = false;
private static final String DEFAULT_STATEXCLUSIONS = "*.js,*.gif,*.jpg,*.png,*.css,*.ico";
private static final Boolean DEFAULT_EXPOSEJEST = true;
private static final String DEFAULT_REFERERHEADCHECKREGULAR = "";
private static final String DEFAULT_ACCESSCONTROLALLOWORIGIN = "";
private static final String DEFAULT_IDFORMATCHECKREGULAR = "";
public static General defaultInstance() {
General o = new General();
o.webSocketEnable = DEFAULT_WEBSOCKETENABLE;
o.configApiEnable = DEFAULT_CONFIGAPIENABLE;
o.scriptingBlockedClasses = DEFAULT_SCRIPTINGBLOCKEDCLASSES;
o.requestLogEnable = DEFAULT_REQUESTLOGENABLE;
o.requestLogRetainDays = DEFAULT_REQUESTLOGRETAINDAYS;
o.requestLogBodyEnable = DEFAULT_REQUESTLOGBODYENABLE;
o.deployResourceEnable = DEFAULT_DEPLOYRESOURCEENABLE;
o.deployWarEnable = DEFAULT_DEPLOYWARENABLE;
o.statEnable = DEFAULT_STATENABLE;
o.statExclusions = DEFAULT_STATEXCLUSIONS;
o.exposeJest = DEFAULT_EXPOSEJEST;
o.refererHeadCheckRegular = DEFAULT_REFERERHEADCHECKREGULAR;
o.accessControlAllowOrigin = DEFAULT_ACCESSCONTROLALLOWORIGIN;
o.idFormatCheckRegular = DEFAULT_IDFORMATCHECKREGULAR;
o.attachmentConfig = new AttachmentConfig();
return o;
}
@FieldDescribe("启用访问日志功能.")
private Boolean requestLogEnable;
@FieldDescribe("访问日志记录天数,默认7天.")
private Integer requestLogRetainDays;
@FieldDescribe("访问日志是否记录post或者put的body内容,只对content-type为application/json的请求有效.")
private Boolean requestLogBodyEnable;
@FieldDescribe("是否启用webSocket链接.")
private Boolean webSocketEnable;
@FieldDescribe("允许通过接口修改系统配置.")
private Boolean configApiEnable;
@FieldDescribe("允许通过接口修改系统配置.")
private Boolean configApiEnable;
@FieldDescribe("是否允许部署war包.")
private Boolean deployWarEnable;
@FieldDescribe("是否允许部署war包.")
private Boolean deployWarEnable;
@FieldDescribe("是否允许部署静态资源.")
private Boolean deployResourceEnable;
@FieldDescribe("是否允许部署静态资源.")
private Boolean deployResourceEnable;
@FieldDescribe("启用统计,默认启用统计.")
private Boolean statEnable;
@FieldDescribe("启用统计,默认启用统计.")
private Boolean statEnable;
@FieldDescribe("统计忽略路径,默认忽略*.js,*.gif,*.jpg,*.png,*.css,*.ico")
private String statExclusions;
@FieldDescribe("统计忽略路径,默认忽略*.js,*.gif,*.jpg,*.png,*.css,*.ico")
private String statExclusions;
@FieldDescribe("暴露jest接口.")
private Boolean exposeJest;
@FieldDescribe("暴露jest接口.")
private Boolean exposeJest;
@FieldDescribe("脚本中禁止用的类名,保持为空则默认禁用Runtime,File,Path.")
private List<String> scriptingBlockedClasses;
@FieldDescribe("脚本中禁止用的类名,保持为空则默认禁用Runtime,File,Path.")
private List<String> scriptingBlockedClasses;
@FieldDescribe("http referer 校验正则表达式,可以对CSRF攻击进行防护校验,样例:(.+?)o2oa.net(.+?)")
private String refererHeadCheckRegular = "";
@FieldDescribe("http referer 校验正则表达式,可以对CSRF攻击进行防护校验,样例:(.+?)o2oa.net(.+?)")
private String refererHeadCheckRegular = "";
@FieldDescribe("跨源资源共享许可,设置http返回的Access-Control-Allow-Origin标识,可以用于CORS攻击防护,样例:https://www.o2oa.net")
private String accessControlAllowOrigin = "";
@FieldDescribe("跨源资源共享许可,设置http返回的Access-Control-Allow-Origin标识,可以用于CORS攻击防护,样例:https://www.o2oa.net")
private String accessControlAllowOrigin = "";
@FieldDescribe("附件上传限制大小或者类型.")
private AttachmentConfig attachmentConfig;
@FieldDescribe("附件上传限制大小或者类型.")
private AttachmentConfig attachmentConfig;
@FieldDescribe("对象id格式校验正则表达式.")
private String idFormatCheckRegular = "";
@FieldDescribe("对象id格式校验正则表达式.")
private String idFormatCheckRegular = "";
public String getIdFormatCheckRegular() {
return this.idFormatCheckRegular;
}
public String getIdFormatCheckRegular() {
return this.idFormatCheckRegular;
}
public String getRefererHeadCheckRegular() {
return (StringUtils.isBlank(refererHeadCheckRegular) ? DEFAULT_REFERERHEADCHECKREGULAR
: this.refererHeadCheckRegular);
}
public String getRefererHeadCheckRegular() {
return (StringUtils.isBlank(refererHeadCheckRegular) ? DEFAULT_REFERERHEADCHECKREGULAR
: this.refererHeadCheckRegular);
}
public String getAccessControlAllowOrigin() {
return (StringUtils.isBlank(accessControlAllowOrigin) ? DEFAULT_ACCESSCONTROLALLOWORIGIN
: this.accessControlAllowOrigin);
}
public String getAccessControlAllowOrigin() {
return (StringUtils.isBlank(accessControlAllowOrigin) ? DEFAULT_ACCESSCONTROLALLOWORIGIN
: this.accessControlAllowOrigin);
}
public Boolean getExposeJest() {
return BooleanUtils.isNotFalse(this.exposeJest);
}
public Boolean getExposeJest() {
return BooleanUtils.isNotFalse(this.exposeJest);
}
public String getStatExclusions() {
return (StringUtils.isEmpty(statExclusions) ? DEFAULT_STATEXCLUSIONS : this.statExclusions) + ",/druid/*";
}
public String getStatExclusions() {
return (StringUtils.isEmpty(statExclusions) ? DEFAULT_STATEXCLUSIONS : this.statExclusions) + ",/druid/*";
}
public Boolean getStatEnable() {
return BooleanUtils.isNotFalse(statEnable);
}
public Boolean getStatEnable() {
return BooleanUtils.isNotFalse(statEnable);
}
public Boolean getRequestLogEnable() {
return BooleanUtils.isTrue(this.requestLogEnable);
}
public Boolean getRequestLogEnable() {
return BooleanUtils.isTrue(this.requestLogEnable);
}
public Integer getRequestLogRetainDays() {
return (null == this.requestLogRetainDays || this.requestLogRetainDays < 1) ? DEFAULT_REQUESTLOGRETAINDAYS
: this.requestLogRetainDays;
}
public Integer getRequestLogRetainDays() {
return (null == this.requestLogRetainDays || this.requestLogRetainDays < 1) ? DEFAULT_REQUESTLOGRETAINDAYS
: this.requestLogRetainDays;
}
public Boolean getRequestLogBodyEnable() {
return BooleanUtils.isTrue(this.requestLogBodyEnable);
}
public Boolean getRequestLogBodyEnable() {
return BooleanUtils.isTrue(this.requestLogBodyEnable);
}
public List<String> getScriptingBlockedClasses() {
return (null == this.scriptingBlockedClasses) ? DEFAULT_SCRIPTINGBLOCKEDCLASSES : this.scriptingBlockedClasses;
}
public List<String> getScriptingBlockedClasses() {
return (null == this.scriptingBlockedClasses) ? DEFAULT_SCRIPTINGBLOCKEDCLASSES : this.scriptingBlockedClasses;
}
public Boolean getWebSocketEnable() {
return null == this.webSocketEnable ? DEFAULT_WEBSOCKETENABLE : this.webSocketEnable;
}
public Boolean getWebSocketEnable() {
return null == this.webSocketEnable ? DEFAULT_WEBSOCKETENABLE : this.webSocketEnable;
}
public Boolean getConfigApiEnable() {
return null == this.configApiEnable ? DEFAULT_CONFIGAPIENABLE : this.configApiEnable;
}
public Boolean getConfigApiEnable() {
return null == this.configApiEnable ? DEFAULT_CONFIGAPIENABLE : this.configApiEnable;
}
public Boolean getDeployWarEnable() {
public Boolean getDeployWarEnable() {
return null == this.deployWarEnable ? DEFAULT_DEPLOYWARENABLE : this.deployWarEnable;
}
return null == this.deployWarEnable ? DEFAULT_DEPLOYWARENABLE : this.deployWarEnable;
}
public Boolean getDeployResourceEnable() {
public Boolean getDeployResourceEnable() {
return null == this.deployResourceEnable ? DEFAULT_DEPLOYRESOURCEENABLE : this.deployResourceEnable;
}
return null == this.deployResourceEnable ? DEFAULT_DEPLOYRESOURCEENABLE : this.deployResourceEnable;
}
public AttachmentConfig getAttachmentConfig() {
return this.attachmentConfig == null ? new AttachmentConfig() : attachmentConfig;
}
public AttachmentConfig getAttachmentConfig() {
return this.attachmentConfig == null ? new AttachmentConfig() : attachmentConfig;
}
public static class AttachmentConfig extends ConfigObject {
public static class AttachmentConfig extends ConfigObject {
private static final long serialVersionUID = -5672631798073576284L;
private static final long serialVersionUID = -5672631798073576284L;
public static AttachmentConfig defaultInstance() {
return new AttachmentConfig();
}
public static AttachmentConfig defaultInstance() {
return new AttachmentConfig();
}
public static final Integer DEFAULT_FILE_SIZE = 0;
public static final Integer DEFAULT_FILE_SIZE = 0;
@FieldDescribe("附件大小限制(单位M,默认不限制).")
private Integer fileSize = DEFAULT_FILE_SIZE;
@FieldDescribe("附件大小限制(单位M,默认不限制).")
private Integer fileSize = DEFAULT_FILE_SIZE;
@FieldDescribe("只允许上传的文件后缀")
private List<String> fileTypeIncludes = new ArrayList<>();
@FieldDescribe("只允许上传的文件后缀")
private List<String> fileTypeIncludes = new ArrayList<>();
@FieldDescribe("不允许上传的文件后缀")
private List<String> fileTypeExcludes = Arrays.asList("jsp", "exe", "sh", "tmp");
@FieldDescribe("不允许上传的文件后缀")
private List<String> fileTypeExcludes = Arrays.asList("jsp", "exe", "sh", "tmp", "html", "htm", "xhtml");
public Integer getFileSize() {
return fileSize;
}
public Integer getFileSize() {
return fileSize;
}
public List<String> getFileTypeIncludes() {
return fileTypeIncludes;
}
public List<String> getFileTypeIncludes() {
return fileTypeIncludes;
}
public List<String> getFileTypeExcludes() {
return fileTypeExcludes;
}
public List<String> getFileTypeExcludes() {
return fileTypeExcludes;
}
}
}
public void save() throws Exception {
File file = new File(Config.base(), Config.PATH_CONFIG_GENERAL);
FileUtils.write(file, XGsonBuilder.toJson(this), DefaultCharset.charset);
BaseTools.executeSyncFile(Config.PATH_CONFIG_GENERAL);
}
public void save() throws Exception {
File file = new File(Config.base(), Config.PATH_CONFIG_GENERAL);
FileUtils.write(file, XGsonBuilder.toJson(this), DefaultCharset.charset);
BaseTools.executeSyncFile(Config.PATH_CONFIG_GENERAL);
}
}
......@@ -132,9 +132,6 @@ public class Main {
nodeAgent.start();
}
// SchedulerBuilder schedulerBuilder = new SchedulerBuilder();
// Scheduler scheduler = schedulerBuilder.start();
if (BooleanUtils.isTrue(Config.currentNode().autoStart())) {
startAll();
}
......
......@@ -34,102 +34,103 @@ import com.x.file.core.entity.personal.Share;
/**
* 定时清理回收站数据
*
* @author sword
*/
public class RecycleClean extends AbstractJob {
private static Logger logger = LoggerFactory.getLogger(RecycleClean.class);
private static final Logger LOGGER = LoggerFactory.getLogger(RecycleClean.class);
@Override
public void schedule(JobExecutionContext jobExecutionContext) throws Exception {
try {
logger.info("开始定时清理网盘回收站数据==========");
this.cleanRecycle();
logger.info("结束定时清理网盘回收站数据==========");
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
@Override
public void schedule(JobExecutionContext jobExecutionContext) throws Exception {
try {
Date start = new Date();
this.cleanRecycle();
LOGGER.info("结束定时清理网盘回收站数据,耗时:{}ms.", (new Date()).getTime() - start.getTime());
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
private void cleanRecycle() throws Exception{
List<String> list = this.listRecycle();
if(ListTools.isEmpty(list)){
return;
}
for (String id : list){
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Recycle recycle = emc.find(id, Recycle.class);
if(Share.FILE_TYPE_ATTACHMENT.equals(recycle.getFileType())){
Attachment2 att = emc.find(recycle.getFileId(), Attachment2.class);
this.deleteFile(business, att);
}else{
Folder2 folder = emc.find(recycle.getFileId(), Folder2.class);
if(folder!=null) {
List<String> ids = new ArrayList<>();
ids.add(folder.getId());
ids.addAll(business.folder2().listSubNested(folder.getId(), null));
for (int i = ids.size() - 1; i >= 0; i--) {
List<Attachment2> attachments = business.attachment2().listWithFolder2(ids.get(i),null);
for (Attachment2 att : attachments) {
this.deleteFile(business, att);
}
emc.beginTransaction(Folder2.class);
emc.delete(Folder2.class, ids.get(i));
emc.commit();
}
}
}
emc.beginTransaction(Recycle.class);
emc.delete(Recycle.class, recycle.getId());
emc.commit();
} catch (Exception e){
logger.warn("清理网盘回收站文件{}异常:{}",id,e.getMessage());
}
}
}
private void cleanRecycle() throws Exception {
List<String> list = this.listRecycle();
if (ListTools.isEmpty(list)) {
return;
}
for (String id : list) {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
Recycle recycle = emc.find(id, Recycle.class);
if (Share.FILE_TYPE_ATTACHMENT.equals(recycle.getFileType())) {
Attachment2 att = emc.find(recycle.getFileId(), Attachment2.class);
this.deleteFile(business, att);
} else {
Folder2 folder = emc.find(recycle.getFileId(), Folder2.class);
if (folder != null) {
List<String> ids = new ArrayList<>();
ids.add(folder.getId());
ids.addAll(business.folder2().listSubNested(folder.getId(), null));
for (int i = ids.size() - 1; i >= 0; i--) {
List<Attachment2> attachments = business.attachment2().listWithFolder2(ids.get(i), null);
for (Attachment2 att : attachments) {
this.deleteFile(business, att);
}
emc.beginTransaction(Folder2.class);
emc.delete(Folder2.class, ids.get(i));
emc.commit();
}
}
}
emc.beginTransaction(Recycle.class);
emc.delete(Recycle.class, recycle.getId());
emc.commit();
} catch (Exception e) {
LOGGER.warn("清理网盘回收站文件{}异常:{}.", id, e.getMessage());
}
}
}
private void deleteFile(Business business, Attachment2 att) throws Exception{
if(att==null){
return;
}
EntityManagerContainer emc = business.entityManagerContainer();
Long count = emc.countEqual(Attachment2.class, Attachment2.originFile_FIELDNAME, att.getOriginFile());
if(count.equals(1L)){
OriginFile originFile = emc.find(att.getOriginFile(), OriginFile.class);
if(originFile!=null){
StorageMapping mapping = ThisApplication.context().storageMappings().get(OriginFile.class,
originFile.getStorage());
if(mapping!=null){
originFile.deleteContent(mapping);
}
emc.beginTransaction(Attachment2.class);
emc.beginTransaction(OriginFile.class);
emc.remove(att);
emc.remove(originFile);
emc.commit();
}
}else{
emc.beginTransaction(Attachment2.class);
emc.remove(att);
emc.commit();
}
}
private void deleteFile(Business business, Attachment2 att) throws Exception {
if (att == null) {
return;
}
EntityManagerContainer emc = business.entityManagerContainer();
Long count = emc.countEqual(Attachment2.class, Attachment2.originFile_FIELDNAME, att.getOriginFile());
if (count.equals(1L)) {
OriginFile originFile = emc.find(att.getOriginFile(), OriginFile.class);
if (originFile != null) {
StorageMapping mapping = ThisApplication.context().storageMappings().get(OriginFile.class,
originFile.getStorage());
if (mapping != null) {
originFile.deleteContent(mapping);
}
emc.beginTransaction(Attachment2.class);
emc.beginTransaction(OriginFile.class);
emc.remove(att);
emc.remove(originFile);
emc.commit();
}
} else {
emc.beginTransaction(Attachment2.class);
emc.remove(att);
emc.commit();
}
}
private List<String> listRecycle() throws Exception{
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Integer days = FileConfig.DEFAULT_RECYCLE_DAYS;
FileConfig config = emc.firstEqual(FileConfig.class, FileConfig.person_FIELDNAME, Business.SYSTEM_CONFIG);
if(config != null && config.getRecycleDays()!=null){
days = config.getRecycleDays();
}
EntityManager em = emc.get(Recycle.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Recycle> root = cq.from(Recycle.class);
Predicate p = cb.lessThan(root.get(JpaObject_.createTime), DateTools.addDay(new Date(), -days));
cq.select(root.get(Recycle_.id)).where(p);
return em.createQuery(cq).getResultList();
}
}
private List<String> listRecycle() throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Integer days = FileConfig.DEFAULT_RECYCLE_DAYS;
FileConfig config = emc.firstEqual(FileConfig.class, FileConfig.person_FIELDNAME, Business.SYSTEM_CONFIG);
if (config != null && config.getRecycleDays() != null) {
days = config.getRecycleDays();
}
EntityManager em = emc.get(Recycle.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Recycle> root = cq.from(Recycle.class);
Predicate p = cb.lessThan(root.get(JpaObject_.createTime), DateTools.addDay(new Date(), -days));
cq.select(root.get(Recycle_.id)).where(p);
return em.createQuery(cq).getResultList();
}
}
}
package com.x.organization.assemble.control.jaxrs.unit;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.StringUtils;
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.annotation.FieldDescribe;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.gson.GsonPropertyObject;
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.organization.assemble.control.Business;
import com.x.organization.core.entity.Person;
import com.x.organization.core.entity.Unit;
import com.x.organization.core.entity.Unit_;
import io.swagger.v3.oas.annotations.media.Schema;
class ActionListWithController extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionListWithController.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<List<Wo>> result = new ActionResult<>();
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), StringUtils.join(wi.getPersonList(), ","));
Optional<?> optional = CacheManager.get(business.cache(), cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>) optional.get());
} else {
List<Wo> wos = this.list(business, wi.getPersonList());
CacheManager.put(business.cache(), cacheKey, wos);
result.setData(wos);
}
return result;
}
}
public static class Wi extends GsonPropertyObject {
@Schema(description = "指定人员.")
@FieldDescribe("指定人员.")
private List<String> personList = new ArrayList<>();
public List<String> getPersonList() {
return personList;
}
public void setPersonList(List<String> personList) {
this.personList = personList;
}
}
public static class Wo extends WoAbstractUnit {
static WrapCopier<Unit, Wo> copier = WrapCopierFactory.wo(Unit.class, Wo.class, null,
JpaObject.FieldsInvisible);
}
private List<Wo> list(Business business, List<String> people) throws Exception {
List<Person> list = business.person().pick(people);
EntityManager em = business.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
List<String> ids = ListTools.extractField(list, JpaObject.id_FIELDNAME, String.class, true, true);
if (ids.isEmpty()) {
return new ArrayList<>();
}
Predicate p = root.get(Unit_.controllerList)
.in(ids);
List<Unit> os = em.createQuery(cq.select(root).where(p)).getResultList();
List<Wo> wos = Wo.copier.copy(os);
wos = business.unit().sort(wos);
return wos;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册