From 133280bc63ab5d7e6842f5f3c649aab6400ad985 Mon Sep 17 00:00:00 2001 From: yaoq Date: Tue, 6 Sep 2022 19:22:34 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=9D=83=E9=99=90?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java | 8 +++++--- .../cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java index 5d9ed9b..bd3a212 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java @@ -56,9 +56,10 @@ public class RoleHandler { if (role_id <= 0) return R.error("未指定角色!"); SwMap formData = data.readMap("form"); Set set = formData.readLongSet("menu"); - if (PubUtil.isEmpty(set)) return R.error("未选择菜单!"); + //if (PubUtil.isEmpty(set)) return R.error("未选择菜单!"); Role role = RoleCache.getInstance().get(role_id); RoleRightContent rc = new RoleRightContent(role.getPrivilege()); + rc.resetItem(); for (Long menu_id : set) { MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), menu_id); RoleRight right = rc.getRoleRight(item.getId()); @@ -66,8 +67,8 @@ public class RoleHandler { right = new RoleRight(); right.setId(item.getId()); right.setMenuId(item.getMenu()); - right.setMenu(1); } + right.setMenu(1); rc.saveItem(right); } if (mp_id > 0) { @@ -81,7 +82,8 @@ public class RoleHandler { } right.setFunc(formData.readStringSet("func")); right.setData(formData.readListMap("data")); - right.setField(MenuCache.getInstance().get(item.getMenu()).getRightSet(SwEnum.MenuRightType.FIELD.value), formData.readStringSet("write"), formData.readStringSet("read")); + if (item.getMenu() > 0L) + right.setField(MenuCache.getInstance().get(item.getMenu()).getRightSet(SwEnum.MenuRightType.FIELD.value), formData.readStringSet("write"), formData.readStringSet("read")); rc.saveItem(right); } role.setPrivilege(rc.toContentStr()); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java index 255d909..88faa42 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java @@ -31,6 +31,12 @@ public class RoleRightContent { RoleRight right = new RoleRight(); } + public void resetItem() { + map.values().forEach(roleRight -> { + roleRight.setMenu(0); + }); + } + // 保存节点 public void saveItem(RoleRight item) { map.put(item.getId(), item); From 5bd9e23df546865fb8a37b09366bb768f4fcbc17 Mon Sep 17 00:00:00 2001 From: zhenggm Date: Tue, 6 Sep 2022 20:08:33 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=83=A8=E5=88=86Util=EF=BC=8C=E5=8E=9FPubUtil?= =?UTF-8?q?=E5=88=86=E6=95=A3=E5=88=B0CommUtil=E5=92=8CStringUtil=E3=80=81?= =?UTF-8?q?NumberUtil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bpm/spring/controller/AttachController.java | 20 +- .../bpm/spring/file/attach/AttachFileWork.java | 4 +- .../bpm/spring/file/attach/AttachFtpWork.java | 4 +- .../bpm/spring/file/attach/AttachHelper.java | 14 +- .../system/bpm/spring/file/attach/AttachUtil.java | 4 +- .../java/cc/smtweb/system/bpm/util/UtilFile.java | 6 +- .../java/cc/smtweb/system/bpm/util/UtilLogger.java | 6 +- .../java/cc/smtweb/system/bpm/util/UtilMath.java | 12 +- .../java/cc/smtweb/system/bpm/util/UtilString.java | 24 +- .../smtweb/system/bpm/util/ftp/FtpTaskManager.java | 6 +- .../cc/smtweb/system/bpm/util/ftp/FtpUtil.java | 4 +- .../cc/smtweb/system/bpm/util/ftp/SFtpUtil.java | 9 +- .../bpm/web/design/form/ModelFormService.java | 1 - .../web/design/preview/PreviewMenuTreeService.java | 8 +- .../bpm/web/engine/dynPage/DynPageHelper.java | 7 +- .../system/bpm/web/engine/flow/FlowInstance.java | 2 - .../system/bpm/web/sys/dev/ComboHandler.java | 4 +- .../system/bpm/web/sys/dev/EnumComboService.java | 4 +- .../smtweb/system/bpm/web/sys/user/menu/Menu.java | 8 +- .../system/bpm/web/sys/user/menu/MenuHandler.java | 22 +- .../bpm/web/sys/user/menuPlan/MenuPlanContent.java | 14 +- .../bpm/web/sys/user/menuPlan/MenuPlanHandler.java | 6 +- .../system/bpm/web/sys/user/party/PartyCache.java | 4 +- .../system/bpm/web/sys/user/role/RoleCache.java | 4 +- .../system/bpm/web/sys/user/role/RoleHandler.java | 10 +- .../bpm/web/sys/user/role/RoleRightContent.java | 13 +- .../system/bpm/web/sys/user/user/UserHandler.java | 10 +- .../bpm/web/sys/user/user/UserPartyCache.java | 8 +- .../bpm/web/sys/user/user/UserRoleCache.java | 14 +- .../smtweb/framework/core/cache/AbstractCache.java | 3 +- .../framework/core/cache/AbstractEntityCache.java | 4 +- .../cc/smtweb/framework/core/common/SwEnum.java | 1 - .../cc/smtweb/framework/core/db/EntityHelper.java | 3 +- .../core/db/cache/ModelDatabaseCache.java | 2 +- .../framework/core/db/cache/ModelTableCache.java | 2 +- .../cc/smtweb/framework/core/util/CommUtil.java | 20 +- .../cc/smtweb/framework/core/util/DateUtil.java | 60 +- .../cc/smtweb/framework/core/util/EmojiFilter.java | 2 +- .../framework/core/util/ListSQLParaHelper.java | 781 --------------------- .../cc/smtweb/framework/core/util/MapUtil.java | 2 +- .../cc/smtweb/framework/core/util/MathUtil.java | 464 ------------ .../cc/smtweb/framework/core/util/PubUtil.java | 780 -------------------- .../cc/smtweb/framework/core/util/SqlUtil.java | 769 +++++++++++++++++++- .../cc/smtweb/framework/core/util/StringUtil.java | 52 +- .../cc/smtweb/framework/core/util/XmlUtil.java | 14 +- 45 files changed, 1017 insertions(+), 2194 deletions(-) delete mode 100644 smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/ListSQLParaHelper.java delete mode 100644 smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MathUtil.java delete mode 100644 smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/PubUtil.java diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java index 7acb3eb..732f75f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java @@ -4,7 +4,7 @@ import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.util.Consts; import cc.smtweb.framework.core.util.DateUtil; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.spring.config.FileConfigProperties; import cc.smtweb.system.bpm.spring.file.attach.AttachHelper; import cc.smtweb.system.bpm.spring.file.attach.AttachUtil; @@ -96,7 +96,7 @@ public class AttachController { } attach.setPath(path);//附件路径 attach.setPartyId(-1l); - attach.setTime(PubUtil.getLastTime()); + attach.setTime(DateUtil.nowDateTimeLong()); attach.setUserId(-1l); attach.setIsTemp("true".equals(attachIsTemp) ? 1 : 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 // 上传文件名 @@ -104,7 +104,7 @@ public class AttachController { if (i >= 0) { attach.setSuffix(file.getOriginalFilename().substring(i)); } - if (PubUtil.isEmptyStr(attachName)) { + if (StringUtil.isEmpty(attachName)) { attachName = file.getOriginalFilename(); } else { @@ -116,7 +116,7 @@ public class AttachController { // 上传文件域对象 File upload = new File(attachHelper.getAttachTmpPath() + attach.getId() + attach.getSuffix()); attach.setSize((long) FileCopyUtils.copy(file.getInputStream(), new BufferedOutputStream(new FileOutputStream(upload)))); - if (PubUtil.isEmpty(savePath)) { + if (StringUtil.isEmpty(savePath)) { localSaveAttach(attach, upload); } else {//复制到指定目录 String filePath; @@ -176,7 +176,7 @@ public class AttachController { // 上传文件类型 //String uploadContentType = file.getContentType(); AttachInfo attach = null; - boolean isNew = PubUtil.isEmpty(attachId+""); + boolean isNew = StringUtil.isEmpty(attachId+""); if (isNew) { attach = new AttachInfo(); } @@ -188,7 +188,7 @@ public class AttachController { } else isNew = attach.isNew(); } attach.setId(attachId); - if (PubUtil.isEmpty(attachId+"")) attach.setId(dbEngine.nextId()); + if (StringUtil.isEmpty(attachId+"")) attach.setId(dbEngine.nextId()); attach.setType(type);//附件类别 if(null !=ownerId) { @@ -196,7 +196,7 @@ public class AttachController { } attach.setPath(path);//附件路径 attach.setPartyId(-1l); - attach.setTime(PubUtil.getLastTime()); + attach.setTime(DateUtil.nowDateTimeLong()); attach.setUserId(-1l); attach.setIsTemp("true".equals(attachIsTemp) ? 1 : 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 attach.setTime(DateUtil.nowDateTimeLong()); @@ -219,7 +219,7 @@ public class AttachController { File upload = new File(attachHelper.getAttachTmpPath() + attach.getId() + attach.getSuffix()); FileUtils.writeByteArrayToFile(upload, byt); attach.setSize(upload.length()); - if (PubUtil.isEmpty(savePath)) { + if (StringUtil.isEmpty(savePath)) { localSaveAttach(attach, upload); } else {//复制到指定目录 String filePath; @@ -239,7 +239,7 @@ public class AttachController { public R copyupload(HttpServletRequest request) throws Exception { String type=request.getParameter("type"); String attachId=request.getParameter("attachId"); - if(PubUtil.isEmpty(attachId)){ + if(StringUtil.isEmpty(attachId)){ return R.success(""); } AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); @@ -259,7 +259,7 @@ public class AttachController { attach.setType(type);//附件类别 attach.setOwnerId(-1l);//附件拥有者id attach.setPartyId(-1l); - attach.setTime(PubUtil.getLastTime()); + attach.setTime(DateUtil.nowDateTimeLong()); attach.setUserId(-1l); attach.setName(attach.getId()+attach.getSuffix()); // 上传文件域对象 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFileWork.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFileWork.java index 5b92dd6..1fe6a88 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFileWork.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFileWork.java @@ -1,6 +1,6 @@ package cc.smtweb.system.bpm.spring.file.attach; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.spring.config.FileConfigProperties; import cc.smtweb.system.bpm.util.UtilDownloadFile; import cc.smtweb.system.bpm.util.UtilFile; @@ -21,7 +21,7 @@ public final class AttachFileWork implements IAttachWorkIntf { private FileConfigProperties properties; private String getPath(String remoteFolderPath) { String path =properties.getAttachPath(); - if (PubUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) + if (StringUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) path = path + "/" + remoteFolderPath; else path = path + remoteFolderPath; path = path.replaceAll("-",""); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFtpWork.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFtpWork.java index abc71cd..5437cb1 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFtpWork.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFtpWork.java @@ -1,6 +1,6 @@ package cc.smtweb.system.bpm.spring.file.attach; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.spring.config.FileConfigProperties; import cc.smtweb.system.bpm.util.UtilDownloadFile; import cc.smtweb.system.bpm.util.UtilFile; @@ -33,7 +33,7 @@ public final class AttachFtpWork implements IAttachWorkIntf { private FileConfigProperties properties; private String getPath(String remoteFolderPath) { String path = properties.getAttachPath(); - if (PubUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) + if (StringUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) path = path + "/" + remoteFolderPath; else path = path + remoteFolderPath; path = path.replaceAll("-", ""); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java index 387cb9d..d1b5a8d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java @@ -1,7 +1,9 @@ package cc.smtweb.system.bpm.spring.file.attach; import cc.smtweb.framework.core.db.DbEngine; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; +import cc.smtweb.framework.core.util.DateUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.spring.config.FileConfigProperties; import cc.smtweb.system.bpm.util.UtilFile; import cc.smtweb.system.bpm.util.UtilMath; @@ -42,7 +44,7 @@ public final class AttachHelper { //删除ftp服务器的文件 public boolean deleteOneAttach(String attachId) throws Exception { - if (PubUtil.isEmpty(attachId)) return true; + if (StringUtil.isEmpty(attachId)) return true; AttachInfo attachInfo = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); if(null == attachInfo){ return true; @@ -93,8 +95,8 @@ public final class AttachHelper { //批量删除 public boolean deleteAttachList(List attachIdList) throws Exception { - if (PubUtil.isEmpty(attachIdList)) return false; - dbEngine.update("delete from "+AttachInfo.ENTITY_NAME+" where attach_id in(" + PubUtil.getSqlInIds(attachIdList) + ")"); + if (CommUtil.isEmpty(attachIdList)) return false; + dbEngine.update("delete from "+AttachInfo.ENTITY_NAME+" where attach_id in(" + CommUtil.getSqlInStr(attachIdList) + ")"); return true; } @@ -201,7 +203,7 @@ public final class AttachHelper { */ public List getAttachsFromFtp(final List attachIds, final String ownerType) throws Exception { List paras = new ArrayList(); - if (PubUtil.isNotEmpty(attachIds)) { + if (!CommUtil.isEmpty(attachIds)) { StringBuilder sb = new StringBuilder(128); for(int i=0;i files = sftp.ls(filename); sftp.cd(now); - return PubUtil.isNotEmpty(files); + return !CommUtil.isEmpty(files); } catch (SftpException e) { logError("判断文件是否存在失败", e); return false; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java index d99a42b..1574fbd 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormService.java @@ -11,7 +11,6 @@ import cc.smtweb.framework.core.db.vo.ModelField; import cc.smtweb.framework.core.db.vo.ModelTable; import cc.smtweb.framework.core.mvc.service.AbstractCompService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; -import cc.smtweb.framework.core.mvc.service.DefaultDelHandler; import cc.smtweb.framework.core.mvc.service.DefaultListHandler; import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.framework.core.util.SqlUtil; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java index 6bcd142..2774213 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java @@ -9,7 +9,7 @@ import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.db.vo.ModelCatalog; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.session.UserSession; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.util.TreeDataUtil; import cc.smtweb.system.bpm.web.design.db.ModelCatalogCache; @@ -34,7 +34,7 @@ public class PreviewMenuTreeService { String prj_id = ModelProjectCache.getInstance().getIdByModule(module); if(!SwConsts.SysParam.SYS_DEBUG){ List menuVOList = buildMenu(prj_id, module, us); - if (PubUtil.isNotEmpty(menuVOList)) { + if (!CommUtil.isEmpty(menuVOList)) { return R.success(menuVOList); } } @@ -79,7 +79,7 @@ public class PreviewMenuTreeService { public List buildMenu(String prj_id, String module, UserSession us) { Set set = MenuPlanCache.getInstance().getByP(prj_id); - if (PubUtil.isEmpty(set)) { + if (CommUtil.isEmpty(set)) { return new ArrayList<>(); } MenuPlan menuPlan = set.iterator().next(); @@ -107,7 +107,7 @@ public class PreviewMenuTreeService { menu.setPath(MenuCache.getInstance().getPath(mp.getMenu())); menu.setParentId(parent_id); List child = new ArrayList<>(); - if (PubUtil.isNotEmpty(mp.getChildren())) { + if (!CommUtil.isEmpty(mp.getChildren())) { for (MenuPlanItem cmp : mp.getChildren()) { List m = buildMenu(menu.getId(), cmp); if (m == null) continue; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java index 634a62b..b4cdb67 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java @@ -14,10 +14,9 @@ import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.mvc.service.SqlNamedPara; import cc.smtweb.framework.core.util.MapUtil; import cc.smtweb.framework.core.util.NumberUtil; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.design.form.define.*; import org.apache.commons.lang3.StringUtils; -import reactor.util.annotation.Nullable; import java.util.HashMap; import java.util.HashSet; @@ -321,13 +320,13 @@ public class DynPageHelper { }); mapBuilder.put(SwEnum.OptType.IN.value, (opt, field, name, value, args) -> { - if (PubUtil.isEmpty(value.toString())) return ""; + if (StringUtil.isEmpty(value.toString())) return ""; args.put(name, value); return field + " in (:" + name + ") "; }); mapBuilder.put(SwEnum.OptType.NOT_IN.value, (opt, field, name, value, args) -> { - if (PubUtil.isEmpty(value.toString())) return ""; + if (StringUtil.isEmpty(value.toString())) return ""; args.put(name, value); return field + " not in (:" + name + ") "; }); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java index 13f1bc1..6f95a8e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java @@ -10,7 +10,6 @@ import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.DateUtil; -import cc.smtweb.framework.core.util.MathUtil; import cc.smtweb.framework.core.util.NumberUtil; import cc.smtweb.system.bpm.web.design.flow.FlowConst; import cc.smtweb.system.bpm.web.design.flow.ModelProc; @@ -18,7 +17,6 @@ import cc.smtweb.system.bpm.web.design.flow.ModelProcHelper; import cc.smtweb.system.bpm.web.design.flow.define.Activity; import cc.smtweb.system.bpm.web.design.flow.define.ProcInfo; import cc.smtweb.system.bpm.web.engine.flow.entity.*; -import cc.smtweb.system.bpm.web.sys.base.billFlow.BillFlow; import cc.smtweb.system.bpm.web.sys.user.dept.Dept; import cc.smtweb.system.bpm.web.sys.user.dept.DeptCache; import cc.smtweb.system.bpm.web.sys.user.party.Party; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/ComboHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/ComboHandler.java index ad27731..430097c 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/ComboHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/ComboHandler.java @@ -5,7 +5,7 @@ import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.mvc.service.SqlPara; import cc.smtweb.framework.core.mvc.service.SwListData; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; import cc.smtweb.system.bpm.web.design.form.ModelForm; import cc.smtweb.system.bpm.web.design.form.ModelFormCache; @@ -67,7 +67,7 @@ public class ComboHandler { @Override public SwListData buildListData() { String cls = params.readMap("filter").readString("cls"); - if (PubUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); + if (StringUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); List list = new ArrayList<>(); try { AbstractEnum e; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java index be5b509..2574e11 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java @@ -8,7 +8,7 @@ import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.framework.core.mvc.service.SwListData; import cc.smtweb.framework.core.session.UserSession; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean; import org.springframework.util.Assert; @@ -37,7 +37,7 @@ public class EnumComboService extends DynPageService { } private SwListData buildListData(String cls) { - if (PubUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); + if (StringUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); List list = new ArrayList<>(); try { Class tempClass ; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/Menu.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/Menu.java index ba2dd4f..48e11ad 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/Menu.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/Menu.java @@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.menu; import cc.smtweb.framework.core.annotation.SwTable; import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.util.JsonUtil; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.StringUtil; import java.util.ArrayList; import java.util.HashSet; @@ -164,18 +164,18 @@ public class Menu extends DefaultEntity { public final String getPath() { - if (PubUtil.isEmpty(getContent())) return ""; + if (StringUtil.isEmpty(getContent())) return ""; return JsonUtil.parseMap(getContent()).get("path").toString(); } public final String getPageId() { - if (PubUtil.isEmpty(getContent())) return ""; + if (StringUtil.isEmpty(getContent())) return ""; return JsonUtil.parseMap(getContent()).get("pageId").toString(); } public final List getRightList(String type) { List set = new ArrayList<>(); - if (PubUtil.isEmpty(getRight())) return set; + if (StringUtil.isEmpty(getRight())) return set; return (List) JsonUtil.parseMap(getRight()).get(type); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuHandler.java index 65093cb..d905a1b 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuHandler.java @@ -5,8 +5,8 @@ import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.db.vo.ModelCatalog; import cc.smtweb.framework.core.db.vo.ModelProject; +import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.JsonUtil; -import cc.smtweb.framework.core.util.PubUtil; import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.design.db.ModelCatalogTreeHelper; import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; @@ -49,16 +49,16 @@ public class MenuHandler { super.afterLoadBean(dataset, bean); Menu menu = new Menu(); menu.setData(bean); - if (PubUtil.isNotEmptyStr(menu.getContent())) { + if (StringUtil.isNotEmpty(menu.getContent())) { Map urlMap = JsonUtil.parseMap(menu.getContent()); bean.put("sm_page_id", urlMap.get("pageId")); bean.put("sm_page_url", urlMap.get("path")); } - if (PubUtil.isNotEmptyStr(menu.getRight())) { + if (StringUtil.isNotEmpty(menu.getRight())) { Map> rightMap = JsonUtil.parseMap(menu.getRight()); - bean.put("sm_right_data", PubUtil.getSqlInIds(rightMap.get("data"))); - bean.put("sm_right_func", PubUtil.getSqlInIds(rightMap.get("func"))); - bean.put("sm_right_field", PubUtil.getSqlInIds(rightMap.get("field"))); + bean.put("sm_right_data", CommUtil.getSqlInStr(rightMap.get("data"))); + bean.put("sm_right_func", CommUtil.getSqlInStr(rightMap.get("func"))); + bean.put("sm_right_field", CommUtil.getSqlInStr(rightMap.get("field"))); } } } @@ -117,7 +117,7 @@ public class MenuHandler { ModelProject mp = ModelProjectCache.getInstance().get(id); if (mp != null) { List mcList = mcTreeHelper.getChildren(0, mp.getId(), true, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); - if (PubUtil.isEmpty(mcList)) return; + if (CommUtil.isEmpty(mcList)) return; for (ModelCatalog mc : mcList) { SwMap row = new SwMap(); row.put("mc_id", mc.getId()); @@ -131,7 +131,7 @@ public class MenuHandler { return; } List mcList = mcTreeHelper.getChildren(id, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); - if (PubUtil.isEmpty(mcList)) return; + if (CommUtil.isEmpty(mcList)) return; for (ModelCatalog mc : mcList) { SwMap row = new SwMap(); row.put("mc_id", mc.getId()); @@ -175,10 +175,10 @@ public class MenuHandler { private List buildTreeData(long prj_id, long id) { List list = new ArrayList<>(); List mcList = mcTreeHelper.getChildren(id, prj_id, false, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); - if (PubUtil.isNotEmpty(mcList)) { + if (!CommUtil.isEmpty(mcList)) { for (ModelCatalog mc : mcList) { List children = buildTreeData(prj_id, mc.getId()); - if (PubUtil.isNotEmpty(children)) { + if (!CommUtil.isEmpty(children)) { MenuNode menuNode = new MenuNode(); menuNode.setMenu(mc.getId()); menuNode.setLabel(mc.getName()); @@ -186,7 +186,7 @@ public class MenuHandler { list.add(menuNode.getData()); } Set menus = MenuCache.getInstance().getByM(String.valueOf(mc.getId())); - if (PubUtil.isNotEmpty(menus)) { + if (!CommUtil.isEmpty(menus)) { for (Menu m : menus) { MenuNode menu = new MenuNode(); menu.setMenu(m.getId()); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java index ddfe910..b02eb27 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java @@ -2,8 +2,8 @@ package cc.smtweb.system.bpm.web.sys.user.menuPlan; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.exception.BizException; +import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.JsonUtil; -import cc.smtweb.framework.core.util.PubUtil; import java.util.ArrayList; import java.util.Collections; @@ -87,7 +87,7 @@ public class MenuPlanContent { removeById(id, list); } else { List children = parent.getChildren(); - if (PubUtil.isNotEmpty(children)) { + if (!CommUtil.isEmpty(children)) { removeById(id, children); } } @@ -123,7 +123,7 @@ public class MenuPlanContent { } private MenuPlanItem findById(long id, List itemList) { - if (PubUtil.isEmpty(itemList)) { + if (CommUtil.isEmpty(itemList)) { return null; } for (MenuPlanItem item : itemList) { @@ -132,7 +132,7 @@ public class MenuPlanContent { } } for (MenuPlanItem item : itemList) { - if(PubUtil.isNotEmpty(item.getChildren())){ + if(!CommUtil.isEmpty(item.getChildren())){ MenuPlanItem rt = findById(id,item.getChildren()); if(rt!=null){ return rt; @@ -143,17 +143,17 @@ public class MenuPlanContent { } private MenuPlanItem findParentById(long id, List itemList) { - if (PubUtil.isEmpty(itemList)) { + if (CommUtil.isEmpty(itemList)) { return null; } for (MenuPlanItem item : itemList) { List children = item.getChildren(); - if (PubUtil.isNotEmpty(children)) { + if (!CommUtil.isEmpty(children)) { for (MenuPlanItem i : children) { if (i.getId() == id) { return item; } - if (PubUtil.isNotEmpty(i.getChildren())) { + if (!CommUtil.isEmpty(i.getChildren())) { return findParentById(id, i.getChildren()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanHandler.java index b3090ec..ac7e8b3 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanHandler.java @@ -7,8 +7,8 @@ import cc.smtweb.framework.core.db.jdbc.IDbWorker; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.framework.core.mvc.service.SwListData; +import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.JsonUtil; -import cc.smtweb.framework.core.util.PubUtil; import cc.smtweb.system.bpm.web.design.form.define.PageDataset; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler; @@ -136,7 +136,7 @@ public class MenuPlanHandler { List children = getChildren(); List list = new ArrayList<>(); int total = 0; - if (PubUtil.isNotEmpty(children)) { + if (!CommUtil.isEmpty(children)) { total = children.size(); for (MenuPlanItem bean : children) { SwMap map = bean.getData(); @@ -219,7 +219,7 @@ public class MenuPlanHandler { boolean exc_menu = params.readBool("exc_menu"); List list = new ArrayList<>(); List temList = menuPlanContent.getChildren(id); - if (PubUtil.isNotEmpty(temList)) { + if (!CommUtil.isEmpty(temList)) { temList.forEach(bean -> { if (exc_menu && bean.getMenu() > 0) { return; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/party/PartyCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/party/PartyCache.java index 8895a35..0e5f3f3 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/party/PartyCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/party/PartyCache.java @@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.party; import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; import java.util.Set; @@ -46,6 +46,6 @@ public class PartyCache extends AbstractEntityCache { //是否末级 public final boolean isLeaf(Long key) { Set children = getChildren(key); - return PubUtil.isEmpty(children); + return CommUtil.isEmpty(children); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleCache.java index 0bc88e4..16ad7ca 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleCache.java @@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.role; import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; import java.util.HashSet; import java.util.Set; @@ -36,6 +36,6 @@ public class RoleCache extends AbstractEntityCache { key.forEach(k -> { names.add(get(k).getName()); }); - return PubUtil.getSqlInIds(names); + return CommUtil.getSqlInStr(names); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java index bd3a212..f85ff7d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java @@ -6,7 +6,8 @@ import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.SwListData; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.design.form.ModelForm; import cc.smtweb.system.bpm.web.design.form.ModelFormCache; import cc.smtweb.system.bpm.web.design.form.define.PageDataset; @@ -56,10 +57,9 @@ public class RoleHandler { if (role_id <= 0) return R.error("未指定角色!"); SwMap formData = data.readMap("form"); Set set = formData.readLongSet("menu"); - //if (PubUtil.isEmpty(set)) return R.error("未选择菜单!"); + //if (CommUtil.isEmpty(set)) return R.error("未选择菜单!"); Role role = RoleCache.getInstance().get(role_id); RoleRightContent rc = new RoleRightContent(role.getPrivilege()); - rc.resetItem(); for (Long menu_id : set) { MenuPlanItem item = MenuPlanCache.getInstance().getById(role.getSmpId(), menu_id); RoleRight right = rc.getRoleRight(item.getId()); @@ -203,7 +203,7 @@ public class RoleHandler { Menu menu = MenuCache.getInstance().get(item.getMenu()); if (menu == null) return SwListData.create(list, 0); for (String f : menu.getRightSet(SwEnum.MenuRightType.FUNC.value)) { - if (PubUtil.isEmpty(f)) continue; + if (StringUtil.isEmpty(f)) continue; SwMap row = new SwMap(); row.put("f_id", f); row.put("f_name", SwEnum.MenuFuncRight.instance.getName(f)); @@ -239,7 +239,7 @@ public class RoleHandler { Map data = rc.getDataRight(item.getId()); for (String f : menu.getRightSet(SwEnum.MenuRightType.DATA.value)) { - if (PubUtil.isEmpty(f)) continue; + if (StringUtil.isEmpty(f)) continue; SwMap row = new SwMap(); row.put("key", f); row.put("key_text", DataRightDefineCache.getInstance().get(f).getName()); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java index 88faa42..4541047 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleRightContent.java @@ -2,8 +2,9 @@ package cc.smtweb.system.bpm.web.sys.user.role; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.exception.BizException; +import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.JsonUtil; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.StringUtil; import java.util.*; @@ -18,10 +19,10 @@ public class RoleRightContent { public RoleRightContent(String content) { List tempList = JsonUtil.parseList(content, RoleRight.class); - if (PubUtil.isNotEmpty(content) && tempList == null) { + if (StringUtil.isNotEmpty(content) && tempList == null) { throw new BizException("角色权限转换失败!"); } - if (PubUtil.isEmpty(tempList)) return; + if (CommUtil.isEmpty(tempList)) return; tempList.forEach(bean -> { map.put(bean.getId(), bean); }); @@ -60,7 +61,7 @@ public class RoleRightContent { public String getFuncRight(long key) { RoleRight right = getRoleRight(key); if (right == null) return ""; - return PubUtil.getSqlInIds(right.getRightFunc()); + return CommUtil.getSqlInStr(right.getRightFunc()); } public String getMenuRight() { @@ -69,7 +70,7 @@ public class RoleRightContent { map.values().forEach(roleRight -> { if (roleRight.getMenu() == 1) menus.add(roleRight.getId() + ""); }); - return PubUtil.getSqlInIds(menus); + return CommUtil.getSqlInStr(menus); } public String getFieldRight(long key, int type) { @@ -81,7 +82,7 @@ public class RoleRightContent { cache.forEach((k, v) -> { if (v == type) fields.add(k); }); - return PubUtil.getSqlInIds(fields); + return CommUtil.getSqlInStr(fields); } public Map getDataRight(long key) { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserHandler.java index 2d4dab0..f3332c0 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserHandler.java @@ -10,7 +10,9 @@ import cc.smtweb.framework.core.db.jdbc.IDbWorker; import cc.smtweb.framework.core.db.vo.ModelTable; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.AbstractHandler; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; +import cc.smtweb.framework.core.util.DateUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.design.form.define.PageDataset; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageDelHandler; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler; @@ -60,7 +62,7 @@ public class UserHandler { roleList = new ArrayList<>(); partyList = new ArrayList<>(); List> rows = data.readListMap("partyData"); - if (PubUtil.isEmpty(rows)) throw new BizException("用户所属机构为空"); + if (CommUtil.isEmpty(rows)) throw new BizException("用户所属机构为空"); for (Map row : rows) { UserParty userParty = new UserParty(); userParty.init(); @@ -70,7 +72,7 @@ public class UserHandler { partyList.add(userParty); String roles = row.get("sup_roles").toString(); - if (PubUtil.isEmpty(roles)) throw new BizException("用户机构所属角色为空"); + if (StringUtil.isEmpty(roles)) throw new BizException("用户机构所属角色为空"); for (String role_id : roles.split(",")) { UserRole userRole = new UserRole(); userRole.init(); @@ -97,7 +99,7 @@ public class UserHandler { UserStatuCache.getInstance().put(userStatu); } if (bean.isNew()) { - ((User) bean).setCreate(PubUtil.getLastTime()); + ((User) bean).setCreate(DateUtil.nowDateTimeLong()); ((User) bean).setPwd(LoginHelper.encodePwd(bean.getEntityId(), SwConsts.DEF_PWD)); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserPartyCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserPartyCache.java index cdb4d6d..c73faff 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserPartyCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserPartyCache.java @@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.user; import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; import java.util.HashSet; import java.util.Set; @@ -46,7 +46,7 @@ public class UserPartyCache extends AbstractEntityCache { public final Set getIdByUser(Long key) { Set ids = new HashSet<>(); Set set = getByUser(String.valueOf(key)); - if (PubUtil.isEmpty(set)) return ids; + if (CommUtil.isEmpty(set)) return ids; set.forEach(bean -> { ids.add(bean.getEntityId()); }); @@ -57,7 +57,7 @@ public class UserPartyCache extends AbstractEntityCache { public final Set getUserByDept(Long key) { Set ids = new HashSet<>(); Set set = getByDept(String.valueOf(key)); - if (PubUtil.isEmpty(set)) return ids; + if (CommUtil.isEmpty(set)) return ids; set.forEach(bean -> { ids.add(bean.getUserId()); }); @@ -67,7 +67,7 @@ public class UserPartyCache extends AbstractEntityCache { public final Set getUserByParty(Long key) { Set ids = new HashSet<>(); Set set = getByParty(String.valueOf(key)); - if (PubUtil.isEmpty(set)) return ids; + if (CommUtil.isEmpty(set)) return ids; set.forEach(bean -> { ids.add(bean.getUserId()); }); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserRoleCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserRoleCache.java index 00262cf..c09c20b 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserRoleCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserRoleCache.java @@ -3,7 +3,7 @@ package cc.smtweb.system.bpm.web.sys.user.user; import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; import java.util.HashSet; import java.util.Set; @@ -34,7 +34,7 @@ public class UserRoleCache extends AbstractEntityCache { public final Set getByParty(Long key) { Set ids = new HashSet<>(); Set set = getByParty(String.valueOf(key)); - if (PubUtil.isEmpty(set)) return ids; + if (CommUtil.isEmpty(set)) return ids; set.forEach(bean -> { ids.add(bean.getEntityId()); }); @@ -50,7 +50,7 @@ public class UserRoleCache extends AbstractEntityCache { public final Set getRoleByParty(Long key) { Set ids = new HashSet<>(); Set set = getByParty(String.valueOf(key)); - if (PubUtil.isEmpty(set)) return ids; + if (CommUtil.isEmpty(set)) return ids; set.forEach(bean -> { ids.add(bean.getRoleId()); }); @@ -75,11 +75,11 @@ public class UserRoleCache extends AbstractEntityCache { public final Set getRoleIdByUP(Long user_id, Long party_id) { Set ids = new HashSet<>(); Set upSet = UserPartyCache.getInstance().getListByKey(UserPartyCache.mk_u, String.valueOf(user_id)); - if (PubUtil.isEmpty(upSet)) return ids; + if (CommUtil.isEmpty(upSet)) return ids; upSet.forEach(up -> { if (up.getPartyId() != party_id) return; Set urSet = getListByKey(mk_s, String.valueOf(up.getId())); - if (PubUtil.isEmpty(urSet)) return; + if (CommUtil.isEmpty(urSet)) return; for (UserRole userRole : urSet) { ids.add(userRole.getRoleId()); } @@ -94,10 +94,10 @@ public class UserRoleCache extends AbstractEntityCache { public final Set getIdByUser(String key) { Set ids = new HashSet<>(); Set upSet = UserPartyCache.getInstance().getListIdByKey(UserPartyCache.mk_u, key); - if (PubUtil.isEmpty(upSet)) return ids; + if (CommUtil.isEmpty(upSet)) return ids; upSet.forEach(k -> { Set urSet = getListByKey(mk_s, String.valueOf(k)); - if (PubUtil.isEmpty(urSet)) return; + if (CommUtil.isEmpty(urSet)) return; for (UserRole userRole : urSet) { ids.add(userRole.getEntityId()); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java index 09df504..c332812 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/AbstractCache.java @@ -5,7 +5,6 @@ import cc.smtweb.framework.core.cache.redis.RedisBroadcastEvent; import cc.smtweb.framework.core.cache.redis.RedisManager; import cc.smtweb.framework.core.common.SwConsts; import cc.smtweb.framework.core.util.CommUtil; -import cc.smtweb.framework.core.util.PubUtil; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.github.benmanes.caffeine.cache.Scheduler; @@ -452,7 +451,7 @@ public abstract class AbstractCache implements ISwCache< } public void removeList(Collection key) { - if (PubUtil.isEmpty(key)) return; + if (CommUtil.isEmpty(key)) return; key.forEach(k -> { remove(k); }); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/AbstractEntityCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/AbstractEntityCache.java index aa464f4..74caf65 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/AbstractEntityCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/AbstractEntityCache.java @@ -4,7 +4,7 @@ import cc.smtweb.framework.core.common.SwConsts; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.db.EntityDao; import cc.smtweb.framework.core.db.impl.DefaultEntity; -import cc.smtweb.framework.core.util.PubUtil; +import cc.smtweb.framework.core.util.CommUtil; import java.util.HashSet; import java.util.List; @@ -59,7 +59,7 @@ public class AbstractEntityCache extends AbstractCache< public final Set getListIdByKey(String rk, String key) { Set idSet = new HashSet<>(); Set beanSet = getListByKey(rk, key); - if (PubUtil.isEmpty(beanSet)) return idSet; + if (CommUtil.isEmpty(beanSet)) return idSet; beanSet.forEach(bean -> { idSet.add(bean.getEntityId()); }); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java index 8903bac..c1b523f 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java @@ -1,7 +1,6 @@ package cc.smtweb.framework.core.common; import cc.smtweb.framework.core.util.NumberUtil; -import cc.smtweb.framework.core.util.PubUtil; import org.apache.commons.lang3.StringUtils; import java.sql.Types; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java index 2d989e9..f785cbd 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java @@ -14,7 +14,6 @@ import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.util.DateUtil; import cc.smtweb.framework.core.util.NumberUtil; -import cc.smtweb.framework.core.util.PubUtil; import cc.smtweb.framework.core.util.StringUtil; import org.apache.commons.lang3.StringUtils; @@ -64,7 +63,7 @@ public class EntityHelper { String value = v != null ? v.toString() : ""; final ModelField field = modelEntity.findField(fname); if (field != null) { - if (PubUtil.isEmpty(value) && PubUtil.isNotEmpty(field.getDefaultValue())) { + if (StringUtil.isEmpty(value) && StringUtil.isNotEmpty(field.getDefaultValue())) { value = field.getDefaultValue(); } args[i++] = SwEnum.DataType.getDataValue(field.getDataType(), value); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelDatabaseCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelDatabaseCache.java index 8e5a382..0cc77a3 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelDatabaseCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelDatabaseCache.java @@ -38,7 +38,7 @@ public class ModelDatabaseCache extends AbstractCache { EntityDao dao = DbEngine.getInstance().findDao(ModelDatabase.class); if (StringUtils.isEmpty(SwConsts.SysParam.RUN_PROJECTS)) return dao.query(); - return dao.queryEx(" inner join " + ModelProject.ENTITY_NAME + " on db_prj_id=prj_id where prj_module in (" + CommUtil.getSqlInStrs(SwConsts.SysParam.RUN_PROJECTS.split(",")) + ")"); + return dao.queryEx(" inner join " + ModelProject.ENTITY_NAME + " on db_prj_id=prj_id where prj_module in (" + CommUtil.getSqlInStr(SwConsts.SysParam.RUN_PROJECTS.split(",")) + ")"); } public final ModelDatabase getByName(String key) { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelTableCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelTableCache.java index 5730790..383079a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelTableCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelTableCache.java @@ -54,7 +54,7 @@ public class ModelTableCache extends AbstractCache { protected List loadAll() { String sql; if (!StringUtils.isEmpty(SwConsts.SysParam.RUN_PROJECTS)) { - sql = " inner join " + ModelProject.ENTITY_NAME + " on tb_prj_id=prj_id where prj_module in (" + CommUtil.getSqlInStrs(SwConsts.SysParam.RUN_PROJECTS.split(",")) + ")"; + sql = " inner join " + ModelProject.ENTITY_NAME + " on tb_prj_id=prj_id where prj_module in (" + CommUtil.getSqlInStr(SwConsts.SysParam.RUN_PROJECTS.split(",")) + ")"; } else sql = ""; return DbEngine.getInstance().query("SELECT\n" + "t.tb_id,\n" + diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/CommUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/CommUtil.java index 2803d0d..c4bb2cd 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/CommUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/CommUtil.java @@ -9,10 +9,8 @@ import org.apache.commons.lang3.StringUtils; import java.io.Serializable; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.text.Collator; import java.util.Collection; import java.util.HashSet; -import java.util.Locale; import java.util.Set; /** @@ -68,6 +66,10 @@ public class CommUtil { return c == null || c.isEmpty(); } + public static boolean isEmpty(Object[] c) { + return c == null || c.length == 0; + } + /** * 从DefaultEntity实体转成自己的对象类 * @param bean @@ -114,7 +116,7 @@ public class CommUtil { return s.substring(0, s.length() - 1); } - public static String getSqlInStrs(Collection ids) { + public static String getSqlInStr(Collection ids) { if (null == ids || ids.isEmpty()) return ""; StringBuilder s = new StringBuilder(128); Set set = new HashSet<>(); @@ -128,7 +130,7 @@ public class CommUtil { return s.substring(0, s.length() - 1); } - public static String getSqlInStrs(String[] ids) { + public static String getSqlInStr(String[] ids) { if (null == ids || ids.length == 0) return ""; StringBuilder s = new StringBuilder(128); Set set = new HashSet<>(); @@ -141,4 +143,14 @@ public class CommUtil { if (s.length() == 0) return ""; return s.substring(0, s.length() - 1); } + + public static String getOrigMsg(Throwable e) { + String s = e.getMessage(); + Throwable t = e.getCause(); + while (t != null) { + s = t.getMessage(); + t = t.getCause(); + } + return s; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/DateUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/DateUtil.java index 9562f6d..46811f3 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/DateUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/DateUtil.java @@ -1,7 +1,6 @@ package cc.smtweb.framework.core.util; import org.apache.commons.lang3.time.DateUtils; -import org.springframework.util.unit.DataUnit; import java.sql.Timestamp; import java.text.DateFormat; @@ -101,7 +100,7 @@ public class DateUtil { * @return yyyy-mm-dd */ public static String toStdDateString(String s) { - if (PubUtil.isEmptyId(s)) return ""; + if (StringUtil.isEmpty(s)) return ""; if (s.contains("-")) return s; return toStdDateString(s, "-", false); } @@ -114,7 +113,7 @@ public class DateUtil { * @return 用分隔符,如“-”,“.”进行分割后的日期串; */ public static String toStdDateString(String s, String split, boolean returnEmptyIfErrDate) { - if (PubUtil.isEmptyId(s)) return ""; + if (StringUtil.isEmpty(s)) return ""; try { if (s == null || s.length() < 8) { return returnEmptyIfErrDate ? "" : s; @@ -714,10 +713,10 @@ public class DateUtil { * @return boolean 如果为日期格式则返回=true; */ public static boolean isDateFormat(String strDate, String format) { - if (PubUtil.isEmpty(strDate)) { + if (StringUtil.isEmpty(strDate)) { return false; } - if (PubUtil.isEmpty(format)) { + if (StringUtil.isEmpty(format)) { format = "YYYY-MM-DD"; } switch (format) { @@ -812,12 +811,14 @@ public class DateUtil { */ public static java.sql.Date toDate(String src) { try { - if (PubUtil.isEmpty(src)) return null; + if (StringUtil.isEmpty(src)) return null; return java.sql.Date.valueOf(src); } catch (Exception e) { return null; } } + + /** * 得到长日期时间字符[yyyyMMddHHmmss] * @@ -877,7 +878,7 @@ public class DateUtil { * @param yearMonth YYYYMM */ public static String fmtCNYearMonth(String yearMonth) { - if (PubUtil.getIntIgnoreErr(yearMonth) > 190000) + if (NumberUtil.getIntIgnoreErr(yearMonth) > 190000) return String.format("%s年%s月", yearMonth.substring(0, 4), yearMonth.substring(4)); return ""; } @@ -887,7 +888,7 @@ public class DateUtil { * @param yearMonth YYYYMMDD */ public static String fmtCNYearMonthDay(String yearMonth) { - if (PubUtil.isEmptyId(yearMonth) || yearMonth.length() != 8) return yearMonth; + if (StringUtil.isEmpty(yearMonth) || yearMonth.length() != 8) return yearMonth; return String.format("%s年%s月%s日", yearMonth.substring(0, 4), yearMonth.substring(4, 6), yearMonth.substring(6)); } @@ -1077,7 +1078,7 @@ public class DateUtil { return getDateYm(nowTimestamp()); } public static String getNextYear(String year, int add) { - if (PubUtil.isEmptyId(year)) return year; + if (StringUtil.isEmpty(year)) return year; int curYear = Integer.parseInt(year) - 1; return curYear + ""; } @@ -1110,7 +1111,7 @@ public class DateUtil { return getNextYm(getNowYm()); } public static String getNextYm(String period_id, int add) { - if (PubUtil.isEmptyId(period_id)) return period_id; + if (StringUtil.isEmpty(period_id)) return period_id; int curYear = Integer.parseInt(period_id.substring(0, 4)); int curMonth = Integer.parseInt(period_id.substring(4)) + add; if (curMonth > 12) { @@ -1226,4 +1227,43 @@ public class DateUtil { public static void main(String[] args) { System.out.println(getTimesmorning()); } + + /** + * 转日期时间long + * + * @param dateStr + * @return + */ + public static long getDateTimeLong(String dateStr) { + if (StringUtil.isEmpty(dateStr)) { + return -1L; + } + String _dateTime = dateStr.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); + _dateTime = StringUtil.getLeft(_dateTime + "00000000000000", 14); + return NumberUtil.getLongIgnoreErr(_dateTime); + } + + public static long getDateLong(String dateStr) { + if (StringUtil.isEmpty(dateStr) || dateStr.length() != 10) { + return -1L; + } + String _dateTime = dateStr.replaceAll("-", ""); + return NumberUtil.getLongIgnoreErr(_dateTime); + } + + /** + * 转日期时间long + * + * @param dateStr + * @return + */ + public static long getEndDateTimeLong(String dateStr) { + if (StringUtil.isEmpty(dateStr)) { + return -1L; + } + String _dateTime = dateStr.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); + _dateTime = StringUtil.getLeft(_dateTime + "00000000", 8) + "235959"; + return NumberUtil.getLongIgnoreErr(_dateTime); + } + } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/EmojiFilter.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/EmojiFilter.java index 9a2782b..51e465a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/EmojiFilter.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/EmojiFilter.java @@ -13,7 +13,7 @@ public class EmojiFilter { * @return */ public static String filterEmoji(String source) { - if(PubUtil.isEmpty(source)){ + if(StringUtil.isEmpty(source)){ return ""; } if (!containsEmoji(source)) { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/ListSQLParaHelper.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/ListSQLParaHelper.java deleted file mode 100644 index c961e9d..0000000 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/ListSQLParaHelper.java +++ /dev/null @@ -1,781 +0,0 @@ -package cc.smtweb.framework.core.util; - -import cc.smtweb.framework.core.common.AbstractEnum; -import cc.smtweb.framework.core.common.IntEnum; -import cc.smtweb.framework.core.common.StrEnum; -import org.apache.commons.lang3.StringUtils; - -import java.util.List; - -/** - * 注意:where参数表示是否已经加入了where关键字 - * - * @author : AKzz - * @version : $Revision:$ - */ -@SuppressWarnings("UnusedDeclaration") -@Deprecated -public abstract class ListSQLParaHelper { - - - /** - * 补充SQL的字符串的==条件 - * - * @param where_is_exist 是否已经加入了where关键字 - */ - public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, int condition_value) { - if (!where_is_exist) { - sql.append(" WHERE "); - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" = ? \n"); - args.add(condition_value); - return true; - } - - /** - * 补充SQL的字符串的==条件 - * - * @param where_is_exist 是否已经加入了where关键字 - */ - public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" = ? \n"); - args.add(condition_value); - } - return where_is_exist; - } - - public static boolean addSql_lesser(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" <= ? \n"); - args.add(condition_value); - } - return where_is_exist; - } - - public static boolean addSql_greater(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" >= ? \n"); - args.add(condition_value); - } - return where_is_exist; - } - - - /** - * 补充SQL的字符串Like条件(仅后匹配) %s - * - * @param where_is_exist 是否已经加入了where关键字 - */ - public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" LIKE ? \n"); - args.add(String.format("%%%s", condition_value)); - } - return where_is_exist; - } - - public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append("(").append(db_field_names[0]).append(" LIKE ? \n"); - args.add(String.format("%%%s", condition_value)); - for (int i = 1; i < db_field_names.length; ++i) { - sql.append(" or ").append(db_field_names[i]).append(" LIKE ? \n"); - args.add(String.format("%%%s", condition_value)); - } - sql.append(")"); - } - return where_is_exist; - } - - public static boolean addSql_LIKE_EX(boolean where_is_exist, StringBuilder sql, List args, String condition_value, String... db_field_name) { - if (db_field_name == null || db_field_name.length == 0) return where_is_exist; - if (PubUtil.isNotEmptyStr(condition_value)) { - //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - if (db_field_name.length == 1) { - sql.append(db_field_name[0]).append(" LIKE ? \n"); - args.add(String.format("%%%s%%", condition_value)); - return where_is_exist; - } - sql.append(" ("); - for (String db_filed : db_field_name) { - sql.append(" ").append(db_filed).append(" LIKE ? \nOR"); - args.add(String.format("%%%s%%", condition_value)); - } - sql.delete(sql.length() - 2, sql.length()); - sql.append(")\n"); - - } - return where_is_exist; - } - - - /** - * 补充SQL的字符串Like条件(仅后匹配) s% - * - * @param where_is_exist 是否已经加入了where关键字 - */ - public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" LIKE ? \n"); - args.add(String.format("%s%%", condition_value)); - } - return where_is_exist; - } - - - public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append("(").append(db_field_names[0]).append(" LIKE ? \n"); - args.add(String.format("%s%%", condition_value)); - for (int i = 1; i < db_field_names.length; ++i) { - sql.append(" or ").append(db_field_names[i]).append(" LIKE ? \n"); - args.add(String.format("%s%%", condition_value)); - } - sql.append(")"); - } - return where_is_exist; - } - - /** - * 补充SQL的字符串Like条件(全模糊) %s% - * - * @param where_is_exist 是否已经加入了where关键字 - */ - public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" LIKE ? \n"); - args.add(String.format("%%%s%%", condition_value)); - } - return where_is_exist; - } - - public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { - if (PubUtil.isNotEmptyStr(condition_value)) { - //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append("(").append(db_field_names[0]).append(" LIKE ? "); - args.add(String.format("%%%s%%", condition_value)); - for (int i = 1; i < db_field_names.length; ++i) { - sql.append(" OR ").append(db_field_names[i]).append(" LIKE ? "); - args.add(String.format("%%%s%%", condition_value)); - } - sql.append(")"); - } - return where_is_exist; - } - - /** - * 补充SQL字符串的IN条件 - * - * @param where_is_exist 是否已经加入了where关键字 - */ - public static boolean addSql_IN_Expr(boolean where_is_exist, StringBuilder sql, String db_field_name, Object... expr) { - if (expr != null && expr.length > 0) { - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" IN (").append(StringUtils.join(expr, ',')).append(")\n"); - } - return where_is_exist; - } - - /** - * 补充SQL字符串的not IN条件 - * - * @param where_is_exist 是否已经加入了where关键字 - */ - public static boolean addSql_NOTIN_Expr(boolean where_is_exist, StringBuilder sql, String db_field_name, Object... expr) { - if (expr != null && expr.length > 0) { - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - sql.append(db_field_name).append(" NOT IN (").append(StringUtils.join(expr, ',')).append(")\n"); - } - return where_is_exist; - } - - /** - * 增加字符串字段条件,可能多选 - * - * @param field 查询的字段名 - * @param value 值,包含','为多选 - * @param sql sql - * @param paras 参数 - */ - public static void addStrConMulti(String field, String value, StringBuilder sql, List paras) { - if (PubUtil.isEmpty(value)) - return; - if (value.contains(",")) {//多选 - sql.append(" and ").append(field).append(" in ('").append(value.replaceAll(",", "','")).append("')"); - } else if (!Consts.NULL_STRING.equals(value)) {//单 - sql.append(" and ").append(field).append("=?"); - paras.add(value); - } - } - - /** - * 增加字符串字段条件,不判断多选 - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - public static void addStrConSingle(String field, String value, StringBuilder sb, List paras) { - addStrConSingle(field, "=", value, sb, paras); - } - - /** - * 增加字符串字段条件,不判断多选 - * - * @param field 查询的字段名 - * @param opt 逻辑运算符 - * @param value 值 - * @param paras 参数 - */ - public static void addStrConSingle(String field, String opt, String value, StringBuilder sb, List paras) { - if (PubUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) {//单 - sb.append(" and ").append(field).append(" ").append(opt).append(" ? \n"); - paras.add(value); - } - } - - /** - * 增加字符串字段条件,包含 - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - public static void addStrConSingleLike(String field, String value, StringBuilder sb, List paras) { - if (PubUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) {//单 - sb.append(" and ").append(field).append(" like ? \n"); - paras.add("%" + value + "%"); - } - } - - /** - * 增加字符串字段条件并且不区分大小写,包含 - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - public static void addStrConSingleLikeIgnoreCase(String field, String value, StringBuilder sb, List paras) { - if (PubUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) { - String valueLower = value.toLowerCase(); - sb.append(" and ").append("lower(").append(field).append(")").append(" like ? \n"); - paras.add("%" + valueLower + "%"); - } - } - - /** - * 增加数字字段条件,可能多选 - * - * @param field 查询的字段名 - * @param value 值,包含','为多选 - * @param paras 参数 - */ - public static void addNumberConMulti(String field, String value, StringBuilder sb, List paras) { - if (PubUtil.isEmptyId(value)) - return; - if (value.contains(",")) {//多选 - sb.append(" and ").append(field).append(" in (").append(value).append(") \n"); - } else if (!Consts.NULL_STRING.equals(value)) {//单 - sb.append(" and ").append(field).append("=? \n"); - paras.add(value); - } - } - - /** - * 增加数字字段条件,单选 - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - public static void addNumConSingle(String field, Number value, StringBuilder sb, List paras) { - addNumConSingle(field, "=", value, sb, paras); - } - - /** - * 增加数字字段条件,单选 - * - * @param field 查询的字段名 - * @param opt 运算符 - * @param value 值 - * @param paras 参数 - */ - public static void addNumConSingle(String field, String opt, Number value, StringBuilder sb, List paras) { - sb.append(" and ").append(field).append(opt).append("? \n"); - paras.add(value); - } - - /** - * 增加日期字段条件,可能多选 - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - @Deprecated - public static void addDateCon(String field, String value, StringBuilder sb, List paras) { - if (PubUtil.isEmpty(value)) - return; - String[] st = value.split(","); - if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 - return; - } - String s = PubUtil.getCurDateStr(); - if (st.length > 0) { - switch (st[0]) { - case "D": //当天 考虑日期时间的情况 - sb.append(" and ").append(field).append(">='").append(s).append("' and ").append(field).append("<'").append(DateUtil.getAfterDays(s, 1)).append("' \n"); - break; - case "W": //本周 - s = DateUtil.toStdDateString(DateUtil.getWeekStart()); - sb.append(" and ").append(field).append(">='").append(s).append("' and ").append(field).append("<'").append(DateUtil.getAfterDays(s, 8)).append("' \n"); - break; - case "M": //本月 - sb.append(" and ").append(field).append(">='").append(DateUtil.getMonthStart()).append("' and ").append(field).append("<='").append(DateUtil.getMonthEnd()).append(" 23:59:59' \n"); - break; - case "Q": //本季度 - sb.append(" and ").append(field).append(">='").append(DateUtil.getSeasonFirstDay()).append("' and ").append(field).append("<='").append(DateUtil.getSeasonLastDay()).append(" 23:59:59' \n"); - break; - case "Y": //本年 - sb.append(" and ").append(field).append(">='").append(DateUtil.getYearFirstDay()).append("' and ").append(field).append("<='").append(DateUtil.getYearLastDay()).append(" 23:59:59' \n"); - break; - default: //自定义 - String df, de; - if (st.length > 1) - df = st[1]; - else - df = ""; - if (st.length > 2) - de = st[2]; - else - de = ""; - if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) - return; - if (PubUtil.isEmpty(df)) { - sb.append(" and ").append(field).append("<=?"); - paras.add(de); - } else if (PubUtil.isEmpty(de)) { - sb.append(" and ").append(field).append(">=?"); - paras.add(df); - } else { - sb.append(" and ").append(field).append(">=? and ").append(field).append("<=? \n"); - paras.add(df); - paras.add(de); - } - break; - } - } - } - - /** - * 增加日期字段条件,可能多选(huangxl:日期格式YYYYMMDD) - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - public static void addDateConEx(String field, String value, StringBuilder sb, List paras) { - if (PubUtil.isEmpty(value)) - return; - String[] st = value.split(","); - if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 - return; - } - String s = PubUtil.getCurDateStr(); - if (st.length > 0) { - switch (st[0]) { - case "D": //当天 - sb.append(" and ").append(field).append("=").append(PubUtil.getDateLong(s)).append(" \n"); - break; - case "W": //本周 - s = DateUtil.toStdDateString(DateUtil.getWeekStart()); - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateLong(s)).append(" and ").append(PubUtil.getDateLong(DateUtil.getAfterDays(s, 7))).append(" \n"); - break; - case "M": //本月 - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateLong(DateUtil.getMonthStart())).append(" and ").append(PubUtil.getDateLong(DateUtil.getMonthEnd())).append(" \n"); - break; - case "Q": //本季度 - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateLong(DateUtil.getSeasonFirstDay())).append(" and ").append(PubUtil.getDateLong(DateUtil.getSeasonLastDay())).append(" \n"); - break; - case "Y": //本年 - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateLong(DateUtil.getYearFirstDay())).append(" and ").append(PubUtil.getDateLong(DateUtil.getYearLastDay())).append(" \n"); - break; - default: //自定义 - String df, de; - if (st.length > 1) - df = st[1]; - else - df = ""; - if (st.length > 2) - de = st[2]; - else - de = ""; - if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) - return; - if (PubUtil.isEmpty(df)) { - sb.append(" and ").append(field).append("<=?"); - paras.add(PubUtil.getDateLong(de)); - } else if (PubUtil.isEmpty(de)) { - sb.append(" and ").append(field).append(">=?"); - paras.add(PubUtil.getDateLong(df)); - } else { - sb.append(" and ").append(field).append(" between ? and ? \n"); - paras.add(PubUtil.getDateLong(df)); - paras.add(PubUtil.getDateLong(de)); - } - break; - } - } - } - - /** - * 增加期间查询日期字段条件,可能多选(huangxl:日期格式YYYYMMDD) - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - public static void addPeriodDateConEx(String field, String value, StringBuilder sb, List paras) { - if (PubUtil.isEmpty(value)) - return; - String[] st = value.split(","); - if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 - return; - } - String df, de; - if (st.length > 1) - df = st[1]; - else - df = ""; - if (st.length > 2) - de = st[2]; - else - de = ""; - - sb.append(" and ").append(field).append(" between ? and ? \n"); - paras.add(df + "01"); - paras.add(de + "31"); - } - - - /** - * 增加日期时间字段条件 - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - public static void addDateTimeConEx(String field, String value, StringBuilder sb, List paras) { - if (PubUtil.isEmpty(value)) - return; - String[] st = value.split(","); - if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 - return; - } - String s = PubUtil.getCurDateStr(); - if (st.length > 0) { - switch (st[0]) { - case "D": //当天 - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(s)).append(" and ").append(PubUtil.getEndDateTimeLong(s)).append(" \n"); - break; - case "W": //本周 - s = DateUtil.toStdDateString(DateUtil.getWeekStart()); - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(s)).append(" and ").append(PubUtil.getEndDateTimeLong(DateUtil.getAfterDays(s, 6))).append(" \n"); - break; - case "M": //本月 - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(DateUtil.getMonthStart())).append(" and ").append(PubUtil.getEndDateTimeLong(DateUtil.getMonthEnd())).append(" \n"); - break; - case "Q": //本季度 - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(DateUtil.getSeasonFirstDay())).append(" and ").append(PubUtil.getEndDateTimeLong(DateUtil.getSeasonLastDay())).append(" \n"); - break; - case "Y": //本年 - sb.append(" and ").append(field).append(" between ").append(PubUtil.getDateTimeLong(DateUtil.getYearFirstDay())).append(" and ").append(PubUtil.getEndDateTimeLong(DateUtil.getYearLastDay())).append(" \n"); - break; - default: //自定义 - String df, de; - if (st.length > 1) - df = st[1]; - else - df = ""; - if (st.length > 2) - de = st[2]; - else - de = ""; - if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) - return; - if (PubUtil.isEmpty(df)) { - sb.append(" and ").append(field).append("<=?"); - paras.add(PubUtil.getEndDateTimeLong(de)); - } else if (PubUtil.isEmpty(de)) { - sb.append(" and ").append(field).append(">=?"); - paras.add(PubUtil.getDateTimeLong(df)); - } else { - sb.append(" and ").append(field).append(" between ? and ? \n"); - paras.add(PubUtil.getDateTimeLong(df)); - paras.add(PubUtil.getEndDateTimeLong(de)); - } - break; - } - } - } - - /** - * 枚举状态字段,in方式 - * - * @param where_is_exist sql是否已包括where - * @param field sql字段名 - * @param value 前端传回来的查询值,格式:1,1,1,1 - * @param intEnum 枚举类型 - * @param sql 待构建的sql - */ - public static void addIntEnumCon(boolean where_is_exist, String field, String value, IntEnum intEnum, StringBuilder sql) { - if (PubUtil.isNotEmpty(value) && value.contains("1") && value.contains("0")) { - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - String s = ""; - String[] ss = value.split(","); - int i = 0; - for (AbstractEnum.IntEnumBean b : intEnum.values()) { - if (ss.length > i && "1".equals(ss[i])) s += "," + b.value; - i++; - } - sql.append(field + " in (" + s.substring(1) + ")"); - } - } - - /** - * 枚举状态字段,in方式 - * - * @param where_is_exist sql是否已包括where - * @param field sql字段名 - * @param value 前端传回来的查询值,格式:1,1,1,1 - * @param intEnum 枚举类型 - * @param sql 待构建的sql - */ - public static void addStrEnumCon(boolean where_is_exist, String field, String value, StrEnum intEnum, StringBuilder sql) { - if (PubUtil.isNotEmpty(value) && value.contains("1") && value.contains("0")) { - if (!where_is_exist) { - sql.append(" WHERE "); - where_is_exist = true; - } else { - sql.append(" AND "); - } - String s = ""; - String[] ss = value.split(","); - int i = 0; - for (AbstractEnum.StrEnumBean b : intEnum.values()) { - if (ss.length > i && "1".equals(ss[i])) s += ",'" + b.value + "'"; - i++; - } - sql.append(field + " in (" + s.substring(1) + ")"); - } - } - - public static void addTreeStateCon(String curPrefix, String value, String tableName, StringBuilder sb, List paras) { - if (PubUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value) && !value.contains(",")) { - int v = PubUtil.getIntIgnoreErr(value); - if (v == 0) {//查启用 自己启用,且父亲未停用 - sb.append(" and ").append(curPrefix).append(".f_status=0 and not exists(select 1 from ").append(tableName).append(" p__ where p__.f_status=1 and ").append(curPrefix).append(".f_level_code like p__.f_level_code || '-%')"); - } else {//查停用 自己停用 或父亲被停用 - sb.append(" and (").append(curPrefix).append(".f_status=1 or exists(select 1 from ").append(tableName).append(" p__ where p__.f_status=1 and ").append(curPrefix).append(".f_level_code like p__.f_level_code || '-%'))"); - } - } - } - - /** - * 增加年月字段条件 - * - * @param field 查询的字段名 - * @param value 值 - * @param paras 参数 - */ - public static void addYmCon(String field, String value, StringBuilder sb, List paras) { - addYmConEx(field, field, value, sb, paras); - } - - public static void addYmConEx(String field_begin, String field_end, String value, StringBuilder sb, List paras) { - if (PubUtil.isEmpty(value)) - return; - String[] st = value.split(","); - if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 - return; - } - String s = PubUtil.getCurDateStr(); - if (st.length > 1) { - switch (st[0]) { - case "M": //本月 - String nowYm = DateUtil.getNowYm(); - sb.append(" and ").append(field_end).append(">='").append(DateUtil.getNowYm()).append("' and ").append(field_begin).append("<='").append(nowYm).append("'"); - break; - case "Q": //本季度 - sb.append(" and ").append(field_end).append(">='").append(DateUtil.getSeasonBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getSeasonEndYm()).append("'"); - break; - case "Y": //本年 - sb.append(" and ").append(field_end).append(">='").append(DateUtil.getYearBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getYearEndYm()).append("'"); - break; - default: //自定义 - String df, de; - if (st.length > 1) - df = st[1]; - else - df = ""; - if (st.length > 2) - de = st[2]; - else - de = ""; - if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) - return; - if (PubUtil.isEmpty(df)) { - sb.append(" and ").append(field_begin).append("<=?"); - paras.add(de); - } else if (PubUtil.isEmpty(de)) { - sb.append(" and ").append(field_end).append(">=?"); - paras.add(df); - } else { - sb.append(" and ").append(field_end).append(">=? and ").append(field_begin).append("<=?"); - paras.add(df); - paras.add(de); - } - break; - } - } else if (st.length == 1) { - sb.append(" and ").append(field_end).append(">='").append(value).append("' and ").append(field_begin).append("<='").append(value).append("'"); - } - } - - //构建年月范围的sql - public static String getYmConSql(String field, String value) { - return getYmConSqlEx(field, field, value); - } - - public static String getYmConSqlEx(String field_begin, String field_end, String value) { - if (PubUtil.isEmpty(value)) return ""; - String[] st = value.split(","); - if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) return ""; - String s = PubUtil.getCurDateStr(); - StringBuilder sb = new StringBuilder(128); - - switch (st[0]) { - case "M": //本月 - String nowYm = DateUtil.getNowYm(); - sb.append(" and ").append(field_end).append(">='").append(DateUtil.getNowYm()).append("' and ").append(field_begin).append("<='").append(nowYm).append("'"); - break; - case "Q": //本季度 - sb.append(" and ").append(field_end).append(">='").append(DateUtil.getSeasonBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getSeasonEndYm()).append("'"); - break; - case "Y": //本年 - sb.append(" and ").append(field_end).append(">='").append(DateUtil.getYearBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getYearEndYm()).append("'"); - break; - default: //自定义 - String df, de; - if (st.length > 1) - df = st[1]; - else - df = ""; - if (st.length > 2) - de = st[2]; - else - de = ""; - if (PubUtil.isEmpty(df) && PubUtil.isEmpty(de)) - return ""; - if (PubUtil.isEmpty(df)) { - sb.append(" and ").append(field_begin).append("<='").append(de).append("'"); - } else if (PubUtil.isEmpty(de)) { - sb.append(" and ").append(field_end).append(">='").append(df).append("'"); - } else { - sb.append(" and ").append(field_end).append(">='").append(df).append("' and ").append(field_begin).append("<='").append(de).append("'"); - } - break; - } - return sb.substring(5); - } -} diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java index f519fdc..a4bf0eb 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MapUtil.java @@ -216,7 +216,7 @@ public class MapUtil { public static List readStringList(SwMap swMap, String name) { Object value = swMap.get(name); - if (value != null && PubUtil.isNotEmpty(value.toString())) { + if (value != null && StringUtil.isNotEmpty(value.toString())) { return Arrays.asList(value.toString().split(",")); } return null; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MathUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MathUtil.java deleted file mode 100644 index de803f1..0000000 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/MathUtil.java +++ /dev/null @@ -1,464 +0,0 @@ -package cc.smtweb.framework.core.util; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.DecimalFormat; - -/** - * Created with IntelliJ IDEA. - * User: AKhh - * Date: 12-12-25 下午1:02 - * To change this template use File | Settings | File Templates. - */ -@Deprecated -public class MathUtil { - //整数 - private static DecimalFormat dfLng = new DecimalFormat("##############0"); - private static DecimalFormat dfLong = new DecimalFormat("###,###,###,###,##0"); - //一位小数 - private static DecimalFormat df1 = new DecimalFormat("##############0.0"); - private static DecimalFormat df1Format = new DecimalFormat("###,###,###,###,##0.0"); - //两位小数 - private static DecimalFormat df2 = new DecimalFormat("##############0.00"); - private static DecimalFormat df2Format = new DecimalFormat("###,###,###,###,##0.00"); - //四位小数 - private static DecimalFormat df4 = new DecimalFormat("###,###,###,###,##0.0000"); - //六位小数 - private static DecimalFormat df6Number = new DecimalFormat("#######################0.000000"); - private static DecimalFormat df6NumberF = new DecimalFormat("#,###,###,###,###,###,##0.000000"); - - public final static DecimalFormat stdAmountFormat = new DecimalFormat("###,###,###,###,##0.00"); - public final static DecimalFormat stdNumberFormat = new DecimalFormat("#0.00"); - public final static String DEF_NUM_TEN_THOUSAND = "10000";//万 - public static final double MAX_VALUE = 9999999999999.99D; - public static final double MIN_VALUE = -9999999999999.99D; - - private final static BigDecimal ONE_BIG = new BigDecimal(1.00D); - private static final String UNIT = "万仟佰拾亿仟佰拾万仟佰拾元角分"; - private static final String DIGIT = "零壹贰叁肆伍陆柒捌玖"; - - /** - * 4舍5入double,2位小数 - */ - public static double roundDouble(double src) { - return roundDouble(src, 2); - } - - /** - * 4舍5入double,N 位小数 - * @param src - * @param scale 小数位数 - * @return - */ - public static double roundDouble(Object src, int scale) { - if (src == null) return 0.0; - String v = src.toString(); - if (PubUtil.isEmpty(v)) return 0.0; - if (scale < 0) scale = 2; - - BigDecimal src_b = new BigDecimal(v); - BigDecimal src_v = src_b.divide(ONE_BIG, scale + 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 - src_v = src_v.divide(ONE_BIG, scale, BigDecimal.ROUND_HALF_UP);// 4舍5入 - return src_v.doubleValue(); - } - - /** - * 舍位处理,原生floor有坑,部分浮点数记录为.99999999999形式,导致floor结果错误 - * @param d - * @return - */ - public static double floor(double d) { - return Math.floor(roundDouble(d, 2)); - } - - /** - * 比较两Double是否相等,将会吧他们专程BigDecimal进行比较; - * - * @param src double1 - * @param tag double2 - * @return src > tag 返回1, src < tag 返回-1, 否则返回0 - */ - public static int compare(double src, double tag) { - BigDecimal src_b = new BigDecimal(src); - BigDecimal src_v = src_b.divide(ONE_BIG, 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 - - BigDecimal tag_b = new BigDecimal(tag); - BigDecimal tag_v = tag_b.divide(ONE_BIG, 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 - - return src_v.compareTo(tag_v); - } - - /** - * 自动过滤金额中的逗号转换为double,如果出错,则返回0 - * - * @param s 源串,可能为带逗号的金额串; - * @return double - */ - public static Double toDouble(String s) { - return todouble(s); - } - - /** - * 自动过滤金额中的逗号转换为double,如果出错,则返回0 - * - * @param s 源串,可能为带逗号的金额串; - * @return double - */ - public static double todouble(String s) { - try { - return Double.parseDouble(s.replaceAll(",", "")); - } catch (Exception e) { - return 0.00; - } - } - - /** - * 获取double,主要过滤d为null的情况; - * - * @param d Double对象; - * @return double - */ - public static double todouble(Double d) { - if (d == null) return 0.0d; - return d.doubleValue(); - } - - /** - * 自动过滤金额中的逗号转换为float,如果出错,则返回0 - * - * @param s 源串,可能为带逗号的金额串; - * @return Float - */ - public static Float toFloat(String s) { - return tofloat(s); - } - - /** - * 自动过滤金额中的逗号转换为float,如果出错,则返回0 - * - * @param s 源串,可能为带逗号的金额串; - * @return Float - */ - public static float tofloat(String s) { - try { - return Float.parseFloat(s.replaceAll(",", "")); - } catch (Exception e) { - return 0.0f; - } - } - - public static long tolong(String src, long defaultvalue) { - try { - return Long.parseLong(src); - } catch (Exception e) { - return defaultvalue; - } - } - - public static int toint(String src, int defaultvalue) { - try { - return Integer.parseInt(src); - } catch (Exception e) { - return defaultvalue; - } - } - - /** - * 考虑使用中的精度,判断一个Value是否>0,实际是>0.00001 - * - * @param value double类型 - * @return boolean - */ - public static boolean isBigThanZero(double value) { - return (value > 0.00001); - } - - /** - * 考虑使用中的精度,判断一个Value是否>0,实际是>0.00001 - * - * @param value String类型 - * @return boolean - */ - public static boolean isBigThanZero(String value) { - return !PubUtil.isEmpty(value) && isBigThanZero(toDouble(value)); - } - - /** - * 考虑使用中的精度,判断一个Value是否=0,实际是给出一个值范围。 - * - * @param value double类型 - * @return boolean - */ - public static boolean isEqualsZero(double value) { - return (-0.00001 < value && value < 0.00001); - } - - /** - * 考虑使用中的精度,判断一个Value是否=0,实际是给出一个值范围。 - * - * @param value String类型 - * @return boolean - */ - public static boolean isEqualsZero(String value) { - return PubUtil.isEmpty(value) || isEqualsZero(toDouble(value)); - } - - /** - * 是否是负数 - * - * @param db_val 要判断的double - * @return 负数则返回true; - */ - public static boolean isNegative(double db_val) { - return (compare(db_val, 0.00D) == -1); - } - - /** - * 是否是正数 - * - * @param db_val 要判断的double - * @return 正数则返回true; - */ - public static boolean isPlus(double db_val) { - return (compare(db_val, 0.00D) == 1); - } - - /** - * 得到金额字符串,保持小数点2位 - * - * @param db 将double转换为金额字符串; - * @return 金额字符串#0.00; - */ - public static String toStdNumberString(double db) { - try { - return stdNumberFormat.format(db); - } catch (Exception e) { - return "0.00"; - } - } - - public static String toStdNumberStringEx(double db) { - try { - if (compare(db, -1d) == 0) return "-"; - return stdNumberFormat.format(db); - } catch (Exception e) { - return "0.00"; - } - } - - /** - * 将金额格式字符串,如23,333,093.01 去掉逗号 - * - * @param s 金额串 - * @return String 去掉逗号后的串,如果amount为空,则返回0.00 - */ - public static String toStdNumberString(String s) { - if (PubUtil.isEmpty(s)) - return "0.00"; - return stdNumberFormat.format(todouble(s)); - } - - /** - * 将数据转换为两位小数的数字格式; - * - * @param d 数据 - * @param isZeroToEmpty 如果未0,是否返回“”; - * @return 两位小数的字符串; - */ - public static String toStdNumberString(double d, boolean isZeroToEmpty) { - if (isEqualsZero(d)) { - return isZeroToEmpty ? "": "0.00"; - } - return stdNumberFormat.format(d); - } - - public static String toStdNumberString(String s, boolean isZeroToEmpty) { - return toStdNumberString(todouble(s), isZeroToEmpty); - } - - public static String toStdNumberString(double d, int scale) { - DecimalFormat dfn = null; - if (scale == 1) dfn = df1Format; - if (scale == 2) dfn = df2Format; - else if (scale == 4) dfn = df4; - else if (scale == 6) dfn = df6NumberF; - else if (scale <= 0) dfn = dfLong; - else { - StringBuilder sb = new StringBuilder("###,###,###,###,##0."); - for (int i = 0; i < scale; i++) sb.append("0"); - dfn = new DecimalFormat(sb.toString()); - } - return dfn.format(d); - } - - /** - * 将数字乘100,保留小数点后两位, 然后后面添加% - * - * @param d 值 - * @param isZeroToEmpty,如果值为0,是否返回空; - * @return 字符串; - */ - public static String toStdPercentNumberStr(double d, boolean isZeroToEmpty) { - if (d > -0.00000000001 && d < 0.00000000001) { - return isZeroToEmpty ? "": "0.00%"; - } - return toStdNumberString(d * 100) + "%"; - } - - - public static String toStdAmountString(double d) { - return toStdAmountString(d, false); - } - - /** - * 将数据转换为两位小数的金额格式,带逗号; - * - * @param d 数据 - * @param isZeroToEmpty 如果未0,是否返回“”; - * @return 金额格式的字符串; - */ - public static String toStdAmountString(double d, boolean isZeroToEmpty) { - if (isEqualsZero(d)) { - return isZeroToEmpty ? "": "0.00"; - } - return stdAmountFormat.format(d); - } - - public static String toStdAmountString(String s) { - return toStdAmountString(todouble(s), false); - } - - public static String toStdAmountString(String s, boolean isZeroToEmpty) { - return toStdAmountString(todouble(s), isZeroToEmpty); - } - - - /** - * 将小写金额转换为人民币大写金额 - * - * @param s 金额格式的串 - * @return String 转换结果 - */ - public static String toCapsAmountString(String s) { - if (PubUtil.isEmpty(s)) return ""; - return toCapsAmountString(todouble(s)); - } - - /** - * 将小写金额转换为人民币大写金额 - * - * @param v double - * @return String 转换结果 - */ - public static String toCapsAmountString(double v) { - if (v < MIN_VALUE || v > MAX_VALUE) return "参数非法!"; - - boolean negative = isNegative(v); - - if (negative) v = Math.abs(v); - long l = Math.round(v * 100); - if (l == 0) return "零元整"; - - String strValue = String.valueOf(l); - // i用来控制数 - int i = 0; - // j用来控制单位 - int j = UNIT.length() - strValue.length(); - StringBuilder rs = new StringBuilder(32); - boolean isZero = false; - for (; i < strValue.length(); i++, j++) { - char ch = strValue.charAt(i); - if (ch == '0') { - isZero = true; - if (UNIT.charAt(j) == '亿' || UNIT.charAt(j) == '万' || UNIT.charAt(j) == '元') { - rs.append(UNIT.charAt(j)); - isZero = false; - } - } else { - if (isZero) { - rs.append('零'); - isZero = false; - } - rs.append(DIGIT.charAt(ch - '0')).append(UNIT.charAt(j)); - } - } - if (rs.charAt(rs.length() - 1) != '分') - rs.append('整'); - - i = rs.indexOf("亿万"); - if (i > 0) rs.delete(i + 1, i + 2); // i+1 ->万 - - if (negative) - return rs.insert(0, '负').toString(); - else - return rs.toString(); - } - - /** - * 返回0 到 maxvalue的随机数 - * - * @param maxvalue 随机数的最大值 - * @return int - */ - public static int rnd(int maxvalue) { - return (int) (Math.random() * (maxvalue + 1)); - } - - - public static double chkDbNull(Double v) { - return v == null ? 0: v; - } - - public static double max(double d1, double d2) { - return compare(d1, d2) < 0 ? d2 : d1; - } - - public static double min(double d1, double d2) { - return compare(d1, d2) < 0 ? d1 : d2; - } - - - public static void main(String[] args) { - double aa=123456789.345678900005; - System.out.println("args0 = " + upDouble(aa,0)); - System.out.println("args1 = " + upDouble(aa,1)); - System.out.println("args2 = " + upDouble(aa,2)); - System.out.println("args3 = " + upDouble(aa,3)); - System.out.println("args4 = " + upDouble(aa,4)); - System.out.println("args5 = " + upDouble(aa,5)); - System.out.println("args5 = " + upDouble(aa,6)); - System.out.println("args5 = " + upDouble(aa,7)); - System.out.println("args5 = " + upDouble(aa,8)); - - } - - /** - * double 去尾法 - * @param src 待处理数据 - * @param scale 保留小数位数 - * @return - */ - public static double cutDouble(double src, int scale){ - String v = toStdNumberString(src, 6);//先到6位小数,再去计算,否则容易出错,如8.3成8.29999999999,舍位就成了8.29了 - DecimalFormat formater = new DecimalFormat(); - formater.setMaximumFractionDigits(scale); - formater.setGroupingSize(0); - formater.setRoundingMode(RoundingMode.FLOOR); - return new BigDecimal(formater.format(toDouble(v))).doubleValue(); - } - - /** - * double 进位法 - * @param src 待处理数据 - * @param scale 保留小数位数 - * @return - */ - public static double upDouble(double src, int scale){ - String v = toStdNumberString(src, 6);//先到6位小数,再去计算 - DecimalFormat formater = new DecimalFormat(); - formater.setMaximumFractionDigits(scale); - formater.setGroupingSize(0); - formater.setRoundingMode(RoundingMode.UP); - return new BigDecimal(formater.format(toDouble(v))).doubleValue(); - } -} diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/PubUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/PubUtil.java deleted file mode 100644 index 2aaa1a5..0000000 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/PubUtil.java +++ /dev/null @@ -1,780 +0,0 @@ -package cc.smtweb.framework.core.util; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; - -import java.io.UnsupportedEncodingException; -import java.sql.Date; -import java.sql.Timestamp; -import java.text.Collator; -import java.text.DecimalFormat; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.function.Function; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Created with IntelliJ IDEA. - * User: AKhh - * Date: 12-12-26 下午11:55 - * 基础工具类; - */ -@SuppressWarnings("UnusedDeclaration") -@Slf4j -@Deprecated -public class PubUtil { - private static SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd"); - private static SimpleDateFormat tFormat = new SimpleDateFormat("HH:mm:ss"); - private static SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private static SimpleDateFormat dLFormat = new SimpleDateFormat("yyyyMMddHHmmss"); - private static SimpleDateFormat dLFormat2 = new SimpleDateFormat("yyyyMMdd"); - private static DecimalFormat df2Format = new DecimalFormat("###,###,###,###,##0.00"); - private static DecimalFormat df2 = new DecimalFormat("##############0.00"); - private static DecimalFormat df = new DecimalFormat("#.##"); - - - public static boolean isEmpty(String str) { - return str == null || str.trim().length() == 0; - } - //判断 是否支持GBK - public static boolean supportGBK(String str){ - if(str == null){ - return true; - } - try { - return str.equals ( new String (str.getBytes ("gbk"),"gbk") ); - }catch (Exception e){ - log.error ( "判断【"+str+"】是否支持GBK时出现异常:"+e.getMessage () ); - e.printStackTrace (); - return false; - } - } - public static boolean isEmpty(Collection collection) { - return collection == null || collection.size() == 0; - } - - public static boolean isEmpty(Object[] o) { - return o == null || o.length == 0; - } - - public static boolean isEmptyStr(String str) { - return str == null || str.trim().length() == 0 || "-".equals(str) || "-1".equals(str); - } - - //判断Id是否为空id,有可能是"-","-1" - public static boolean isEmptyId(String id) { - return id == null || id.trim().length() == 0 || "-".equals(id) || "-1".equals(id) || "null".equals(id) || "(无)".equals(id); - } - - public static boolean isNotEmpty(String str) { - return !isEmpty(str); - } - - public static boolean isNotEmptyId(String str) { - return !isEmptyId(str); - } - - public static boolean isNotEmptyStr(String str) { - return !isEmptyStr(str); - } - - public static boolean isNotEmpty(Collection collection) { - return !isEmpty(collection); - } - - public static boolean isNotEmpty(Object[] o) { - return !isEmpty(o); - } - - /** - * 获取浮点数(有错误默认为0),可以识别金额中的逗号格式 - * - * @param str 带转换的字符串 - * @return 浮点数 - */ - public static double getDoubleIgnoreErr(String str) { - if (str == null) - return 0.0; - str = str.trim(); - if (str.equals("")) - return 0.0; - str = str.replaceAll(",", "").replaceAll(",", ""); - try { - return Double.valueOf(str); - } catch (Exception e) { - return 0.0; - } - } - - /** - * 得到int 获取转换的int值,有错返回0 - * - * @param str 带转换的字符串 - * @return int - */ - public static int getIntIgnoreErr(String str) { - return getIntIgnoreErr(str, 0); - } - - public static int getIntIgnoreErr(String str, int defValue) { - if (str == null) - return defValue; - str = str.trim(); - if (str.equals("")) - return defValue; - str = str.replaceAll(",", "").replaceAll(",", ""); - if (str.contains(".")) - str = str.substring(0, str.indexOf('.')); - try { - return Integer.valueOf(str); - } catch (Exception e) { - return defValue; - } - } - - /** - * 得到Long 获取转换的Long值,有错返回0 - * - * @param str 带转换的字符串 - * @return long - */ - public static long getLongIgnoreErr(String str) { - return getLongIgnoreErr(str, 0L); - } - - public static long getLongIgnoreErr(String str, long defValue) { - if (str == null) - return defValue; - str = str.trim(); - if (str.equals("")) - return defValue; - str = str.replaceAll(",", "").replaceAll(",", ""); - try { - return Long.valueOf(str); - } catch (Exception e) { - return defValue; - } - } - - public static String getDateStrIgnoreNull(Timestamp obj) { - if (obj == null) - return ""; - return dFormat.format(obj); - } - - public static String getTimeStrIgnoreNull(Timestamp obj) { - if (obj == null) - return ""; - return tFormat.format(obj); - } - - public static Date getCurDate() { - return new Date(System.currentTimeMillis()); - } - - public static String getCurDateStr() { - return dFormat.format(new Date(System.currentTimeMillis())); - } - - public static Timestamp getCurDatetime() { - return new Timestamp(System.currentTimeMillis()); - } - - public static String getCurDatetimeStr() { - return dtFormat.format(new Timestamp(System.currentTimeMillis())); - } - - public static String getCurDatetimeShortStr() { - return dLFormat.format(new Timestamp(System.currentTimeMillis())); - } - - /** - * Func:为空,返回"" - * - * @param str 带检查的字符串 - * @return "" - */ - public static String checkNull(String str) { - if (isEmpty(str)) - return ""; - return str.trim(); - } - - /** - * 功能:null过滤,返回默认值 - * - * @param strValue 带检查的字符串 - * @param defaultValue 为空返回的字符串 - * @return str - */ - public static String checkNull(String strValue, String defaultValue) { - return strValue == null ? defaultValue : strValue; - } - - public static String checkNull(Integer n) { - return checkNull(n, true); - } - - public static String checkNull(Integer n, boolean zeroToEmpty) { - int v; - if (n == null || n == 0) - v = 0; - else - v = n; - return v != 0 ? String.valueOf(v) : zeroToEmpty ? "" : "0"; - } - - public static String checkNull(Long n) { - return checkNull(n, 0L); - } - - public static String checkNull(Long n, long defValue) { - return n != null ? String.valueOf(n) : String.valueOf(defValue); - } - - public static String checkNull(Double n) { - return checkNull(n, 0d); - } - public static String checkNull(Double n, boolean zeroToEmpty) { - double v; - if (n == null || n == 0) - v = 0; - else - v = n; - return v != 0 ? String.valueOf(v) : zeroToEmpty ? "" : "0"; - } - public static String checkNull(Double n, double defValue) { - double d = n != null ? n : defValue; - return getDoubleStr(d); - } - - //字符串清洗 - public static String clearStr(String str) { - if (str == null) return ""; - else - str = str.replaceAll("\u3000", "").replaceAll("\n", "").replaceAll("\b", "").replaceAll("\r", "").replaceAll("\t", "").replaceAll("\\s", "").replaceAll(" ", "").trim(); - return str; - } - - /** - * Func:取当前年 - * - * @return "" - */ - public static String getThisYear() { - Calendar tlpDate = new GregorianCalendar(); - tlpDate.setTime(getCurDate()); - return String.valueOf(tlpDate.get(Calendar.YEAR)); - } - - /** - * Func:取当前月 - * - * @return "" - */ - public static String getThisMonth() { - Calendar tlpDate = new GregorianCalendar(); - tlpDate.setTime(getCurDate()); - return String.valueOf(tlpDate.get(Calendar.MONTH)); - } - - /** - * 功能:空值过滤,返回默认值 - * - * @param strValue 待检查的字符串 - * @param defaultValue 为空返回的字符串 - * @return str - */ - public static String checkEmpty(String strValue, String defaultValue) { - return isEmpty(strValue) ? defaultValue : strValue; - } - - /** - * 功能:空值过滤,返回默认值 - * - * @param strValue 待检查的字符串 - * @return str - */ - - public static String checkEmptyId(String strValue, String defaultValue) { - return isEmptyId(strValue) ? defaultValue : strValue; - } - - public static String checkEmptyId(String strValue) { - return isEmptyId(strValue) ? "" : strValue; - } - - public static String getOrigMsg(Throwable e) { - String s = e.getMessage(); - Throwable t = e.getCause(); - while (t != null) { - s = t.getMessage(); - t = t.getCause(); - } - return s; - } - - //计算一个字符串source的长度(英文和数字占一个长度,其他字符(中文和特殊符号等)占2个长度) - public static int strLength(String source) { - int totalLength = source.length();// 总长度 - String otherStr = source.replaceAll("\\d|\\w", "");// 去掉字符串中的数字和英文字符 - int otherLength = otherStr.length();// 占2个长度的字符 - return (totalLength - otherLength) + otherLength * 2; - } - - /** - * 格式化最后修改时间 - * - * @param strTime YYYYMMDDhhmmss - * @return YYYY-MM-DD hh:mm:ss - */ - public static String checkLastTime(String strTime) { - if (isEmpty(strTime)) - return ""; - return checkLastTime(getLongIgnoreErr(strTime)); - } - - public static String checkLastTime(long lngTime) { - if (0 >= lngTime) - return ""; - String s1 = String.valueOf(lngTime + "").trim(); - if (s1.length() != 14) - return ""; - return s1.substring(0, 4).concat("-").concat(s1.substring(4, 6)).concat("-").concat(s1.substring(6, 8)).concat(" ").concat(s1.substring(8, 10)).concat(":").concat(s1.substring(10, 12)).concat(":").concat(s1.substring(12)); - } - - /** - * 格式化最后修改时间 - * - * @param strTime YYYYMMDDhhmmss - * @return YYYY-MM-DD hh:mm:ss - */ - public static String getTimeFormatValue(String strTime) { - if (isEmpty(strTime)) - return ""; - return getTimeFormatValue(getTimeDbValue(strTime)); - } - - /** - * 日期格式化 YYYYMMDDHHMMSS 转 YYYY-MM-DD- HH:MM:SS - * - * @param lngTime - * @return - */ - public static String getTimeFormatValue(long lngTime) { - if (lngTime <= 0L) return ""; - String s1 = String.valueOf(lngTime + "").trim(); - if (s1.length() == 8) {//日期 - return s1.substring(0, 4).concat("-").concat(s1.substring(4, 6)).concat("-").concat(s1.substring(6, 8)); - } - if (s1.length() == 6) {//时间 - return s1.substring(0, 2).concat(":").concat(s1.substring(2, 4)).concat(":").concat(s1.substring(4, 6)); - } - if (s1.length() == 14) {//日期 - return s1.substring(0, 4).concat("-").concat(s1.substring(4, 6)).concat("-").concat(s1.substring(6, 8)).concat(" ").concat(s1.substring(8, 10)).concat(":").concat(s1.substring(10, 12)).concat(":").concat(s1.substring(12)); - } - return ""; - } - - /** - * 日期格式化 YYYY-MM-DD- HH:MM:SS 转 YYYYMMDDHHMMSS - * - * @param strTime - * @return - */ - public static long getTimeDbValue(String strTime) { - if (isEmptyId(strTime)) return -1L; - - return getLongIgnoreErr(strTime.replaceAll("-", "").replaceAll(":", "").replaceAll(" ", "")); - } - - /** - * 取最后修改时间 - * - * @return Long - */ - public static Long getLastTime() { - return DateUtil.nowDateTimeNumber(); - } - - /** - * 取最后修改日期 - * - * @return - */ - public static Long getLastDate() { - return Long.valueOf(dLFormat2.format(new Timestamp(System.currentTimeMillis()))); - } - - public static String getAmountStr(double amount) { - return df2Format.format(amount); - } - - public static String getAmountStrEx(double amount) { - return df.format(amount); - } - - public static String getSingleAmountStr(double amount) { - return df2.format(amount); - } - - - public static String getIntStr(int d) { - if (d == 0) - return ""; - else - return String.valueOf(d); - } - - /** - * 截取右边的0串 - * - * @param codeStr - * @return - */ - public static String cutZero(String codeStr) { - int j = 0; - int len = codeStr.length() - 1; - for (int i = len; i > -1; i--) { - if ('0' == codeStr.charAt(i)) { - j++; - } else { - break; - } - } - return codeStr.substring(0, len - j + 1); - } - - /** - * 右边补0串 - * - * @param codeLen - * @param cutedCode - * @return - */ - public static String fillZero(int codeLen, String cutedCode) { - StringBuilder codeStr = new StringBuilder(20).append(cutedCode); - for (int len = cutedCode.length(), i = 0; i < codeLen - len; i++) { - codeStr.append("0"); - } - return codeStr.toString(); - } - - /** - * 转换为boolean - */ - public static boolean toBoolean(String v, boolean b) { - if (v == null) return b; - return "1".equals(v) || "true".equalsIgnoreCase(v) || "Y".equalsIgnoreCase(v) || "yes".equalsIgnoreCase(v); - } - - public static String getDateStr(Object _dateTime) { //yyyymmddhhMMss - if (_dateTime == null) return ""; - String dateTime = String.valueOf(_dateTime); - if (PubUtil.isEmpty(dateTime) || dateTime.length() < 8) { - return ""; - } else { - String s1 = String.valueOf(dateTime); - return s1.substring(0, 4) + "-" + s1.substring(4, 6) + "-" + s1.substring(6, 8); - } - } - - /** - * 日期转long - * - * @param dateStr YYYY-MM-DD - * @return YYYYmmDD - */ - public static long getDateLong(String dateStr) { - if (PubUtil.isEmpty(dateStr) || dateStr.length() != 10) { - return -1L; - } - String _dateTime = dateStr.replaceAll("-", ""); - return getLongIgnoreErr(_dateTime); - } - - /** - * 转日期时间long - * - * @param dateStr - * @return - */ - public static long getDateTimeLong(String dateStr) { - if (PubUtil.isEmpty(dateStr)) { - return -1L; - } - String _dateTime = dateStr.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); - _dateTime = StringUtil.getLeft(_dateTime + "00000000000000", 14); - return getLongIgnoreErr(_dateTime); - } - - /** - * 转日期时间long - * - * @param dateStr - * @return - */ - public static long getEndDateTimeLong(String dateStr) { - if (PubUtil.isEmpty(dateStr)) { - return -1L; - } - String _dateTime = dateStr.replaceAll("-", "").replaceAll(" ", "").replaceAll(":", ""); - _dateTime = StringUtil.getLeft(_dateTime + "00000000", 8) + "235959"; - return getLongIgnoreErr(_dateTime); - } - - public static String getDateTimeStr(Object _dateTime) { //yyyymmddhhMMss - String dateTime = String.valueOf(_dateTime); - if (PubUtil.isEmpty(dateTime) || dateTime.length() < 14) { - return ""; - } else { - String s1 = String.valueOf(dateTime); - return s1.substring(0, 4) + "-" + s1.substring(4, 6) + "-" + s1.substring(6, 8);// + " " + s1.substr(8, 10) + ":" + s1.substr(10, 12) + ":" + s1.substr(12); - } - } - - //删除除 {"0","1","2","3","4","5","6","7","8","9",".","/","-"}以外的字符 - public static String remove(String str) { - if (isEmpty(str)) return ""; - char[] charArray = str.toCharArray(); - char[] strArray = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '/', '-'}; - for (char c : charArray) { - if (!ArrayUtils.contains(strArray, c)) { - str = StringUtils.remove(str, c); - } - } - return str; - } - - //数字转字符串,如无小数,则去掉.00 - public static String getDoubleStr(double d) { - return getAmountStr(d).replaceAll(",", "").replaceAll("\\.00", ""); - } - - //将List转为sql语句in后面的常量,'XXX','XXX'格式 - public static String getSqlInstr(List list) { - if (PubUtil.isEmpty(list)) return ""; - StringBuilder sb = new StringBuilder(256); - for (String s : list) { - if (PubUtil.isEmptyId(s)) continue; - sb.append(",'").append(s).append("'"); - } - if (sb.length() == 0) return ""; - return sb.substring(1); - } - - /** - * 将数组ID转为sql语句in后面的常量 - * - * @param ids ID数组 - * @return 返回格式:110,1002 - */ - public static String getSqlInIds(String[] ids) { - if (null == ids || ids.length < 1) return ""; - StringBuilder s = new StringBuilder(128); - for (String id : ids) { - if (PubUtil.isEmptyId(id)) continue; - s.append(id.trim()).append(","); - } - if (s.length() == 0) return ""; - return s.substring(0, s.length() - 1); - } - - public static String getSqlInIds(Collection ids) { - if (null == ids || ids.size() < 1) return ""; - StringBuilder s = new StringBuilder(128); - for (String id : ids) { - if (PubUtil.isEmptyId(id)) continue; - s.append(id).append(","); - } - if (s.length() == 0) return ""; - return s.substring(0, s.length() - 1); - } - - public static String getSqlInStrIds(Collection ids) { - if (null == ids || ids.size() < 1) return ""; - StringBuilder s = new StringBuilder(128); - for (String id : ids) { - if (PubUtil.isEmptyId(id)) continue; - s.append("'" + id + "'").append(","); - } - if (s.length() == 0) return ""; - return s.substring(0, s.length() - 1); - } - - - public static List buildSqlIds(Collection ids, int size) { - List l = new ArrayList<>(); - StringBuilder sb = new StringBuilder(); - int count = 0; - for (String id : ids) { - if (count >= size) { - l.add(sb.substring(1)); - sb.setLength(0); - count = 0; - } - sb.append(",").append(id); - count++; - } - if (sb.length() > 0) l.add(sb.substring(1)); - return l; - } - - - /** - * 判断字符串是否只包含unicode数字。 - *

- *

- * null将返回false,空字符串""将返回 - * true。 - *

- *

- *

- *

-     * StringUtil.isNumeric(null)   = false
-     * StringUtil.isNumeric("")     = true
-     * StringUtil.isNumeric("  ")   = false
-     * StringUtil.isNumeric("123")  = true
-     * StringUtil.isNumeric("12 3") = false
-     * StringUtil.isNumeric("ab2c") = false
-     * StringUtil.isNumeric("12-3") = false
-     * StringUtil.isNumeric("12.3") = false
-     * 
- * - * @param str 要检查的字符串 - * @return 如果字符串非null并且全由unicode数字组成,则返回true - */ - public static boolean isNumeric(String str) { - if (PubUtil.isEmpty(str)) { - return false; - } - - int length = str.length(); - - for (int i = 0; i < length; i++) { - if (!Character.isDigit(str.charAt(i))) { - return false; - } - } - - return true; - } - - public static boolean isDouble(String str) { - if (null == str || "".equals(str)) { - return false; - } - Pattern pattern = Pattern.compile("^[-\\+]?[.\\d]*$"); - return pattern.matcher(str).matches(); - - } - - /** - * 获得某个字符在 字符串中 出现第n次时的 下标 - * - * @param res - * @param _c - * @param index - * @return - */ - public static int getIndexChar(String res, String _c, int index) { - Matcher mh = Pattern.compile(_c).matcher(res); - int i = 0; - while (mh.find()) { - i++; - if (i == index) { - break; - } - } - return mh.start(); - } - - /** - * 将字符串转为指定字符集 - * @param str - * @param charSet - * @return - */ - public static String changeStrCharSet(String str, String charSet) { - if (isEmptyId(str)) return str; - String newStr = str; - try { - newStr = new String(str.getBytes(charSet), charSet); - } catch (UnsupportedEncodingException e) { - return newStr; - } - return newStr; - } - - /** - * 转布尔 - * - * @param o - * @return - */ - public static boolean getBool(Object o) { - if (o == null) return false; - String v = o.toString(); - return "1".equals(v) || "t".equalsIgnoreCase(v) || "true".equalsIgnoreCase(v); - } - - /** - * 返回当恰能操作系统是否为Linux - * - * @return boolean - */ - public static boolean osIsLinux() { - String s = System.getProperty("os.name"); - return s != null && s.equalsIgnoreCase("linux"); - } - - public static boolean strAllEqual(String str) { - if (PubUtil.isEmptyId(str)) return true; - for (int i = 1; i < str.length(); i++) - if (str.charAt(i) != str.charAt(0)) return false; - return true; - } - - /** - * 对中文字段 list排序 - * - * @param list - * @param fun 获取排序的值 - * @param desc 降序 - * @throws Exception - */ - - public static void sortChineseStrList(List list, Function fun, boolean desc) { - list.sort((T o1, T o2) -> { - int rt = Collator.getInstance(Locale.CHINESE).compare(fun.apply(o1), fun.apply(o2)); - if (rt < 0) { - if (desc) { - return 1; - } - return -1; - } - if (rt > 0) { - if (desc) { - return -1; - } - return 1; - } - return 0; - }); - } - - - //遍历map - public static void doForMap(Map map, IMapEntryReader reader) throws Exception { - if (map == null) return; - for (Map.Entry entry : map.entrySet()) { - reader.readEntry(entry.getKey(), entry.getValue()); - } - } - - public interface IMapEntryReader { - void readEntry(K key, V value) throws Exception; - } -} diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/SqlUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/SqlUtil.java index f67d777..0d45675 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/SqlUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/SqlUtil.java @@ -1,10 +1,20 @@ package cc.smtweb.framework.core.util; +import cc.smtweb.framework.core.common.AbstractEnum; +import cc.smtweb.framework.core.common.IntEnum; +import cc.smtweb.framework.core.common.StrEnum; +import org.apache.commons.lang3.StringUtils; + +import java.util.List; + /** - * Created by Akmm at 2022/5/20 16:57 - * sql工具类 + * 注意:where参数表示是否已经加入了where关键字 + * + * @author : AKzz + * @version : $Revision:$ */ -public class SqlUtil { +@SuppressWarnings("UnusedDeclaration") +public abstract class SqlUtil { /** * 将sql中的表名替换成schema.table的格式 * @param sql @@ -14,5 +24,758 @@ public class SqlUtil { return sql; } + /** + * 补充SQL的字符串的==条件 + * + * @param where_is_exist 是否已经加入了where关键字 + */ + public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, int condition_value) { + return addSql_EQUALE_Expr(where_is_exist, sql, args, db_field_name, String.valueOf(condition_value)); + } + + public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, long condition_value) { + return addSql_EQUALE_Expr(where_is_exist, sql, args, db_field_name, String.valueOf(condition_value)); + } + + /** + * 补充SQL的字符串的==条件 + * + * @param where_is_exist 是否已经加入了where关键字 + */ + public static boolean addSql_EQUALE_Expr(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + if (!where_is_exist) { + sql.append(" WHERE "); + } else { + sql.append(" AND "); + } + sql.append(db_field_name).append(" = ? \n"); + args.add(condition_value); + } + return true; + } + + public static boolean addSql_lesser(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append(db_field_name).append(" <= ? \n"); + args.add(condition_value); + } + return where_is_exist; + } + + public static boolean addSql_greater(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append(db_field_name).append(" >= ? \n"); + args.add(condition_value); + } + return where_is_exist; + } + + + /** + * 补充SQL的字符串Like条件(仅后匹配) %s + * + * @param where_is_exist 是否已经加入了where关键字 + */ + public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + //mysq _ 是一个占位符需要加\进行处理 + condition_value = condition_value.replaceAll("_", "\\\\_"); + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append(db_field_name).append(" LIKE ? \n"); + args.add(String.format("%%%s", condition_value)); + } + return where_is_exist; + } + + public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + //mysq _ 是一个占位符需要加\进行处理 + condition_value = condition_value.replaceAll("_", "\\\\_"); + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append("(").append(db_field_names[0]).append(" LIKE ? \n"); + args.add(String.format("%%%s", condition_value)); + for (int i = 1; i < db_field_names.length; ++i) { + sql.append(" or ").append(db_field_names[i]).append(" LIKE ? \n"); + args.add(String.format("%%%s", condition_value)); + } + sql.append(")"); + } + return where_is_exist; + } + + public static boolean addSql_LIKE_EX(boolean where_is_exist, StringBuilder sql, List args, String condition_value, String... db_field_name) { + if (db_field_name == null || db_field_name.length == 0) return where_is_exist; + if (StringUtil.isNotEmpty(condition_value)) { + //mysq _ 是一个占位符需要加\进行处理 + condition_value = condition_value.replaceAll("_", "\\\\_"); + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + if (db_field_name.length == 1) { + sql.append(db_field_name[0]).append(" LIKE ? \n"); + args.add(String.format("%%%s%%", condition_value)); + return where_is_exist; + } + sql.append(" ("); + for (String db_filed : db_field_name) { + sql.append(" ").append(db_filed).append(" LIKE ? \nOR"); + args.add(String.format("%%%s%%", condition_value)); + } + sql.delete(sql.length() - 2, sql.length()); + sql.append(")\n"); + + } + return where_is_exist; + } + + + /** + * 补充SQL的字符串Like条件(仅后匹配) s% + * + * @param where_is_exist 是否已经加入了where关键字 + */ + public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + //mysq _ 是一个占位符需要加\进行处理 + condition_value = condition_value.replaceAll("_", "\\\\_"); + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append(db_field_name).append(" LIKE ? \n"); + args.add(String.format("%s%%", condition_value)); + } + return where_is_exist; + } + + + public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + //mysq _ 是一个占位符需要加\进行处理 + condition_value = condition_value.replaceAll("_", "\\\\_"); + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append("(").append(db_field_names[0]).append(" LIKE ? \n"); + args.add(String.format("%s%%", condition_value)); + for (int i = 1; i < db_field_names.length; ++i) { + sql.append(" or ").append(db_field_names[i]).append(" LIKE ? \n"); + args.add(String.format("%s%%", condition_value)); + } + sql.append(")"); + } + return where_is_exist; + } + + /** + * 补充SQL的字符串Like条件(全模糊) %s% + * + * @param where_is_exist 是否已经加入了where关键字 + */ + public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + //mysq _ 是一个占位符需要加\进行处理 + condition_value = condition_value.replaceAll("_", "\\\\_"); + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append(db_field_name).append(" LIKE ? \n"); + args.add(String.format("%%%s%%", condition_value)); + } + return where_is_exist; + } + + public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { + if (StringUtil.isNotEmpty(condition_value)) { + //mysq _ 是一个占位符需要加\进行处理 + condition_value = condition_value.replaceAll("_", "\\\\_"); + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append("(").append(db_field_names[0]).append(" LIKE ? "); + args.add(String.format("%%%s%%", condition_value)); + for (int i = 1; i < db_field_names.length; ++i) { + sql.append(" OR ").append(db_field_names[i]).append(" LIKE ? "); + args.add(String.format("%%%s%%", condition_value)); + } + sql.append(")"); + } + return where_is_exist; + } + + /** + * 补充SQL字符串的IN条件 + * + * @param where_is_exist 是否已经加入了where关键字 + */ + public static boolean addSql_IN_Expr(boolean where_is_exist, StringBuilder sql, String db_field_name, Object... expr) { + if (expr != null && expr.length > 0) { + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append(db_field_name).append(" IN (").append(StringUtils.join(expr, ',')).append(")\n"); + } + return where_is_exist; + } + + /** + * 补充SQL字符串的not IN条件 + * + * @param where_is_exist 是否已经加入了where关键字 + */ + public static boolean addSql_NOTIN_Expr(boolean where_is_exist, StringBuilder sql, String db_field_name, Object... expr) { + if (expr != null && expr.length > 0) { + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + sql.append(db_field_name).append(" NOT IN (").append(StringUtils.join(expr, ',')).append(")\n"); + } + return where_is_exist; + } + + /** + * 增加字符串字段条件,可能多选 + * + * @param field 查询的字段名 + * @param value 值,包含','为多选 + * @param sql sql + * @param paras 参数 + */ + public static void addStrConMulti(String field, String value, StringBuilder sql, List paras) { + if (StringUtil.isEmpty(value)) + return; + if (value.contains(",")) {//多选 + sql.append(" and ").append(field).append(" in ('").append(value.replaceAll(",", "','")).append("')"); + } else if (!Consts.NULL_STRING.equals(value)) {//单 + sql.append(" and ").append(field).append("=?"); + paras.add(value); + } + } + + /** + * 增加字符串字段条件,不判断多选 + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + public static void addStrConSingle(String field, String value, StringBuilder sb, List paras) { + addStrConSingle(field, "=", value, sb, paras); + } + + /** + * 增加字符串字段条件,不判断多选 + * + * @param field 查询的字段名 + * @param opt 逻辑运算符 + * @param value 值 + * @param paras 参数 + */ + public static void addStrConSingle(String field, String opt, String value, StringBuilder sb, List paras) { + if (StringUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) {//单 + sb.append(" and ").append(field).append(" ").append(opt).append(" ? \n"); + paras.add(value); + } + } + /** + * 增加字符串字段条件,包含 + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + public static void addStrConSingleLike(String field, String value, StringBuilder sb, List paras) { + if (StringUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) {//单 + sb.append(" and ").append(field).append(" like ? \n"); + paras.add("%" + value + "%"); + } + } + + /** + * 增加字符串字段条件并且不区分大小写,包含 + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + public static void addStrConSingleLikeIgnoreCase(String field, String value, StringBuilder sb, List paras) { + if (StringUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value)) { + String valueLower = value.toLowerCase(); + sb.append(" and ").append("lower(").append(field).append(")").append(" like ? \n"); + paras.add("%" + valueLower + "%"); + } + } + + /** + * 增加数字字段条件,可能多选 + * + * @param field 查询的字段名 + * @param value 值,包含','为多选 + * @param paras 参数 + */ + public static void addNumberConMulti(String field, String value, StringBuilder sb, List paras) { + if (StringUtil.isEmpty(value)) + return; + if (value.contains(",")) {//多选 + sb.append(" and ").append(field).append(" in (").append(value).append(") \n"); + } else if (!Consts.NULL_STRING.equals(value)) {//单 + sb.append(" and ").append(field).append("=? \n"); + paras.add(value); + } + } + + /** + * 增加数字字段条件,单选 + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + public static void addNumConSingle(String field, Number value, StringBuilder sb, List paras) { + addNumConSingle(field, "=", value, sb, paras); + } + + /** + * 增加数字字段条件,单选 + * + * @param field 查询的字段名 + * @param opt 运算符 + * @param value 值 + * @param paras 参数 + */ + public static void addNumConSingle(String field, String opt, Number value, StringBuilder sb, List paras) { + sb.append(" and ").append(field).append(opt).append("? \n"); + paras.add(value); + } + + /** + * 增加日期字段条件,可能多选 + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + @Deprecated + public static void addDateCon(String field, String value, StringBuilder sb, List paras) { + if (StringUtil.isEmpty(value)) + return; + String[] st = value.split(","); + if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 + return; + } + String s = DateUtil.nowDateString(); + if (st.length > 0) { + switch (st[0]) { + case "D": //当天 考虑日期时间的情况 + sb.append(" and ").append(field).append(">='").append(s).append("' and ").append(field).append("<'").append(DateUtil.getAfterDays(s, 1)).append("' \n"); + break; + case "W": //本周 + s = DateUtil.toStdDateString(DateUtil.getWeekStart()); + sb.append(" and ").append(field).append(">='").append(s).append("' and ").append(field).append("<'").append(DateUtil.getAfterDays(s, 8)).append("' \n"); + break; + case "M": //本月 + sb.append(" and ").append(field).append(">='").append(DateUtil.getMonthStart()).append("' and ").append(field).append("<='").append(DateUtil.getMonthEnd()).append(" 23:59:59' \n"); + break; + case "Q": //本季度 + sb.append(" and ").append(field).append(">='").append(DateUtil.getSeasonFirstDay()).append("' and ").append(field).append("<='").append(DateUtil.getSeasonLastDay()).append(" 23:59:59' \n"); + break; + case "Y": //本年 + sb.append(" and ").append(field).append(">='").append(DateUtil.getYearFirstDay()).append("' and ").append(field).append("<='").append(DateUtil.getYearLastDay()).append(" 23:59:59' \n"); + break; + default: //自定义 + String df, de; + if (st.length > 1) + df = st[1]; + else + df = ""; + if (st.length > 2) + de = st[2]; + else + de = ""; + if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) + return; + if (StringUtil.isEmpty(df)) { + sb.append(" and ").append(field).append("<=?"); + paras.add(de); + } else if (StringUtil.isEmpty(de)) { + sb.append(" and ").append(field).append(">=?"); + paras.add(df); + } else { + sb.append(" and ").append(field).append(">=? and ").append(field).append("<=? \n"); + paras.add(df); + paras.add(de); + } + break; + } + } + } + + /** + * 增加日期字段条件,可能多选(huangxl:日期格式YYYYMMDD) + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + public static void addDateConEx(String field, String value, StringBuilder sb, List paras) { + if (StringUtil.isEmpty(value)) + return; + String[] st = value.split(","); + if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 + return; + } + String s = DateUtil.nowDateString(); + if (st.length > 0) { + switch (st[0]) { + case "D": //当天 + sb.append(" and ").append(field).append("=").append(DateUtil.getDateLong(s)).append(" \n"); + break; + case "W": //本周 + s = DateUtil.toStdDateString(DateUtil.getWeekStart()); + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateLong(s)).append(" and ").append(DateUtil.getDateLong(DateUtil.getAfterDays(s, 7))).append(" \n"); + break; + case "M": //本月 + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateLong(DateUtil.getMonthStart())).append(" and ").append(DateUtil.getDateLong(DateUtil.getMonthEnd())).append(" \n"); + break; + case "Q": //本季度 + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateLong(DateUtil.getSeasonFirstDay())).append(" and ").append(DateUtil.getDateLong(DateUtil.getSeasonLastDay())).append(" \n"); + break; + case "Y": //本年 + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateLong(DateUtil.getYearFirstDay())).append(" and ").append(DateUtil.getDateLong(DateUtil.getYearLastDay())).append(" \n"); + break; + default: //自定义 + String df, de; + if (st.length > 1) + df = st[1]; + else + df = ""; + if (st.length > 2) + de = st[2]; + else + de = ""; + if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) + return; + if (StringUtil.isEmpty(df)) { + sb.append(" and ").append(field).append("<=?"); + paras.add(DateUtil.getDateLong(de)); + } else if (StringUtil.isEmpty(de)) { + sb.append(" and ").append(field).append(">=?"); + paras.add(DateUtil.getDateLong(df)); + } else { + sb.append(" and ").append(field).append(" between ? and ? \n"); + paras.add(DateUtil.getDateLong(df)); + paras.add(DateUtil.getDateLong(de)); + } + break; + } + } + } + + /** + * 增加期间查询日期字段条件,可能多选(huangxl:日期格式YYYYMMDD) + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + public static void addPeriodDateConEx(String field, String value, StringBuilder sb, List paras) { + if (StringUtil.isEmpty(value)) + return; + String[] st = value.split(","); + if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 + return; + } + String df, de; + if (st.length > 1) + df = st[1]; + else + df = ""; + if (st.length > 2) + de = st[2]; + else + de = ""; + + sb.append(" and ").append(field).append(" between ? and ? \n"); + paras.add(df + "01"); + paras.add(de + "31"); + } + + + /** + * 增加日期时间字段条件 + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + public static void addDateTimeConEx(String field, String value, StringBuilder sb, List paras) { + if (StringUtil.isEmpty(value)) + return; + String[] st = value.split(","); + if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 + return; + } + String s = DateUtil.nowDateString(); + if (st.length > 0) { + switch (st[0]) { + case "D": //当天 + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(s)).append(" and ").append(DateUtil.getEndDateTimeLong(s)).append(" \n"); + break; + case "W": //本周 + s = DateUtil.toStdDateString(DateUtil.getWeekStart()); + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(s)).append(" and ").append(DateUtil.getEndDateTimeLong(DateUtil.getAfterDays(s, 6))).append(" \n"); + break; + case "M": //本月 + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(DateUtil.getMonthStart())).append(" and ").append(DateUtil.getEndDateTimeLong(DateUtil.getMonthEnd())).append(" \n"); + break; + case "Q": //本季度 + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(DateUtil.getSeasonFirstDay())).append(" and ").append(DateUtil.getEndDateTimeLong(DateUtil.getSeasonLastDay())).append(" \n"); + break; + case "Y": //本年 + sb.append(" and ").append(field).append(" between ").append(DateUtil.getDateTimeLong(DateUtil.getYearFirstDay())).append(" and ").append(DateUtil.getEndDateTimeLong(DateUtil.getYearLastDay())).append(" \n"); + break; + default: //自定义 + String df, de; + if (st.length > 1) + df = st[1]; + else + df = ""; + if (st.length > 2) + de = st[2]; + else + de = ""; + if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) + return; + if (StringUtil.isEmpty(df)) { + sb.append(" and ").append(field).append("<=?"); + paras.add(DateUtil.getEndDateTimeLong(de)); + } else if (StringUtil.isEmpty(de)) { + sb.append(" and ").append(field).append(">=?"); + paras.add(DateUtil.getDateTimeLong(df)); + } else { + sb.append(" and ").append(field).append(" between ? and ? \n"); + paras.add(DateUtil.getDateTimeLong(df)); + paras.add(DateUtil.getEndDateTimeLong(de)); + } + break; + } + } + } + + /** + * 枚举状态字段,in方式 + * + * @param where_is_exist sql是否已包括where + * @param field sql字段名 + * @param value 前端传回来的查询值,格式:1,1,1,1 + * @param intEnum 枚举类型 + * @param sql 待构建的sql + */ + public static void addIntEnumCon(boolean where_is_exist, String field, String value, IntEnum intEnum, StringBuilder sql) { + if (StringUtil.isNotEmpty(value) && value.contains("1") && value.contains("0")) { + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + String s = ""; + String[] ss = value.split(","); + int i = 0; + for (AbstractEnum.IntEnumBean b : intEnum.values()) { + if (ss.length > i && "1".equals(ss[i])) s += "," + b.value; + i++; + } + sql.append(field + " in (" + s.substring(1) + ")"); + } + } + + /** + * 枚举状态字段,in方式 + * + * @param where_is_exist sql是否已包括where + * @param field sql字段名 + * @param value 前端传回来的查询值,格式:1,1,1,1 + * @param intEnum 枚举类型 + * @param sql 待构建的sql + */ + public static void addStrEnumCon(boolean where_is_exist, String field, String value, StrEnum intEnum, StringBuilder sql) { + if (StringUtil.isNotEmpty(value) && value.contains("1") && value.contains("0")) { + if (!where_is_exist) { + sql.append(" WHERE "); + where_is_exist = true; + } else { + sql.append(" AND "); + } + String s = ""; + String[] ss = value.split(","); + int i = 0; + for (AbstractEnum.StrEnumBean b : intEnum.values()) { + if (ss.length > i && "1".equals(ss[i])) s += ",'" + b.value + "'"; + i++; + } + sql.append(field + " in (" + s.substring(1) + ")"); + } + } + + public static void addTreeStateCon(String curPrefix, String value, String tableName, StringBuilder sb, List paras) { + if (StringUtil.isNotEmpty(value) && !Consts.NULL_STRING.equals(value) && !value.contains(",")) { + int v = NumberUtil.getIntIgnoreErr(value); + if (v == 0) {//查启用 自己启用,且父亲未停用 + sb.append(" and ").append(curPrefix).append(".f_status=0 and not exists(select 1 from ").append(tableName).append(" p__ where p__.f_status=1 and ").append(curPrefix).append(".f_level_code like p__.f_level_code || '-%')"); + } else {//查停用 自己停用 或父亲被停用 + sb.append(" and (").append(curPrefix).append(".f_status=1 or exists(select 1 from ").append(tableName).append(" p__ where p__.f_status=1 and ").append(curPrefix).append(".f_level_code like p__.f_level_code || '-%'))"); + } + } + } + + /** + * 增加年月字段条件 + * + * @param field 查询的字段名 + * @param value 值 + * @param paras 参数 + */ + public static void addYmCon(String field, String value, StringBuilder sb, List paras) { + addYmConEx(field, field, value, sb, paras); + } + + public static void addYmConEx(String field_begin, String field_end, String value, StringBuilder sb, List paras) { + if (StringUtil.isEmpty(value)) + return; + String[] st = value.split(","); + if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) {//无 + return; + } + if (st.length > 1) { + switch (st[0]) { + case "M": //本月 + String nowYm = DateUtil.getNowYm(); + sb.append(" and ").append(field_end).append(">='").append(DateUtil.getNowYm()).append("' and ").append(field_begin).append("<='").append(nowYm).append("'"); + break; + case "Q": //本季度 + sb.append(" and ").append(field_end).append(">='").append(DateUtil.getSeasonBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getSeasonEndYm()).append("'"); + break; + case "Y": //本年 + sb.append(" and ").append(field_end).append(">='").append(DateUtil.getYearBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getYearEndYm()).append("'"); + break; + default: //自定义 + String df, de; + if (st.length > 1) + df = st[1]; + else + df = ""; + if (st.length > 2) + de = st[2]; + else + de = ""; + if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) + return; + if (StringUtil.isEmpty(df)) { + sb.append(" and ").append(field_begin).append("<=?"); + paras.add(de); + } else if (StringUtil.isEmpty(de)) { + sb.append(" and ").append(field_end).append(">=?"); + paras.add(df); + } else { + sb.append(" and ").append(field_end).append(">=? and ").append(field_begin).append("<=?"); + paras.add(df); + paras.add(de); + } + break; + } + } else if (st.length == 1) { + sb.append(" and ").append(field_end).append(">='").append(value).append("' and ").append(field_begin).append("<='").append(value).append("'"); + } + } + + //构建年月范围的sql + public static String getYmConSql(String field, String value) { + return getYmConSqlEx(field, field, value); + } + + public static String getYmConSqlEx(String field_begin, String field_end, String value) { + if (StringUtil.isEmpty(value)) return ""; + String[] st = value.split(","); + if (st.length == 0 || Consts.NULL_STRING.equals(st[0])) return ""; + StringBuilder sb = new StringBuilder(128); + + switch (st[0]) { + case "M": //本月 + String nowYm = DateUtil.getNowYm(); + sb.append(" and ").append(field_end).append(">='").append(DateUtil.getNowYm()).append("' and ").append(field_begin).append("<='").append(nowYm).append("'"); + break; + case "Q": //本季度 + sb.append(" and ").append(field_end).append(">='").append(DateUtil.getSeasonBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getSeasonEndYm()).append("'"); + break; + case "Y": //本年 + sb.append(" and ").append(field_end).append(">='").append(DateUtil.getYearBeginYm()).append("' and ").append(field_begin).append("<='").append(DateUtil.getYearEndYm()).append("'"); + break; + default: //自定义 + String df, de; + if (st.length > 1) + df = st[1]; + else + df = ""; + if (st.length > 2) + de = st[2]; + else + de = ""; + if (StringUtil.isEmpty(df) && StringUtil.isEmpty(de)) + return ""; + if (StringUtil.isEmpty(df)) { + sb.append(" and ").append(field_begin).append("<='").append(de).append("'"); + } else if (StringUtil.isEmpty(de)) { + sb.append(" and ").append(field_end).append(">='").append(df).append("'"); + } else { + sb.append(" and ").append(field_end).append(">='").append(df).append("' and ").append(field_begin).append("<='").append(de).append("'"); + } + break; + } + return sb.substring(5); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/StringUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/StringUtil.java index 5a2e127..eac0ee3 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/StringUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/StringUtil.java @@ -17,6 +17,15 @@ import java.util.*; public class StringUtil { private static Collator chineseCollator = Collator.getInstance(Locale.CHINA); + public static boolean isEmpty(String str) { + return str == null || str.trim().length() == 0 || "-".equals(str); + } + + public static boolean isNotEmpty(String cs) { + return !isEmpty(cs); + } + + /** * strSrc中寻找第一个strSe并且返回以其分隔的Left部分,汉字长度也为1 * @@ -25,9 +34,9 @@ public class StringUtil { * @return String 返回 */ public static String getLeft(String strSrc, String strSe) { - if (PubUtil.isEmpty(strSrc)) + if (isEmpty(strSrc)) return ""; - if (PubUtil.isEmpty(strSe)) + if (isEmpty(strSe)) strSe = " "; String result = ""; @@ -45,7 +54,7 @@ public class StringUtil { * @return String return */ public static String getLeft(String strSrc, int count) { - if (PubUtil.isEmpty(strSrc) || count <= 0) { + if (isEmpty(strSrc) || count <= 0) { return ""; } if (strSrc.length() < count) { @@ -63,9 +72,9 @@ public class StringUtil { * @return String right部分 */ public static String getRight(String strSrc, String strSe) { - if (PubUtil.isEmpty(strSrc)) + if (isEmpty(strSrc)) return ""; - if (PubUtil.isEmpty(strSe)) + if (isEmpty(strSe)) strSe = " "; String result = strSrc; @@ -83,7 +92,7 @@ public class StringUtil { * @return String return */ public static String getRight(String strSrc, int count) { - if (PubUtil.isEmpty(strSrc) || count <= 0) { + if (isEmpty(strSrc) || count <= 0) { return ""; } int l = strSrc.length(); @@ -196,7 +205,7 @@ public class StringUtil { * @return 处理结果 */ public static String cutStringLeft(String src, String cut) { - if (PubUtil.isEmpty(src) || PubUtil.isEmpty(cut)) { + if (isEmpty(src) || isEmpty(cut)) { return ""; } if (src.startsWith(cut)) { @@ -207,7 +216,7 @@ public class StringUtil { } public static String cutStringRight(String src, String cut) { - if (PubUtil.isEmpty(src) || PubUtil.isEmpty(cut)) { + if (isEmpty(src) || isEmpty(cut)) { return ""; } while (src.endsWith(cut)) @@ -447,7 +456,7 @@ public class StringUtil { return myReplaceStrEx(express, b, e, new IStrHanlder() { @Override public String work(String src) { - return PubUtil.checkNull(mapVals.get(src)); + return checkNull(mapVals.get(src)); } }); } @@ -473,6 +482,29 @@ public class StringUtil { return "true".equalsIgnoreCase(s) || "1".equals(s) || "y".equalsIgnoreCase(s); } + /** + * 功能:null过滤,返回默认值 + * + * @param strValue 带检查的字符串 + * @param defaultValue 为空返回的字符串 + * @return str + */ + public static String checkNull(String strValue, String defaultValue) { + return strValue == null ? defaultValue : strValue; + } + + /** + * Func:为空,返回"" + * + * @param str 带检查的字符串 + * @return "" + */ + public static String checkNull(String str) { + if (isEmpty(str)) + return ""; + return str.trim(); + } + /*Blob转String*/ // public static String blob2Str(Blob blob) { // if (blob == null) return ""; @@ -507,7 +539,7 @@ public class StringUtil { String[] ss = src.split(ch); int[] ret = new int[ss.length]; for (int i = 0, len = ss.length; i < len; i++) { - ret[i] = PubUtil.getIntIgnoreErr(ss[i]); + ret[i] = NumberUtil.getIntIgnoreErr(ss[i]); } return ret; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/XmlUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/XmlUtil.java index 4645c61..35ea056 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/XmlUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/XmlUtil.java @@ -124,7 +124,7 @@ public class XmlUtil { //获取节点属性,转为字符串数组 public static String[] getAttrStrArray(Element e, String attrName) { String s = getAttribute(e, attrName); - if (PubUtil.isNotEmptyStr(s)) return StringUtil.split(s, ",").toArray(new String[]{}); + if (StringUtil.isNotEmpty(s)) return StringUtil.split(s, ",").toArray(new String[]{}); return new String[0]; } @@ -133,17 +133,17 @@ public class XmlUtil { String[] ss = getAttrStrArray(e, attrName); int[] ret = new int[ss.length]; for (int i = 0, len = ss.length; i < len; i++) { - ret[i] = PubUtil.getIntIgnoreErr(ss[i]); + ret[i] = NumberUtil.getIntIgnoreErr(ss[i]); } return ret; } public static int getAttributeInt(Element e, String attrName) { - return PubUtil.getIntIgnoreErr(getAttribute(e, attrName)); + return NumberUtil.getIntIgnoreErr(getAttribute(e, attrName)); } public static double getAttributeDbl(Element e, String attrName) { - return PubUtil.getDoubleIgnoreErr(getAttribute(e, attrName)); + return NumberUtil.getDoubleIgnoreErr(getAttribute(e, attrName)); } public static boolean getAttributeBool(Element e, String attrName) { @@ -153,7 +153,7 @@ public class XmlUtil { //获取节点属性 public static String getAttributeIgnoreNull(Element e, String attrName) { - return PubUtil.checkNull(getAttribute(e, attrName)); + return StringUtil.checkNull(getAttribute(e, attrName)); } //读取节点所有属性,返回map @@ -173,7 +173,7 @@ public class XmlUtil { //设置节点属性 public static void setAttribute(Element e, String attrName, String attrValue) { - if (PubUtil.isNotEmpty(attrValue)) e.addAttribute(attrName, attrValue); + if (StringUtil.isNotEmpty(attrValue)) e.addAttribute(attrName, attrValue); else removeAttribute(e, attrName); } @@ -185,7 +185,7 @@ public class XmlUtil { //设置节点属性 public static void setAttribute(Element e, String attrName, double attrValue) { - if (!MathUtil.isEqualsZero(attrValue)) e.addAttribute(attrName, String.valueOf(attrValue)); + if (!NumberUtil.isEqualsZero(attrValue)) e.addAttribute(attrName, String.valueOf(attrValue)); else removeAttribute(e, attrName); } From 4571518688aa9c6024a02d0e4cb7d52f93fc3f16 Mon Sep 17 00:00:00 2001 From: zhenggm Date: Tue, 6 Sep 2022 20:15:46 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=83=A8=E5=88=86Util=EF=BC=8C=E5=8E=9FPubUtil?= =?UTF-8?q?=E5=88=86=E6=95=A3=E5=88=B0CommUtil=E5=92=8CStringUtil=E3=80=81?= =?UTF-8?q?NumberUtil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bpm/spring/controller/AttachController.java | 4 +- .../bpm/spring/file/attach/AttachHelper.java | 6 +- .../java/cc/smtweb/system/bpm/util/UtilMath.java | 465 ------------------- .../java/cc/smtweb/system/bpm/util/UtilString.java | 506 --------------------- 4 files changed, 5 insertions(+), 976 deletions(-) delete mode 100644 smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilMath.java delete mode 100644 smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilString.java diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java index 732f75f..6f908a6 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java @@ -4,6 +4,7 @@ import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.util.Consts; import cc.smtweb.framework.core.util.DateUtil; +import cc.smtweb.framework.core.util.NumberUtil; import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.spring.config.FileConfigProperties; import cc.smtweb.system.bpm.spring.file.attach.AttachHelper; @@ -11,7 +12,6 @@ import cc.smtweb.system.bpm.spring.file.attach.AttachUtil; import cc.smtweb.system.bpm.util.UtilDownloadFile; import cc.smtweb.system.bpm.util.UtilFile; import cc.smtweb.system.bpm.util.UtilLogger; -import cc.smtweb.system.bpm.util.UtilMath; import cc.smtweb.system.bpm.web.sys.base.attach.AttachInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; @@ -372,7 +372,7 @@ public class AttachController { if (h > height) { r = Math.min(1.0 * height / h, r); } - if (!UtilMath.isEqualsZero(r - 1)) { + if (!NumberUtil.isEqualsZero(r - 1)) { w = (int) Math.round(w * r); h = (int) Math.round(h * r); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java index d1b5a8d..129e9ed 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java @@ -3,10 +3,10 @@ package cc.smtweb.system.bpm.spring.file.attach; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.DateUtil; +import cc.smtweb.framework.core.util.NumberUtil; import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.spring.config.FileConfigProperties; import cc.smtweb.system.bpm.util.UtilFile; -import cc.smtweb.system.bpm.util.UtilMath; import cc.smtweb.system.bpm.web.sys.base.attach.AttachInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -228,9 +228,9 @@ public final class AttachHelper { public String getSizeStr(long fileSize) { if (fileSize < 1024) return fileSize + "B"; double n = fileSize * 1.0 / 1024; - if (UtilMath.compare(n, 1024) < 0) return UtilMath.toStdNumberString(n, 0) + "KB"; + if (NumberUtil.compare(n, 1024) < 0) return NumberUtil.toStdNumberString(n, 0) + "KB"; n = n / 1024; - return UtilMath.toStdNumberString(n) + "MB"; + return NumberUtil.toStdNumberString(n) + "MB"; } /** diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilMath.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilMath.java deleted file mode 100644 index cc882a4..0000000 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilMath.java +++ /dev/null @@ -1,465 +0,0 @@ -package cc.smtweb.system.bpm.util; - -import cc.smtweb.framework.core.util.StringUtil; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.text.DecimalFormat; - -/** - * Created with IntelliJ IDEA. - * User: AKhh - * Date: 12-12-25 下午1:02 - * To change this template use File | Settings | File Templates. - */ -public class UtilMath { - //整数 - private static DecimalFormat dfLng = new DecimalFormat("##############0"); - private static DecimalFormat dfLong = new DecimalFormat("###,###,###,###,##0"); - //一位小数 - private static DecimalFormat df1 = new DecimalFormat("##############0.0"); - private static DecimalFormat df1Format = new DecimalFormat("###,###,###,###,##0.0"); - //两位小数 - private static DecimalFormat df2 = new DecimalFormat("##############0.00"); - private static DecimalFormat df2Format = new DecimalFormat("###,###,###,###,##0.00"); - //四位小数 - private static DecimalFormat df4 = new DecimalFormat("###,###,###,###,##0.0000"); - //六位小数 - private static DecimalFormat df6Number = new DecimalFormat("#######################0.000000"); - private static DecimalFormat df6NumberF = new DecimalFormat("#,###,###,###,###,###,##0.000000"); - - public final static DecimalFormat stdAmountFormat = new DecimalFormat("###,###,###,###,##0.00"); - public final static DecimalFormat stdNumberFormat = new DecimalFormat("#0.00"); - public final static String DEF_NUM_TEN_THOUSAND = "10000";//万 - public static final double MAX_VALUE = 9999999999999.99D; - public static final double MIN_VALUE = -9999999999999.99D; - - private final static BigDecimal ONE_BIG = new BigDecimal(1.00D); - private static final String UNIT = "万仟佰拾亿仟佰拾万仟佰拾元角分"; - private static final String DIGIT = "零壹贰叁肆伍陆柒捌玖"; - - /** - * 4舍5入double,2位小数 - */ - public static double roundDouble(double src) { - return roundDouble(src, 2); - } - - /** - * 4舍5入double,N 位小数 - * @param src - * @param scale 小数位数 - * @return - */ - public static double roundDouble(Object src, int scale) { - if (src == null) return 0.0; - String v = src.toString(); - if (StringUtil.isEmpty(v)) return 0.0; - if (scale < 0) scale = 2; - - BigDecimal src_b = new BigDecimal(v); - BigDecimal src_v = src_b.divide(ONE_BIG, scale + 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 - src_v = src_v.divide(ONE_BIG, scale, BigDecimal.ROUND_HALF_UP);// 4舍5入 - return src_v.doubleValue(); - } - - /** - * 舍位处理,原生floor有坑,部分浮点数记录为.99999999999形式,导致floor结果错误 - * @param d - * @return - */ - public static double floor(double d) { - return Math.floor(UtilMath.roundDouble(d, 2)); - } - - /** - * 比较两Double是否相等,将会吧他们专程BigDecimal进行比较; - * - * @param src double1 - * @param tag double2 - * @return src > tag 返回1, src < tag 返回-1, 否则返回0 - */ - public static int compare(double src, double tag) { - BigDecimal src_b = new BigDecimal(src); - BigDecimal src_v = src_b.divide(ONE_BIG, 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 - - BigDecimal tag_b = new BigDecimal(tag); - BigDecimal tag_v = tag_b.divide(ONE_BIG, 2, BigDecimal.ROUND_HALF_UP);// 4舍5入 - - return src_v.compareTo(tag_v); - } - - /** - * 自动过滤金额中的逗号转换为double,如果出错,则返回0 - * - * @param s 源串,可能为带逗号的金额串; - * @return double - */ - public static Double toDouble(String s) { - return todouble(s); - } - - /** - * 自动过滤金额中的逗号转换为double,如果出错,则返回0 - * - * @param s 源串,可能为带逗号的金额串; - * @return double - */ - public static double todouble(String s) { - try { - return Double.parseDouble(s.replaceAll(",", "")); - } catch (Exception e) { - return 0.00; - } - } - - /** - * 获取double,主要过滤d为null的情况; - * - * @param d Double对象; - * @return double - */ - public static double todouble(Double d) { - if (d == null) return 0.0d; - return d.doubleValue(); - } - - /** - * 自动过滤金额中的逗号转换为float,如果出错,则返回0 - * - * @param s 源串,可能为带逗号的金额串; - * @return Float - */ - public static Float toFloat(String s) { - return tofloat(s); - } - - /** - * 自动过滤金额中的逗号转换为float,如果出错,则返回0 - * - * @param s 源串,可能为带逗号的金额串; - * @return Float - */ - public static float tofloat(String s) { - try { - return Float.parseFloat(s.replaceAll(",", "")); - } catch (Exception e) { - return 0.0f; - } - } - - public static long tolong(String src, long defaultvalue) { - try { - return Long.parseLong(src); - } catch (Exception e) { - return defaultvalue; - } - } - - public static int toint(String src, int defaultvalue) { - try { - return Integer.parseInt(src); - } catch (Exception e) { - return defaultvalue; - } - } - - /** - * 考虑使用中的精度,判断一个Value是否>0,实际是>0.00001 - * - * @param value double类型 - * @return boolean - */ - public static boolean isBigThanZero(double value) { - return (value > 0.00001); - } - - /** - * 考虑使用中的精度,判断一个Value是否>0,实际是>0.00001 - * - * @param value String类型 - * @return boolean - */ - public static boolean isBigThanZero(String value) { - return !StringUtil.isEmpty(value) && isBigThanZero(toDouble(value)); - } - - /** - * 考虑使用中的精度,判断一个Value是否=0,实际是给出一个值范围。 - * - * @param value double类型 - * @return boolean - */ - public static boolean isEqualsZero(double value) { - return (-0.00001 < value && value < 0.00001); - } - - /** - * 考虑使用中的精度,判断一个Value是否=0,实际是给出一个值范围。 - * - * @param value String类型 - * @return boolean - */ - public static boolean isEqualsZero(String value) { - return StringUtil.isEmpty(value) || isEqualsZero(toDouble(value)); - } - - /** - * 是否是负数 - * - * @param db_val 要判断的double - * @return 负数则返回true; - */ - public static boolean isNegative(double db_val) { - return (compare(db_val, 0.00D) == -1); - } - - /** - * 是否是正数 - * - * @param db_val 要判断的double - * @return 正数则返回true; - */ - public static boolean isPlus(double db_val) { - return (compare(db_val, 0.00D) == 1); - } - - /** - * 得到金额字符串,保持小数点2位 - * - * @param db 将double转换为金额字符串; - * @return 金额字符串#0.00; - */ - public static String toStdNumberString(double db) { - try { - return stdNumberFormat.format(db); - } catch (Exception e) { - return "0.00"; - } - } - - public static String toStdNumberStringEx(double db) { - try { - if (compare(db, -1d) == 0) return "-"; - return stdNumberFormat.format(db); - } catch (Exception e) { - return "0.00"; - } - } - - /** - * 将金额格式字符串,如23,333,093.01 去掉逗号 - * - * @param s 金额串 - * @return String 去掉逗号后的串,如果amount为空,则返回0.00 - */ - public static String toStdNumberString(String s) { - if (StringUtil.isEmpty(s)) - return "0.00"; - return stdNumberFormat.format(UtilMath.todouble(s)); - } - - /** - * 将数据转换为两位小数的数字格式; - * - * @param d 数据 - * @param isZeroToEmpty 如果未0,是否返回“”; - * @return 两位小数的字符串; - */ - public static String toStdNumberString(double d, boolean isZeroToEmpty) { - if (isEqualsZero(d)) { - return isZeroToEmpty ? "": "0.00"; - } - return stdNumberFormat.format(d); - } - - public static String toStdNumberString(String s, boolean isZeroToEmpty) { - return toStdNumberString(UtilMath.todouble(s), isZeroToEmpty); - } - - public static String toStdNumberString(double d, int scale) { - DecimalFormat dfn = null; - if (scale == 1) dfn = df1Format; - if (scale == 2) dfn = df2Format; - else if (scale == 4) dfn = df4; - else if (scale == 6) dfn = df6NumberF; - else if (scale <= 0) dfn = dfLong; - else { - StringBuilder sb = new StringBuilder("###,###,###,###,##0."); - for (int i = 0; i < scale; i++) sb.append("0"); - dfn = new DecimalFormat(sb.toString()); - } - return dfn.format(d); - } - - /** - * 将数字乘100,保留小数点后两位, 然后后面添加% - * - * @param d 值 - * @param isZeroToEmpty,如果值为0,是否返回空; - * @return 字符串; - */ - public static String toStdPercentNumberStr(double d, boolean isZeroToEmpty) { - if (d > -0.00000000001 && d < 0.00000000001) { - return isZeroToEmpty ? "": "0.00%"; - } - return toStdNumberString(d * 100) + "%"; - } - - - public static String toStdAmountString(double d) { - return toStdAmountString(d, false); - } - - /** - * 将数据转换为两位小数的金额格式,带逗号; - * - * @param d 数据 - * @param isZeroToEmpty 如果未0,是否返回“”; - * @return 金额格式的字符串; - */ - public static String toStdAmountString(double d, boolean isZeroToEmpty) { - if (isEqualsZero(d)) { - return isZeroToEmpty ? "": "0.00"; - } - return stdAmountFormat.format(d); - } - - public static String toStdAmountString(String s) { - return toStdAmountString(UtilMath.todouble(s), false); - } - - public static String toStdAmountString(String s, boolean isZeroToEmpty) { - return toStdAmountString(UtilMath.todouble(s), isZeroToEmpty); - } - - - /** - * 将小写金额转换为人民币大写金额 - * - * @param s 金额格式的串 - * @return String 转换结果 - */ - public static String toCapsAmountString(String s) { - if (StringUtil.isEmpty(s)) return ""; - return toCapsAmountString(todouble(s)); - } - - /** - * 将小写金额转换为人民币大写金额 - * - * @param v double - * @return String 转换结果 - */ - public static String toCapsAmountString(double v) { - if (v < MIN_VALUE || v > MAX_VALUE) return "参数非法!"; - - boolean negative = isNegative(v); - - if (negative) v = Math.abs(v); - long l = Math.round(v * 100); - if (l == 0) return "零元整"; - - String strValue = String.valueOf(l); - // i用来控制数 - int i = 0; - // j用来控制单位 - int j = UNIT.length() - strValue.length(); - StringBuilder rs = new StringBuilder(32); - boolean isZero = false; - for (; i < strValue.length(); i++, j++) { - char ch = strValue.charAt(i); - if (ch == '0') { - isZero = true; - if (UNIT.charAt(j) == '亿' || UNIT.charAt(j) == '万' || UNIT.charAt(j) == '元') { - rs.append(UNIT.charAt(j)); - isZero = false; - } - } else { - if (isZero) { - rs.append('零'); - isZero = false; - } - rs.append(DIGIT.charAt(ch - '0')).append(UNIT.charAt(j)); - } - } - if (rs.charAt(rs.length() - 1) != '分') - rs.append('整'); - - i = rs.indexOf("亿万"); - if (i > 0) rs.delete(i + 1, i + 2); // i+1 ->万 - - if (negative) - return rs.insert(0, '负').toString(); - else - return rs.toString(); - } - - /** - * 返回0 到 maxvalue的随机数 - * - * @param maxvalue 随机数的最大值 - * @return int - */ - public static int rnd(int maxvalue) { - return (int) (Math.random() * (maxvalue + 1)); - } - - - public static double chkDbNull(Double v) { - return v == null ? 0: v; - } - - public static double max(double d1, double d2) { - return compare(d1, d2) < 0 ? d2 : d1; - } - - public static double min(double d1, double d2) { - return compare(d1, d2) < 0 ? d1 : d2; - } - - - public static void main(String[] args) { - double aa=123456789.345678900005; - System.out.println("args0 = " + upDouble(aa,0)); - System.out.println("args1 = " + upDouble(aa,1)); - System.out.println("args2 = " + upDouble(aa,2)); - System.out.println("args3 = " + upDouble(aa,3)); - System.out.println("args4 = " + upDouble(aa,4)); - System.out.println("args5 = " + upDouble(aa,5)); - System.out.println("args5 = " + upDouble(aa,6)); - System.out.println("args5 = " + upDouble(aa,7)); - System.out.println("args5 = " + upDouble(aa,8)); - - } - - /** - * double 去尾法 - * @param src 待处理数据 - * @param scale 保留小数位数 - * @return - */ - public static double cutDouble(double src, int scale){ - String v = toStdNumberString(src, 6);//先到6位小数,再去计算,否则容易出错,如8.3成8.29999999999,舍位就成了8.29了 - DecimalFormat formater = new DecimalFormat(); - formater.setMaximumFractionDigits(scale); - formater.setGroupingSize(0); - formater.setRoundingMode(RoundingMode.FLOOR); - return new BigDecimal(formater.format(toDouble(v))).doubleValue(); - } - - /** - * double 进位法 - * @param src 待处理数据 - * @param scale 保留小数位数 - * @return - */ - public static double upDouble(double src, int scale){ - String v = toStdNumberString(src, 6);//先到6位小数,再去计算 - DecimalFormat formater = new DecimalFormat(); - formater.setMaximumFractionDigits(scale); - formater.setGroupingSize(0); - formater.setRoundingMode(RoundingMode.UP); - return new BigDecimal(formater.format(toDouble(v))).doubleValue(); - } -} diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilString.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilString.java deleted file mode 100644 index d8d8f8d..0000000 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilString.java +++ /dev/null @@ -1,506 +0,0 @@ -package cc.smtweb.system.bpm.util; - - -import cc.smtweb.framework.core.util.NumberUtil; -import cc.smtweb.framework.core.util.StringUtil; - -import java.text.Collator; -import java.util.*; - -/** - * Created with IntelliJ IDEA. - * User: AKhh - * Date: 12-12-24 下午5:09 - * To change this template use File | Settings | File Templates. - */ -@SuppressWarnings("UnusedDeclaration") -@Deprecated -public class UtilString { - private static Collator chineseCollator = Collator.getInstance(Locale.CHINA); - - /** - * strSrc中寻找第一个strSe并且返回以其分隔的Left部分,汉字长度也为1 - * - * @param strSrc 源字符串 - * @param strSe 分割字符 - * @return String 返回 - */ - public static String getLeft(String strSrc, String strSe) { - if (StringUtil.isEmpty(strSrc)) - return ""; - if (StringUtil.isEmpty(strSe)) - strSe = " "; - - String result = ""; - int pos = strSrc.indexOf(strSe); - if (pos >= 0) - result = strSrc.substring(0, pos); - return result; - } - - /** - * 返回字符串的左边部分,汉字长度也为1 - * - * @param strSrc 源串,如果为空,则返回“”; - * @param count 要获取的右边字符串长度,负数将返回“”,如果count>字符串长度,则返回整个字符串; - * @return String return - */ - public static String getLeft(String strSrc, int count) { - if (StringUtil.isEmpty(strSrc) || count <= 0) { - return ""; - } - if (strSrc.length() < count) { - return strSrc; - } else { - return strSrc.substring(0, count); - } - } - - /** - * strSrc中寻找第一个strSe并且返回以其分隔的Right部分,汉字长度也为1 - * - * @param strSrc 源串 - * @param strSe 分隔符,一个字符 - * @return String right部分 - */ - public static String getRight(String strSrc, String strSe) { - if (StringUtil.isEmpty(strSrc)) - return ""; - if (StringUtil.isEmpty(strSe)) - strSe = " "; - - String result = strSrc; - int pos = strSrc.indexOf(strSe); - if (pos >= 0) - result = strSrc.substring(pos + strSe.length()); - return result; - } - - /** - * 返回字符串的右边部分,汉字长度也为1 - * - * @param strSrc 源串 - * @param count 要获取的右边字符串长度,负数将返回“”,如果count>字符串长度,则返回整个字符串; - * @return String return - */ - public static String getRight(String strSrc, int count) { - if (StringUtil.isEmpty(strSrc) || count <= 0) { - return ""; - } - int l = strSrc.length(); - if (l <= count) { - return strSrc; - } - return strSrc.substring(l - count); - } - - /** - * 左边补齐字符 - * - * @param src 源串 - * @param pad 补齐字符 - * @param length 最终长度 - * @return 补齐后的字符串 - */ - public static String padLeft(String src, String pad, int length) { - StringBuilder sb = new StringBuilder(repeatString(pad, length)); - sb.append(src); - return sb.substring(sb.length() - length); - } - - public static String padLeft(long src, String pad, int length) { - StringBuilder sb = new StringBuilder(repeatString(pad, length)); - sb.append(src); - return sb.substring(sb.length() - length); - } - - public static String padRight(String src, String pad, int length) { - StringBuilder sb = new StringBuilder(length * pad.length() + src.length()); - sb.append(src).append(repeatString(pad, length)); - return sb.substring(0, length); - } - - public static String padRight(long src, String pad, int length) { - StringBuilder sb = new StringBuilder(length * pad.length()); - sb.append(src).append(repeatString(pad, length)); - return sb.substring(0, length); - } - - /** - * 由于jdk1.3提供的replace函数不能满足替换要求,自己写一个 - * - * @param src 源串 - * @param oldS 将... - * @param newS 替换成... - * @return 替换后的字符串 - */ - public static String replaceString(String src, String oldS, String newS) { - StringBuilder ret = new StringBuilder(64); - int pos = src.indexOf(oldS); - while (pos >= 0) { - ret.append(src, 0, pos).append(newS); - src = src.substring(pos + oldS.length()); - pos = src.indexOf(oldS); - } - ret.append(src); - return ret.toString(); - } - - /** - * 取得指定字符串左边的有效数字,首先去掉两边空格 - * - * @param s 源串 - * @return 串左边的有效数字 - */ - public static String getStringLeftNumber(String s) { - String ret = ""; - int dotCount = 0; - s = s.trim(); - char[] carr = s.toCharArray(); - for (char aCarr : carr) { - if (Character.isDigit(aCarr)) { - ret += aCarr; - } else if (aCarr == '.' && dotCount == 0) { - ret += aCarr; - dotCount++; - } else { - break; - } - } - if (ret.endsWith(".")) { - ret = ret.substring(0, ret.length() - 1); - } - return ret; - } - - /** - * 取得重复字串 - * - * @param repeatString 重复字串 - * @param count 重复次数 - * @return String - */ - public static String repeatString(String repeatString, int count) { - if (count <= 0) return ""; - StringBuilder ret = new StringBuilder(repeatString.length() * count); - for (int i = 1; i <= count; i++) { - ret.append(repeatString); - } - return ret.toString(); - } - - /** - * 去除字符串左边的指定字符串 - * - * @param src 源字符串 - * @param cut 要去掉的字符串; - * @return 处理结果 - */ - public static String cutStringLeft(String src, String cut) { - if (StringUtil.isEmpty(src) || StringUtil.isEmpty(cut)) { - return ""; - } - if (src.startsWith(cut)) { - return cutStringLeft(src.substring(cut.length()), cut); - } else { - return src; - } - } - - public static String cutStringRight(String src, String cut) { - if (StringUtil.isEmpty(src) || StringUtil.isEmpty(cut)) { - return ""; - } - while (src.endsWith(cut)) - src = src.substring(0, src.length() - cut.length()); - - return src; - } - - /** - * Removes all spaces from a string - * 可以替换大部分空白字符, 不限于空格,\s 可以匹配空格、制表符、换页符等空白字符的其中任意一个 - */ - public static String removeSpaces(String str) { - return str.replaceAll("\\s*", ""); - } - - /** - * Creates a single string from a List of strings seperated by a delimiter. - * - * @param list a list of strings to join - * @param delim the delimiter character(s) to use. (null value will join with no delimiter) - * @return a String of all values in the list seperated by the delimiter - */ - public static String join(List list, String delim) { - if (list == null || list.size() < 1) - return null; - StringBuffer buf = new StringBuffer(); - Iterator i = list.iterator(); - - while (i.hasNext()) { - buf.append((String) i.next()); - if (i.hasNext()) - buf.append(delim); - } - return buf.toString(); - } - - /** - * Splits a String on a delimiter into a List of Strings. - * - * @param str the String to split - * @param delim the delimiter character(s) to join on (null will split on whitespace) - * @return a list of Strings - */ - public static List split(String str, String delim) { - List splitList = new ArrayList<>(); - StringTokenizer st; - if (str == null) - return splitList; - - if (delim != null) - st = new StringTokenizer(str, delim); - else - st = new StringTokenizer(str); - - while (st.hasMoreTokens()) { - splitList.add(st.nextToken()); - } - return splitList; - } - - //是否为true,(1,y,true,yes) - public static boolean toBoolean(String v) { - return "1".equals(v) || "y".equalsIgnoreCase(v) || "true".equalsIgnoreCase(v) || "yes".equalsIgnoreCase(v); - } - - public static int chineseCompare(String s1, String s2) { - return chineseCollator.compare(s1, s2); - } - - /** - * 按照编码级次,得到类型的真实编码,主要用于like 'parentCode%' - * getSplitTypeCode('GF82000',2, 2, 1) == GF82 - * getSplitTypeCode('GF82100',3, 2, 1) == GF821 - * getSplitTypeCode('82100' ,3, 0, 1) == 821 - * - * @param curLevel 当前编码的所在层次 - * @param startIndex 数字编码的开始选项 - * @param perSize 每层的数字编码长度 - */ - public static String getRealCode(String code, int curLevel, int startIndex, int perSize) { - StringBuilder sb = new StringBuilder(code.length()); - if (startIndex > 0) sb.append(code, 0, startIndex); - for (int i = startIndex, l = 0; i < code.length(); i += perSize) { - if (l < curLevel) { - sb.append(code, i, i + perSize); - ++l; - } else { - break; - } - } - return sb.toString(); - } - - //函数功能: 正整数 - public static boolean isPureNumber(String inputString) { - return inputString.matches("^[1-9]\\d*$"); - } - - //函数功能: 整数 - public static boolean isNumber(String inputString) { - return inputString.matches("^[-+][0-9]\\d*$"); - } - - //函数功能: 浮点数 - public static boolean isAmount(String inputString) { - return inputString.matches("^[-+]?[\\d,]+(\\.\\d+)?$"); - } - - //函数功能: 带千分号的整数 - public static boolean isFormatNumber(String inputString) { - return inputString.matches("^[-+]?[\\d,]+(\\d+)?$"); - } - - - //首字母大写 - public static String upFirst(String s) { - return s.substring(0, 1).toUpperCase() + s.substring(1); - } - - public static String padRightBytes(String src, String pad, int length) { - length -= src.replaceAll("[^\\x00-\\xff]", "**").length(); - return src + repeatString(pad, length); - } - - //按字节数取子串,begin不是按字节的 - public static String substrByte(String src, int begin, int len) { - StringBuilder sb = new StringBuilder(32); - char c; - int tl = src.length(); - for (int i = begin; i < len + begin && i < tl; i++) { - - c = src.charAt(i); - sb.append(c); - if (String.valueOf(c).replaceAll("[^\\x00-\\xff]", "**").length() > 1) { - // 遇到中文汉字,截取字节总数减1 - --len; - } - } - return sb.toString(); - } - - /** - * 通配符算法。 可以匹配"*"和"?" - * 如a*b?d可以匹配aAAAbcd - * - * @param pattern 匹配表达式 - * @param str 匹配的字符串 - * @return - */ - public static boolean match(String pattern, String str) { - if (pattern == null || str == null) - return false; - - boolean result = false; - char c; // 当前要匹配的字符串 - boolean beforeStar = false; // 是否遇到通配符* - int back_i = 0;// 回溯,当遇到通配符时,匹配不成功则回溯 - int back_j = 0; - int i, j; - for (i = 0, j = 0; i < str.length(); ) { - if (pattern.length() <= j) { - if (back_i != 0) {// 有通配符,但是匹配未成功,回溯 - beforeStar = true; - i = back_i; - j = back_j; - back_i = 0; - back_j = 0; - continue; - } - break; - } - - if ((c = pattern.charAt(j)) == '*') { - if (j == pattern.length() - 1) {// 通配符已经在末尾,返回true - result = true; - break; - } - beforeStar = true; - j++; - continue; - } - - if (beforeStar) { - if (str.charAt(i) == c) { - beforeStar = false; - back_i = i + 1; - back_j = j; - j++; - } - } else { - if (c != '?' && c != str.charAt(i)) { - result = false; - if (back_i != 0) {// 有通配符,但是匹配未成功,回溯 - beforeStar = true; - i = back_i; - j = back_j; - back_i = 0; - back_j = 0; - continue; - } - break; - } - j++; - } - i++; - } - - if (i == str.length() && j == pattern.length())// 全部遍历完毕 - result = true; - return result; - } - - //填充变量 - public static String myReplaceStrEx(String express, String b, String e, IStrHanlder hanlder) { - if (null == express) return express; - int keyBegin = 0, keyEnd = 0; - int lb = b.length(), le = e.length(); - String fn; - while (true) { - keyBegin = express.indexOf(b, keyBegin); - if (keyBegin < 0) break; - keyEnd = express.indexOf(e, keyBegin); - if (keyEnd <= keyBegin) break; - keyBegin++; - fn = express.substring(keyBegin + lb - 1, keyEnd); - fn = hanlder.work(fn); - if (fn != null) { - express = express.substring(0, keyBegin - 1) + fn + express.substring(keyEnd + le); - } - } - return express; - } - - //填充变量 - public static String myReplaceStrEx(String express, String b, String e, final Map mapVals) { - return myReplaceStrEx(express, b, e, new IStrHanlder() { - @Override - public String work(String src) { - return StringUtil.checkNull(mapVals.get(src)); - } - }); - } - - /*Blob转String*/ -// public static String blob2Str(Blob blob) { -// if (blob == null) return ""; -// ByteArrayOutputStream outStream = null; -// try { -// long len = blob.length(); -// if (len == 0L) return ""; -// byte[] bytes; -// long i = 1L; -// outStream = new ByteArrayOutputStream(); -// while (i < len) { -// bytes = blob.getBytes(i, 1024); -// i += 1024L; -// outStream.write(bytes); -// } -// -// return UtilEncode.base64EncodeB(outStream.toByteArray()); -// } catch (Exception e) { -// e.printStackTrace(); -// return ""; -// } finally { -// IOUtils.closeQuietly(outStream); -// } -// } - - - public interface IStrHanlder { - String work(String src); - } - - public static int[] splitStr(String src, String ch) { - String[] ss = src.split(ch); - int[] ret = new int[ss.length]; - for (int i = 0, len = ss.length; i < len; i++) { - ret[i] = NumberUtil.getIntIgnoreErr(ss[i]); - } - return ret; - } - - public static void main(String[] args) { - String s = "a[#[#123#]bcde[aaa]bcd"; - s = UtilString.myReplaceStrEx(s, "[#", "#]", new UtilString.IStrHanlder() { - @Override - public String work(String src) { - if (src.equals("123")) return "1"; - return null; - } - }); - System.out.println(s); - } -} From 0397ca5b77fa6b93f2c0fbcfceb26d16b3466963 Mon Sep 17 00:00:00 2001 From: zhenggm Date: Tue, 6 Sep 2022 20:19:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E5=A4=9A=E4=BD=99=E5=BC=95=E7=94=A8+=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smtweb/system/bpm/spring/BpmApplication.java | 2 +- .../system/bpm/spring/BpmAutoConfiguration.java | 12 +- .../cc/smtweb/system/bpm/spring/BpmConfigBean.java | 4 +- .../system/bpm/spring/config/FileConfig.java | 2 +- .../bpm/spring/config/FileConfigProperties.java | 2 +- .../bpm/spring/controller/AttachController.java | 107 ++- .../spring/controller/FileDownloadController.java | 293 ++++---- .../spring/controller/FileUploadController.java | 236 +++--- .../system/bpm/spring/dao/ImageAttachDao.java | 88 +-- .../smtweb/system/bpm/spring/dao/SysAttachDao.java | 142 ++-- .../dataCacheInit/AttachFolderEntityBuffer.java | 22 +- .../system/bpm/spring/entity/AttachPathPO.java | 12 +- .../system/bpm/spring/entity/FileDataVO.java | 2 +- .../system/bpm/spring/entity/UploadDataVO.java | 16 +- .../bpm/spring/file/attach/AttachFileWork.java | 7 +- .../bpm/spring/file/attach/AttachFtpWork.java | 3 +- .../bpm/spring/file/attach/AttachHelper.java | 77 +- .../system/bpm/spring/file/attach/AttachUtil.java | 29 +- .../bpm/spring/file/attach/IAttachWorkIntf.java | 10 +- .../system/bpm/spring/initPlugin/RunDataInit.java | 1 + .../java/cc/smtweb/system/bpm/util/BeanUtil.java | 162 ++-- .../cc/smtweb/system/bpm/util/CodeGenerator.java | 3 +- .../cc/smtweb/system/bpm/util/FileDynPath.java | 2 +- .../smtweb/system/bpm/util/FilePathGenerator.java | 125 ++-- .../cc/smtweb/system/bpm/util/FilePathInfo.java | 64 +- .../smtweb/system/bpm/util/ITreeDataHandler.java | 66 +- .../system/bpm/util/ITreeDataLevelHandler.java | 5 +- .../java/cc/smtweb/system/bpm/util/IdeaUtil.java | 11 +- .../smtweb/system/bpm/util/MemMultipartFile.java | 112 +-- .../java/cc/smtweb/system/bpm/util/ThumbImage.java | 175 ++--- .../cc/smtweb/system/bpm/util/TreeDataUtil.java | 330 ++++---- .../java/cc/smtweb/system/bpm/util/UtilFile.java | 8 +- .../java/cc/smtweb/system/bpm/util/XmlUtil.java | 117 +-- .../java/cc/smtweb/system/bpm/util/YamlUtil.java | 158 ++-- .../smtweb/system/bpm/util/ftp/FtpTaskManager.java | 13 +- .../system/bpm/util/ftp/IFtpServerConfig.java | 1 + .../cc/smtweb/system/bpm/util/ftp/IFtpUtil.java | 5 + .../smtweb/system/bpm/web/BpmStartedListener.java | 11 +- .../bpm/web/design/db/ModelCatalogCache.java | 2 +- .../bpm/web/design/db/ModelCatalogTreeHandler.java | 8 +- .../bpm/web/design/db/ModelCatalogTreeHelper.java | 6 +- .../bpm/web/design/db/ModelProjectCache.java | 15 +- .../system/bpm/web/design/flow/FlowConst.java | 1 + .../system/bpm/web/design/flow/ModelProc.java | 2 +- .../system/bpm/web/design/flow/ModelProcCache.java | 6 +- .../bpm/web/design/flow/ModelProcHelper.java | 6 +- .../bpm/web/design/flow/ModelProcLoadHandler.java | 2 - .../bpm/web/design/flow/ModelProcService.java | 10 +- .../bpm/web/design/flow/define/ProcInfo.java | 6 +- .../system/bpm/web/design/flow/define/Sign.java | 2 +- .../bpm/web/design/form/CodeBuildHandler.java | 4 +- .../system/bpm/web/design/form/ModelForm.java | 2 +- .../bpm/web/design/form/ModelFormDelHandler.java | 7 +- .../bpm/web/design/form/ModelFormHelper.java | 17 +- .../bpm/web/design/form/ModelFormLoadHandler.java | 11 +- .../web/design/form/define/BaseDatasetField.java | 1 + .../bpm/web/design/form/define/PageDatasets.java | 5 +- .../bpm/web/design/form/model/BaseModelWorker.java | 5 +- .../bpm/web/design/form/model/LcLtMsWorker.java | 4 +- .../bpm/web/design/form/model/LcLtWorker.java | 4 +- .../bpm/web/design/form/model/LcMsWorker.java | 6 +- .../bpm/web/design/form/model/LcNormalWorker.java | 4 +- .../bpm/web/design/form/model/ModelFactory.java | 5 +- .../design/form/model/flow/FlowSingleWorker.java | 11 +- .../system/bpm/web/design/preview/MenuVO.java | 84 +-- .../web/design/preview/PreviewMenuTreeService.java | 2 +- .../web/engine/dynPage/AbstractDynPageHandler.java | 5 +- .../bpm/web/engine/dynPage/DynPageHelper.java | 4 +- .../bpm/web/engine/dynPage/DynPageListHandler.java | 6 +- .../bpm/web/engine/dynPage/DynPageLoadHandler.java | 17 +- .../bpm/web/engine/dynPage/DynPageProvider.java | 6 +- .../bpm/web/engine/dynPage/DynPageService.java | 18 +- .../bpm/web/engine/dynPage/DynPageTreeHandler.java | 4 +- .../system/bpm/web/engine/dynPage/DynRetBean.java | 1 + .../bpm/web/engine/dynPage/IBuildSqlListener.java | 1 - .../system/bpm/web/engine/flow/FlowHelper.java | 4 +- .../system/bpm/web/engine/flow/FlowListener.java | 23 +- .../system/bpm/web/engine/flow/FlowProvider.java | 4 - .../system/bpm/web/engine/flow/entity/Comment.java | 99 ++- .../system/bpm/web/engine/flow/entity/FlowLog.java | 81 +- .../bpm/web/engine/flow/entity/ProcInst.java | 133 +++- .../system/bpm/web/engine/flow/entity/Task.java | 179 ++++- .../system/bpm/web/engine/flow/entity/TaskRel.java | 35 +- .../model/flow/listcard/single/FlowDelHandler.java | 3 +- .../flow/listcard/single/FlowListHandler.java | 2 +- .../listcard/single/FlowSingleLoadHandler.java | 13 +- .../listcard/single/FlowSingleSaveHandler.java | 3 +- .../flow/listcard/single/FlowSingleService.java | 5 +- .../flow/listcard/single/FlowTransHandler.java | 2 +- .../model/listcard/abshandler/AbsDelHandler.java | 2 +- .../model/listcard/abshandler/AbsLoadHandler.java | 11 +- .../model/listcard/abshandler/AbsSaveHandler.java | 4 +- .../model/listcard/lclc1/LCLC1DelHandler.java | 12 +- .../model/listcard/lclc1/LCLC1LoadHandler.java | 16 +- .../model/listcard/lclc1/LCLC1SaveHandler.java | 2 + .../engine/model/listcard/lclc1/LCLC1Service.java | 29 +- .../model/listcard/mastersub/LCMsDelHandler.java | 20 +- .../model/listcard/mastersub/LCMsLoadHandler.java | 14 +- .../model/listcard/mastersub/LCMsSaveHandler.java | 12 +- .../model/listcard/mastersub/LCMsService.java | 18 +- .../model/listcard/normal/LCNormalDelHandler.java | 6 +- .../model/listcard/normal/LCNormalLoadHandler.java | 1 + .../model/listcard/normal/LCNormalSaveHandler.java | 5 +- .../model/listcard/normal/LCNormalService.java | 16 +- .../model/listcard/single/LCSingleDelHandler.java | 3 +- .../model/listcard/single/LCSingleLoadHandler.java | 1 + .../model/listcard/single/LCSingleSaveHandler.java | 3 +- .../model/listcard/single/LCSingleService.java | 15 +- .../smtweb/system/bpm/web/login/AuthService.java | 9 +- .../smtweb/system/bpm/web/login/LoginHelper.java | 9 +- .../cc/smtweb/system/bpm/web/login/MenuPO.java | 6 +- .../cc/smtweb/system/bpm/web/login/UserPO.java | 2 +- .../system/bpm/web/sys/base/attach/AttachInfo.java | 107 ++- .../web/sys/base/attachFolder/AttachFolder.java | 45 +- .../system/bpm/web/sys/base/billFlow/BillFlow.java | 45 +- .../bpm/web/sys/base/billFlow/BillFlowCache.java | 3 - .../system/bpm/web/sys/base/billType/BillType.java | 36 +- .../bpm/web/sys/base/billType/BillTypeCache.java | 2 +- .../web/sys/base/billType/BillTypeSaveHandler.java | 1 - .../bpm/web/sys/base/billType/BillTypeService.java | 7 +- .../smtweb/system/bpm/web/sys/base/dict/Dict.java | 45 +- .../system/bpm/web/sys/base/dict/DictCache.java | 7 +- .../system/bpm/web/sys/base/dict/DictService.java | 1 - .../system/bpm/web/sys/base/dict/DictType.java | 45 +- .../bpm/web/sys/base/dict/DictTypeCache.java | 5 - .../system/bpm/web/sys/dev/EnumComboService.java | 10 +- .../system/bpm/web/sys/dev/FieldComboService.java | 6 +- .../smtweb/system/bpm/web/sys/user/area/Area.java | 90 ++- .../system/bpm/web/sys/user/area/AreaCache.java | 4 +- .../system/bpm/web/sys/user/area/AreaService.java | 9 +- .../web/sys/user/dataRight/DataRightDefine.java | 36 +- .../sys/user/dataRight/DataRightDefineCache.java | 5 - .../web/sys/user/dataRight/DataRightService.java | 6 +- .../sys/user/dataRightGroup/DataRightGroup.java | 54 +- .../user/dataRightGroup/DataRightGroupCache.java | 5 - .../user/dataRightGroup/DataRightGroupHandler.java | 2 - .../smtweb/system/bpm/web/sys/user/dept/Dept.java | 62 +- .../system/bpm/web/sys/user/dept/DeptCache.java | 1 + .../system/bpm/web/sys/user/menu/MenuNode.java | 2 +- .../system/bpm/web/sys/user/menu/MenuService.java | 6 +- .../system/bpm/web/sys/user/menuPlan/MenuPlan.java | 36 +- .../bpm/web/sys/user/menuPlan/MenuPlanContent.java | 13 +- .../bpm/web/sys/user/menuPlan/MenuPlanHandler.java | 12 +- .../bpm/web/sys/user/menuPlan/MenuPlanItem.java | 1 - .../bpm/web/sys/user/menuPlan/MenuPlanService.java | 10 +- .../system/bpm/web/sys/user/party/Party.java | 135 +++- .../smtweb/system/bpm/web/sys/user/role/Role.java | 72 +- .../system/bpm/web/sys/user/role/RoleHandler.java | 1 - .../smtweb/system/bpm/web/sys/user/user/User.java | 134 +++- .../system/bpm/web/sys/user/user/UserParty.java | 36 +- .../bpm/web/sys/user/user/UserPartyCache.java | 2 + .../system/bpm/web/sys/user/user/UserRole.java | 27 +- .../system/bpm/web/sys/user/user/UserService.java | 2 +- .../system/bpm/web/sys/user/user/UserStatu.java | 90 ++- .../bpm/web/sys/user/user/UserStatuCache.java | 5 - .../bpm/web/sys/user/userGroup/UserGroup.java | 47 +- .../bpm/web/sys/user/userGroup/UserGroupCache.java | 5 - .../sys/user/userGroup/UserGroupComboHandler.java | 3 - .../web/sys/user/userGroup/UserGroupHelper.java | 9 +- .../web/sys/user/userGroup/UserGroupService.java | 1 - .../system/bpm/web/sys/user/userSso/UserSso.java | 36 +- .../cc/smtweb/framework/core/CoreApplication.java | 6 +- .../core/CoreApplicationStartedListener.java | 2 - .../framework/core/CoreAutoConfiguration.java | 37 +- .../smtweb/framework/core/annotation/SwAction.java | 12 +- .../smtweb/framework/core/annotation/SwAttr.java | 6 +- .../smtweb/framework/core/annotation/SwBean.java | 14 +- .../smtweb/framework/core/annotation/SwBody.java | 6 +- .../smtweb/framework/core/annotation/SwCache.java | 4 + .../smtweb/framework/core/annotation/SwColumn.java | 45 +- .../framework/core/annotation/SwColumnForeign.java | 15 +- .../framework/core/annotation/SwConstruct.java | 12 +- .../framework/core/annotation/SwDestroy.java | 12 +- .../framework/core/annotation/SwHeaderParam.java | 4 +- .../smtweb/framework/core/annotation/SwParam.java | 9 +- .../framework/core/annotation/SwPathParam.java | 4 +- .../smtweb/framework/core/annotation/SwPerm.java | 15 +- .../framework/core/annotation/SwScheduling.java | 26 +- .../framework/core/annotation/SwService.java | 3 +- .../framework/core/annotation/SwStartListener.java | 1 + .../smtweb/framework/core/annotation/SwTable.java | 7 +- .../cc/smtweb/framework/core/cache/ISwCache.java | 38 +- .../core/cache/redis/RedisBroadcastEvent.java | 26 +- .../core/cache/redis/RedisPooledObjectFactory.java | 56 +- .../framework/core/cache/redis/RedisSysTask.java | 86 +-- .../core/cache/redis/config/RedisConfig.java | 4 +- .../smtweb/framework/core/common/AbstractEnum.java | 4 +- .../java/cc/smtweb/framework/core/common/R.java | 2 +- .../cc/smtweb/framework/core/common/SwEnum.java | 2 +- .../cc/smtweb/framework/core/common/SwIpAddr.java | 4 +- .../cc/smtweb/framework/core/db/BeanEntityDao.java | 57 +- .../java/cc/smtweb/framework/core/db/DbEngine.java | 2 + .../cc/smtweb/framework/core/db/EntityDao.java | 3 +- .../cc/smtweb/framework/core/db/EntityHelper.java | 8 +- .../framework/core/db/cache/EntityCache.java | 2 +- .../framework/core/db/cache/ModelTableCache.java | 13 +- .../core/db/config/DbEngineConfiguration.java | 30 +- .../core/db/config/YamlPropertyLoaderFactory.java | 12 +- .../core/db/dao/AbstractBeanEntityDao.java | 832 +++++++++++---------- .../framework/core/db/dao/AbstractEntityDao.java | 7 +- .../framework/core/db/dao/EntityColumnForeign.java | 30 +- .../cc/smtweb/framework/core/db/impl/BaseBean.java | 4 +- .../framework/core/db/impl/DatabaseUtil.java | 9 +- .../core/db/impl/DefaultDatabaseInfoImpl.java | 8 +- .../framework/core/db/impl/DefaultEntity.java | 2 +- .../smtweb/framework/core/db/jdbc/AbsDbWorker.java | 6 +- .../core/db/jdbc/BaseBeanPropertyRowMapper.java | 37 +- .../smtweb/framework/core/db/jdbc/IDbWorker.java | 9 +- .../smtweb/framework/core/db/jdbc/IdGenerator.java | 9 +- .../smtweb/framework/core/db/jdbc/JdbcEngine.java | 10 +- .../core/db/jdbc/MapPropertyRowMapper.java | 37 +- .../core/db/jdbc/SwMapPropertyRowMapper.java | 73 +- .../db/sqlbuilder/AbstractSelectSqlBuilder.java | 170 ++--- .../db/sqlbuilder/AbstractUpdateSqlBuilder.java | 20 +- .../core/db/sqlbuilder/DeleteSqlBuilder.java | 42 +- .../core/db/sqlbuilder/DirectSelectSqlBuilder.java | 20 +- .../core/db/sqlbuilder/InsertSqlBuilder.java | 46 +- .../core/db/sqlbuilder/SelectSqlBuilder.java | 112 +-- .../framework/core/db/sqlbuilder/SqlBuilder.java | 150 ++-- .../core/db/sqlbuilder/SqlFieldValue.java | 12 +- .../framework/core/db/sqlbuilder/SqlJoinField.java | 12 +- .../framework/core/db/sqlbuilder/SqlJoinTable.java | 45 +- .../core/db/sqlbuilder/SqlWhereValue.java | 12 +- .../core/db/sqlbuilder/UpdateSqlBuilder.java | 68 +- .../cc/smtweb/framework/core/db/vo/ModelCache.java | 2 +- .../cc/smtweb/framework/core/db/vo/ModelField.java | 1 + .../cc/smtweb/framework/core/db/vo/ModelTable.java | 7 +- .../core/exception/BindBeanException.java | 44 +- .../core/exception/BindParamException.java | 42 +- .../framework/core/exception/BizException.java | 34 +- .../framework/core/exception/DbException.java | 34 +- .../core/exception/JsonParseException.java | 6 +- .../framework/core/exception/SwException.java | 2 - .../framework/core/mvc/ISchedulerWakeup.java | 16 +- .../framework/core/mvc/SchedulerManager.java | 32 +- .../core/mvc/config/ControllerConfig.java | 30 +- .../core/mvc/config/GlobalExceptionHandler.java | 2 +- .../config/SettingsEnvironmentPostProcessor.java | 4 +- .../framework/core/mvc/config/WebMvcConfig.java | 8 +- .../core/mvc/controller/ApiConfigBean.java | 13 +- .../core/mvc/controller/ApiController.java | 79 +- .../core/mvc/controller/DefaultPageController.java | 35 +- .../core/mvc/controller/IActionManager.java | 2 +- .../core/mvc/controller/IBeanContext.java | 5 +- .../framework/core/mvc/controller/IEditor.java | 30 +- .../core/mvc/controller/IStartListener.java | 2 + .../mvc/controller/access/BindFieldAccess.java | 28 +- .../mvc/controller/access/ControllerAccess.java | 90 +-- .../core/mvc/controller/access/FieldAccess.java | 42 +- .../core/mvc/controller/access/IBeanAccess.java | 2 +- .../core/mvc/controller/access/IMethodAccess.java | 79 +- .../core/mvc/controller/access/MethodAccess.java | 2 +- .../mvc/controller/access/MethodParamAccess.java | 45 +- .../controller/access/SchedulerMethodAccess.java | 16 +- .../controller/access/SingletonFieldAccess.java | 18 +- .../core/mvc/controller/binder/BeanContext.java | 60 +- .../core/mvc/controller/binder/CacheEditor.java | 22 +- .../core/mvc/controller/binder/ParamEditor.java | 56 +- .../core/mvc/controller/binder/WebDataBinder.java | 382 +++++----- .../controller/binder/attr/AbstractAttrEditor.java | 11 +- .../mvc/controller/binder/attr/BeanAttrEditor.java | 9 +- .../binder/bean/AbstractContextEditor.java | 10 +- .../mvc/controller/binder/bean/BeanEditor.java | 16 +- .../binder/bean/HttpServletRequestEditor.java | 8 +- .../mvc/controller/binder/bean/NullEditor.java | 8 +- .../mvc/controller/binder/bean/SwIpAddrEditor.java | 34 +- .../controller/binder/bean/UserSessionEditor.java | 8 +- .../mvc/controller/binder/body/BeanBodyEditor.java | 107 +-- .../core/mvc/controller/binder/body/BeanUtil.java | 230 +++--- .../controller/binder/body/StringBodyEditor.java | 11 +- .../controller/binder/body/SwMapBodyEditor.java | 85 +-- .../binder/param/AbstractNumberEditor.java | 53 +- .../binder/param/AbstractParameterEditor.java | 160 ++-- .../binder/param/AbstractRequestEditor.java | 10 +- .../controller/binder/param/BeanTypeEditor.java | 8 +- .../mvc/controller/binder/param/BooleanEditor.java | 38 +- .../mvc/controller/binder/param/ByteEditor.java | 32 +- .../mvc/controller/binder/param/CharEditor.java | 34 +- .../mvc/controller/binder/param/DateEditor.java | 86 +-- .../mvc/controller/binder/param/DoubleEditor.java | 32 +- .../mvc/controller/binder/param/FloatEditor.java | 32 +- .../mvc/controller/binder/param/IntegerEditor.java | 32 +- .../mvc/controller/binder/param/LongEditor.java | 32 +- .../mvc/controller/binder/param/ShortEditor.java | 32 +- .../mvc/controller/binder/param/StringEditor.java | 20 +- .../mvc/controller/binder/param/TimeEditor.java | 42 +- .../controller/binder/param/TimestampEditor.java | 92 +-- .../controller/binder/path/PathParamEditor.java | 10 +- .../core/mvc/controller/scan/IScanAction.java | 17 +- .../mvc/controller/scan/IScanActionBuilder.java | 3 +- .../core/mvc/controller/scan/MethodParser.java | 198 ++--- .../core/mvc/controller/scan/PackageScanner.java | 272 +++---- .../core/mvc/controller/scan/ScanContext.java | 112 +-- .../core/mvc/controller/scan/UrlMaker.java | 126 ++-- .../framework/core/mvc/realm/IRealmLoader.java | 13 +- .../realm/exception/AuthenticationException.java | 6 +- .../realm/exception/AuthorizationException.java | 6 +- .../mvc/realm/exception/ForbiddenException.java | 6 +- .../realm/exception/UnauthenticatedException.java | 6 +- .../realm/exception/UnknownAccountException.java | 6 +- .../interceptor/AuthorizationInterceptor.java | 48 +- .../mvc/realm/interceptor/PermInterceptor.java | 26 +- .../core/mvc/realm/service/PermCheckItem.java | 26 +- .../core/mvc/realm/service/PermChecker.java | 50 +- .../framework/core/mvc/scheduler/AbstractJob.java | 30 +- .../core/mvc/scheduler/AbstractJobExecutor.java | 114 +-- .../core/mvc/scheduler/AbstractJobQueue.java | 87 +-- .../core/mvc/scheduler/CronTimerTask.java | 25 +- .../core/mvc/scheduler/FixedTimerTask.java | 20 +- .../core/mvc/scheduler/SchedulerPoint.java | 62 +- .../core/mvc/scheduler/SchedulerTaskManager.java | 122 +-- .../framework/core/mvc/scheduler/job/GroupJob.java | 16 +- .../core/mvc/scheduler/job/GroupJobQueue.java | 108 +-- .../core/mvc/scheduler/job/LocalJobExecutor.java | 20 +- .../core/mvc/scheduler/job/RedisJobExecutor.java | 88 +-- .../core/mvc/scheduler/job/SimpleJob.java | 16 +- .../core/mvc/scheduler/job/SimpleJobQueue.java | 24 +- .../core/mvc/service/AbstractCompProvider.java | 2 +- .../core/mvc/service/AbstractCompService.java | 26 +- .../core/mvc/service/AbstractDelHandler.java | 12 +- .../core/mvc/service/AbstractListHandler.java | 6 +- .../core/mvc/service/AbstractLoadHandler.java | 1 + .../core/mvc/service/AbstractSaveHandler.java | 7 +- .../core/mvc/service/AbstractTreeHandler.java | 11 +- .../core/mvc/service/DefaultComboHandler.java | 5 +- .../core/mvc/service/DefaultLoadHandler.java | 4 - .../core/mvc/service/DefaultProvider.java | 2 +- .../core/mvc/service/DefaultSaveHandler.java | 22 +- .../smtweb/framework/core/mvc/service/IWorker.java | 2 +- .../framework/core/mvc/service/TreeHelper.java | 9 +- .../framework/core/mvc/variable/ICalcVar.java | 3 +- .../core/mvc/variable/SwVariableFactory.java | 5 +- .../framework/core/session/SessionManager.java | 97 +-- .../smtweb/framework/core/session/SessionUtil.java | 62 +- .../core/session/UserSessionArgumentResolver.java | 1 + .../cc/smtweb/framework/core/systask/ISysTask.java | 2 +- .../framework/core/systask/SysTaskManager.java | 30 +- .../cc/smtweb/framework/core/util/CommUtil.java | 4 + .../cc/smtweb/framework/core/util/DateUtil.java | 237 +++--- .../cc/smtweb/framework/core/util/EmojiFilter.java | 5 +- .../cc/smtweb/framework/core/util/HttpUtil.java | 24 +- .../cc/smtweb/framework/core/util/IpAddrUtil.java | 2 +- .../cc/smtweb/framework/core/util/JsonUtil.java | 11 +- .../smtweb/framework/core/util/PersonUIDUtil.java | 23 +- .../cc/smtweb/framework/core/util/SpringUtil.java | 4 +- .../cc/smtweb/framework/core/util/SqlUtil.java | 15 +- .../cc/smtweb/framework/core/util/StringUtil.java | 2 +- .../smtweb/framework/core/util/VariableUtil.java | 103 +-- .../cc/smtweb/framework/core/util/XmlUtil.java | 10 +- .../core/util/jackson/BaseBeanSerializer.java | 18 +- .../core/util/jackson/DateSerializer.java | 24 +- .../core/util/jackson/NullSerializer.java | 10 +- .../core/util/jackson/TimeSerializer.java | 20 +- .../java/com/serotonin/timer/CronExpression.java | 329 ++++---- .../java/com/serotonin/timer/FixedRateTrigger.java | 3 +- .../java/com/serotonin/timer/ModelTimeoutTask.java | 3 +- .../java/com/serotonin/timer/NamedRunnable.java | 3 +- .../com/serotonin/timer/NonConcurrentTask.java | 3 +- .../java/com/serotonin/timer/RealTimeTimer.java | 6 +- .../serotonin/timer/ScheduledNamedRunnable.java | 3 +- .../java/com/serotonin/timer/SimulationTimer.java | 3 +- .../main/java/com/serotonin/timer/TaskQueue.java | 4 +- .../main/java/com/serotonin/timer/TimerTask.java | 21 +- .../main/java/com/serotonin/timer/TimerThread.java | 15 +- .../java/com/serotonin/timer/TimerTrigger.java | 4 +- .../com/serotonin/timer/sync/AsyncJobSink.java | 9 +- .../timer/sync/SingleExecutorSingleWaiter.java | 6 +- .../com/serotonin/timer/sync/Synchronizer.java | 21 +- 368 files changed, 6854 insertions(+), 5839 deletions(-) diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmApplication.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmApplication.java index 3c3543b..879c8d8 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmApplication.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmApplication.java @@ -9,6 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class BpmApplication { public static void main(String[] args) { - SpringApplication.run(BpmApplication.class, args); + SpringApplication.run(BpmApplication.class, args); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmAutoConfiguration.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmAutoConfiguration.java index 211a8f7..f283b7b 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmAutoConfiguration.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmAutoConfiguration.java @@ -11,9 +11,11 @@ import org.springframework.context.annotation.Configuration; @Configuration @ComponentScan public class BpmAutoConfiguration { - /** 配置自定义service扫描路径 {module}/{service}/{method} */ - @Bean - public ControllerConfig bpmControllerConfig() { - return new ControllerConfig("bpm", "cc.smtweb.system.bpm.web", null); - } + /** + * 配置自定义service扫描路径 {module}/{service}/{method} + */ + @Bean + public ControllerConfig bpmControllerConfig() { + return new ControllerConfig("bpm", "cc.smtweb.system.bpm.web", null); + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmConfigBean.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmConfigBean.java index a090766..512aec0 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmConfigBean.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/BpmConfigBean.java @@ -8,6 +8,6 @@ import org.springframework.stereotype.Component; @ConfigurationProperties(prefix = "smtweb.bpm") @Data public class BpmConfigBean { - private String codeJavaPath; - private int mode; + private String codeJavaPath; + private int mode; } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/config/FileConfig.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/config/FileConfig.java index 19475c5..ce49fee 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/config/FileConfig.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/config/FileConfig.java @@ -1,10 +1,10 @@ package cc.smtweb.system.bpm.spring.config; +import cc.smtweb.framework.core.db.jdbc.IdGenerator; import cc.smtweb.system.bpm.util.FilePathGenerator; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import cc.smtweb.framework.core.db.jdbc.IdGenerator; /** * 微服务框架封装自动配置类 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/config/FileConfigProperties.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/config/FileConfigProperties.java index 69e97b3..1f9ddda 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/config/FileConfigProperties.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/config/FileConfigProperties.java @@ -13,7 +13,7 @@ public class FileConfigProperties { /** * 系统底层附件保存路径和访问路径 */ - private String localPath; + private String localPath; private String url; /** diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java index 6f908a6..d279e48 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java @@ -48,7 +48,7 @@ import java.util.Map; @RestController @RequestMapping("/api/attach") public class AttachController { - private static Logger logger = LoggerFactory.getLogger(AttachController.class); + private static Logger logger = LoggerFactory.getLogger(AttachController.class); @Autowired private FileConfigProperties properties; @Autowired @@ -60,14 +60,13 @@ public class AttachController { private BASE64Decoder decoder = new BASE64Decoder(); /** - * * @param request - * @param type 类型,如idcard:身份证、headImg:头像 - * @param ownerId 拥有者ID - * @param path 存储目录路径名,如:idcard + * @param type 类型,如idcard:身份证、headImg:头像 + * @param ownerId 拥有者ID + * @param path 存储目录路径名,如:idcard * @param attachIsTemp 是否临时文件:true/false 字符串 - * @param attachName 附件名称,如:XXXXX.jpg - * @param savePath 保存路径,指定文件保存目录,可为空 + * @param attachName 附件名称,如:XXXXX.jpg + * @param savePath 保存路径,指定文件保存目录,可为空 * @return * @throws Exception */ @@ -91,14 +90,14 @@ public class AttachController { AttachInfo attach = new AttachInfo(); attach.setId(dbEngine.nextId()); attach.setType(type);//附件类别 - if(null !=ownerId) { + if (null != ownerId) { attach.setOwnerId(ownerId);//附件拥有者id } attach.setPath(path);//附件路径 attach.setPartyId(-1l); attach.setTime(DateUtil.nowDateTimeLong()); attach.setUserId(-1l); - attach.setIsTemp("true".equals(attachIsTemp) ? 1 : 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 + attach.setIsTemp("true".equals(attachIsTemp) ? 1: 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 // 上传文件名 final int i = file.getOriginalFilename().lastIndexOf("."); if (i >= 0) { @@ -106,8 +105,7 @@ public class AttachController { } if (StringUtil.isEmpty(attachName)) { attachName = file.getOriginalFilename(); - } - else { + } else { attachName = attachName + attach.getSuffix(); } attach.setName(attachName); @@ -138,18 +136,17 @@ public class AttachController { } /** - * * @param request * @param response - * @param base64File 文件base64编码 - * @param attachId 附件ID,可为空,如果有,则替换此附件ID对应数据 - * @param type 类型,如idcard:身份证、headImg:头像 - * @param ownerId 拥有者ID - * @param path 存储目录路径名,如:idcard + * @param base64File 文件base64编码 + * @param attachId 附件ID,可为空,如果有,则替换此附件ID对应数据 + * @param type 类型,如idcard:身份证、headImg:头像 + * @param ownerId 拥有者ID + * @param path 存储目录路径名,如:idcard * @param attachIsTemp 是否临时文件:true/false 字符串 - * @param attachName 附件名称,如:XXXXX.jpg - * @param savePath 保存路径,指定文件保存目录,可为空 - * @param suffix 文件后缀,如.jpg + * @param attachName 附件名称,如:XXXXX.jpg + * @param savePath 保存路径,指定文件保存目录,可为空 + * @param suffix 文件后缀,如.jpg * @return * @throws Exception */ @@ -164,23 +161,22 @@ public class AttachController { @RequestParam(value = "attachName", required = false) String attachName, @RequestParam(value = "savePath", required = false) String savePath, @RequestParam(value = "suffix", required = false) String suffix - ) throws Exception { + ) throws Exception { // UtilLogger.error("上传文件接收base64", base64File); - if (null == base64File || "".equals(base64File)){ + if (null == base64File || "".equals(base64File)) { return R.error("文件不能为空"); } - String str[]=base64File.split(","); - if(str.length>1){ - base64File=str[1]; + String str[] = base64File.split(","); + if (str.length > 1) { + base64File = str[1]; } // 上传文件类型 //String uploadContentType = file.getContentType(); AttachInfo attach = null; - boolean isNew = StringUtil.isEmpty(attachId+""); + boolean isNew = StringUtil.isEmpty(attachId + ""); if (isNew) { attach = new AttachInfo(); - } - else { + } else { attach = dbEngine.findDao(AttachInfo.class).queryEntity(attachId); if (attach == null) { attach = new AttachInfo(); @@ -188,19 +184,19 @@ public class AttachController { } else isNew = attach.isNew(); } attach.setId(attachId); - if (StringUtil.isEmpty(attachId+"")) attach.setId(dbEngine.nextId()); + if (StringUtil.isEmpty(attachId + "")) attach.setId(dbEngine.nextId()); attach.setType(type);//附件类别 - if(null !=ownerId) { + if (null != ownerId) { attach.setOwnerId(ownerId);//附件拥有者id } attach.setPath(path);//附件路径 attach.setPartyId(-1l); attach.setTime(DateUtil.nowDateTimeLong()); attach.setUserId(-1l); - attach.setIsTemp("true".equals(attachIsTemp) ? 1 : 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 + attach.setIsTemp("true".equals(attachIsTemp) ? 1: 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 attach.setTime(DateUtil.nowDateTimeLong()); - attach.setIsTemp("true".equals(attachIsTemp) ? 1 : 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 + attach.setIsTemp("true".equals(attachIsTemp) ? 1: 0);//暂时没有有效拥有者标记 方便定时任务清除垃圾附件 // 上传文件名 attach.setSuffix(suffix); attach.setName(attachName); @@ -235,25 +231,26 @@ public class AttachController { } return R.success(attach.getId()); } + @PostMapping({"/copyupload"}) public R copyupload(HttpServletRequest request) throws Exception { - String type=request.getParameter("type"); - String attachId=request.getParameter("attachId"); - if(StringUtil.isEmpty(attachId)){ + String type = request.getParameter("type"); + String attachId = request.getParameter("attachId"); + if (StringUtil.isEmpty(attachId)) { return R.success(""); } - AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); - if(null ==attach){ + AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); + if (null == attach) { return R.success(""); } - String remoteName =attach.getId()+attach.getName().substring(attach.getName().lastIndexOf(".")); + String remoteName = attach.getId() + attach.getName().substring(attach.getName().lastIndexOf(".")); String remotePath = attach.getPath(); - String filePath =attachHelper.getAttachTmpPath()+"tempFiles/"; + String filePath = attachHelper.getAttachTmpPath() + "tempFiles/"; UtilFile.makeDir(filePath); Map map = null; try { attachUtil.downloadAttach(remotePath, remoteName, filePath); - String filePaths=filePath+remoteName; + String filePaths = filePath + remoteName; attach.setId(dbEngine.nextId()); attach.setType(type);//附件类别 @@ -261,16 +258,16 @@ public class AttachController { attach.setPartyId(-1l); attach.setTime(DateUtil.nowDateTimeLong()); attach.setUserId(-1l); - attach.setName(attach.getId()+attach.getSuffix()); + attach.setName(attach.getId() + attach.getSuffix()); // 上传文件域对象 File upload = new File(filePaths); // attach.setSize((long) FileCopyUtils.copy(file.getInputStream(), new BufferedOutputStream(new FileOutputStream(upload)))); localSaveAttach(attach, upload); - }catch (Exception e){ + } catch (Exception e) { logger.error("上传文件失败", e); return R.error("上传文件失败"); } - return R.success(attach.getId()); + return R.success(attach.getId()); } @@ -291,7 +288,7 @@ public class AttachController { //附件下载 @RequestMapping(value = "/download", method = {RequestMethod.GET, RequestMethod.POST}) public R down(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "attachId", required = false) Long attachId) throws Exception { - AttachInfo attach = dbEngine.queryEntity(AttachInfo.class,attachId); + AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, attachId); if (null == attach) { return R.error("附件不存在"); } @@ -302,9 +299,9 @@ public class AttachController { try { attachUtil.downloadAttach(remotePath, remoteFileName, fileName, response); attach.setCount(attach.getCount() + 1); - dbEngine.updateEntity(attach,"attach_count"); + dbEngine.updateEntity(attach, "attach_count"); } catch (Exception e) { - logger.error("附件下载失败",e); + logger.error("附件下载失败", e); R.error("附件下载失败"); } @@ -314,21 +311,21 @@ public class AttachController { //图片附件显示路径 @GetMapping(value = "/showImg") public R showImg(HttpServletResponse response, @RequestParam(value = "attachId", required = false) Long attachId) throws Exception { - AttachInfo attach = dbEngine.queryEntity(AttachInfo.class,attachId); + AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, attachId); if (null == attach) { return R.error("附件不存在"); } // attachUtil.showImg(attach.getPath(),attach.getName(),response); - attachUtil.downloadAttach(attach.getPath(),attach.getName(),attach.getName(),response); + attachUtil.downloadAttach(attach.getPath(), attach.getName(), attach.getName(), response); return null; } //图片附件显示路径 @RequestMapping(value = "/showImgThumb", method = {RequestMethod.GET, RequestMethod.POST}) public R showImgThumb(HttpServletResponse response, @RequestParam(value = "attachId", required = false) Long attachId, - @RequestParam(value = "width", required = false,defaultValue = "200") String width, - @RequestParam(value = "height", required = false,defaultValue = "120") String height) throws Exception { - AttachInfo attach = dbEngine.queryEntity(AttachInfo.class,attachId); + @RequestParam(value = "width", required = false, defaultValue = "200") String width, + @RequestParam(value = "height", required = false, defaultValue = "120") String height) throws Exception { + AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, attachId); if (null == attach) { return R.error("附件不存在"); } @@ -339,8 +336,8 @@ public class AttachController { String lfo = tempPath + "/" + remoteFileName; String lfd = tempPath + "/thumb_" + attach.getId() + attach.getSuffix(); attachUtil.downloadAttach(remotePath, remoteFileName, tempPath); - int w=Integer.valueOf(width); - int h=Integer.valueOf(height); + int w = Integer.valueOf(width); + int h = Integer.valueOf(height); if (w <= 0) w = 100; if (h <= 0) h = 100; getImgThumb(lfo, lfd, w, h); @@ -350,7 +347,7 @@ public class AttachController { UtilDownloadFile.downfileEx(response, lfo, attach.getName()); } } catch (Exception e) { - logger.error("附件下载失败",e); + logger.error("附件下载失败", e); R.error("附件下载失败"); } return null; @@ -419,7 +416,7 @@ public class AttachController { //图片附件显示路径 @GetMapping(value = "/loadAttachBean") public R loadAttachBean(@RequestParam(value = "attachIds") String attachIds) throws Exception { - List beans = dbEngine.queryWhere(AttachInfo.class, "attach_id in ("+attachIds+")"); + List beans = dbEngine.queryWhere(AttachInfo.class, "attach_id in (" + attachIds + ")"); return R.success(beans); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileDownloadController.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileDownloadController.java index 40e6795..b21cc62 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileDownloadController.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileDownloadController.java @@ -9,7 +9,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.InputStreamResource; import org.springframework.http.*; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.io.File; @@ -22,164 +25,170 @@ import java.util.concurrent.TimeUnit; @RestController public class FileDownloadController { - private static final MediaType APPLICATION_JAVASCRIPT = new MediaType("application", "javascript"); - @Value("${smtweb.static.local-path:}") - private String staticLocalPath; - - @Autowired - private FilePathGenerator filePathGenerator; - - @Autowired - private RedisManager redisManager; - - /** path方式下载文件 */ - @GetMapping("/fs/files/**") - public ResponseEntity files(@RequestParam(value="name", required=false) String name, - @RequestParam(value="noCache", required=false) Boolean noCache, - HttpServletRequest request - ) throws FileNotFoundException { - String filePath = request.getRequestURI().substring(10); - return download(filePath, name, noCache, request); - } - - /** 参数方式下载文件 */ - @GetMapping("/fs/download") - public ResponseEntity download(@RequestParam(value="path") String path, - @RequestParam(value="name", required=false) String name, - @RequestParam(value="noCache", required=false) Boolean noCache, - HttpServletRequest request - ) throws FileNotFoundException { - SessionUtil.checkSession(request, redisManager); - - File file = new File(filePathGenerator.getFileDiskPath(path)); - - if (!file.exists()) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + private static final MediaType APPLICATION_JAVASCRIPT = new MediaType("application", "javascript"); + @Value("${smtweb.static.local-path:}") + private String staticLocalPath; + + @Autowired + private FilePathGenerator filePathGenerator; + + @Autowired + private RedisManager redisManager; + + /** + * path方式下载文件 + */ + @GetMapping("/fs/files/**") + public ResponseEntity files(@RequestParam(value = "name", required = false) String name, + @RequestParam(value = "noCache", required = false) Boolean noCache, + HttpServletRequest request + ) throws FileNotFoundException { + String filePath = request.getRequestURI().substring(10); + return download(filePath, name, noCache, request); } - if (StringUtils.isBlank(name)) { - name = file.getName(); - } - - HttpHeaders headers = new HttpHeaders(); - if (Boolean.TRUE.equals(noCache)) { - headers.setCacheControl("no-cache, no-store, must-revalidate"); - headers.setPragma("no-cache"); - headers.setExpires(0); - } - - headers.setLastModified(file.lastModified()); - headers.add("Content-Disposition", - String.format("attachment; filename=\"%s\"", new String(name.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1))); - - return ResponseEntity.ok() - .headers(headers) - .contentLength(file.length()) - .contentType(MediaType.APPLICATION_OCTET_STREAM) - .body(new InputStreamResource(new FileInputStream(file))); - } - - /** path方式读取静态目录文件 */ - @GetMapping("/fs/static/**") - public ResponseEntity resource(@RequestParam(value="default", required=false) String defaultPath, - @RequestParam(value="noCache", required=false) Boolean noCache, - @RequestHeader(value="If-Modified-Since", required = false) String ifModifiedSince, - HttpServletRequest request) throws FileNotFoundException { - String filePath = request.getRequestURI().substring(11); - - HttpHeaders headers = new HttpHeaders(); - - if (Boolean.TRUE.equals(noCache)) { - headers.setCacheControl("no-cache, no-store, must-revalidate"); - headers.setPragma("no-cache"); - headers.setExpires(0); - } else { - // 暂时缓存1天 - headers.setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS)); - headers.setExpires(Instant.ofEpochMilli(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY)); - } - - String name = getFileName(filePath); - headers.add("Content-Disposition", - String.format("attachment; filename=\"%s\"", new String(name.getBytes(StandardCharsets.UTF_8),StandardCharsets.ISO_8859_1))); - - MediaType contentType = getContentType(filePath); - // 先找文件 - if (StringUtils.isNotBlank(staticLocalPath)) { - File file = new File(staticLocalPath + filePath); + /** + * 参数方式下载文件 + */ + @GetMapping("/fs/download") + public ResponseEntity download(@RequestParam(value = "path") String path, + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "noCache", required = false) Boolean noCache, + HttpServletRequest request + ) throws FileNotFoundException { + SessionUtil.checkSession(request, redisManager); + + File file = new File(filePathGenerator.getFileDiskPath(path)); + + if (!file.exists()) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + } + + if (StringUtils.isBlank(name)) { + name = file.getName(); + } + + HttpHeaders headers = new HttpHeaders(); + if (Boolean.TRUE.equals(noCache)) { + headers.setCacheControl("no-cache, no-store, must-revalidate"); + headers.setPragma("no-cache"); + headers.setExpires(0); + } - if (file.exists()) { headers.setLastModified(file.lastModified()); + headers.add("Content-Disposition", + String.format("attachment; filename=\"%s\"", new String(name.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1))); return ResponseEntity.ok() .headers(headers) .contentLength(file.length()) - .contentType(contentType) + .contentType(MediaType.APPLICATION_OCTET_STREAM) .body(new InputStreamResource(new FileInputStream(file))); - } } - // 再找资源目录 - InputStream inputStream = getClass().getResourceAsStream("/static/" + filePath); - if (inputStream != null) { - return buildResource(inputStream, contentType, headers); - } else if (StringUtils.isNotBlank(defaultPath)) { - inputStream = getClass().getResourceAsStream("/static/" + defaultPath); - if (inputStream != null) { - return buildResource(inputStream, contentType, headers); - } + /** + * path方式读取静态目录文件 + */ + @GetMapping("/fs/static/**") + public ResponseEntity resource(@RequestParam(value = "default", required = false) String defaultPath, + @RequestParam(value = "noCache", required = false) Boolean noCache, + @RequestHeader(value = "If-Modified-Since", required = false) String ifModifiedSince, + HttpServletRequest request) throws FileNotFoundException { + String filePath = request.getRequestURI().substring(11); + + HttpHeaders headers = new HttpHeaders(); + + if (Boolean.TRUE.equals(noCache)) { + headers.setCacheControl("no-cache, no-store, must-revalidate"); + headers.setPragma("no-cache"); + headers.setExpires(0); + } else { + // 暂时缓存1天 + headers.setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS)); + headers.setExpires(Instant.ofEpochMilli(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY)); + } + + String name = getFileName(filePath); + headers.add("Content-Disposition", + String.format("attachment; filename=\"%s\"", new String(name.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1))); + + MediaType contentType = getContentType(filePath); + // 先找文件 + if (StringUtils.isNotBlank(staticLocalPath)) { + File file = new File(staticLocalPath + filePath); + + if (file.exists()) { + headers.setLastModified(file.lastModified()); + + return ResponseEntity.ok() + .headers(headers) + .contentLength(file.length()) + .contentType(contentType) + .body(new InputStreamResource(new FileInputStream(file))); + } + } + + // 再找资源目录 + InputStream inputStream = getClass().getResourceAsStream("/static/" + filePath); + if (inputStream != null) { + return buildResource(inputStream, contentType, headers); + } else if (StringUtils.isNotBlank(defaultPath)) { + inputStream = getClass().getResourceAsStream("/static/" + defaultPath); + if (inputStream != null) { + return buildResource(inputStream, contentType, headers); + } + } + + return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); } - return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); - } + private String getFileName(String filePath) { + int pos = filePath.lastIndexOf("/"); + if (pos >= 0) { + return filePath.substring(pos + 1); + } - private String getFileName(String filePath) { - int pos = filePath.lastIndexOf("/"); - if (pos >= 0) { - return filePath.substring(pos + 1); + return filePath; } - return filePath; - } - - private ResponseEntity buildResource(InputStream inputStream, MediaType contentType, HttpHeaders headers) { - return ResponseEntity.ok() - .headers(headers) + private ResponseEntity buildResource(InputStream inputStream, MediaType contentType, HttpHeaders headers) { + return ResponseEntity.ok() + .headers(headers) // .contentLength(file.length()) - .contentType(contentType) - .body(new InputStreamResource(inputStream)); - } - - private static MediaType getContentType(String filePath) { - int pos = filePath.lastIndexOf("."); - - if (pos >= 0) { - String fileExt = filePath.substring(pos + 1).toLowerCase(); - switch (fileExt) { - case "htm": - case "html": - case "css": - return MediaType.TEXT_HTML; - case "js": - return APPLICATION_JAVASCRIPT; - case "txt": - return MediaType.TEXT_PLAIN; - case "pdf": - return MediaType.APPLICATION_PDF; - case "xml": - return MediaType.TEXT_XML; - case "gif": - return MediaType.IMAGE_GIF; - case "jpeg": - case "jpg": - return MediaType.IMAGE_JPEG; - case "png": - return MediaType.IMAGE_PNG; - default: - return MediaType.APPLICATION_OCTET_STREAM; - } + .contentType(contentType) + .body(new InputStreamResource(inputStream)); } - return MediaType.APPLICATION_OCTET_STREAM; - } + private static MediaType getContentType(String filePath) { + int pos = filePath.lastIndexOf("."); + + if (pos >= 0) { + String fileExt = filePath.substring(pos + 1).toLowerCase(); + switch (fileExt) { + case "htm": + case "html": + case "css": + return MediaType.TEXT_HTML; + case "js": + return APPLICATION_JAVASCRIPT; + case "txt": + return MediaType.TEXT_PLAIN; + case "pdf": + return MediaType.APPLICATION_PDF; + case "xml": + return MediaType.TEXT_XML; + case "gif": + return MediaType.IMAGE_GIF; + case "jpeg": + case "jpg": + return MediaType.IMAGE_JPEG; + case "png": + return MediaType.IMAGE_PNG; + default: + return MediaType.APPLICATION_OCTET_STREAM; + } + } + + return MediaType.APPLICATION_OCTET_STREAM; + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileUploadController.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileUploadController.java index b0f1404..260826f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileUploadController.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/FileUploadController.java @@ -1,10 +1,12 @@ package cc.smtweb.system.bpm.spring.controller; +import cc.smtweb.framework.core.cache.redis.RedisManager; import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.db.DbEngine; -import cc.smtweb.framework.core.cache.redis.RedisManager; import cc.smtweb.framework.core.session.SessionUtil; import cc.smtweb.system.bpm.spring.dao.ImageAttachDao; +import cc.smtweb.system.bpm.spring.entity.FileDataVO; +import cc.smtweb.system.bpm.spring.entity.UploadDataVO; import cc.smtweb.system.bpm.util.FilePathGenerator; import cc.smtweb.system.bpm.util.FilePathInfo; import cc.smtweb.system.bpm.util.MemMultipartFile; @@ -13,8 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import cc.smtweb.system.bpm.spring.entity.FileDataVO; -import cc.smtweb.system.bpm.spring.entity.UploadDataVO; import javax.servlet.http.HttpServletRequest; import java.io.*; @@ -23,135 +23,135 @@ import java.text.SimpleDateFormat; @RestController public class FileUploadController { - @Autowired - private FilePathGenerator filePathGenerator; - - @Autowired - private DbEngine dbEngine; - - @Autowired - private RedisManager redisManager; - - @Autowired - private ImageAttachDao imageAttachDao; - - // TODO: 权限处理,临时文件处理 - @PostMapping("/fs/upload/{path}") - public R upload(@RequestParam("file") MultipartFile file, @PathVariable("path") String path, - @RequestParam(value="thumb", required=false) String thumb, - @RequestParam(value="thumbHeight", required=false) Integer thumbHeight, - @RequestParam(value="commit", required=false) Boolean insert, - @RequestParam(value="keepName", required=false) Boolean keepName, - HttpServletRequest request - ) { - SessionUtil.checkSession(request, redisManager); - return uploadFile(path, file, ThumbImage.type(thumb), thumbHeight, insert, keepName); - } - - @PostMapping("/fs/uploadImage/{path}") - public R upload(@RequestBody FileDataVO data, @PathVariable("path") String path, - @RequestParam(value="thumb", required=false) String thumb, - @RequestParam(value="thumbHeight", required=false) Integer thumbHeight, - @RequestParam(value="commit", required=false) Boolean insert, - HttpServletRequest request) { - SessionUtil.checkSession(request, redisManager); - - MultipartFile file = MemMultipartFile.build(data.getData()); - if (file == null) { - return R.error("数据内容格式有错"); + @Autowired + private FilePathGenerator filePathGenerator; + + @Autowired + private DbEngine dbEngine; + + @Autowired + private RedisManager redisManager; + + @Autowired + private ImageAttachDao imageAttachDao; + + // TODO: 权限处理,临时文件处理 + @PostMapping("/fs/upload/{path}") + public R upload(@RequestParam("file") MultipartFile file, @PathVariable("path") String path, + @RequestParam(value = "thumb", required = false) String thumb, + @RequestParam(value = "thumbHeight", required = false) Integer thumbHeight, + @RequestParam(value = "commit", required = false) Boolean insert, + @RequestParam(value = "keepName", required = false) Boolean keepName, + HttpServletRequest request + ) { + SessionUtil.checkSession(request, redisManager); + return uploadFile(path, file, ThumbImage.type(thumb), thumbHeight, insert, keepName); } - return uploadFile(path, file, ThumbImage.type(thumb), thumbHeight, insert, false); - } - - @PostMapping("/fs/uploadAvatar/{path}") - public R uploadAvatar(@RequestParam("file") MultipartFile file, @PathVariable("path") String path, - @RequestParam(value="size", required=false) Integer size, - @RequestParam(value="commit", required=false) Boolean insert, - @RequestParam(value="keepName", required=false) Boolean keepName, - HttpServletRequest request) { - SessionUtil.checkSession(request, redisManager); - return uploadFile(path, file, ThumbImage.TYPE_AVATAR, size, insert, keepName); - } - - // 保存文件和插入数据库数据 - @PostMapping("/fs/commit/{path}") - public R commit(@RequestParam("file") MultipartFile file, @PathVariable("path") String path, - @RequestParam(value="thumb", required=false) String thumb, - @RequestParam(value="thumbHeight", required=false) Integer thumbHeight, - @RequestParam(value="keepName", required=false) Boolean keepName, - HttpServletRequest request) { - SessionUtil.checkSession(request, redisManager); - return uploadFile(path, file, ThumbImage.type(thumb), thumbHeight, true, keepName); - } - - private R uploadFile(String path, MultipartFile file, int type, Integer size, Boolean insert, Boolean keepName) { - //获取上传时的文件名 - String fileName = file.getOriginalFilename(); - - //判断文件是否为空 - if(file.isEmpty() && fileName != null){ - return R.error("文件为空"); - } + @PostMapping("/fs/uploadImage/{path}") + public R upload(@RequestBody FileDataVO data, @PathVariable("path") String path, + @RequestParam(value = "thumb", required = false) String thumb, + @RequestParam(value = "thumbHeight", required = false) Integer thumbHeight, + @RequestParam(value = "commit", required = false) Boolean insert, + HttpServletRequest request) { + SessionUtil.checkSession(request, redisManager); - // 判断保持文件名不变 - FilePathInfo fileInfo = filePathGenerator.make(path, fileName, Boolean.TRUE.equals(keepName)); + MultipartFile file = MemMultipartFile.build(data.getData()); + if (file == null) { + return R.error("数据内容格式有错"); + } - // 注意是路径+文件名 - File targetFile = new File(fileInfo.getFullFileName()); + return uploadFile(path, file, ThumbImage.type(thumb), thumbHeight, insert, false); + } - try(InputStream inputStream = file.getInputStream(); OutputStream outputStream = new FileOutputStream(targetFile)) { - // 最后使用资源访问器FileCopyUtils的copy方法拷贝文件 - FileCopyUtils.copy(inputStream, outputStream); - } catch (IOException e) { - //出现异常,则告诉页面失败 - return R.error("上传失败", e); + @PostMapping("/fs/uploadAvatar/{path}") + public R uploadAvatar(@RequestParam("file") MultipartFile file, @PathVariable("path") String path, + @RequestParam(value = "size", required = false) Integer size, + @RequestParam(value = "commit", required = false) Boolean insert, + @RequestParam(value = "keepName", required = false) Boolean keepName, + HttpServletRequest request) { + SessionUtil.checkSession(request, redisManager); + return uploadFile(path, file, ThumbImage.TYPE_AVATAR, size, insert, keepName); } - // 生成缩略图 -// String contentType = file.getContentType(); - UploadDataVO data = new UploadDataVO(); - - data.setPath(fileInfo.getMysqlFilePath()); - data.setName(fileName); - data.setSize(file.getSize()); - data.setContentType(file.getContentType()); - data.setUrl(filePathGenerator.getFileUrl(fileInfo.getMysqlFilePath())); - - if (type == ThumbImage.TYPE_THUMB || type == ThumbImage.TYPE_AVATAR) { - try { - imageAttachDao.makeThumb(data, type == ThumbImage.TYPE_THUMB, targetFile, size); - } catch (IOException e) { - return R.error("生成缩略图失败", e); - } + // 保存文件和插入数据库数据 + @PostMapping("/fs/commit/{path}") + public R commit(@RequestParam("file") MultipartFile file, @PathVariable("path") String path, + @RequestParam(value = "thumb", required = false) String thumb, + @RequestParam(value = "thumbHeight", required = false) Integer thumbHeight, + @RequestParam(value = "keepName", required = false) Boolean keepName, + HttpServletRequest request) { + SessionUtil.checkSession(request, redisManager); + return uploadFile(path, file, ThumbImage.type(thumb), thumbHeight, true, keepName); } - if (Boolean.TRUE.equals(insert)) { - Long id = dbEngine.nextId(); - Timestamp now = new Timestamp(System.currentTimeMillis()); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + private R uploadFile(String path, MultipartFile file, int type, Integer size, Boolean insert, Boolean keepName) { + //获取上传时的文件名 + String fileName = file.getOriginalFilename(); - dbEngine.update("insert into sw_user.sys_attach(attach_id, attach_name, attach_path, attach_content_type, attach_size, attach_create_time) values(?, ?, ?, ?, ?, ?)", - id, data.getName(), data.getPath(), data.getContentType(), data.getSize(), sdf.format(now)); + //判断文件是否为空 + if (file.isEmpty() && fileName != null) { + return R.error("文件为空"); + } - data.setId(id); - } + // 判断保持文件名不变 + FilePathInfo fileInfo = filePathGenerator.make(path, fileName, Boolean.TRUE.equals(keepName)); - return R.success(data); - } + // 注意是路径+文件名 + File targetFile = new File(fileInfo.getFullFileName()); - // TODO: 修改为安全的后台删除方式 - @PostMapping("/fs/remove") - public R remove(@RequestParam(value="filePath") String filePath, HttpServletRequest request) { - SessionUtil.checkSession(request, redisManager); + try (InputStream inputStream = file.getInputStream(); OutputStream outputStream = new FileOutputStream(targetFile)) { + // 最后使用资源访问器FileCopyUtils的copy方法拷贝文件 + FileCopyUtils.copy(inputStream, outputStream); + } catch (IOException e) { + //出现异常,则告诉页面失败 + return R.error("上传失败", e); + } - File file = new File(filePathGenerator.getFileDiskPath(filePath)); - if (file.exists() && file.isFile()) { - if (file.delete()) { - R.success(filePath); - } + // 生成缩略图 +// String contentType = file.getContentType(); + UploadDataVO data = new UploadDataVO(); + + data.setPath(fileInfo.getMysqlFilePath()); + data.setName(fileName); + data.setSize(file.getSize()); + data.setContentType(file.getContentType()); + data.setUrl(filePathGenerator.getFileUrl(fileInfo.getMysqlFilePath())); + + if (type == ThumbImage.TYPE_THUMB || type == ThumbImage.TYPE_AVATAR) { + try { + imageAttachDao.makeThumb(data, type == ThumbImage.TYPE_THUMB, targetFile, size); + } catch (IOException e) { + return R.error("生成缩略图失败", e); + } + } + + if (Boolean.TRUE.equals(insert)) { + Long id = dbEngine.nextId(); + Timestamp now = new Timestamp(System.currentTimeMillis()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + + dbEngine.update("insert into sw_user.sys_attach(attach_id, attach_name, attach_path, attach_content_type, attach_size, attach_create_time) values(?, ?, ?, ?, ?, ?)", + id, data.getName(), data.getPath(), data.getContentType(), data.getSize(), sdf.format(now)); + + data.setId(id); + } + + return R.success(data); } - return R.success(); - } + // TODO: 修改为安全的后台删除方式 + @PostMapping("/fs/remove") + public R remove(@RequestParam(value = "filePath") String filePath, HttpServletRequest request) { + SessionUtil.checkSession(request, redisManager); + + File file = new File(filePathGenerator.getFileDiskPath(filePath)); + if (file.exists() && file.isFile()) { + if (file.delete()) { + R.success(filePath); + } + } + + return R.success(); + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dao/ImageAttachDao.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dao/ImageAttachDao.java index 322d293..906365b 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dao/ImageAttachDao.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dao/ImageAttachDao.java @@ -1,63 +1,63 @@ package cc.smtweb.system.bpm.spring.dao; +import cc.smtweb.system.bpm.spring.entity.UploadDataVO; import cc.smtweb.system.bpm.util.ThumbImage; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; -import cc.smtweb.system.bpm.spring.entity.UploadDataVO; import java.io.File; import java.io.IOException; @Service public class ImageAttachDao { - public static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; - - public void makeThumb(UploadDataVO data, boolean isThumb, File targetFile, Integer size) throws IOException { - boolean imageType = false; - String fileName = data.getName(); - String contentType = data.getContentType(); - - if (contentType.startsWith("image/")) { - imageType = true; - } else if (contentType.equals(APPLICATION_OCTET_STREAM)) { - String fileExt = fileName.substring(fileName.lastIndexOf(".")); - - if (StringUtils.isNotEmpty(fileExt)) { - switch (fileExt.toLowerCase()) { - case ".jpg": - case ".jpeg": - contentType = "image/jpg"; - imageType = true; - break; - case ".gif": - contentType = "image/gif"; - imageType = true; - break; - case ".png": - contentType = "image/png"; + public static final String APPLICATION_OCTET_STREAM = "application/octet-stream"; + + public void makeThumb(UploadDataVO data, boolean isThumb, File targetFile, Integer size) throws IOException { + boolean imageType = false; + String fileName = data.getName(); + String contentType = data.getContentType(); + + if (contentType.startsWith("image/")) { imageType = true; - break; - default: - break; + } else if (contentType.equals(APPLICATION_OCTET_STREAM)) { + String fileExt = fileName.substring(fileName.lastIndexOf(".")); + + if (StringUtils.isNotEmpty(fileExt)) { + switch (fileExt.toLowerCase()) { + case ".jpg": + case ".jpeg": + contentType = "image/jpg"; + imageType = true; + break; + case ".gif": + contentType = "image/gif"; + imageType = true; + break; + case ".png": + contentType = "image/png"; + imageType = true; + break; + default: + break; + } + + if (imageType) { + data.setContentType(contentType); + } + } } if (imageType) { - data.setContentType(contentType); - } - } - } + int thumbHeight = 80; + if (size != null) { + thumbHeight = (size > 500) ? 500: size; + } - if (imageType) { - int thumbHeight = 80; - if (size != null) { - thumbHeight = (size > 500) ? 500 : size; - } + ThumbImage thumbImage = new ThumbImage(); - ThumbImage thumbImage = new ThumbImage(); - - thumbImage.makeThumb(isThumb, targetFile, thumbHeight); - data.setWidth(thumbImage.getImageWidth()); - data.setHeight(thumbImage.getImageHeight()); + thumbImage.makeThumb(isThumb, targetFile, thumbHeight); + data.setWidth(thumbImage.getImageWidth()); + data.setHeight(thumbImage.getImageHeight()); + } } - } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dao/SysAttachDao.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dao/SysAttachDao.java index 166e76b..dc3f543 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dao/SysAttachDao.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dao/SysAttachDao.java @@ -14,101 +14,101 @@ import java.util.Map; @Service public class SysAttachDao { - @Autowired - private FilePathGenerator filePathGenerator; - - @Autowired - private DbEngine dbEngine; - - /** - * 获取文件本地文件路径 - * - * @param filePath 相对路径 - * @return 本地文件全路径 - */ - public String getDiskPath(String filePath) { - return filePathGenerator.getFileDiskPath(filePath); - } - - /** - * 获取访问文件的URL地址 - * - * @param filePath 文件相对路径 - * @return 文件URL地址 - */ - public String getFileUrl(String filePath) { - return filePathGenerator.getFileUrl(filePath); - } - - /** - * 获取访问文件的URL地址 - * - * @param filePath 文件相对路径 - * @param filePath 文件名 - * @return 文件URL地址 - */ - public String getFileUrl(String filePath, String fileName) { - return "/fs/download?path=" + UriEncoder.encode(filePath) + "&name=" + UriEncoder.encode(fileName); - } - - public AttachPathPO get(Long id) { - if (id != null) { - return dbEngine.queryEntity("select attach_id, attach_name, attach_path, attach_content_type, attach_size, attach_create_time from sw_user.sys_attach where attach_id=?", - AttachPathPO.class, id); + @Autowired + private FilePathGenerator filePathGenerator; + + @Autowired + private DbEngine dbEngine; + + /** + * 获取文件本地文件路径 + * + * @param filePath 相对路径 + * @return 本地文件全路径 + */ + public String getDiskPath(String filePath) { + return filePathGenerator.getFileDiskPath(filePath); } - return null; - } + /** + * 获取访问文件的URL地址 + * + * @param filePath 文件相对路径 + * @return 文件URL地址 + */ + public String getFileUrl(String filePath) { + return filePathGenerator.getFileUrl(filePath); + } + + /** + * 获取访问文件的URL地址 + * + * @param filePath 文件相对路径 + * @param filePath 文件名 + * @return 文件URL地址 + */ + public String getFileUrl(String filePath, String fileName) { + return "/fs/download?path=" + UriEncoder.encode(filePath) + "&name=" + UriEncoder.encode(fileName); + } + + public AttachPathPO get(Long id) { + if (id != null) { + return dbEngine.queryEntity("select attach_id, attach_name, attach_path, attach_content_type, attach_size, attach_create_time from sw_user.sys_attach where attach_id=?", + AttachPathPO.class, id); + } + + return null; + } - // 删除文件记录和文件 - public void remove(Long fileId) { + // 删除文件记录和文件 + public void remove(Long fileId) { // if (id != null) { // return dbEngine.queryEntity("select attach_id, attach_name, attach_path, attach_content_type, attach_size, attach_create_time from sw_user.sys_attach where attach_id=?", // AttachPathPO.class, id); // } // // return null; - } + } - // 删除文件 - public void remove(String filePath) { + // 删除文件 + public void remove(String filePath) { // if (id != null) { // return dbEngine.queryEntity("select attach_id, attach_name, attach_path, attach_content_type, attach_size, attach_create_time from sw_user.sys_attach where attach_id=?", // AttachPathPO.class, id); // } // // return null; - } + } + + public List list(Long[] ids) { + if (ids != null && ids.length > 0) { + return dbEngine.query("select attach_id, attach_name, attach_path, attach_content_type, attach_size, attach_create_time from sw_user.sys_attach where attach_id in( " + + StringUtils.join(ids, ",") + ")", + AttachPathPO.class); + } - public List list(Long[] ids) { - if (ids != null && ids.length > 0) { - return dbEngine.query("select attach_id, attach_name, attach_path, attach_content_type, attach_size, attach_create_time from sw_user.sys_attach where attach_id in( " - + StringUtils.join(ids, ",") + ")", - AttachPathPO.class); + return null; } - return null; - } + public Map map(Long[] ids) { + List list = list(ids); + if (list != null && !list.isEmpty()) { + Map map = new HashMap<>(list.size()); + list.forEach((item) -> map.put(item.getAttachId(), item)); - public Map map(Long[] ids) { - List list = list(ids); - if (list != null && !list.isEmpty()) { - Map map = new HashMap<>(list.size()); - list.forEach((item) -> map.put(item.getAttachId(), item)); + return map; + } - return map; + return null; } - return null; - } + // 保持文件,删除临时文件记录,避免被定时删除 + public void retain(String filePath) { - // 保持文件,删除临时文件记录,避免被定时删除 - public void retain(String filePath) { - - } + } - // 保持文件,删除临时文件记录,避免被定时删除 - public void retain(Long fileId) { + // 保持文件,删除临时文件记录,避免被定时删除 + public void retain(Long fileId) { - } + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dataCacheInit/AttachFolderEntityBuffer.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dataCacheInit/AttachFolderEntityBuffer.java index 684bec9..dc3e840 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dataCacheInit/AttachFolderEntityBuffer.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/dataCacheInit/AttachFolderEntityBuffer.java @@ -20,13 +20,13 @@ public final class AttachFolderEntityBuffer { @Autowired private DbEngine dbEngine; - public static final String cacheKey="attach_folder_"; + public static final String cacheKey = "attach_folder_"; //根据附件路径和期间获取对象 public AttachFolderPojo getByPath(String attachPath, String period) { - return redisManager.get(cacheKey+attachPath + "_" + period, AttachFolderPojo.class); + return redisManager.get(cacheKey + attachPath + "_" + period, AttachFolderPojo.class); } @@ -45,27 +45,27 @@ public final class AttachFolderEntityBuffer { } //初始化数据 - public void initData(){ + public void initData() { //查询所有数据 - String sql="select folder_id,folder_path,folder_period,folder_max_seq,folder_file_count from "+ AttachFolder.ENTITY_NAME; - List returnList = dbEngine.query(sql,AttachFolder.class); - if(null !=returnList && returnList.size()>0){ - for(AttachFolder pojo:returnList){ - AttachFolderPojo p=new AttachFolderPojo(); + String sql = "select folder_id,folder_path,folder_period,folder_max_seq,folder_file_count from " + AttachFolder.ENTITY_NAME; + List returnList = dbEngine.query(sql, AttachFolder.class); + if (null != returnList && returnList.size() > 0) { + for (AttachFolder pojo : returnList) { + AttachFolderPojo p = new AttachFolderPojo(); p.setFolderId(pojo.getId()); p.setFolderAttachPath(pojo.getPath()); p.setFolderFileCount(pojo.getFileCount()); p.setFolderPeriod(pojo.getPeriod()); p.setFolderMaxSeq(pojo.getMaxSeq()); - redisManager.set(cacheKey+pojo.getPath()+"_"+pojo.getPeriod(),p,0); + redisManager.set(cacheKey + pojo.getPath() + "_" + pojo.getPeriod(), p, 0); } } } //写入一个数据 - public void putOneData(AttachFolderPojo pojo){ + public void putOneData(AttachFolderPojo pojo) { //查询所有数据 - redisManager.set(cacheKey+pojo.getFolderAttachPath()+"_"+pojo.getFolderPeriod(),pojo,0); + redisManager.set(cacheKey + pojo.getFolderAttachPath() + "_" + pojo.getFolderPeriod(), pojo, 0); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/AttachPathPO.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/AttachPathPO.java index 399bfc7..94af804 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/AttachPathPO.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/AttachPathPO.java @@ -4,10 +4,10 @@ import lombok.Data; @Data public class AttachPathPO { - private Long attachId; - private String attachName; - private String attachPath; - private String attachContentType; - private Long attachSize; - private Long attachCreate; + private Long attachId; + private String attachName; + private String attachPath; + private String attachContentType; + private Long attachSize; + private Long attachCreate; } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/FileDataVO.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/FileDataVO.java index 5754e26..2befe57 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/FileDataVO.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/FileDataVO.java @@ -4,5 +4,5 @@ import lombok.Data; @Data public class FileDataVO { - private String data; + private String data; } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/UploadDataVO.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/UploadDataVO.java index d67aeb4..356f952 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/UploadDataVO.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/entity/UploadDataVO.java @@ -4,12 +4,12 @@ import lombok.Data; @Data public class UploadDataVO { - private Long id; - private Integer height; - private Integer width; - private long size; - private String path; - private String name; - private String contentType; - private String url; + private Long id; + private Integer height; + private Integer width; + private long size; + private String path; + private String name; + private String contentType; + private String url; } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFileWork.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFileWork.java index 1fe6a88..1677dee 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFileWork.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFileWork.java @@ -19,12 +19,13 @@ import java.util.List; public final class AttachFileWork implements IAttachWorkIntf { @Autowired private FileConfigProperties properties; + private String getPath(String remoteFolderPath) { - String path =properties.getAttachPath(); + String path = properties.getAttachPath(); if (StringUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) path = path + "/" + remoteFolderPath; else path = path + remoteFolderPath; - path = path.replaceAll("-",""); + path = path.replaceAll("-", ""); UtilFile.makeDir(path); if (!path.endsWith("/")) path = path + "/"; return path; @@ -37,7 +38,7 @@ public final class AttachFileWork implements IAttachWorkIntf { public void saveAttach(String remoteAttachName, String remoteFolderPath, String localAttach, boolean isDelLocal) throws Exception { String dstFile = getFileName(remoteFolderPath, remoteAttachName); if (isDelLocal) UtilFile.renameTo(localAttach, dstFile); - else UtilFile.copy(localAttach,dstFile); + else UtilFile.copy(localAttach, dstFile); } @Override diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFtpWork.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFtpWork.java index 5437cb1..77fa099 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFtpWork.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachFtpWork.java @@ -31,6 +31,7 @@ public final class AttachFtpWork implements IAttachWorkIntf { Logger logger = LoggerFactory.getLogger(AttachFtpWork.class); @Autowired private FileConfigProperties properties; + private String getPath(String remoteFolderPath) { String path = properties.getAttachPath(); if (StringUtil.isNotEmpty(remoteFolderPath) && !path.endsWith("/") && !remoteFolderPath.startsWith("/")) @@ -169,7 +170,7 @@ public final class AttachFtpWork implements IAttachWorkIntf { getFtpManager().execute(new FtpTask() { public Object execute(IFtpUtil ftp) throws Exception { try { - ftp.downloadFileEx(getPath(remotePath), remoteName,localPath + File.separator + localName ); + ftp.downloadFileEx(getPath(remotePath), remoteName, localPath + File.separator + localName); } catch (Exception e) { e.printStackTrace(); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java index 129e9ed..1deb63d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java @@ -31,8 +31,9 @@ public final class AttachHelper { private DbEngine dbEngine; @Autowired private AttachUtil attachUtil; + //得到附件临时目录 - public String getAttachTmpPath() { + public String getAttachTmpPath() { String tmp_attach = properties.getAttachTempPath(); if (!tmp_attach.endsWith("/")) tmp_attach += "/"; File file = new File(tmp_attach); @@ -43,10 +44,10 @@ public final class AttachHelper { } //删除ftp服务器的文件 - public boolean deleteOneAttach(String attachId) throws Exception { + public boolean deleteOneAttach(String attachId) throws Exception { if (StringUtil.isEmpty(attachId)) return true; AttachInfo attachInfo = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); - if(null == attachInfo){ + if (null == attachInfo) { return true; } boolean deleteSuccess = deleteAttachInFtpServer(attachInfo.getPath(), attachInfo.getName()); @@ -57,7 +58,7 @@ public final class AttachHelper { } //删除ftp服务器的文件 - public boolean deleteOneAttach(AttachInfo bean) { + public boolean deleteOneAttach(AttachInfo bean) { boolean deleteSuccess = deleteAttachInFtpServer(bean.getPath(), bean.getName()); if (deleteSuccess) { dbEngine.deleteEntity(bean); @@ -66,41 +67,41 @@ public final class AttachHelper { } //删除ftp服务器的文件夹 - public void deleteFolder(final String remotePath) throws Exception { + public void deleteFolder(final String remotePath) throws Exception { attachUtil.deletePath(remotePath); } - public List getAttachListByOwnerId(String ownerId) throws Exception { - return dbEngine.query("select * from "+AttachInfo.ENTITY_NAME+" where attach_owner_id=? ",AttachInfo.class,ownerId); + public List getAttachListByOwnerId(String ownerId) throws Exception { + return dbEngine.query("select * from " + AttachInfo.ENTITY_NAME + " where attach_owner_id=? ", AttachInfo.class, ownerId); } - public List listAttachListByOwnerIdAndType(String ownerId, String attach_type) throws Exception { - return dbEngine.query("select * from "+AttachInfo.ENTITY_NAME+" where attach_owner_id=? and attach_type=? ",AttachInfo.class,ownerId,attach_type); + public List listAttachListByOwnerIdAndType(String ownerId, String attach_type) throws Exception { + return dbEngine.query("select * from " + AttachInfo.ENTITY_NAME + " where attach_owner_id=? and attach_type=? ", AttachInfo.class, ownerId, attach_type); } - public int getAttachCountByOwnerId(String ownerId) throws Exception { - return dbEngine.queryInt("select count(0) from "+AttachInfo.ENTITY_NAME+" where attach_owner_id=? ",ownerId); + public int getAttachCountByOwnerId(String ownerId) throws Exception { + return dbEngine.queryInt("select count(0) from " + AttachInfo.ENTITY_NAME + " where attach_owner_id=? ", ownerId); } //根据附件拥有者和附件类型删除 - public boolean deleteAttachByOwnerIdAndType(String ownerId, String attachType) throws Exception { + public boolean deleteAttachByOwnerIdAndType(String ownerId, String attachType) throws Exception { final List list = listAttachListByOwnerIdAndType(ownerId, attachType); return deleteAttachListEx(list); } - public boolean deleteAttachByOwnerId(String ownerId) throws Exception { + public boolean deleteAttachByOwnerId(String ownerId) throws Exception { final List list = getAttachListByOwnerId(ownerId); return deleteAttachListEx(list); } //批量删除 - public boolean deleteAttachList(List attachIdList) throws Exception { + public boolean deleteAttachList(List attachIdList) throws Exception { if (CommUtil.isEmpty(attachIdList)) return false; - dbEngine.update("delete from "+AttachInfo.ENTITY_NAME+" where attach_id in(" + CommUtil.getSqlInStr(attachIdList) + ")"); + dbEngine.update("delete from " + AttachInfo.ENTITY_NAME + " where attach_id in(" + CommUtil.getSqlInStr(attachIdList) + ")"); return true; } - public boolean deleteAttachListEx(List list) throws Exception { + public boolean deleteAttachListEx(List list) throws Exception { boolean result = true; for (AttachInfo bean : list) { if (!deleteAttachInFtpServer(bean.getPath(), bean.getName())) { @@ -117,7 +118,7 @@ public final class AttachHelper { } //删除在ftp服务器上的附件 - public boolean deleteAttachInFtpServer(String remotePath, String remoteName) { + public boolean deleteAttachInFtpServer(String remotePath, String remoteName) { try { attachUtil.deleteAttach(remotePath, remoteName); } catch (Exception e) { @@ -135,7 +136,7 @@ public final class AttachHelper { * @return 返回文件名 * @throws Exception */ - public String getAttachFromFtp(final String attachId, final String localPath) throws Exception { + public String getAttachFromFtp(final String attachId, final String localPath) throws Exception { AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); if (null == attach) throw new Exception("附件不存在!"); @@ -155,7 +156,7 @@ public final class AttachHelper { * @return 返回文件名 * @throws Exception */ - public String getAttachFromFtp(final String attachId, final String localPath, String localName) throws Exception { + public String getAttachFromFtp(final String attachId, final String localPath, String localName) throws Exception { AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, Long.valueOf(attachId)); if (null == attach) throw new Exception("附件不存在!"); final String remoteFileName = attach.getName(); @@ -174,7 +175,7 @@ public final class AttachHelper { * @return 返回文件名列表,本地有此文件将不再下载 * @throws Exception */ - private List getAttachListFromFtp(final List attachlist, final String ownerType) throws Exception { + private List getAttachListFromFtp(final List attachlist, final String ownerType) throws Exception { return attachUtil.getAttachListFromFtp(attachlist, ownerType, getAttachTmpPath()); } @@ -186,7 +187,7 @@ public final class AttachHelper { * @return 返回文件名列表,本地有此文件将不再下载 * @throws Exception */ - public List getAttachsFromFtp(final String ownerId, final String ownerType) throws Exception { + public List getAttachsFromFtp(final String ownerId, final String ownerType) throws Exception { final List attachlist = getAttachListByOwnerId(ownerId); return getAttachListFromFtp(attachlist, ownerType); @@ -201,20 +202,20 @@ public final class AttachHelper { * @return 返回文件名列表,本地有此文件将不再下载 * @throws Exception */ - public List getAttachsFromFtp(final List attachIds, final String ownerType) throws Exception { + public List getAttachsFromFtp(final List attachIds, final String ownerType) throws Exception { List paras = new ArrayList(); if (!CommUtil.isEmpty(attachIds)) { StringBuilder sb = new StringBuilder(128); - for(int i=0;i attachlist =dbEngine.queryWhere(AttachInfo.class,sb.toString(),paras.toArray()); - if (null == attachlist || attachlist.size()<1) throw new Exception("附件不存在!"); + final List attachlist = dbEngine.queryWhere(AttachInfo.class, sb.toString(), paras.toArray()); + if (null == attachlist || attachlist.size() < 1) throw new Exception("附件不存在!"); return getAttachListFromFtp(attachlist, ownerType); } return new ArrayList<>(); @@ -225,7 +226,7 @@ public final class AttachHelper { * * @return */ - public String getSizeStr(long fileSize) { + public String getSizeStr(long fileSize) { if (fileSize < 1024) return fileSize + "B"; double n = fileSize * 1.0 / 1024; if (NumberUtil.compare(n, 1024) < 0) return NumberUtil.toStdNumberString(n, 0) + "KB"; @@ -239,23 +240,23 @@ public final class AttachHelper { * @param attach_owner_id 拥有者 * @throws Exception */ - public void removeTempTag(String attach_owner_id) throws Exception { - dbEngine.update("update "+AttachInfo.ENTITY_NAME+" set attach_is_temp=0 WHERE attach_owner_id=? AND attach_is_temp=1 ",attach_owner_id); + public void removeTempTag(String attach_owner_id) throws Exception { + dbEngine.update("update " + AttachInfo.ENTITY_NAME + " set attach_is_temp=0 WHERE attach_owner_id=? AND attach_is_temp=1 ", attach_owner_id); } - public String copyupload(String type,Long attachId) { + public String copyupload(String type, Long attachId) { AttachInfo attach = dbEngine.queryEntity(AttachInfo.class, attachId); - if(attach==null){ + if (attach == null) { return ""; } - String remoteName =attach.getId()+attach.getName().substring(attach.getName().lastIndexOf(".")); + String remoteName = attach.getId() + attach.getName().substring(attach.getName().lastIndexOf(".")); String remotePath = attach.getPath(); - String filePath =getAttachTmpPath()+"tempFiles/"; + String filePath = getAttachTmpPath() + "tempFiles/"; UtilFile.makeDir(filePath); Map map = null; try { attachUtil.downloadAttach(remotePath, remoteName, filePath); - String filePaths=filePath+remoteName; + String filePaths = filePath + remoteName; attach.setId(dbEngine.nextId()); attach.setType(type);//附件类别 @@ -263,7 +264,7 @@ public final class AttachHelper { attach.setPartyId(-1l); attach.setTime(DateUtil.nowDateTimeLong()); attach.setUserId(-1l); - attach.setName(attach.getId()+attach.getSuffix()); + attach.setName(attach.getId() + attach.getSuffix()); // 上传文件域对象 File upload = new File(filePaths); // attach.setAttachSize((long) FileCopyUtils.copy(file.getInputStream(), new BufferedOutputStream(new FileOutputStream(upload)))); @@ -276,10 +277,10 @@ public final class AttachHelper { } finally { UtilFile.delFile(upload.getAbsolutePath()); } - }catch (Exception e){ + } catch (Exception e) { logger.error("复制文件失败", e); return ""; } - return attach.getId()+""; + return attach.getId() + ""; } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java index af1a2bc..9dd8ae2 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java @@ -24,7 +24,7 @@ import java.util.List; public final class AttachUtil { //一个文件夹下最多允许多少文件 private final static int MAX_FILE_COUNT = 1000; - private static IAttachWorkIntf worker; + private static IAttachWorkIntf worker; @Autowired private FileConfigProperties properties; @Autowired @@ -35,22 +35,23 @@ public final class AttachUtil { private AttachFtpWork attachFtpWork; @Autowired private AttachFileWork attachFileWork; + static { // init(); } - public void init() { + public void init() { final String at = StringUtil.checkNull(properties.getAttachType()).toLowerCase(); if ("ftp".equals(at) || "sftp".equals(at)) worker = attachFtpWork; else worker = attachFileWork; } - private void checkAttachFolder(final AttachInfo attach) throws Exception { + private void checkAttachFolder(final AttachInfo attach) throws Exception { final String period = DateUtil.getNowYm(); AttachFolderPojo folder = attachFolderEntityBuffer.getByPath(attach.getPath(), period); - AttachFolder entity=new AttachFolder(); + AttachFolder entity = new AttachFolder(); boolean isNew = false; if (folder == null) { isNew = true; @@ -92,43 +93,43 @@ public final class AttachUtil { } } - public void saveAttach(String remoteAttachName, String remoteFolderPath, String localAttach, boolean isDelLocal) throws Exception { + public void saveAttach(String remoteAttachName, String remoteFolderPath, String localAttach, boolean isDelLocal) throws Exception { worker.saveAttach(remoteAttachName, remoteFolderPath, localAttach, isDelLocal); } - public void copyAttach(String srcFileName, String desFileName, String remoteFolderPath, boolean isDelSrc) throws Exception { + public void copyAttach(String srcFileName, String desFileName, String remoteFolderPath, boolean isDelSrc) throws Exception { worker.copyAttach(srcFileName, desFileName, remoteFolderPath, isDelSrc); } - public void deletePath(String remotePath) throws Exception { + public void deletePath(String remotePath) throws Exception { worker.deletePath(remotePath); } - public void deleteAttach(String remotePath, String remoteName) throws Exception { + public void deleteAttach(String remotePath, String remoteName) throws Exception { worker.deleteAttach(remotePath, remoteName); } - public void downloadAttach(String remotePath, String remoteName, String fileName, HttpServletResponse response) throws Exception { + public void downloadAttach(String remotePath, String remoteName, String fileName, HttpServletResponse response) throws Exception { worker.downloadAttach(remotePath, remoteName, fileName, response); } - public void downloadAttach(String remotePath, String remoteName, String localPath) throws Exception { + public void downloadAttach(String remotePath, String remoteName, String localPath) throws Exception { worker.downloadAttach(remotePath, remoteName, localPath); } - public void downloadAttach(String remotePath, String remoteName, String localPath, String localName) throws Exception { + public void downloadAttach(String remotePath, String remoteName, String localPath, String localName) throws Exception { worker.downloadAttach(remotePath, remoteName, localPath, localName); } - public List getAttachListFromFtp(final List attachlist, final String ownerType, final String localRoot) throws Exception { + public List getAttachListFromFtp(final List attachlist, final String ownerType, final String localRoot) throws Exception { return worker.getAttachListFromFtp(attachlist, ownerType, localRoot); } - public void makeRemoteDir(String path) throws Exception { + public void makeRemoteDir(String path) throws Exception { worker.makeRemoteDir(path); } - public Path getAttachPath(String remotePath, String remoteName) throws Exception { + public Path getAttachPath(String remotePath, String remoteName) throws Exception { return worker.getAttachPath(remotePath, remoteName); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/IAttachWorkIntf.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/IAttachWorkIntf.java index 1702aff..61d662f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/IAttachWorkIntf.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/IAttachWorkIntf.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.spring.file.attach; - import cc.smtweb.system.bpm.web.sys.base.attach.AttachInfo; import javax.servlet.http.HttpServletResponse; @@ -28,10 +27,10 @@ public interface IAttachWorkIntf { /** * 复制附件 * - * @param srcFileName 源文件 - * @param desFileName 新文件 - * @param remoteFolderPath 文件路径 - * @param isDelSrc 保存后是否删除源文件 + * @param srcFileName 源文件 + * @param desFileName 新文件 + * @param remoteFolderPath 文件路径 + * @param isDelSrc 保存后是否删除源文件 * @throws Exception */ void copyAttach(String srcFileName, String desFileName, String remoteFolderPath, boolean isDelSrc) throws Exception; @@ -109,7 +108,6 @@ public interface IAttachWorkIntf { /** * 获取文件路径 - * */ Path getAttachPath(String remotePath, String remoteName); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/initPlugin/RunDataInit.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/initPlugin/RunDataInit.java index 83a1484..b6c87f8 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/initPlugin/RunDataInit.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/initPlugin/RunDataInit.java @@ -18,6 +18,7 @@ public class RunDataInit implements ApplicationRunner { private AttachFolderEntityBuffer attachFolderEntityBuffer; @Autowired private AttachUtil attachUtil; + @Override public void run(ApplicationArguments args) throws Exception { attachFolderEntityBuffer.initData();//附件目录缓存 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/BeanUtil.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/BeanUtil.java index 4dbeabb..3a848b9 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/BeanUtil.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/BeanUtil.java @@ -1,7 +1,7 @@ package cc.smtweb.system.bpm.util; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.common.SwMap; +import cc.smtweb.framework.core.exception.SwException; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.FatalBeanException; @@ -17,104 +17,104 @@ import java.util.Arrays; import java.util.List; public class BeanUtil { - private BeanUtil() {} + private BeanUtil() { + } - public static void mapToBean(SwMap source, Object target) { - mapToBean(source, target, null); - } + public static void mapToBean(SwMap source, Object target) { + mapToBean(source, target, null); + } - private static void mapToBean(SwMap source, Object target, @Nullable Class editable, - @Nullable String... ignoreProperties) throws BeansException { - Assert.notNull(source, "Source must not be null"); - Assert.notNull(target, "Target must not be null"); + private static void mapToBean(SwMap source, Object target, @Nullable Class editable, + @Nullable String... ignoreProperties) throws BeansException { + Assert.notNull(source, "Source must not be null"); + Assert.notNull(target, "Target must not be null"); - Class actualEditable = target.getClass(); - if (editable != null) { - if (!editable.isInstance(target)) { - throw new IllegalArgumentException("Target class [" + target.getClass().getName() + - "] not assignable to Editable class [" + editable.getName() + "]"); - } - actualEditable = editable; - } - PropertyDescriptor[] targetPds = BeanUtils.getPropertyDescriptors(actualEditable); - List ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null); + Class actualEditable = target.getClass(); + if (editable != null) { + if (!editable.isInstance(target)) { + throw new IllegalArgumentException("Target class [" + target.getClass().getName() + + "] not assignable to Editable class [" + editable.getName() + "]"); + } + actualEditable = editable; + } + PropertyDescriptor[] targetPds = BeanUtils.getPropertyDescriptors(actualEditable); + List ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties): null); - for (PropertyDescriptor targetPd : targetPds) { - Method writeMethod = targetPd.getWriteMethod(); - if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) { - Object value = source.get(targetPd.getName()); + for (PropertyDescriptor targetPd : targetPds) { + Method writeMethod = targetPd.getWriteMethod(); + if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) { + Object value = source.get(targetPd.getName()); - if (value == null || ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], value.getClass())) { - try { - if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { - writeMethod.setAccessible(true); + if (value == null || ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], value.getClass())) { + try { + if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { + writeMethod.setAccessible(true); + } + writeMethod.invoke(target, value); + } catch (Throwable ex) { + throw new FatalBeanException( + "Could not copy property '" + targetPd.getName() + "' from source to target", ex); + } + } } - writeMethod.invoke(target, value); - } catch (Throwable ex) { - throw new FatalBeanException( - "Could not copy property '" + targetPd.getName() + "' from source to target", ex); - } } - } } - } - public static void beanToMap(Object source, SwMap target, @Nullable String... ignoreProperties) throws BeansException { - Assert.notNull(source, "Source must not be null"); - Assert.notNull(target, "Target must not be null"); + public static void beanToMap(Object source, SwMap target, @Nullable String... ignoreProperties) throws BeansException { + Assert.notNull(source, "Source must not be null"); + Assert.notNull(target, "Target must not be null"); - List ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null); + List ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties): null); - PropertyDescriptor[] sourcePds = BeanUtils.getPropertyDescriptors(source.getClass()); + PropertyDescriptor[] sourcePds = BeanUtils.getPropertyDescriptors(source.getClass()); - for (PropertyDescriptor sourcePd: sourcePds) { - if (ignoreList == null || !ignoreList.contains(sourcePd.getName())) { + for (PropertyDescriptor sourcePd : sourcePds) { + if (ignoreList == null || !ignoreList.contains(sourcePd.getName())) { // PropertyDescriptor sourcePd = BeanUtils.getPropertyDescriptor(source.getClass(), targetPd.getKey()); // if (sourcePd != null) { - Method readMethod = sourcePd.getReadMethod(); - if (readMethod != null) { - try { - if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { - readMethod.setAccessible(true); - } - Object value = readMethod.invoke(source); - target.put(sourcePd.getName(), value); - } - catch (Throwable ex) { - throw new FatalBeanException( - "Could not copy property '" + sourcePd.getName() + "' from source to target", ex); - } - } + Method readMethod = sourcePd.getReadMethod(); + if (readMethod != null) { + try { + if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { + readMethod.setAccessible(true); + } + Object value = readMethod.invoke(source); + target.put(sourcePd.getName(), value); + } catch (Throwable ex) { + throw new FatalBeanException( + "Could not copy property '" + sourcePd.getName() + "' from source to target", ex); + } + } // } - } + } + } } - } - public static List toBeanList(List bodyList, Class clazz) { - List beans = new ArrayList<>(bodyList.size()); - try { - for (SwMap body: bodyList) { - Object bean = clazz.newInstance(); - BeanUtil.mapToBean(body, bean); - beans.add(bean); - } - } catch (InstantiationException | IllegalAccessException e) { - throw new SwException(e); + public static List toBeanList(List bodyList, Class clazz) { + List beans = new ArrayList<>(bodyList.size()); + try { + for (SwMap body : bodyList) { + Object bean = clazz.newInstance(); + BeanUtil.mapToBean(body, bean); + beans.add(bean); + } + } catch (InstantiationException | IllegalAccessException e) { + throw new SwException(e); + } + return beans; } - return beans; - } - public static List toMapList(List beans) { - List bodyList = null; - if (beans != null) { - bodyList = new ArrayList<>(beans.size()); - for (Object bean: beans) { - SwMap body = new SwMap(); - beanToMap(bean, body); - bodyList.add(body); - } - } + public static List toMapList(List beans) { + List bodyList = null; + if (beans != null) { + bodyList = new ArrayList<>(beans.size()); + for (Object bean : beans) { + SwMap body = new SwMap(); + beanToMap(bean, body); + bodyList.add(body); + } + } - return bodyList; - } + return bodyList; + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java index dc041a1..2b5924e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/CodeGenerator.java @@ -1,9 +1,9 @@ package cc.smtweb.system.bpm.util; import cc.smtweb.framework.core.common.SwConsts; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.DbEngine; +import cc.smtweb.framework.core.exception.SwException; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateMethodModelEx; @@ -12,7 +12,6 @@ import org.apache.commons.io.IOUtils; import java.io.*; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FileDynPath.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FileDynPath.java index 34e841b..879e936 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FileDynPath.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FileDynPath.java @@ -53,7 +53,7 @@ public class FileDynPath extends FileFixPath { // 如果文件数量太大就需要创建新子目录 while (this.fileCount >= MAX_FILE_COUNT) { this.pathIndex++; - if(this.pathIndex > MAX_DIR_COUNT) { + if (this.pathIndex > MAX_DIR_COUNT) { throw new RuntimeException("dir is two many"); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FilePathGenerator.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FilePathGenerator.java index 4d307ba..3804dbb 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FilePathGenerator.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FilePathGenerator.java @@ -1,16 +1,16 @@ package cc.smtweb.system.bpm.util; -import java.text.SimpleDateFormat; -import java.util.HashMap; -import java.util.Map; - +import cc.smtweb.framework.core.db.jdbc.IdGenerator; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.tika.mime.MimeType; import org.apache.tika.mime.MimeTypeException; import org.apache.tika.mime.MimeTypes; import org.springframework.web.multipart.MultipartFile; -import cc.smtweb.framework.core.db.jdbc.IdGenerator; + +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.Map; /** * 文件名生成规则 subDir/[yyyymm]/[d]/[hex(fileid)]_[hex(rand)].[fileExt] 如果文件是图片格式,会生成缩略图,文件名会直接添加.thumb.jpg后缀 规则参数 yyyymm: @@ -19,50 +19,51 @@ import cc.smtweb.framework.core.db.jdbc.IdGenerator; @Slf4j public class FilePathGenerator { - public static final String THUMB_FILE_EXT = ".thumb.jpg"; - // 文件时间是否作为PK - private SimpleDateFormat sdf; - @Getter - private String rootPath; - private Map fileFxPathMap = new HashMap<>(); - private Map fileDynPathMap = new HashMap<>(); - private String fileUrl; - private IdGenerator idGenerator; - - public FilePathGenerator(String rootPath, String fileUrl, IdGenerator idGenerator) { - this.fileUrl = fixEnd(fileUrl); - this.idGenerator = idGenerator; - this.rootPath = fixEnd(rootPath); - - sdf = new SimpleDateFormat("yyyyMM/dd/"); - } - - private static String fixEnd(String path) { - if (path.endsWith("/") || path.endsWith("\\")) { - return path; - } else { - return path + "/"; - } - } - - /** - * 生成文件路径,根据日期分目录存储 - * - * @param subPath 子目录,区分不同应用的文件 - * @param originalFileName 原始的文件名,用于提取扩展名用 - * @return 文件路径信息类 - */ - public FilePathInfo make(String subPath, String originalFileName) { - return make(subPath, originalFileName, null, false); - } - - public FilePathInfo make(String subPath, String originalFileName, boolean keepName) { - return make(subPath, originalFileName, null, keepName); - } + public static final String THUMB_FILE_EXT = ".thumb.jpg"; + // 文件时间是否作为PK + private SimpleDateFormat sdf; + @Getter + private String rootPath; + private Map fileFxPathMap = new HashMap<>(); + private Map fileDynPathMap = new HashMap<>(); + private String fileUrl; + private IdGenerator idGenerator; + + public FilePathGenerator(String rootPath, String fileUrl, IdGenerator idGenerator) { + this.fileUrl = fixEnd(fileUrl); + this.idGenerator = idGenerator; + this.rootPath = fixEnd(rootPath); + + sdf = new SimpleDateFormat("yyyyMM/dd/"); + } + + private static String fixEnd(String path) { + if (path.endsWith("/") || path.endsWith("\\")) { + return path; + } else { + return path + "/"; + } + } + /** * 生成文件路径,根据日期分目录存储 * - * @param subPath 子目录,区分不同应用的文件 + * @param subPath 子目录,区分不同应用的文件 + * @param originalFileName 原始的文件名,用于提取扩展名用 + * @return 文件路径信息类 + */ + public FilePathInfo make(String subPath, String originalFileName) { + return make(subPath, originalFileName, null, false); + } + + public FilePathInfo make(String subPath, String originalFileName, boolean keepName) { + return make(subPath, originalFileName, null, keepName); + } + + /** + * 生成文件路径,根据日期分目录存储 + * + * @param subPath 子目录,区分不同应用的文件 * @param multipartFile 上传文件流,用于提取扩展名用 * @return 文件路径信息类 */ @@ -71,23 +72,23 @@ public class FilePathGenerator { } private synchronized FilePathInfo make(String subPath, String originFileName, String contentType, boolean keepName) { - if (keepName) { - FileFixPath filePathSub = fileFxPathMap.get(subPath); - if (filePathSub == null) { - filePathSub = new FileFixPath(this.rootPath, subPath); - fileFxPathMap.put(subPath, filePathSub); - } + if (keepName) { + FileFixPath filePathSub = fileFxPathMap.get(subPath); + if (filePathSub == null) { + filePathSub = new FileFixPath(this.rootPath, subPath); + fileFxPathMap.put(subPath, filePathSub); + } - return filePathSub.makeDatePath(this.idGenerator.nextId(), originFileName); - } else { - FileDynPath filePathSub = fileDynPathMap.get(subPath); - if (filePathSub == null) { - filePathSub = new FileDynPath(this.rootPath, subPath, sdf); - fileDynPathMap.put(subPath, filePathSub); - } + return filePathSub.makeDatePath(this.idGenerator.nextId(), originFileName); + } else { + FileDynPath filePathSub = fileDynPathMap.get(subPath); + if (filePathSub == null) { + filePathSub = new FileDynPath(this.rootPath, subPath, sdf); + fileDynPathMap.put(subPath, filePathSub); + } - return filePathSub.makeDatePath(this.idGenerator.nextId(), ext(originFileName, contentType)); - } + return filePathSub.makeDatePath(this.idGenerator.nextId(), ext(originFileName, contentType)); + } } private static String ext(String filename, String contentType) { @@ -127,6 +128,6 @@ public class FilePathGenerator { // 获取下载路径前缀 public String getDownloadUrl() { - return this.fileUrl; + return this.fileUrl; } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FilePathInfo.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FilePathInfo.java index de9557e..8b01116 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FilePathInfo.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/FilePathInfo.java @@ -9,40 +9,40 @@ import lombok.Getter; */ @Getter public class FilePathInfo { - // 文件ID - private long fileId; - // 文件创建时间,数据库需要存储 - private long fileTime; - // 文件子路径 - private String subPath; - // 文件名 - private String fileName; - // 本地根路径 - private String rootPath; + // 文件ID + private long fileId; + // 文件创建时间,数据库需要存储 + private long fileTime; + // 文件子路径 + private String subPath; + // 文件名 + private String fileName; + // 本地根路径 + private String rootPath; - public FilePathInfo(String rootPath, String subPath, long fileTime, String fileName, long fileId) { - this.rootPath = rootPath; - this.subPath = subPath; - this.fileTime = fileTime; - this.fileName = fileName; - this.fileId = fileId; - } + public FilePathInfo(String rootPath, String subPath, long fileTime, String fileName, long fileId) { + this.rootPath = rootPath; + this.subPath = subPath; + this.fileTime = fileTime; + this.fileName = fileName; + this.fileId = fileId; + } - /** - * 获取本地需要存储的文件全路径 - */ - public String getFullFileName() { - return getDiskFilePath(); - } + /** + * 获取本地需要存储的文件全路径 + */ + public String getFullFileName() { + return getDiskFilePath(); + } - public String getDiskFilePath() { - return this.rootPath + subPath + fileName; - } + public String getDiskFilePath() { + return this.rootPath + subPath + fileName; + } - /** - * 获取数据库存储需要的文件全路径 - */ - public String getMysqlFilePath() { - return subPath + fileName; - } + /** + * 获取数据库存储需要的文件全路径 + */ + public String getMysqlFilePath() { + return subPath + fileName; + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ITreeDataHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ITreeDataHandler.java index ec08884..b856af4 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ITreeDataHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ITreeDataHandler.java @@ -4,42 +4,50 @@ import java.util.List; /** * 树型节点句柄 + * * @author xkliu */ public interface ITreeDataHandler { - /** - * 获取ID - * @param node 节点 - * @return 节点ID - */ - Long getId(T node); + /** + * 获取ID + * + * @param node 节点 + * @return 节点ID + */ + Long getId(T node); - /** - * 获取上级ID - * @param node 当前节点 - * @return 上级ID - */ - Long getParentId(T node); + /** + * 获取上级ID + * + * @param node 当前节点 + * @return 上级ID + */ + Long getParentId(T node); // void addChild(IWebTreeVO item); - /** - * 获取下级对象列表 - * @param node 当前节点 - * @return 下级对象列表 - */ - List getChildren(T node); + /** + * 获取下级对象列表 + * + * @param node 当前节点 + * @return 下级对象列表 + */ + List getChildren(T node); - /** - * 设置下级对象列表 - * @param children 下级对象列表 - */ - void setChildren(T node, List children); + /** + * 设置下级对象列表 + * + * @param children 下级对象列表 + */ + void setChildren(T node, List children); - /** - * 是否强行添加未找到上级的错误节点到顶级 - * @param node 通过node有parentId值,但未找到对应上级节点 - * @return 是否强行添加错误节点到顶级 - */ - default boolean forceAdd(T node) { return false; } + /** + * 是否强行添加未找到上级的错误节点到顶级 + * + * @param node 通过node有parentId值,但未找到对应上级节点 + * @return 是否强行添加错误节点到顶级 + */ + default boolean forceAdd(T node) { + return false; + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ITreeDataLevelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ITreeDataLevelHandler.java index 2e43c00..e92ab8d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ITreeDataLevelHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ITreeDataLevelHandler.java @@ -1,6 +1,7 @@ package cc.smtweb.system.bpm.util; public interface ITreeDataLevelHandler extends ITreeDataHandler { - int getLevel(T t); - void setLevel(T t, int level); + int getLevel(T t); + + void setLevel(T t, int level); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/IdeaUtil.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/IdeaUtil.java index 8b0d2ba..cc42832 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/IdeaUtil.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/IdeaUtil.java @@ -1,18 +1,13 @@ package cc.smtweb.system.bpm.util; -import cc.smtweb.framework.core.common.SwMap; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import lombok.Data; -import org.apache.commons.io.FileUtils; import java.io.File; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,6 +18,7 @@ import java.util.Map; */ public class IdeaUtil { private final static int MODE_POM = 1; + //获取工程中的Module文件 public static Map getModules(String ideaPath, int mode) { if (mode == MODE_POM) { @@ -41,7 +37,7 @@ public class IdeaUtil { Map map = new HashMap<>(); PomProject project = XmlUtil.readValue(file, PomProject.class); if (project == null || project.modules == null) return map; - for (String module: project.modules) { + for (String module : project.modules) { File f = new File(ideaPath + "/" + module); String s = f.getName(); int i = s.lastIndexOf("."); @@ -50,11 +46,12 @@ public class IdeaUtil { } return map; } + public static Map getModulesFromModule(String ideaPath, File file) { Map map = new HashMap<>(); IdeaProject project = XmlUtil.readValue(file, IdeaProject.class); if (project == null || project.component == null || project.component.modules == null) return map; - for (Module module: project.component.modules) { + for (Module module : project.component.modules) { String s = module.filepath.replace("$PROJECT_DIR$", ideaPath); File f = new File(s); s = f.getName(); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/MemMultipartFile.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/MemMultipartFile.java index 33f5681..82af5c9 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/MemMultipartFile.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/MemMultipartFile.java @@ -6,74 +6,74 @@ import org.springframework.web.multipart.MultipartFile; import java.io.*; public class MemMultipartFile implements MultipartFile { - private static final String DATA_IMAGE = "data:image/"; - private byte[] data; - private String contentType; - private String filename; + private static final String DATA_IMAGE = "data:image/"; + private byte[] data; + private String contentType; + private String filename; - public static MemMultipartFile build(String dataUrl) { - if (dataUrl != null && dataUrl.startsWith(DATA_IMAGE)) { - // data:image/png;base64, - int pos1 = dataUrl.indexOf(';', DATA_IMAGE.length()); - int pos2 = dataUrl.indexOf(',', DATA_IMAGE.length()); - if (pos1 > 0 && pos2 > pos1) { - byte[] data = Base64.decodeBase64(dataUrl.substring(pos2)); + public static MemMultipartFile build(String dataUrl) { + if (dataUrl != null && dataUrl.startsWith(DATA_IMAGE)) { + // data:image/png;base64, + int pos1 = dataUrl.indexOf(';', DATA_IMAGE.length()); + int pos2 = dataUrl.indexOf(',', DATA_IMAGE.length()); + if (pos1 > 0 && pos2 > pos1) { + byte[] data = Base64.decodeBase64(dataUrl.substring(pos2)); - if (data != null) { - String contentType = dataUrl.substring(5, pos1); - return new MemMultipartFile(contentType.replace('/', '.'), contentType, data); + if (data != null) { + String contentType = dataUrl.substring(5, pos1); + return new MemMultipartFile(contentType.replace('/', '.'), contentType, data); + } + } } - } - } - return null; - } + return null; + } - private MemMultipartFile(String filename, String contentType, byte[] data) { - this.data = data; - this.contentType = contentType; - this.filename = filename; - } + private MemMultipartFile(String filename, String contentType, byte[] data) { + this.data = data; + this.contentType = contentType; + this.filename = filename; + } - @Override - public String getName() { - return "data"; - } + @Override + public String getName() { + return "data"; + } - @Override - public String getOriginalFilename() { - return filename; - } + @Override + public String getOriginalFilename() { + return filename; + } - @Override - public String getContentType() { - return contentType; - } + @Override + public String getContentType() { + return contentType; + } - @Override - public boolean isEmpty() { - return data.length == 0; - } + @Override + public boolean isEmpty() { + return data.length == 0; + } - @Override - public long getSize() { - return data.length; - } + @Override + public long getSize() { + return data.length; + } - @Override - public byte[] getBytes() throws IOException { - return data; - } + @Override + public byte[] getBytes() throws IOException { + return data; + } - @Override - public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(data); - } + @Override + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(data); + } - @Override - public void transferTo(File file) throws IOException, IllegalStateException { - try(FileOutputStream os = new FileOutputStream(file)) { - os.write(data); + @Override + public void transferTo(File file) throws IOException, IllegalStateException { + try (FileOutputStream os = new FileOutputStream(file)) { + os.write(data); + } } - } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ThumbImage.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ThumbImage.java index e3b2d22..1b43d06 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ThumbImage.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ThumbImage.java @@ -1,13 +1,5 @@ package cc.smtweb.system.bpm.util; -import java.awt.Color; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.List; - -import javax.imageio.ImageIO; - import lombok.Getter; import net.coobird.thumbnailator.Thumbnails; import net.coobird.thumbnailator.geometry.Positions; @@ -15,95 +7,104 @@ import net.coobird.thumbnailator.resizers.configurations.Antialiasing; import net.sf.image4j.codec.ico.ICODecoder; import org.apache.commons.lang3.StringUtils; +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.List; + /** * 缩略图生成工具 + * * @author xkliu */ @Getter public class ThumbImage { - // 图片处理方式 - public static final int TYPE_DEFAULT = 1; - public static final int TYPE_THUMB = 2; - public static final int TYPE_AVATAR = 3; - - private int imageWidth; - private int imageHeight; - - public static int type(String thumb) { - // 解决历史遗留boolean类型 - if (StringUtils.isBlank(thumb) || "false".equalsIgnoreCase(thumb)) { - return TYPE_DEFAULT; - } - - if ("true".equalsIgnoreCase(thumb)) { - return TYPE_THUMB; - } - - return Integer.parseInt(thumb); - } - - public void makeThumb(boolean isThumb, File file, int size) throws IOException { - makeThumb(file, size, size, isThumb); - } - // 后台等比压缩后大小最好控制在20k以内 - public void makeThumb(File file, int w, int h, boolean keepAspectRatio) throws IOException { - String fileName = file.getName().toLowerCase(); - - BufferedImage image; - - if (fileName.endsWith(".ico")) { - List images = ICODecoder.read(file); - image = images.get(images.size() - 1); - } else { - image = ImageIO.read(file); - } - - imageWidth = image.getWidth(); - imageHeight = image.getHeight(); - - if (fileName.endsWith(".png") || fileName.endsWith(".gif")) { - // 把透明的图填充白色背景 - BufferedImage newBufferedImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); - newBufferedImage.createGraphics().drawImage(image, 0, 0, Color.WHITE, null); - image = newBufferedImage; - } - - Thumbnails.Builder builder = Thumbnails.of(image); - - if (keepAspectRatio) { - if (h > 0) { - // 高度为基准调整宽度到达原图缩放比例 - int imageR = imageWidth * 1000 / imageHeight; - w = h * imageR / 1000; - } else { - // 宽度为基准调整宽度到达原图缩放比例 - int imageR = imageHeight * 1000 / imageWidth; - h = w * imageR / 1000; - } + // 图片处理方式 + public static final int TYPE_DEFAULT = 1; + public static final int TYPE_THUMB = 2; + public static final int TYPE_AVATAR = 3; + + private int imageWidth; + private int imageHeight; + + public static int type(String thumb) { + // 解决历史遗留boolean类型 + if (StringUtils.isBlank(thumb) || "false".equalsIgnoreCase(thumb)) { + return TYPE_DEFAULT; + } + + if ("true".equalsIgnoreCase(thumb)) { + return TYPE_THUMB; + } + + return Integer.parseInt(thumb); + } + + public void makeThumb(boolean isThumb, File file, int size) throws IOException { + makeThumb(file, size, size, isThumb); + } + + // 后台等比压缩后大小最好控制在20k以内 + public void makeThumb(File file, int w, int h, boolean keepAspectRatio) throws IOException { + String fileName = file.getName().toLowerCase(); + + BufferedImage image; + + if (fileName.endsWith(".ico")) { + List images = ICODecoder.read(file); + image = images.get(images.size() - 1); + } else { + image = ImageIO.read(file); + } + + imageWidth = image.getWidth(); + imageHeight = image.getHeight(); + + if (fileName.endsWith(".png") || fileName.endsWith(".gif")) { + // 把透明的图填充白色背景 + BufferedImage newBufferedImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); + newBufferedImage.createGraphics().drawImage(image, 0, 0, Color.WHITE, null); + image = newBufferedImage; + } + + Thumbnails.Builder builder = Thumbnails.of(image); + + if (keepAspectRatio) { + if (h > 0) { + // 高度为基准调整宽度到达原图缩放比例 + int imageR = imageWidth * 1000 / imageHeight; + w = h * imageR / 1000; + } else { + // 宽度为基准调整宽度到达原图缩放比例 + int imageR = imageHeight * 1000 / imageWidth; + h = w * imageR / 1000; + } // int r = w * 1000 / h; // int imageR = imageWidth * 1000 / imageHeight; // if (r != imageR) { // w = imageHeight * r / 1000; // } - } else { - int r = w * 1000 / h; - int imageR = imageWidth * 1000 / imageHeight; - - if (r != imageR) { - int width = imageWidth; - int height = imageHeight; - if (r > imageR) { - width = imageHeight * r / 1000; - } else { - height = imageWidth * 1000 / r; - } - - builder.sourceRegion(Positions.CENTER, width, height); - } - } - - builder.size(w, h).antialiasing(Antialiasing.ON).outputFormat("jpg").outputQuality(0.9) - .toFile(file.getAbsolutePath() + FilePathGenerator.THUMB_FILE_EXT); - } + } else { + int r = w * 1000 / h; + int imageR = imageWidth * 1000 / imageHeight; + + if (r != imageR) { + int width = imageWidth; + int height = imageHeight; + if (r > imageR) { + width = imageHeight * r / 1000; + } else { + height = imageWidth * 1000 / r; + } + + builder.sourceRegion(Positions.CENTER, width, height); + } + } + + builder.size(w, h).antialiasing(Antialiasing.ON).outputFormat("jpg").outputQuality(0.9) + .toFile(file.getAbsolutePath() + FilePathGenerator.THUMB_FILE_EXT); + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/TreeDataUtil.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/TreeDataUtil.java index 7c1e490..f8b71a2 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/TreeDataUtil.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/TreeDataUtil.java @@ -6,212 +6,214 @@ import java.util.function.Consumer; /** * 树结构数据创建器 + * * @author xkliu */ public class TreeDataUtil { - private TreeDataUtil(){} - - public static boolean longEquals(Long l1, Long l2) { - if (l1 != null) { - return l1.equals(l2); + private TreeDataUtil() { } - return l2 == null; - } + public static boolean longEquals(Long l1, Long l2) { + if (l1 != null) { + return l1.equals(l2); + } - private static boolean findAndAdd(T parent, T item, ITreeDataHandler handler) { - if (longEquals(handler.getId(parent), handler.getParentId(item))) { - addChild(parent, item, handler); - return true; - } else { - List children = handler.getChildren(parent); + return l2 == null; + } - if (children != null) { - for (T child : children) { - if (findAndAdd(child, item, handler)) { + private static boolean findAndAdd(T parent, T item, ITreeDataHandler handler) { + if (longEquals(handler.getId(parent), handler.getParentId(item))) { + addChild(parent, item, handler); return true; - } + } else { + List children = handler.getChildren(parent); + + if (children != null) { + for (T child : children) { + if (findAndAdd(child, item, handler)) { + return true; + } + } + } } - } - } - - return false; - } - private static boolean findAndAddLevel(T parent, T item, ITreeDataLevelHandler handler) { - if (longEquals(handler.getId(parent), handler.getParentId(item))) { - addChildLevel(parent, item, handler); - return true; - } else { - List children = handler.getChildren(parent); + return false; + } - if (children != null) { - for (T child : children) { - if (findAndAddLevel(child, item, handler)) { + private static boolean findAndAddLevel(T parent, T item, ITreeDataLevelHandler handler) { + if (longEquals(handler.getId(parent), handler.getParentId(item))) { + addChildLevel(parent, item, handler); return true; - } + } else { + List children = handler.getChildren(parent); + + if (children != null) { + for (T child : children) { + if (findAndAddLevel(child, item, handler)) { + return true; + } + } + } } - } + + return false; } - return false; - } + private static void addChild(T parent, T item, ITreeDataHandler handler) { + List children = handler.getChildren(parent); + if (children == null) { + children = new ArrayList<>(); + handler.setChildren(parent, children); + } - private static void addChild(T parent, T item, ITreeDataHandler handler) { - List children = handler.getChildren(parent); - if (children == null) { - children = new ArrayList<>(); - handler.setChildren(parent, children); + children.add(item); } - children.add(item); - } + private static void addChildLevel(T parent, T item, ITreeDataLevelHandler handler) { + List children = handler.getChildren(parent); + if (children == null) { + children = new ArrayList<>(); + handler.setChildren(parent, children); + } - private static void addChildLevel(T parent, T item, ITreeDataLevelHandler handler) { - List children = handler.getChildren(parent); - if (children == null) { - children = new ArrayList<>(); - handler.setChildren(parent, children); + updateLevel(item, handler.getLevel(parent) + 1, handler); + children.add(item); } - updateLevel(item, handler.getLevel(parent) + 1, handler); - children.add(item); - } - - private static void updateLevel(T parent, int parentLevel, ITreeDataLevelHandler handler) { - handler.setLevel(parent, parentLevel); - List children = handler.getChildren(parent); - if (children != null) { - int level = parentLevel + 1; - for (T t: children) { - handler.setLevel(t, level); - updateLevel(t, level, handler); - } - } - } - - // 读取树结构 - public static List buildTree(T root, List list, ITreeDataHandler handler) { - if (list != null) { - for (T item: list) { - if (!findAndAdd(root, item, handler)) { - for (T it: list) { - if (longEquals(handler.getId(it), handler.getParentId(item))) { - addChild(it, item, handler); - item = null; - break; + private static void updateLevel(T parent, int parentLevel, ITreeDataLevelHandler handler) { + handler.setLevel(parent, parentLevel); + List children = handler.getChildren(parent); + if (children != null) { + int level = parentLevel + 1; + for (T t : children) { + handler.setLevel(t, level); + updateLevel(t, level, handler); } - } - - // not find item parent - if (item != null && handler.forceAdd(item)) { - addChild(root, item, handler); - } } - } } - return handler.getChildren(root); - } - - // 读取树结构 - public static List buildLevelTree(T root, List list, ITreeDataLevelHandler handler) { - if (list != null) { - handler.setLevel(root, 0); - for (T item: list) { - if (!findAndAddLevel(root, item, handler)) { - for (T it: list) { - if (longEquals(handler.getId(it), handler.getParentId(item))) { - addChildLevel(it, item, handler); - item = null; - break; + // 读取树结构 + public static List buildTree(T root, List list, ITreeDataHandler handler) { + if (list != null) { + for (T item : list) { + if (!findAndAdd(root, item, handler)) { + for (T it : list) { + if (longEquals(handler.getId(it), handler.getParentId(item))) { + addChild(it, item, handler); + item = null; + break; + } + } + + // not find item parent + if (item != null && handler.forceAdd(item)) { + addChild(root, item, handler); + } + } } - } - - // not find item parent - if (item != null && handler.forceAdd(item)) { - addChildLevel(root, item, handler); - } } - } + + return handler.getChildren(root); } - return handler.getChildren(root); - } + // 读取树结构 + public static List buildLevelTree(T root, List list, ITreeDataLevelHandler handler) { + if (list != null) { + handler.setLevel(root, 0); + for (T item : list) { + if (!findAndAddLevel(root, item, handler)) { + for (T it : list) { + if (longEquals(handler.getId(it), handler.getParentId(item))) { + addChildLevel(it, item, handler); + item = null; + break; + } + } + + // not find item parent + if (item != null && handler.forceAdd(item)) { + addChildLevel(root, item, handler); + } + } + } + } - public static T findParent(T root, Long id, int treeLevel, ITreeDataLevelHandler handler) { - T result = findParentInLevel(root, id, treeLevel, handler); - if (result != null && handler.getLevel(result) != treeLevel) { - result = null; + return handler.getChildren(root); } - return result; - } + public static T findParent(T root, Long id, int treeLevel, ITreeDataLevelHandler handler) { + T result = findParentInLevel(root, id, treeLevel, handler); + if (result != null && handler.getLevel(result) != treeLevel) { + result = null; + } - private static T findParentInLevel(T parent, Long id, int treeLevel, ITreeDataLevelHandler handler) { - List children = handler.getChildren(parent); - if (children != null) { - for (T child: children) { - if (id.equals(handler.getId(child))) { - return parent; - } else { - T find = findParentInLevel(child, id, treeLevel - 1, handler); - if (find != null) { - if (treeLevel > 0) { - return find; - } else { - return parent; + return result; + } + + private static T findParentInLevel(T parent, Long id, int treeLevel, ITreeDataLevelHandler handler) { + List children = handler.getChildren(parent); + if (children != null) { + for (T child : children) { + if (id.equals(handler.getId(child))) { + return parent; + } else { + T find = findParentInLevel(child, id, treeLevel - 1, handler); + if (find != null) { + if (treeLevel > 0) { + return find; + } else { + return parent; + } + } + } } - } } - } - } - return null; - } + return null; + } - public static T findParent(T root, Long id,ITreeDataHandler handler) { - List children = handler.getChildren(root); - if (children != null) { - for (T child: children) { - if (id.equals(handler.getId(child))) { - return root; - } else { - T find = findParent(child, id, handler); - if (find != null) { - return find; - } + public static T findParent(T root, Long id, ITreeDataHandler handler) { + List children = handler.getChildren(root); + if (children != null) { + for (T child : children) { + if (id.equals(handler.getId(child))) { + return root; + } else { + T find = findParent(child, id, handler); + if (find != null) { + return find; + } + } + } } - } - } - return null; - } + return null; + } - public static T find(T root, Long id, ITreeDataHandler handler) { - List children = handler.getChildren(root); - if (children != null) { - for (T child: children) { - if (id.equals(handler.getId(child))) { - return child; - } else { - T find = find(child, id, handler); - if (find != null) { - return find; - } + public static T find(T root, Long id, ITreeDataHandler handler) { + List children = handler.getChildren(root); + if (children != null) { + for (T child : children) { + if (id.equals(handler.getId(child))) { + return child; + } else { + T find = find(child, id, handler); + if (find != null) { + return find; + } + } + } } - } - } - return null; - } + return null; + } - public static void forEach(T node, ITreeDataHandler handler, Consumer action) { - List children = handler.getChildren(node); - if (children != null) { - for (T child: children) { - action.accept(child); - } + public static void forEach(T node, ITreeDataHandler handler, Consumer action) { + List children = handler.getChildren(node); + if (children != null) { + for (T child : children) { + action.accept(child); + } + } } - } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilFile.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilFile.java index e32ad98..0cc6bd9 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilFile.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/UtilFile.java @@ -149,7 +149,7 @@ public class UtilFile { write.flush(); write.close(); } catch (IOException e) { - UtilLogger.error(e.getMessage( ), e); + UtilLogger.error(e.getMessage(), e); } } @@ -341,8 +341,8 @@ public class UtilFile { /** * 查找所有的文件 * * - * @param sSearchStr 要搜索的字符串 - * return 文件名list + * @param sSearchStr 要搜索的字符串 + * return 文件名list */ public static List searchFiles(String sSearchStr, String sFilePath) { List list = new ArrayList<>(); @@ -1069,6 +1069,7 @@ public class UtilFile { /** * 读取txt文件类型 + * * @param fileName * @return */ @@ -1097,6 +1098,7 @@ public class UtilFile { } return sbf.toString(); } + /** * 解压文件到指定目录 * diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/XmlUtil.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/XmlUtil.java index 3235db6..df442dc 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/XmlUtil.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/XmlUtil.java @@ -13,76 +13,77 @@ import java.io.InputStream; import java.io.OutputStream; public class XmlUtil { - private static final XmlMapper OBJECT_MAPPER = new XmlMapper(); + private static final XmlMapper OBJECT_MAPPER = new XmlMapper(); - static { - OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); - OBJECT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT); - } + static { + OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + OBJECT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT); + } - private XmlUtil() {} + private XmlUtil() { + } - public static T readValue(String str, Class clazz) { - try { - if (StringUtils.isBlank(str)) { - return null; - } else { - return OBJECT_MAPPER.readValue(str, clazz); - } - } catch (Exception e) { - throw new JsonParseException("can't convert this json to " + clazz + " type", e); + public static T readValue(String str, Class clazz) { + try { + if (StringUtils.isBlank(str)) { + return null; + } else { + return OBJECT_MAPPER.readValue(str, clazz); + } + } catch (Exception e) { + throw new JsonParseException("can't convert this json to " + clazz + " type", e); + } } - } - public static T readValue(File file, Class clazz) { - try { - if (file == null || !file.exists()) { - return null; - } else { - return OBJECT_MAPPER.readValue(file, clazz); - } - } catch (Exception e) { - throw new JsonParseException("can't convert this json to " + clazz + " type", e); + public static T readValue(File file, Class clazz) { + try { + if (file == null || !file.exists()) { + return null; + } else { + return OBJECT_MAPPER.readValue(file, clazz); + } + } catch (Exception e) { + throw new JsonParseException("can't convert this json to " + clazz + " type", e); + } } - } - public static T readValue(InputStream is, Class clazz) { - try { - if (is == null) { - return null; - } else { - return OBJECT_MAPPER.readValue(is, clazz); - } - } catch (Exception e) { - throw new JsonParseException("can't convert this xml to " + clazz + " type", e); + public static T readValue(InputStream is, Class clazz) { + try { + if (is == null) { + return null; + } else { + return OBJECT_MAPPER.readValue(is, clazz); + } + } catch (Exception e) { + throw new JsonParseException("can't convert this xml to " + clazz + " type", e); + } } - } - public static String writeValue(Object obj) { - try { - return OBJECT_MAPPER.writeValueAsString(obj); - } catch (JsonProcessingException e) { - throw new JsonParseException("can't convert type " + obj.getClass() + " to json string", e); + public static String writeValue(Object obj) { + try { + return OBJECT_MAPPER.writeValueAsString(obj); + } catch (JsonProcessingException e) { + throw new JsonParseException("can't convert type " + obj.getClass() + " to json string", e); + } } - } - public static void writeValue(OutputStream outputStream, Object obj) { - try { - OBJECT_MAPPER.writeValue(outputStream, obj); - } catch (JsonProcessingException e) { - throw new JsonParseException("can't convert type " + obj.getClass() + " to json string", e); - } catch (IOException e) { - throw new JsonParseException(e.getMessage(), e); + public static void writeValue(OutputStream outputStream, Object obj) { + try { + OBJECT_MAPPER.writeValue(outputStream, obj); + } catch (JsonProcessingException e) { + throw new JsonParseException("can't convert type " + obj.getClass() + " to json string", e); + } catch (IOException e) { + throw new JsonParseException(e.getMessage(), e); + } } - } - public static void writeValue(File file, Object obj) { - try { - OBJECT_MAPPER.writeValue(file, obj); - } catch (JsonProcessingException e) { - throw new JsonParseException("can't convert type " + obj.getClass() + " to json string", e); - } catch (IOException e) { - throw new JsonParseException(e.getMessage(), e); + public static void writeValue(File file, Object obj) { + try { + OBJECT_MAPPER.writeValue(file, obj); + } catch (JsonProcessingException e) { + throw new JsonParseException("can't convert type " + obj.getClass() + " to json string", e); + } catch (IOException e) { + throw new JsonParseException(e.getMessage(), e); + } } - } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/YamlUtil.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/YamlUtil.java index 24ebd47..1ec1de2 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/YamlUtil.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/YamlUtil.java @@ -16,97 +16,97 @@ import java.io.*; import java.nio.charset.StandardCharsets; public class YamlUtil { - private static final ObjectMapper OBJECT_MAPPER; - private static final Representer representer; + private static final ObjectMapper OBJECT_MAPPER; + private static final Representer representer; - static { - YAMLFactory yamlFactory = new YAMLFactory(); + static { + YAMLFactory yamlFactory = new YAMLFactory(); // yamlFactory.enable(YAMLGenerator.Feature.CANONICAL_OUTPUT); - yamlFactory.disable(YAMLGenerator.Feature.SPLIT_LINES); - yamlFactory.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES); - - OBJECT_MAPPER = new ObjectMapper(yamlFactory); - OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); - - // 生成yaml时忽略null属性 - representer = new Representer() { - @Override - protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) { - // if value of property is null, ignore it. - if (propertyValue == null) { - return null; + yamlFactory.disable(YAMLGenerator.Feature.SPLIT_LINES); + yamlFactory.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES); + + OBJECT_MAPPER = new ObjectMapper(yamlFactory); + OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + // 生成yaml时忽略null属性 + representer = new Representer() { + @Override + protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) { + // if value of property is null, ignore it. + if (propertyValue == null) { + return null; + } else { + return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); + } + } + }; + } + + private YamlUtil() { + } + + public static T readValue(String str, Class clazz) { + try { + if (StringUtils.isBlank(str)) { + return null; + } else { + return OBJECT_MAPPER.readValue(str, clazz); + } + } catch (Exception e) { + throw new JsonParseException("can't convert this json to " + clazz + " type", e); } - else { - return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); + } + + public static T readValue(File file, Class clazz) { + try { + return OBJECT_MAPPER.readValue(file, clazz); + } catch (Exception e) { + throw new JsonParseException("can't convert this json to " + clazz + " type", e); } - } - }; - } - - private YamlUtil() {} - - public static T readValue(String str, Class clazz) { - try { - if (StringUtils.isBlank(str)) { - return null; - } else { - return OBJECT_MAPPER.readValue(str, clazz); - } - } catch (Exception e) { - throw new JsonParseException("can't convert this json to " + clazz + " type", e); } - } - public static T readValue(File file, Class clazz) { - try { - return OBJECT_MAPPER.readValue(file, clazz); - } catch (Exception e) { - throw new JsonParseException("can't convert this json to " + clazz + " type", e); + public static T readValue(InputStream is, Class clazz) { + try { + if (is == null) { + return null; + } else { + return OBJECT_MAPPER.readValue(is, clazz); + } + } catch (Exception e) { + throw new JsonParseException("can't convert this yaml to " + clazz + " type", e); + } } - } - - public static T readValue(InputStream is, Class clazz) { - try { - if (is == null) { - return null; - } else { - return OBJECT_MAPPER.readValue(is, clazz); - } - } catch (Exception e) { - throw new JsonParseException("can't convert this yaml to " + clazz + " type", e); + + public static String writeValue(Object obj) { + Yaml yaml = buildYaml(); + StringWriter sw = new StringWriter(); + yaml.dump(obj, sw); + return sw.toString(); } - } - - public static String writeValue(Object obj) { - Yaml yaml = buildYaml(); - StringWriter sw = new StringWriter(); - yaml.dump(obj, sw); - return sw.toString(); - } - - private static Yaml buildYaml() { - Yaml result = new Yaml(representer); - - return result; - } - - public static void writeValue(OutputStream outputStream, Object obj) { - Yaml yaml = buildYaml(); - yaml.dump(obj, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)); - } - - public static void writeValue(File file, Object obj) { - Yaml yaml = buildYaml(); - try(OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { - yaml.dump(obj, out); -// OBJECT_MAPPER.writeValue(file, obj); - } catch (IOException e) { - throw new JsonParseException(e.getMessage(), e); + + private static Yaml buildYaml() { + Yaml result = new Yaml(representer); + + return result; + } + + public static void writeValue(OutputStream outputStream, Object obj) { + Yaml yaml = buildYaml(); + yaml.dump(obj, new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)); } + public static void writeValue(File file, Object obj) { + Yaml yaml = buildYaml(); + try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { + yaml.dump(obj, out); +// OBJECT_MAPPER.writeValue(file, obj); + } catch (IOException e) { + throw new JsonParseException(e.getMessage(), e); + } + // StringWriter sw = new StringWriter(); // System.out.println(sw.toString()); - } + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/FtpTaskManager.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/FtpTaskManager.java index e4666b9..25743a1 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/FtpTaskManager.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/FtpTaskManager.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.util.ftp; - import cc.smtweb.framework.core.util.DateUtil; import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.util.UtilLogger; @@ -24,7 +23,7 @@ public class FtpTaskManager { private Map mapThreadFtp = new HashMap<>(); public static FtpTaskManager getInstance(String key, IFtpServerConfig ftpConfig) { - key = key + "_" + (ftpConfig.isSFTP() ? 1 : 0) + ftpConfig.getServerIp() + "_" + ftpConfig.getPort() + "_" + ftpConfig.getUserName(); + key = key + "_" + (ftpConfig.isSFTP() ? 1: 0) + ftpConfig.getServerIp() + "_" + ftpConfig.getPort() + "_" + ftpConfig.getUserName(); FtpTaskManager instance = mapInstance.get(key); if (instance == null) { synchronized (FtpTaskManager.class) { @@ -55,7 +54,7 @@ public class FtpTaskManager { IFtpUtil ftp = mapThreadFtp.get(Thread.currentThread()); if (ftp != null) return ftp; - ftp = ftpConfig.isSFTP() ? new SFtpUtil() : new FtpUtil(); + ftp = ftpConfig.isSFTP() ? new SFtpUtil(): new FtpUtil(); boolean isConnect = ftp.login(ftpConfig); if (isConnect) { UtilLogger.info("FTP连接成功!"); @@ -87,7 +86,7 @@ public class FtpTaskManager { public Object execute(FtpTask ftpTask) throws Exception { IFtpUtil ftp = getFtpUtil(); if (!ftp.isConnected()) - throw new Exception("FTP连接失败(" + ftpConfig.getServerIp() + "/" + ftpConfig.getUserName() + "/" + (ftpConfig.isSFTP() ? "sftp" : "ftp") + ")。"); + throw new Exception("FTP连接失败(" + ftpConfig.getServerIp() + "/" + ftpConfig.getUserName() + "/" + (ftpConfig.isSFTP() ? "sftp": "ftp") + ")。"); try { return ftpTask.execute(ftp); } finally { @@ -118,7 +117,7 @@ public class FtpTaskManager { } private String getBakPath(String path) { - path = StringUtil.isEmpty(path) ? DateUtil.getNowYm() : path; + path = StringUtil.isEmpty(path) ? DateUtil.getNowYm(): path; return "bak/" + path + "/"; } @@ -161,15 +160,17 @@ public class FtpTaskManager { } }); } + public void delFile(String delPath, String fileName) throws Exception { this.execute(new FtpTask() { public Object execute(IFtpUtil ftp) throws Exception { if (!ftp.existsFile(delPath, fileName)) return null; - ftp.deleteFile(delPath,fileName ); + ftp.deleteFile(delPath, fileName); return null; } }); } + //从服务器下载文件到本地。传完后,根据设置删除远程目录文件 public String[] listFileNames(final String remotePath) throws Exception { IFtpUtil ftp = getFtpUtil(); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/IFtpServerConfig.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/IFtpServerConfig.java index 28a2ec8..2bd138a 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/IFtpServerConfig.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/IFtpServerConfig.java @@ -6,6 +6,7 @@ package cc.smtweb.system.bpm.util.ftp; */ public interface IFtpServerConfig { boolean isSFTP(); + String getServerIp(); Integer getPort(); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/IFtpUtil.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/IFtpUtil.java index cfd4459..dcb70b1 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/IFtpUtil.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/util/ftp/IFtpUtil.java @@ -9,10 +9,13 @@ import java.io.InputStream; public interface IFtpUtil { //是否自动删除 boolean isAutoFree(); + //设置自动删除 void setAutoFree(boolean autoFree); + //登录ftp boolean login(IFtpServerConfig ftpConf); + //退出ftp void logout(); @@ -21,6 +24,7 @@ public interface IFtpUtil { //设置远程目录 boolean setRemoteDir(String path); + void mkdir(String dirName); //删除远程路径 @@ -37,6 +41,7 @@ public interface IFtpUtil { boolean uploadFile(String path, String filename, File localFile) throws Exception; void deleteFile(String path, String filename); + //判断文件是否存在 boolean existsFile(String path, String filename); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/BpmStartedListener.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/BpmStartedListener.java index 224dd92..60c8c9b 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/BpmStartedListener.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/BpmStartedListener.java @@ -1,22 +1,13 @@ package cc.smtweb.system.bpm.web; -import cc.smtweb.framework.core.annotation.SwService; import cc.smtweb.framework.core.annotation.SwStartListener; import cc.smtweb.framework.core.cache.CacheManager; import cc.smtweb.framework.core.common.SwConsts; -import cc.smtweb.framework.core.db.cache.ModelTableCache; import cc.smtweb.framework.core.db.impl.DatabaseUtil; import cc.smtweb.framework.core.db.vo.ModelCatalog; import cc.smtweb.framework.core.mvc.controller.IStartListener; import cc.smtweb.framework.core.mvc.service.TreeHelper; -import cc.smtweb.framework.core.systask.TaskStartEvent; -import cc.smtweb.framework.core.systask.WebStartedEvent; import cc.smtweb.system.bpm.web.design.db.ModelCatalogTreeHelper; -import org.springframework.boot.context.event.ApplicationStartedEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.EventListener; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; /** * Created by Akmm at 2022/7/8 19:57 @@ -38,7 +29,7 @@ public class BpmStartedListener implements IStartListener { new DatabaseUtil(true, false).checkDb(); //初始化缓存 CacheManager.getIntance().init(); - + TreeHelper.regTreeHelper(ModelCatalog.ENTITY_NAME, ModelCatalogTreeHelper.class); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogCache.java index 4d4e880..5c7f372 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogCache.java @@ -40,7 +40,7 @@ public class ModelCatalogCache extends AbstractCache { public String getName(long id) { ModelCatalog bean = get(id); - return bean != null ? bean.getName() : ""; + return bean != null ? bean.getName(): ""; } public String getFullName(long id) { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java index a045192..a499a79 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHandler.java @@ -64,7 +64,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler @Override protected List filterData() { - Set setId =exc_depend ? new HashSet<>(Arrays.asList(prj_id)) : ModelProjectCache.getInstance().getDependsPrjIds(prj_id); + Set setId = exc_depend ? new HashSet<>(Arrays.asList(prj_id)): ModelProjectCache.getInstance().getDependsPrjIds(prj_id); if (setId.isEmpty()) return new ArrayList<>(); String sqlPrjId = CommUtil.getSqlInIds(setId); @@ -106,7 +106,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler @Override protected List getChildren(long id) { - List list = mcTreeHelper.getChildren(id, prj_id,exc_depend, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); + List list = mcTreeHelper.getChildren(id, prj_id, exc_depend, (o1, o2) -> StringUtil.chineseCompare(o1.getName(), o2.getName())); List listRet; if (type != TYPE_CATALOG && exc_empty) {//排除空目录 listRet = cleanEmpty(list); @@ -160,7 +160,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler addPageChildren(listRet, mc.getId(), type); } if (!listRet.isEmpty()) return true; - List list = mcTreeHelper.getChildren(mc.getId(), prj_id,exc_depend,null); + List list = mcTreeHelper.getChildren(mc.getId(), prj_id, exc_depend, null); if (list == null || list.isEmpty()) return false; for (ModelCatalog c : list) { if (hasChildren(c)) return true; @@ -259,7 +259,7 @@ public class ModelCatalogTreeHandler extends AbstractTreeHandler final ModelForm form = (ModelForm) bean; node.put("type", form.getType() + 2); // 返回页面名称 - bean.put("pageName",ModelProjectCache.getInstance().getModule(((ModelForm) bean).getPrjId())+"."+((ModelForm) bean).getName()); + bean.put("pageName", ModelProjectCache.getInstance().getModule(((ModelForm) bean).getPrjId()) + "." + ((ModelForm) bean).getName()); //是模块,需要加子页面 if (form.getType() == SwEnum.FormType.MODULE.value) { List lf = mapFormChild.get(form.getEntityId()); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHelper.java index 12e6c14..1f4fd3e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelCatalogTreeHelper.java @@ -17,15 +17,15 @@ public class ModelCatalogTreeHelper extends TreeHelper { super(ModelCatalog.ENTITY_NAME); } - public List getChildren(long id, long prj_id,boolean exc_depend, Comparator comparator) { + public List getChildren(long id, long prj_id, boolean exc_depend, Comparator comparator) { if (id > 0L) { return getChildren(id, comparator); } - Set setId = exc_depend ? new HashSet<>(Arrays.asList(prj_id)) : ModelProjectCache.getInstance().getDependsPrjIds(prj_id); + Set setId = exc_depend ? new HashSet<>(Arrays.asList(prj_id)): ModelProjectCache.getInstance().getDependsPrjIds(prj_id); if (setId.isEmpty()) return new ArrayList<>(); Set set = new HashSet<>(); - for (long prjId: setId) { + for (long prjId : setId) { Collection st = cache.getListByKey(CACHE_KEY, prjId + SwConsts.SPLIT_CHAR + SwConsts.DEF_ROOT_ID); if (st != null) set.addAll(st); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelProjectCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelProjectCache.java index cece0c4..088c29e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelProjectCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/db/ModelProjectCache.java @@ -19,12 +19,13 @@ import java.util.Set; @SwCache(ident = "ASP_MODEL_PROJECT", title = "项目定义") public class ModelProjectCache extends AbstractCache { private final static String mm = "m"; + public static ModelProjectCache getInstance() { return CacheManager.getIntance().getCache(ModelProjectCache.class); } public ModelProjectCache() { - regMap(mm, k-> String.valueOf(k.getModule())); + regMap(mm, k -> String.valueOf(k.getModule())); } @Override @@ -40,14 +41,16 @@ public class ModelProjectCache extends AbstractCache { public String getModule(long id) { ModelProject bean = get(id); - return bean != null ? bean.getModule() : ""; + return bean != null ? bean.getModule(): ""; } - public ModelProject getByModule(String module){ - return getByKey(mm,module); + + public ModelProject getByModule(String module) { + return getByKey(mm, module); } + public String getIdByModule(String module) { ModelProject bean = getByModule(module); - return bean !=null ? String.valueOf(bean.getId()): ""; + return bean != null ? String.valueOf(bean.getId()): ""; } //找当前项目及其依赖项目的id集合,递归 @@ -65,7 +68,7 @@ public class ModelProjectCache extends AbstractCache { set.add(id); if (StringUtils.isEmpty(bean.getDepends())) return; String[] dps = bean.getDepends().split(","); - for (String s: dps) { + for (String s : dps) { s = s.trim(); if (StringUtils.isEmpty(s)) return; addPrjId(set, NumberUtil.getLongIgnoreErr(s)); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/FlowConst.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/FlowConst.java index 3446847..b05af85 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/FlowConst.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/FlowConst.java @@ -44,6 +44,7 @@ public interface FlowConst { public static StrEnumBean LOG = instance.addEnum("log", "流程历史"); } + /** * 活动类型 1-开始任务 2-用户任务 3-条件分支 4-并行开始 5-并行结束 6-脚本任务 9-结束任务 */ diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProc.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProc.java index 691451c..aae810e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProc.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProc.java @@ -24,7 +24,7 @@ public class ModelProc extends DefaultEntity { public void clear() { procInfo = null; } - + public ProcInfo getProcInfo() { if (procInfo == null) { synchronized ("ModelProc_" + getId()) { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcCache.java index 1d33e7f..587b22a 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcCache.java @@ -25,9 +25,9 @@ public class ModelProcCache extends AbstractCache { } public ModelProcCache() { - regMap(mk, k-> k.getName().toUpperCase()); - regList(mp, k-> String.valueOf(k.getPrjId())); - regList(mc, k-> String.valueOf(k.getMcId())); + regMap(mk, k -> k.getName().toUpperCase()); + regList(mp, k -> String.valueOf(k.getPrjId())); + regList(mc, k -> String.valueOf(k.getMcId())); } @Override diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcHelper.java index 38d682c..01445d7 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcHelper.java @@ -22,11 +22,13 @@ public class ModelProcHelper { public static ModelProc getFromCache(long proc_id) { return ModelProcCache.getInstance().get(proc_id); } + public static ProcInfo getProcFromCache(long proc_id) { ModelProc proc = getFromCache(proc_id); if (proc == null) return null; return proc.getProcInfo(); } + /** * 获取配置的工作流程定义 * @@ -36,7 +38,7 @@ public class ModelProcHelper { */ public static ModelProc getBillProc(long bill_type, long user_id) { Set list = BillFlowCache.getInstance().getByBillType(bill_type); - + if (CommUtil.isEmpty(list)) { return null; } @@ -101,7 +103,7 @@ public class ModelProcHelper { return act; } } - + return null; } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcLoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcLoadHandler.java index eefe9c6..fb65b94 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcLoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcLoadHandler.java @@ -1,8 +1,6 @@ package cc.smtweb.system.bpm.web.design.flow; import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.db.DbEngine; -import cc.smtweb.framework.core.db.EntityDao; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.DefaultLoadHandler; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcService.java index d671148..be6679a 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/ModelProcService.java @@ -3,7 +3,6 @@ package cc.smtweb.system.bpm.web.design.flow; import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.common.SwConsts; import cc.smtweb.framework.core.common.SwEnum; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.cache.ModelTableCache; @@ -14,15 +13,12 @@ import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.framework.core.mvc.service.DefaultDelHandler; import cc.smtweb.framework.core.mvc.service.DefaultListHandler; import cc.smtweb.framework.core.session.UserSession; -import cc.smtweb.system.bpm.web.design.form.ModelForm; -import cc.smtweb.system.bpm.web.design.form.ModelFormCache; import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; import cc.smtweb.system.bpm.web.engine.flow.entity.Comment; import cc.smtweb.system.bpm.web.engine.flow.entity.ProcInst; import java.util.ArrayList; import java.util.List; -import java.util.Set; /** * Created by Akmm at 2022/3/22 9:12 @@ -47,12 +43,12 @@ public class ModelProcService extends AbstractCompService { //保存页面模型 public R saveModel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_SAVE, handler -> ((ModelProcSaveHandler)handler).saveModel()); + return pageHandler(params, us, TYPE_SAVE, handler -> ((ModelProcSaveHandler) handler).saveModel()); } //加载页面模型 public R loadModel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LOAD, handler -> ((ModelProcLoadHandler)handler).loadModel()); + return pageHandler(params, us, TYPE_LOAD, handler -> ((ModelProcLoadHandler) handler).loadModel()); } //加载工作流的列表字段 @@ -66,7 +62,7 @@ public class ModelProcService extends AbstractCompService { ModelFormHelper.buildFieldInfo(table, field, col); ret.add(col); } - + return R.success(ret); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/define/ProcInfo.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/define/ProcInfo.java index 1a2c153..524441d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/define/ProcInfo.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/define/ProcInfo.java @@ -26,7 +26,7 @@ public class ProcInfo { public Activity findActivity(String id) { if (StringUtils.isEmpty(id)) return null; - for (Activity act: activities) { + for (Activity act : activities) { if (id.equalsIgnoreCase(act.getId())) { return act; } @@ -37,13 +37,13 @@ public class ProcInfo { //获取任务名称 public String getActNameById(String id) { Activity act = findActivity(id); - return act != null ? act.getLabel() : ""; + return act != null ? act.getLabel(): ""; } //获取结束节点 public List findEndActivity() { List list = new ArrayList<>(); - for (Activity act: activities) { + for (Activity act : activities) { if (act.getType() == FlowConst.ActivityType.END.value) { list.add(act); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/define/Sign.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/define/Sign.java index 1e46dc1..17bdf1d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/define/Sign.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/flow/define/Sign.java @@ -14,5 +14,5 @@ public class Sign extends Handler { private int minAgree; //最少会签同意人数单位:0-人数 1-会签同意占比 private int minAgreeUnit; - + } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/CodeBuildHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/CodeBuildHandler.java index 046e1c6..609ae07 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/CodeBuildHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/CodeBuildHandler.java @@ -1,6 +1,8 @@ package cc.smtweb.system.bpm.web.design.form; -import cc.smtweb.framework.core.common.*; +import cc.smtweb.framework.core.common.R; +import cc.smtweb.framework.core.common.SwEnum; +import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.cache.ModelTableCache; import cc.smtweb.framework.core.db.vo.ModelCache; import cc.smtweb.framework.core.db.vo.ModelField; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java index 2794a63..6777a7b 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelForm.java @@ -231,6 +231,6 @@ public class ModelForm extends DefaultEntity { //返回单据类型id public long getBillType() { SwMap opts = getOpts(); - return opts != null ? opts.readLong(ModelFormHelper.KEY_BILL_TYPE) : 0L; + return opts != null ? opts.readLong(ModelFormHelper.KEY_BILL_TYPE): 0L; } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormDelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormDelHandler.java index da6c038..975fb75 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormDelHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormDelHandler.java @@ -16,6 +16,7 @@ import java.util.Set; public class ModelFormDelHandler extends DefaultDelHandler { //被删除的id private Set listDeled = new HashSet<>(); + public ModelFormDelHandler() { super(ModelForm.ENTITY_NAME); } @@ -29,7 +30,7 @@ public class ModelFormDelHandler extends DefaultDelHandler { protected void delDb() { EntityDao dao = DbEngine.getInstance().findDao(ModelForm.class); Set l1 = ModelFormCache.getInstance().getListByModule(id); - Set list = l1 != null ? new HashSet<>(l1) : null; + Set list = l1 != null ? new HashSet<>(l1): null; if (CommUtil.isEmpty(list)) { listDeled = null; dao.deleteEntity(id); @@ -37,7 +38,7 @@ public class ModelFormDelHandler extends DefaultDelHandler { listDeled = new HashSet<>(list); List ids = new ArrayList<>(); ids.add(id); - for (ModelForm form: list) { + for (ModelForm form : list) { ids.add(form.getId()); } dao.deleteEntity(ids); @@ -48,7 +49,7 @@ public class ModelFormDelHandler extends DefaultDelHandler { protected void saveSuccess() { ModelFormCache cache = ModelFormCache.getInstance(); if (!CommUtil.isEmpty(listDeled)) { - for (ModelForm form: listDeled) { + for (ModelForm form : listDeled) { cache.remove(form.getId()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java index c7d0d1e..85c7cc2 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormHelper.java @@ -1,6 +1,5 @@ package cc.smtweb.system.bpm.web.design.form; -import cc.smtweb.framework.core.common.AbstractEnum; import cc.smtweb.framework.core.common.SwEnum; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.cache.ModelTableCache; @@ -9,7 +8,10 @@ import cc.smtweb.framework.core.db.vo.ModelTable; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.variable.SwVariableFactory; import cc.smtweb.framework.core.session.UserSession; -import cc.smtweb.framework.core.util.*; +import cc.smtweb.framework.core.util.JsonUtil; +import cc.smtweb.framework.core.util.MapUtil; +import cc.smtweb.framework.core.util.SpringUtil; +import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.spring.BpmConfigBean; import cc.smtweb.system.bpm.util.CodeGenerator; import cc.smtweb.system.bpm.util.IdeaUtil; @@ -493,7 +495,7 @@ public class ModelFormHelper { field.put("field", pdf.field); field.put("name", pdf.name); String label = (String) field.get("field_label"); - field.put("label", StringUtils.isEmpty(label)? pdf.label: label); + field.put("label", StringUtils.isEmpty(label) ? pdf.label: label); field.put("required", pdf.isFieldNotNull()); final SwEnum.DataTypeBean dtb = SwEnum.DataType.instance.getByValue(pdf.dataType); if (dtb != null) { @@ -501,10 +503,10 @@ public class ModelFormHelper { } else { field.put("maxlength", 0); } - Map lookup = (Map)field.get("lookup"); - if (lookup!=null){ - long widgetId = MapUtil.readLong(lookup, "widgetId",-1L); - if(widgetId>0){ + Map lookup = (Map) field.get("lookup"); + if (lookup != null) { + long widgetId = MapUtil.readLong(lookup, "widgetId", -1L); + if (widgetId > 0) { setWidget.add(widgetId); } } @@ -513,6 +515,7 @@ public class ModelFormHelper { /** * 页面设计时,返回的字段信息,带控件 + * * @param table * @param field * @param col diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormLoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormLoadHandler.java index e47862a..eaadc46 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormLoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/ModelFormLoadHandler.java @@ -2,23 +2,16 @@ package cc.smtweb.system.bpm.web.design.form; import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwConsts; -import cc.smtweb.framework.core.exception.BizException; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.common.SwMap; +import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.DefaultLoadHandler; import cc.smtweb.framework.core.util.FileUtil; import cc.smtweb.framework.core.util.JsonUtil; -import cc.smtweb.framework.core.util.SpringUtil; -import cc.smtweb.system.bpm.spring.BpmConfigBean; -import cc.smtweb.system.bpm.util.IdeaUtil; -import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; import cc.smtweb.system.bpm.web.sys.base.billType.BillTypeCache; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; /** * Created by Akmm at 2022/5/9 16:17 @@ -76,7 +69,7 @@ public class ModelFormLoadHandler extends DefaultLoadHandler { //加载页面js方法 public R loadJsFuncs() { ModelForm form = localLoadForm(); - + List listRet = new ArrayList<>(); R r = R.success(listRet); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/BaseDatasetField.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/BaseDatasetField.java index 1ea9e19..5127ae6 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/BaseDatasetField.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/BaseDatasetField.java @@ -42,6 +42,7 @@ public class BaseDatasetField { public String defValue; // type为depend时, 表达式 public String dependExpr; + @JsonIgnore public boolean isFieldNotNull() { return notNull == 1; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/PageDatasets.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/PageDatasets.java index def7f1d..ba64000 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/PageDatasets.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/define/PageDatasets.java @@ -3,7 +3,10 @@ package cc.smtweb.system.bpm.web.design.form.define; import cc.smtweb.framework.core.db.cache.ModelTableCache; import com.fasterxml.jackson.annotation.JsonIgnore; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Created by Akmm at 2022/5/25 15:53 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/BaseModelWorker.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/BaseModelWorker.java index 0803ae5..ffdfb44 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/BaseModelWorker.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/BaseModelWorker.java @@ -5,16 +5,13 @@ import cc.smtweb.framework.core.common.SwEnum; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.exception.SwException; -import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.JsonUtil; import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.design.form.ModelForm; -import cc.smtweb.system.bpm.web.design.form.ModelFormCache; import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; import org.apache.commons.lang3.StringUtils; import java.util.List; -import java.util.Set; /** * Created by Akmm at 2022-08-14 10:37 @@ -23,6 +20,7 @@ import java.util.Set; public class BaseModelWorker { /** * 模块/页面保存:opts根据模型做些个性化处理,如果是模块,需要添加子页面 + * * @param bean * @param listFormChild */ @@ -74,6 +72,7 @@ public class BaseModelWorker { /** * 根据模型生成页面 + * * @param bean */ public void buildSaveModel(ModelForm bean) { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcLtMsWorker.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcLtMsWorker.java index b38c926..a4afb4d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcLtMsWorker.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcLtMsWorker.java @@ -14,10 +14,10 @@ public class LcLtMsWorker extends LcMsWorker { @Override protected String getTmplId(ModelForm bean) { - if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.LIST.value))){ + if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.LIST.value))) { return templateList; } - if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.CARD.value))){ + if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.CARD.value))) { return templateCard; } return super.getTmplId(bean); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcLtWorker.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcLtWorker.java index e45bc96..88078bb 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcLtWorker.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcLtWorker.java @@ -14,10 +14,10 @@ public class LcLtWorker extends LcNormalWorker { @Override protected String getTmplId(ModelForm bean) { - if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.LIST.value))){ + if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.LIST.value))) { return templateList; } - if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.CARD.value))){ + if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.CARD.value))) { return templateCard; } return super.getTmplId(bean); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcMsWorker.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcMsWorker.java index 28d736d..8130a51 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcMsWorker.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcMsWorker.java @@ -8,16 +8,16 @@ import cc.smtweb.system.bpm.web.design.form.ModelForm; * @Author:lip * @Date : 2022/8/28 12:11 */ -public class LcMsWorker extends LcNormalWorker{ +public class LcMsWorker extends LcNormalWorker { private final static String templateList = "model_list_normal"; private final static String templateCard = "model_card_ms"; @Override protected String getTmplId(ModelForm bean) { - if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.LIST.value))){ + if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.LIST.value))) { return templateList; } - if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.CARD.value))){ + if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.CARD.value))) { return templateCard; } return super.getTmplId(bean); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcNormalWorker.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcNormalWorker.java index 59b9cc1..9842b9f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcNormalWorker.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/LcNormalWorker.java @@ -59,10 +59,10 @@ public class LcNormalWorker extends BaseModelWorker { @Override protected String getTmplId(ModelForm bean) { - if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.LIST.value))){ + if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.LIST.value))) { return templateList; } - if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.CARD.value))){ + if (bean.getName().endsWith(StringUtil.upFirst(SwEnum.PageType.CARD.value))) { return templateCard; } return super.getTmplId(bean); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/ModelFactory.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/ModelFactory.java index 849a160..f137609 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/ModelFactory.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/ModelFactory.java @@ -8,7 +8,9 @@ import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; import cc.smtweb.system.bpm.web.design.form.model.flow.FlowSingleWorker; import org.apache.commons.lang3.StringUtils; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Created by Akmm at 2022-08-14 10:02 @@ -17,6 +19,7 @@ import java.util.*; public class ModelFactory { private static ModelFactory instance; private static Map mapWorker; + static { instance = new ModelFactory(); mapWorker = new HashMap<>(); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/flow/FlowSingleWorker.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/flow/FlowSingleWorker.java index 990b331..b7eb073 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/flow/FlowSingleWorker.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/form/model/flow/FlowSingleWorker.java @@ -22,6 +22,7 @@ import java.util.List; public class FlowSingleWorker extends BaseModelWorker { private final static String listTmpl = "model_list_flow"; private final static String cardTmpl = "model_card_flow"; + @Override protected void saveModule(ModelForm bean, List listFormChild) { EntityDao dao = DbEngine.getInstance().findDao(ModelForm.class); @@ -58,14 +59,14 @@ public class FlowSingleWorker extends BaseModelWorker { @Override public void buildSaveModel(ModelForm bean) { ModelForm parent = ModelFormCache.getInstance().get(bean.getParent()); - if(parent==null){ + if (parent == null) { return; } - String listFormName = parent.getName()+ StringUtil.upFirst(SwEnum.PageType.LIST.value); - String cardFormName = parent.getName()+ StringUtil.upFirst(SwEnum.PageType.CARD.value); - if(listFormName.equals(bean.getName())){ + String listFormName = parent.getName() + StringUtil.upFirst(SwEnum.PageType.LIST.value); + String cardFormName = parent.getName() + StringUtil.upFirst(SwEnum.PageType.CARD.value); + if (listFormName.equals(bean.getName())) { ModelFormHelper.buildSaveModelByTmpl(bean, listTmpl); - }else if(cardFormName.equals(bean.getName())){ + } else if (cardFormName.equals(bean.getName())) { ModelFormHelper.buildSaveModelByTmpl(bean, cardTmpl); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/MenuVO.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/MenuVO.java index 09a506d..f1d2e24 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/MenuVO.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/MenuVO.java @@ -7,46 +7,46 @@ import java.util.List; @Data public class MenuVO { - private Long id; - private Long parentId; - private int level; - private String name; - private String path; - private String icon; - private List children; - - // 树结构数据句柄 - public static ITreeDataLevelHandler createTreeHandler() { - return new ITreeDataLevelHandler () { - @Override - public Long getId (MenuVO node){ - return node.getId(); - } - - @Override - public Long getParentId (MenuVO node){ - return node.getParentId(); - } - - @Override - public List getChildren (MenuVO node){ - return node.children; - } - - @Override - public void setChildren (MenuVO node, List children){ - node.children = children; - } - - @Override - public int getLevel (MenuVO node){ - return node.level; - } - - @Override - public void setLevel (MenuVO node, int level){ - node.level = level; - } - } ; - } + private Long id; + private Long parentId; + private int level; + private String name; + private String path; + private String icon; + private List children; + + // 树结构数据句柄 + public static ITreeDataLevelHandler createTreeHandler() { + return new ITreeDataLevelHandler() { + @Override + public Long getId(MenuVO node) { + return node.getId(); + } + + @Override + public Long getParentId(MenuVO node) { + return node.getParentId(); + } + + @Override + public List getChildren(MenuVO node) { + return node.children; + } + + @Override + public void setChildren(MenuVO node, List children) { + node.children = children; + } + + @Override + public int getLevel(MenuVO node) { + return node.level; + } + + @Override + public void setLevel(MenuVO node, int level) { + node.level = level; + } + }; + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java index 2774213..54c963e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java @@ -32,7 +32,7 @@ public class PreviewMenuTreeService { public R treeAll(@SwParam("module") String module, UserSession us) { String prj_id = ModelProjectCache.getInstance().getIdByModule(module); - if(!SwConsts.SysParam.SYS_DEBUG){ + if (!SwConsts.SysParam.SYS_DEBUG) { List menuVOList = buildMenu(prj_id, module, us); if (!CommUtil.isEmpty(menuVOList)) { return R.success(menuVOList); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/AbstractDynPageHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/AbstractDynPageHandler.java index b678aad..53a6f18 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/AbstractDynPageHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/AbstractDynPageHandler.java @@ -1,8 +1,7 @@ package cc.smtweb.system.bpm.web.engine.dynPage; -import cc.smtweb.framework.core.exception.BizException; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.common.SwMap; +import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.system.bpm.web.design.form.ModelForm; @@ -20,9 +19,11 @@ public abstract class AbstractDynPageHandler extends AbstractHandler { protected PageDatasets datasets; protected DynPageProvider provider = getProvider(); + public DynPageProvider getProvider() { return new DynPageProvider(); } + @Override public void init(SwMap params, UserSession us) { super.init(params, us); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java index b4cdb67..d805477 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageHelper.java @@ -274,7 +274,7 @@ public class DynPageHelper { return null; } IBuilderExpr builder = getBuilder(dynCond.opt); - String ns = isNameSelf ? filter.name : filter.name + "_" + dynCond.hashCode(); + String ns = isNameSelf ? filter.name: filter.name + "_" + dynCond.hashCode(); return builder.build(dynCond.opt, filter.sqlName, ns, value, args); } @@ -334,7 +334,7 @@ public class DynPageHelper { private static IBuilderExpr getBuilder(String opt) { IBuilderExpr builder = mapBuilder.get(opt); - return builder != null ? builder : baseBuilder; + return builder != null ? builder: baseBuilder; } interface IBuilderExpr { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageListHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageListHandler.java index 3d811ab..104eda5 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageListHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageListHandler.java @@ -52,18 +52,18 @@ public class DynPageListHandler extends AbstractListHandler { @Override protected List queryData(String sql, SqlPara sqlPara) { List list; - SqlNamedPara sp = (SqlNamedPara)sqlPara; + SqlNamedPara sp = (SqlNamedPara) sqlPara; if (sqlPara.page > 0 && sqlPara.rows > 0) { list = DbEngine.getInstance().pagedQueryN(sql, SwMap.class, (sqlPara.page - 1) * sqlPara.rows, sqlPara.rows, sp.mapParas); } else { list = DbEngine.getInstance().queryN(sql, sp.mapParas, SwMap.class); } - if(pageDataSet.masterTable > 0L){ + if (pageDataSet.masterTable > 0L) { ModelTable masterTable = ModelTableCache.getInstance().get(pageDataSet.masterTable); EntityHelper.loadBeanText(masterTable.getName(), list, sp.mapFieldAlias); } - for (SwMap map: list) { + for (SwMap map : list) { DynPageHelper.setCalcFields(map, pageDataSet); } return list; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageLoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageLoadHandler.java index a9fad55..c024f6a 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageLoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageLoadHandler.java @@ -4,8 +4,6 @@ import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwEnum; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.mvc.service.SwListData; -import cc.smtweb.system.bpm.web.design.form.ModelForm; -import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; import cc.smtweb.system.bpm.web.design.form.define.PageDataset; /** @@ -19,6 +17,7 @@ public class DynPageLoadHandler extends AbstractDynPageHandler { //对应的数据集定义 private PageDataset pageDataSet; + //列表工具类 public DynPageListHandler getListWorker(SwMap filter, PageDataset pageDataSet) { DynPageListHandler listHandler = new DynPageListHandler(form.getId(), filter, pageDataSet); @@ -32,6 +31,7 @@ public class DynPageLoadHandler extends AbstractDynPageHandler { listHandler.init(params, us); return listHandler; } + //新增操作,初始化定义的数据集 public R add() { //返回的数据,以dataset.name为key,查出的结果(bean或list)为value @@ -64,11 +64,16 @@ public class DynPageLoadHandler extends AbstractDynPageHandler { } //新增初始化 - bean - protected void afterAddBean(PageDataset dataset, SwMap bean){} + protected void afterAddBean(PageDataset dataset, SwMap bean) { + } + //加载之后 - protected void afterLoadBean(PageDataset dataset, SwMap bean){} + protected void afterLoadBean(PageDataset dataset, SwMap bean) { + } + //新增初始化 - list - protected void afterAddList(PageDataset dataset, SwListData bean){} + protected void afterAddList(PageDataset dataset, SwListData bean) { + } //新增操作,初始化定义的数据集 public R addOne() { @@ -107,7 +112,7 @@ public class DynPageLoadHandler extends AbstractDynPageHandler { bean = DynRetBean.createList(SwListData.create(getTreeWorker(filter, pageDataSet).buildData(), 0)); } else {//表单类 SwMap data = provider.loadData(filter, pageDataSet); - afterLoadBean(pageDataSet,data); + afterLoadBean(pageDataSet, data); bean = DynRetBean.createBean(data); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageProvider.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageProvider.java index 4d8d024..180b78b 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageProvider.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageProvider.java @@ -1,13 +1,13 @@ package cc.smtweb.system.bpm.web.engine.dynPage; -import cc.smtweb.framework.core.db.EntityDao; -import cc.smtweb.framework.core.db.impl.DefaultEntity; -import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.DbEngine; +import cc.smtweb.framework.core.db.EntityDao; import cc.smtweb.framework.core.db.EntityHelper; import cc.smtweb.framework.core.db.cache.ModelTableCache; +import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.db.vo.ModelTable; +import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.mvc.service.AbstractCompProvider; import cc.smtweb.framework.core.mvc.service.SqlNamedPara; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageService.java index 1bd9220..eb35f30 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageService.java @@ -30,46 +30,46 @@ public class DynPageService extends AbstractCompService { //新增 public R add(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).add()); + return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler) handler).add()); } //新增 public R addOne(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).addOne()); + return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler) handler).addOne()); } //加载 public R loadOne(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).loadOne()); + return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler) handler).loadOne()); } //保存指定数据集 public R saveOne(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_SAVE, handler -> ((DynPageSaveHandler)handler).saveOne()); + return pageHandler(params, us, TYPE_SAVE, handler -> ((DynPageSaveHandler) handler).saveOne()); } //保存指定数据集 public R save(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_SAVE, handler -> ((DynPageSaveHandler)handler).saveAll()); + return pageHandler(params, us, TYPE_SAVE, handler -> ((DynPageSaveHandler) handler).saveAll()); } //删除指定数据集 public R delOne(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_DEL, handler -> ((DynPageDelHandler)handler).delOne()); + return pageHandler(params, us, TYPE_DEL, handler -> ((DynPageDelHandler) handler).delOne()); } //删除数据 public R del(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_DEL, handler -> ((DynPageDelHandler)handler).delAll()); + return pageHandler(params, us, TYPE_DEL, handler -> ((DynPageDelHandler) handler).delAll()); } //列表总记录数及合计栏 public R total(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).getTotal()); + return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler) handler).getTotal()); } //树过滤 public R treeFilter(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler)handler).treeFilter()); + return pageHandler(params, us, TYPE_LOAD, handler -> ((DynPageLoadHandler) handler).treeFilter()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageTreeHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageTreeHandler.java index 7884432..4ca2394 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageTreeHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynPageTreeHandler.java @@ -50,6 +50,7 @@ public class DynPageTreeHandler extends AbstractTreeHandler { /** * 构建sql + * * @return */ protected SqlNamedPara buildDataSqlPara(long id) { @@ -58,6 +59,7 @@ public class DynPageTreeHandler extends AbstractTreeHandler { /** * 构建sql + * * @return */ protected SqlNamedPara buildFilterSqlPara(String text) { @@ -86,6 +88,6 @@ public class DynPageTreeHandler extends AbstractTreeHandler { ModelTable table = ModelTableCache.getInstance().get(pageDataSet.masterTable); if (table == null) throw new BizException("未找到数据集表定义:" + pageDataSet.masterTable); ModelField field = table.findFieldByType(SwEnum.FieldType.NAME.value); - return field != null ? bean.readString(field.getName()) : bean.readString(table.getIdField()); + return field != null ? bean.readString(field.getName()): bean.readString(table.getIdField()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynRetBean.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynRetBean.java index ed08934..153fc73 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynRetBean.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/DynRetBean.java @@ -19,6 +19,7 @@ public class DynRetBean { public static DynRetBean createBean(DefaultEntity bean) { return createBean(bean.getData()); } + public static DynRetBean createBean(SwMap swMap) { SwMap form = (SwMap) swMap.clone(); DynRetBean bean = new DynRetBean(); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/IBuildSqlListener.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/IBuildSqlListener.java index 56e371b..83acad2 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/IBuildSqlListener.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/dynPage/IBuildSqlListener.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.engine.dynPage; import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.framework.core.mvc.service.SqlNamedPara; import cc.smtweb.system.bpm.web.design.form.define.PageDataset; /** diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowHelper.java index 6710821..c22a3ee 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowHelper.java @@ -49,7 +49,7 @@ public class FlowHelper { public static void stopTask(long billId, long tskId) { DbEngine.getInstance().update("update " + EntityHelper.getSchemaTableName(Task.ENTITY_NAME) + - " set tsk_statu=? where tsk_pri_id=? and tsk_id<>? and tsk_statu? and tsk_statu dstTasks) {} + default void afterSubmit(Task srcTask, List dstTasks) { + } + //取回 - default void afterRetake(Task srcTask, List dstTasks) {} + default void afterRetake(Task srcTask, List dstTasks) { + } + //驳回 - default void afterReject(Task srcTask, List dstTasks) {} + default void afterReject(Task srcTask, List dstTasks) { + } + //办理,签收 - default void afterHandle(Task srcTask) {} + default void afterHandle(Task srcTask) { + } + //作废 - default void afterDisuse(Task srcTask) {} + default void afterDisuse(Task srcTask) { + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java index d371d17..7acf9ca 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowProvider.java @@ -5,12 +5,8 @@ import cc.smtweb.framework.core.db.EntityDao; import cc.smtweb.framework.core.db.EntityHelper; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.AbstractCompProvider; -import cc.smtweb.framework.core.mvc.service.IDataProvider; -import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.system.bpm.web.design.flow.FlowConst; -import cc.smtweb.system.bpm.web.design.form.ModelForm; -import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; import cc.smtweb.system.bpm.web.engine.flow.entity.Comment; import cc.smtweb.system.bpm.web.engine.flow.entity.ProcInst; import cc.smtweb.system.bpm.web.engine.flow.entity.Task; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java index 1a35236..b92ca18 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Comment.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.engine.flow.entity; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,102 +15,156 @@ public class Comment extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("cmt_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long cmt_id) { put("cmt_id", cmt_id); } - /** 流程id */ + + /** + * 流程id + */ public long getPriId() { return getLong("cmt_pri_id"); } - /** 流程id */ + /** + * 流程id + */ public void setPriId(long cmt_pri_id) { put("cmt_pri_id", cmt_pri_id); } - /** 任务id */ + + /** + * 任务id + */ public long getTskId() { return getLong("cmt_tsk_id"); } - /** 任务id */ + /** + * 任务id + */ public void setTskId(long cmt_tsk_id) { put("cmt_tsk_id", cmt_tsk_id); } - /** 活动id */ + + /** + * 活动id + */ public String getActId() { return getStr("cmt_act_id"); } - /** 活动id */ + /** + * 活动id + */ public void setActId(String cmt_act_id) { put("cmt_act_id", cmt_act_id); } - /** 活动名 */ + + /** + * 活动名 + */ public String getActName() { return getStr("cmt_act_name"); } - /** 活动名 */ + /** + * 活动名 + */ public void setActName(String cmt_act_name) { put("cmt_act_name", cmt_act_name); } - /** 主办人 */ + + /** + * 主办人 + */ public long getHandler() { return getLong("cmt_handler"); } - /** 主办人 */ + /** + * 主办人 + */ public void setHandler(long cmt_handler) { put("cmt_handler", cmt_handler); } - /** 开始时间 */ + + /** + * 开始时间 + */ public long getStartTime() { return getLong("cmt_start_time"); } - /** 开始时间 */ + /** + * 开始时间 + */ public void setStartTime(long cmt_start_time) { put("cmt_start_time", cmt_start_time); } - /** 签收时间 */ + + /** + * 签收时间 + */ public long getHandlerTime() { return getLong("cmt_handler_time"); } - /** 签收时间 */ + /** + * 签收时间 + */ public void setHandlerTime(long cmt_handler_time) { put("cmt_handler_time", cmt_handler_time); } - /** 结束时间 */ + + /** + * 结束时间 + */ public long getEndTime() { return getLong("cmt_end_time"); } - /** 结束时间 */ + /** + * 结束时间 + */ public void setEndTime(long cmt_end_time) { put("cmt_end_time", cmt_end_time); } - /** 审批意见 */ + + /** + * 审批意见 + */ public String getComment() { return getStr("cmt_comment"); } - /** 审批意见 */ + /** + * 审批意见 + */ public void setComment(String cmt_comment) { put("cmt_comment", cmt_comment); } - /** 状态 */ + + /** + * 状态 + */ public int getStatu() { return getInt("cmt_statu"); } - /** 状态 */ + /** + * 状态 + */ public void setStatu(int cmt_statu) { put("cmt_statu", cmt_statu); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/FlowLog.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/FlowLog.java index 99e365f..2370834 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/FlowLog.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/FlowLog.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.engine.flow.entity; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,84 +15,128 @@ public class FlowLog extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("wfl_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long wfl_id) { put("wfl_id", wfl_id); } - /** 单据id */ + + /** + * 单据id + */ public long getPriId() { return getLong("wfl_pri_id"); } - /** 单据id */ + /** + * 单据id + */ public void setPriId(long wfl_pri_id) { put("wfl_pri_id", wfl_pri_id); } - /** 操作人 */ + + /** + * 操作人 + */ public long getUsrId() { return getLong("wfl_usr_id"); } - /** 操作人 */ + /** + * 操作人 + */ public void setUsrId(long wfl_usr_id) { put("wfl_usr_id", wfl_usr_id); } - /** 步骤id */ + + /** + * 步骤id + */ public long getActId() { return getLong("wfl_act_id"); } - /** 步骤id */ + /** + * 步骤id + */ public void setActId(long wfl_act_id) { put("wfl_act_id", wfl_act_id); } - /** 步骤名 */ + + /** + * 步骤名 + */ public String getActName() { return getStr("wfl_act_name"); } - /** 步骤名 */ + /** + * 步骤名 + */ public void setActName(String wfl_act_name) { put("wfl_act_name", wfl_act_name); } - /** 操作 */ + + /** + * 操作 + */ public String getOpt() { return getStr("wfl_opt"); } - /** 操作 */ + /** + * 操作 + */ public void setOpt(String wfl_opt) { put("wfl_opt", wfl_opt); } - /** 提交信息 */ + + /** + * 提交信息 + */ public String getInfo() { return getStr("wfl_info"); } - /** 提交信息 */ + /** + * 提交信息 + */ public void setInfo(String wfl_info) { put("wfl_info", wfl_info); } - /** 意见 */ + + /** + * 意见 + */ public String getComment() { return getStr("wfl_comment"); } - /** 意见 */ + /** + * 意见 + */ public void setComment(String wfl_comment) { put("wfl_comment", wfl_comment); } - /** 操作时间 */ + + /** + * 操作时间 + */ public long getTime() { return getLong("wfl_time"); } - /** 操作时间 */ + /** + * 操作时间 + */ public void setTime(long wfl_time) { put("wfl_time", wfl_time); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/ProcInst.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/ProcInst.java index ffd502b..9d9defc 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/ProcInst.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/ProcInst.java @@ -15,111 +15,170 @@ public class ProcInst extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("pri_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long pri_id) { put("pri_id", pri_id); } - /** 单据编号 */ + + /** + * 单据编号 + */ public String getBillCode() { return getStr("pri_bill_code"); } - /** 单据编号 */ + /** + * 单据编号 + */ public void setBillCode(String pri_bill_code) { put("pri_bill_code", pri_bill_code); } - /** 制单日期 */ + + /** + * 制单日期 + */ public long getMakeDate() { return getLong("pri_make_date"); } - /** 制单日期 */ + /** + * 制单日期 + */ public void setMakeDate(long pri_make_date) { put("pri_make_date", pri_make_date); } - /** 单据类别 */ + + /** + * 单据类别 + */ public long getBillType() { return getLong("pri_bill_type"); } - /** 单据类别 */ + /** + * 单据类别 + */ public void setBillType(long pri_bill_type) { put("pri_bill_type", pri_bill_type); } - /** 编制单位 */ + + /** + * 编制单位 + */ public long getPartyId() { return getLong("pri_party_id"); } - /** 编制单位 */ + /** + * 编制单位 + */ public void setPartyId(long pri_party_id) { put("pri_party_id", pri_party_id); } - /** 编制部门 */ + + /** + * 编制部门 + */ public long getDeptId() { return getLong("pri_dept_id"); } - /** 编制部门 */ + /** + * 编制部门 + */ public void setDeptId(long pri_dept_id) { put("pri_dept_id", pri_dept_id); } - /** 摘要 */ + + /** + * 摘要 + */ public String getBillDesc() { return getStr("pri_bill_desc"); } - /** 摘要 */ + /** + * 摘要 + */ public void setBillDesc(String pri_bill_desc) { put("pri_bill_desc", pri_bill_desc); } - /** 流程定义 */ + + /** + * 流程定义 + */ public long getPrcId() { return getLong("pri_prc_id"); } - /** 流程定义 */ + /** + * 流程定义 + */ public void setPrcId(long pri_prc_id) { put("pri_prc_id", pri_prc_id); } - /** 开始时间 */ + + /** + * 开始时间 + */ public long getStartTime() { return getLong("pri_start_time"); } - /** 开始时间 */ + /** + * 开始时间 + */ public void setStartTime(long pri_start_time) { put("pri_start_time", pri_start_time); } - /** 结束时间 */ + + /** + * 结束时间 + */ public long getEndTime() { return getLong("pri_end_time"); } - /** 结束时间 */ + /** + * 结束时间 + */ public void setEndTime(long pri_end_time) { put("pri_end_time", pri_end_time); } - /** 最后操作用户 */ + + /** + * 最后操作用户 + */ public long getUserId() { return getLong("pri_user_id"); } - /** 最后操作用户 */ + /** + * 最后操作用户 + */ public void setUserId(long pri_user_id) { put("pri_user_id", pri_user_id); } - /** 当前任务 */ + + /** + * 当前任务 + */ public long getTaskId() { return getLong("pri_task_id"); } - /** 当前任务 */ + /** + * 当前任务 + */ public void setTaskId(long pri_task_id) { put("pri_task_id", pri_task_id); } @@ -132,30 +191,44 @@ public class ProcInst extends DefaultEntity { put("pri_act_name", priActName); } - /** 单据状态 */ + /** + * 单据状态 + */ public int getStatu() { return getInt("pri_statu"); } - /** 单据状态 */ + /** + * 单据状态 + */ public void setStatu(int pri_statu) { put("pri_statu", pri_statu); } - /** 单据描述 */ + + /** + * 单据描述 + */ public String getBillInfo() { return getStr("pri_bill_info"); } - /** 单据描述 */ + /** + * 单据描述 + */ public void setBillInfo(String pri_bill_info) { put("pri_bill_info", pri_bill_info); } - /** 单据链接 */ + + /** + * 单据链接 + */ public String getUrl() { return getStr("pri_url"); } - /** 单据链接 */ + /** + * 单据链接 + */ public void setUrl(String pri_url) { put("pri_url", pri_url); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Task.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Task.java index f22c7d3..70f087e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Task.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/Task.java @@ -15,183 +15,282 @@ public class Task extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("tsk_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long tsk_id) { put("tsk_id", tsk_id); } - /** 流程实例id */ + + /** + * 流程实例id + */ public long getPriId() { return getLong("tsk_pri_id"); } - /** 流程实例id */ + /** + * 流程实例id + */ public void setPriId(long tsk_pri_id) { put("tsk_pri_id", tsk_pri_id); } - /** 流程定义id */ + + /** + * 流程定义id + */ public long getPrcId() { return getLong("tsk_prc_id"); } - /** 流程定义id */ + /** + * 流程定义id + */ public void setPrcId(long tsk_prc_id) { put("tsk_prc_id", tsk_prc_id); } - /** 活动定义id */ + + /** + * 活动定义id + */ public String getActId() { return getStr("tsk_act_id"); } - /** 活动定义id */ + /** + * 活动定义id + */ public void setActId(String tsk_act_id) { put("tsk_act_id", tsk_act_id); } - /** 活动名称 */ + + /** + * 活动名称 + */ public String getActName() { return getStr("tsk_act_name"); } - /** 活动名称 */ + /** + * 活动名称 + */ public void setActName(String tsk_act_name) { put("tsk_act_name", tsk_act_name); } - /** 主办人 */ + + /** + * 主办人 + */ public long getHandler() { return getLong("tsk_handler"); } - /** 主办人 */ + /** + * 主办人 + */ public void setHandler(long tsk_handler) { put("tsk_handler", tsk_handler); } - /** 开始时间 */ + + /** + * 开始时间 + */ public long getStartTime() { return getLong("tsk_start_time"); } - /** 开始时间 */ + /** + * 开始时间 + */ public void setStartTime(long tsk_start_time) { put("tsk_start_time", tsk_start_time); } - /** 签收时间 */ + + /** + * 签收时间 + */ public long getHandlerTime() { return getLong("tsk_handler_time"); } - /** 签收时间 */ + /** + * 签收时间 + */ public void setHandlerTime(long tsk_handler_time) { put("tsk_handler_time", tsk_handler_time); } - /** 结束时间 */ + + /** + * 结束时间 + */ public long getEndTime() { return getLong("tsk_end_time"); } - /** 结束时间 */ + /** + * 结束时间 + */ public void setEndTime(long tsk_end_time) { put("tsk_end_time", tsk_end_time); } - /** 状态 */ + + /** + * 状态 + */ public int getStatu() { return getInt("tsk_statu"); } - /** 状态 */ + /** + * 状态 + */ public void setStatu(int tsk_statu) { put("tsk_statu", tsk_statu); } - /** 审批意见 */ + + /** + * 审批意见 + */ public String getComment() { return getStr("tsk_comment"); } - /** 审批意见 */ + /** + * 审批意见 + */ public void setComment(String tsk_comment) { put("tsk_comment", tsk_comment); } - /** 是否制单步骤 */ + + /** + * 是否制单步骤 + */ public boolean isMake() { return getBool("tsk_is_make"); } - /** 是否制单步骤 */ + /** + * 是否制单步骤 + */ public void setMake(boolean tsk_is_make) { setBool("tsk_is_make", tsk_is_make); } - /** 是否需要会签 */ + + /** + * 是否需要会签 + */ public boolean isSign() { return getBool("tsk_is_sign"); } - /** 是否需要会签 */ + /** + * 是否需要会签 + */ public void setSign(boolean tsk_is_sign) { setBool("tsk_is_sign", tsk_is_sign); } - /** 会签人数 */ + + /** + * 会签人数 + */ public int getSignTotal() { return getInt("tsk_sign_total"); } - /** 会签人数 */ + /** + * 会签人数 + */ public void setSignTotal(int tsk_sign_total) { put("tsk_sign_total", tsk_sign_total); } - /** 设置会签过关人数 */ + + /** + * 设置会签过关人数 + */ public int getSignPass() { return getInt("tsk_sign_pass"); } - /** 设置会签过关人数 */ + /** + * 设置会签过关人数 + */ public void setSignPass(int tsk_sign_pass) { put("tsk_sign_pass", tsk_sign_pass); } - /** 会签同意人数 */ + + /** + * 会签同意人数 + */ public int getSignAgree() { return getInt("tsk_sign_agree"); } - /** 会签同意人数 */ + /** + * 会签同意人数 + */ public void setSignAgree(int tsk_sign_agree) { put("tsk_sign_agree", tsk_sign_agree); } - /** 是否被驳回 */ + + /** + * 是否被驳回 + */ public boolean isReject() { return getBool("tsk_is_reject"); } - /** 是否被驳回 */ + /** + * 是否被驳回 + */ public void setReject(boolean tsk_is_reject) { setBool("tsk_is_reject", tsk_is_reject); } - /** 是否取回 */ + + /** + * 是否取回 + */ public boolean isRetake() { return getBool("tsk_is_retake"); } - /** 是否取回 */ + /** + * 是否取回 + */ public void setRetake(boolean tsk_is_retake) { setBool("tsk_is_retake", tsk_is_retake); } - /** 是否自动任务 */ + + /** + * 是否自动任务 + */ public boolean isAuto() { return getBool("tsk_is_auto"); } - /** 是否自动任务 */ + /** + * 是否自动任务 + */ public void setAuto(boolean tsk_is_auto) { setBool("tsk_is_auto", tsk_is_auto); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("tsk_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String tsk_remark) { put("tsk_remark", tsk_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/TaskRel.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/TaskRel.java index 3a6f924..081ff05 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/TaskRel.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/entity/TaskRel.java @@ -15,39 +15,58 @@ public class TaskRel extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("trl_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long trl_id) { put("trl_id", trl_id); } - /** 流程实例id */ + + /** + * 流程实例id + */ public long getPriId() { return getLong("trl_pri_id"); } - /** 流程实例id */ + /** + * 流程实例id + */ public void setPriId(long trl_pri_id) { put("trl_pri_id", trl_pri_id); } - /** 前任务id */ + + /** + * 前任务id + */ public long getSrcTaskId() { return getLong("trl_src_task_id"); } - /** 前任务id */ + /** + * 前任务id + */ public void setSrcTaskId(long trl_src_task_id) { put("trl_src_task_id", trl_src_task_id); } - /** 目标任务id */ + + /** + * 目标任务id + */ public long getDstTaskId() { return getLong("trl_dst_task_id"); } - /** 目标任务id */ + /** + * 目标任务id + */ public void setDstTaskId(long trl_dst_task_id) { put("trl_dst_task_id", trl_dst_task_id); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowDelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowDelHandler.java index 2e6989e..fb3282e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowDelHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowDelHandler.java @@ -11,12 +11,13 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleDelHandler; */ public class FlowDelHandler extends LCSingleDelHandler implements FlowListener { protected FlowInstance flowInstance; + @Override protected void localDel(long id, ModelTable table) { long taskId = params.readLong("taskId"); flowInstance = FlowInstance.createById(us, this, id, taskId); flowInstance.delete(); super.localDel(id, table); - + } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowListHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowListHandler.java index 9be2871..b7dea8f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowListHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowListHandler.java @@ -14,7 +14,7 @@ import cc.smtweb.system.bpm.web.engine.flow.entity.ProcInst; * Created by Akmm at 2022-08-29 11:41 */ public class FlowListHandler extends DynPageListHandler { - static IBuildSqlListener sqlListener = new IBuildSqlListener(){ + static IBuildSqlListener sqlListener = new IBuildSqlListener() { @Override public void buildSelect(PageDataset dataSet, StringBuilder sql) { sql.append("\ninner join " + EntityHelper.getSchemaTableName(ProcInst.ENTITY_NAME) + " on pri_id=" + dataSet._getModelTable().getIdField()); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleLoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleLoadHandler.java index 8d10cf5..6800305 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleLoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleLoadHandler.java @@ -1,27 +1,18 @@ package cc.smtweb.system.bpm.web.engine.model.flow.listcard.single; import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.common.SwConsts; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; -import cc.smtweb.framework.core.db.vo.ModelTable; -import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.SwListData; -import cc.smtweb.system.bpm.web.design.flow.FlowConst; -import cc.smtweb.system.bpm.web.design.form.ModelForm; -import cc.smtweb.system.bpm.web.design.form.ModelFormHelper; import cc.smtweb.system.bpm.web.design.form.define.PageDataset; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageListHandler; import cc.smtweb.system.bpm.web.engine.dynPage.DynRetBean; import cc.smtweb.system.bpm.web.engine.flow.FlowHelper; import cc.smtweb.system.bpm.web.engine.flow.FlowInstance; import cc.smtweb.system.bpm.web.engine.flow.FlowListener; -import cc.smtweb.system.bpm.web.engine.flow.FlowProvider; import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleHelper; import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleLoadHandler; -import java.util.ArrayList; - /** * Created by Akmm at 2022-08-26 17:15 * 流程加载 @@ -32,7 +23,7 @@ public class FlowSingleLoadHandler extends LCSingleLoad @Override protected void afterAdd(SwMap ret, T bean) { flowInstance = FlowInstance.createByBillType(us, this, form.getBillType()); - + PageDataset cardDataset = LCSingleHelper.findCardDataset(datasets); bean.setEntityId(flowInstance.getProcInst().getId()); @@ -54,7 +45,7 @@ public class FlowSingleLoadHandler extends LCSingleLoad ret.put(cardDataset.name, DynRetBean.createBean(bean)); //加载流程信息 - flowInstance = FlowInstance.createById(us,this, id, taskId); + flowInstance = FlowInstance.createById(us, this, id, taskId); ret.put(FlowHelper.DATASET_NAME_FLOW, DynRetBean.createBean(flowInstance.getProcInst())); ret.put(FlowHelper.DATASET_NAME_COMMENT, DynRetBean.createList(SwListData.create(flowInstance.loadComment(), 0))); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java index 9f0ab5a..c4c968e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleSaveHandler.java @@ -1,6 +1,5 @@ package cc.smtweb.system.bpm.web.engine.model.flow.listcard.single; -import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.exception.BizException; @@ -35,7 +34,7 @@ public class FlowSingleSaveHandler extends LCSingleSave if (bean.isNew()) { flowInstance = FlowInstance.createByBillType(us, this, form.getBillType()); } else { - flowInstance = FlowInstance.createById(us,this, id, taskId); + flowInstance = FlowInstance.createById(us, this, id, taskId); } flowInstance.readFromPage(data); flowInstance.getProcInst().setIsNew(bean.isNew()); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleService.java index 6ed76d4..6b7845f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowSingleService.java @@ -4,7 +4,6 @@ import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.framework.core.mvc.service.IWorker; import cc.smtweb.framework.core.session.UserSession; @@ -20,6 +19,7 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleService; @SwService public class FlowSingleService extends LCSingleService { public static final String TYPE_FLOW = "flow"; + @Override protected AbstractHandler createHandler(String type) { if (TYPE_FLOW.equals(type)) return new FlowTransHandler(); @@ -43,12 +43,13 @@ public class FlowSingleService extends LCSingleService { protected R flowHandler(SwMap params, UserSession us, IWorker worker) { try { - FlowTransHandler handler = (FlowTransHandler)getHandler(params, us, TYPE_FLOW); + FlowTransHandler handler = (FlowTransHandler) getHandler(params, us, TYPE_FLOW); return worker.doWork(handler); } catch (Exception e) { return R.error("操作失败!", e); } } + public R submit(@SwBody SwMap params, UserSession us) { return flowHandler(params, us, FlowTransHandler::submit); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java index 2ad9a72..d9602e0 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/flow/listcard/single/FlowTransHandler.java @@ -17,7 +17,7 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleHelper; * Created by Akmm at 2022-09-01 15:03 * 流程流转 */ -public class FlowTransHandler extends AbstractDynPageHandler implements FlowListener{ +public class FlowTransHandler extends AbstractDynPageHandler implements FlowListener { //流程id protected long billId; //任务id diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsDelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsDelHandler.java index 7fba375..56ff23c 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsDelHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsDelHandler.java @@ -27,7 +27,7 @@ public abstract class AbsDelHandler extends AbstractDynPageHandler { long id = params.readLong("id"); if (id <= 0L) throw new BizException("没有收到待删除记录Id(" + id + ")!"); //数据集 - PageDataset pageDataset = ModelUtils.findPageDatasetByName(this.datasets,dsName); + PageDataset pageDataset = ModelUtils.findPageDatasetByName(this.datasets, dsName); // checkBean(pageDataset, id); // diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsLoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsLoadHandler.java index 24fbb06..a6fef02 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsLoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsLoadHandler.java @@ -18,6 +18,7 @@ public abstract class AbsLoadHandler extends AbstractDynPageHandler { /** * 新增初始化 + * * @param dsName * @return */ @@ -36,19 +37,21 @@ public abstract class AbsLoadHandler extends AbstractDynPageHandler { /** * 加载卡片数据 + * * @param dsName * @return */ - protected SwMap doLoadCard(String dsName){ + protected SwMap doLoadCard(String dsName) { //过滤条件 SwMap filter = params.readMap("filter"); //对应的数据集定义 - PageDataset loadDataSet = ModelUtils.findPageDatasetByName(this.datasets,dsName); + PageDataset loadDataSet = ModelUtils.findPageDatasetByName(this.datasets, dsName); return provider.loadData(filter, loadDataSet); } /** * 列表数据 + * * @return */ protected DynRetBean doList(String dsName) { @@ -56,7 +59,7 @@ public abstract class AbsLoadHandler extends AbstractDynPageHandler { SwMap filter = params.readMap("filter"); //对应的数据集定义 - PageDataset listDataSet = ModelUtils.findPageDatasetByName(this.datasets,dsName); + PageDataset listDataSet = ModelUtils.findPageDatasetByName(this.datasets, dsName); return DynRetBean.createList(getListWorker(filter, listDataSet).buildListData()); } @@ -71,7 +74,7 @@ public abstract class AbsLoadHandler extends AbstractDynPageHandler { SwMap filter = params.readMap("filter"); //对应的数据集定义 - PageDataset listDataSet = ModelUtils.findPageDatasetByName(this.datasets,dsName); + PageDataset listDataSet = ModelUtils.findPageDatasetByName(this.datasets, dsName); return getListWorker(filter, listDataSet).getTotal(); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsSaveHandler.java index 0e11d08..50e38a5 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/abshandler/AbsSaveHandler.java @@ -29,7 +29,7 @@ import java.util.Map; * @Author:lip * @Date : 2022/9/2 15:02 */ -public abstract class AbsSaveHandler extends AbstractDynPageHandler { +public abstract class AbsSaveHandler extends AbstractDynPageHandler { private Map> mapTreeBean = new HashMap<>(); protected void setNewId(T bean) { @@ -43,7 +43,7 @@ public abstract class AbsSaveHandler extends AbstractD SwMap data = params.readMap("data"); if (data == null) throw new BizException("没有收到待保存的的数据:" + dsName + "!"); //对应的数据集定义 - PageDataset pageDataSet = ModelUtils.findPageDatasetByName(this.datasets,dsName); + PageDataset pageDataSet = ModelUtils.findPageDatasetByName(this.datasets, dsName); //读取待保存的bean T bean = readBeanFromPage(pageDataSet, data.readMap(dsName).readMap("form")); if (filter != null && bean.isNew()) {//有过滤条件,将关联的值设上 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1DelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1DelHandler.java index e4e13ba..a25ad52 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1DelHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1DelHandler.java @@ -11,36 +11,40 @@ public class LCLC1DelHandler extends AbsDelHandler { /** * 左列表删除 + * * @return */ - public R lLDel(){ + public R lLDel() { doDel(LCLC1Define.dsLList); return R.success(); } /** * 左卡片删除 + * * @return */ - public R lCDel(){ + public R lCDel() { doDel(LCLC1Define.dsLCard); return R.success(); } /** * 右列表删除 + * * @return */ - public R rLDel(){ + public R rLDel() { doDel(LCLC1Define.dsRList); return R.success(); } /** * 右卡片删除 + * * @return */ - public R rCDel(){ + public R rCDel() { doDel(LCLC1Define.dsRCard); return R.success(); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1LoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1LoadHandler.java index c6f82d1..247d636 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1LoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1LoadHandler.java @@ -13,6 +13,7 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleHelper; public class LCLC1LoadHandler extends AbsLoadHandler { /** * 左表新增 + * * @return */ public R lAdd() { @@ -22,6 +23,7 @@ public class LCLC1LoadHandler extends AbsLoadHandler { /** * 右表新增 + * * @return */ public R rAdd() { @@ -31,6 +33,7 @@ public class LCLC1LoadHandler extends AbsLoadHandler { /** * 左表编辑 + * * @return */ public R lLoad() { @@ -40,6 +43,7 @@ public class LCLC1LoadHandler extends AbsLoadHandler { /** * 右表编辑 + * * @return */ public R rLoad() { @@ -49,35 +53,39 @@ public class LCLC1LoadHandler extends AbsLoadHandler { /** * 左列表加载 + * * @return */ - public R lList(){ + public R lList() { DynRetBean list = doList(LCLC1Define.dsLList); return R.success(list); } /** * 右列表加载 + * * @return */ - public R rList(){ + public R rList() { DynRetBean list = doList(LCLC1Define.dsRList); return R.success(list); } /** * 左列表分页数据 + * * @return */ - public R getLTotal(){ + public R getLTotal() { return doTotal(LCLC1Define.dsLList); } /** * 右列表分页数据 + * * @return */ - public R getRTotal(){ + public R getRTotal() { return doTotal(LCLC1Define.dsRList); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1SaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1SaveHandler.java index b1dfbc5..128900a 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1SaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1SaveHandler.java @@ -12,6 +12,7 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleHelper; public class LCLC1SaveHandler extends AbsSaveHandler { /** * 左表保存 + * * @return */ public R lSave() { @@ -21,6 +22,7 @@ public class LCLC1SaveHandler extends AbsSaveHandler { /** * 右表保存 + * * @return */ public R rSave() { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1Service.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1Service.java index f3e9c3f..1df7f21 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1Service.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/lclc1/LCLC1Service.java @@ -19,6 +19,7 @@ public class LCLC1Service extends DynPageService { protected final static String TYPE_MODEL_LOAD = "modelLoad"; protected final static String TYPE_MODEL_SAVE = "modelSave"; protected final static String TYPE_MODEL_DEL = "modelDel"; + // @Override protected AbstractHandler createHandler(String type) { @@ -37,73 +38,73 @@ public class LCLC1Service extends DynPageService { //保存 public R modelLSave(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCLC1SaveHandler)handler).lSave()); + return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCLC1SaveHandler) handler).lSave()); } //读取 public R modelLLoad(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCLC1LoadHandler)handler).lLoad()); + return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCLC1LoadHandler) handler).lLoad()); } //读取 public R modelLAdd(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCLC1LoadHandler)handler).lAdd()); + return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCLC1LoadHandler) handler).lAdd()); } //删除 public R modelLLDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCLC1DelHandler)handler).lLDel()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCLC1DelHandler) handler).lLDel()); } //删除 public R modelLCDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCLC1DelHandler)handler).lCDel()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCLC1DelHandler) handler).lCDel()); } //列表数据 public R modelLList(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCLC1LoadHandler)handler).lList()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCLC1LoadHandler) handler).lList()); } //列表总记录数及合计栏 public R modelLListTotal(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCLC1LoadHandler)handler).getLTotal()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCLC1LoadHandler) handler).getLTotal()); } //右表 //保存 public R modelRSave(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCLC1SaveHandler)handler).rSave()); + return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCLC1SaveHandler) handler).rSave()); } //读取 public R modelRLoad(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCLC1LoadHandler)handler).rLoad()); + return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCLC1LoadHandler) handler).rLoad()); } //读取 public R modelRAdd(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCLC1LoadHandler)handler).rAdd()); + return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCLC1LoadHandler) handler).rAdd()); } //删除 public R modelRLDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCLC1DelHandler)handler).rLDel()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCLC1DelHandler) handler).rLDel()); } //删除 public R modelRCDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCLC1DelHandler)handler).rCDel()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCLC1DelHandler) handler).rCDel()); } //列表数据 public R modelRList(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCLC1LoadHandler)handler).rList()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCLC1LoadHandler) handler).rList()); } //列表总记录数及合计栏 public R modelRListTotal(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCLC1LoadHandler)handler).getRTotal()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCLC1LoadHandler) handler).getRTotal()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsDelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsDelHandler.java index 8cc78fe..33637fa 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsDelHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsDelHandler.java @@ -25,17 +25,19 @@ public class LCMsDelHandler extends AbsDelHandler { /** * 列表删除 + * * @return */ - public R lDel(){ + public R lDel() { return del(); } /** * 卡片删除 + * * @return */ - public R cDel(){ + public R cDel() { return del(); } @@ -49,13 +51,13 @@ public class LCMsDelHandler extends AbsDelHandler { if (id <= 0L) throw new BizException("没有收到待删除记录Id(" + id + ")!"); SwMap props = form.getOpts().readMap("config").readMap("props"); //主表 - ModelTable masterTable = ModelTableCache.getInstance().get(props.readLong("masterTable",-1L)); - Assert.notNull(masterTable,"未获取到主表配置"); + ModelTable masterTable = ModelTableCache.getInstance().get(props.readLong("masterTable", -1L)); + Assert.notNull(masterTable, "未获取到主表配置"); //获取子表 - ModelTable subTable = ModelTableCache.getInstance().get(props.readLong("subTable",-1L)); - String subForeignKey = props.readString("subForeignKey","-1"); - Assert.isTrue(subTable!= null && !subForeignKey.equals("-1"),"未获取到子表配置"); + ModelTable subTable = ModelTableCache.getInstance().get(props.readLong("subTable", -1L)); + String subForeignKey = props.readString("subForeignKey", "-1"); + Assert.isTrue(subTable != null && !subForeignKey.equals("-1"), "未获取到子表配置"); // DbEngine engine = DbEngine.getInstance(); @@ -88,7 +90,7 @@ public class LCMsDelHandler extends AbsDelHandler { return R.success(); } - protected void checkDetails(List details){ - details.forEach(item-> EntityHelper.checkExists(item.getModelTable().getId(), item.getEntityId())); + protected void checkDetails(List details) { + details.forEach(item -> EntityHelper.checkExists(item.getModelTable().getId(), item.getEntityId())); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsLoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsLoadHandler.java index c21d40f..b399090 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsLoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsLoadHandler.java @@ -13,6 +13,7 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleHelper; public class LCMsLoadHandler extends AbsLoadHandler { /** * 主表新增 + * * @return */ public R mAdd() { @@ -22,6 +23,7 @@ public class LCMsLoadHandler extends AbsLoadHandler { /** * 主表编辑 + * * @return */ public R mLoad() { @@ -31,35 +33,39 @@ public class LCMsLoadHandler extends AbsLoadHandler { /** * 主表列表加载 + * * @return */ - public R mList(){ + public R mList() { DynRetBean list = doList(LCMsDefine.dsMList); return R.success(list); } /** * 子列表加载 + * * @return */ - public R sList(){ + public R sList() { DynRetBean list = doList(LCMsDefine.dsSList); return R.success(list); } /** * 主列表分页数据 + * * @return */ - public R getMTotal(){ + public R getMTotal() { return doTotal(LCMsDefine.dsMList); } /** * 子列表分页数据 + * * @return */ - public R getSTotal(){ + public R getSTotal() { return doTotal(LCMsDefine.dsSList); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsSaveHandler.java index c711a2e..4754bc9 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsSaveHandler.java @@ -38,8 +38,8 @@ public class LCMsSaveHandler extends AbsSaveHandler { if (data == null) throw new BizException("没有收到待保存的的数据:" + LCMsDefine.dsMCard + "!"); //获取子表关联字段 - String subForeignKey = form.getOpts().readMap("config").readMap("props").readString("subForeignKey","-1"); - Assert.isTrue(!subForeignKey.equals("-1"),"未获取到子表外键配置"); + String subForeignKey = form.getOpts().readMap("config").readMap("props").readString("subForeignKey", "-1"); + Assert.isTrue(!subForeignKey.equals("-1"), "未获取到子表外键配置"); //读取待保存的bean DefaultEntity masterBean = readBeanFromPage(masterDataSet, data.readMap(LCMsDefine.dsMCard).readMap("form")); @@ -49,7 +49,7 @@ public class LCMsSaveHandler extends AbsSaveHandler { } // 读取子表数据 SwMap details = params.readMap("details"); - Assert.notNull(details,"没有收到待保存的明细数据"); + Assert.notNull(details, "没有收到待保存的明细数据"); // ArrayList inserted = new ArrayList<>(); ArrayList updated = new ArrayList<>(); @@ -57,7 +57,7 @@ public class LCMsSaveHandler extends AbsSaveHandler { SwMap rowData = new SwMap(); rowData.putAll(row); DefaultEntity insertBean = readBeanFromPage(subDataSet, rowData); - insertBean.put(subForeignKey,masterBean.getEntityId()); + insertBean.put(subForeignKey, masterBean.getEntityId()); inserted.add(insertBean); }); details.readListMap("updated").forEach(row -> { @@ -76,12 +76,12 @@ public class LCMsSaveHandler extends AbsSaveHandler { public void work() { saveBean(masterBean); ModelTable subTable = ModelTableCache.getInstance().get(subDataSet.masterTable); - Assert.notNull(subTable,"未获取到子表"); + Assert.notNull(subTable, "未获取到子表"); EntityDao dao = DbEngine.getInstance().findDao(subTable.getName()); dao.batchInsertEntity(inserted); dao.batchUpdateEntity(updated); - if (deleted != null){ + if (deleted != null) { dao.deleteEntity(deleted); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsService.java index 224c8d2..86969a0 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/mastersub/LCMsService.java @@ -37,46 +37,46 @@ public class LCMsService extends DynPageService { //保存 public R modelSave(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCMsSaveHandler)handler).save()); + return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCMsSaveHandler) handler).save()); } //读取 public R modelLoad(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCMsLoadHandler)handler).mLoad()); + return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCMsLoadHandler) handler).mLoad()); } //新增 public R modelAdd(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCMsLoadHandler)handler).mAdd()); + return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCMsLoadHandler) handler).mAdd()); } //列表删除 public R modelLDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCMsDelHandler)handler).lDel()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCMsDelHandler) handler).lDel()); } //卡片删除 public R modelCDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCMsDelHandler)handler).cDel()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCMsDelHandler) handler).cDel()); } //主表列表数据 public R modelMList(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCMsLoadHandler)handler).mList()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCMsLoadHandler) handler).mList()); } //主表列表总记录数及合计栏 public R modelMListTotal(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCMsLoadHandler)handler).getMTotal()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCMsLoadHandler) handler).getMTotal()); } //子表列表数据 public R modelSList(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCMsLoadHandler)handler).sList()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCMsLoadHandler) handler).sList()); } //子表列表总记录数及合计栏 public R modelSListTotal(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCMsLoadHandler)handler).getSTotal()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCMsLoadHandler) handler).getSTotal()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalDelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalDelHandler.java index 8c3afbc..b780aba 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalDelHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalDelHandler.java @@ -10,18 +10,20 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.abshandler.AbsDelHandler; public class LCNormalDelHandler extends AbsDelHandler { /** * 通过列表删除 + * * @return */ - public R listDel(){ + public R listDel() { doDel(LCNormalDefine.dsList); return R.success(); } /** * 通过卡片删除 + * * @return */ - public R cardDel(){ + public R cardDel() { doDel(LCNormalDefine.dsCard); return R.success(); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalLoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalLoadHandler.java index a70d868..5e76454 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalLoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalLoadHandler.java @@ -25,6 +25,7 @@ public class LCNormalLoadHandler extends AbsLoadHandler { /** * 列表数据 + * * @return */ public R list() { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalSaveHandler.java index 68c6687..3b48992 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalSaveHandler.java @@ -11,12 +11,11 @@ import cc.smtweb.system.bpm.web.engine.model.listcard.abshandler.AbsSaveHandler; */ public class LCNormalSaveHandler extends AbsSaveHandler { /** - * * @return */ - public R save(){ + public R save() { DefaultEntity bean = doSave(LCNormalDefine.dsCard); - return R.success(ModelUtils.buildRetData(LCNormalDefine.dsCard,bean.getData())); + return R.success(ModelUtils.buildRetData(LCNormalDefine.dsCard, bean.getData())); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalService.java index 66e9cd0..1513364 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/normal/LCNormalService.java @@ -7,7 +7,6 @@ import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; -import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleSaveHandler; /** * @Author:lip @@ -35,38 +34,39 @@ public class LCNormalService extends DynPageService { } return super.createHandler(type); } + //保存 public R modelSave(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCNormalSaveHandler)handler).save()); + return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCNormalSaveHandler) handler).save()); } //列表删除 public R modelLDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCNormalDelHandler)handler).listDel()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCNormalDelHandler) handler).listDel()); } //卡片删除 public R modelCDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCNormalDelHandler)handler).cardDel()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCNormalDelHandler) handler).cardDel()); } //读取 public R modelLoad(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCNormalLoadHandler)handler).load()); + return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCNormalLoadHandler) handler).load()); } //读取 public R modelAdd(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCNormalLoadHandler)handler).add()); + return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCNormalLoadHandler) handler).add()); } //列表数据 public R modelList(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCNormalLoadHandler)handler).list()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCNormalLoadHandler) handler).list()); } //列表总记录数及合计栏 public R modelListTotal(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCNormalLoadHandler)handler).getTotal()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCNormalLoadHandler) handler).getTotal()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleDelHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleDelHandler.java index 9211d7d..4cd0444 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleDelHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleDelHandler.java @@ -60,7 +60,8 @@ public class LCSingleDelHandler extends AbstractDynPageHandler { } //回调:::删除之后 - protected void localDel(long id, ModelTable table) {} + protected void localDel(long id, ModelTable table) { + } //回调:::提交成功后 protected void afterCommit(long id, ModelTable table) { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleLoadHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleLoadHandler.java index ee3e193..b2aa1fa 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleLoadHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleLoadHandler.java @@ -67,6 +67,7 @@ public class LCSingleLoadHandler extends AbstractDynPag /** * 列表数据 + * * @return */ public R list() { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java index 47e4474..151b334 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleSaveHandler.java @@ -74,7 +74,8 @@ public class LCSingleSaveHandler extends AbstractDynPag return R.success(ret); } - protected void afterSave(SwMap ret, T bean) {} + protected void afterSave(SwMap ret, T bean) { + } /** * 从页面获取待保存的bean diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleService.java index 9d25c89..603c298 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/model/listcard/single/LCSingleService.java @@ -4,9 +4,8 @@ import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.framework.core.mvc.service.*; +import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.framework.core.session.UserSession; -import cc.smtweb.system.bpm.web.design.form.*; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; /** @@ -50,31 +49,31 @@ public class LCSingleService extends DynPageService { //保存 public R modelSave(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCSingleSaveHandler)handler).save()); + return pageHandler(params, us, TYPE_MODEL_SAVE, handler -> ((LCSingleSaveHandler) handler).save()); } //读取 public R modelLoad(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCSingleLoadHandler)handler).load()); + return pageHandler(params, us, TYPE_MODEL_LOAD, handler -> ((LCSingleLoadHandler) handler).load()); } //读取 public R modelAdd(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCSingleLoadHandler)handler).add()); + return pageHandler(params, us, TYPE_MODEL_ADD, handler -> ((LCSingleLoadHandler) handler).add()); } //删除 public R modelDel(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCSingleDelHandler)handler).del()); + return pageHandler(params, us, TYPE_MODEL_DEL, handler -> ((LCSingleDelHandler) handler).del()); } //列表数据 public R modelList(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCSingleLoadHandler)handler).list()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCSingleLoadHandler) handler).list()); } //列表总记录数及合计栏 public R modelListTotal(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCSingleLoadHandler)handler).getTotal()); + return pageHandler(params, us, TYPE_MODEL_LIST, handler -> ((LCSingleLoadHandler) handler).getTotal()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java index e7bc3c7..5e6cb6e 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java @@ -13,7 +13,6 @@ import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.system.bpm.web.sys.user.party.Party; import cc.smtweb.system.bpm.web.sys.user.party.PartyCache; import cc.smtweb.system.bpm.web.sys.user.user.User; -import cc.smtweb.system.bpm.web.sys.user.user.UserCache; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; @@ -54,9 +53,9 @@ public class AuthService { userSession = new UserSession(1); // user=new User(); // return new UserSession(1); - }else{ - user= LoginHelper.login(loginPO); - userSession=new UserSession(user.getId()); + } else { + user = LoginHelper.login(loginPO); + userSession = new UserSession(user.getId()); } } catch (BizException e) { data.put("isOk", false); @@ -87,7 +86,7 @@ public class AuthService { loginAckVO.setAvatar(""); loginAckVO.setDesc(user.getSign()); loginAckVO.setToken(sessionManager.login(userSession)); - loginAckVO.setUserLevel(user.getLevel()+""); + loginAckVO.setUserLevel(user.getLevel() + ""); data.put("user", loginAckVO); data.put("token", loginAckVO.getToken()); data.put("isOk", true); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java index 3895689..945ce06 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java @@ -1,6 +1,5 @@ package cc.smtweb.system.bpm.web.login; -import cc.smtweb.framework.core.annotation.SwParam; import cc.smtweb.framework.core.cache.redis.RedisManager; import cc.smtweb.framework.core.common.SwConsts; import cc.smtweb.framework.core.common.SwEnum; @@ -35,7 +34,6 @@ public class LoginHelper { } - if (StringUtils.isBlank(loginPO.getPassword())) { throw new BizException("密码不能为空"); } @@ -51,10 +49,10 @@ public class LoginHelper { //查询数据库 List userObjList = DbEngine.getInstance().findDao(User.ENTITY_NAME).queryWhere(" sur_code=? or sur_tel=?", loginPO.getUsername(), loginPO.getUsername()); // User user = UserCache.getInstance().getByKey(loginPO.getUsername()); - if(null == userObjList || userObjList.size()<=0){ + if (null == userObjList || userObjList.size() <= 0) { throw new BizException("账号或者密码出错"); } - User user =userObjList.get(0); + User user = userObjList.get(0); // if (user == null) { // throw new BizException("账号或者密码出错"); // } @@ -69,7 +67,8 @@ public class LoginHelper { return user; } - public static UserSession simpleLogin(long useId){ + + public static UserSession simpleLogin(long useId) { User user = UserCache.getInstance().get(useId); if (user == null) { throw new BizException("账号或者密码出错"); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MenuPO.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MenuPO.java index 933b334..0149375 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MenuPO.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MenuPO.java @@ -9,10 +9,10 @@ import java.io.Serializable; @Data @SwTable("sw_user.sys_menu") public class MenuPO implements Serializable { - @SwColumn(type={SwColumn.Type.ID}) + @SwColumn(type = {SwColumn.Type.ID}) private Long menuId; - @SwColumn(type={SwColumn.Type.PARENT_ID}) + @SwColumn(type = {SwColumn.Type.PARENT_ID}) private Long menuParentId; private String menuName; @@ -24,6 +24,6 @@ public class MenuPO implements Serializable { private String menuUrl; - @SwColumn(type={SwColumn.Type.ORDER}) + @SwColumn(type = {SwColumn.Type.ORDER}) private Integer menuSort; } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/UserPO.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/UserPO.java index af5c679..6e89164 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/UserPO.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/UserPO.java @@ -9,7 +9,7 @@ import java.io.Serializable; @Data @SwTable("sw_user.sys_user") public class UserPO implements Serializable { - @SwColumn(type={SwColumn.Type.ID}) + @SwColumn(type = {SwColumn.Type.ID}) private Long userId; private String userNickCode; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/attach/AttachInfo.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/attach/AttachInfo.java index 421d27a..b5fff98 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/attach/AttachInfo.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/attach/AttachInfo.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.base.attach; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,112 +15,170 @@ public class AttachInfo extends DefaultEntity { super(ENTITY_NAME); } - /** 附件ID */ + /** + * 附件ID + */ public long getId() { return getLong("attach_id"); } - /** 附件ID */ + /** + * 附件ID + */ public void setId(long attach_id) { put("attach_id", attach_id); } - /** 附件名称 */ + + /** + * 附件名称 + */ public String getName() { return getStr("attach_name"); } - /** 附件名称 */ + /** + * 附件名称 + */ public void setName(String attach_name) { put("attach_name", attach_name); } - /** 附件文件后缀 */ + + /** + * 附件文件后缀 + */ public String getSuffix() { return getStr("attach_suffix"); } - /** 附件文件后缀 */ + /** + * 附件文件后缀 + */ public void setSuffix(String attach_suffix) { put("attach_suffix", attach_suffix); } - /** 拥有者id */ + + /** + * 拥有者id + */ public long getOwnerId() { return getLong("attach_owner_id"); } - /** 拥有者id */ + /** + * 拥有者id + */ public void setOwnerId(long attach_owner_id) { put("attach_owner_id", attach_owner_id); } - /** 远程路径 */ + + /** + * 远程路径 + */ public String getPath() { return getStr("attach_path"); } - /** 远程路径 */ + /** + * 远程路径 + */ public void setPath(String attach_path) { put("attach_path", attach_path); } - /** 附件类别 */ + + /** + * 附件类别 + */ public String getType() { return getStr("attach_type"); } - /** 附件类别 */ + /** + * 附件类别 + */ public void setType(String attach_type) { put("attach_type", attach_type); } - /** 附件大小 */ + + /** + * 附件大小 + */ public long getSize() { return getLong("attach_size"); } - /** 附件大小 */ + /** + * 附件大小 + */ public void setSize(long attach_size) { put("attach_size", attach_size); } - /** 是否临时文件 */ + + /** + * 是否临时文件 + */ public int getIsTemp() { return getInt("attach_is_temp"); } - /** 是否临时文件 */ + /** + * 是否临时文件 + */ public void setIsTemp(int attach_is_temp) { put("attach_is_temp", attach_is_temp); } - /** 上传单位 */ + + /** + * 上传单位 + */ public long getPartyId() { return getLong("attach_party_id"); } - /** 上传单位 */ + /** + * 上传单位 + */ public void setPartyId(long attach_party_id) { put("attach_party_id", attach_party_id); } - /** 上传时间 */ + + /** + * 上传时间 + */ public long getTime() { return getLong("attach_time"); } - /** 上传时间 */ + /** + * 上传时间 + */ public void setTime(long attach_time) { put("attach_time", attach_time); } - /** 上传人员 */ + + /** + * 上传人员 + */ public long getUserId() { return getLong("attach_user_id"); } - /** 上传人员 */ + /** + * 上传人员 + */ public void setUserId(long attach_user_id) { put("attach_user_id", attach_user_id); } - /** 下载次数 */ + /** + * 下载次数 + */ public int getCount() { return getInt("attach_count"); } - /** 下载次数 */ + /** + * 下载次数 + */ public void setCount(int attach_count) { put("attach_count", attach_count); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/attachFolder/AttachFolder.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/attachFolder/AttachFolder.java index 4fcb89e..7a6e64d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/attachFolder/AttachFolder.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/attachFolder/AttachFolder.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.base.attachFolder; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,48 +15,72 @@ public class AttachFolder extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("folder_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long folder_id) { put("folder_id", folder_id); } - /** 远程路径 */ + + /** + * 远程路径 + */ public String getPath() { return getStr("folder_path"); } - /** 远程路径 */ + /** + * 远程路径 + */ public void setPath(String folder_path) { put("folder_path", folder_path); } - /** 年月目录 */ + + /** + * 年月目录 + */ public String getPeriod() { return getStr("folder_period"); } - /** 年月目录 */ + /** + * 年月目录 + */ public void setPeriod(String folder_period) { put("folder_period", folder_period); } - /** 最大序号 */ + + /** + * 最大序号 + */ public int getMaxSeq() { return getInt("folder_max_seq"); } - /** 最大序号 */ + /** + * 最大序号 + */ public void setMaxSeq(int folder_max_seq) { put("folder_max_seq", folder_max_seq); } - /** 文件个数 */ + + /** + * 文件个数 + */ public long getFileCount() { return getLong("folder_file_count"); } - /** 文件个数 */ + /** + * 文件个数 + */ public void setFileCount(long folder_file_count) { put("folder_file_count", folder_file_count); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billFlow/BillFlow.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billFlow/BillFlow.java index a0c2c3c..e782ebd 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billFlow/BillFlow.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billFlow/BillFlow.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.base.billFlow; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,48 +15,72 @@ public class BillFlow extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sbfl_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sbfl_id) { put("sbfl_id", sbfl_id); } - /** 用户组 */ + + /** + * 用户组 + */ public long getUserGroup() { return getLong("sbfl_user_group"); } - /** 用户组 */ + /** + * 用户组 + */ public void setUserGroup(long sbfl_user_group) { put("sbfl_user_group", sbfl_user_group); } - /** 单据类型 */ + + /** + * 单据类型 + */ public long getBillType() { return getLong("sbfl_bill_type"); } - /** 单据类型 */ + /** + * 单据类型 + */ public void setBillType(long sbfl_bill_type) { put("sbfl_bill_type", sbfl_bill_type); } - /** 流程 */ + + /** + * 流程 + */ public long getProc() { return getLong("sbfl_proc"); } - /** 流程 */ + /** + * 流程 + */ public void setProc(long sbfl_proc) { put("sbfl_proc", sbfl_proc); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("sbfl_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String sbfl_remark) { put("sbfl_remark", sbfl_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billFlow/BillFlowCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billFlow/BillFlowCache.java index 382ac9e..d156f8f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billFlow/BillFlowCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billFlow/BillFlowCache.java @@ -4,9 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; import java.util.Set; /** diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillType.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillType.java index daf1a14..d324e88 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillType.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillType.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.base.billType; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,39 +15,58 @@ public class BillType extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sbtp_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sbtp_id) { put("sbtp_id", sbtp_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("sbtp_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String sbtp_code) { put("sbtp_code", sbtp_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("sbtp_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String sbtp_name) { put("sbtp_name", sbtp_name); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("sbtp_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String sbtp_remark) { put("sbtp_remark", sbtp_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeCache.java index ff597fa..36e77e4 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeCache.java @@ -29,6 +29,6 @@ public class BillTypeCache extends AbstractEntityCache { public String getName(long id) { BillType bean = get(id); - return bean != null ? bean.getName() : String.valueOf(id); + return bean != null ? bean.getName(): String.valueOf(id); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeSaveHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeSaveHandler.java index 89a5a68..1aa545a 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeSaveHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeSaveHandler.java @@ -1,6 +1,5 @@ package cc.smtweb.system.bpm.web.sys.base.billType; -import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleSaveHandler; import org.apache.commons.lang3.StringUtils; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeService.java index c08d3b0..d74b3d7 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/billType/BillTypeService.java @@ -1,13 +1,8 @@ package cc.smtweb.system.bpm.web.sys.base.billType; -import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; -import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.framework.core.mvc.service.DefaultComboHandler; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; -import cc.smtweb.framework.core.session.UserSession; +import cc.smtweb.framework.core.mvc.service.DefaultComboHandler; import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleSaveHandler; import cc.smtweb.system.bpm.web.engine.model.listcard.single.LCSingleService; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/Dict.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/Dict.java index cfd6e0d..4e87353 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/Dict.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/Dict.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.base.dict; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,48 +15,72 @@ public class Dict extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sdc_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sdc_id) { put("sdc_id", sdc_id); } - /** 类别 */ + + /** + * 类别 + */ public long getType() { return getLong("sdc_type"); } - /** 类别 */ + /** + * 类别 + */ public void setType(long sdc_type) { put("sdc_type", sdc_type); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("sdc_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String sdc_code) { put("sdc_code", sdc_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("sdc_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String sdc_name) { put("sdc_name", sdc_name); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("sdc_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String sdc_remark) { put("sdc_remark", sdc_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictCache.java index 2299750..f0534d0 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictCache.java @@ -4,11 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - /** * Created by 1 at 2022-07-27 19:59:05 * 实体【[数据字典](SYS_DICT)】的缓存类 @@ -34,6 +29,6 @@ public class DictCache extends AbstractEntityCache { public final String getName(long id) { Dict bean = get(id); - return bean != null ? bean.getName() : String.valueOf(id); + return bean != null ? bean.getName(): String.valueOf(id); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictService.java index 24f9225..15ab778 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictService.java @@ -3,7 +3,6 @@ package cc.smtweb.system.bpm.web.sys.base.dict; import cc.smtweb.framework.core.annotation.SwService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; -import cc.smtweb.system.bpm.web.sys.user.area.AreaHandler; /** * Created by 1 at 2022-07-28 09:23:54 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictType.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictType.java index 835bdf1..6becf4c 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictType.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictType.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.base.dict; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,48 +15,72 @@ public class DictType extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sdct_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sdct_id) { put("sdct_id", sdct_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("sdct_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String sdct_code) { put("sdct_code", sdct_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("sdct_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String sdct_name) { put("sdct_name", sdct_name); } - /** 归属项目 */ + + /** + * 归属项目 + */ public long getPrjId() { return getLong("sdct_prj_id"); } - /** 归属项目 */ + /** + * 归属项目 + */ public void setPrjId(long sdct_prj_id) { put("sdct_prj_id", sdct_prj_id); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("sdct_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String sdct_remark) { put("sdct_remark", sdct_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictTypeCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictTypeCache.java index 00958eb..5d250d4 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictTypeCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/base/dict/DictTypeCache.java @@ -4,11 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - /** * Created by 1 at 2022-07-27 19:59:05 * 实体【[字典类别](SYS_DICT_TYPE)】的缓存类 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java index 2574e11..9ed8cf9 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/EnumComboService.java @@ -40,18 +40,18 @@ public class EnumComboService extends DynPageService { if (StringUtil.isEmpty(cls)) return SwListData.create(new ArrayList(), 0); List list = new ArrayList<>(); try { - Class tempClass ; + Class tempClass; Class wantClass = null; try { tempClass = Class.forName(cls); wantClass = tempClass; - }catch (Exception e){ + } catch (Exception e) { // e.printStackTrace(); // int lIndex = cls.lastIndexOf("."); if (lIndex > 0) { String outClass = cls.substring(0, lIndex); - String innerClass = outClass + "$" + cls.substring(lIndex+1); + String innerClass = outClass + "$" + cls.substring(lIndex + 1); tempClass = Class.forName(outClass); Class[] declaredClasses = tempClass.getDeclaredClasses(); for (Class declaredClass : declaredClasses) { @@ -62,8 +62,8 @@ public class EnumComboService extends DynPageService { } } } - Assert.notNull(wantClass,"classNotFound"); - AbstractEnum e ; + Assert.notNull(wantClass, "classNotFound"); + AbstractEnum e; try { e = (AbstractEnum) wantClass.getDeclaredField("inst").get(null); } catch (Exception e1) { diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/FieldComboService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/FieldComboService.java index 03b4db1..82b2582 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/FieldComboService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/dev/FieldComboService.java @@ -1,12 +1,8 @@ package cc.smtweb.system.bpm.web.sys.dev; -import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; -import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; -import cc.smtweb.framework.core.session.UserSession; +import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; /** * Created by 1 at 2022-08-03 14:48:43 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/Area.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/Area.java index 484fbd3..4ef89ae 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/Area.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/Area.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.area; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,93 +15,142 @@ public class Area extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("ar_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long ar_id) { put("ar_id", ar_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("ar_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String ar_code) { put("ar_code", ar_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("ar_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String ar_name) { put("ar_name", ar_name); } - /** 父ID */ + + /** + * 父ID + */ public long getParentId() { return getLong("ar_parent_id"); } - /** 父ID */ + /** + * 父ID + */ public void setParentId(long ar_parent_id) { put("ar_parent_id", ar_parent_id); } - /** 级次码 */ + + /** + * 级次码 + */ public String getLevelCode() { return getStr("ar_level_code"); } - /** 级次码 */ + /** + * 级次码 + */ public void setLevelCode(String ar_level_code) { put("ar_level_code", ar_level_code); } - /** 全称 */ + + /** + * 全称 + */ public String getFullName() { return getStr("ar_full_name"); } - /** 全称 */ + /** + * 全称 + */ public void setFullName(String ar_full_name) { put("ar_full_name", ar_full_name); } - /** 级次 */ + + /** + * 级次 + */ public int getType() { return getInt("ar_type"); } - /** 级次 */ + /** + * 级次 + */ public void setType(int ar_type) { put("ar_type", ar_type); } - /** 状态 */ + + /** + * 状态 + */ public boolean isStatu() { return getBool("ar_statu"); } - /** 状态 */ + /** + * 状态 + */ public void set(boolean ar_statu) { setBool("ar_statu", ar_statu); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("ar_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String ar_remark) { put("ar_remark", ar_remark); } - /** 排序码 */ + + /** + * 排序码 + */ public int getSeq() { return getInt("ar_seq"); } - /** 排序码 */ + /** + * 排序码 + */ public void setSeq(int ar_seq) { put("ar_seq", ar_seq); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaCache.java index 60b05d2..caa657d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaCache.java @@ -4,9 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; import java.util.Set; /** @@ -35,6 +32,7 @@ public class AreaCache extends AbstractEntityCache { public final Area getByCode(String key) { return getByKey(mk_code, key); } + //缓存key:按父ID public final Set getByPr(String key) { return getListByKey(mk_pr, key); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaService.java index 7d724b7..dc26f08 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/area/AreaService.java @@ -1,15 +1,8 @@ package cc.smtweb.system.bpm.web.sys.user.area; -import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; -import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageDelHandler; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageSaveHandler; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; -import cc.smtweb.framework.core.session.UserSession; +import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; /** * Created by 1 at 2022-06-17 07:58:14 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefine.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefine.java index 8ca9a64..d6c851d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefine.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefine.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.dataRight; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,39 +15,58 @@ public class DataRightDefine extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sdrd_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sdrd_id) { put("sdrd_id", sdrd_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("sdrd_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String sdrd_code) { put("sdrd_code", sdrd_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("sdrd_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String sdrd_name) { put("sdrd_name", sdrd_name); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("sdrd_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String sdrd_remark) { put("sdrd_remark", sdrd_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefineCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefineCache.java index 1b6b633..6798c4d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefineCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightDefineCache.java @@ -4,11 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - /** * Created by 1 at 2022-08-03 16:27:55 * 实体【[数据权限定义](SYS_DATA_RIGHT_DEFINE)】的缓存类 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightService.java index 70bc05e..cdb20ce 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRight/DataRightService.java @@ -1,12 +1,8 @@ package cc.smtweb.system.bpm.web.sys.user.dataRight; -import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; -import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; -import cc.smtweb.framework.core.session.UserSession; +import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; /** * Created by 1 at 2022-08-03 16:27:55 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroup.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroup.java index 5e9ed48..1624e97 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroup.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroup.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.dataRightGroup; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,57 +15,86 @@ public class DataRightGroup extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sdrg_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sdrg_id) { put("sdrg_id", sdrg_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("sdrg_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String sdrg_code) { put("sdrg_code", sdrg_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("sdrg_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String sdrg_name) { put("sdrg_name", sdrg_name); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("sdrg_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String sdrg_remark) { put("sdrg_remark", sdrg_remark); } - /** 数据权限详细 */ + + /** + * 数据权限详细 + */ public String getContent() { return getStr("sdrg_content"); } - /** 数据权限详细 */ + /** + * 数据权限详细 + */ public void setContent(String sdrg_content) { put("sdrg_content", sdrg_content); } - /** 数据权限定义 */ + + /** + * 数据权限定义 + */ public long getSdrdId() { return getLong("sdrg_sdrd_id"); } - /** 数据权限定义 */ + /** + * 数据权限定义 + */ public void setSdrdId(long sdrg_sdrd_id) { put("sdrg_sdrd_id", sdrg_sdrd_id); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupCache.java index 35e2467..afbad78 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupCache.java @@ -4,11 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - /** * Created by 1 at 2022-08-04 17:45:35 * 实体【[数据权限组](SYS_DATA_RIGHT_GROUP)】的缓存类 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupHandler.java index f5180b6..82bc9fe 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dataRightGroup/DataRightGroupHandler.java @@ -7,8 +7,6 @@ import cc.smtweb.system.bpm.web.design.form.define.PageDataset; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageSaveHandler; -import java.util.ArrayList; -import java.util.List; import java.util.Map; /** diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dept/Dept.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dept/Dept.java index 5e94c25..324259b 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dept/Dept.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dept/Dept.java @@ -15,66 +15,100 @@ public class Dept extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("dpt_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long dpt_id) { put("dpt_id", dpt_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("dpt_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String dpt_code) { put("dpt_code", dpt_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("dpt_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String dpt_name) { put("dpt_name", dpt_name); } - /** 部门性质 */ + + /** + * 部门性质 + */ public long getType() { return getLong("dpt_type"); } - /** 部门性质 */ + /** + * 部门性质 + */ public void setType(long dpt_type) { put("dpt_type", dpt_type); } - /** 所属机构 */ + + /** + * 所属机构 + */ public long getPtId() { return getLong("dpt_pt_id"); } - /** 所属机构 */ + /** + * 所属机构 + */ public void setPtId(long dpt_pt_id) { put("dpt_pt_id", dpt_pt_id); } - /** 状态 */ + + /** + * 状态 + */ public int getStatu() { return getInt("dpt_statu"); } - /** 状态 */ + /** + * 状态 + */ public void setStatu(int dpt_statu) { put("dpt_statu", dpt_statu); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("dpt_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String dpt_remark) { put("dpt_remark", dpt_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dept/DeptCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dept/DeptCache.java index 5532068..a8221d9 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dept/DeptCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/dept/DeptCache.java @@ -32,6 +32,7 @@ public class DeptCache extends AbstractEntityCache { public final Dept getByCode(String key) { return getByKey(mk_code, key); } + //缓存key:按机构 public final Set getByP(String key) { return getListByKey(mk_p, key); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuNode.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuNode.java index 6119c54..4d2bfb4 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuNode.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuNode.java @@ -74,6 +74,6 @@ public class MenuNode extends DefaultEntity { public List getChildren() { Object obj = get("children"); - return obj == null ? new ArrayList<>() : (List) obj; + return obj == null ? new ArrayList<>(): (List) obj; } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuService.java index 710aa16..1abbbf4 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menu/MenuService.java @@ -1,12 +1,8 @@ package cc.smtweb.system.bpm.web.sys.user.menu; -import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; -import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; -import cc.smtweb.framework.core.session.UserSession; +import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; /** * Created by 1 at 2022-08-03 17:21:52 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlan.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlan.java index 0658662..0e331b0 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlan.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlan.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.menuPlan; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,39 +15,58 @@ public class MenuPlan extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("smp_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long smp_id) { put("smp_id", smp_id); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("smp_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String smp_name) { put("smp_name", smp_name); } - /** 详细 */ + + /** + * 详细 + */ public String getContent() { return getStr("smp_content"); } - /** 详细 */ + /** + * 详细 + */ public void setContent(String smp_content) { put("smp_content", smp_content); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("smp_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String smp_remark) { put("smp_remark", smp_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java index b02eb27..d3dd293 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java @@ -55,10 +55,10 @@ public class MenuPlanContent { // 判断是否修改了父节点 MenuPlanItem oldParent = findParentById(item.getId()); MenuPlanItem newParent = findById(parentId); - boolean changeParent = (oldParent == null ? -1 : oldParent.getId()) != parentId; + boolean changeParent = (oldParent == null ? -1: oldParent.getId()) != parentId; if (changeParent) { // 改了父节点 父节点的children需要移除,新的父节点需要添加 - removeById(item.getId(), oldParent == null ? list : oldParent.getChildren()); + removeById(item.getId(), oldParent == null ? list: oldParent.getChildren()); if (newParent == null) { addItem(item, list); } else { @@ -92,6 +92,7 @@ public class MenuPlanContent { } } } + // 转换成字符串 public String toContentStr() { return JsonUtil.encodeString(list); @@ -119,7 +120,7 @@ public class MenuPlanContent { return list; } MenuPlanItem parent = findById(parentId); - return parent == null ? new ArrayList<>() : parent.getChildren(); + return parent == null ? new ArrayList<>(): parent.getChildren(); } private MenuPlanItem findById(long id, List itemList) { @@ -132,9 +133,9 @@ public class MenuPlanContent { } } for (MenuPlanItem item : itemList) { - if(!CommUtil.isEmpty(item.getChildren())){ - MenuPlanItem rt = findById(id,item.getChildren()); - if(rt!=null){ + if (!CommUtil.isEmpty(item.getChildren())) { + MenuPlanItem rt = findById(id, item.getChildren()); + if (rt != null) { return rt; } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanHandler.java index ac7e8b3..d05d3de 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanHandler.java @@ -141,8 +141,8 @@ public class MenuPlanHandler { for (MenuPlanItem bean : children) { SwMap map = bean.getData(); map.put("plan_id", plan_id); - map.put("type", bean.getMenu() > 0 ? 1 : 0); - map.put("type_text", bean.getMenu() > 0 ? "菜单" : "目录"); + map.put("type", bean.getMenu() > 0 ? 1: 0); + map.put("type_text", bean.getMenu() > 0 ? "菜单": "目录"); list.add(map); } } @@ -187,14 +187,14 @@ public class MenuPlanHandler { MenuPlanItem parent; if (menuPlanItem == null) { return new SwMap(); - }else { + } else { parent = menuPlanContent.findParentById(menuPlanItem.getId()); } SwMap r = new SwMap(); r.putAll(menuPlanItem.getData()); r.put("plan_id", plan_id); - r.put("type", menuPlanItem.getMenu() > 0 ? 1 : 0); - r.put("parent_id",parent == null ? -1 : parent.getId()); + r.put("type", menuPlanItem.getMenu() > 0 ? 1: 0); + r.put("parent_id", parent == null ? -1: parent.getId()); return r; } return super.loadData(filter, pageDataSet); @@ -211,7 +211,7 @@ public class MenuPlanHandler { menuPlanContent = new MenuPlanContent(null); } MenuPlan menuPlan = MenuPlanCache.getInstance().get(plan_id); - menuPlanContent = new MenuPlanContent(menuPlan == null ? null : menuPlan.getContent()); + menuPlanContent = new MenuPlanContent(menuPlan == null ? null: menuPlan.getContent()); } @Override diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java index 8df9153..e9d275f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java @@ -3,7 +3,6 @@ package cc.smtweb.system.bpm.web.sys.user.menuPlan; import cc.smtweb.framework.core.db.impl.BaseBean; import java.util.Collections; -import java.util.Comparator; import java.util.List; /** diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanService.java index 4001299..3bc2bfe 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanService.java @@ -4,9 +4,9 @@ import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.annotation.SwService; import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwMap; -import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.framework.core.session.UserSession; +import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; /** * Created by 1 at 2022-08-01 18:08:28 @@ -15,9 +15,10 @@ import cc.smtweb.framework.core.session.UserSession; @SwService public class MenuPlanService extends DynPageService { public final static String TYPE_CUST = "cust"; + @Override protected AbstractHandler createHandler(String type) { - switch (type){ + switch (type) { case TYPE_CUST: return new MenuPlanHandler.MenuCustHandler(); case TYPE_LOAD: @@ -28,10 +29,11 @@ public class MenuPlanService extends DynPageService { //保存方案明细 public R savePlanItem(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_CUST, handler -> ((MenuPlanHandler.MenuCustHandler)handler).savePlanItem()); + return pageHandler(params, us, TYPE_CUST, handler -> ((MenuPlanHandler.MenuCustHandler) handler).savePlanItem()); } + // 删除方案明细 public R delPlanItem(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_CUST, handler -> ((MenuPlanHandler.MenuCustHandler)handler).delPlanItem()); + return pageHandler(params, us, TYPE_CUST, handler -> ((MenuPlanHandler.MenuCustHandler) handler).delPlanItem()); } } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/party/Party.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/party/Party.java index 0b81344..9bb0ee4 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/party/Party.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/party/Party.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.party; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,138 +15,212 @@ public class Party extends DefaultEntity { super(ENTITY_NAME); } - /** ID */ + /** + * ID + */ public long getId() { return getLong("pt_id"); } - /** ID */ + /** + * ID + */ public void setId(long pt_id) { put("pt_id", pt_id); } - /** 父ID */ + + /** + * 父ID + */ public long getParentId() { return getLong("pt_parent_id"); } - /** 父ID */ + /** + * 父ID + */ public void setParentId(long pt_parent_id) { put("pt_parent_id", pt_parent_id); } - /** 级次码 */ + + /** + * 级次码 + */ public String getLevelCode() { return getStr("pt_level_code"); } - /** 级次码 */ + /** + * 级次码 + */ public void setLevelCode(String pt_level_code) { put("pt_level_code", pt_level_code); } - /** 行政区划 */ + + /** + * 行政区划 + */ public long getAreaId() { return getLong("pt_area_id"); } - /** 行政区划 */ + /** + * 行政区划 + */ public void setAreaId(long pt_area_id) { put("pt_area_id", pt_area_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("pt_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String pt_code) { put("pt_code", pt_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("pt_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String pt_name) { put("pt_name", pt_name); } - /** 机构性质 */ + + /** + * 机构性质 + */ public long getType() { return getLong("pt_type"); } - /** 机构性质 */ + /** + * 机构性质 + */ public void setType(long pt_type) { put("pt_type", pt_type); } - /** 级次 */ + + /** + * 级次 + */ public int getLevel() { return getInt("pt_level"); } - /** 级次 */ + /** + * 级次 + */ public void setLevel(int pt_level) { put("pt_level", pt_level); } - /** 状态 */ + + /** + * 状态 + */ public boolean isStatu() { return getBool("pt_statu"); } - /** 状态 */ + /** + * 状态 + */ public void set(boolean pt_statu) { setBool("pt_statu", pt_statu); } - /** 联系人 */ + + /** + * 联系人 + */ public String getLinker() { return getStr("pt_linker"); } - /** 联系人 */ + /** + * 联系人 + */ public void setLinker(String pt_linker) { put("pt_linker", pt_linker); } - /** 联系方式 */ + + /** + * 联系方式 + */ public String getTel() { return getStr("pt_tel"); } - /** 联系方式 */ + /** + * 联系方式 + */ public void setTel(String pt_tel) { put("pt_tel", pt_tel); } - /** 地址 */ + + /** + * 地址 + */ public String getAddr() { return getStr("pt_addr"); } - /** 地址 */ + /** + * 地址 + */ public void setAddr(String pt_addr) { put("pt_addr", pt_addr); } - /** 经度 */ + + /** + * 经度 + */ public long getLon() { return getLong("pt_lon"); } - /** 经度 */ + /** + * 经度 + */ public void setLon(long pt_lon) { put("pt_lon", pt_lon); } - /** 维度 */ + + /** + * 维度 + */ public long getLat() { return getLong("pt_lat"); } - /** 维度 */ + /** + * 维度 + */ public void setLat(long pt_lat) { put("pt_lat", pt_lat); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("pt_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String pt_remark) { put("pt_remark", pt_remark); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/Role.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/Role.java index 2779f63..aaca925 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/Role.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/Role.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.role; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,75 +15,114 @@ public class Role extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("srl_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long srl_id) { put("srl_id", srl_id); } - /** 类别 */ + + /** + * 类别 + */ public long getType() { return getLong("srl_type"); } - /** 类别 */ + /** + * 类别 + */ public void setType(long srl_type) { put("srl_type", srl_type); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("srl_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String srl_code) { put("srl_code", srl_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("srl_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String srl_name) { put("srl_name", srl_name); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("srl_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String srl_remark) { put("srl_remark", srl_remark); } - /** 等级 */ + + /** + * 等级 + */ public long getLevel() { return getLong("srl_level"); } - /** 等级 */ + /** + * 等级 + */ public void setLevel(long srl_level) { put("srl_level", srl_level); } - /** 菜单方案 */ + + /** + * 菜单方案 + */ public long getSmpId() { return getLong("srl_smp_id"); } - /** 菜单方案 */ + /** + * 菜单方案 + */ public void setSmpId(long srl_smp_id) { put("srl_smp_id", srl_smp_id); } - /** 权限详细 */ + + /** + * 权限详细 + */ public String getPrivilege() { return getStr("srl_privilege"); } - /** 权限详细 */ + /** + * 权限详细 + */ public void setPrivilege(String srl_privilege) { put("srl_privilege", srl_privilege); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java index f85ff7d..6b4b16d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHandler.java @@ -6,7 +6,6 @@ import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.mvc.service.SwListData; -import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.framework.core.util.StringUtil; import cc.smtweb.system.bpm.web.design.form.ModelForm; import cc.smtweb.system.bpm.web.design.form.ModelFormCache; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/User.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/User.java index 8a45787..05acd27 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/User.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/User.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.user; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,139 +15,212 @@ public class User extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sur_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sur_id) { put("sur_id", sur_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("sur_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String sur_code) { put("sur_code", sur_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("sur_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String sur_name) { put("sur_name", sur_name); } - /** 登录帐号 */ + + /** + * 登录帐号 + */ public String getNicky() { return getStr("sur_nicky"); } - /** 登录帐号 */ + /** + * 登录帐号 + */ public void setNicky(String sur_nicky) { put("sur_nicky", sur_nicky); } - /** 用户等级 */ + + /** + * 用户等级 + */ public long getLevel() { return getLong("sur_level"); } - /** 用户等级 */ + /** + * 用户等级 + */ public void setLevel(long sur_level) { put("sur_level", sur_level); } - /** 状态 */ + + /** + * 状态 + */ public int getStatu() { return getInt("sur_statu"); } - /** 状态 */ + /** + * 状态 + */ public void setStatu(int sur_statu) { put("sur_statu", sur_statu); } - /** 手机号 */ + + /** + * 手机号 + */ public String getTel() { return getStr("sur_tel"); } - /** 手机号 */ + /** + * 手机号 + */ public void setTel(String sur_tel) { put("sur_tel", sur_tel); } - /** 邮箱 */ + + /** + * 邮箱 + */ public String getEmail() { return getStr("sur_email"); } - /** 邮箱 */ + /** + * 邮箱 + */ public void setEmail(String sur_email) { put("sur_email", sur_email); } - /** 令牌 */ + + /** + * 令牌 + */ public long getOpt() { return getLong("sur_opt"); } - /** 令牌 */ + /** + * 令牌 + */ public void setOpt(long sur_opt) { put("sur_opt", sur_opt); } - /** 密码 */ + + /** + * 密码 + */ public String getPwd() { return getStr("sur_pwd"); } - /** 密码 */ + /** + * 密码 + */ public void setPwd(String sur_pwd) { put("sur_pwd", sur_pwd); } - /** 头像 */ + + /** + * 头像 + */ public long getHead() { return getLong("sur_head"); } - /** 头像 */ + /** + * 头像 + */ public void setHead(long sur_head) { put("sur_head", sur_head); } - /** 个性签名 */ + + /** + * 个性签名 + */ public String getSign() { return getStr("sur_sign"); } - /** 个性签名 */ + /** + * 个性签名 + */ public void setSign(String sur_sign) { put("sur_sign", sur_sign); } - /** 密码等级 */ + + /** + * 密码等级 + */ public int getPwdLevel() { return getInt("sur_pwd_level"); } - /** 密码等级 */ + /** + * 密码等级 + */ public void setPwdLevel(int sur_pwd_level) { put("sur_pwd_level", sur_pwd_level); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("sur_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String sur_remark) { put("sur_remark", sur_remark); } - /** 创建时间 */ + /** + * 创建时间 + */ public long getCreate() { return getLong("sur_create"); } - /** 创建时间 */ + /** + * 创建时间 + */ public void setCreate(long sur_create) { put("sur_create", sur_create); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserParty.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserParty.java index 18c407a..b6fc138 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserParty.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserParty.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.user; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,39 +15,58 @@ public class UserParty extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sup_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sup_id) { put("sup_id", sup_id); } - /** 机构 */ + + /** + * 机构 + */ public long getPartyId() { return getLong("sup_party_id"); } - /** 机构 */ + /** + * 机构 + */ public void setPartyId(long sup_party_id) { put("sup_party_id", sup_party_id); } - /** 部门 */ + + /** + * 部门 + */ public long getDeptId() { return getLong("sup_dept_id"); } - /** 部门 */ + /** + * 部门 + */ public void setDeptId(long sup_dept_id) { put("sup_dept_id", sup_dept_id); } - /** 用户 */ + + /** + * 用户 + */ public long getUserId() { return getLong("sup_user_id"); } - /** 用户 */ + /** + * 用户 + */ public void setUserId(long sup_user_id) { put("sup_user_id", sup_user_id); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserPartyCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserPartyCache.java index c73faff..539447f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserPartyCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserPartyCache.java @@ -36,9 +36,11 @@ public class UserPartyCache extends AbstractEntityCache { public final Set getByUser(String key) { return getListByKey(mk_u, key); } + public final Set getByDept(String key) { return getListByKey(mk_d, key); } + public final Set getByParty(String key) { return getListByKey(mk_p, key); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserRole.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserRole.java index 08c605d..bb2ff7d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserRole.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserRole.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.user; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,30 +15,44 @@ public class UserRole extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sur_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sur_id) { put("sur_id", sur_id); } - /** 机构关系 */ + + /** + * 机构关系 + */ public long getSupId() { return getLong("sur_sup_id"); } - /** 机构关系 */ + /** + * 机构关系 + */ public void setSupId(long sur_sup_id) { put("sur_sup_id", sur_sup_id); } - /** 角色 */ + + /** + * 角色 + */ public long getRoleId() { return getLong("sur_role_id"); } - /** 角色 */ + /** + * 角色 + */ public void setRoleId(long sur_role_id) { put("sur_role_id", sur_role_id); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserService.java index 09bf762..2880871 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserService.java @@ -60,7 +60,7 @@ public class UserService extends DynPageService { * @Date 2022/8/15 16:48 * @Params * @Return cc.smtweb.framework.core.common.R - * @Description 重置密码 + * @Description 重置密码 */ public R resetPwd(@SwBody SwMap params, UserSession us) { return pageHandler(params, us, TYPE_CUST, handler -> ((UserHandler.UserCustHandler) handler).resetPwd()); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserStatu.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserStatu.java index d4e11cc..f917c50 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserStatu.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserStatu.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.user; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,93 +15,142 @@ public class UserStatu extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sus_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sus_id) { put("sus_id", sus_id); } - /** 积分 */ + + /** + * 积分 + */ public int getScore() { return getInt("sus_score"); } - /** 积分 */ + /** + * 积分 + */ public void setScore(int sus_score) { put("sus_score", sus_score); } - /** 密码错误次数 */ + + /** + * 密码错误次数 + */ public int getErrCount() { return getInt("sus_err_count"); } - /** 密码错误次数 */ + /** + * 密码错误次数 + */ public void setErrCount(int sus_err_count) { put("sus_err_count", sus_err_count); } - /** 开始锁定时间 */ + + /** + * 开始锁定时间 + */ public long getLockTime() { return getLong("sus_lock_time"); } - /** 开始锁定时间 */ + /** + * 开始锁定时间 + */ public void setLockTime(long sus_lock_time) { put("sus_lock_time", sus_lock_time); } - /** 登录时间 */ + + /** + * 登录时间 + */ public long getLoginTime() { return getLong("sus_login_time"); } - /** 登录时间 */ + /** + * 登录时间 + */ public void setLoginTime(long sus_login_time) { put("sus_login_time", sus_login_time); } - /** 登录IP */ + + /** + * 登录IP + */ public String getLoginIp() { return getStr("sus_login_ip"); } - /** 登录IP */ + /** + * 登录IP + */ public void setLoginIp(String sus_login_ip) { put("sus_login_ip", sus_login_ip); } - /** 登录信息 */ + + /** + * 登录信息 + */ public String getLoginInfo() { return getStr("sus_login_info"); } - /** 登录信息 */ + /** + * 登录信息 + */ public void setLoginInfo(String sus_login_info) { put("sus_login_info", sus_login_info); } - /** 登录来源 */ + + /** + * 登录来源 + */ public int getLoginType() { return getInt("sus_login_type"); } - /** 登录来源 */ + /** + * 登录来源 + */ public void setLoginType(int sus_login_type) { put("sus_login_type", sus_login_type); } - /** 退出时间 */ + + /** + * 退出时间 + */ public long getLogoutTime() { return getLong("sus_logout_time"); } - /** 退出时间 */ + /** + * 退出时间 + */ public void setLogoutTime(long sus_logout_time) { put("sus_logout_time", sus_logout_time); } - /** 在线状态 */ + + /** + * 在线状态 + */ public boolean isStatu() { return getBool("sus_statu"); } - /** 在线状态 */ + /** + * 在线状态 + */ public void set(boolean sus_statu) { setBool("sus_statu", sus_statu); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserStatuCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserStatuCache.java index 1912f70..85cac91 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserStatuCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/user/UserStatuCache.java @@ -4,11 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - /** * Created by 1 at 2022-07-28 15:24:49 * 实体【[用户状态](SYS_USER_STATU)】的缓存类 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroup.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroup.java index 2f52af7..0e97aa3 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroup.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroup.java @@ -1,11 +1,8 @@ package cc.smtweb.system.bpm.web.sys.user.userGroup; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.util.JsonUtil; -import cc.smtweb.system.bpm.web.design.flow.define.ProcInfo; -import cc.smtweb.system.bpm.web.design.form.define.PageDataset; import java.util.ArrayList; import java.util.Collections; @@ -39,48 +36,72 @@ public class UserGroup extends DefaultEntity { return items; } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sugp_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sugp_id) { put("sugp_id", sugp_id); } - /** 编码 */ + + /** + * 编码 + */ public String getCode() { return getStr("sugp_code"); } - /** 编码 */ + /** + * 编码 + */ public void setCode(String sugp_code) { put("sugp_code", sugp_code); } - /** 名称 */ + + /** + * 名称 + */ public String getName() { return getStr("sugp_name"); } - /** 名称 */ + /** + * 名称 + */ public void setName(String sugp_name) { put("sugp_name", sugp_name); } - /** 备注 */ + + /** + * 备注 + */ public String getRemark() { return getStr("sugp_remark"); } - /** 备注 */ + /** + * 备注 + */ public void setRemark(String sugp_remark) { put("sugp_remark", sugp_remark); } - /** 分组详细 */ + + /** + * 分组详细 + */ public String getContent() { return getStr("sugp_content"); } - /** 分组详细 */ + /** + * 分组详细 + */ public void setContent(String sugp_content) { put("sugp_content", sugp_content); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupCache.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupCache.java index bf28a15..b127fd4 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupCache.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupCache.java @@ -4,11 +4,6 @@ import cc.smtweb.framework.core.annotation.SwCache; import cc.smtweb.framework.core.cache.AbstractEntityCache; import cc.smtweb.framework.core.cache.CacheManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - /** * Created by 1 at 2022-08-02 20:19:02 * 实体【[用户分组](SYS_USER_GROUP)】的缓存类 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupComboHandler.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupComboHandler.java index 388fd61..dc1b958 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupComboHandler.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupComboHandler.java @@ -2,11 +2,8 @@ package cc.smtweb.system.bpm.web.sys.user.userGroup; import cc.smtweb.framework.core.db.vo.ModelTable; import cc.smtweb.framework.core.mvc.service.DefaultComboHandler; -import cc.smtweb.framework.core.util.CommUtil; -import cc.smtweb.system.bpm.web.design.db.ModelProjectCache; import java.util.List; -import java.util.Set; /** * Created by Akmm at 2022/3/22 19:25 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupHelper.java index 9e93829..6f84215 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupHelper.java @@ -1,15 +1,10 @@ package cc.smtweb.system.bpm.web.sys.user.userGroup; import cc.smtweb.framework.core.session.UserSession; -import cc.smtweb.framework.core.util.CommUtil; import cc.smtweb.system.bpm.web.engine.flow.entity.ProcInst; -import org.apache.commons.lang3.StringUtils; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.ResultSetExtractor; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; +import java.util.HashSet; +import java.util.Set; /** * Created by Akmm at 2022-08-02 20:19 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupService.java index 85d4828..656c873 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userGroup/UserGroupService.java @@ -3,7 +3,6 @@ package cc.smtweb.system.bpm.web.sys.user.userGroup; import cc.smtweb.framework.core.annotation.SwService; import cc.smtweb.framework.core.mvc.service.AbstractHandler; import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService; -import cc.smtweb.system.bpm.web.sys.user.menu.MenuHandler; /** * Created by zhenggm at 2022-08-03 17:21:52 diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userSso/UserSso.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userSso/UserSso.java index 3e710c4..f073fcc 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userSso/UserSso.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/userSso/UserSso.java @@ -1,7 +1,6 @@ package cc.smtweb.system.bpm.web.sys.user.userSso; import cc.smtweb.framework.core.annotation.SwTable; -import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.DefaultEntity; /** @@ -16,39 +15,58 @@ public class UserSso extends DefaultEntity { super(ENTITY_NAME); } - /** 主键 */ + /** + * 主键 + */ public long getId() { return getLong("sso_id"); } - /** 主键 */ + /** + * 主键 + */ public void setId(long sso_id) { put("sso_id", sso_id); } - /** 用户ID */ + + /** + * 用户ID + */ public long getSurId() { return getLong("sso_sur_id"); } - /** 用户ID */ + /** + * 用户ID + */ public void setSurId(long sso_sur_id) { put("sso_sur_id", sso_sur_id); } - /** 单点账号 */ + + /** + * 单点账号 + */ public String getCode() { return getStr("sso_code"); } - /** 单点账号 */ + /** + * 单点账号 + */ public void setCode(String sso_code) { put("sso_code", sso_code); } - /** 类型 */ + + /** + * 类型 + */ public String getType() { return getStr("sso_type"); } - /** 类型 */ + /** + * 类型 + */ public void setType(String sso_type) { put("sso_type", sso_type); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreApplication.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreApplication.java index 5c73f81..765ed77 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreApplication.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreApplication.java @@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class CoreApplication { - public static void main(String[] args) { - SpringApplication.run(CoreApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(CoreApplication.class, args); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreApplicationStartedListener.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreApplicationStartedListener.java index 9960e66..cbe83ad 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreApplicationStartedListener.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreApplicationStartedListener.java @@ -1,8 +1,6 @@ package cc.smtweb.framework.core; -import cc.smtweb.framework.core.cache.CacheManager; import cc.smtweb.framework.core.common.SwConsts; -import cc.smtweb.framework.core.db.impl.DatabaseUtil; import cc.smtweb.framework.core.mvc.controller.IStartListener; import cc.smtweb.framework.core.mvc.controller.scan.ApplicationScanner; import cc.smtweb.framework.core.mvc.controller.scan.BeanManager; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreAutoConfiguration.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreAutoConfiguration.java index 7299424..c3b4d75 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreAutoConfiguration.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/CoreAutoConfiguration.java @@ -9,7 +9,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * @author kevin @@ -18,24 +17,24 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @ComponentScan @EnableScheduling public class CoreAutoConfiguration implements WebMvcConfigurer { - /** - * ID生成器的分步式机器码(1-1023) - */ - @Value("${smtweb.machine-id}") - private int machineId; - - @Bean - public IdGenerator idGenerator() { - return new IdGenerator(machineId); - } + /** + * ID生成器的分步式机器码(1-1023) + */ + @Value("${smtweb.machine-id}") + private int machineId; - @Bean - public ControllerConfig coreControllerConfig() { - return new ControllerConfig("core", "cc.smtweb.framework.core"); - } + @Bean + public IdGenerator idGenerator() { + return new IdGenerator(machineId); + } - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new CoreInterceptor()); - } + @Bean + public ControllerConfig coreControllerConfig() { + return new ControllerConfig("core", "cc.smtweb.framework.core"); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new CoreInterceptor()); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwAction.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwAction.java index 112ed75..3f524fe 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwAction.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwAction.java @@ -8,14 +8,16 @@ import java.lang.annotation.Target; /** * 配置在@SwService中的函数,对应API请求,默认公用函数不用配置拦截器的函数, * 也可以作为拦截实现的基类 + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface SwAction { - /** - * 重写API请求地址,不配置使用: 服务类地址 + “/” + 函数名 - * @return API请求地址 - */ - String value() default ""; + /** + * 重写API请求地址,不配置使用: 服务类地址 + “/” + 函数名 + * + * @return API请求地址 + */ + String value() default ""; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwAttr.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwAttr.java index e9c3675..9a9182f 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwAttr.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwAttr.java @@ -4,13 +4,13 @@ import java.lang.annotation.*; /** * 参数注解,request定制的上下文内容,定制使用 - * @author kevin * + * @author kevin */ -@Target( { ElementType.PARAMETER}) +@Target({ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SwAttr { - String value() default ""; + String value() default ""; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwBean.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwBean.java index 31b4376..a739a44 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwBean.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwBean.java @@ -7,16 +7,18 @@ import java.lang.annotation.Target; /** * 被该注释修饰的类提供服务,如Dao,Service等 + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) public @interface SwBean { - String value() default ""; + String value() default ""; - /** - * 是否强行生成对象,不检查单例 - * @return 是否强行生成对象 - */ - boolean alwaysCreate() default false; + /** + * 是否强行生成对象,不检查单例 + * + * @return 是否强行生成对象 + */ + boolean alwaysCreate() default false; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwBody.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwBody.java index 50ff91b..aa0732a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwBody.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwBody.java @@ -4,12 +4,12 @@ import java.lang.annotation.*; /** * 参数注解,当编译器无法找到参数名称时,需要用该注解标明参数名称,当然你也可以用该参数标注参数别名与表单域字段名同意 - * @author kevin * + * @author kevin */ -@Target( { ElementType.PARAMETER}) +@Target({ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SwBody { - String value() default ""; + String value() default ""; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwCache.java index b6dbbd4..8ee4fdb 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwCache.java @@ -15,12 +15,16 @@ import java.lang.annotation.Target; public @interface SwCache { //唯一标识 String ident(); + //标题,展示用 String title(); + //依赖的缓存ident,多个用英文逗号分隔 String depends() default ""; + //是否懒加载 boolean lazy() default false; + //失效时间,单位分钟 long timeout() default 0; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwColumn.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwColumn.java index c4d88ed..64b744e 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwColumn.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwColumn.java @@ -7,32 +7,35 @@ import java.lang.annotation.Target; /** * 被该注释修饰的方法对应了字段名和类型 + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD}) public @interface SwColumn { - String value() default ""; + String value() default ""; - /** 字段作用,前端用RefType表示 */ - Type[] type() default {}; + /** + * 字段作用,前端用RefType表示 + */ + Type[] type() default {}; - public static enum Type { - // 主键 - ID, - // 上级ID,树结构需要 - PARENT_ID, - // 排序字段,树结构需要 - ORDER, - // 编码字段 - CODE, - // 名词字段 - NAME, - // 主表ID,MapToOne - MASTER_ID, - // 创建时间 - CREATE_TIME, - // 更新时间 - LAST_TIME, - } + public static enum Type { + // 主键 + ID, + // 上级ID,树结构需要 + PARENT_ID, + // 排序字段,树结构需要 + ORDER, + // 编码字段 + CODE, + // 名词字段 + NAME, + // 主表ID,MapToOne + MASTER_ID, + // 创建时间 + CREATE_TIME, + // 更新时间 + LAST_TIME, + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwColumnForeign.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwColumnForeign.java index fa1ada1..2eedcaf 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwColumnForeign.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwColumnForeign.java @@ -7,15 +7,18 @@ import java.lang.annotation.Target; /** * 被该注释修饰的方法对应了外键表名和字段名,名称可选 + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD}) public @interface SwColumnForeign { - // 外键表名 - String table() default ""; - // ID字段名 - String id() default ""; - // 唯一名称字段名 - String code() default ""; + // 外键表名 + String table() default ""; + + // ID字段名 + String id() default ""; + + // 唯一名称字段名 + String code() default ""; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwConstruct.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwConstruct.java index ed9eef5..8aa65ef 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwConstruct.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwConstruct.java @@ -7,14 +7,16 @@ import java.lang.annotation.Target; /** * 通过对@SwService/@SwBean类中的函数注解,服务启动时会调用一次被注解的函数 + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface SwConstruct { - /** - * 销毁顺序,值越小越先创建 - * @return 销毁顺序值 - */ - int order() default 0; + /** + * 销毁顺序,值越小越先创建 + * + * @return 销毁顺序值 + */ + int order() default 0; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwDestroy.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwDestroy.java index da89811..3fe2e0c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwDestroy.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwDestroy.java @@ -7,14 +7,16 @@ import java.lang.annotation.Target; /** * 通过对@SwService/@SwBean类中的函数注解,服务停止时会调用一次被注解的函数 + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface SwDestroy { - /** - * 销毁顺序,值越大越先销毁 - * @return 销毁顺序值 - */ - int order() default 0; + /** + * 销毁顺序,值越大越先销毁 + * + * @return 销毁顺序值 + */ + int order() default 0; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwHeaderParam.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwHeaderParam.java index 69af9d4..04ca25f 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwHeaderParam.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwHeaderParam.java @@ -5,10 +5,10 @@ import java.lang.annotation.*; /** * 路径注解 - * @author kevin * + * @author kevin */ -@Target( { ElementType.PARAMETER, ElementType.FIELD}) +@Target({ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SwHeaderParam { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwParam.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwParam.java index 033d671..c42a48b 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwParam.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwParam.java @@ -5,14 +5,17 @@ import java.lang.annotation.*; /** * 参数注解,当编译器无法找到参数名称时,需要用该注解标明参数名称,当然你也可以用该参数标注参数别名与表单域字段名同意 - * @author kevin * + * @author kevin */ -@Target( { ElementType.PARAMETER, ElementType.FIELD}) +@Target({ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SwParam { String value() default ""; - /** 注入类型,有多个类实现/子类时使用 */ + + /** + * 注入类型,有多个类实现/子类时使用 + */ Class type() default Object.class; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwPathParam.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwPathParam.java index c4ced93..863e5d9 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwPathParam.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwPathParam.java @@ -5,10 +5,10 @@ import java.lang.annotation.*; /** * 路径注解 - * @author kevin * + * @author kevin */ -@Target( { ElementType.PARAMETER, ElementType.FIELD}) +@Target({ElementType.PARAMETER, ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SwPathParam { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwPerm.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwPerm.java index 0ef2c48..2487667 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwPerm.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwPerm.java @@ -7,15 +7,20 @@ import java.lang.annotation.Target; /** * 被该注释修饰的方法都会经过切面拦截校验权限,默认是需要已登录权限 + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) public @interface SwPerm { - /** 无权限控制的值,在函数上注解@SwPerm(SwPerm.NONE) */ - static final String NONE = "*"; - static final String SESSION = ""; + /** + * 无权限控制的值,在函数上注解@SwPerm(SwPerm.NONE) + */ + static final String NONE = "*"; + static final String SESSION = ""; - /** 权限定义值 */ - String value() default SESSION; + /** + * 权限定义值 + */ + String value() default SESSION; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwScheduling.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwScheduling.java index 261f1f0..da11474 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwScheduling.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwScheduling.java @@ -11,20 +11,20 @@ import java.lang.annotation.Target; * @author xkliu */ @Retention(RetentionPolicy.RUNTIME) -@Target(value={ElementType.METHOD}) +@Target(value = {ElementType.METHOD}) public @interface SwScheduling { - /** - * 时间触发条件,如果值是单数字就是用秒定时,否则就是采用linux/unux crondtab 样式 - */ - String value(); + /** + * 时间触发条件,如果值是单数字就是用秒定时,否则就是采用linux/unux crondtab 样式 + */ + String value(); - /** - * 定时任务分组条件, 有值时同一分组不允许并发执行 - */ - String group() default ""; + /** + * 定时任务分组条件, 有值时同一分组不允许并发执行 + */ + String group() default ""; - /** - * 是否支持多服务同时运行 - */ - boolean multiServer() default false; + /** + * 是否支持多服务同时运行 + */ + boolean multiServer() default false; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwService.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwService.java index ba25e6c..079147e 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwService.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwService.java @@ -7,10 +7,11 @@ import java.lang.annotation.Target; /** * 被该注释修饰的类提供控制器服务 + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public @interface SwService { - String value() default ""; + String value() default ""; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwStartListener.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwStartListener.java index 2f9fe86..3f01a89 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwStartListener.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwStartListener.java @@ -7,6 +7,7 @@ import java.lang.annotation.Target; /** * 启动监听,order为执行顺序,请按SWConsts.DEFAULT_ORDER + XXX + * * @author zhenggm */ @Retention(RetentionPolicy.RUNTIME) diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwTable.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwTable.java index 464f322..0885c85 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwTable.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/annotation/SwTable.java @@ -7,11 +7,14 @@ import java.lang.annotation.Target; /** * 被该注释修饰的类对应了数据库表名(库+表的形式,如 sw_user.sys_user) + * * @author kevin */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public @interface SwTable { - /** 库名+表名 */ - String value() default ""; + /** + * 库名+表名 + */ + String value() default ""; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/ISwCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/ISwCache.java index 59d3c8a..ceb2a62 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/ISwCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/ISwCache.java @@ -1,24 +1,28 @@ package cc.smtweb.framework.core.cache; public interface ISwCache { - /** 权限缓存名称 */ - String REALM_CACHE = "RealmCache"; + /** + * 权限缓存名称 + */ + String REALM_CACHE = "RealmCache"; - /** - * 根据键值获取缓存对象 - * @param key 缓存唯一键值 - * @return 缓存对象 - */ - V get(K key); + /** + * 根据键值获取缓存对象 + * + * @param key 缓存唯一键值 + * @return 缓存对象 + */ + V get(K key); - /** - * 给redis发送广播消息,多服务同步删除相同key值的缓存对象 - * @param key 缓存键值 - */ - void publishRemove(K key); + /** + * 给redis发送广播消息,多服务同步删除相同key值的缓存对象 + * + * @param key 缓存键值 + */ + void publishRemove(K key); - /** - * 给redis发送广播消息,多服务同步清空相同类型的缓存对象 - */ - void publishClear(); + /** + * 给redis发送广播消息,多服务同步清空相同类型的缓存对象 + */ + void publishClear(); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisBroadcastEvent.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisBroadcastEvent.java index f9d00bf..c4a6d55 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisBroadcastEvent.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisBroadcastEvent.java @@ -7,18 +7,20 @@ import lombok.Data; */ @Data public class RedisBroadcastEvent { - public static final int CODE_REMOVE = 1; - public static final int CODE_CLEAR = 2; - /** 缓存更新 */ - public static final int CODE_CACHE_UPDATE = 3; - public static final int CODE_CACHE_REFRESH = 4; + public static final int CODE_REMOVE = 1; + public static final int CODE_CLEAR = 2; + /** + * 缓存更新 + */ + public static final int CODE_CACHE_UPDATE = 3; + public static final int CODE_CACHE_REFRESH = 4; - private int action; - private String ident; - private String key; + private int action; + private String ident; + private String key; - @Override - public String toString() { - return "ident=" + ident + "&&key=" + key + "&&act=" + action; - } + @Override + public String toString() { + return "ident=" + ident + "&&key=" + key + "&&act=" + action; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisPooledObjectFactory.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisPooledObjectFactory.java index 0c0c4c6..b98eb26 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisPooledObjectFactory.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisPooledObjectFactory.java @@ -8,32 +8,32 @@ import org.apache.commons.pool2.PooledObjectFactory; import org.apache.commons.pool2.impl.DefaultPooledObject; class RedisPooledObjectFactory implements PooledObjectFactory> { - private RedisClient redisClient; - - public RedisPooledObjectFactory(RedisClient redisClient) { - this.redisClient = redisClient; - } - - @Override - public void activateObject(PooledObject> pooledObject) throws Exception { - } - - @Override - public void destroyObject(PooledObject> pooledObject) throws Exception { - pooledObject.getObject().close(); - } - - @Override - public PooledObject> makeObject() throws Exception { - return new DefaultPooledObject<>(redisClient.connect(ByteArrayCodec.INSTANCE)); - } - - @Override - public void passivateObject(PooledObject> pooledObject) throws Exception { - } - - @Override - public boolean validateObject(PooledObject> pooledObject) { - return pooledObject.getObject().isOpen(); - } + private RedisClient redisClient; + + public RedisPooledObjectFactory(RedisClient redisClient) { + this.redisClient = redisClient; + } + + @Override + public void activateObject(PooledObject> pooledObject) throws Exception { + } + + @Override + public void destroyObject(PooledObject> pooledObject) throws Exception { + pooledObject.getObject().close(); + } + + @Override + public PooledObject> makeObject() throws Exception { + return new DefaultPooledObject<>(redisClient.connect(ByteArrayCodec.INSTANCE)); + } + + @Override + public void passivateObject(PooledObject> pooledObject) throws Exception { + } + + @Override + public boolean validateObject(PooledObject> pooledObject) { + return pooledObject.getObject().isOpen(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisSysTask.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisSysTask.java index b679838..c7d9ce4 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisSysTask.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/RedisSysTask.java @@ -9,53 +9,53 @@ import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands; import org.springframework.context.ApplicationContext; public class RedisSysTask implements ISysTask { - private ApplicationContext applicationContext; - private StatefulRedisPubSubConnection connection; - private RedisClient redisClient; - //订阅消息的channel,一般带通配符 - private String scribeChannel; - //自己的唯一标记,自己发的消息不处理 - private String selfChannel; - - public RedisSysTask(ApplicationContext applicationContext, RedisClient redisClient, String scribeChannel, String selfChannel) { - this.applicationContext = applicationContext; - this.redisClient = redisClient; - this.scribeChannel = scribeChannel; - this.selfChannel = selfChannel; - } - - @Override - public int run() { - // 非集群模式下的发布订阅 - if (connection == null) { - connection = redisClient.connectPubSub(); - - if (connection != null) { - connection.addListener(new RedisPubSubAdapter() { - @Override - public void message(String channel, String message) { - if (channel.equalsIgnoreCase(selfChannel)) return; - RedisBroadcastEvent redisBroadcast = JsonUtil.parse(message, RedisBroadcastEvent.class); - - applicationContext.publishEvent(redisBroadcast); + private ApplicationContext applicationContext; + private StatefulRedisPubSubConnection connection; + private RedisClient redisClient; + //订阅消息的channel,一般带通配符 + private String scribeChannel; + //自己的唯一标记,自己发的消息不处理 + private String selfChannel; + + public RedisSysTask(ApplicationContext applicationContext, RedisClient redisClient, String scribeChannel, String selfChannel) { + this.applicationContext = applicationContext; + this.redisClient = redisClient; + this.scribeChannel = scribeChannel; + this.selfChannel = selfChannel; + } + + @Override + public int run() { + // 非集群模式下的发布订阅 + if (connection == null) { + connection = redisClient.connectPubSub(); + + if (connection != null) { + connection.addListener(new RedisPubSubAdapter() { + @Override + public void message(String channel, String message) { + if (channel.equalsIgnoreCase(selfChannel)) return; + RedisBroadcastEvent redisBroadcast = JsonUtil.parse(message, RedisBroadcastEvent.class); + + applicationContext.publishEvent(redisBroadcast); // log.debug("Redis [" + channel + "] message:" + redisBroadcast); - } - }); + } + }); - // 订阅 - RedisPubSubCommands sync = connection.sync(); - sync.subscribe(scribeChannel); - } - } + // 订阅 + RedisPubSubCommands sync = connection.sync(); + sync.subscribe(scribeChannel); + } + } - return 0; - } + return 0; + } - public void close() { - if (connection != null) { - connection.close(); - connection = null; + public void close() { + if (connection != null) { + connection.close(); + connection = null; + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/config/RedisConfig.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/config/RedisConfig.java index 83367e3..3a768e1 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/config/RedisConfig.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/cache/redis/config/RedisConfig.java @@ -45,7 +45,7 @@ public class RedisConfig { @Bean public RedisManager redisManager() { - RedisURI redisUri = RedisURI.create (redisHost, redisPort); + RedisURI redisUri = RedisURI.create(redisHost, redisPort); if (StringUtils.isNotBlank(clientName)) { redisUri.setClientName(clientName); } @@ -56,7 +56,7 @@ public class RedisConfig { redisUri.setUsername(redisUserName.trim()); } if (StringUtils.isNotBlank(redisPassword)) { - redisUri.setPassword((CharSequence)redisPassword.trim()); + redisUri.setPassword((CharSequence) redisPassword.trim()); } return new RedisManager(applicationContext, sysTaskManager, redisUri); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java index 29f6bb9..3e18ee0 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/AbstractEnum.java @@ -17,7 +17,7 @@ public abstract class AbstractEnum { return bean; } - public void delEnum(K value) { + public void delEnum(K value) { mapAll.remove(value); } @@ -63,7 +63,7 @@ public abstract class AbstractEnum { //遍历枚举类 public void doEnum(IEnumWorker worker) { - for (V bean: mapAll.values()) { + for (V bean : mapAll.values()) { worker.work(bean); } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/R.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/R.java index 4a91157..6d0b6d2 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/R.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/R.java @@ -48,7 +48,7 @@ public class R extends SwMap { return r; } - public static R errorf(String format, Object...args) { + public static R errorf(String format, Object... args) { R r = new R(ExceptionMessage.INNER_ERROR.getCode()); r.put("msg", String.format(format, args)); return r; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java index c1b523f..1c3bb28 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwEnum.java @@ -276,7 +276,7 @@ public interface SwEnum { public static StrEnumBean LIST = instance.addEnum("list", "列表"); public static StrEnumBean FORM = instance.addEnum("form", "表单"); -// public static StrEnumBean ITEM = instance.addEnum("item", "子表编辑"); + // public static StrEnumBean ITEM = instance.addEnum("item", "子表编辑"); public static StrEnumBean TREE = instance.addEnum("tree", "树"); // public static StrEnumBean ENUM = instance.addEnum("enum", "枚举"); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwIpAddr.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwIpAddr.java index ab2b357..7dba1b7 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwIpAddr.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/common/SwIpAddr.java @@ -4,6 +4,6 @@ import lombok.Data; @Data public class SwIpAddr { - private String ip; - private int port; + private String ip; + private int port; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/BeanEntityDao.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/BeanEntityDao.java index 2e9ea78..1bce417 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/BeanEntityDao.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/BeanEntityDao.java @@ -2,7 +2,6 @@ package cc.smtweb.framework.core.db; import cc.smtweb.framework.core.annotation.SwColumn; import cc.smtweb.framework.core.db.dao.AbstractBeanEntityDao; -import cc.smtweb.framework.core.db.dao.AbstractEntityDao; import cc.smtweb.framework.core.db.dao.EntityColumn; import cc.smtweb.framework.core.db.jdbc.JdbcEngine; import cc.smtweb.framework.core.util.DateUtil; @@ -13,6 +12,7 @@ import java.util.List; /** * 提供数据对象Dao操作,不是通过平台构建的表的dao + * * @author xkliu */ public class BeanEntityDao extends AbstractBeanEntityDao { @@ -26,6 +26,7 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 获取数据库唯一id + * * @return 返回ID值 */ public long nextId() { @@ -34,15 +35,17 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 根据PO对象的ID值更新其余所有字段 + * * @param entity PO对象 * @return 更新数量 */ public int updateEntity(T entity) { - return updateEntity(entity, null,null); + return updateEntity(entity, null, null); } /** * 使用ID字段更新单行数据 + * * @param entity PO值对象,对象属性是需要更新的值 * @param fields 需要更新额字段列表,逗号分隔 * @return 更新数量 @@ -53,8 +56,9 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 指定自定义条件更新对象 - * @param entity PO值对象,对象属性是需要更新的值和更新条件值 - * @param fields 需要更新额字段列表,逗号分隔 + * + * @param entity PO值对象,对象属性是需要更新的值和更新条件值 + * @param fields 需要更新额字段列表,逗号分隔 * @param whereFields 更新条件字段列表,逗号分隔 * @return 更新数量 */ @@ -67,23 +71,28 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 用PO对象所有字段入单行数据 - * @param type PO对象字段范围的类,是entity的父类 + * + * @param type PO对象字段范围的类,是entity的父类 * @param entity PO对象 * @return 更新数量 */ public int insertEntity(Class type, T entity) { return insertEntity(type, entity, null); } + /** * 用PO对象所有字段入单行数据 + * * @param entity PO对象 * @return 更新数量 */ public int insertEntity(T entity) { return insertEntity(entity.getClass(), entity, null); } + /** * 插入单行数据 + * * @param entity PO对象 * @param fields 逗号分隔的字段列表 * @return 更新数量 @@ -102,6 +111,7 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 批量插入单行数据 + * * @param entities PO对象列表 * @return 更新数量 */ @@ -111,8 +121,9 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 批量插入单行数据 + * * @param entities PO对象列表 - * @param fields 逗号分隔的字段列表 + * @param fields 逗号分隔的字段列表 * @return 更新数量 */ public int[] batchInsertEntity(List entities, String fields) { @@ -129,14 +140,14 @@ public class BeanEntityDao extends AbstractBeanEntityDao { List insertColumns = new ArrayList<>(this.columns.size()); if (fields == null) { - for (EntityColumn column: this.columns.values()) { + for (EntityColumn column : this.columns.values()) { sql.append(column.getFieldName()).append(","); insertColumns.add(column); } } else { String[] fieldNames = fields.split(","); - for (String name: fieldNames) { + for (String name : fieldNames) { EntityColumn column = this.columns.get(name.trim()); sql.append(column.getFieldName()).append(","); if (column == createTimeColumn) { @@ -167,7 +178,7 @@ public class BeanEntityDao extends AbstractBeanEntityDao { // 参数列表 List listParams = new ArrayList<>(entities.size()); - for (T obj: entities) { + for (T obj : entities) { List params = new ArrayList<>(insertColumns.size()); for (EntityColumn column : insertColumns) { @@ -191,6 +202,7 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 根据ID值删除单行数据 + * * @param entity PO对象 * @return 删除数量 */ @@ -204,6 +216,7 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 根据ID值删除单行数据 + * * @param id 记录主建值 * @return 删除数量 */ @@ -216,11 +229,12 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 根据ID值删除单行数据 + * * @param whereSql Where条件SQL语句,以where开头 - * @param params 条件的值,可以多个 + * @param params 条件的值,可以多个 * @return 删除数量 */ - public int deleteEntity(String whereSql, Object...params) { + public int deleteEntity(String whereSql, Object... params) { StringBuilder sb = new StringBuilder("DELETE FROM "); sb.append(getTableName()).append(" ").append(whereSql); @@ -229,14 +243,17 @@ public class BeanEntityDao extends AbstractBeanEntityDao { /** * 读取实体对象ID值 + * * @param entity * @return */ public Long readEntityId(T entity) { - return (Long)readId(entity); + return (Long) readId(entity); } - /** 查询单行数据,返回bean */ + /** + * 查询单行数据,返回bean + */ public T queryEntity(Long id) { return queryEntity(id, null); } @@ -254,12 +271,16 @@ public class BeanEntityDao extends AbstractBeanEntityDao { return null; } - /** 查询对象所有数据,返回列表 */ + /** + * 查询对象所有数据,返回列表 + */ public List query() { return query(null); } - /** 查询对象所有数据,返回列表 */ + /** + * 查询对象所有数据,返回列表 + */ public List query(String fields) { StringBuilder sb = new StringBuilder(); handleSelect(sb, fields); @@ -267,8 +288,10 @@ public class BeanEntityDao extends AbstractBeanEntityDao { return jdbcEngine.query(sb.toString(), type); } - /** 查询对象所有数据,返回列表 */ - public List queryWhere(String sqlWhere, Object...params) { + /** + * 查询对象所有数据,返回列表 + */ + public List queryWhere(String sqlWhere, Object... params) { StringBuilder sb = new StringBuilder(); handleSelect(sb, null); sb.append(" where ").append(sqlWhere); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/DbEngine.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/DbEngine.java index cc231cc..b474d0f 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/DbEngine.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/DbEngine.java @@ -37,6 +37,7 @@ public class DbEngine extends JdbcEngine { /** * 不是通过平台构建的表的dao + * * @param type * @param * @return @@ -56,6 +57,7 @@ public class DbEngine extends JdbcEngine { /** * bean为Data格式,调用此方法 + * * @param type bean类 * @param * @return diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java index 6a518ef..89c66c2 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityDao.java @@ -285,7 +285,7 @@ public class EntityDao extends AbstractEntityDao { public int batchDelete(Collection list) { if (CommUtil.isEmpty(list)) return 0; List ids = new ArrayList<>(list.size()); - for (DefaultEntity bean: list) { + for (DefaultEntity bean : list) { ids.add(bean.getEntityId()); } return deleteEntity(" where " + modelTable.getIdField() + " in (" + CommUtil.getSqlInIds(ids) + ")"); @@ -373,6 +373,7 @@ public class EntityDao extends AbstractEntityDao { if (CommUtil.isEmpty(list)) return null; return list.get(0); } + /** * 查询对象所有数据,返回列表 */ diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java index f785cbd..9648572 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/EntityHelper.java @@ -60,7 +60,7 @@ public class EntityHelper { for (String fieldName : fieldNames) { String fname = fieldName.toLowerCase(); //转换为小写,因此在bean中定义的字段都是小写的; Object v = bean.getData().get(fname); - String value = v != null ? v.toString() : ""; + String value = v != null ? v.toString(): ""; final ModelField field = modelEntity.findField(fname); if (field != null) { if (StringUtil.isEmpty(value) && StringUtil.isNotEmpty(field.getDefaultValue())) { @@ -91,7 +91,7 @@ public class EntityHelper { //获取字段别名 private static String getFieldAlias(Map mapFieldAlias, String field) { - return (mapFieldAlias != null && mapFieldAlias.containsKey(field)) ? mapFieldAlias.get(field) : field; + return (mapFieldAlias != null && mapFieldAlias.containsKey(field)) ? mapFieldAlias.get(field): field; } /** @@ -129,7 +129,7 @@ public class EntityHelper { String sn = (String) dao.readValue(b, l.getLinkNameField()); if (StringUtils.isNotEmpty(sn)) names += "," + sn; } - bean.put(fieldName + SwConsts.TEXT_SUFFIX, names.length() > 1 ? names.substring(1) : ""); + bean.put(fieldName + SwConsts.TEXT_SUFFIX, names.length() > 1 ? names.substring(1): ""); } else { List list = mapIds.computeIfAbsent(l.getLinkTable().getName(), k -> new ArrayList<>()); Collections.addAll(list, ids); @@ -225,7 +225,7 @@ public class EntityHelper { if (StringUtils.isNotEmpty(names)) { row.put(fieldName + SwConsts.TEXT_SUFFIX, names.substring(1)); } else { - row.put(fieldName + SwConsts.TEXT_SUFFIX, ""); + row.put(fieldName + SwConsts.TEXT_SUFFIX, ""); } } else { List list = mapIds.computeIfAbsent(l.getLinkTable().getName(), k -> new ArrayList<>()); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/EntityCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/EntityCache.java index b95d305..97557be 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/EntityCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/EntityCache.java @@ -21,7 +21,7 @@ public class EntityCache extends AbstractCache { public EntityCache(String tableName) { this.tableName = tableName; - Class clazz = (Class)BeanManager.getInstance().getTableClass(tableName); + Class clazz = (Class) BeanManager.getInstance().getTableClass(tableName); if (clazz != null) { this.pTypeClass = clazz; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelTableCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelTableCache.java index 383079a..1e2b2be 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelTableCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/cache/ModelTableCache.java @@ -32,12 +32,12 @@ public class ModelTableCache extends AbstractCache { } public ModelTableCache() { - regMap(mk, k-> k.getName().toUpperCase()); - regList(md, k-> String.valueOf(k.getDbId())); - regList(mc, k-> String.valueOf(k.getMcId())); - regListEx(mk_link, k-> { + regMap(mk, k -> k.getName().toUpperCase()); + regList(md, k -> String.valueOf(k.getDbId())); + regList(mc, k -> String.valueOf(k.getMcId())); + regListEx(mk_link, k -> { Set list = new HashSet<>(); - for (ModelField field: k.getFields()) { + for (ModelField field : k.getFields()) { if (field.getLink() > 0) list.add(String.valueOf(field.getLink())); } return list.toArray(new String[list.size()]); @@ -103,6 +103,7 @@ public class ModelTableCache extends AbstractCache { public final ModelTable getByName(String key) { return getByKey(mk, key.toUpperCase()); } + public final Set getDbTables(long dbId) { return getListByKey(md, String.valueOf(dbId)); } @@ -121,7 +122,7 @@ public class ModelTableCache extends AbstractCache { public final String getTableName(long id) { ModelTable bean = get(id); - return bean == null ? String.valueOf(id) : bean.getTitle(); + return bean == null ? String.valueOf(id): bean.getTitle(); } //根据外键 diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/config/DbEngineConfiguration.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/config/DbEngineConfiguration.java index 774420e..5d33427 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/config/DbEngineConfiguration.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/config/DbEngineConfiguration.java @@ -10,12 +10,13 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; /** * 默认数据源 + * * @author xkliu */ @Configuration public class DbEngineConfiguration { - @Value("${smtweb.db.type}") - private String dbType; + @Value("${smtweb.db.type}") + private String dbType; // @Bean // public DataSource dataSource() { // return DataSourceBuilder.create().build(); @@ -26,16 +27,17 @@ public class DbEngineConfiguration { // return new NamedParameterJdbcTemplate(dataSource); // } - /** - * 产生数据库数据库访问对象 dbEngine - * @param namedJdbcTemplate Spring框架Jdbc,通过 spring.datasource 配置 - * @param idGenerator ID生成器对象,思想数据库ID生成 - * @return dbEngine对象 - */ - @Bean - @ConfigurationProperties(prefix = "smtweb.db.default") - public DbEngine dbEngine(NamedParameterJdbcTemplate namedJdbcTemplate, IdGenerator idGenerator) { - System.out.println("create dbEngine============="); - return new DbEngine(namedJdbcTemplate, idGenerator, dbType); - } + /** + * 产生数据库数据库访问对象 dbEngine + * + * @param namedJdbcTemplate Spring框架Jdbc,通过 spring.datasource 配置 + * @param idGenerator ID生成器对象,思想数据库ID生成 + * @return dbEngine对象 + */ + @Bean + @ConfigurationProperties(prefix = "smtweb.db.default") + public DbEngine dbEngine(NamedParameterJdbcTemplate namedJdbcTemplate, IdGenerator idGenerator) { + System.out.println("create dbEngine============="); + return new DbEngine(namedJdbcTemplate, idGenerator, dbType); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/config/YamlPropertyLoaderFactory.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/config/YamlPropertyLoaderFactory.java index 24c0c05..d383e5b 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/config/YamlPropertyLoaderFactory.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/config/YamlPropertyLoaderFactory.java @@ -11,13 +11,13 @@ import java.io.IOException; * 实现yaml配置文件加载工厂,以使用@PropertySource注解加载指定yaml文件的配置 */ public class YamlPropertyLoaderFactory extends DefaultPropertySourceFactory { - @Override - public PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { + @Override + public PropertySource createPropertySource(String name, EncodedResource resource) throws IOException { - if (null == resource) { - super.createPropertySource(name, resource); + if (null == resource) { + super.createPropertySource(name, resource); + } + return new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource()).get(0); } - return new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource()).get(0); - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractBeanEntityDao.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractBeanEntityDao.java index 3f24a38..b867d7a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractBeanEntityDao.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractBeanEntityDao.java @@ -1,7 +1,6 @@ package cc.smtweb.framework.core.db.dao; import cc.smtweb.framework.core.annotation.SwColumn; -import cc.smtweb.framework.core.annotation.SwColumnForeign; import cc.smtweb.framework.core.annotation.SwTable; import cc.smtweb.framework.core.exception.DbException; import cc.smtweb.framework.core.util.DateUtil; @@ -21,433 +20,444 @@ import java.util.Map; /** * 抽象的值对象数据库访问 * 不是通过平台构建的表的dao + * * @param 数据库值对象类型 */ public class AbstractBeanEntityDao { protected String tableName; - protected Map columns = new HashMap<>(); - protected Map typeColumns = new HashMap<>(); - protected Class type; + protected Map columns = new HashMap<>(); + protected Map typeColumns = new HashMap<>(); + protected Class type; // public AbstractEntityDao(String tableName) { // this.tableName = tableName; // } - /** - * 通过值对象类型构造值对象数据库访问 - * @param type 值对象类型 - */ - public AbstractBeanEntityDao(Class type) { - this.type = type; + /** + * 通过值对象类型构造值对象数据库访问 + * + * @param type 值对象类型 + */ + public AbstractBeanEntityDao(Class type) { + this.type = type; - // type.isAnnotationPresent(Table.class); - SwTable table = type.getAnnotation(SwTable.class); + // type.isAnnotationPresent(Table.class); + SwTable table = type.getAnnotation(SwTable.class); - Class superclass = type.getSuperclass(); + Class superclass = type.getSuperclass(); - if (table == null && superclass != null) { - table = superclass.getAnnotation(SwTable.class); - } + if (table == null && superclass != null) { + table = superclass.getAnnotation(SwTable.class); + } - if (table == null) { - throw new IllegalAccessError("not find annotation @SwTable"); - } + if (table == null) { + throw new IllegalAccessError("not find annotation @SwTable"); + } - List fields; - if (superclass == null) { - fields = appendField(type.getFields(), type.getDeclaredFields()); - } else { - fields = appendField(type.getFields(), type.getDeclaredFields(), superclass.getFields(), - superclass.getDeclaredFields()); - } + List fields; + if (superclass == null) { + fields = appendField(type.getFields(), type.getDeclaredFields()); + } else { + fields = appendField(type.getFields(), type.getDeclaredFields(), superclass.getFields(), + superclass.getDeclaredFields()); + } // Map columnToPropertyOverrides = new HashMap<>(); - tableName = table.value(); - - for (Field field : fields) { - SwColumn column = field.getAnnotation(SwColumn.class); - // 获取name - String columnName; - if (column != null && StringUtils.isNotBlank(column.value())) { - columnName = column.value(); - } else { - columnName = VariableUtil.humpToUnderline(field.getName()); - } - - // 处理get method - try { - PropertyDescriptor pd = new PropertyDescriptor(field.getName(), type); - // 获得get方法 - Method readMethod = pd.getReadMethod(); - Method writeMethod = pd.getWriteMethod(); - - if (readMethod != null && writeMethod != null) { - Class[] parameterTypes = writeMethod.getParameterTypes(); - if (parameterTypes.length == 1 && ClassUtils.isAssignable(parameterTypes[0], readMethod.getReturnType())) { - add(columnName, readMethod, writeMethod, column); - } - } - } catch (IntrospectionException ignore) { - } - - // TODO 判断是否Public - } - } - - private List appendField(Field[]... fields) { - List list = new ArrayList<>(); - if (fields == null) { - return list; - } - - for (Field[] field : fields) { - if (field == null) { - continue; - } - - for (Field temp : field) { - list.add(temp); - } - } - return list; - } - - /** - * 添加值对象的属性访问方法何注解值 - * @param fieldName 字段名 - * @param readMethod 读值对象属性方法 - * @param writeMethod 写值值对象属性方法 - * @param column 字段注解 - */ - public void add(String fieldName, Method readMethod, Method writeMethod, SwColumn column) { - EntityColumnForeign foreign = null; - - EntityColumn beanColumn = new EntityColumn(fieldName, readMethod, writeMethod); - columns.put(fieldName, beanColumn); - - if (column != null) { - for (SwColumn.Type type : column.type()) { - typeColumns.put(type, beanColumn); - } - } - } - - /** - * 拼接插入SQL语句 - * @param obj 值对象 - * @param sql 记录sql的字符缓存 - * @param fields 逗号分割字段列表,设置为null表示使用所有字段 - * @return SQL参数列表 - */ - protected Object[] handleInsert(T obj, StringBuilder sql, String fields) { - List result; - - sql.append("insert into ").append(tableName).append("("); - - Long now = DateUtil.nowDateTimeLong(); - EntityColumn createTimeColumn = typeColumns.get(SwColumn.Type.CREATE_TIME); - EntityColumn lastTimeColumn = typeColumns.get(SwColumn.Type.LAST_TIME); - - if (fields == null) { + tableName = table.value(); + + for (Field field : fields) { + SwColumn column = field.getAnnotation(SwColumn.class); + // 获取name + String columnName; + if (column != null && StringUtils.isNotBlank(column.value())) { + columnName = column.value(); + } else { + columnName = VariableUtil.humpToUnderline(field.getName()); + } + + // 处理get method + try { + PropertyDescriptor pd = new PropertyDescriptor(field.getName(), type); + // 获得get方法 + Method readMethod = pd.getReadMethod(); + Method writeMethod = pd.getWriteMethod(); + + if (readMethod != null && writeMethod != null) { + Class[] parameterTypes = writeMethod.getParameterTypes(); + if (parameterTypes.length == 1 && ClassUtils.isAssignable(parameterTypes[0], readMethod.getReturnType())) { + add(columnName, readMethod, writeMethod, column); + } + } + } catch (IntrospectionException ignore) { + } + + // TODO 判断是否Public + } + } + + private List appendField(Field[]... fields) { + List list = new ArrayList<>(); + if (fields == null) { + return list; + } + + for (Field[] field : fields) { + if (field == null) { + continue; + } + + for (Field temp : field) { + list.add(temp); + } + } + return list; + } + + /** + * 添加值对象的属性访问方法何注解值 + * + * @param fieldName 字段名 + * @param readMethod 读值对象属性方法 + * @param writeMethod 写值值对象属性方法 + * @param column 字段注解 + */ + public void add(String fieldName, Method readMethod, Method writeMethod, SwColumn column) { + EntityColumnForeign foreign = null; + + EntityColumn beanColumn = new EntityColumn(fieldName, readMethod, writeMethod); + columns.put(fieldName, beanColumn); + + if (column != null) { + for (SwColumn.Type type : column.type()) { + typeColumns.put(type, beanColumn); + } + } + } + + /** + * 拼接插入SQL语句 + * + * @param obj 值对象 + * @param sql 记录sql的字符缓存 + * @param fields 逗号分割字段列表,设置为null表示使用所有字段 + * @return SQL参数列表 + */ + protected Object[] handleInsert(T obj, StringBuilder sql, String fields) { + List result; + + sql.append("insert into ").append(tableName).append("("); + + Long now = DateUtil.nowDateTimeLong(); + EntityColumn createTimeColumn = typeColumns.get(SwColumn.Type.CREATE_TIME); + EntityColumn lastTimeColumn = typeColumns.get(SwColumn.Type.LAST_TIME); + + if (fields == null) { // len = this.columns.size(); - result = new ArrayList<>(this.columns.size()); + result = new ArrayList<>(this.columns.size()); // int index = 0; - for (EntityColumn column: this.columns.values()) { - Object value = column.readValue(obj); - - if (column == createTimeColumn) { - if (value == null) { - column.writeValue(obj, now); - value = now; - } - createTimeColumn = null; - } else if (column == lastTimeColumn) { - if (value == null) { - column.writeValue(obj, now); - value = now; - } - lastTimeColumn = null; - } - - result.add(value); - sql.append(column.getFieldName()).append(","); - } - } else { - String[] fieldNames = fields.split(","); - result = new ArrayList<>(fieldNames.length + 2); - - for (String name: fieldNames) { - EntityColumn column = this.columns.get(name.trim()); - if (column == null) { - throw new IllegalArgumentException("not define column: " + name); - } - - Object value = column.readValue(obj); - - if (column == createTimeColumn) { - if (value == null) { - column.writeValue(obj, now); - value = now; - } - createTimeColumn = null; - } else if (column == lastTimeColumn) { - if (value == null) { - column.writeValue(obj, now); - value = now; - } - lastTimeColumn = null; - } - - result.add(value); - sql.append(column.getFieldName()).append(","); - } - - // 自动更新fields未设置 createTime - if (createTimeColumn != null) { - createTimeColumn.writeValue(obj, now); - result.add(now); - sql.append(createTimeColumn.getFieldName()).append(","); - } - - // 自动更新fields未设置 createTime - if (lastTimeColumn != null) { - lastTimeColumn.writeValue(obj, now); - result.add(now); - sql.append(lastTimeColumn.getFieldName()).append(","); - } - } - - sql.setCharAt(sql.length() - 1, ')'); - - // values(?,?) - sql.append(" values("); - for (int i = result.size(); i > 0; i--) { - sql.append("?,"); - } - sql.setCharAt(sql.length() - 1, ')'); - - return result.toArray(); - } - - /** - * 拼接更新SQL语句 - * @param obj 值对象 - * @param sql 记录sql的字符缓存 - * @param fields 逗号分割更新字段列表,设置为null表示使用所有字段 - * @param whereFields 逗号分割查询字段列表,设置为null表示使用ID字段作为查询条件 - * @return SQL参数列表 - */ - protected Object[] handleUpdate(T obj, StringBuilder sql, String fields, String whereFields) { - EntityColumn idColumn = findIdColumn(); - - EntityColumn lastTimeColumn = typeColumns.get(SwColumn.Type.LAST_TIME); - Long now = DateUtil.nowDateTimeLong(); - - sql.append("update ").append(tableName).append(" set "); - List result = new ArrayList<>(); - - if (fields == null) { - for (EntityColumn column: this.columns.values()) { - if (idColumn != column) { - Object value = column.readValue(obj); - if (lastTimeColumn == column) { - if (value == null) { - value = now; - } else { - lastTimeColumn = null; - } - } - - result.add(value); - sql.append(column.getFieldName()).append("=?,"); - } - } - sql.setCharAt(sql.length() - 1, ' '); - - // 默认使用Id字段条件 - result.add(idColumn.readValue(obj)); - - sql.append("where ").append(idColumn.getFieldName()).append("=?"); - } else { - String[] fieldNames = fields.split(","); - - for (String name: fieldNames) { - name = name.trim(); - EntityColumn beanColumn = getBeanColumn(name); - - Object value = beanColumn.readValue(obj); - if (lastTimeColumn == beanColumn) { - if (value == null) { - value = now; - } else { - lastTimeColumn = null; - } - } - - result.add(value); - sql.append(name).append("=?,"); - } - - if (lastTimeColumn != null) { - result.add(now); - sql.append(lastTimeColumn.getFieldName()).append("=?,"); - } - - sql.setCharAt(sql.length() - 1, ' '); - - if (StringUtils.isNotBlank(whereFields)) { - sql.append("where "); - boolean first = true; - for (String name: whereFields.split(",")) { - name = name.trim(); - if (first) { - first = false; - } else { - sql.append(" and "); - } - - sql.append(name).append("=?"); - result.add(readValue(obj, name)); - } - } else { - // 默认使用Id字段条件 - result.add(idColumn.readValue(obj)); - - sql.append("where ").append(idColumn.getFieldName()).append("=?"); - } - } - - // 自动更新对象的值 - if (lastTimeColumn != null) { - lastTimeColumn.writeValue(obj, now); - } - - return result.toArray(); - } - - private EntityColumn findIdColumn() { - EntityColumn idColumn = typeColumns.get(SwColumn.Type.ID); - - if (idColumn == null) { - throw new DbException(tableName + " not define id column"); - } - - return idColumn; - } - - /** - * 拼接删除值对象语句 - * @param obj 值对象 - * @param sql 记录sql的字符缓存 - * @return SQL参数列表 - */ - protected Object[] handleDelete(T obj, StringBuilder sql) { - EntityColumn idColumn = findIdColumn(); - - sql.append("DELETE FROM ").append(tableName).append(" WHERE ").append(idColumn.getFieldName()).append("=?"); - - return new Object[]{idColumn.readValue(obj)}; - } - - /** - * 拼接删除值对象语句,条件由外部设置 - * @param sql 记录sql的字符缓存 - */ - protected void handleDelete(StringBuilder sql) { - EntityColumn idColumn = findIdColumn(); - - sql.append("DELETE FROM ").append(tableName).append(" WHERE ").append(idColumn.getFieldName()).append("=?"); - } - - private Object readValue(T obj, String fieldName) { - EntityColumn beanColumn = getBeanColumn(fieldName); - - return beanColumn.readValue(obj); - } - - private EntityColumn getBeanColumn(String fieldName) { - EntityColumn beanColumn = this.columns.get(fieldName); - - if (beanColumn == null) { - throw new DbException("not define column:" + fieldName); - } - - return beanColumn; - } - - /** - * 获取表名 - * @return 表名 - */ - protected String getTableName() { - return tableName; - } - - /** - * 拼接查询SQL语句 - * @param sql SQL字符缓存 - * @param fields 逗号分割的查询字段列表,传入null表示全部值对象字段 - */ - public void handleSelect(StringBuilder sql, String fields) { - sql.append("select "); - - if (fields != null) { - sql.append(fields).append(' '); - } else { - for (String fieldName : columns.keySet()) { - sql.append(fieldName).append(','); - } - sql.setCharAt(sql.length() - 1, ' '); - } - - sql.append("from ").append(tableName); - } - - /** - * 拼接SQL排序字段 - * @param sql SQL字符缓存 - */ - public void handleOrderBy(StringBuilder sql) { - EntityColumn entityColumn = this.typeColumns.get(SwColumn.Type.ORDER); - if (entityColumn != null) { - sql.append(" order by ").append(entityColumn.getFieldName()); - EntityColumn idColumn = this.typeColumns.get(SwColumn.Type.ID); - if (idColumn != null) { - sql.append(", ").append(idColumn.getFieldName()); - } - } - } - - protected void handleSelectOne(StringBuilder sql, String fields) { - EntityColumn idColumn = findIdColumn(); - - sql.append("select "); - - if (fields != null) { - sql.append(fields).append(' '); - } else { - for (EntityColumn field : columns.values()) { - sql.append(field.getFieldName()).append(","); - } - sql.setCharAt(sql.length() - 1, ' '); - } - - sql.append("from ").append(tableName).append(" where ").append(idColumn.getFieldName()).append("=?"); - } - - public EntityColumn getColumn(SwColumn.Type type) { - return this.typeColumns.get(type); - } - - /** - * 读取ID值 - * @param entity - * @return - */ - public Long readId(T entity) { - EntityColumn idColumn = findIdColumn(); - - return (Long)idColumn.readValue(entity); - } + for (EntityColumn column : this.columns.values()) { + Object value = column.readValue(obj); + + if (column == createTimeColumn) { + if (value == null) { + column.writeValue(obj, now); + value = now; + } + createTimeColumn = null; + } else if (column == lastTimeColumn) { + if (value == null) { + column.writeValue(obj, now); + value = now; + } + lastTimeColumn = null; + } + + result.add(value); + sql.append(column.getFieldName()).append(","); + } + } else { + String[] fieldNames = fields.split(","); + result = new ArrayList<>(fieldNames.length + 2); + + for (String name : fieldNames) { + EntityColumn column = this.columns.get(name.trim()); + if (column == null) { + throw new IllegalArgumentException("not define column: " + name); + } + + Object value = column.readValue(obj); + + if (column == createTimeColumn) { + if (value == null) { + column.writeValue(obj, now); + value = now; + } + createTimeColumn = null; + } else if (column == lastTimeColumn) { + if (value == null) { + column.writeValue(obj, now); + value = now; + } + lastTimeColumn = null; + } + + result.add(value); + sql.append(column.getFieldName()).append(","); + } + + // 自动更新fields未设置 createTime + if (createTimeColumn != null) { + createTimeColumn.writeValue(obj, now); + result.add(now); + sql.append(createTimeColumn.getFieldName()).append(","); + } + + // 自动更新fields未设置 createTime + if (lastTimeColumn != null) { + lastTimeColumn.writeValue(obj, now); + result.add(now); + sql.append(lastTimeColumn.getFieldName()).append(","); + } + } + + sql.setCharAt(sql.length() - 1, ')'); + + // values(?,?) + sql.append(" values("); + for (int i = result.size(); i > 0; i--) { + sql.append("?,"); + } + sql.setCharAt(sql.length() - 1, ')'); + + return result.toArray(); + } + + /** + * 拼接更新SQL语句 + * + * @param obj 值对象 + * @param sql 记录sql的字符缓存 + * @param fields 逗号分割更新字段列表,设置为null表示使用所有字段 + * @param whereFields 逗号分割查询字段列表,设置为null表示使用ID字段作为查询条件 + * @return SQL参数列表 + */ + protected Object[] handleUpdate(T obj, StringBuilder sql, String fields, String whereFields) { + EntityColumn idColumn = findIdColumn(); + + EntityColumn lastTimeColumn = typeColumns.get(SwColumn.Type.LAST_TIME); + Long now = DateUtil.nowDateTimeLong(); + + sql.append("update ").append(tableName).append(" set "); + List result = new ArrayList<>(); + + if (fields == null) { + for (EntityColumn column : this.columns.values()) { + if (idColumn != column) { + Object value = column.readValue(obj); + if (lastTimeColumn == column) { + if (value == null) { + value = now; + } else { + lastTimeColumn = null; + } + } + + result.add(value); + sql.append(column.getFieldName()).append("=?,"); + } + } + sql.setCharAt(sql.length() - 1, ' '); + + // 默认使用Id字段条件 + result.add(idColumn.readValue(obj)); + + sql.append("where ").append(idColumn.getFieldName()).append("=?"); + } else { + String[] fieldNames = fields.split(","); + + for (String name : fieldNames) { + name = name.trim(); + EntityColumn beanColumn = getBeanColumn(name); + + Object value = beanColumn.readValue(obj); + if (lastTimeColumn == beanColumn) { + if (value == null) { + value = now; + } else { + lastTimeColumn = null; + } + } + + result.add(value); + sql.append(name).append("=?,"); + } + + if (lastTimeColumn != null) { + result.add(now); + sql.append(lastTimeColumn.getFieldName()).append("=?,"); + } + + sql.setCharAt(sql.length() - 1, ' '); + + if (StringUtils.isNotBlank(whereFields)) { + sql.append("where "); + boolean first = true; + for (String name : whereFields.split(",")) { + name = name.trim(); + if (first) { + first = false; + } else { + sql.append(" and "); + } + + sql.append(name).append("=?"); + result.add(readValue(obj, name)); + } + } else { + // 默认使用Id字段条件 + result.add(idColumn.readValue(obj)); + + sql.append("where ").append(idColumn.getFieldName()).append("=?"); + } + } + + // 自动更新对象的值 + if (lastTimeColumn != null) { + lastTimeColumn.writeValue(obj, now); + } + + return result.toArray(); + } + + private EntityColumn findIdColumn() { + EntityColumn idColumn = typeColumns.get(SwColumn.Type.ID); + + if (idColumn == null) { + throw new DbException(tableName + " not define id column"); + } + + return idColumn; + } + + /** + * 拼接删除值对象语句 + * + * @param obj 值对象 + * @param sql 记录sql的字符缓存 + * @return SQL参数列表 + */ + protected Object[] handleDelete(T obj, StringBuilder sql) { + EntityColumn idColumn = findIdColumn(); + + sql.append("DELETE FROM ").append(tableName).append(" WHERE ").append(idColumn.getFieldName()).append("=?"); + + return new Object[]{idColumn.readValue(obj)}; + } + + /** + * 拼接删除值对象语句,条件由外部设置 + * + * @param sql 记录sql的字符缓存 + */ + protected void handleDelete(StringBuilder sql) { + EntityColumn idColumn = findIdColumn(); + + sql.append("DELETE FROM ").append(tableName).append(" WHERE ").append(idColumn.getFieldName()).append("=?"); + } + + private Object readValue(T obj, String fieldName) { + EntityColumn beanColumn = getBeanColumn(fieldName); + + return beanColumn.readValue(obj); + } + + private EntityColumn getBeanColumn(String fieldName) { + EntityColumn beanColumn = this.columns.get(fieldName); + + if (beanColumn == null) { + throw new DbException("not define column:" + fieldName); + } + + return beanColumn; + } + + /** + * 获取表名 + * + * @return 表名 + */ + protected String getTableName() { + return tableName; + } + + /** + * 拼接查询SQL语句 + * + * @param sql SQL字符缓存 + * @param fields 逗号分割的查询字段列表,传入null表示全部值对象字段 + */ + public void handleSelect(StringBuilder sql, String fields) { + sql.append("select "); + + if (fields != null) { + sql.append(fields).append(' '); + } else { + for (String fieldName : columns.keySet()) { + sql.append(fieldName).append(','); + } + sql.setCharAt(sql.length() - 1, ' '); + } + + sql.append("from ").append(tableName); + } + + /** + * 拼接SQL排序字段 + * + * @param sql SQL字符缓存 + */ + public void handleOrderBy(StringBuilder sql) { + EntityColumn entityColumn = this.typeColumns.get(SwColumn.Type.ORDER); + if (entityColumn != null) { + sql.append(" order by ").append(entityColumn.getFieldName()); + EntityColumn idColumn = this.typeColumns.get(SwColumn.Type.ID); + if (idColumn != null) { + sql.append(", ").append(idColumn.getFieldName()); + } + } + } + + protected void handleSelectOne(StringBuilder sql, String fields) { + EntityColumn idColumn = findIdColumn(); + + sql.append("select "); + + if (fields != null) { + sql.append(fields).append(' '); + } else { + for (EntityColumn field : columns.values()) { + sql.append(field.getFieldName()).append(","); + } + sql.setCharAt(sql.length() - 1, ' '); + } + + sql.append("from ").append(tableName).append(" where ").append(idColumn.getFieldName()).append("=?"); + } + + public EntityColumn getColumn(SwColumn.Type type) { + return this.typeColumns.get(type); + } + + /** + * 读取ID值 + * + * @param entity + * @return + */ + public Long readId(T entity) { + EntityColumn idColumn = findIdColumn(); + + return (Long) idColumn.readValue(entity); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java index 4bbb8aa..f3457cc 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java @@ -1,29 +1,24 @@ package cc.smtweb.framework.core.db.dao; -import cc.smtweb.framework.core.annotation.SwColumn; -import cc.smtweb.framework.core.annotation.SwColumnForeign; import cc.smtweb.framework.core.annotation.SwTable; import cc.smtweb.framework.core.cache.CacheManager; import cc.smtweb.framework.core.common.SwEnum; -import cc.smtweb.framework.core.db.DbEngine; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.db.cache.ModelTableCache; import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.db.vo.ModelField; import cc.smtweb.framework.core.db.vo.ModelTable; import cc.smtweb.framework.core.exception.DbException; +import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.util.DateUtil; import cc.smtweb.framework.core.util.NumberUtil; import cc.smtweb.framework.core.util.SpringUtil; import cc.smtweb.framework.core.util.VariableUtil; -import com.esotericsoftware.minlog.Log; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.util.ClassUtils; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; -import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/EntityColumnForeign.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/EntityColumnForeign.java index 49c4d7d..f7331b4 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/EntityColumnForeign.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/EntityColumnForeign.java @@ -4,23 +4,25 @@ import lombok.Getter; /** * 字段外键属性 + * * @author admin */ @Getter public class EntityColumnForeign { - private final String table; - private final String id; - private final String name; + private final String table; + private final String id; + private final String name; - /** - * 构造字段外键属性 - * @param table 外键表名 - * @param id 外键ID字段名 - * @param name 外键名称字段名 - */ - public EntityColumnForeign(String table, String id, String name) { - this.table = table; - this.id = id; - this.name = name; - } + /** + * 构造字段外键属性 + * + * @param table 外键表名 + * @param id 外键ID字段名 + * @param name 外键名称字段名 + */ + public EntityColumnForeign(String table, String id, String name) { + this.table = table; + this.id = id; + this.name = name; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/BaseBean.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/BaseBean.java index b4de094..8d608fe 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/BaseBean.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/BaseBean.java @@ -43,7 +43,7 @@ public class BaseBean implements Serializable { public String getStr(String fieldName, String defValue) { Object o = data.get(fieldName); - return o != null ? o.toString() : defValue; + return o != null ? o.toString(): defValue; } public double getDouble(String fieldName) { @@ -83,7 +83,7 @@ public class BaseBean implements Serializable { } public void setBool(String fieldName, boolean value) { - this.data.put(fieldName, value ? 1 : 0); + this.data.put(fieldName, value ? 1: 0); } public Object get(String fieldName) { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DatabaseUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DatabaseUtil.java index 7169f29..3d3efa0 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DatabaseUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DatabaseUtil.java @@ -2,7 +2,6 @@ package cc.smtweb.framework.core.db.impl; import cc.smtweb.framework.core.common.SwEnum; import cc.smtweb.framework.core.db.DbEngine; -import cc.smtweb.framework.core.db.EntityHelper; import cc.smtweb.framework.core.db.cache.ModelTableCache; import cc.smtweb.framework.core.db.vo.ModelField; import cc.smtweb.framework.core.db.vo.ModelIndex; @@ -231,7 +230,7 @@ public class DatabaseUtil { String k = entity.getSchemaTableName().toUpperCase(); //表名 Map> exists_indexes = tableIndexListMap.get(k); Set setEnabled = new HashSet<>();//有效的索引 - for (ModelIndex mi: entity.getIndexes()) { + for (ModelIndex mi : entity.getIndexes()) { if (SwEnum.IndexType.PK.value.equalsIgnoreCase(mi.getType())) continue; Set dbfields = null; @@ -432,8 +431,8 @@ public class DatabaseUtil { SwEnum.DataTypeBean type = SwEnum.DataType.instance.getByValue(field.getDataType()); if (type == null) return null; try { - String defValue = StringUtils.isNotEmpty(field.getDefaultValue()) ? "'" + field.getDefaultValue() + "'" : ""; - String dvs = StringUtils.isNotEmpty(field.getDefaultValue()) ? " DEFAULT '" + field.getDefaultValue() + "'" : ""; + String defValue = StringUtils.isNotEmpty(field.getDefaultValue()) ? "'" + field.getDefaultValue() + "'": ""; + String dvs = StringUtils.isNotEmpty(field.getDefaultValue()) ? " DEFAULT '" + field.getDefaultValue() + "'": ""; String sql = "ALTER TABLE " + entity.getSchemaTableName() + " MODIFY COLUMN " + field.getName() + " " + type.getSqlTypeCreate() + dvs + " COMMENT '" + field.getRemark() + "'"; DbEngine.getInstance().update(sql); } catch (Exception e) { @@ -493,7 +492,7 @@ public class DatabaseUtil { private String makeIndexClause(ModelTable entity, ModelIndex modelIndex) { if (SwEnum.IndexType.PK.value.equalsIgnoreCase(modelIndex.getType())) return null; SwEnum.IndexTypeBean type = SwEnum.IndexType.instance.getByValue(modelIndex.getType()); - return "CREATE " + (SwEnum.IndexType.U.value.equalsIgnoreCase(modelIndex.getType()) ? SwEnum.IndexType.U.fullName : "") + + return "CREATE " + (SwEnum.IndexType.U.value.equalsIgnoreCase(modelIndex.getType()) ? SwEnum.IndexType.U.fullName: "") + " INDEX " + getDbIndexName(entity, modelIndex) + " ON " + entity.getSchemaTableName() + " (" + modelIndex.getFields() + ")"; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultDatabaseInfoImpl.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultDatabaseInfoImpl.java index 29332a4..f959f27 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultDatabaseInfoImpl.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultDatabaseInfoImpl.java @@ -129,8 +129,8 @@ public class DefaultDatabaseInfoImpl implements IDatabaseInfo { getTableSet(dbData, null, needsUpperCase, lookupSchemaName); } } catch (SQLException e) { - log.error(e.getMessage(), e); - } + log.error(e.getMessage(), e); + } return null; } @@ -215,7 +215,7 @@ public class DefaultDatabaseInfoImpl implements IDatabaseInfo { Collection list = ModelDatabaseCache.getInstance().getAll(); if (list != null && !list.isEmpty()) { for (ModelDatabase db : list) { - String dn = SwConsts.DEF_DB_NAME.equals(db.getName()) ? "" : ("_" + db.getName()); + String dn = SwConsts.DEF_DB_NAME.equals(db.getName()) ? "": ("_" + db.getName()); getColumnInfo(dbData, dbName + dn, needsUpperCase, lookupSchemaName); } } @@ -263,7 +263,7 @@ public class DefaultDatabaseInfoImpl implements IDatabaseInfo { ccInfo.decimalDigits = rsCols.getInt("DECIMAL_DIGITS"); // NOTE: this may need a toUpperCase in some cases, keep an eye on it ccInfo.isNullable = rsCols.getString("IS_NULLABLE"); - List tableColInfo = colInfo.computeIfAbsent(k, k1->new ArrayList<>()); + List tableColInfo = colInfo.computeIfAbsent(k, k1 -> new ArrayList<>()); tableColInfo.add(ccInfo); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultEntity.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultEntity.java index cd1d8ca..178dcf0 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultEntity.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/impl/DefaultEntity.java @@ -85,7 +85,7 @@ public class DefaultEntity extends BaseBean implements Serializable, Cloneable { } @Override - public DefaultEntity clone() { + public DefaultEntity clone() { try { DefaultEntity bean = (DefaultEntity) super.clone(); bean.getData().remove(getPkFieldName()); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/AbsDbWorker.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/AbsDbWorker.java index f337520..a3f0e75 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/AbsDbWorker.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/AbsDbWorker.java @@ -7,8 +7,10 @@ package cc.smtweb.framework.core.db.jdbc; @Deprecated public abstract class AbsDbWorker implements IDbWorker { @Override - public void doAfterDbCommit() {} + public void doAfterDbCommit() { + } @Override - public void doAfterDbRollback(){} + public void doAfterDbRollback() { + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/BaseBeanPropertyRowMapper.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/BaseBeanPropertyRowMapper.java index 8c4607a..416e05e 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/BaseBeanPropertyRowMapper.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/BaseBeanPropertyRowMapper.java @@ -10,31 +10,32 @@ import java.sql.SQLException; /** * ORM映射处理器,实现spring jdbcTemplate的行集映射器 + * * @author xkliu */ public class BaseBeanPropertyRowMapper implements RowMapper { - private Class mappedClass; + private Class mappedClass; - public BaseBeanPropertyRowMapper(Class mappedClass) { - this.mappedClass = mappedClass; - } + public BaseBeanPropertyRowMapper(Class mappedClass) { + this.mappedClass = mappedClass; + } - @Override - public T mapRow(ResultSet resultSet, int i) throws SQLException { - T mappedObject = BeanUtils.instantiateClass(this.mappedClass); - BaseBean map = (BaseBean) mappedObject; + @Override + public T mapRow(ResultSet resultSet, int i) throws SQLException { + T mappedObject = BeanUtils.instantiateClass(this.mappedClass); + BaseBean map = (BaseBean) mappedObject; - ResultSetMetaData rsmd = resultSet.getMetaData(); - int columnCount = rsmd.getColumnCount(); + ResultSetMetaData rsmd = resultSet.getMetaData(); + int columnCount = rsmd.getColumnCount(); - for(int index = 1; index <= columnCount; ++index) { - Object value = resultSet.getObject(index); + for (int index = 1; index <= columnCount; ++index) { + Object value = resultSet.getObject(index); - if (value != null) { - map.put(rsmd.getColumnLabel(index), value); - } - } + if (value != null) { + map.put(rsmd.getColumnLabel(index), value); + } + } - return mappedObject; - } + return mappedObject; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IDbWorker.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IDbWorker.java index 6ccc3ab..032da9b 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IDbWorker.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IDbWorker.java @@ -5,11 +5,14 @@ package cc.smtweb.framework.core.db.jdbc; * 数据库事务操作方法类 */ public interface IDbWorker { - default void work(){} + default void work() { + } //数据库提交完后的业务或缓存处理 - default void doAfterDbCommit(){} + default void doAfterDbCommit() { + } //数据库回滚后的业务或缓存处理 - default void doAfterDbRollback(){} + default void doAfterDbRollback() { + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IdGenerator.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IdGenerator.java index 4be311a..dc7673a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IdGenerator.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/IdGenerator.java @@ -35,10 +35,11 @@ package cc.smtweb.framework.core.db.jdbc; /** * tweeter的snowflake - * time—42bits,精确到ms,那就意味着其可以表示长达(2^42-1)/(1000360024*365)=139.5年 - * (a) id构成: 42位的时间前缀 + 10位的节点标识 + 12位的sequence避免并发的数字(12位不够用时强制得到新的时间前缀) - * 注意这里进行了小改动: snowkflake是5位的datacenter加5位的机器id; 这里变成使用10位的机器id - * (b) 对系统时间的依赖性非常强,需关闭ntp的时间同步功能。当检测到ntp时间调整后,将会拒绝分配id + * time—42bits,精确到ms,那就意味着其可以表示长达(2^42-1)/(1000360024*365)=139.5年 + * (a) id构成: 42位的时间前缀 + 10位的节点标识 + 12位的sequence避免并发的数字(12位不够用时强制得到新的时间前缀) + * 注意这里进行了小改动: snowkflake是5位的datacenter加5位的机器id; 这里变成使用10位的机器id + * (b) 对系统时间的依赖性非常强,需关闭ntp的时间同步功能。当检测到ntp时间调整后,将会拒绝分配id + * * @author xkliu */ public class IdGenerator { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/JdbcEngine.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/JdbcEngine.java index 5a06455..0492bfc 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/JdbcEngine.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/JdbcEngine.java @@ -1,9 +1,9 @@ package cc.smtweb.framework.core.db.jdbc; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.impl.BaseBean; import cc.smtweb.framework.core.exception.DbException; +import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.util.JsonUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.dao.EmptyResultDataAccessException; @@ -292,7 +292,6 @@ public class JdbcEngine { return false; }*/ - public void beginTrans() { Thread t = Thread.currentThread(); JdbcTrans jdbcTrans = mapThreadTrans.get(t); @@ -315,7 +314,7 @@ public class JdbcEngine { } public void recTransLog() { - for (JdbcTrans tm: mapThreadTrans.values()) { + for (JdbcTrans tm : mapThreadTrans.values()) { tm.doEnd("process"); } } @@ -467,7 +466,7 @@ public class JdbcEngine { } public int[] batchUpdateN(String sql, List> params) { - return namedJdbcTemplate.batchUpdate(sql, (Map[])params.toArray()); + return namedJdbcTemplate.batchUpdate(sql, (Map[]) params.toArray()); } /** @@ -476,6 +475,7 @@ public class JdbcEngine { public List pagedQueryN(String sql, Class type, int start, int limit, Map params) { return queryN(sql + " LIMIT " + start + "," + limit, params, type); } + /*=================以上为具名参数方法==================================================*/ public boolean isExists(String sql, Object... params) { try { @@ -490,7 +490,7 @@ public class JdbcEngine { RowMapper rowMapper; if (BaseBean.class.isAssignableFrom(type)) { rowMapper = new BaseBeanPropertyRowMapper<>(type); - } else if (java.util.Map.class.isAssignableFrom(type)) { + } else if (java.util.Map.class.isAssignableFrom(type)) { if (SwMap.class.equals(type)) { rowMapper = new SwMapPropertyRowMapper<>(type); } else { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/MapPropertyRowMapper.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/MapPropertyRowMapper.java index c8ebc51..3039526 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/MapPropertyRowMapper.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/MapPropertyRowMapper.java @@ -9,31 +9,32 @@ import java.sql.SQLException; /** * ORM映射处理器,实现spring jdbcTemplate的行集映射器 + * * @author xkliu */ public class MapPropertyRowMapper implements RowMapper { - private Class mappedClass; + private Class mappedClass; - public MapPropertyRowMapper(Class mappedClass) { - this.mappedClass = mappedClass; - } + public MapPropertyRowMapper(Class mappedClass) { + this.mappedClass = mappedClass; + } - @Override - public T mapRow(ResultSet resultSet, int i) throws SQLException { - T mappedObject = BeanUtils.instantiateClass(this.mappedClass); - java.util.Map map = (java.util.Map)mappedObject; + @Override + public T mapRow(ResultSet resultSet, int i) throws SQLException { + T mappedObject = BeanUtils.instantiateClass(this.mappedClass); + java.util.Map map = (java.util.Map) mappedObject; - ResultSetMetaData rsmd = resultSet.getMetaData(); - int columnCount = rsmd.getColumnCount(); + ResultSetMetaData rsmd = resultSet.getMetaData(); + int columnCount = rsmd.getColumnCount(); - for(int index = 1; index <= columnCount; ++index) { - Object value = resultSet.getObject(index); + for (int index = 1; index <= columnCount; ++index) { + Object value = resultSet.getObject(index); - if (value != null) { - map.put(rsmd.getColumnLabel(index), value); - } - } + if (value != null) { + map.put(rsmd.getColumnLabel(index), value); + } + } - return mappedObject; - } + return mappedObject; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/SwMapPropertyRowMapper.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/SwMapPropertyRowMapper.java index a5aad19..71c0eb4 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/SwMapPropertyRowMapper.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/jdbc/SwMapPropertyRowMapper.java @@ -9,51 +9,52 @@ import java.sql.SQLException; /** * ORM映射处理器,实现spring jdbcTemplate的行集映射器,对下划线进行小驼峰命名转化 + * * @author xkliu */ public class SwMapPropertyRowMapper implements RowMapper { - public SwMapPropertyRowMapper(Class mappedClass) { - } + public SwMapPropertyRowMapper(Class mappedClass) { + } + + @Override + public T mapRow(ResultSet resultSet, int i) throws SQLException { + SwMap map = new SwMap(); - @Override - public T mapRow(ResultSet resultSet, int i) throws SQLException { - SwMap map = new SwMap(); + ResultSetMetaData rsmd = resultSet.getMetaData(); + int columnCount = rsmd.getColumnCount(); - ResultSetMetaData rsmd = resultSet.getMetaData(); - int columnCount = rsmd.getColumnCount(); + for (int index = 1; index <= columnCount; ++index) { + Object value = resultSet.getObject(index); - for(int index = 1; index <= columnCount; ++index) { - Object value = resultSet.getObject(index); + if (value != null) { + String columnLabel = rsmd.getColumnLabel(index); + map.put(columnLabel, value); //toCamelCase(columnLabel) + } + } - if (value != null) { - String columnLabel = rsmd.getColumnLabel(index); - map.put(columnLabel, value); //toCamelCase(columnLabel) - } + return (T) map; } - return (T)map; - } - - private String toCamelCase(String columnLabel) { - int len = columnLabel.length(); - StringBuilder sb = new StringBuilder(len); - int lowCase = 1; - for (int i = 0; i < len; i++) { - char ch = columnLabel.charAt(i); - if (ch == '_') { - lowCase = 2; - } else { - if (lowCase == 1) { - ch = Character.toLowerCase(ch); - lowCase = 0; - } else if (lowCase == 2) { - ch = Character.toUpperCase(ch); - lowCase = 0; + private String toCamelCase(String columnLabel) { + int len = columnLabel.length(); + StringBuilder sb = new StringBuilder(len); + int lowCase = 1; + for (int i = 0; i < len; i++) { + char ch = columnLabel.charAt(i); + if (ch == '_') { + lowCase = 2; + } else { + if (lowCase == 1) { + ch = Character.toLowerCase(ch); + lowCase = 0; + } else if (lowCase == 2) { + ch = Character.toUpperCase(ch); + lowCase = 0; + } + sb.append(ch); + } } - sb.append(ch); - } - } - return sb.toString(); - } + return sb.toString(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/AbstractSelectSqlBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/AbstractSelectSqlBuilder.java index 9006790..d0367ab 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/AbstractSelectSqlBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/AbstractSelectSqlBuilder.java @@ -8,122 +8,122 @@ import java.util.List; import java.util.function.BiFunction; public class AbstractSelectSqlBuilder extends SqlBuilder { - private List orderBy; + private List orderBy; - protected void makeFields(StringBuilder sb) { - } - - protected Object[] makeParams(StringBuilder sb) { - makeFields(sb); - - if (wheres != null) { - List params = new ArrayList<>(wheres.size()); - - if (wheres.size() > 0) { - String logicOp = " AND "; - boolean addLoginOp = false; - - for (int i = 0; i < wheres.size(); i++) { - SqlWhereValue whereValue = wheres.get(i); - - if (i == 0) { - sb.append(" WHERE "); - } - - if (whereValue.getName() == null) { - Object value = whereValue.getValue(); + protected void makeFields(StringBuilder sb) { + } - if ("(".equals(value)) { - if (i > 0) { - sb.append(logicOp); - } - addLoginOp = false; + protected Object[] makeParams(StringBuilder sb) { + makeFields(sb); + + if (wheres != null) { + List params = new ArrayList<>(wheres.size()); + + if (wheres.size() > 0) { + String logicOp = " AND "; + boolean addLoginOp = false; + + for (int i = 0; i < wheres.size(); i++) { + SqlWhereValue whereValue = wheres.get(i); + + if (i == 0) { + sb.append(" WHERE "); + } + + if (whereValue.getName() == null) { + Object value = whereValue.getValue(); + + if ("(".equals(value)) { + if (i > 0) { + sb.append(logicOp); + } + addLoginOp = false; + } + + sb.append(value); + logicOp = whereValue.getOp(); + } else { + if (addLoginOp) { + sb.append(logicOp); + } else { + addLoginOp = true; + } + + sb.append(whereValue.getName()).append(whereValue.getOp()).append('?'); + params.add(whereValue.getValue()); + } + } } - sb.append(value); - logicOp = whereValue.getOp(); - } else { - if (addLoginOp) { - sb.append(logicOp); - } else { - addLoginOp = true; + if (orderBy != null) { + for (int i = 0; i < orderBy.size(); i++) { + if (i == 0) { + sb.append(" ORDER BY "); + } else { + sb.append(","); + } + + sb.append(orderBy.get(i)); + } } - sb.append(whereValue.getName()).append(whereValue.getOp()).append('?'); - params.add(whereValue.getValue()); - } + return params.toArray(new Object[params.size()]); } - } - if (orderBy != null) { - for (int i = 0; i < orderBy.size(); i++) { - if (i == 0) { - sb.append(" ORDER BY "); - } else { - sb.append(","); - } + return null; + } - sb.append(orderBy.get(i)); + @Override + public AbstractSelectSqlBuilder addOrderBy(String orderByField) { + if (this.orderBy == null) { + this.orderBy = new ArrayList<>(); } - } - - return params.toArray(new Object[params.size()]); - } - return null; - } + this.orderBy.add(orderByField); - @Override - public AbstractSelectSqlBuilder addOrderBy(String orderByField) { - if (this.orderBy == null) { - this.orderBy = new ArrayList<>(); + return this; } - this.orderBy.add(orderByField); - - return this; - } - - public List query(DbEngine dbEngine, Class clazz) { - return exec((sql, params) -> dbEngine.query(sql, clazz, params)); - } + public List query(DbEngine dbEngine, Class clazz) { + return exec((sql, params) -> dbEngine.query(sql, clazz, params)); + } - public T queryEntity(DbEngine dbEngine, Class clazz) { - return exec((sql, params) -> dbEngine.queryEntity(sql, clazz, params)); + public T queryEntity(DbEngine dbEngine, Class clazz) { + return exec((sql, params) -> dbEngine.queryEntity(sql, clazz, params)); // StringBuilder sb = new StringBuilder("select "); // // Object[] params = makeParams(sb); // // return dbEngine.queryEntity(sb.toString(), clazz, params); - } + } - public T exec(BiFunction execute) { - StringBuilder sb = new StringBuilder("select "); + public T exec(BiFunction execute) { + StringBuilder sb = new StringBuilder("select "); - Object[] params = makeParams(sb); + Object[] params = makeParams(sb); - return execute.apply(sb.toString(), params); - } + return execute.apply(sb.toString(), params); + } - public List pagedQuery(DbEngine dbEngine, Class clazz, int start, int limit) { - return exec((sql, params) -> dbEngine.pagedQuery(sql, clazz, start, limit, params)); + public List pagedQuery(DbEngine dbEngine, Class clazz, int start, int limit) { + return exec((sql, params) -> dbEngine.pagedQuery(sql, clazz, start, limit, params)); // StringBuilder sb = new StringBuilder("select "); // // Object[] params = makeParams(sb); // // return dbEngine.pagedQuery(sb.toString(), clazz, start, limit, params); - } + } - public int queryInt(JdbcEngine dbEngine) { - return exec(dbEngine::queryInt); - } + public int queryInt(JdbcEngine dbEngine) { + return exec(dbEngine::queryInt); + } - public SqlJoinTable addJoinTable(String dbName, String tableName, String tableAlias) { - return null; - } + public SqlJoinTable addJoinTable(String dbName, String tableName, String tableAlias) { + return null; + } - public SqlJoinTable findJoinTable(String dbName, String tableName) { - return null; - } + public SqlJoinTable findJoinTable(String dbName, String tableName) { + return null; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/AbstractUpdateSqlBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/AbstractUpdateSqlBuilder.java index ebb4e53..1bcf516 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/AbstractUpdateSqlBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/AbstractUpdateSqlBuilder.java @@ -3,18 +3,18 @@ package cc.smtweb.framework.core.db.sqlbuilder; import cc.smtweb.framework.core.db.jdbc.JdbcEngine; public abstract class AbstractUpdateSqlBuilder extends SqlBuilder { - // 无效的更新值,用以占位表示不组装值到params对象里面 - public static final Object VALUE_INVALID = new SqlFieldValue("", ""); + // 无效的更新值,用以占位表示不组装值到params对象里面 + public static final Object VALUE_INVALID = new SqlFieldValue("", ""); - public boolean isEmpty() { - return fields.isEmpty(); - } + public boolean isEmpty() { + return fields.isEmpty(); + } - public abstract int update(JdbcEngine dbEngine); + public abstract int update(JdbcEngine dbEngine); - public void updateMap(java.util.Map map) { - for (SqlFieldValue field: fields) { - map.put(field.getName(), field.getValue()); + public void updateMap(java.util.Map map) { + for (SqlFieldValue field : fields) { + map.put(field.getName(), field.getValue()); + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/DeleteSqlBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/DeleteSqlBuilder.java index 4fdcc78..e9aae1f 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/DeleteSqlBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/DeleteSqlBuilder.java @@ -3,31 +3,31 @@ package cc.smtweb.framework.core.db.sqlbuilder; import cc.smtweb.framework.core.db.jdbc.JdbcEngine; public class DeleteSqlBuilder extends AbstractUpdateSqlBuilder { - private String tableName; + private String tableName; - DeleteSqlBuilder(String tableName) { - this.tableName = tableName; - } + DeleteSqlBuilder(String tableName) { + this.tableName = tableName; + } - @Override - public int update(JdbcEngine dbEngine) { - int fieldSize = wheres.size(); - Object[] params = new Object[fieldSize]; + @Override + public int update(JdbcEngine dbEngine) { + int fieldSize = wheres.size(); + Object[] params = new Object[fieldSize]; - StringBuilder sb = new StringBuilder("delete from "); + StringBuilder sb = new StringBuilder("delete from "); - sb.append(tableName).append(" where "); + sb.append(tableName).append(" where "); - int index = 0; - for (SqlWhereValue whereValue: wheres) { - if (index > 0){ - sb.append(" and "); - } - sb.append(whereValue.getName()).append("=?"); - params[index] = whereValue.getValue(); - index++; - } + int index = 0; + for (SqlWhereValue whereValue : wheres) { + if (index > 0) { + sb.append(" and "); + } + sb.append(whereValue.getName()).append("=?"); + params[index] = whereValue.getValue(); + index++; + } - return dbEngine.update(sb.toString(), params); - } + return dbEngine.update(sb.toString(), params); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/DirectSelectSqlBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/DirectSelectSqlBuilder.java index 6986db6..5265089 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/DirectSelectSqlBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/DirectSelectSqlBuilder.java @@ -3,18 +3,18 @@ package cc.smtweb.framework.core.db.sqlbuilder; import java.util.function.BiFunction; public class DirectSelectSqlBuilder extends AbstractSelectSqlBuilder { - private String sql; + private String sql; - DirectSelectSqlBuilder(String sql) { - this.sql = sql; - } + DirectSelectSqlBuilder(String sql) { + this.sql = sql; + } - @Override - public T exec(BiFunction execute) { - StringBuilder sb = new StringBuilder(sql); + @Override + public T exec(BiFunction execute) { + StringBuilder sb = new StringBuilder(sql); - Object[] params = makeParams(sb); + Object[] params = makeParams(sb); - return execute.apply(sb.toString(), params); - } + return execute.apply(sb.toString(), params); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/InsertSqlBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/InsertSqlBuilder.java index dfc1e3c..b7bd604 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/InsertSqlBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/InsertSqlBuilder.java @@ -3,36 +3,36 @@ package cc.smtweb.framework.core.db.sqlbuilder; import cc.smtweb.framework.core.db.jdbc.JdbcEngine; public class InsertSqlBuilder extends AbstractUpdateSqlBuilder { - private String tableName; + private String tableName; - InsertSqlBuilder(String tableName) { - this.tableName = tableName; - } + InsertSqlBuilder(String tableName) { + this.tableName = tableName; + } - @Override - public int update(JdbcEngine dbEngine) { - int fieldSize = fields.size(); - Object[] params = new Object[fieldSize]; + @Override + public int update(JdbcEngine dbEngine) { + int fieldSize = fields.size(); + Object[] params = new Object[fieldSize]; - StringBuilder sb = new StringBuilder("insert into "); - sb.append(tableName).append('('); + StringBuilder sb = new StringBuilder("insert into "); + sb.append(tableName).append('('); - for (int i = 0; i < fieldSize; i++) { - SqlFieldValue field = fields.get(i); - sb.append(field.getName()).append(','); - params[i] = field.getValue(); - } + for (int i = 0; i < fieldSize; i++) { + SqlFieldValue field = fields.get(i); + sb.append(field.getName()).append(','); + params[i] = field.getValue(); + } - sb.setCharAt(sb.length() - 1, ')'); + sb.setCharAt(sb.length() - 1, ')'); - sb.append(" values("); + sb.append(" values("); - for (int i = 0; i < fieldSize; i++) { - sb.append("?,"); - } + for (int i = 0; i < fieldSize; i++) { + sb.append("?,"); + } - sb.setCharAt(sb.length() - 1, ')'); + sb.setCharAt(sb.length() - 1, ')'); - return dbEngine.update(sb.toString(), params); - } + return dbEngine.update(sb.toString(), params); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SelectSqlBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SelectSqlBuilder.java index 2a83149..98e3508 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SelectSqlBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SelectSqlBuilder.java @@ -5,12 +5,12 @@ import java.util.List; import java.util.function.BiFunction; public class SelectSqlBuilder extends AbstractSelectSqlBuilder { - private String tableName; - private List joinTables; + private String tableName; + private List joinTables; - SelectSqlBuilder(String tableName) { - this.tableName = tableName; - } + SelectSqlBuilder(String tableName) { + this.tableName = tableName; + } // @Override // public List query(DbEngine dbEngine, Class clazz) { @@ -25,71 +25,71 @@ public class SelectSqlBuilder extends AbstractSelectSqlBuilder { // } // } - @Override - protected void makeFields(StringBuilder sb) { - for (SqlFieldValue field: fields) { - sb.append(field.getName()).append(","); - } + @Override + protected void makeFields(StringBuilder sb) { + for (SqlFieldValue field : fields) { + sb.append(field.getName()).append(","); + } - sb.setCharAt(sb.length() - 1, ' '); - sb.append("FROM ").append(tableName); + sb.setCharAt(sb.length() - 1, ' '); + sb.append("FROM ").append(tableName); - if (joinTables != null) { - for (SqlJoinTable joinTable: joinTables) { - sb.append(joinTable.joinSql()).append(joinTable.getDbName()).append('.').append(joinTable.getTableName()) - .append(' ').append(joinTable.getTableAlias()).append(" ON("); + if (joinTables != null) { + for (SqlJoinTable joinTable : joinTables) { + sb.append(joinTable.joinSql()).append(joinTable.getDbName()).append('.').append(joinTable.getTableName()) + .append(' ').append(joinTable.getTableAlias()).append(" ON("); - boolean first = true; - for (SqlJoinField joinField: joinTable.getFields()) { - if (first) { - first = false; - } else { - sb.append(" AND "); - } + boolean first = true; + for (SqlJoinField joinField : joinTable.getFields()) { + if (first) { + first = false; + } else { + sb.append(" AND "); + } - sb.append(joinField.getKeyField()).append("=").append(joinField.getValueField()); - } + sb.append(joinField.getKeyField()).append("=").append(joinField.getValueField()); + } - sb.append(')'); - } + sb.append(')'); + } + } } - } - - @Override - public T exec(BiFunction execute) { - StringBuilder sb = new StringBuilder("select "); - Object[] params = makeParams(sb); + @Override + public T exec(BiFunction execute) { + StringBuilder sb = new StringBuilder("select "); - return execute.apply(sb.toString(), params); - } + Object[] params = makeParams(sb); - @Override - public SqlJoinTable addJoinTable(String dbName, String tableName, String tableAlias) { - if (joinTables == null) { - joinTables = new ArrayList<>(); + return execute.apply(sb.toString(), params); } - SqlJoinTable joinTable = new SqlJoinTable(); - joinTable.setDbName(dbName); - joinTable.setTableName(tableName); - joinTable.setTableAlias(tableAlias); + @Override + public SqlJoinTable addJoinTable(String dbName, String tableName, String tableAlias) { + if (joinTables == null) { + joinTables = new ArrayList<>(); + } - joinTables.add(joinTable); + SqlJoinTable joinTable = new SqlJoinTable(); + joinTable.setDbName(dbName); + joinTable.setTableName(tableName); + joinTable.setTableAlias(tableAlias); - return joinTable; - } + joinTables.add(joinTable); - @Override - public SqlJoinTable findJoinTable(String dbName, String tableName) { - if (joinTables != null) { - for (SqlJoinTable table: joinTables) { - if (dbName.equals(table.getDbName()) && tableName.equals(table.getTableName())) { - return table; - } - } + return joinTable; } - return null; - } + @Override + public SqlJoinTable findJoinTable(String dbName, String tableName) { + if (joinTables != null) { + for (SqlJoinTable table : joinTables) { + if (dbName.equals(table.getDbName()) && tableName.equals(table.getTableName())) { + return table; + } + } + } + + return null; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlBuilder.java index c4ef731..2e43f4d 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlBuilder.java @@ -5,80 +5,84 @@ import java.util.List; /** * SQL语句建造器 - * @author admin + * * @param 建造器类型 + * @author admin */ public abstract class SqlBuilder { - protected List fields = new ArrayList<>(); - protected List wheres; - - SqlBuilder() { - } - - public static InsertSqlBuilder createInsert(String tableName) { - return new InsertSqlBuilder(tableName); - } - public static UpdateSqlBuilder createUpdate(String tableName) { - return new UpdateSqlBuilder(tableName); - } - public static SelectSqlBuilder createSelect(String tableName) { - return new SelectSqlBuilder(tableName); - } - public static DeleteSqlBuilder createDelete(String tableName) { - return new DeleteSqlBuilder(tableName); - } - - public static InsertSqlBuilder createInsert(String dbName, String tableName) { - return new InsertSqlBuilder(dbName + "." + tableName); - } - - public static UpdateSqlBuilder createUpdate(String dbName, String tableName) { - return new UpdateSqlBuilder(dbName + "." + tableName); - } - - public static AbstractSelectSqlBuilder createSelect(String dbName, String tableName) { - return new SelectSqlBuilder(dbName + "." + tableName); - } - - public static AbstractSelectSqlBuilder createDirectSelect(String sql) { - return new DirectSelectSqlBuilder(sql); - } - - public static DeleteSqlBuilder createDelete(String dbName, String tableName) { - return new DeleteSqlBuilder(dbName + "." + tableName); - } - - public T add(String fieldName) { - fields.add(new SqlFieldValue(fieldName, null)); - return (T)this; - } - - public T add(String fieldName, Object fieldValue) { - fields.add(new SqlFieldValue(fieldName, fieldValue)); - return (T)this; - } - - public T addWhere(String fieldName, Object fieldValue, String op) { - if (wheres == null) { - wheres = new ArrayList<>(); - } - wheres.add(new SqlWhereValue(fieldName, fieldValue, op)); - return (T)this; - } - - public T addWhere(String fieldName, Object fieldValue) { - return addWhere(fieldName, fieldValue, "="); - } - - public T addWhereOrBegin() { - return addWhere(null, "(", " or "); - } - - public T addWhereOrEnd() { - return addWhere(null, ")", " and "); - } - - public T addOrderBy(String orderBy) { - return (T)this; - } + protected List fields = new ArrayList<>(); + protected List wheres; + + SqlBuilder() { + } + + public static InsertSqlBuilder createInsert(String tableName) { + return new InsertSqlBuilder(tableName); + } + + public static UpdateSqlBuilder createUpdate(String tableName) { + return new UpdateSqlBuilder(tableName); + } + + public static SelectSqlBuilder createSelect(String tableName) { + return new SelectSqlBuilder(tableName); + } + + public static DeleteSqlBuilder createDelete(String tableName) { + return new DeleteSqlBuilder(tableName); + } + + public static InsertSqlBuilder createInsert(String dbName, String tableName) { + return new InsertSqlBuilder(dbName + "." + tableName); + } + + public static UpdateSqlBuilder createUpdate(String dbName, String tableName) { + return new UpdateSqlBuilder(dbName + "." + tableName); + } + + public static AbstractSelectSqlBuilder createSelect(String dbName, String tableName) { + return new SelectSqlBuilder(dbName + "." + tableName); + } + + public static AbstractSelectSqlBuilder createDirectSelect(String sql) { + return new DirectSelectSqlBuilder(sql); + } + + public static DeleteSqlBuilder createDelete(String dbName, String tableName) { + return new DeleteSqlBuilder(dbName + "." + tableName); + } + + public T add(String fieldName) { + fields.add(new SqlFieldValue(fieldName, null)); + return (T) this; + } + + public T add(String fieldName, Object fieldValue) { + fields.add(new SqlFieldValue(fieldName, fieldValue)); + return (T) this; + } + + public T addWhere(String fieldName, Object fieldValue, String op) { + if (wheres == null) { + wheres = new ArrayList<>(); + } + wheres.add(new SqlWhereValue(fieldName, fieldValue, op)); + return (T) this; + } + + public T addWhere(String fieldName, Object fieldValue) { + return addWhere(fieldName, fieldValue, "="); + } + + public T addWhereOrBegin() { + return addWhere(null, "(", " or "); + } + + public T addWhereOrEnd() { + return addWhere(null, ")", " and "); + } + + public T addOrderBy(String orderBy) { + return (T) this; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlFieldValue.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlFieldValue.java index 50ee584..db46a62 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlFieldValue.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlFieldValue.java @@ -4,11 +4,11 @@ import lombok.Getter; @Getter class SqlFieldValue { - private final String name; - private final Object value; + private final String name; + private final Object value; - public SqlFieldValue(String name, Object value) { - this.name = name; - this.value = value; - } + public SqlFieldValue(String name, Object value) { + this.name = name; + this.value = value; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlJoinField.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlJoinField.java index e9ecfce..fbf7e11 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlJoinField.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlJoinField.java @@ -4,11 +4,11 @@ import lombok.Getter; @Getter public class SqlJoinField { - private String keyField; - private String valueField; + private String keyField; + private String valueField; - public SqlJoinField(String keyField, String valueField) { - this.keyField = keyField; - this.valueField = valueField; - } + public SqlJoinField(String keyField, String valueField) { + this.keyField = keyField; + this.valueField = valueField; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlJoinTable.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlJoinTable.java index a5bc154..c01aef2 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlJoinTable.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlJoinTable.java @@ -7,33 +7,38 @@ import java.util.List; /** * SelectSqlBuilder使用的查询关联表 + * * @author xkliu */ @Data public class SqlJoinTable { - public static final int LEFT_JOIN = 1; - public static final int RIGHT_JOIN = 2; - public static final int INNER_JOIN = 3; - public static final int FULL_JOIN = 4; + public static final int LEFT_JOIN = 1; + public static final int RIGHT_JOIN = 2; + public static final int INNER_JOIN = 3; + public static final int FULL_JOIN = 4; - private int joinType = LEFT_JOIN; - private String dbName; - private String tableName; - private String tableAlias; + private int joinType = LEFT_JOIN; + private String dbName; + private String tableName; + private String tableAlias; - private List fields = new ArrayList<>(); + private List fields = new ArrayList<>(); - public void add(String keyField, String valueField) { - fields.add(new SqlJoinField(keyField, valueField)); - } + public void add(String keyField, String valueField) { + fields.add(new SqlJoinField(keyField, valueField)); + } - public String joinSql() { - switch (joinType) { - default: - case LEFT_JOIN: return " LEFT JOIN "; - case RIGHT_JOIN: return " RIGHT JOIN "; - case INNER_JOIN: return " INNER JOIN "; - case FULL_JOIN: return " FULL JOIN "; + public String joinSql() { + switch (joinType) { + default: + case LEFT_JOIN: + return " LEFT JOIN "; + case RIGHT_JOIN: + return " RIGHT JOIN "; + case INNER_JOIN: + return " INNER JOIN "; + case FULL_JOIN: + return " FULL JOIN "; + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlWhereValue.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlWhereValue.java index d3a9360..c9b11a6 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlWhereValue.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/SqlWhereValue.java @@ -3,11 +3,11 @@ package cc.smtweb.framework.core.db.sqlbuilder; import lombok.Getter; class SqlWhereValue extends SqlFieldValue { - @Getter - private String op; + @Getter + private String op; - public SqlWhereValue(String name, Object value, String op) { - super(name, value); - this.op = op; - } + public SqlWhereValue(String name, Object value, String op) { + super(name, value); + this.op = op; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/UpdateSqlBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/UpdateSqlBuilder.java index e7c638a..c1edf51 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/UpdateSqlBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/sqlbuilder/UpdateSqlBuilder.java @@ -6,50 +6,50 @@ import java.util.ArrayList; import java.util.List; public class UpdateSqlBuilder extends AbstractUpdateSqlBuilder { - private String tableName; + private String tableName; - UpdateSqlBuilder(String tableName) { - this.tableName = tableName; - } + UpdateSqlBuilder(String tableName) { + this.tableName = tableName; + } - @Override - public int update(JdbcEngine dbEngine) { - int fieldSize = fields.size() + wheres.size(); - List params = new ArrayList<>(fieldSize); + @Override + public int update(JdbcEngine dbEngine) { + int fieldSize = fields.size() + wheres.size(); + List params = new ArrayList<>(fieldSize); // Object[] params = new Object[fieldSize]; - StringBuilder sb = new StringBuilder("update "); + StringBuilder sb = new StringBuilder("update "); - sb.append(tableName).append(" set "); + sb.append(tableName).append(" set "); // int index = 0; - for (SqlFieldValue field: fields) { - if (field.getValue() == VALUE_INVALID) { - sb.append(field.getName()); - } else { - sb.append(field.getName()).append("=?,"); - params.add(field.getValue()); - } + for (SqlFieldValue field : fields) { + if (field.getValue() == VALUE_INVALID) { + sb.append(field.getName()); + } else { + sb.append(field.getName()).append("=?,"); + params.add(field.getValue()); + } // params[index] = field.getValue(); // index++; - } - - sb.setCharAt(sb.length() - 1, ' '); - sb.append("where "); - - boolean first = true; - for (SqlWhereValue whereValue: wheres) { - if (first) { - first = false; - } else { - sb.append(" and "); - } - sb.append(whereValue.getName()).append("=?"); - params.add(whereValue.getValue()); + } + + sb.setCharAt(sb.length() - 1, ' '); + sb.append("where "); + + boolean first = true; + for (SqlWhereValue whereValue : wheres) { + if (first) { + first = false; + } else { + sb.append(" and "); + } + sb.append(whereValue.getName()).append("=?"); + params.add(whereValue.getValue()); // params[index] // index++; - } + } - return dbEngine.update(sb.toString(), params.toArray()); - } + return dbEngine.update(sb.toString(), params.toArray()); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCache.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCache.java index edd4d1b..4e36823 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCache.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelCache.java @@ -23,6 +23,6 @@ public class ModelCache { private String type; public boolean isMapType() { - return CACHE_TYPE_MAP.equalsIgnoreCase(type); + return CACHE_TYPE_MAP.equalsIgnoreCase(type); } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelField.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelField.java index 0263245..77325f9 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelField.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelField.java @@ -33,6 +33,7 @@ public class ModelField { private long link; //控件类型:TEXT/TextArea/NUMBER/COMBO private String editor; + @JsonIgnore public boolean isNotNull() { return notNull == 1; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelTable.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelTable.java index d37c5f8..b61f545 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelTable.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/vo/ModelTable.java @@ -178,7 +178,7 @@ public class ModelTable extends DefaultEntity { public String findFieldTitle(String fieldName) { ModelField field = findField(fieldName); - return field != null ? field.getTitle() : fieldName; + return field != null ? field.getTitle(): fieldName; } public String fullName() { @@ -253,7 +253,7 @@ public class ModelTable extends DefaultEntity { public List findLinkeNames() { List list = new ArrayList<>(); for (ModelField field : fields) { - if (field.getLink()<=0) { + if (field.getLink() <= 0) { continue; } ModelTable linkTable = ModelTableCache.getInstance().get(field.getLink()); @@ -286,7 +286,8 @@ public class ModelTable extends DefaultEntity { public String getSchemaTableName() { String dbName = getDbName(); - if (StringUtils.isEmpty(dbName) || dbName.equals(SwConsts.DEF_DB_NAME)) return DbEngine.getInstance().getDbSchema() + "." + getName(); + if (StringUtils.isEmpty(dbName) || dbName.equals(SwConsts.DEF_DB_NAME)) + return DbEngine.getInstance().getDbSchema() + "." + getName(); return DbEngine.getInstance().getDbSchema() + "_" + dbName + "." + getName(); } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BindBeanException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BindBeanException.java index 0168e3a..aa0d5f9 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BindBeanException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BindBeanException.java @@ -2,38 +2,38 @@ package cc.smtweb.framework.core.exception; /** * bean绑定错误 + * * @author kevin * @since 2010-9-14 上午11:17:43 - * */ public class BindBeanException extends SwException { - /** - * - */ - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = 1L; - private static String msg = "绑定bean异常:Context中已经存在这个bean: "; + private static String msg = "绑定bean异常:Context中已经存在这个bean: "; - public BindBeanException() { - super(); - // TODO Auto-generated constructor stub - } + public BindBeanException() { + super(); + // TODO Auto-generated constructor stub + } - public BindBeanException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub - } + public BindBeanException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } - public BindBeanException(String message) { + public BindBeanException(String message) { - super(msg+message); - // TODO Auto-generated constructor stub - } + super(msg + message); + // TODO Auto-generated constructor stub + } - public BindBeanException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub - } + public BindBeanException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BindParamException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BindParamException.java index 678c044..fd149de 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BindParamException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BindParamException.java @@ -3,30 +3,30 @@ package cc.smtweb.framework.core.exception; import java.text.ParseException; public class BindParamException extends SwException { - /** - * - */ - private static final long serialVersionUID = 1L; - private String paramName; + /** + * + */ + private static final long serialVersionUID = 1L; + private String paramName; - public String getParamName() { - return paramName; - } + public String getParamName() { + return paramName; + } - public BindParamException(String message, String paramName) { - this(message, null, paramName); - } + public BindParamException(String message, String paramName) { + this(message, null, paramName); + } - public BindParamException(Exception e, String paramName) { - this(e.getMessage(), e, paramName); - } + public BindParamException(Exception e, String paramName) { + this(e.getMessage(), e, paramName); + } - public BindParamException(String message, Exception e, String paramName) { - super("[" + paramName + "]" + message, e); - this.paramName = paramName; - } + public BindParamException(String message, Exception e, String paramName) { + super("[" + paramName + "]" + message, e); + this.paramName = paramName; + } - public BindParamException(ParseException e) { - super(e); - } + public BindParamException(ParseException e) { + super(e); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BizException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BizException.java index 0fbb71a..fe097be 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BizException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/BizException.java @@ -2,28 +2,28 @@ package cc.smtweb.framework.core.exception; /** * 业务异常 - * @author kevin * + * @author kevin */ public class BizException extends RuntimeException { - /** - * - */ - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = 1L; - public BizException() { - super(); - } + public BizException() { + super(); + } - public BizException(String message, Throwable cause) { - super(message, cause); - } + public BizException(String message, Throwable cause) { + super(message, cause); + } - public BizException(String message) { - super(message); - } + public BizException(String message) { + super(message); + } - public BizException(Throwable cause) { - super(cause.getMessage(), cause); - } + public BizException(Throwable cause) { + super(cause.getMessage(), cause); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/DbException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/DbException.java index 5ca0635..07597a3 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/DbException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/DbException.java @@ -2,30 +2,30 @@ package cc.smtweb.framework.core.exception; /** * bean绑定错误 + * * @author kevin * @since 2010-9-14 上午11:17:43 - * */ public class DbException extends RuntimeException { - /** - * - */ - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = 1L; - public DbException() { - super(); - } + public DbException() { + super(); + } - public DbException(String message, Throwable cause) { - super(message, cause); - } + public DbException(String message, Throwable cause) { + super(message, cause); + } - public DbException(String message) { - super(message); - } + public DbException(String message) { + super(message); + } - public DbException(Throwable cause) { - super(cause.getMessage(), cause); - } + public DbException(Throwable cause) { + super(cause.getMessage(), cause); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/JsonParseException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/JsonParseException.java index 22fc5bf..fa679d9 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/JsonParseException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/JsonParseException.java @@ -1,7 +1,7 @@ package cc.smtweb.framework.core.exception; public class JsonParseException extends SwException { - public JsonParseException(String s, Exception e) { - super(s, e); - } + public JsonParseException(String s, Exception e) { + super(s, e); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/SwException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/SwException.java index 50306a5..752ad9c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/SwException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/exception/SwException.java @@ -1,7 +1,5 @@ package cc.smtweb.framework.core.exception; -import cc.smtweb.framework.core.exception.ExceptionMessage; - /** * 〈全局异常〉 * diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/ISchedulerWakeup.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/ISchedulerWakeup.java index 0cfd153..237a1cd 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/ISchedulerWakeup.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/ISchedulerWakeup.java @@ -2,14 +2,16 @@ package cc.smtweb.framework.core.mvc; /** * 定时任务唤醒服务接口 + * * @author xkliu */ public interface ISchedulerWakeup { - /** - * 唤醒定时任务立即执行 - * @param clazz 包含定时任务方法的类名 - * @param methodName 有定时任务注解的方法名 - * @return 是否唤醒请求成功 - */ - boolean wakeup(Class clazz, String methodName); + /** + * 唤醒定时任务立即执行 + * + * @param clazz 包含定时任务方法的类名 + * @param methodName 有定时任务注解的方法名 + * @return 是否唤醒请求成功 + */ + boolean wakeup(Class clazz, String methodName); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/SchedulerManager.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/SchedulerManager.java index 5baf5aa..8e3b53e 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/SchedulerManager.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/SchedulerManager.java @@ -4,26 +4,28 @@ import org.springframework.stereotype.Component; /** * 定时器服务 + * * @author xkliu */ @Component public class SchedulerManager { - private ISchedulerWakeup schedulerWakeup; + private ISchedulerWakeup schedulerWakeup; - public void install(ISchedulerWakeup schedulerWakeup) { - this.schedulerWakeup = schedulerWakeup; - } - - /** - * 唤醒定时器立即执行 - * @param clazz 定时器类 - * @param methodName 有@SwScheduling注解的定时器方法名 - */ - public boolean wakeup(Class clazz, String methodName) { - if (this.schedulerWakeup != null) { - return schedulerWakeup.wakeup(clazz, methodName); + public void install(ISchedulerWakeup schedulerWakeup) { + this.schedulerWakeup = schedulerWakeup; } - return false; - } + /** + * 唤醒定时器立即执行 + * + * @param clazz 定时器类 + * @param methodName 有@SwScheduling注解的定时器方法名 + */ + public boolean wakeup(Class clazz, String methodName) { + if (this.schedulerWakeup != null) { + return schedulerWakeup.wakeup(clazz, methodName); + } + + return false; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/ControllerConfig.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/ControllerConfig.java index a36f7bd..0347438 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/ControllerConfig.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/ControllerConfig.java @@ -5,20 +5,24 @@ import lombok.Getter; @Getter public class ControllerConfig { - /** 模块名称 */ - private final String module; - /** 控制器的包路径 */ - private final String packagePath; + /** + * 模块名称 + */ + private final String module; + /** + * 控制器的包路径 + */ + private final String packagePath; - private IScanActionBuilder scanActionBuilder; + private IScanActionBuilder scanActionBuilder; - public ControllerConfig(String module, String packagePath) { - this(module, packagePath, null); - } + public ControllerConfig(String module, String packagePath) { + this(module, packagePath, null); + } - public ControllerConfig(String module, String packagePath, IScanActionBuilder scanActionBuilder) { - this.module = module; - this.packagePath = packagePath; - this.scanActionBuilder = scanActionBuilder; - } + public ControllerConfig(String module, String packagePath, IScanActionBuilder scanActionBuilder) { + this.module = module; + this.packagePath = packagePath; + this.scanActionBuilder = scanActionBuilder; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/GlobalExceptionHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/GlobalExceptionHandler.java index 6737ab9..e8d6055 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/GlobalExceptionHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/GlobalExceptionHandler.java @@ -70,7 +70,7 @@ public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public R handleException(Exception ex) { Throwable e = ex; - if (ex instanceof java.lang.reflect.InvocationTargetException) { + if (ex instanceof java.lang.reflect.InvocationTargetException) { e = ex.getCause(); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/SettingsEnvironmentPostProcessor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/SettingsEnvironmentPostProcessor.java index e31d3a9..72fdbdf 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/SettingsEnvironmentPostProcessor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/SettingsEnvironmentPostProcessor.java @@ -21,7 +21,7 @@ public class SettingsEnvironmentPostProcessor implements EnvironmentPostProcesso @Override public void postProcessEnvironment(ConfigurableEnvironment configurableEnvironment, - SpringApplication springApplication) { + SpringApplication springApplication) { List files = this.getProperties(); for (File file : files) { if (file.exists()) { @@ -30,7 +30,7 @@ public class SettingsEnvironmentPostProcessor implements EnvironmentPostProcesso yaml.setResources(resource); if (yaml.getObject() != null) { configurableEnvironment.getPropertySources() - .addLast(new PropertiesPropertySource(file.getName(), yaml.getObject())); + .addLast(new PropertiesPropertySource(file.getName(), yaml.getObject())); } } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/WebMvcConfig.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/WebMvcConfig.java index 11369d7..83c4bb1 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/WebMvcConfig.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/config/WebMvcConfig.java @@ -71,10 +71,10 @@ public class WebMvcConfig implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { // 2.4 以前使用 .allowedOrigins("*") registry.addMapping("/**") - .allowedOriginPatterns("*") - .allowedMethods("*") - .maxAge(3600) - .allowCredentials(true); + .allowedOriginPatterns("*") + .allowedMethods("*") + .maxAge(3600) + .allowCredentials(true); } @Bean diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiConfigBean.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiConfigBean.java index 2d69275..67a8484 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiConfigBean.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiConfigBean.java @@ -6,16 +6,17 @@ import org.springframework.stereotype.Component; /** * API相关配置参数 + * * @author xkliu */ @Component @ConfigurationProperties(prefix = "smtweb.api") @Data public class ApiConfigBean { - // JSON是否输出非空字段 - private boolean jsonFull; - // 是否支持大驼峰url匹配规则 - private boolean lowerCaseUrl; - // 是否支持大驼峰url匹配规则,默认都支持 little camel-case - private boolean bigCameCaseUrl; + // JSON是否输出非空字段 + private boolean jsonFull; + // 是否支持大驼峰url匹配规则 + private boolean lowerCaseUrl; + // 是否支持大驼峰url匹配规则,默认都支持 little camel-case + private boolean bigCameCaseUrl; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiController.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiController.java index 61be1cc..b21fd05 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiController.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiController.java @@ -11,50 +11,53 @@ import java.util.Map; /** * API接口控制器,所有API的入口 + * * @author xkliu */ @RestController public class ApiController { - @Autowired - private MethodAccessManager methodAccessManager; + @Autowired + private MethodAccessManager methodAccessManager; - /** - * 处理API的GET请求 - * @param params URL请求参数 - * @param request Http请求类 - * @param response Http应答类 - * @return 返回对象,一般在函数里面使用R - * @throws Exception API处理异常 - */ - @GetMapping(value = "/api/**", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}) - public Object commonGet(@RequestParam Map params, - HttpServletRequest request, HttpServletResponse response) throws Exception { - String apiUrl = request.getServletPath().substring(5); - return methodAccessManager.invoke(apiUrl, params, null, request, response); - } + /** + * 处理API的GET请求 + * + * @param params URL请求参数 + * @param request Http请求类 + * @param response Http应答类 + * @return 返回对象,一般在函数里面使用R + * @throws Exception API处理异常 + */ + @GetMapping(value = "/api/**", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}) + public Object commonGet(@RequestParam Map params, + HttpServletRequest request, HttpServletResponse response) throws Exception { + String apiUrl = request.getServletPath().substring(5); + return methodAccessManager.invoke(apiUrl, params, null, request, response); + } - /** - * 处理API的POST请求 - * @param params URL请求参数 - * @param body POST内容,JSON格式 - * @param request Http请求类 - * @param response Http应答类 - * @return 返回对象,一般在函数里面使用R - * @throws Exception API处理异常 - */ - @PostMapping(value = "/api/**", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}) - public Object commonPost(@RequestParam Map params, @RequestBody(required = false) String body, - HttpServletRequest request, HttpServletResponse response) throws Exception { - String apiUrl = request.getServletPath().substring(5); - // 保证body在post的清空下不为null,用于区分get时吧参数组合成body - if (body == null) { - body = ""; + /** + * 处理API的POST请求 + * + * @param params URL请求参数 + * @param body POST内容,JSON格式 + * @param request Http请求类 + * @param response Http应答类 + * @return 返回对象,一般在函数里面使用R + * @throws Exception API处理异常 + */ + @PostMapping(value = "/api/**", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}) + public Object commonPost(@RequestParam Map params, @RequestBody(required = false) String body, + HttpServletRequest request, HttpServletResponse response) throws Exception { + String apiUrl = request.getServletPath().substring(5); + // 保证body在post的清空下不为null,用于区分get时吧参数组合成body + if (body == null) { + body = ""; + } + return methodAccessManager.invoke(apiUrl, params, body, request, response); } - return methodAccessManager.invoke(apiUrl, params, body, request, response); - } - @PreDestroy - public void fin() { - methodAccessManager.showdown(); - } + @PreDestroy + public void fin() { + methodAccessManager.showdown(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/DefaultPageController.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/DefaultPageController.java index 1f2fa7d..9aa2715 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/DefaultPageController.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/DefaultPageController.java @@ -5,25 +5,28 @@ import org.springframework.web.bind.annotation.GetMapping; /** * 默认静态页面处理 + * * @author xkliu */ @Controller public class DefaultPageController { - /** - * 重定向默认静态页面 - * @return 静态页面重定向路径 - */ - @GetMapping("/") - public String index() { - return "forward:/static/index.html"; - } + /** + * 重定向默认静态页面 + * + * @return 静态页面重定向路径 + */ + @GetMapping("/") + public String index() { + return "forward:/static/index.html"; + } - /** - * 重定向默认网站图标 - * @return 网站图标重定向路径 - */ - @GetMapping(value = "/favicon.ico") - public String favicon() { - return "forward:/static/favicon.ico"; - } + /** + * 重定向默认网站图标 + * + * @return 网站图标重定向路径 + */ + @GetMapping(value = "/favicon.ico") + public String favicon() { + return "forward:/static/favicon.ico"; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IActionManager.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IActionManager.java index 63ca1ca..1144acf 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IActionManager.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IActionManager.java @@ -3,5 +3,5 @@ package cc.smtweb.framework.core.mvc.controller; import cc.smtweb.framework.core.mvc.controller.access.IMethodAccess; public interface IActionManager { - boolean api(String url, IMethodAccess methodAccess); + boolean api(String url, IMethodAccess methodAccess); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IBeanContext.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IBeanContext.java index 9746ee7..701b4ff 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IBeanContext.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IBeanContext.java @@ -3,6 +3,7 @@ package cc.smtweb.framework.core.mvc.controller; import org.springframework.beans.BeansException; public interface IBeanContext { - T getBean(String name, Class type) throws BeansException; - T getBean(Class type) throws BeansException; + T getBean(String name, Class type) throws BeansException; + + T getBean(Class type) throws BeansException; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IEditor.java index 8eff0d7..df906ba 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IEditor.java @@ -5,23 +5,25 @@ import java.util.Map; /** * API参数解析器接口 + * * @author xkliu */ public interface IEditor { - String USER_SESSION = "_SW_USER_SESSION"; - String USER_TOKEN = "_SW_TOKEN"; - String BODY_MAP = "_SW_BODY_MAP"; + String USER_SESSION = "_SW_USER_SESSION"; + String USER_TOKEN = "_SW_TOKEN"; + String BODY_MAP = "_SW_BODY_MAP"; // String BODY_BEAN = "_SW_BODY_BEAN"; - /** - * 根据请求参数转为函数参数定义的类型的值 - * @param paramName 参数名 - * @param paramType 参数类型 - * @param context 全局bean对象上下文 - * @param params URL请求参数(query) - * @param body POST内容 - * @param request http请求 - * @return 转化后的值 - */ - Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request); + /** + * 根据请求参数转为函数参数定义的类型的值 + * + * @param paramName 参数名 + * @param paramType 参数类型 + * @param context 全局bean对象上下文 + * @param params URL请求参数(query) + * @param body POST内容 + * @param request http请求 + * @return 转化后的值 + */ + Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IStartListener.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IStartListener.java index 901b4a0..8eed93c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IStartListener.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/IStartListener.java @@ -7,8 +7,10 @@ package cc.smtweb.framework.core.mvc.controller; public interface IStartListener { //启动执行顺序 int order(); + //初始化设置,一般为设置参数配置 void init(); + //启动事件 void run(); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/BindFieldAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/BindFieldAccess.java index 482b0df..f7229bb 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/BindFieldAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/BindFieldAccess.java @@ -7,21 +7,21 @@ import java.lang.reflect.Field; import java.util.Map; public class BindFieldAccess extends FieldAccess { - private IEditor editor; - private final String beanName; + private IEditor editor; + private final String beanName; - public BindFieldAccess(IEditor editor, Field field, String beanName) { - super(field); - this.editor = editor; - this.beanName = beanName; - } - - @Override - protected Object getFieldValue(Object instance, IBeanContext context, Map params) { - if (editor != null) { - return editor.getParamValue(beanName, this.field.getType(), context, params, null, null); + public BindFieldAccess(IEditor editor, Field field, String beanName) { + super(field); + this.editor = editor; + this.beanName = beanName; } - return null; - } + @Override + protected Object getFieldValue(Object instance, IBeanContext context, Map params) { + if (editor != null) { + return editor.getParamValue(beanName, this.field.getType(), context, params, null, null); + } + + return null; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/ControllerAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/ControllerAccess.java index dc61fff..ae4cc5c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/ControllerAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/ControllerAccess.java @@ -7,63 +7,65 @@ import lombok.extern.slf4j.Slf4j; import java.util.List; import java.util.Map; -/** 控制器访问类 */ +/** + * 控制器访问类 + */ @Slf4j public class ControllerAccess implements IBeanAccess { - private final Class clazz; - private final List fieldList; - @Getter - private final boolean singleton; - @Getter - private Object singletonInstance; + private final Class clazz; + private final List fieldList; + @Getter + private final boolean singleton; + @Getter + private Object singletonInstance; - public ControllerAccess(Class clazz, List fieldList, boolean singleton) { - this.clazz = clazz; - this.fieldList = fieldList; - this.singleton = singleton; - } + public ControllerAccess(Class clazz, List fieldList, boolean singleton) { + this.clazz = clazz; + this.fieldList = fieldList; + this.singleton = singleton; + } - public String getFullName() { - return clazz.getName(); - } + public String getFullName() { + return clazz.getName(); + } - public Object getOrNewInstance(IBeanContext context, Map params) throws IllegalAccessException, InstantiationException { - if (singletonInstance != null) { - return singletonInstance; - } else { - Object result = clazz.newInstance(); + public Object getOrNewInstance(IBeanContext context, Map params) throws IllegalAccessException, InstantiationException { + if (singletonInstance != null) { + return singletonInstance; + } else { + Object result = clazz.newInstance(); - writeBeanFields(result, context, params); + writeBeanFields(result, context, params); - return result; + return result; + } } - } - private void writeBeanFields(Object bean, IBeanContext context, Map params) { - for (FieldAccess fieldAccess: fieldList) { - boolean ret = fieldAccess.writeValue(bean, context, params); - if (!ret) { - log.error("write bean " + fieldAccess.getFullName(bean) - + " failure."); - } + private void writeBeanFields(Object bean, IBeanContext context, Map params) { + for (FieldAccess fieldAccess : fieldList) { + boolean ret = fieldAccess.writeValue(bean, context, params); + if (!ret) { + log.error("write bean " + fieldAccess.getFullName(bean) + + " failure."); + } + } } - } - public Object initSingletonFields(IBeanContext context, Map params) { - if (singletonInstance != null) { - writeBeanFields(singletonInstance, context, params); - } + public Object initSingletonFields(IBeanContext context, Map params) { + if (singletonInstance != null) { + writeBeanFields(singletonInstance, context, params); + } - return singletonInstance; - } + return singletonInstance; + } - public Class getBeanType() { - return clazz; - } + public Class getBeanType() { + return clazz; + } - public void newSingletonInstance() throws IllegalAccessException, InstantiationException { - if (isSingleton()) { - this.singletonInstance = clazz.newInstance(); + public void newSingletonInstance() throws IllegalAccessException, InstantiationException { + if (isSingleton()) { + this.singletonInstance = clazz.newInstance(); + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/FieldAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/FieldAccess.java index 392ec6e..8496a0d 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/FieldAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/FieldAccess.java @@ -7,33 +7,33 @@ import java.lang.reflect.Field; import java.util.Map; public abstract class FieldAccess { - protected final Field field; + protected final Field field; - public FieldAccess(Field field) { - this.field = field; - } + public FieldAccess(Field field) { + this.field = field; + } - protected abstract Object getFieldValue(Object instance, IBeanContext context, Map params); + protected abstract Object getFieldValue(Object instance, IBeanContext context, Map params); - public boolean writeValue(Object instance, IBeanContext context, Map params) { - Object bean = getFieldValue(instance, context, params); + public boolean writeValue(Object instance, IBeanContext context, Map params) { + Object bean = getFieldValue(instance, context, params); - if (bean != null) { - field.setAccessible(true); + if (bean != null) { + field.setAccessible(true); - try { - field.set(instance, bean); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new BindBeanException("not set " + getFullName(instance) + " value", e); - } + try { + field.set(instance, bean); + } catch (IllegalArgumentException | IllegalAccessException e) { + throw new BindBeanException("not set " + getFullName(instance) + " value", e); + } - return true; - } + return true; + } - return false; - } + return false; + } - public String getFullName(Object instance) { - return instance.getClass().getName() + "." + field.getName(); - } + public String getFullName(Object instance) { + return instance.getClass().getName() + "." + field.getName(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/IBeanAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/IBeanAccess.java index 17c8fc3..d769440 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/IBeanAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/IBeanAccess.java @@ -1,5 +1,5 @@ package cc.smtweb.framework.core.mvc.controller.access; public interface IBeanAccess { - Object getSingletonInstance(); + Object getSingletonInstance(); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/IMethodAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/IMethodAccess.java index b070db5..ddfef8c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/IMethodAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/IMethodAccess.java @@ -7,44 +7,49 @@ import java.util.Map; /** * API方法访问接口 + * * @author xkliu */ public interface IMethodAccess { - // 方法返回值Java类型 - Class getReturnType(); - - // @SwBody 注解Java类型 - Class getBodyType(); - - // @SwAttr 注解Java类型 - Class getAttrType(String paramName); - - /** - * 执行反射的API函数,一般时定时器等无参数环境调用 - * @param context 对象上下文 - * @return API函数返回值 - */ - Object invoke(IBeanContext context); - - /** - * 执行类方法,实现API调用 - * @param context 上下文对象,包括springboot服务类,@SwBean类 - * @param params url请求参数map - * @param body post请求的内容 - * @param request HTTP请求对象 - * @return 应答对象,一般是返回R转换为json返回 - */ - Object invoke(IBeanContext context, Map params, String body, HttpServletRequest request); - - /** - * 输出错误信息用,方法全名 - * @return 方法全名 - */ - String fullName(); - - /** - * API权限 - * @return 权限串 - */ - String getPerm(); + // 方法返回值Java类型 + Class getReturnType(); + + // @SwBody 注解Java类型 + Class getBodyType(); + + // @SwAttr 注解Java类型 + Class getAttrType(String paramName); + + /** + * 执行反射的API函数,一般时定时器等无参数环境调用 + * + * @param context 对象上下文 + * @return API函数返回值 + */ + Object invoke(IBeanContext context); + + /** + * 执行类方法,实现API调用 + * + * @param context 上下文对象,包括springboot服务类,@SwBean类 + * @param params url请求参数map + * @param body post请求的内容 + * @param request HTTP请求对象 + * @return 应答对象,一般是返回R转换为json返回 + */ + Object invoke(IBeanContext context, Map params, String body, HttpServletRequest request); + + /** + * 输出错误信息用,方法全名 + * + * @return 方法全名 + */ + String fullName(); + + /** + * API权限 + * + * @return 权限串 + */ + String getPerm(); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/MethodAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/MethodAccess.java index 3ec44b1..e322bcd 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/MethodAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/MethodAccess.java @@ -1,9 +1,9 @@ package cc.smtweb.framework.core.mvc.controller.access; import cc.smtweb.framework.core.common.R; +import cc.smtweb.framework.core.exception.BindBeanException; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.exception.SwException; -import cc.smtweb.framework.core.exception.BindBeanException; import cc.smtweb.framework.core.mvc.controller.IBeanContext; import cc.smtweb.framework.core.mvc.controller.binder.ParamEditor; import lombok.Getter; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/MethodParamAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/MethodParamAccess.java index 800c24a..eb66801 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/MethodParamAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/MethodParamAccess.java @@ -9,34 +9,35 @@ import java.util.Map; /** * API方法参数访问器 + * * @author xkliu */ @Getter public class MethodParamAccess { - private int bindType; - private final IEditor editor; - private final String paramName; - private final Class collectionType; - private final Class paramType; + private int bindType; + private final IEditor editor; + private final String paramName; + private final Class collectionType; + private final Class paramType; - public MethodParamAccess(IEditor editor, String paramName, Class paramType, int bindType, Class collectionType) { - this.editor = editor; - this.paramName = paramName; - this.paramType = paramType; - this.bindType = bindType; - this.collectionType = collectionType; - } - - public Object getParamValue(IBeanContext context, Map params, String body, HttpServletRequest request) { - if (editor != null) { - return editor.getParamValue(paramName, paramType, context, params, body, request); + public MethodParamAccess(IEditor editor, String paramName, Class paramType, int bindType, Class collectionType) { + this.editor = editor; + this.paramName = paramName; + this.paramType = paramType; + this.bindType = bindType; + this.collectionType = collectionType; } - return null; - } + public Object getParamValue(IBeanContext context, Map params, String body, HttpServletRequest request) { + if (editor != null) { + return editor.getParamValue(paramName, paramType, context, params, body, request); + } + + return null; + } - @Override - public String toString() { - return paramName + ":" + paramType.getSimpleName() + "-" + editor.getClass().getSimpleName(); - } + @Override + public String toString() { + return paramName + ":" + paramType.getSimpleName() + "-" + editor.getClass().getSimpleName(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/SchedulerMethodAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/SchedulerMethodAccess.java index 6104a6a..e4236ed 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/SchedulerMethodAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/SchedulerMethodAccess.java @@ -9,13 +9,13 @@ import java.text.ParseException; @Getter public class SchedulerMethodAccess { - private final MethodAccess methodAccess; - private final SwScheduling swScheduling; - private final TimerTrigger timerTrigger; + private final MethodAccess methodAccess; + private final SwScheduling swScheduling; + private final TimerTrigger timerTrigger; - public SchedulerMethodAccess(MethodAccess methodAccess, SwScheduling swScheduling) throws ParseException { - this.timerTrigger = new CronTimerTrigger(swScheduling.value()); - this.methodAccess = methodAccess; - this.swScheduling = swScheduling; - } + public SchedulerMethodAccess(MethodAccess methodAccess, SwScheduling swScheduling) throws ParseException { + this.timerTrigger = new CronTimerTrigger(swScheduling.value()); + this.methodAccess = methodAccess; + this.swScheduling = swScheduling; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/SingletonFieldAccess.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/SingletonFieldAccess.java index 88a5d7f..d9de590 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/SingletonFieldAccess.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/access/SingletonFieldAccess.java @@ -6,15 +6,15 @@ import java.lang.reflect.Field; import java.util.Map; public class SingletonFieldAccess extends FieldAccess { - private final Object fieldValue; + private final Object fieldValue; - public SingletonFieldAccess(Object fieldValue, Field field) { - super(field); - this.fieldValue = fieldValue; - } + public SingletonFieldAccess(Object fieldValue, Field field) { + super(field); + this.fieldValue = fieldValue; + } - @Override - protected Object getFieldValue(Object instance, IBeanContext context, Map params) { - return fieldValue; - } + @Override + protected Object getFieldValue(Object instance, IBeanContext context, Map params) { + return fieldValue; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/BeanContext.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/BeanContext.java index 7510494..7ade57f 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/BeanContext.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/BeanContext.java @@ -7,41 +7,41 @@ import org.springframework.beans.factory.BeanFactory; import java.util.Map; public class BeanContext implements IBeanContext { - private final Map, Object> beanMap; - private final BeanFactory applicationContext; - - public BeanContext(Map, Object> beanMap, BeanFactory applicationContext) { - this.beanMap = beanMap; - this.applicationContext = applicationContext; - } - - @Override - public T getBean(String name, Class type) throws BeansException { - Object controllerAccess = beanMap.get(type); - - if (controllerAccess == null) { - return applicationContext.getBean(name, type); - } else { - return (T)controllerAccess; + private final Map, Object> beanMap; + private final BeanFactory applicationContext; + + public BeanContext(Map, Object> beanMap, BeanFactory applicationContext) { + this.beanMap = beanMap; + this.applicationContext = applicationContext; } - } - @Override - public T getBean(Class type) throws BeansException { - Object controllerAccess = beanMap.get(type); + @Override + public T getBean(String name, Class type) throws BeansException { + Object controllerAccess = beanMap.get(type); - if (controllerAccess != null) { - return (T) controllerAccess; + if (controllerAccess == null) { + return applicationContext.getBean(name, type); + } else { + return (T) controllerAccess; + } } - controllerAccess = applicationContext.getBean(type); - if (controllerAccess != null) { - return (T) controllerAccess; - } + @Override + public T getBean(Class type) throws BeansException { + Object controllerAccess = beanMap.get(type); + + if (controllerAccess != null) { + return (T) controllerAccess; + } - return null; - } + controllerAccess = applicationContext.getBean(type); + if (controllerAccess != null) { + return (T) controllerAccess; + } - public void init() { - } + return null; + } + + public void init() { + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/CacheEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/CacheEditor.java index cc67d88..2c5a77f 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/CacheEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/CacheEditor.java @@ -9,18 +9,18 @@ import javax.servlet.http.HttpServletRequest; import java.util.Map; public class CacheEditor implements IEditor { - private CacheManager cacheManager; + private CacheManager cacheManager; - public CacheEditor(CacheManager cacheManager) { - this.cacheManager = cacheManager; - } + public CacheEditor(CacheManager cacheManager) { + this.cacheManager = cacheManager; + } - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - if (StringUtils.isNotBlank(paramName)) { - return cacheManager.getCache(paramName); - } else { - return cacheManager.getCache(paramType.getSimpleName()); + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + if (StringUtils.isNotBlank(paramName)) { + return cacheManager.getCache(paramName); + } else { + return cacheManager.getCache(paramType.getSimpleName()); + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/ParamEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/ParamEditor.java index fcd56e3..03d6176 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/ParamEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/ParamEditor.java @@ -7,34 +7,34 @@ import java.util.HashMap; import java.util.Map; public class ParamEditor { - public static final int TYPE_UNKNOWN = 0; - public static final int TYPE_FIELD = 1; - public static final int TYPE_PARAM = 2; - public static final int TYPE_BODY = 3; - public static final int TYPE_PATH = 4; - public static final int TYPE_HEADER = 5; - public static final int TYPE_COOKIE = 6; - public static final int TYPE_ATTR = 7; - - private final Map, IEditor> editors = new HashMap<>(); - - @Setter - private IEditor defaultEditor; - - ParamEditor(IEditor defaultEditor) { - this.defaultEditor = defaultEditor; - } - - public void add(Class clazz, IEditor editor) { - editors.put(clazz, editor); - } - - public IEditor find(Class paramType) { - IEditor result = editors.get(paramType); - if (result == null) { - result = defaultEditor; + public static final int TYPE_UNKNOWN = 0; + public static final int TYPE_FIELD = 1; + public static final int TYPE_PARAM = 2; + public static final int TYPE_BODY = 3; + public static final int TYPE_PATH = 4; + public static final int TYPE_HEADER = 5; + public static final int TYPE_COOKIE = 6; + public static final int TYPE_ATTR = 7; + + private final Map, IEditor> editors = new HashMap<>(); + + @Setter + private IEditor defaultEditor; + + ParamEditor(IEditor defaultEditor) { + this.defaultEditor = defaultEditor; } - return result; - } + public void add(Class clazz, IEditor editor) { + editors.put(clazz, editor); + } + + public IEditor find(Class paramType) { + IEditor result = editors.get(paramType); + if (result == null) { + result = defaultEditor; + } + + return result; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/WebDataBinder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/WebDataBinder.java index d11759e..d2e0d1c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/WebDataBinder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/WebDataBinder.java @@ -20,206 +20,210 @@ import java.sql.Timestamp; @Slf4j public class WebDataBinder { - private ParamEditor paramEditor = new ParamEditor(new BeanEditor()); - private ParamEditor bodyEditor = new ParamEditor(new BeanBodyEditor()); - private ParamEditor pathEditor = new ParamEditor(new PathParamEditor()); - private ParamEditor headerEditor = new ParamEditor(new NullEditor()); - private ParamEditor attributeEditor = new ParamEditor(new BeanAttrEditor()); - private IEditor cacheEditor; - - public WebDataBinder(IEditor cacheEditor) { - this.cacheEditor = cacheEditor; - initParamEditor(); - initBodyEditor(); - initHeaderEditor(); - } + private ParamEditor paramEditor = new ParamEditor(new BeanEditor()); + private ParamEditor bodyEditor = new ParamEditor(new BeanBodyEditor()); + private ParamEditor pathEditor = new ParamEditor(new PathParamEditor()); + private ParamEditor headerEditor = new ParamEditor(new NullEditor()); + private ParamEditor attributeEditor = new ParamEditor(new BeanAttrEditor()); + private IEditor cacheEditor; + + public WebDataBinder(IEditor cacheEditor) { + this.cacheEditor = cacheEditor; + initParamEditor(); + initBodyEditor(); + initHeaderEditor(); + } // public void addParamEditor(Class type, IEditor editor) { // paramEditor.add(String.class, editor); // } - public IEditor findEditor(Class paramType, int bindType) { - IEditor result; - - switch (bindType) { - case ParamEditor.TYPE_UNKNOWN: - case ParamEditor.TYPE_PARAM: - case ParamEditor.TYPE_FIELD: - if (AbstractCache.class.isAssignableFrom(paramType)) { - result = cacheEditor; - } else { - result = paramEditor.find(paramType); + public IEditor findEditor(Class paramType, int bindType) { + IEditor result; + + switch (bindType) { + case ParamEditor.TYPE_UNKNOWN: + case ParamEditor.TYPE_PARAM: + case ParamEditor.TYPE_FIELD: + if (AbstractCache.class.isAssignableFrom(paramType)) { + result = cacheEditor; + } else { + result = paramEditor.find(paramType); + } + break; + case ParamEditor.TYPE_BODY: + // @SwBody + result = bodyEditor.find(paramType); + break; + case ParamEditor.TYPE_PATH: + result = pathEditor.find(paramType); + break; + case ParamEditor.TYPE_HEADER: + result = headerEditor.find(paramType); + break; + case ParamEditor.TYPE_ATTR: + result = attributeEditor.find(paramType); + break; + default: + throw new IllegalStateException("Unexpected type value: " + bindType); } - break; - case ParamEditor.TYPE_BODY: - // @SwBody - result = bodyEditor.find(paramType); - break; - case ParamEditor.TYPE_PATH: - result = pathEditor.find(paramType); - break; - case ParamEditor.TYPE_HEADER: - result = headerEditor.find(paramType); - break; - case ParamEditor.TYPE_ATTR: - result = attributeEditor.find(paramType); - break; - default: - throw new IllegalStateException("Unexpected type value: " + bindType); + + return result; } - return result; - } - - private void initParamEditor() { - TimestampEditor timestampEditor = new TimestampEditor(ParamEditor.TYPE_PARAM); - paramEditor.add(String.class, new StringEditor(ParamEditor.TYPE_PARAM)); - paramEditor.add(Timestamp.class, timestampEditor); - paramEditor.add(java.util.Date.class, timestampEditor); - paramEditor.add(java.sql.Date.class, new DateEditor(ParamEditor.TYPE_PARAM)); - paramEditor.add(java.sql.Time.class, new TimeEditor(ParamEditor.TYPE_PARAM)); - - paramEditor.add(Byte.TYPE, new ByteEditor(ParamEditor.TYPE_PARAM,true)); - paramEditor.add(Long.TYPE, new LongEditor(ParamEditor.TYPE_PARAM, true)); - paramEditor.add(Double.TYPE, new DoubleEditor(ParamEditor.TYPE_PARAM, true)); - paramEditor.add(Float.TYPE, new FloatEditor(ParamEditor.TYPE_PARAM, true)); - paramEditor.add(Short.TYPE, new ShortEditor(ParamEditor.TYPE_PARAM, true)); - paramEditor.add(Integer.TYPE, new IntegerEditor(ParamEditor.TYPE_PARAM, true)); - paramEditor.add(Boolean.TYPE, new BooleanEditor(ParamEditor.TYPE_PARAM, true)); - paramEditor.add(Character.TYPE,new CharEditor(ParamEditor.TYPE_PARAM, true)); - - paramEditor.add(Byte.class, new ByteEditor(ParamEditor.TYPE_PARAM, false)); - paramEditor.add(Long.class, new LongEditor(ParamEditor.TYPE_PARAM, false)); - paramEditor.add(Double.class, new DoubleEditor(ParamEditor.TYPE_PARAM,false)); - paramEditor.add(Float.class, new FloatEditor(ParamEditor.TYPE_PARAM,false)); - paramEditor.add(Short.class, new ShortEditor(ParamEditor.TYPE_PARAM,false)); - paramEditor.add(Integer.class, new IntegerEditor(ParamEditor.TYPE_PARAM,false)); - paramEditor.add(Boolean.class, new BooleanEditor(ParamEditor.TYPE_PARAM,false)); - - paramEditor.add(HttpServletRequest.class, new HttpServletRequestEditor()); + private void initParamEditor() { + TimestampEditor timestampEditor = new TimestampEditor(ParamEditor.TYPE_PARAM); + paramEditor.add(String.class, new StringEditor(ParamEditor.TYPE_PARAM)); + paramEditor.add(Timestamp.class, timestampEditor); + paramEditor.add(java.util.Date.class, timestampEditor); + paramEditor.add(java.sql.Date.class, new DateEditor(ParamEditor.TYPE_PARAM)); + paramEditor.add(java.sql.Time.class, new TimeEditor(ParamEditor.TYPE_PARAM)); + + paramEditor.add(Byte.TYPE, new ByteEditor(ParamEditor.TYPE_PARAM, true)); + paramEditor.add(Long.TYPE, new LongEditor(ParamEditor.TYPE_PARAM, true)); + paramEditor.add(Double.TYPE, new DoubleEditor(ParamEditor.TYPE_PARAM, true)); + paramEditor.add(Float.TYPE, new FloatEditor(ParamEditor.TYPE_PARAM, true)); + paramEditor.add(Short.TYPE, new ShortEditor(ParamEditor.TYPE_PARAM, true)); + paramEditor.add(Integer.TYPE, new IntegerEditor(ParamEditor.TYPE_PARAM, true)); + paramEditor.add(Boolean.TYPE, new BooleanEditor(ParamEditor.TYPE_PARAM, true)); + paramEditor.add(Character.TYPE, new CharEditor(ParamEditor.TYPE_PARAM, true)); + + paramEditor.add(Byte.class, new ByteEditor(ParamEditor.TYPE_PARAM, false)); + paramEditor.add(Long.class, new LongEditor(ParamEditor.TYPE_PARAM, false)); + paramEditor.add(Double.class, new DoubleEditor(ParamEditor.TYPE_PARAM, false)); + paramEditor.add(Float.class, new FloatEditor(ParamEditor.TYPE_PARAM, false)); + paramEditor.add(Short.class, new ShortEditor(ParamEditor.TYPE_PARAM, false)); + paramEditor.add(Integer.class, new IntegerEditor(ParamEditor.TYPE_PARAM, false)); + paramEditor.add(Boolean.class, new BooleanEditor(ParamEditor.TYPE_PARAM, false)); + + paramEditor.add(HttpServletRequest.class, new HttpServletRequestEditor()); // paramEditor.add(HttpServletResponse.class, new HttpServletResponseEditor()); - paramEditor.add(UserSession.class, new UserSessionEditor()); - paramEditor.add(SwIpAddr.class, new SwIpAddrEditor()); - paramEditor.add(SchedulerPoint.class, new BeanTypeEditor()); - } - - private void initBodyEditor() { - TimestampEditor timestampEditor = new TimestampEditor(ParamEditor.TYPE_BODY); - bodyEditor.add(String.class, new StringEditor(ParamEditor.TYPE_BODY)); - bodyEditor.add(Timestamp.class, timestampEditor); - bodyEditor.add(java.util.Date.class, timestampEditor); - bodyEditor.add(java.sql.Date.class, new DateEditor(ParamEditor.TYPE_BODY)); - bodyEditor.add(java.sql.Time.class, new TimeEditor(ParamEditor.TYPE_BODY)); - - bodyEditor.add(Byte.TYPE, new ByteEditor(ParamEditor.TYPE_BODY,true)); - bodyEditor.add(Long.TYPE, new LongEditor(ParamEditor.TYPE_BODY, true)); - bodyEditor.add(Double.TYPE, new DoubleEditor(ParamEditor.TYPE_BODY, true)); - bodyEditor.add(Float.TYPE, new FloatEditor(ParamEditor.TYPE_BODY, true)); - bodyEditor.add(Short.TYPE, new ShortEditor(ParamEditor.TYPE_BODY, true)); - bodyEditor.add(Integer.TYPE, new IntegerEditor(ParamEditor.TYPE_BODY, true)); - bodyEditor.add(Boolean.TYPE, new BooleanEditor(ParamEditor.TYPE_BODY, true)); - bodyEditor.add(Character.TYPE,new CharEditor(ParamEditor.TYPE_BODY, true)); - - bodyEditor.add(Byte.class, new ByteEditor(ParamEditor.TYPE_BODY, false)); - bodyEditor.add(Long.class, new LongEditor(ParamEditor.TYPE_BODY, false)); - bodyEditor.add(Double.class, new DoubleEditor(ParamEditor.TYPE_BODY,false)); - bodyEditor.add(Float.class, new FloatEditor(ParamEditor.TYPE_BODY,false)); - bodyEditor.add(Short.class, new ShortEditor(ParamEditor.TYPE_BODY,false)); - bodyEditor.add(Integer.class, new IntegerEditor(ParamEditor.TYPE_BODY,false)); - bodyEditor.add(Boolean.class, new BooleanEditor(ParamEditor.TYPE_BODY,false)); - - bodyEditor.add(String.class, new StringBodyEditor()); - bodyEditor.add(SwMap.class, new SwMapBodyEditor()); - } - - private void initHeaderEditor() { - TimestampEditor timestampEditor = new TimestampEditor(ParamEditor.TYPE_HEADER); - headerEditor.add(String.class, new StringEditor(ParamEditor.TYPE_HEADER)); - headerEditor.add(Timestamp.class, timestampEditor); - headerEditor.add(java.util.Date.class, timestampEditor); - headerEditor.add(java.sql.Date.class, new DateEditor(ParamEditor.TYPE_HEADER)); - headerEditor.add(java.sql.Time.class, new TimeEditor(ParamEditor.TYPE_HEADER)); - - headerEditor.add(Byte.TYPE, new ByteEditor(ParamEditor.TYPE_HEADER,true)); - headerEditor.add(Long.TYPE, new LongEditor(ParamEditor.TYPE_HEADER, true)); - headerEditor.add(Double.TYPE, new DoubleEditor(ParamEditor.TYPE_HEADER, true)); - headerEditor.add(Float.TYPE, new FloatEditor(ParamEditor.TYPE_HEADER, true)); - headerEditor.add(Short.TYPE, new ShortEditor(ParamEditor.TYPE_HEADER, true)); - headerEditor.add(Integer.TYPE, new IntegerEditor(ParamEditor.TYPE_HEADER, true)); - headerEditor.add(Boolean.TYPE, new BooleanEditor(ParamEditor.TYPE_HEADER, true)); - headerEditor.add(Character.TYPE,new CharEditor(ParamEditor.TYPE_HEADER, true)); - - headerEditor.add(Byte.class, new ByteEditor(ParamEditor.TYPE_HEADER, false)); - headerEditor.add(Long.class, new LongEditor(ParamEditor.TYPE_HEADER, false)); - headerEditor.add(Double.class, new DoubleEditor(ParamEditor.TYPE_HEADER,false)); - headerEditor.add(Float.class, new FloatEditor(ParamEditor.TYPE_HEADER,false)); - headerEditor.add(Short.class, new ShortEditor(ParamEditor.TYPE_HEADER,false)); - headerEditor.add(Integer.class, new IntegerEditor(ParamEditor.TYPE_HEADER,false)); - headerEditor.add(Boolean.class, new BooleanEditor(ParamEditor.TYPE_HEADER,false)); - } - - public void bindParam(Class type, IEditor editor) { - paramEditor.add(type, editor); - } - - public void bindBody(Class type, IEditor editor) { - bodyEditor.add(type, editor); - } - - /** - * 绑定自定义参数读取器 - * @param bindType 绑定类型ParamEditor.TYPE_XXX - * @param type 参数类型 - * @param editor 参数读取器 - */ - public void bind(int bindType, Class type, IEditor editor) { - switch (bindType) { - case ParamEditor.TYPE_PARAM: + paramEditor.add(UserSession.class, new UserSessionEditor()); + paramEditor.add(SwIpAddr.class, new SwIpAddrEditor()); + paramEditor.add(SchedulerPoint.class, new BeanTypeEditor()); + } + + private void initBodyEditor() { + TimestampEditor timestampEditor = new TimestampEditor(ParamEditor.TYPE_BODY); + bodyEditor.add(String.class, new StringEditor(ParamEditor.TYPE_BODY)); + bodyEditor.add(Timestamp.class, timestampEditor); + bodyEditor.add(java.util.Date.class, timestampEditor); + bodyEditor.add(java.sql.Date.class, new DateEditor(ParamEditor.TYPE_BODY)); + bodyEditor.add(java.sql.Time.class, new TimeEditor(ParamEditor.TYPE_BODY)); + + bodyEditor.add(Byte.TYPE, new ByteEditor(ParamEditor.TYPE_BODY, true)); + bodyEditor.add(Long.TYPE, new LongEditor(ParamEditor.TYPE_BODY, true)); + bodyEditor.add(Double.TYPE, new DoubleEditor(ParamEditor.TYPE_BODY, true)); + bodyEditor.add(Float.TYPE, new FloatEditor(ParamEditor.TYPE_BODY, true)); + bodyEditor.add(Short.TYPE, new ShortEditor(ParamEditor.TYPE_BODY, true)); + bodyEditor.add(Integer.TYPE, new IntegerEditor(ParamEditor.TYPE_BODY, true)); + bodyEditor.add(Boolean.TYPE, new BooleanEditor(ParamEditor.TYPE_BODY, true)); + bodyEditor.add(Character.TYPE, new CharEditor(ParamEditor.TYPE_BODY, true)); + + bodyEditor.add(Byte.class, new ByteEditor(ParamEditor.TYPE_BODY, false)); + bodyEditor.add(Long.class, new LongEditor(ParamEditor.TYPE_BODY, false)); + bodyEditor.add(Double.class, new DoubleEditor(ParamEditor.TYPE_BODY, false)); + bodyEditor.add(Float.class, new FloatEditor(ParamEditor.TYPE_BODY, false)); + bodyEditor.add(Short.class, new ShortEditor(ParamEditor.TYPE_BODY, false)); + bodyEditor.add(Integer.class, new IntegerEditor(ParamEditor.TYPE_BODY, false)); + bodyEditor.add(Boolean.class, new BooleanEditor(ParamEditor.TYPE_BODY, false)); + + bodyEditor.add(String.class, new StringBodyEditor()); + bodyEditor.add(SwMap.class, new SwMapBodyEditor()); + } + + private void initHeaderEditor() { + TimestampEditor timestampEditor = new TimestampEditor(ParamEditor.TYPE_HEADER); + headerEditor.add(String.class, new StringEditor(ParamEditor.TYPE_HEADER)); + headerEditor.add(Timestamp.class, timestampEditor); + headerEditor.add(java.util.Date.class, timestampEditor); + headerEditor.add(java.sql.Date.class, new DateEditor(ParamEditor.TYPE_HEADER)); + headerEditor.add(java.sql.Time.class, new TimeEditor(ParamEditor.TYPE_HEADER)); + + headerEditor.add(Byte.TYPE, new ByteEditor(ParamEditor.TYPE_HEADER, true)); + headerEditor.add(Long.TYPE, new LongEditor(ParamEditor.TYPE_HEADER, true)); + headerEditor.add(Double.TYPE, new DoubleEditor(ParamEditor.TYPE_HEADER, true)); + headerEditor.add(Float.TYPE, new FloatEditor(ParamEditor.TYPE_HEADER, true)); + headerEditor.add(Short.TYPE, new ShortEditor(ParamEditor.TYPE_HEADER, true)); + headerEditor.add(Integer.TYPE, new IntegerEditor(ParamEditor.TYPE_HEADER, true)); + headerEditor.add(Boolean.TYPE, new BooleanEditor(ParamEditor.TYPE_HEADER, true)); + headerEditor.add(Character.TYPE, new CharEditor(ParamEditor.TYPE_HEADER, true)); + + headerEditor.add(Byte.class, new ByteEditor(ParamEditor.TYPE_HEADER, false)); + headerEditor.add(Long.class, new LongEditor(ParamEditor.TYPE_HEADER, false)); + headerEditor.add(Double.class, new DoubleEditor(ParamEditor.TYPE_HEADER, false)); + headerEditor.add(Float.class, new FloatEditor(ParamEditor.TYPE_HEADER, false)); + headerEditor.add(Short.class, new ShortEditor(ParamEditor.TYPE_HEADER, false)); + headerEditor.add(Integer.class, new IntegerEditor(ParamEditor.TYPE_HEADER, false)); + headerEditor.add(Boolean.class, new BooleanEditor(ParamEditor.TYPE_HEADER, false)); + } + + public void bindParam(Class type, IEditor editor) { paramEditor.add(type, editor); - break; - case ParamEditor.TYPE_BODY: - // @SwBody + } + + public void bindBody(Class type, IEditor editor) { bodyEditor.add(type, editor); - break; - case ParamEditor.TYPE_PATH: - pathEditor.add(type, editor); - break; - case ParamEditor.TYPE_HEADER: - headerEditor.add(type, editor);; - break; - case ParamEditor.TYPE_ATTR: - attributeEditor.add(type, editor); - break; - default: - throw new IllegalStateException("Unexpected type value: " + bindType); } - } - - /** - * 绑定默认自定义参数读取器 - * @param bindType 绑定类型ParamEditor.TYPE_XXX - * @param editor 默认参数读取器 - */ - public void bindDefault(int bindType, IEditor editor) { - switch (bindType) { - case ParamEditor.TYPE_PARAM: - paramEditor.setDefaultEditor(editor); - break; - case ParamEditor.TYPE_BODY: - // @SwBody - bodyEditor.setDefaultEditor(editor); - break; - case ParamEditor.TYPE_PATH: - pathEditor.setDefaultEditor(editor); - break; - case ParamEditor.TYPE_HEADER: - headerEditor.setDefaultEditor(editor);; - break; - case ParamEditor.TYPE_ATTR: - attributeEditor.setDefaultEditor(editor); - break; - default: - throw new IllegalStateException("Unexpected type value: " + bindType); + + /** + * 绑定自定义参数读取器 + * + * @param bindType 绑定类型ParamEditor.TYPE_XXX + * @param type 参数类型 + * @param editor 参数读取器 + */ + public void bind(int bindType, Class type, IEditor editor) { + switch (bindType) { + case ParamEditor.TYPE_PARAM: + paramEditor.add(type, editor); + break; + case ParamEditor.TYPE_BODY: + // @SwBody + bodyEditor.add(type, editor); + break; + case ParamEditor.TYPE_PATH: + pathEditor.add(type, editor); + break; + case ParamEditor.TYPE_HEADER: + headerEditor.add(type, editor); + ; + break; + case ParamEditor.TYPE_ATTR: + attributeEditor.add(type, editor); + break; + default: + throw new IllegalStateException("Unexpected type value: " + bindType); + } + } + + /** + * 绑定默认自定义参数读取器 + * + * @param bindType 绑定类型ParamEditor.TYPE_XXX + * @param editor 默认参数读取器 + */ + public void bindDefault(int bindType, IEditor editor) { + switch (bindType) { + case ParamEditor.TYPE_PARAM: + paramEditor.setDefaultEditor(editor); + break; + case ParamEditor.TYPE_BODY: + // @SwBody + bodyEditor.setDefaultEditor(editor); + break; + case ParamEditor.TYPE_PATH: + pathEditor.setDefaultEditor(editor); + break; + case ParamEditor.TYPE_HEADER: + headerEditor.setDefaultEditor(editor); + ; + break; + case ParamEditor.TYPE_ATTR: + attributeEditor.setDefaultEditor(editor); + break; + default: + throw new IllegalStateException("Unexpected type value: " + bindType); + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/attr/AbstractAttrEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/attr/AbstractAttrEditor.java index e28d213..8347891 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/attr/AbstractAttrEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/attr/AbstractAttrEditor.java @@ -8,13 +8,14 @@ import java.util.Map; /** * API函数@SwBody参数的转换处理,POST请求直接转换Json内容为Bean对象,GET请求转换Map请求参数为Bean对 + * * @author xkliu */ public abstract class AbstractAttrEditor implements IEditor { - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - return getValue(paramName, paramType, request); - } + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + return getValue(paramName, paramType, request); + } - public abstract Object getValue(String paramName, Class paramType, HttpServletRequest request); + public abstract Object getValue(String paramName, Class paramType, HttpServletRequest request); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/attr/BeanAttrEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/attr/BeanAttrEditor.java index fc6058f..b837a08 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/attr/BeanAttrEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/attr/BeanAttrEditor.java @@ -4,11 +4,12 @@ import javax.servlet.http.HttpServletRequest; /** * API函数@SwBody参数的转换处理,POST请求直接转换Json内容为Bean对象,GET请求转换Map请求参数为Bean对 + * * @author xkliu */ public class BeanAttrEditor extends AbstractAttrEditor { - @Override - public Object getValue(String paramName, Class paramType, HttpServletRequest request) { - return request.getAttribute(paramName); - } + @Override + public Object getValue(String paramName, Class paramType, HttpServletRequest request) { + return request.getAttribute(paramName); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/AbstractContextEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/AbstractContextEditor.java index 1187721..7a2a248 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/AbstractContextEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/AbstractContextEditor.java @@ -7,10 +7,10 @@ import javax.servlet.http.HttpServletRequest; import java.util.Map; public abstract class AbstractContextEditor implements IEditor { - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - return getValue(paramName, paramType, context); - } + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + return getValue(paramName, paramType, context); + } - protected abstract Object getValue(String paramName, Class paramType, IBeanContext context); + protected abstract Object getValue(String paramName, Class paramType, IBeanContext context); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/BeanEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/BeanEditor.java index 399673a..5271530 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/BeanEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/BeanEditor.java @@ -4,12 +4,12 @@ import cc.smtweb.framework.core.mvc.controller.IBeanContext; import org.apache.commons.lang3.StringUtils; public class BeanEditor extends AbstractContextEditor { - @Override - public Object getValue(String paramName, Class paramType, IBeanContext context) { - if (StringUtils.isBlank(paramName)) { - return context.getBean(paramType); - } else { - return context.getBean(paramName, paramType); - } - } + @Override + public Object getValue(String paramName, Class paramType, IBeanContext context) { + if (StringUtils.isBlank(paramName)) { + return context.getBean(paramType); + } else { + return context.getBean(paramName, paramType); + } + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/HttpServletRequestEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/HttpServletRequestEditor.java index 3cdbfa2..f8b29d6 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/HttpServletRequestEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/HttpServletRequestEditor.java @@ -5,8 +5,8 @@ import cc.smtweb.framework.core.mvc.controller.binder.param.AbstractRequestEdito import javax.servlet.http.HttpServletRequest; public class HttpServletRequestEditor extends AbstractRequestEditor { - @Override - public Object getValue(HttpServletRequest request) { - return request; - } + @Override + public Object getValue(HttpServletRequest request) { + return request; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/NullEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/NullEditor.java index c791f97..5c2cd23 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/NullEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/NullEditor.java @@ -7,8 +7,8 @@ import javax.servlet.http.HttpServletRequest; import java.util.Map; public class NullEditor implements IEditor { - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - return null; - } + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + return null; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/SwIpAddrEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/SwIpAddrEditor.java index 8329f39..1e9c629 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/SwIpAddrEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/SwIpAddrEditor.java @@ -9,26 +9,26 @@ import javax.servlet.http.HttpServletRequest; * 获取客户端IP地址;这里通过了Nginx获取;X-Real-IP */ public class SwIpAddrEditor extends AbstractRequestEditor { - @Override - public Object getValue(HttpServletRequest request) { - String ip = request.getHeader("X-Real-IP"); + @Override + public Object getValue(HttpServletRequest request) { + String ip = request.getHeader("X-Real-IP"); - if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("X-Forwarded-For"); - } + if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("X-Forwarded-For"); + } - if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("Proxy-Client-IP"); - } + if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } - if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("WL-Proxy-Client-IP"); - } + if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } - if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { - ip = request.getRemoteAddr(); - } + if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } - return ip; - } + return ip; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/UserSessionEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/UserSessionEditor.java index 3478ebb..3ac1392 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/UserSessionEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/bean/UserSessionEditor.java @@ -6,8 +6,8 @@ import cc.smtweb.framework.core.session.SessionUtil; import javax.servlet.http.HttpServletRequest; public class UserSessionEditor extends AbstractRequestEditor { - @Override - public Object getValue(HttpServletRequest request) { - return SessionUtil.getSession(); - } + @Override + public Object getValue(HttpServletRequest request) { + return SessionUtil.getSession(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/BeanBodyEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/BeanBodyEditor.java index 68a7590..55868da 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/BeanBodyEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/BeanBodyEditor.java @@ -12,71 +12,72 @@ import java.util.Map; /** * API函数@SwBody参数的转换处理,POST请求直接转换Json内容为Bean对象,GET请求转换Map请求参数为Bean对 + * * @author xkliu */ public class BeanBodyEditor implements IEditor { - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - if (paramName != null) { - Object map = request.getAttribute(BODY_MAP); - if (map != null) { - return getFieldValue((SwMap) map, paramName, paramType); - } - } + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + if (paramName != null) { + Object map = request.getAttribute(BODY_MAP); + if (map != null) { + return getFieldValue((SwMap) map, paramName, paramType); + } + } - if (body != null) { - return getPostValue(paramName, paramType, body, request); - } else { - return getGetValue(paramName, paramType, params); - } - } + if (body != null) { + return getPostValue(paramName, paramType, body, request); + } else { + return getGetValue(paramName, paramType, params); + } + } - private Object getGetValue(String paramName, Class paramType, Map params) { - if (paramName == null) { - return JsonUtil.parseSimple(params, paramType); - } + private Object getGetValue(String paramName, Class paramType, Map params) { + if (paramName == null) { + return JsonUtil.parseSimple(params, paramType); + } - // Json字符进行类型转化 - Object result = params.get(paramName); - if (result == null) { - return null; - } + // Json字符进行类型转化 + Object result = params.get(paramName); + if (result == null) { + return null; + } - if (paramType.isAssignableFrom(result.getClass())) { - return result; - } + if (paramType.isAssignableFrom(result.getClass())) { + return result; + } - throw new BindBeanException("传入的 @SwBody(" + paramName + ") " + paramType.getName() + "类型不一致! " + result.getClass().getName()); - } + throw new BindBeanException("传入的 @SwBody(" + paramName + ") " + paramType.getName() + "类型不一致! " + result.getClass().getName()); + } - private Object getPostValue(String paramName, Class paramType, String body, HttpServletRequest request) { - if (body == null || StringUtils.isBlank(body)) { - return null; - } + private Object getPostValue(String paramName, Class paramType, String body, HttpServletRequest request) { + if (body == null || StringUtils.isBlank(body)) { + return null; + } - if (paramName == null) { - return JsonUtil.parse(body, paramType); - } else { - SwMap map = JsonUtil.parse(body, SwMap.class); - if (map != null) { - request.setAttribute(BODY_MAP, map); - return getFieldValue(map, paramName, paramType); - } + if (paramName == null) { + return JsonUtil.parse(body, paramType); + } else { + SwMap map = JsonUtil.parse(body, SwMap.class); + if (map != null) { + request.setAttribute(BODY_MAP, map); + return getFieldValue(map, paramName, paramType); + } - return null; - } - } + return null; + } + } - private Object getFieldValue(SwMap result, String paramName, Class paramType) { - Object value = result.get(paramName); - if (value == null) { - return null; - } + private Object getFieldValue(SwMap result, String paramName, Class paramType) { + Object value = result.get(paramName); + if (value == null) { + return null; + } - if (value instanceof Map) { - return BeanUtil.toBean((Map)value, paramType); - } + if (value instanceof Map) { + return BeanUtil.toBean((Map) value, paramType); + } - throw new BindBeanException("传入的 @SwBody(" + paramName + ") 值非Object类型! " + value.getClass().getName()); - } + throw new BindBeanException("传入的 @SwBody(" + paramName + ") 值非Object类型! " + value.getClass().getName()); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/BeanUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/BeanUtil.java index 641492a..ad9ba82 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/BeanUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/BeanUtil.java @@ -16,56 +16,57 @@ import java.util.Map; import java.util.Set; public class BeanUtil { - private static final Set> simpleType = new HashSet<>(); - - static { - simpleType.add(String.class); - simpleType.add(Timestamp.class); - simpleType.add(java.util.Date.class); - simpleType.add(java.sql.Date.class); - simpleType.add(java.sql.Time.class); - - simpleType.add(Byte.TYPE); - simpleType.add(Long.TYPE); - simpleType.add(Double.TYPE); - simpleType.add(Float.TYPE); - simpleType.add(Short.TYPE); - simpleType.add(Integer.TYPE); - simpleType.add(Boolean.TYPE); - simpleType.add(Character.TYPE); - - simpleType.add(Byte.class); - simpleType.add(Long.class); - simpleType.add(Double.class); - simpleType.add(Float.class); - simpleType.add(Short.class); - simpleType.add(Integer.class); - simpleType.add(Boolean.class); - } - - private BeanUtil() {} - - public static Object toBean(Map source, Class clazz) { - Object target = null; - try { - target = clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - throw new FatalBeanException( - "Could not copy property '" + clazz.getName() + "' from source to target", e); + private static final Set> simpleType = new HashSet<>(); + + static { + simpleType.add(String.class); + simpleType.add(Timestamp.class); + simpleType.add(java.util.Date.class); + simpleType.add(java.sql.Date.class); + simpleType.add(java.sql.Time.class); + + simpleType.add(Byte.TYPE); + simpleType.add(Long.TYPE); + simpleType.add(Double.TYPE); + simpleType.add(Float.TYPE); + simpleType.add(Short.TYPE); + simpleType.add(Integer.TYPE); + simpleType.add(Boolean.TYPE); + simpleType.add(Character.TYPE); + + simpleType.add(Byte.class); + simpleType.add(Long.class); + simpleType.add(Double.class); + simpleType.add(Float.class); + simpleType.add(Short.class); + simpleType.add(Integer.class); + simpleType.add(Boolean.class); } - mapToBean(source, target); - return target; - } - private static void mapToBean(Map source, Object target) { - mapToBean(source, target, true); - } + private BeanUtil() { + } - private static void mapToBean(Map source, Object target, boolean root) throws BeansException { - Assert.notNull(source, "Source must not be null"); - Assert.notNull(target, "Target must not be null"); + public static Object toBean(Map source, Class clazz) { + Object target = null; + try { + target = clazz.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw new FatalBeanException( + "Could not copy property '" + clazz.getName() + "' from source to target", e); + } + mapToBean(source, target); + return target; + } + + private static void mapToBean(Map source, Object target) { + mapToBean(source, target, true); + } - Class actualEditable = target.getClass(); + private static void mapToBean(Map source, Object target, boolean root) throws BeansException { + Assert.notNull(source, "Source must not be null"); + Assert.notNull(target, "Target must not be null"); + + Class actualEditable = target.getClass(); // if (editable != null) { // if (!editable.isInstance(target)) { // throw new IllegalArgumentException("Target class [" + target.getClass().getName() + @@ -73,88 +74,87 @@ public class BeanUtil { // } // actualEditable = editable; // } - PropertyDescriptor[] targetPds = BeanUtils.getPropertyDescriptors(actualEditable); - - for (PropertyDescriptor targetPd : targetPds) { - Method writeMethod = targetPd.getWriteMethod(); - Object value = source.get(targetPd.getName()); - - if (value == null) { - Class parameterType = writeMethod.getParameterTypes()[0]; - - if (ClassUtils.isAssignable(parameterType, value.getClass())) { - writeBeanValue(target, targetPd, writeMethod, value); - } else { - if (root && value instanceof Map) { - Object propValue; - try { - propValue = parameterType.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - throw new FatalBeanException( - "Could not copy property '" + targetPd.getName() + "' from source to target", e); + PropertyDescriptor[] targetPds = BeanUtils.getPropertyDescriptors(actualEditable); + + for (PropertyDescriptor targetPd : targetPds) { + Method writeMethod = targetPd.getWriteMethod(); + Object value = source.get(targetPd.getName()); + + if (value == null) { + Class parameterType = writeMethod.getParameterTypes()[0]; + + if (ClassUtils.isAssignable(parameterType, value.getClass())) { + writeBeanValue(target, targetPd, writeMethod, value); + } else { + if (root && value instanceof Map) { + Object propValue; + try { + propValue = parameterType.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw new FatalBeanException( + "Could not copy property '" + targetPd.getName() + "' from source to target", e); + } + + mapToBean((Map) value, propValue, false); + writeBeanValue(target, targetPd, writeMethod, propValue); + } + } } - - mapToBean((Map) value, propValue, false); - writeBeanValue(target, targetPd, writeMethod, propValue); - } } - } } - } - - private static void writeBeanValue(Object target, PropertyDescriptor targetPd, Method writeMethod, Object value) { - try { - if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { - writeMethod.setAccessible(true); - } - writeMethod.invoke(target, value); - } catch (Throwable ex) { - throw new FatalBeanException( - "Could not copy property '" + targetPd.getName() + "' from source to target", ex); + + private static void writeBeanValue(Object target, PropertyDescriptor targetPd, Method writeMethod, Object value) { + try { + if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { + writeMethod.setAccessible(true); + } + writeMethod.invoke(target, value); + } catch (Throwable ex) { + throw new FatalBeanException( + "Could not copy property '" + targetPd.getName() + "' from source to target", ex); + } } - } - public static void beanToMap(Object source, SwMap target) throws BeansException { - beanToMap(source, target, true); - } + public static void beanToMap(Object source, SwMap target) throws BeansException { + beanToMap(source, target, true); + } - public static void beanToMap(Object source, SwMap target, boolean root) throws BeansException { - Assert.notNull(source, "Source must not be null"); - Assert.notNull(target, "Target must not be null"); - PropertyDescriptor[] sourcePds = BeanUtils.getPropertyDescriptors(source.getClass()); + public static void beanToMap(Object source, SwMap target, boolean root) throws BeansException { + Assert.notNull(source, "Source must not be null"); + Assert.notNull(target, "Target must not be null"); + PropertyDescriptor[] sourcePds = BeanUtils.getPropertyDescriptors(source.getClass()); - for (PropertyDescriptor sourcePd: sourcePds) { + for (PropertyDescriptor sourcePd : sourcePds) { // PropertyDescriptor sourcePd = BeanUtils.getPropertyDescriptor(source.getClass(), targetPd.getKey()); // if (sourcePd != null) { - Method readMethod = sourcePd.getReadMethod(); - if (readMethod != null) { - try { - if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { - readMethod.setAccessible(true); - } - Object value = readMethod.invoke(source); - target.put(sourcePd.getName(), root ? toMapValue(value) : value); + Method readMethod = sourcePd.getReadMethod(); + if (readMethod != null) { + try { + if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { + readMethod.setAccessible(true); + } + Object value = readMethod.invoke(source); + target.put(sourcePd.getName(), root ? toMapValue(value): value); + } catch (Throwable ex) { + throw new FatalBeanException( + "Could not copy property '" + sourcePd.getName() + "' from source to target", ex); + } } - catch (Throwable ex) { - throw new FatalBeanException( - "Could not copy property '" + sourcePd.getName() + "' from source to target", ex); - } - } // } + } } - } - private static Object toMapValue(Object value) { - if (value != null && isBeanType(value.getClass())) { - SwMap mapValue = new SwMap(); - beanToMap(value, mapValue, false); - return mapValue; - } + private static Object toMapValue(Object value) { + if (value != null && isBeanType(value.getClass())) { + SwMap mapValue = new SwMap(); + beanToMap(value, mapValue, false); + return mapValue; + } - return value; - } + return value; + } - private static boolean isBeanType(Class type) { - return !simpleType.contains(type); - } + private static boolean isBeanType(Class type) { + return !simpleType.contains(type); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/StringBodyEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/StringBodyEditor.java index 9de8a32..0f45a3c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/StringBodyEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/StringBodyEditor.java @@ -7,12 +7,13 @@ import javax.servlet.http.HttpServletRequest; import java.util.Map; /** - * API函数@SwBody参数的转换处理,直接获取POST请求文本内容 + * API函数@SwBody参数的转换处理,直接获取POST请求文本内容 + * * @author xkliu */ public class StringBodyEditor implements IEditor { - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - return body; - } + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + return body; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/SwMapBodyEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/SwMapBodyEditor.java index 93e09f9..ae64f13 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/SwMapBodyEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/body/SwMapBodyEditor.java @@ -12,58 +12,59 @@ import java.util.Map; /** * API函数@SwBody参数的转换处理,POST请求直接转换Json内容为Bean对象,GET请求转换Map请求参数为Bean对 + * * @author xkliu */ public class SwMapBodyEditor implements IEditor { - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - Object map = request.getAttribute(BODY_MAP); - if (map != null) { - return getFieldValue((SwMap)map, paramName); - } + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + Object map = request.getAttribute(BODY_MAP); + if (map != null) { + return getFieldValue((SwMap) map, paramName); + } - if (body != null) { - return getPostValue(paramName, paramType, body, request); - } else { - return getGetValue(paramName, paramType, params, request); - } - } + if (body != null) { + return getPostValue(paramName, paramType, body, request); + } else { + return getGetValue(paramName, paramType, params, request); + } + } - private Object getGetValue(String paramName, Class paramType, Map params, HttpServletRequest request) { - SwMap result = JsonUtil.parseSimple(params, SwMap.class); - request.setAttribute(BODY_MAP, result); - return getFieldValue(result, paramName); - } + private Object getGetValue(String paramName, Class paramType, Map params, HttpServletRequest request) { + SwMap result = JsonUtil.parseSimple(params, SwMap.class); + request.setAttribute(BODY_MAP, result); + return getFieldValue(result, paramName); + } - private Object getPostValue(String paramName, Class paramType, String body, HttpServletRequest request) { - if (body == null || StringUtils.isBlank(body)) { - return null; - } + private Object getPostValue(String paramName, Class paramType, String body, HttpServletRequest request) { + if (body == null || StringUtils.isBlank(body)) { + return null; + } - SwMap result = JsonUtil.parse(body, SwMap.class); - request.setAttribute(BODY_MAP, result); - return getFieldValue(result, paramName); - } + SwMap result = JsonUtil.parse(body, SwMap.class); + request.setAttribute(BODY_MAP, result); + return getFieldValue(result, paramName); + } - private Object getFieldValue(SwMap result, String paramName) { - if (paramName != null) { - Object value = result.get(paramName); - if (value == null) { - return null; - } + private Object getFieldValue(SwMap result, String paramName) { + if (paramName != null) { + Object value = result.get(paramName); + if (value == null) { + return null; + } - if (value instanceof Map) { - SwMap map = new SwMap(); - ((Map) value).forEach((k, v) -> { - map.put(k.toString(), v); - }); - return map; - } + if (value instanceof Map) { + SwMap map = new SwMap(); + ((Map) value).forEach((k, v) -> { + map.put(k.toString(), v); + }); + return map; + } - throw new BindBeanException("传入的 @SwBody(" + paramName + ") 值非MAP类型! " + value.getClass().getName()); - } + throw new BindBeanException("传入的 @SwBody(" + paramName + ") 值非MAP类型! " + value.getClass().getName()); + } - return result; - } + return result; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractNumberEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractNumberEditor.java index 24d2feb..e92040c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractNumberEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractNumberEditor.java @@ -7,40 +7,41 @@ import org.apache.commons.lang3.StringUtils; * 字符串到Number类型的转换 * * @author kevin - * */ public abstract class AbstractNumberEditor extends AbstractParameterEditor { - protected boolean automicType; + protected boolean automicType; + + public AbstractNumberEditor(int paramEditType, boolean automicType) { + super(paramEditType); + this.automicType = automicType; + } + + @Override + protected Object parseText(Object value) { + Object result = null; - public AbstractNumberEditor(int paramEditType, boolean automicType) { - super(paramEditType); - this.automicType = automicType; - } + if (value == null) { + return automicType ? defaultValue(): null; + } - @Override - protected Object parseText(Object value) { - Object result = null; + if (value instanceof Number) { + return convert((Number) value); + } - if (value == null) { - return automicType ? defaultValue() : null; - } + String text = value.toString(); - if (value instanceof Number) { - return convert((Number)value); - } + if (StringUtils.isNotBlank(text)) { + result = getValue(text); + } else { + result = automicType ? defaultValue(): null; + } - String text = value.toString(); + return result; + } - if (StringUtils.isNotBlank(text)) { - result = getValue(text); - } else { - result = automicType ? defaultValue() : null; - } + protected abstract Object convert(Number value); - return result; - } + protected abstract Object getValue(String text); - protected abstract Object convert(Number value); - protected abstract Object getValue(String text); - protected abstract Object defaultValue(); + protected abstract Object defaultValue(); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractParameterEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractParameterEditor.java index db51dba..744a9b7 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractParameterEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractParameterEditor.java @@ -16,94 +16,96 @@ import java.util.Map; /** * 字符串参数到对象的转换; + * * @author xkliu */ public abstract class AbstractParameterEditor implements IEditor { - private static final IEditorValue paramValue = (paramName, params, body, request) -> params.get(paramName); - private static final IEditorValue headerValue = (paramName, params, body, request) -> request.getHeader(paramName); - private static final IEditorValue bodyValue = (paramName, params, body, request) -> { - if (body == null) { - if (paramName != null) { - return params.get(paramName); - } - } else { - SwMap map = (SwMap) request.getAttribute(BODY_MAP); - if (map != null) { - return map.get(paramName); - } - - map = JsonUtil.parse(body, SwMap.class); - if (map != null) { - request.setAttribute(BODY_MAP, map); - return map.get(paramName); - } - } - - return null; - }; - - private final IEditorValue editorValue; + private static final IEditorValue paramValue = (paramName, params, body, request) -> params.get(paramName); + private static final IEditorValue headerValue = (paramName, params, body, request) -> request.getHeader(paramName); + private static final IEditorValue bodyValue = (paramName, params, body, request) -> { + if (body == null) { + if (paramName != null) { + return params.get(paramName); + } + } else { + SwMap map = (SwMap) request.getAttribute(BODY_MAP); + if (map != null) { + return map.get(paramName); + } + + map = JsonUtil.parse(body, SwMap.class); + if (map != null) { + request.setAttribute(BODY_MAP, map); + return map.get(paramName); + } + } + + return null; + }; + + private final IEditorValue editorValue; // AbstractParameterEditor() { // editorValue = paramValue; // } - AbstractParameterEditor(int paramEditorType) { - switch (paramEditorType) { - case ParamEditor.TYPE_HEADER: - editorValue = headerValue; - break; - case ParamEditor.TYPE_PARAM: - editorValue = paramValue; - break; - case ParamEditor.TYPE_BODY: - editorValue = bodyValue; - break; - default: - throw new UnsupportedOperationException("not implement type: " + paramEditorType); - } - } - - protected static Date parseDateTime(String text) throws ParseException { - DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - df.setLenient(false); - - return df.parse(text); - } - - protected static Date parseShortDateTime(String text) throws ParseException { - DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - df.setLenient(false); - - return df.parse(text); - } - - protected static Date parseDate(String text) throws ParseException { - DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - df.setLenient(false); - - return df.parse(text); - } - - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - if (StringUtils.isBlank(paramName)) { - return null; - } - - return parseText(editorValue.getValue(paramName, params, body, request)); - } - - protected abstract Object parseText(Object text); + AbstractParameterEditor(int paramEditorType) { + switch (paramEditorType) { + case ParamEditor.TYPE_HEADER: + editorValue = headerValue; + break; + case ParamEditor.TYPE_PARAM: + editorValue = paramValue; + break; + case ParamEditor.TYPE_BODY: + editorValue = bodyValue; + break; + default: + throw new UnsupportedOperationException("not implement type: " + paramEditorType); + } + } + + protected static Date parseDateTime(String text) throws ParseException { + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + df.setLenient(false); + + return df.parse(text); + } + + protected static Date parseShortDateTime(String text) throws ParseException { + DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + df.setLenient(false); + + return df.parse(text); + } + + protected static Date parseDate(String text) throws ParseException { + DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + df.setLenient(false); + + return df.parse(text); + } + + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + if (StringUtils.isBlank(paramName)) { + return null; + } + + return parseText(editorValue.getValue(paramName, params, body, request)); + } + + protected abstract Object parseText(Object text); } interface IEditorValue { - /** - * 获取参数值 - * @param paramName 参数名 - * @param params HTTP请求参数集合 - * @param request HTTP请求对象 - * @return 参数值 - */ - Object getValue(String paramName, Map params, String body, HttpServletRequest request); + /** + * 获取参数值 + * + * @param paramName 参数名 + * @param params HTTP请求参数集合 + * @param request HTTP请求对象 + * @return 参数值 + */ + Object getValue(String paramName, Map params, String body, HttpServletRequest request); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractRequestEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractRequestEditor.java index eb17731..7fe7e6e 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractRequestEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/AbstractRequestEditor.java @@ -7,10 +7,10 @@ import javax.servlet.http.HttpServletRequest; import java.util.Map; public abstract class AbstractRequestEditor implements IEditor { - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - return getValue(request); - } + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + return getValue(request); + } - protected abstract Object getValue(HttpServletRequest request); + protected abstract Object getValue(HttpServletRequest request); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/BeanTypeEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/BeanTypeEditor.java index b96da02..8a25f3c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/BeanTypeEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/BeanTypeEditor.java @@ -7,8 +7,8 @@ import javax.servlet.http.HttpServletRequest; import java.util.Map; public class BeanTypeEditor implements IEditor { - @Override - public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { - return params.get(paramType.getName()); - } + @Override + public Object getParamValue(String paramName, Class paramType, IBeanContext context, Map params, String body, HttpServletRequest request) { + return params.get(paramType.getName()); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/BooleanEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/BooleanEditor.java index 30572c0..4b527ab 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/BooleanEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/BooleanEditor.java @@ -3,28 +3,28 @@ package cc.smtweb.framework.core.mvc.controller.binder.param; import org.apache.commons.lang3.StringUtils; public class BooleanEditor extends AbstractParameterEditor { - private final boolean automicType; + private final boolean automicType; - public BooleanEditor(int header, boolean automicType) { - super(header); - this.automicType = automicType; - } + public BooleanEditor(int header, boolean automicType) { + super(header); + this.automicType = automicType; + } - @Override - public Object parseText(Object text) { - if (text == null) { - return automicType ? Boolean.FALSE : null; - } + @Override + public Object parseText(Object text) { + if (text == null) { + return automicType ? Boolean.FALSE: null; + } - if (text instanceof Boolean) { - return text; - } + if (text instanceof Boolean) { + return text; + } - String s = text.toString(); - if (StringUtils.isBlank(s)) { - return automicType ? Boolean.FALSE : null; - } + String s = text.toString(); + if (StringUtils.isBlank(s)) { + return automicType ? Boolean.FALSE: null; + } - return Boolean.valueOf(s); - } + return Boolean.valueOf(s); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/ByteEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/ByteEditor.java index fd3a27e..4c9f3c1 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/ByteEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/ByteEditor.java @@ -1,24 +1,24 @@ package cc.smtweb.framework.core.mvc.controller.binder.param; public class ByteEditor extends AbstractNumberEditor { - private static final Byte BYTE_ZERO = 0; + private static final Byte BYTE_ZERO = 0; - public ByteEditor(int header, boolean automicType) { - super(header, automicType); - } + public ByteEditor(int header, boolean automicType) { + super(header, automicType); + } - @Override - protected Object convert(Number value) { - return value.byteValue(); - } + @Override + protected Object convert(Number value) { + return value.byteValue(); + } - @Override - protected Object getValue(String text) { - return Byte.valueOf(text); - } + @Override + protected Object getValue(String text) { + return Byte.valueOf(text); + } - @Override - protected Object defaultValue() { - return BYTE_ZERO; - } + @Override + protected Object defaultValue() { + return BYTE_ZERO; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/CharEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/CharEditor.java index a723b20..0b1167a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/CharEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/CharEditor.java @@ -4,26 +4,26 @@ import org.apache.commons.lang3.StringUtils; public class CharEditor extends AbstractParameterEditor { - private static final char CHAR_ZERO = '\u0000'; - private final boolean automicType; + private static final char CHAR_ZERO = '\u0000'; + private final boolean automicType; - public CharEditor(int header, boolean automicType) { - super(header); - this.automicType = automicType; - } + public CharEditor(int header, boolean automicType) { + super(header); + this.automicType = automicType; + } - @Override - protected Object parseText(Object value) { - if (value == null) { - return automicType ? CHAR_ZERO : null; - } + @Override + protected Object parseText(Object value) { + if (value == null) { + return automicType ? CHAR_ZERO: null; + } - String text = value.toString(); + String text = value.toString(); - if(StringUtils.isBlank(text)){ - return automicType ? CHAR_ZERO : null; - } + if (StringUtils.isBlank(text)) { + return automicType ? CHAR_ZERO: null; + } - return text.charAt(0); - } + return text.charAt(0); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/DateEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/DateEditor.java index 8f49da3..0705b6c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/DateEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/DateEditor.java @@ -7,47 +7,47 @@ import java.text.ParseException; import java.util.Date; public class DateEditor extends AbstractParameterEditor { - public DateEditor(int header) { - super(header); - } - - @Override - protected Object parseText(Object value) { - if (value == null) { - return null; - } - - if (value instanceof Date) { - return new java.sql.Date(((Date) value).getTime()); - } - - String text = value.toString(); - if (StringUtils.isBlank(text)) { - return null; - } - - Object result = null; - - if (StringUtils.isNotBlank(text)) { - text = text.trim(); - - if ("null".equals(text)) { - return null; - } else { - int pos = text.indexOf(' '); - if (pos > 0) { - text = text.substring(0, pos); - } - - try { - result = new java.sql.Date(parseDate(text).getTime()); - } catch (ParseException e) { - throw new BindParamException(e); - } - } - - } - - return result; - } + public DateEditor(int header) { + super(header); + } + + @Override + protected Object parseText(Object value) { + if (value == null) { + return null; + } + + if (value instanceof Date) { + return new java.sql.Date(((Date) value).getTime()); + } + + String text = value.toString(); + if (StringUtils.isBlank(text)) { + return null; + } + + Object result = null; + + if (StringUtils.isNotBlank(text)) { + text = text.trim(); + + if ("null".equals(text)) { + return null; + } else { + int pos = text.indexOf(' '); + if (pos > 0) { + text = text.substring(0, pos); + } + + try { + result = new java.sql.Date(parseDate(text).getTime()); + } catch (ParseException e) { + throw new BindParamException(e); + } + } + + } + + return result; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/DoubleEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/DoubleEditor.java index 8b8d7d9..ec81242 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/DoubleEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/DoubleEditor.java @@ -2,24 +2,24 @@ package cc.smtweb.framework.core.mvc.controller.binder.param; public class DoubleEditor extends AbstractNumberEditor { - private static final Double DOUBLE_ZERO = 0.0d; + private static final Double DOUBLE_ZERO = 0.0d; - public DoubleEditor(int header, boolean automicType) { - super(header, automicType); - } + public DoubleEditor(int header, boolean automicType) { + super(header, automicType); + } - @Override - protected Object convert(Number value) { - return value.doubleValue(); - } + @Override + protected Object convert(Number value) { + return value.doubleValue(); + } - @Override - protected Object getValue(String text) { - return Double.valueOf(text); - } + @Override + protected Object getValue(String text) { + return Double.valueOf(text); + } - @Override - protected Object defaultValue() { - return DOUBLE_ZERO; - } + @Override + protected Object defaultValue() { + return DOUBLE_ZERO; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/FloatEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/FloatEditor.java index c6cfe12..7e1ec52 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/FloatEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/FloatEditor.java @@ -2,24 +2,24 @@ package cc.smtweb.framework.core.mvc.controller.binder.param; public class FloatEditor extends AbstractNumberEditor { - private static final Float FLOAT_ZERO = 0.0f; + private static final Float FLOAT_ZERO = 0.0f; - public FloatEditor(int header, boolean automicType) { - super(header, automicType); - } + public FloatEditor(int header, boolean automicType) { + super(header, automicType); + } - @Override - protected Object convert(Number value) { - return value.floatValue(); - } + @Override + protected Object convert(Number value) { + return value.floatValue(); + } - @Override - protected Object getValue(String text) { - return Float.valueOf(text); - } + @Override + protected Object getValue(String text) { + return Float.valueOf(text); + } - @Override - protected Object defaultValue() { - return FLOAT_ZERO; - } + @Override + protected Object defaultValue() { + return FLOAT_ZERO; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/IntegerEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/IntegerEditor.java index e3666e2..88315c9 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/IntegerEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/IntegerEditor.java @@ -1,24 +1,24 @@ package cc.smtweb.framework.core.mvc.controller.binder.param; public class IntegerEditor extends AbstractNumberEditor { - private static final Integer INT_ZERO = 0; + private static final Integer INT_ZERO = 0; - public IntegerEditor(int header, boolean automicType) { - super(header, automicType); - } + public IntegerEditor(int header, boolean automicType) { + super(header, automicType); + } - @Override - protected Object convert(Number value) { - return value.intValue(); - } + @Override + protected Object convert(Number value) { + return value.intValue(); + } - @Override - protected Object getValue(String text) { - return Integer.valueOf(text); - } + @Override + protected Object getValue(String text) { + return Integer.valueOf(text); + } - @Override - protected Object defaultValue() { - return INT_ZERO; - } + @Override + protected Object defaultValue() { + return INT_ZERO; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/LongEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/LongEditor.java index 359cc0b..e6efde1 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/LongEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/LongEditor.java @@ -2,24 +2,24 @@ package cc.smtweb.framework.core.mvc.controller.binder.param; public class LongEditor extends AbstractNumberEditor { - private static final Long LONG_ZERO = 0L; + private static final Long LONG_ZERO = 0L; - public LongEditor(int header, boolean automicType) { - super(header, automicType); - } + public LongEditor(int header, boolean automicType) { + super(header, automicType); + } - @Override - protected Object convert(Number value) { - return value.longValue(); - } + @Override + protected Object convert(Number value) { + return value.longValue(); + } - @Override - protected Object getValue(String text) { - return Long.valueOf(text); - } + @Override + protected Object getValue(String text) { + return Long.valueOf(text); + } - @Override - protected Object defaultValue() { - return LONG_ZERO; - } + @Override + protected Object defaultValue() { + return LONG_ZERO; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/ShortEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/ShortEditor.java index 5587c17..05984e6 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/ShortEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/ShortEditor.java @@ -2,24 +2,24 @@ package cc.smtweb.framework.core.mvc.controller.binder.param; public class ShortEditor extends AbstractNumberEditor { - private static final Short SHORT_ZERO = 0; + private static final Short SHORT_ZERO = 0; - public ShortEditor(int header, boolean automicType) { - super(header, automicType); - } + public ShortEditor(int header, boolean automicType) { + super(header, automicType); + } - @Override - protected Object convert(Number value) { - return value.shortValue(); - } + @Override + protected Object convert(Number value) { + return value.shortValue(); + } - @Override - protected Object getValue(String text) { - return Short.valueOf(text); - } + @Override + protected Object getValue(String text) { + return Short.valueOf(text); + } - @Override - protected Object defaultValue() { - return SHORT_ZERO; - } + @Override + protected Object defaultValue() { + return SHORT_ZERO; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/StringEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/StringEditor.java index c6f7e69..7649952 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/StringEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/StringEditor.java @@ -2,16 +2,16 @@ package cc.smtweb.framework.core.mvc.controller.binder.param; public class StringEditor extends AbstractParameterEditor { - public StringEditor(int header) { - super(header); - } + public StringEditor(int header) { + super(header); + } - @Override - protected Object parseText(Object text) { - if (text == null) { - return text; - } + @Override + protected Object parseText(Object text) { + if (text == null) { + return text; + } - return text.toString(); - } + return text.toString(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/TimeEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/TimeEditor.java index 5377898..c6970ab 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/TimeEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/TimeEditor.java @@ -7,29 +7,29 @@ import java.text.ParseException; import java.util.Date; public class TimeEditor extends AbstractParameterEditor { - public TimeEditor(int header) { - super(header); - } + public TimeEditor(int header) { + super(header); + } - @Override - public Object parseText(Object value) { - if (value == null) { - return null; - } + @Override + public Object parseText(Object value) { + if (value == null) { + return null; + } - if (value instanceof Date) { - return new java.sql.Time(((Date) value).getTime()); - } + if (value instanceof Date) { + return new java.sql.Time(((Date) value).getTime()); + } - String text = value.toString(); - if (StringUtils.isBlank(text)) { - return null; - } + String text = value.toString(); + if (StringUtils.isBlank(text)) { + return null; + } - try { - return new java.sql.Time(parseDateTime(text).getTime()); - } catch (ParseException e) { - throw new BindParamException(e); - } - } + try { + return new java.sql.Time(parseDateTime(text).getTime()); + } catch (ParseException e) { + throw new BindParamException(e); + } + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/TimestampEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/TimestampEditor.java index 44141bf..c6f75b2 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/TimestampEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/param/TimestampEditor.java @@ -8,50 +8,50 @@ import java.text.ParseException; import java.util.Date; public class TimestampEditor extends AbstractParameterEditor { - public TimestampEditor(int header) { - super(header); - } - - @Override - public Object parseText(Object value) throws IllegalArgumentException { - if (value == null) { - return null; - } - - if (value instanceof Date) { - return new Timestamp(((Date) value).getTime()); - } - - String text = value.toString(); - if (StringUtils.isBlank(text)) { - return null; - } - - text = text.trim(); - - if ("null".equals(text)) { - return null; - } - - Timestamp result = null; - - try { - int pos = text.indexOf(':'); - if (pos < 0 && text.indexOf("-") < 0) { - result = new Timestamp(Long.parseLong(text)); - } else if (text.length() > 10) { - if (text.indexOf(':', pos + 1) > pos) { - result = new Timestamp(parseDateTime(text).getTime()); - } else { - result = new Timestamp(parseDateTime(text).getTime()); - } - } else { - result = new Timestamp(parseDateTime(text).getTime()); - } - } catch (ParseException ex) { - throw new BindParamException(ex); - } - - return result; - } + public TimestampEditor(int header) { + super(header); + } + + @Override + public Object parseText(Object value) throws IllegalArgumentException { + if (value == null) { + return null; + } + + if (value instanceof Date) { + return new Timestamp(((Date) value).getTime()); + } + + String text = value.toString(); + if (StringUtils.isBlank(text)) { + return null; + } + + text = text.trim(); + + if ("null".equals(text)) { + return null; + } + + Timestamp result = null; + + try { + int pos = text.indexOf(':'); + if (pos < 0 && text.indexOf("-") < 0) { + result = new Timestamp(Long.parseLong(text)); + } else if (text.length() > 10) { + if (text.indexOf(':', pos + 1) > pos) { + result = new Timestamp(parseDateTime(text).getTime()); + } else { + result = new Timestamp(parseDateTime(text).getTime()); + } + } else { + result = new Timestamp(parseDateTime(text).getTime()); + } + } catch (ParseException ex) { + throw new BindParamException(ex); + } + + return result; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/path/PathParamEditor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/path/PathParamEditor.java index cb42ef7..cfa96d1 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/path/PathParamEditor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/binder/path/PathParamEditor.java @@ -5,10 +5,10 @@ import cc.smtweb.framework.core.mvc.controller.binder.param.AbstractRequestEdito import javax.servlet.http.HttpServletRequest; public class PathParamEditor extends AbstractRequestEditor { - public final static String ATTR_KEY = "SMTWEB_PATH"; + public final static String ATTR_KEY = "SMTWEB_PATH"; - @Override - public Object getValue(HttpServletRequest request) { - return request.getAttribute(ATTR_KEY); - } + @Override + public Object getValue(HttpServletRequest request) { + return request.getAttribute(ATTR_KEY); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/IScanAction.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/IScanAction.java index 798fc2e..58f8f3d 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/IScanAction.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/IScanAction.java @@ -5,14 +5,17 @@ import cc.smtweb.framework.core.mvc.controller.access.IMethodAccess; /** * 实现自定义@SwAction的拦截器,需要配合@SwAction继承注解配置到函数上使用 + * * @author kevin */ public interface IScanAction { - Class actionType(); - /** - * 一种@SwAction子类型只能声明一个SwActionPointcut - * @param module 模块名称 - * @param actionManager action管理器,用以注册API服务 - */ - void load(IActionManager actionManager, String module, T anno, IMethodAccess methodAccess); + Class actionType(); + + /** + * 一种@SwAction子类型只能声明一个SwActionPointcut + * + * @param module 模块名称 + * @param actionManager action管理器,用以注册API服务 + */ + void load(IActionManager actionManager, String module, T anno, IMethodAccess methodAccess); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/IScanActionBuilder.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/IScanActionBuilder.java index dcb9529..0cffa39 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/IScanActionBuilder.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/IScanActionBuilder.java @@ -5,8 +5,9 @@ import org.springframework.context.ConfigurableApplicationContext; /** * 实现自定义@SwAction的拦截器,需要配合@SwAction继承注解配置到函数上使用 + * * @author kevin */ public interface IScanActionBuilder { - IScanAction build(ConfigurableApplicationContext applicationContext, WebDataBinder webDataBinder); + IScanAction build(ConfigurableApplicationContext applicationContext, WebDataBinder webDataBinder); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/MethodParser.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/MethodParser.java index 37664f2..34229ea 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/MethodParser.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/MethodParser.java @@ -20,41 +20,41 @@ import java.util.List; @Slf4j public class MethodParser { - private final UrlMaker urlMaker; - private final BeanManager controllers; - private final WebDataBinder webDataBinder; - private ScanContext scanContext; + private final UrlMaker urlMaker; + private final BeanManager controllers; + private final WebDataBinder webDataBinder; + private ScanContext scanContext; // private ControllerAccess controllerAccess; - public MethodParser(UrlMaker urlMaker, ScanContext scanContext) { - this.urlMaker = urlMaker; - this.controllers = scanContext.getBeanManager(); - this.webDataBinder = scanContext.getWebDataBinder(); - this.scanContext = scanContext; - } + public MethodParser(UrlMaker urlMaker, ScanContext scanContext) { + this.urlMaker = urlMaker; + this.controllers = scanContext.getBeanManager(); + this.webDataBinder = scanContext.getWebDataBinder(); + this.scanContext = scanContext; + } - public void parse(Class clazz, ControllerAccess controllerAccess, boolean isApi) throws ParseException { + public void parse(Class clazz, ControllerAccess controllerAccess, boolean isApi) throws ParseException { // this.controllerAccess = controllerAccess; - // 服务的默认权限 - String classPerm = ""; - SwPerm swPerm = clazz.getAnnotation(SwPerm.class); - if (swPerm != null) { - classPerm = swPerm.value(); - } + // 服务的默认权限 + String classPerm = ""; + SwPerm swPerm = clazz.getAnnotation(SwPerm.class); + if (swPerm != null) { + classPerm = swPerm.value(); + } - // 扫描方法注解 - for (Method m : clazz.getMethods()) { - int modifier = m.getModifiers(); + // 扫描方法注解 + for (Method m : clazz.getMethods()) { + int modifier = m.getModifiers(); - // && (R.class.isAssignableFrom(m.getReturnType())) - if (Modifier.isPublic(modifier) && !Modifier.isStatic(modifier) && !Object.class.equals(m.getDeclaringClass())) { - MethodAccess methodAccess = parseMethod(controllerAccess, m, classPerm); + // && (R.class.isAssignableFrom(m.getReturnType())) + if (Modifier.isPublic(modifier) && !Modifier.isStatic(modifier) && !Object.class.equals(m.getDeclaringClass())) { + MethodAccess methodAccess = parseMethod(controllerAccess, m, classPerm); - if (scanContext.dealMethod(m, methodAccess)) { - if (isApi) { - urlMaker.addApi(clazz, m, methodAccess, controllers); - } - } + if (scanContext.dealMethod(m, methodAccess)) { + if (isApi) { + urlMaker.addApi(clazz, m, methodAccess, controllers); + } + } // SwScheduling scheduling = m.getAnnotation(SwScheduling.class); // SwConstruct construct = m.getAnnotation(SwConstruct.class); @@ -77,83 +77,83 @@ public class MethodParser { // } else if (isApi) { // urlMaker.addApi(clazz, m, methodAccess, controllers); // } - } - } - } - - private MethodAccess parseMethod(ControllerAccess controllerAccess, Method method, String defaultPerm) { - Class[] paramTypes = method.getParameterTypes(); - Annotation[][] paramAnnotations = method.getParameterAnnotations(); - - MethodParamAccess[] paramBinds = new MethodParamAccess[paramTypes.length]; - - for (int i = 0; i < paramTypes.length; i++) { - Class paramType = paramTypes[i]; - String paramName = null; - int bindType = ParamEditor.TYPE_UNKNOWN; - if (!ObjectUtils.isEmpty(paramAnnotations[i])) { - for (Annotation annotation: paramAnnotations[i]) { - // isAssignableFrom - Class annotationType = annotation.annotationType(); - if (SwParam.class.equals(annotationType)) { - bindType = ParamEditor.TYPE_PARAM; - String value = ((SwParam) annotation).value(); - if (StringUtils.isNotBlank(value)) { - paramName = value; } - break; - } else if (SwPathParam.class.equals(annotationType)) { - bindType = ParamEditor.TYPE_PATH; - break; - } else if (SwHeaderParam.class.equals(annotationType)) { - bindType = ParamEditor.TYPE_HEADER; - String value = ((SwHeaderParam) annotation).value(); - if (StringUtils.isNotBlank(value)) { - paramName = value; + } + } + + private MethodAccess parseMethod(ControllerAccess controllerAccess, Method method, String defaultPerm) { + Class[] paramTypes = method.getParameterTypes(); + Annotation[][] paramAnnotations = method.getParameterAnnotations(); + + MethodParamAccess[] paramBinds = new MethodParamAccess[paramTypes.length]; + + for (int i = 0; i < paramTypes.length; i++) { + Class paramType = paramTypes[i]; + String paramName = null; + int bindType = ParamEditor.TYPE_UNKNOWN; + if (!ObjectUtils.isEmpty(paramAnnotations[i])) { + for (Annotation annotation : paramAnnotations[i]) { + // isAssignableFrom + Class annotationType = annotation.annotationType(); + if (SwParam.class.equals(annotationType)) { + bindType = ParamEditor.TYPE_PARAM; + String value = ((SwParam) annotation).value(); + if (StringUtils.isNotBlank(value)) { + paramName = value; + } + break; + } else if (SwPathParam.class.equals(annotationType)) { + bindType = ParamEditor.TYPE_PATH; + break; + } else if (SwHeaderParam.class.equals(annotationType)) { + bindType = ParamEditor.TYPE_HEADER; + String value = ((SwHeaderParam) annotation).value(); + if (StringUtils.isNotBlank(value)) { + paramName = value; + } + break; + } else if (SwBody.class.equals(annotationType)) { + bindType = ParamEditor.TYPE_BODY; + String value = ((SwBody) annotation).value(); + if (StringUtils.isNotBlank(value)) { + paramName = value; + } + break; + } else if (SwAttr.class.equals(annotationType)) { + bindType = ParamEditor.TYPE_ATTR; + String value = ((SwAttr) annotation).value(); + if (StringUtils.isNotBlank(value)) { + paramName = value; + } + break; + } + } } - break; - } else if (SwBody.class.equals(annotationType)) { - bindType = ParamEditor.TYPE_BODY; - String value = ((SwBody) annotation).value(); - if (StringUtils.isNotBlank(value)) { - paramName = value; + + IEditor editor = webDataBinder.findEditor(paramType, bindType); + + if (List.class.isAssignableFrom(paramType)) { + // List bind类型使用泛型声明的对象 + ResolvableType resolvableType = ResolvableType.forMethodParameter(method, i); + paramType = resolvableType.getGeneric(0).getRawClass(); + paramBinds[i] = new MethodParamAccess(editor, paramName, resolvableType.getGeneric(0).getRawClass(), bindType, paramType); + } else { + paramBinds[i] = new MethodParamAccess(editor, paramName, paramType, bindType, null); } - break; - } else if (SwAttr.class.equals(annotationType)) { - bindType = ParamEditor.TYPE_ATTR; - String value = ((SwAttr) annotation).value(); - if (StringUtils.isNotBlank(value)) { - paramName = value; + + if (editor == null) { + log.error("not bind type:" + controllerAccess.getFullName() + "." + method.getName()); } - break; - } } - } - - IEditor editor = webDataBinder.findEditor(paramType, bindType); - - if (List.class.isAssignableFrom(paramType)) { - // List bind类型使用泛型声明的对象 - ResolvableType resolvableType = ResolvableType.forMethodParameter(method, i); - paramType = resolvableType.getGeneric(0).getRawClass(); - paramBinds[i] = new MethodParamAccess(editor, paramName, resolvableType.getGeneric(0).getRawClass(), bindType, paramType); - } else { - paramBinds[i] = new MethodParamAccess(editor, paramName, paramType, bindType, null); - } - - if (editor == null) { - log.error("not bind type:" + controllerAccess.getFullName() + "." + method.getName()); - } - } - // 得到权限注解 - String perm = defaultPerm; - SwPerm swPerm = method.getAnnotation(SwPerm.class); - if (swPerm != null) { - perm = swPerm.value(); - } + // 得到权限注解 + String perm = defaultPerm; + SwPerm swPerm = method.getAnnotation(SwPerm.class); + if (swPerm != null) { + perm = swPerm.value(); + } - return new MethodAccess(controllerAccess, method, perm, paramBinds); - } + return new MethodAccess(controllerAccess, method, perm, paramBinds); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/PackageScanner.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/PackageScanner.java index d0bfe8b..eee2666 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/PackageScanner.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/PackageScanner.java @@ -14,51 +14,51 @@ import java.util.jar.JarFile; @Slf4j public class PackageScanner { - private ClassParser classParser; - - public PackageScanner(ClassParser classParser) { - this.classParser = classParser; - } - - /** - * 1. 遍历所有目录 2. 处理注解类,进行适配类匹配 3. 放入路径映射map - * - * @throws IOException - */ - public void scan(String packagePath) throws IOException { + private ClassParser classParser; + + public PackageScanner(ClassParser classParser) { + this.classParser = classParser; + } + + /** + * 1. 遍历所有目录 2. 处理注解类,进行适配类匹配 3. 放入路径映射map + * + * @throws IOException + */ + public void scan(String packagePath) throws IOException { // log.info("[smt]start scan " + packagePath); - directorize(packagePath, true); + directorize(packagePath, true); // log.info("[smt]end scan " + packagePath); - } - - /** - * 扫描目录下的注解类 - * - * @param packageName 目录对象 - * @param recursive 是否递归扫描包 - */ - private void directorize(String packageName, boolean recursive) - throws IOException { - String packageDirName = packageName.replace('.', '/'); - - Enumeration dirs = Thread.currentThread().getContextClassLoader() - .getResources(packageDirName); - - // 循环迭代下去 - while (dirs.hasMoreElements()) { - // 获取下一个元素 - URL url = dirs.nextElement(); - // 得到协议的名称 - String protocol = url.getProtocol(); - // 如果是以文件的形式保存在服务器上 - if ("file".equals(protocol)) { + } + + /** + * 扫描目录下的注解类 + * + * @param packageName 目录对象 + * @param recursive 是否递归扫描包 + */ + private void directorize(String packageName, boolean recursive) + throws IOException { + String packageDirName = packageName.replace('.', '/'); + + Enumeration dirs = Thread.currentThread().getContextClassLoader() + .getResources(packageDirName); + + // 循环迭代下去 + while (dirs.hasMoreElements()) { + // 获取下一个元素 + URL url = dirs.nextElement(); + // 得到协议的名称 + String protocol = url.getProtocol(); + // 如果是以文件的形式保存在服务器上 + if ("file".equals(protocol)) { // log.debug("scan action in file"); - // 获取包的物理路径 - String filePath = URLDecoder.decode(url.getFile(), "UTF-8"); - // 以文件的方式扫描整个包下的文件 并添加到集合中 - findAndAddClassesInPackageByFile(packageName, "", filePath, - recursive); - // 执行属性设置 + // 获取包的物理路径 + String filePath = URLDecoder.decode(url.getFile(), "UTF-8"); + // 以文件的方式扫描整个包下的文件 并添加到集合中 + findAndAddClassesInPackageByFile(packageName, "", filePath, + recursive); + // 执行属性设置 // for (FieldAutowriter field : fieldList) { // boolean ret = field.writeValue(this.context); // if (ret) { @@ -69,112 +69,112 @@ public class PackageScanner { // + " failure."); // } // } - } else if ("jar".equals(protocol)) { - // 如果是jar包文件 - // 定义一个JarFile - try { - // 获取jar - JarFile jar = ((JarURLConnection) url.openConnection()) - .getJarFile(); - // 从此jar包 得到一个枚举类 - Enumeration entries = jar.entries(); - // 同样的进行循环迭代 - while (entries.hasMoreElements()) { - // 获取jar里的一个实体 可以是目录 和一些jar包里的其他文件 如META-INF等文件 - JarEntry entry = entries.nextElement(); - String name = entry.getName(); - // 如果是以/开头的 - if (name.charAt(0) == '/') { - // 获取后面的字符串 - name = name.substring(1); - } - // 如果前半部分和定义的包名相同 - if (name.startsWith(packageDirName)) { - int idx = name.lastIndexOf('/'); - // 如果以"/"结尾 是一个包 - if (idx != -1) { - // 获取包名 把"/"替换成"." - packageName = name.substring(0, idx).replace( - '/', '.'); - } - // 如果可以迭代下去 并且是一个包 - if ((idx != -1) || recursive) { - // 如果是一个.class文件 而且不是目录 - if (!entry.isDirectory()) { - parseFile( - packageName, "", - name.substring(packageName.length() + 1)); + } else if ("jar".equals(protocol)) { + // 如果是jar包文件 + // 定义一个JarFile + try { + // 获取jar + JarFile jar = ((JarURLConnection) url.openConnection()) + .getJarFile(); + // 从此jar包 得到一个枚举类 + Enumeration entries = jar.entries(); + // 同样的进行循环迭代 + while (entries.hasMoreElements()) { + // 获取jar里的一个实体 可以是目录 和一些jar包里的其他文件 如META-INF等文件 + JarEntry entry = entries.nextElement(); + String name = entry.getName(); + // 如果是以/开头的 + if (name.charAt(0) == '/') { + // 获取后面的字符串 + name = name.substring(1); + } + // 如果前半部分和定义的包名相同 + if (name.startsWith(packageDirName)) { + int idx = name.lastIndexOf('/'); + // 如果以"/"结尾 是一个包 + if (idx != -1) { + // 获取包名 把"/"替换成"." + packageName = name.substring(0, idx).replace( + '/', '.'); + } + // 如果可以迭代下去 并且是一个包 + if ((idx != -1) || recursive) { + // 如果是一个.class文件 而且不是目录 + if (!entry.isDirectory()) { + parseFile( + packageName, "", + name.substring(packageName.length() + 1)); + } + } + } + } + } catch (IOException e) { + log.error("scan jar error", e); + // log.error("在扫描用户定义视图时从jar包获取文件出错"); + // e.printStackTrace(); } - } } - } - } catch (IOException e) { - log.error("scan jar error", e); - // log.error("在扫描用户定义视图时从jar包获取文件出错"); - // e.printStackTrace(); } - } - } - } - - /** - * 以文件的形式来获取包下的所有Class - * - * @param packageName - * @param packagePath - * @param recursive - */ - public void findAndAddClassesInPackageByFile(String packageName, String dirName, - String packagePath, final boolean recursive) { - // 获取此包的目录 建立一个File - File dir = new File(packagePath); - // 如果不存在或者 也不是目录就直接返回 - if (!dir.exists() || !dir.isDirectory()) { - // log.warn("用户定义包名 " + packageName + " 下没有任何文件"); - return; } - // 如果存在 就获取包下的所有文件 包括目录 - // 自定义过滤规则 如果可以循环(包含子目录) 或则是以.class结尾的文件(编译好的java类文件) - File[] dirFiles = dir.listFiles(file -> { - String fileName = file.getName(); - return (recursive && file.isDirectory()) - || fileName.endsWith(".class"); - }); - - // 循环所有文件 - if (dirFiles != null) { - for (File file : dirFiles) { - // 如果是目录 则继续扫描 - if (file.isDirectory()) { - findAndAddClassesInPackageByFile(packageName + "." + file.getName(), - file.getName(), file.getAbsolutePath(), recursive); - } else { - parseFile(packageName, dirName, file.getName()); + /** + * 以文件的形式来获取包下的所有Class + * + * @param packageName + * @param packagePath + * @param recursive + */ + public void findAndAddClassesInPackageByFile(String packageName, String dirName, + String packagePath, final boolean recursive) { + // 获取此包的目录 建立一个File + File dir = new File(packagePath); + // 如果不存在或者 也不是目录就直接返回 + if (!dir.exists() || !dir.isDirectory()) { + // log.warn("用户定义包名 " + packageName + " 下没有任何文件"); + return; + } + + // 如果存在 就获取包下的所有文件 包括目录 + // 自定义过滤规则 如果可以循环(包含子目录) 或则是以.class结尾的文件(编译好的java类文件) + File[] dirFiles = dir.listFiles(file -> { + String fileName = file.getName(); + return (recursive && file.isDirectory()) + || fileName.endsWith(".class"); + }); + + // 循环所有文件 + if (dirFiles != null) { + for (File file : dirFiles) { + // 如果是目录 则继续扫描 + if (file.isDirectory()) { + findAndAddClassesInPackageByFile(packageName + "." + file.getName(), + file.getName(), file.getAbsolutePath(), recursive); + } else { + parseFile(packageName, dirName, file.getName()); + } + } } - } } - } - private void parseFile(String packageName, String dirName, String fileName) { - if (fileName.endsWith(".class")) { - // 去掉后面的".class" 获取真正的类名 - String className = fileName.substring(0, fileName.length() - 6); + private void parseFile(String packageName, String dirName, String fileName) { + if (fileName.endsWith(".class")) { + // 去掉后面的".class" 获取真正的类名 + String className = fileName.substring(0, fileName.length() - 6); - className = packageName + '.' + className; + className = packageName + '.' + className; - try { - Class clazz = Class.forName(className); + try { + Class clazz = Class.forName(className); - int modifiers = clazz.getModifiers(); + int modifiers = clazz.getModifiers(); - if (Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers)) { - classParser.parse(dirName, clazz); + if (Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers)) { + classParser.parse(dirName, clazz); + } + } catch (Exception e) { + log.error("init class error " + className, e); + throw new RuntimeException(e); + } } - } catch (Exception e) { - log.error("init class error " + className, e); - throw new RuntimeException(e); - } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/ScanContext.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/ScanContext.java index b20338c..3c88666 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/ScanContext.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/ScanContext.java @@ -22,16 +22,16 @@ import java.util.function.BiFunction; @Getter @Slf4j public class ScanContext { - private final BeanManager beanManager; - private final WebDataBinder webDataBinder; -// private Map, List> actions = new HashMap<>(); - private Map, BiFunction> dealMethodAnnotation = new HashMap<>(); - @Setter - private String module; + private final BeanManager beanManager; + private final WebDataBinder webDataBinder; + // private Map, List> actions = new HashMap<>(); + private Map, BiFunction> dealMethodAnnotation = new HashMap<>(); + @Setter + private String module; - public ScanContext(BeanManager beanManager, WebDataBinder webDataBinder) { - this.beanManager = beanManager; - this.webDataBinder = webDataBinder; + public ScanContext(BeanManager beanManager, WebDataBinder webDataBinder) { + this.beanManager = beanManager; + this.webDataBinder = webDataBinder; // if (scheduling != null) { // // 定时任务用seed值限定 // log.debug(" add timer task: " + clazz.getSimpleName() + "." + m.getName()); @@ -47,32 +47,32 @@ public class ScanContext { // } else if (isApi) { // urlMaker.addApi(clazz, m, methodAccess, controllers); // } - dealMethodAnnotation.put(SwScheduling.class, (a, methodAccess) -> { - try { - // 定时任务用seed值限定 - beanManager.addTask(new SchedulerMethodAccess(methodAccess, ((SwScheduling)a))); - log.debug(" add timer task: " + methodAccess.fullName()); - } catch (ParseException e) { - throw new SwException(e); - } + dealMethodAnnotation.put(SwScheduling.class, (a, methodAccess) -> { + try { + // 定时任务用seed值限定 + beanManager.addTask(new SchedulerMethodAccess(methodAccess, ((SwScheduling) a))); + log.debug(" add timer task: " + methodAccess.fullName()); + } catch (ParseException e) { + throw new SwException(e); + } - return false; - }); + return false; + }); - dealMethodAnnotation.put(SwConstruct.class, (a, methodAccess) -> { - beanManager.addConstruct(((SwConstruct)a).order(), methodAccess); - return false; - }); + dealMethodAnnotation.put(SwConstruct.class, (a, methodAccess) -> { + beanManager.addConstruct(((SwConstruct) a).order(), methodAccess); + return false; + }); - dealMethodAnnotation.put(SwDestroy.class, (a, methodAccess) -> { - beanManager.addDestroy(((SwDestroy)a).order(), methodAccess); - return false; - }); + dealMethodAnnotation.put(SwDestroy.class, (a, methodAccess) -> { + beanManager.addDestroy(((SwDestroy) a).order(), methodAccess); + return false; + }); - dealMethodAnnotation.put(SwBean.class, (a, methodAccess) -> { - beanManager.addBeanMethod(methodAccess); - return false; - }); + dealMethodAnnotation.put(SwBean.class, (a, methodAccess) -> { + beanManager.addBeanMethod(methodAccess); + return false; + }); // // dealMethodAnnotation.put(SwAction.class, (a, methodAccess) -> { // return true; @@ -81,35 +81,35 @@ public class ScanContext { // dealMethodAnnotation.put(SwPerm.class, (a, methodAccess) -> { // return true; // }); - } + } - public void addScanAction(IScanAction apiLoader) { - Object old = dealMethodAnnotation.putIfAbsent(apiLoader.actionType(), (a, methodAccess) -> { - apiLoader.load(beanManager, module, a, methodAccess); - return false; - }); + public void addScanAction(IScanAction apiLoader) { + Object old = dealMethodAnnotation.putIfAbsent(apiLoader.actionType(), (a, methodAccess) -> { + apiLoader.load(beanManager, module, a, methodAccess); + return false; + }); - if (old != null) { - log.error("已经存在动作解析器:" + apiLoader.actionType()); + if (old != null) { + log.error("已经存在动作解析器:" + apiLoader.actionType()); + } } - } - public boolean dealMethod(Method m, MethodAccess methodAccess) { - boolean result = true; - Annotation[] annos = m.getDeclaredAnnotations(); - if (annos != null) { - for (Annotation anno: annos) { - BiFunction func = dealMethodAnnotation.get(anno.annotationType()); - if (func != null) { - boolean ret = func.apply(anno, methodAccess); - if (!ret) { - result = false; - break; - } + public boolean dealMethod(Method m, MethodAccess methodAccess) { + boolean result = true; + Annotation[] annos = m.getDeclaredAnnotations(); + if (annos != null) { + for (Annotation anno : annos) { + BiFunction func = dealMethodAnnotation.get(anno.annotationType()); + if (func != null) { + boolean ret = func.apply(anno, methodAccess); + if (!ret) { + result = false; + break; + } + } + } } - } - } - return result; - } + return result; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/UrlMaker.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/UrlMaker.java index 7aa6aa9..7971b28 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/UrlMaker.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/controller/scan/UrlMaker.java @@ -11,85 +11,87 @@ import java.lang.reflect.Method; /** * URL构造器,用于API的访问路径构造 + * * @author xkliu */ @Slf4j class UrlMaker { - private static final String SERVICE_SUFFIX = "Service"; + private static final String SERVICE_SUFFIX = "Service"; - private final ApiConfigBean apiConfig; - @Getter - private final String module; - private String serviceUrl; + private final ApiConfigBean apiConfig; + @Getter + private final String module; + private String serviceUrl; - UrlMaker(ApiConfigBean apiConfig, String module) { - this.apiConfig = apiConfig; - this.module = module; - } + UrlMaker(ApiConfigBean apiConfig, String module) { + this.apiConfig = apiConfig; + this.module = module; + } + + private String getServiceName(Class clazz) { + String simpleName = clazz.getSimpleName(); + if (simpleName.endsWith(SERVICE_SUFFIX)) { + simpleName = simpleName.substring(0, simpleName.length() - SERVICE_SUFFIX.length()); + } - private String getServiceName(Class clazz) { - String simpleName = clazz.getSimpleName(); - if (simpleName.endsWith(SERVICE_SUFFIX)) { - simpleName = simpleName.substring(0, simpleName.length() - SERVICE_SUFFIX.length()); + return simpleName; } - return simpleName; - } + /** + * 添加API映射到BeanManager,API的url先取SwApi配置的值,然后取SwService配置的值+“/”+方法名,最后使用默认规则: “服务名” / "方法名" + * url都以模块名开头,避免应用模块服务名称重复 + * + * @param clazz 服务类 + * @param method 执行方法,用于映射API + * @param methodAccess 方法实际执行 + * @param controllers 控制器管理容器 + */ + void addApi(Class clazz, Method method, MethodAccess methodAccess, BeanManager controllers) { + String serviceName = getServiceName(clazz); + String methodName = method.getName(); + String urlPrefix = module + "/"; + SwAction swAction = method.getAnnotation(SwAction.class); - /** - * 添加API映射到BeanManager,API的url先取SwApi配置的值,然后取SwService配置的值+“/”+方法名,最后使用默认规则: “服务名” / "方法名" - * url都以模块名开头,避免应用模块服务名称重复 - * @param clazz 服务类 - * @param method 执行方法,用于映射API - * @param methodAccess 方法实际执行 - * @param controllers 控制器管理容器 - */ - void addApi(Class clazz, Method method, MethodAccess methodAccess, BeanManager controllers) { - String serviceName = getServiceName(clazz); - String methodName = method.getName(); - String urlPrefix = module + "/"; - SwAction swAction = method.getAnnotation(SwAction.class); + if (swAction != null && StringUtils.isNotBlank(swAction.value())) { + // SwApi设置了URL + mappingApi(methodAccess, controllers, urlPrefix + swAction.value()); + } else if (this.serviceUrl != null) { + // SwService设置了URL + mappingApi(methodAccess, controllers, urlPrefix + this.serviceUrl + "/" + methodName); + } else { + // 小驼峰路径 + String littleCamelCaseUrl = urlPrefix + toLittleCamelName(serviceName) + "/" + methodName; - if (swAction != null && StringUtils.isNotBlank(swAction.value())) { - // SwApi设置了URL - mappingApi(methodAccess, controllers, urlPrefix + swAction.value()); - } else if (this.serviceUrl != null) { - // SwService设置了URL - mappingApi(methodAccess, controllers, urlPrefix + this.serviceUrl + "/" + methodName); - } else { - // 小驼峰路径 - String littleCamelCaseUrl = urlPrefix + toLittleCamelName(serviceName) + "/" + methodName; + if (mappingApi(methodAccess, controllers, littleCamelCaseUrl)) { + // 大驼峰路径,类原名 + if (apiConfig.isBigCameCaseUrl()) { + mappingApi(methodAccess, controllers, urlPrefix + serviceName + "/" + methodName); + } - if (mappingApi(methodAccess, controllers, littleCamelCaseUrl)) { - // 大驼峰路径,类原名 - if (apiConfig.isBigCameCaseUrl()) { - mappingApi(methodAccess, controllers, urlPrefix + serviceName + "/" + methodName); + // 小写服务名路径 + if (apiConfig.isLowerCaseUrl()) { + mappingApi(methodAccess, controllers, urlPrefix + serviceName.toLowerCase() + "/" + methodName); + } + } } + } - // 小写服务名路径 - if (apiConfig.isLowerCaseUrl()) { - mappingApi(methodAccess, controllers, urlPrefix + serviceName.toLowerCase() + "/" + methodName); - } - } + private String toLittleCamelName(String serviceName) { + return Character.toLowerCase(serviceName.charAt(0)) + + serviceName.substring(1); } - } - private String toLittleCamelName(String serviceName) { - return Character.toLowerCase(serviceName.charAt(0)) - + serviceName.substring(1); - } + private boolean mappingApi(MethodAccess methodAccess, BeanManager controllers, String url) { + if (controllers.putIfAbsent(url, methodAccess) != null) { + log.error("url is repeat: " + url + ", " + methodAccess.controllerFullName()); + return false; + } - private boolean mappingApi(MethodAccess methodAccess, BeanManager controllers, String url) { - if (controllers.putIfAbsent(url, methodAccess) != null) { - log.error("url is repeat: " + url + ", " + methodAccess.controllerFullName()); - return false; + log.debug("[smt]init: " + url + ", " + methodAccess.controllerFullName()); + return true; } - log.debug("[smt]init: " + url + ", " + methodAccess.controllerFullName()); - return true; - } - - void setServiceUrl(String value) { - this.serviceUrl = StringUtils.trimToNull(value); - } + void setServiceUrl(String value) { + this.serviceUrl = StringUtils.trimToNull(value); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/IRealmLoader.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/IRealmLoader.java index 5d5a490..dbd3b7a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/IRealmLoader.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/IRealmLoader.java @@ -9,10 +9,11 @@ import java.util.Set; * 用户权限加载器 */ public interface IRealmLoader { - /** - * 读取用户权限集合 - * @param userSession 用户会话 - * @return 权限集合 - */ - Set getPermits(UserSession userSession); + /** + * 读取用户权限集合 + * + * @param userSession 用户会话 + * @return 权限集合 + */ + Set getPermits(UserSession userSession); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/AuthenticationException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/AuthenticationException.java index 3a65419..35a81da 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/AuthenticationException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/AuthenticationException.java @@ -1,7 +1,7 @@ package cc.smtweb.framework.core.mvc.realm.exception; public class AuthenticationException extends AuthorizationException { - public AuthenticationException(String s) { - super(s); - } + public AuthenticationException(String s) { + super(s); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/AuthorizationException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/AuthorizationException.java index 423cbbd..5437c96 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/AuthorizationException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/AuthorizationException.java @@ -3,7 +3,7 @@ package cc.smtweb.framework.core.mvc.realm.exception; import cc.smtweb.framework.core.exception.SwException; public class AuthorizationException extends SwException { - public AuthorizationException(String s) { - super(s); - } + public AuthorizationException(String s) { + super(s); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/ForbiddenException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/ForbiddenException.java index 2aa0cdd..0bfe347 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/ForbiddenException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/ForbiddenException.java @@ -1,7 +1,7 @@ package cc.smtweb.framework.core.mvc.realm.exception; public class ForbiddenException extends AuthorizationException { - public ForbiddenException(String s) { - super(s); - } + public ForbiddenException(String s) { + super(s); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/UnauthenticatedException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/UnauthenticatedException.java index 52ea554..1ecb280 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/UnauthenticatedException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/UnauthenticatedException.java @@ -1,7 +1,7 @@ package cc.smtweb.framework.core.mvc.realm.exception; public class UnauthenticatedException extends AuthorizationException { - public UnauthenticatedException(String s) { - super(s); - } + public UnauthenticatedException(String s) { + super(s); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/UnknownAccountException.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/UnknownAccountException.java index 3ac1681..08bdaec 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/UnknownAccountException.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/exception/UnknownAccountException.java @@ -1,7 +1,7 @@ package cc.smtweb.framework.core.mvc.realm.exception; public class UnknownAccountException extends AuthorizationException { - public UnknownAccountException(String s) { - super(s); - } + public UnknownAccountException(String s) { + super(s); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/interceptor/AuthorizationInterceptor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/interceptor/AuthorizationInterceptor.java index 47a24d5..b6430f0 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/interceptor/AuthorizationInterceptor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/interceptor/AuthorizationInterceptor.java @@ -13,30 +13,30 @@ import javax.servlet.http.HttpServletResponse; */ public class AuthorizationInterceptor extends AbstractPermInterceptor implements HandlerInterceptor { - public AuthorizationInterceptor(RedisManager redisManager) { - super(redisManager); - } - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) - throws Exception { - if (handler instanceof HandlerMethod) { - HandlerMethod handlerMethod = (HandlerMethod) handler; - // 获取方法上的注解 - SwPerm requiredSwPerm = handlerMethod.getMethod().getAnnotation(SwPerm.class); - // 如果方法上的注解为空 则获取类的注解 - if (requiredSwPerm == null) { - requiredSwPerm = handlerMethod.getMethod().getDeclaringClass().getAnnotation(SwPerm.class); - } - - String requiredValue = null; - if (requiredSwPerm != null) { - requiredValue = requiredSwPerm.value(); - } - - return super.handle(request, requiredValue); + public AuthorizationInterceptor(RedisManager redisManager) { + super(redisManager); } - return true; - } + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + if (handler instanceof HandlerMethod) { + HandlerMethod handlerMethod = (HandlerMethod) handler; + // 获取方法上的注解 + SwPerm requiredSwPerm = handlerMethod.getMethod().getAnnotation(SwPerm.class); + // 如果方法上的注解为空 则获取类的注解 + if (requiredSwPerm == null) { + requiredSwPerm = handlerMethod.getMethod().getDeclaringClass().getAnnotation(SwPerm.class); + } + + String requiredValue = null; + if (requiredSwPerm != null) { + requiredValue = requiredSwPerm.value(); + } + + return super.handle(request, requiredValue); + } + + return true; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/interceptor/PermInterceptor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/interceptor/PermInterceptor.java index dcf9184..0edd4b0 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/interceptor/PermInterceptor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/interceptor/PermInterceptor.java @@ -6,20 +6,22 @@ import javax.servlet.http.HttpServletRequest; /** * 权限拦截器,在API请求处理中一起完成 + * * @author xkliu */ public class PermInterceptor extends AbstractPermInterceptor { - public PermInterceptor(RedisManager redisManager) { - super(redisManager); - } + public PermInterceptor(RedisManager redisManager) { + super(redisManager); + } - /** - * 校验用户是否有API权限 - * @param request http请求 - * @param permissionValue 权限值 - * @return 是否有权限 - */ - public boolean preHandle(HttpServletRequest request, String permissionValue) { - return super.handle(request, permissionValue); - } + /** + * 校验用户是否有API权限 + * + * @param request http请求 + * @param permissionValue 权限值 + * @return 是否有权限 + */ + public boolean preHandle(HttpServletRequest request, String permissionValue) { + return super.handle(request, permissionValue); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/service/PermCheckItem.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/service/PermCheckItem.java index 2cecf28..50753c4 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/service/PermCheckItem.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/service/PermCheckItem.java @@ -1,21 +1,21 @@ package cc.smtweb.framework.core.mvc.realm.service; public class PermCheckItem { - // 全匹配 - private static final int TYPE_ALL_MATCH = 0; - // 前缀匹配 - private static final int TYPE_PREFIX_MATCH = 1; + // 全匹配 + private static final int TYPE_ALL_MATCH = 0; + // 前缀匹配 + private static final int TYPE_PREFIX_MATCH = 1; - private int type; + private int type; - public static final PermCheckItem allMatch = new PermCheckItem(TYPE_ALL_MATCH); - public static final PermCheckItem prefixMatch = new PermCheckItem(TYPE_PREFIX_MATCH); + public static final PermCheckItem allMatch = new PermCheckItem(TYPE_ALL_MATCH); + public static final PermCheckItem prefixMatch = new PermCheckItem(TYPE_PREFIX_MATCH); - private PermCheckItem(int type) { - this.type = type; - } + private PermCheckItem(int type) { + this.type = type; + } - public boolean isPerfixMath() { - return this.type == TYPE_PREFIX_MATCH; - } + public boolean isPerfixMath() { + return this.type == TYPE_PREFIX_MATCH; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/service/PermChecker.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/service/PermChecker.java index 8bb2cc5..01db85d 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/service/PermChecker.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/realm/service/PermChecker.java @@ -4,32 +4,32 @@ import java.util.HashMap; import java.util.Set; public class PermChecker extends HashMap { - private static final PermChecker CHECKER_ZERO = new PermChecker(); - - private PermChecker(){ - super(); - } - - private PermChecker(int size){ - super(size); - } - - public static PermChecker build(Set permits) { - if (permits != null) { - PermChecker result = new PermChecker(permits.size()); - - for (String perm: permits) { - if (perm.endsWith(":*")) { - perm = perm.substring(0, perm.length() - 2); - result.put(perm, PermCheckItem.prefixMatch); - } else { - result.putIfAbsent(perm, PermCheckItem.allMatch); - } - } + private static final PermChecker CHECKER_ZERO = new PermChecker(); + + private PermChecker() { + super(); + } - return result; + private PermChecker(int size) { + super(size); } - return CHECKER_ZERO; - } + public static PermChecker build(Set permits) { + if (permits != null) { + PermChecker result = new PermChecker(permits.size()); + + for (String perm : permits) { + if (perm.endsWith(":*")) { + perm = perm.substring(0, perm.length() - 2); + result.put(perm, PermCheckItem.prefixMatch); + } else { + result.putIfAbsent(perm, PermCheckItem.allMatch); + } + } + + return result; + } + + return CHECKER_ZERO; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJob.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJob.java index d3d8030..c51100a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJob.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJob.java @@ -6,21 +6,21 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class AbstractJob { - final MethodAccess method; - @Getter - private String key; - boolean hasPointParam; + final MethodAccess method; + @Getter + private String key; + boolean hasPointParam; // @Getter @Setter // private AbstractJobQueue jobQueue; - public AbstractJob(MethodAccess methodAccess) { - this.method = methodAccess; - this.hasPointParam = methodAccess.findParam(SchedulerPoint.class) != null; - } + public AbstractJob(MethodAccess methodAccess) { + this.method = methodAccess; + this.hasPointParam = methodAccess.findParam(SchedulerPoint.class) != null; + } - protected void initKey(String key) { - this.key = key; - } + protected void initKey(String key) { + this.key = key; + } // public void invoke(Map params) { // try { @@ -51,9 +51,9 @@ public abstract class AbstractJob { // } // } - public abstract AbstractJobQueue createJobQueue(AbstractJobExecutor jobManager); + public abstract AbstractJobQueue createJobQueue(AbstractJobExecutor jobManager); - public String getName() { - return this.method.fullName(); - } + public String getName() { + return this.method.fullName(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJobExecutor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJobExecutor.java index 57a0fe4..ea9887d 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJobExecutor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJobExecutor.java @@ -12,74 +12,74 @@ import java.util.Map; import java.util.concurrent.ExecutorService; public abstract class AbstractJobExecutor { - @Getter - private IBeanContext beanContext; - private ExecutorService executor; - protected Long redisLockValue; - private DbEngine dbEngine; - protected final Map jobMap = new HashMap<>(); + @Getter + private IBeanContext beanContext; + private ExecutorService executor; + protected Long redisLockValue; + private DbEngine dbEngine; + protected final Map jobMap = new HashMap<>(); - public AbstractJobExecutor(IBeanContext beanContext, ExecutorService executor, Long redisLockValue, DbEngine dbEngine) { - this.beanContext = beanContext; - this.executor = executor; - this.redisLockValue = redisLockValue; - this.dbEngine = dbEngine; - } + public AbstractJobExecutor(IBeanContext beanContext, ExecutorService executor, Long redisLockValue, DbEngine dbEngine) { + this.beanContext = beanContext; + this.executor = executor; + this.redisLockValue = redisLockValue; + this.dbEngine = dbEngine; + } - public abstract boolean tryLock(AbstractJob job); + public abstract boolean tryLock(AbstractJob job); - public abstract void unlock(AbstractJob job); + public abstract void unlock(AbstractJob job); - // 执行任务 - public void execute(final AbstractJobQueue jobQueue, final AbstractJob job) { - this.executor.submit(() -> { - if (tryLock(job)) { - try { - jobQueue.execute(job); - } finally { - unlock(job); - } - } - }); - } + // 执行任务 + public void execute(final AbstractJobQueue jobQueue, final AbstractJob job) { + this.executor.submit(() -> { + if (tryLock(job)) { + try { + jobQueue.execute(job); + } finally { + unlock(job); + } + } + }); + } - void saveBreakPoint(AbstractJob job, SchedulerPoint schedulerPoint) { - if (schedulerPoint != null && schedulerPoint.changed) { - String value = JsonUtil.encodeString(schedulerPoint.value); - long now = DateUtil.nowDateTimeLong(); - if (schedulerPoint.insert) { - dbEngine.update("insert into sw_user.sch_break_point(bp_id, bp_job_name, bp_machine_id, bp_value, bp_create_time, bp_last_time) values(?,?,?,?,?,?)", - dbEngine.nextId(), job.getName(), this.redisLockValue, value, now, now); - } else { - dbEngine.update("update sw_user.sch_break_point set bp_machine_id=?, bp_value=?, bp_last_time=? where bp_job_name=?", - this.redisLockValue, value, now, job.getName()); - } + void saveBreakPoint(AbstractJob job, SchedulerPoint schedulerPoint) { + if (schedulerPoint != null && schedulerPoint.changed) { + String value = JsonUtil.encodeString(schedulerPoint.value); + long now = DateUtil.nowDateTimeLong(); + if (schedulerPoint.insert) { + dbEngine.update("insert into sw_user.sch_break_point(bp_id, bp_job_name, bp_machine_id, bp_value, bp_create_time, bp_last_time) values(?,?,?,?,?,?)", + dbEngine.nextId(), job.getName(), this.redisLockValue, value, now, now); + } else { + dbEngine.update("update sw_user.sch_break_point set bp_machine_id=?, bp_value=?, bp_last_time=? where bp_job_name=?", + this.redisLockValue, value, now, job.getName()); + } + } } - } - SchedulerPoint loadBreakPoint(AbstractJob job) { - String value = dbEngine.queryString("select bp_value from sw_user.sch_break_point where bp_job_name=?", job.getName()); + SchedulerPoint loadBreakPoint(AbstractJob job) { + String value = dbEngine.queryString("select bp_value from sw_user.sch_break_point where bp_job_name=?", job.getName()); - SchedulerPoint result; - if (value != null) { - SwMap swMap = JsonUtil.parse(value, SwMap.class); - result = new SchedulerPoint(swMap); - } else { - result = new SchedulerPoint(); + SchedulerPoint result; + if (value != null) { + SwMap swMap = JsonUtil.parse(value, SwMap.class); + result = new SchedulerPoint(swMap); + } else { + result = new SchedulerPoint(); + } + + return result; } - return result; - } + AbstractJobQueue initJobQueue(AbstractJob job) { + String key = job.getKey(); - AbstractJobQueue initJobQueue(AbstractJob job) { - String key = job.getKey(); + AbstractJobQueue jobQueue = jobMap.get(key); + if (jobQueue == null) { + jobQueue = job.createJobQueue(this); + jobMap.put(key, jobQueue); + } - AbstractJobQueue jobQueue = jobMap.get(key); - if (jobQueue == null) { - jobQueue = job.createJobQueue(this); - jobMap.put(key, jobQueue); + return jobQueue; } - - return jobQueue; - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJobQueue.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJobQueue.java index 1f5993f..cc39fec 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJobQueue.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/AbstractJobQueue.java @@ -10,63 +10,64 @@ import java.util.concurrent.locks.ReentrantLock; /** * Job执行队列 + * * @author xkliu */ @Slf4j public abstract class AbstractJobQueue { - private AtomicLong lastTime = new AtomicLong(); - private ReentrantLock lock = new ReentrantLock(); - @Getter - private AbstractJobExecutor jobExecutor; + private AtomicLong lastTime = new AtomicLong(); + private ReentrantLock lock = new ReentrantLock(); + @Getter + private AbstractJobExecutor jobExecutor; - public AbstractJobQueue(AbstractJobExecutor jobExecutor) { - this.jobExecutor = jobExecutor; - } + public AbstractJobQueue(AbstractJobExecutor jobExecutor) { + this.jobExecutor = jobExecutor; + } - public void execute(AbstractJob job) { - try { - // 组织断点对象参数 - Map params = null; - SchedulerPoint schedulerPoint = null; - if (job.hasPointParam) { - schedulerPoint = jobExecutor.loadBreakPoint(job); - if (schedulerPoint != null) { - params = new HashMap<>(1); - params.put(SchedulerPoint.class.getName(), schedulerPoint); - } - } + public void execute(AbstractJob job) { + try { + // 组织断点对象参数 + Map params = null; + SchedulerPoint schedulerPoint = null; + if (job.hasPointParam) { + schedulerPoint = jobExecutor.loadBreakPoint(job); + if (schedulerPoint != null) { + params = new HashMap<>(1); + params.put(SchedulerPoint.class.getName(), schedulerPoint); + } + } - job.method.invoke(jobExecutor.getBeanContext(), params, null, null); + job.method.invoke(jobExecutor.getBeanContext(), params, null, null); + + if (job.hasPointParam) { + jobExecutor.saveBreakPoint(job, schedulerPoint); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + } - if (job.hasPointParam) { - jobExecutor.saveBreakPoint(job, schedulerPoint); - } - } catch (Exception e) { - log.error(e.getMessage(), e); } - } + public long getLastTime() { + return lastTime.get(); + } - public long getLastTime() { - return lastTime.get(); - } + protected boolean tryLock() { + boolean result = lock.tryLock(); - protected boolean tryLock() { - boolean result = lock.tryLock(); + if (result) { + lastTime.set(System.currentTimeMillis()); + } - if (result) { - lastTime.set(System.currentTimeMillis()); + return result; } - return result; - } - - protected void unlock() { - lastTime.set(0); - lock.unlock(); - } + protected void unlock() { + lastTime.set(0); + lock.unlock(); + } - public void updateLastTime() { - lastTime.set(System.currentTimeMillis()); - } + public void updateLastTime() { + lastTime.set(System.currentTimeMillis()); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/CronTimerTask.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/CronTimerTask.java index 4184df9..caa87c9 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/CronTimerTask.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/CronTimerTask.java @@ -9,22 +9,21 @@ import lombok.extern.slf4j.Slf4j; * 包装定时器任务 * * @author xkliu - * */ @Slf4j public class CronTimerTask extends TimerTask { - private final AbstractJobQueue jobQueue; - private AbstractJob job; + private final AbstractJobQueue jobQueue; + private AbstractJob job; - CronTimerTask(TimerTrigger timerTrigger, AbstractJobQueue jobQueue, AbstractJob job) { - super(timerTrigger); - this.jobQueue = jobQueue; - this.job = job; - } + CronTimerTask(TimerTrigger timerTrigger, AbstractJobQueue jobQueue, AbstractJob job) { + super(timerTrigger); + this.jobQueue = jobQueue; + this.job = job; + } - @Override - public void run(long time) { - // 开启线程执行 - jobQueue.getJobExecutor().execute(jobQueue, job); - } + @Override + public void run(long time) { + // 开启线程执行 + jobQueue.getJobExecutor().execute(jobQueue, job); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/FixedTimerTask.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/FixedTimerTask.java index 7f33937..12708bc 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/FixedTimerTask.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/FixedTimerTask.java @@ -4,16 +4,16 @@ import com.serotonin.timer.FixedRateTrigger; import com.serotonin.timer.TimerTask; public class FixedTimerTask extends TimerTask { - private final Runnable job; + private final Runnable job; - // new TimerTask(new FixedRateTrigger(30, 60)), result.redisJobManager - public FixedTimerTask(int delay, int period, Runnable job) { - super(new FixedRateTrigger(delay, period)); - this.job = job; - } + // new TimerTask(new FixedRateTrigger(30, 60)), result.redisJobManager + public FixedTimerTask(int delay, int period, Runnable job) { + super(new FixedRateTrigger(delay, period)); + this.job = job; + } - @Override - public void run(long runtime) { - job.run(); - } + @Override + public void run(long runtime) { + job.run(); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/SchedulerPoint.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/SchedulerPoint.java index b2bf66c..eb415c0 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/SchedulerPoint.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/SchedulerPoint.java @@ -4,37 +4,39 @@ import cc.smtweb.framework.core.common.SwMap; /** * 定时器断点数据 + * * @author xkliu */ public class SchedulerPoint { - SwMap value; - boolean changed; - boolean insert; - - public SchedulerPoint() { - insert = true; - value = new SwMap(); - } - - public SchedulerPoint(SwMap value) { - this.value = value; - } - - public Object get(String key) { - return value.get(key); - } - - public Long readLong(String key) { - return value.readLong(key); - } - public Long readLong(String key, Long defaultValue) { - return value.readLong(key, defaultValue); - } - - public SchedulerPoint put(String key, Object value) { - this.value.put(key, value); - this.changed = true; - - return this; - } + SwMap value; + boolean changed; + boolean insert; + + public SchedulerPoint() { + insert = true; + value = new SwMap(); + } + + public SchedulerPoint(SwMap value) { + this.value = value; + } + + public Object get(String key) { + return value.get(key); + } + + public Long readLong(String key) { + return value.readLong(key); + } + + public Long readLong(String key, Long defaultValue) { + return value.readLong(key, defaultValue); + } + + public SchedulerPoint put(String key, Object value) { + this.value.put(key, value); + this.changed = true; + + return this; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/SchedulerTaskManager.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/SchedulerTaskManager.java index 7fe5a7d..5a21e8a 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/SchedulerTaskManager.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/SchedulerTaskManager.java @@ -24,74 +24,74 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class SchedulerTaskManager implements ISchedulerWakeup { - private final ExecutorService executor; - private final RealTimeTimer timer; - private final Map timerTaskMap = new HashMap<>(); - - private SchedulerTaskManager() { - int poolSize = Runtime.getRuntime().availableProcessors(); - this.executor = new ThreadPoolExecutor(2, poolSize * 2 + 2, 5, TimeUnit.MINUTES, - new SynchronousQueue<>(), - new BasicThreadFactory.Builder().namingPattern("sw-scheduler-").build()); - - // 保证2个线程就够了,1个触发定时器,1个定时同步redis状态 - this.timer = new RealTimeTimer(); - this.timer.init(1, 4); - } - - public static SchedulerTaskManager build(IBeanContext beanContext, List tasks) { - if (!tasks.isEmpty()) { - SchedulerTaskManager result = new SchedulerTaskManager(); - - DbEngine dbEngine = beanContext.getBean(DbEngine.class); - RedisManager redisManager = beanContext.getBean(RedisManager.class); - Long redisLockValue = dbEngine.nextId(); - - LocalJobExecutor localJobExecutor = new LocalJobExecutor(beanContext, result.executor, redisLockValue, dbEngine); - RedisJobExecutor redisJobExecutor = new RedisJobExecutor(beanContext, result.executor, redisLockValue, dbEngine, redisManager); - - for (SchedulerMethodAccess schedulerMethodAccess: tasks) { - SwScheduling swScheduling = schedulerMethodAccess.getSwScheduling(); - - AbstractJob job; - String group = swScheduling.group(); - AbstractJobExecutor jobManager = swScheduling.multiServer() ? localJobExecutor : redisJobExecutor; - - if (StringUtils.isNotBlank(group)) { - job = new GroupJob(group, schedulerMethodAccess.getMethodAccess()); - } else { - job = new SimpleJob(schedulerMethodAccess.getMethodAccess()); - } + private final ExecutorService executor; + private final RealTimeTimer timer; + private final Map timerTaskMap = new HashMap<>(); + + private SchedulerTaskManager() { + int poolSize = Runtime.getRuntime().availableProcessors(); + this.executor = new ThreadPoolExecutor(2, poolSize * 2 + 2, 5, TimeUnit.MINUTES, + new SynchronousQueue<>(), + new BasicThreadFactory.Builder().namingPattern("sw-scheduler-").build()); + + // 保证2个线程就够了,1个触发定时器,1个定时同步redis状态 + this.timer = new RealTimeTimer(); + this.timer.init(1, 4); + } - AbstractJobQueue jobQueue = jobManager.initJobQueue(job); - CronTimerTask task = new CronTimerTask(schedulerMethodAccess.getTimerTrigger(), jobQueue, job); + public static SchedulerTaskManager build(IBeanContext beanContext, List tasks) { + if (!tasks.isEmpty()) { + SchedulerTaskManager result = new SchedulerTaskManager(); - result.timer.schedule(task); - result.timerTaskMap.put(job.getName(), task); - } + DbEngine dbEngine = beanContext.getBean(DbEngine.class); + RedisManager redisManager = beanContext.getBean(RedisManager.class); + Long redisLockValue = dbEngine.nextId(); - int time = RedisJobExecutor.TIME_CHECK_SEC * 1000; - result.timer.schedule(new FixedTimerTask(time, time, redisJobExecutor)); + LocalJobExecutor localJobExecutor = new LocalJobExecutor(beanContext, result.executor, redisLockValue, dbEngine); + RedisJobExecutor redisJobExecutor = new RedisJobExecutor(beanContext, result.executor, redisLockValue, dbEngine, redisManager); - return result; - } + for (SchedulerMethodAccess schedulerMethodAccess : tasks) { + SwScheduling swScheduling = schedulerMethodAccess.getSwScheduling(); + + AbstractJob job; + String group = swScheduling.group(); + AbstractJobExecutor jobManager = swScheduling.multiServer() ? localJobExecutor: redisJobExecutor; - return null; - } + if (StringUtils.isNotBlank(group)) { + job = new GroupJob(group, schedulerMethodAccess.getMethodAccess()); + } else { + job = new SimpleJob(schedulerMethodAccess.getMethodAccess()); + } - public void shutdown() { - this.timer.cancel(); - this.executor.shutdown(); - } + AbstractJobQueue jobQueue = jobManager.initJobQueue(job); + CronTimerTask task = new CronTimerTask(schedulerMethodAccess.getTimerTrigger(), jobQueue, job); - @Override - public boolean wakeup(Class clazz, String methodName) { - TimerTask task = timerTaskMap.get(clazz.getName() + "." + methodName); - if (task != null) { - task.run(System.currentTimeMillis()); - return true; + result.timer.schedule(task); + result.timerTaskMap.put(job.getName(), task); + } + + int time = RedisJobExecutor.TIME_CHECK_SEC * 1000; + result.timer.schedule(new FixedTimerTask(time, time, redisJobExecutor)); + + return result; + } + + return null; + } + + public void shutdown() { + this.timer.cancel(); + this.executor.shutdown(); } - return false; - } + @Override + public boolean wakeup(Class clazz, String methodName) { + TimerTask task = timerTaskMap.get(clazz.getName() + "." + methodName); + if (task != null) { + task.run(System.currentTimeMillis()); + return true; + } + + return false; + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/GroupJob.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/GroupJob.java index 0fc49c5..019ad6e 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/GroupJob.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/GroupJob.java @@ -7,13 +7,13 @@ import cc.smtweb.framework.core.mvc.scheduler.AbstractJobExecutor; import cc.smtweb.framework.core.mvc.scheduler.AbstractJobQueue; public class GroupJob extends AbstractJob { - @Override - public AbstractJobQueue createJobQueue(AbstractJobExecutor jobManager) { - return new GroupJobQueue(jobManager); - } + @Override + public AbstractJobQueue createJobQueue(AbstractJobExecutor jobManager) { + return new GroupJobQueue(jobManager); + } - public GroupJob(String group, MethodAccess methodAccess) { - super(methodAccess); - initKey(RedisManager.PREFIX_TIMER + '.' + group); - } + public GroupJob(String group, MethodAccess methodAccess) { + super(methodAccess); + initKey(RedisManager.PREFIX_TIMER + '.' + group); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/GroupJobQueue.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/GroupJobQueue.java index 2fd9a56..13dd47c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/GroupJobQueue.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/GroupJobQueue.java @@ -10,73 +10,75 @@ import java.util.LinkedList; import java.util.Set; public class GroupJobQueue extends AbstractJobQueue { - private Deque queue; - private Set keySet; - private String currentJobName; + private Deque queue; + private Set keySet; + private String currentJobName; - public GroupJobQueue(AbstractJobExecutor jobManager) {super(jobManager);} + public GroupJobQueue(AbstractJobExecutor jobManager) { + super(jobManager); + } - private synchronized void setCurrent(AbstractJob job) { - currentJobName = job.getName(); - } + private synchronized void setCurrent(AbstractJob job) { + currentJobName = job.getName(); + } - private synchronized AbstractJob pull() { - AbstractJob result = null; + private synchronized AbstractJob pull() { + AbstractJob result = null; - if (queue != null) { - result = queue.pop(); + if (queue != null) { + result = queue.pop(); - if (result != null) { - keySet.remove(result.getName()); - } - } + if (result != null) { + keySet.remove(result.getName()); + } + } - if (result != null) { - this.currentJobName = result.getName(); - } else { - this.currentJobName = null; + if (result != null) { + this.currentJobName = result.getName(); + } else { + this.currentJobName = null; + } + + return result; } - return result; - } + private synchronized boolean push(AbstractJob job) { + String jobName = job.getName(); - private synchronized boolean push(AbstractJob job) { - String jobName = job.getName(); + if (jobName.equals(currentJobName)) { + return false; + } - if (jobName.equals(currentJobName)) { - return false; - } + if (keySet == null) { + keySet = new HashSet<>(); + } else if (keySet.contains(jobName)) { + // 避免重复加入 + return false; + } - if (keySet == null) { - keySet = new HashSet<>(); - } else if (keySet.contains(jobName)) { - // 避免重复加入 - return false; - } + keySet.add(jobName); - keySet.add(jobName); + if (queue == null) { + queue = new LinkedList<>(); + } - if (queue == null) { - queue = new LinkedList<>(); + queue.push(job); + return true; } - queue.push(job); - return true; - } - - @Override - public void execute(AbstractJob job) { - if (tryLock()) { - try { - setCurrent(job); - do { - super.execute(job); - } while((job = pull()) != null); - } finally { - unlock(); - } - } else { - push(job); + @Override + public void execute(AbstractJob job) { + if (tryLock()) { + try { + setCurrent(job); + do { + super.execute(job); + } while ((job = pull()) != null); + } finally { + unlock(); + } + } else { + push(job); + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/LocalJobExecutor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/LocalJobExecutor.java index d085307..cda4be1 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/LocalJobExecutor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/LocalJobExecutor.java @@ -8,16 +8,16 @@ import cc.smtweb.framework.core.mvc.scheduler.AbstractJobExecutor; import java.util.concurrent.ExecutorService; public class LocalJobExecutor extends AbstractJobExecutor { - public LocalJobExecutor(IBeanContext beanContext, ExecutorService executor, Long redisLockValue, DbEngine dbEngine) { - super(beanContext, executor, redisLockValue, dbEngine); - } + public LocalJobExecutor(IBeanContext beanContext, ExecutorService executor, Long redisLockValue, DbEngine dbEngine) { + super(beanContext, executor, redisLockValue, dbEngine); + } - @Override - public boolean tryLock(AbstractJob job) { - return true; - } + @Override + public boolean tryLock(AbstractJob job) { + return true; + } - @Override - public void unlock(AbstractJob job) { - } + @Override + public void unlock(AbstractJob job) { + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/RedisJobExecutor.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/RedisJobExecutor.java index 643d67a..34f2fcf 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/RedisJobExecutor.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/RedisJobExecutor.java @@ -12,59 +12,59 @@ import java.util.concurrent.locks.ReentrantLock; @Slf4j public class RedisJobExecutor extends AbstractJobExecutor implements Runnable { - public static final int TIME_CHECK_SEC = 30; - public static final int TIME_LOOK_SEC = 3 * TIME_CHECK_SEC; + public static final int TIME_CHECK_SEC = 30; + public static final int TIME_LOOK_SEC = 3 * TIME_CHECK_SEC; - private ReentrantLock lock = new ReentrantLock(); - private RedisManager redisManager; + private ReentrantLock lock = new ReentrantLock(); + private RedisManager redisManager; - public RedisJobExecutor(IBeanContext beanContext, ExecutorService executor, Long redisLockValue, DbEngine dbEngine, RedisManager redisManager) { - super(beanContext, executor, redisLockValue, dbEngine); - this.redisManager = redisManager; - } + public RedisJobExecutor(IBeanContext beanContext, ExecutorService executor, Long redisLockValue, DbEngine dbEngine, RedisManager redisManager) { + super(beanContext, executor, redisLockValue, dbEngine); + this.redisManager = redisManager; + } - @Override - public boolean tryLock(AbstractJob job) { - // redis检查, 同group需要排队等待执行\ - String key = job.getKey(); + @Override + public boolean tryLock(AbstractJob job) { + // redis检查, 同group需要排队等待执行\ + String key = job.getKey(); - boolean redisLocked = redisManager.setnx(key, redisLockValue, TIME_LOOK_SEC); + boolean redisLocked = redisManager.setnx(key, redisLockValue, TIME_LOOK_SEC); - if (!redisLocked) { - Long oldLockedValue = redisManager.get(key, Long.class); - if (!redisLockValue.equals(oldLockedValue)) { - return false; - } - } + if (!redisLocked) { + Long oldLockedValue = redisManager.get(key, Long.class); + if (!redisLockValue.equals(oldLockedValue)) { + return false; + } + } - return redisLocked; - } + return redisLocked; + } - @Override - public void unlock(AbstractJob job) { - redisManager.del(job.getKey()); - } + @Override + public void unlock(AbstractJob job) { + redisManager.del(job.getKey()); + } - @Override - public void run() { - if (lock.tryLock()) { - try { - // 定时更新redis锁定状态 - long now = System.currentTimeMillis(); - jobMap.forEach((key, value) -> { - long lastTime = value.getLastTime(); + @Override + public void run() { + if (lock.tryLock()) { + try { + // 定时更新redis锁定状态 + long now = System.currentTimeMillis(); + jobMap.forEach((key, value) -> { + long lastTime = value.getLastTime(); - if (lastTime > 0 && now - lastTime >= TIME_CHECK_SEC) { - if (redisManager.set(key, redisLockValue, TIME_LOOK_SEC)) { - value.updateLastTime(); - } else { - log.error("update redis lock failed, key: " + key); + if (lastTime > 0 && now - lastTime >= TIME_CHECK_SEC) { + if (redisManager.set(key, redisLockValue, TIME_LOOK_SEC)) { + value.updateLastTime(); + } else { + log.error("update redis lock failed, key: " + key); + } + } + }); + } finally { + lock.unlock(); } - } - }); - } finally { - lock.unlock(); - } + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/SimpleJob.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/SimpleJob.java index 19b2720..52f3dd2 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/SimpleJob.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/SimpleJob.java @@ -7,13 +7,13 @@ import cc.smtweb.framework.core.mvc.scheduler.AbstractJobExecutor; import cc.smtweb.framework.core.mvc.scheduler.AbstractJobQueue; public class SimpleJob extends AbstractJob { - public SimpleJob(MethodAccess methodAccess) { - super(methodAccess); - initKey(RedisManager.PREFIX_TIMER + methodAccess.fullName()); - } + public SimpleJob(MethodAccess methodAccess) { + super(methodAccess); + initKey(RedisManager.PREFIX_TIMER + methodAccess.fullName()); + } - @Override - public AbstractJobQueue createJobQueue(AbstractJobExecutor jobManager) { - return new SimpleJobQueue(jobManager); - } + @Override + public AbstractJobQueue createJobQueue(AbstractJobExecutor jobManager) { + return new SimpleJobQueue(jobManager); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/SimpleJobQueue.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/SimpleJobQueue.java index e0de2d1..3aa9fde 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/SimpleJobQueue.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/scheduler/job/SimpleJobQueue.java @@ -5,18 +5,18 @@ import cc.smtweb.framework.core.mvc.scheduler.AbstractJobExecutor; import cc.smtweb.framework.core.mvc.scheduler.AbstractJobQueue; public class SimpleJobQueue extends AbstractJobQueue { - public SimpleJobQueue(AbstractJobExecutor jobManager) { - super(jobManager); - } + public SimpleJobQueue(AbstractJobExecutor jobManager) { + super(jobManager); + } - @Override - public void execute(AbstractJob job) { - if (tryLock()) { - try { - super.execute(job); - } finally { - unlock(); - } + @Override + public void execute(AbstractJob job) { + if (tryLock()) { + try { + super.execute(job); + } finally { + unlock(); + } + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompProvider.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompProvider.java index 472a9a3..7945f09 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompProvider.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompProvider.java @@ -11,7 +11,7 @@ public class AbstractCompProvider { //临时缓存 private Map cacheData = new HashMap<>(); - protected T doGetData(String key, IDataProvider loader) { + protected T doGetData(String key, IDataProvider loader) { cacheData.computeIfAbsent(key, s -> loader.load()); if (!cacheData.containsKey(key)) { cacheData.put(key, loader.load()); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java index 4f1d5fe..a366de2 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractCompService.java @@ -2,10 +2,8 @@ package cc.smtweb.framework.core.mvc.service; import cc.smtweb.framework.core.annotation.SwBody; import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.db.impl.DefaultEntity; -import cc.smtweb.framework.core.exception.BizException; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.common.SwMap; +import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.session.UserSession; /** @@ -42,56 +40,56 @@ public abstract class AbstractCompService { //保存 public R save(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_SAVE, handler -> ((DefaultSaveHandler)handler).save()); + return pageHandler(params, us, TYPE_SAVE, handler -> ((DefaultSaveHandler) handler).save()); } //树,换爹 public R trcp(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_SAVE, handler -> ((DefaultSaveHandler)handler).changeParent()); + return pageHandler(params, us, TYPE_SAVE, handler -> ((DefaultSaveHandler) handler).changeParent()); } //读取 public R load(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LOAD, handler -> ((DefaultLoadHandler)handler).load()); + return pageHandler(params, us, TYPE_LOAD, handler -> ((DefaultLoadHandler) handler).load()); } //删除 public R del(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_DEL, handler -> ((AbstractDelHandler)handler).del()); + return pageHandler(params, us, TYPE_DEL, handler -> ((AbstractDelHandler) handler).del()); } //列表数据 public R list(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LIST, handler -> ((AbstractListHandler)handler).data()); + return pageHandler(params, us, TYPE_LIST, handler -> ((AbstractListHandler) handler).data()); } //列表总记录数及合计栏 public R listTotal(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_LIST, handler -> ((AbstractListHandler)handler).getTotal()); + return pageHandler(params, us, TYPE_LIST, handler -> ((AbstractListHandler) handler).getTotal()); } //combo数据 public R combo(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler)handler).data()); + return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler) handler).data()); } //combo总记录数及合计栏 public R comboTotal(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler)handler).getTotal()); + return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler) handler).getTotal()); } //combo数据过滤 public R comboFilter(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler)handler).filter()); + return pageHandler(params, us, TYPE_COMBO, handler -> ((DefaultComboHandler) handler).filter()); } //树数据 public R tree(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_TREE, handler -> ((AbstractTreeHandler)handler).data()); + return pageHandler(params, us, TYPE_TREE, handler -> ((AbstractTreeHandler) handler).data()); } //树过滤 public R treeFilter(@SwBody SwMap params, UserSession us) { - return pageHandler(params, us, TYPE_TREE, handler -> ((AbstractTreeHandler)handler).filter()); + return pageHandler(params, us, TYPE_TREE, handler -> ((AbstractTreeHandler) handler).filter()); } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractDelHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractDelHandler.java index aa99708..1f43e85 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractDelHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractDelHandler.java @@ -10,7 +10,7 @@ import lombok.extern.slf4j.Slf4j; * 保存 */ @Slf4j -public abstract class AbstractDelHandler extends AbstractHandler{ +public abstract class AbstractDelHandler extends AbstractHandler { protected long id; public R del() { @@ -38,6 +38,7 @@ public abstract class AbstractDelHandler extends AbstractHandler{ /** * 读取页面传回来的id + * * @return */ protected long readId() { @@ -45,7 +46,12 @@ public abstract class AbstractDelHandler extends AbstractHandler{ } protected abstract void checkValid(); + protected abstract void delDb(); - protected void saveSuccess() {} - protected void saveFailed() {} + + protected void saveSuccess() { + } + + protected void saveFailed() { + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java index df06082..9ee3f98 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractListHandler.java @@ -153,9 +153,9 @@ public abstract class AbstractListHandler extends AbstractHandler { else { for (String key : params.keySet()) { Object v = map.get(key); - String cv = v != null && StringUtils.isNotEmpty(v.toString()) ? v.toString() : ""; + String cv = v != null && StringUtils.isNotEmpty(v.toString()) ? v.toString(): ""; v = params.get(key); - String rv = v != null && StringUtils.isNotEmpty(v.toString()) ? v.toString() : ""; + String rv = v != null && StringUtils.isNotEmpty(v.toString()) ? v.toString(): ""; if (!cv.equals(rv)) { query = true; break; @@ -187,7 +187,7 @@ public abstract class AbstractListHandler extends AbstractHandler { * * @throws Exception */ - protected void buildParam() { + protected void buildParam() { } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractLoadHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractLoadHandler.java index 9fe0974..fd98aac 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractLoadHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractLoadHandler.java @@ -21,6 +21,7 @@ public abstract class AbstractLoadHandler extends AbstractHandler { /** * 读取页面传回来的id + * * @return */ protected long readId() { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractSaveHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractSaveHandler.java index e297ce4..81712ac 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractSaveHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractSaveHandler.java @@ -31,17 +31,17 @@ public abstract class AbstractSaveHandler extends AbstractHandler { checkValid(); DbEngine.getInstance().doTrans(new IDbWorker() { @Override - public void work(){ + public void work() { saveDb(); } @Override - public void doAfterDbCommit(){ + public void doAfterDbCommit() { saveSuccess(); } @Override - public void doAfterDbRollback(){ + public void doAfterDbRollback() { saveFailed(); } }); @@ -56,6 +56,7 @@ public abstract class AbstractSaveHandler extends AbstractHandler { protected long readId() { return params.readLong("id", 0L); } + protected abstract void setNewId(); //从页面读取数据 diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java index f7cafa1..4f3dbd3 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/AbstractTreeHandler.java @@ -19,26 +19,28 @@ public abstract class AbstractTreeHandler extends AbstractHandler { } //构建过滤数据 - public List buildFilter() { + public List buildFilter() { List rows = filterData(); return buildNodes(rows, true); } //下拉数据 - public R data() { + public R data() { return R.success(buildData()); } //构建 - public List buildData() { + public List buildData() { List rows = getChildren(params.readLong("parent_id")); return buildNodes(rows, params.readBool("lazy")); } //搜索 protected abstract List filterData(); + //获取指定节点的下级节点 protected abstract List getChildren(long id); + protected List getChildren(T bean) { return getChildren(getId(bean)); } @@ -67,7 +69,8 @@ public abstract class AbstractTreeHandler extends AbstractHandler { } //根据bean,构建treenode - protected void buildNode(SwMap node, T bean) {} + protected void buildNode(SwMap node, T bean) { + } protected abstract long getId(T bean); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultComboHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultComboHandler.java index 296a35d..581bfeb 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultComboHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultComboHandler.java @@ -2,14 +2,13 @@ package cc.smtweb.framework.core.mvc.service; import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwEnum; -import cc.smtweb.framework.core.exception.BizException; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.db.cache.ModelTableCache; import cc.smtweb.framework.core.db.impl.DefaultEntity; import cc.smtweb.framework.core.db.vo.ModelField; import cc.smtweb.framework.core.db.vo.ModelTable; +import cc.smtweb.framework.core.exception.BizException; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; @@ -65,7 +64,7 @@ public class DefaultComboHandler extends DefaultListHan if (fields.isEmpty()) return; text = text + "%";//combo不支持全模糊 - for (String field: fields) { + for (String field : fields) { sqlFilter.append(" or " + field + " like ?"); args.add(text); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultLoadHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultLoadHandler.java index d19e590..e1c8b4b 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultLoadHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultLoadHandler.java @@ -1,13 +1,9 @@ package cc.smtweb.framework.core.mvc.service; import cc.smtweb.framework.core.common.R; -import cc.smtweb.framework.core.common.SwEnum; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.db.EntityDao; -import cc.smtweb.framework.core.db.cache.ModelTableCache; import cc.smtweb.framework.core.db.impl.DefaultEntity; -import cc.smtweb.framework.core.db.vo.ModelField; -import cc.smtweb.framework.core.db.vo.ModelTable; /** * Created by Akmm at 2022/3/2 19:52 diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultProvider.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultProvider.java index 43cc73a..46d6d15 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultProvider.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultProvider.java @@ -1,10 +1,10 @@ package cc.smtweb.framework.core.mvc.service; -import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.db.EntityDao; import cc.smtweb.framework.core.db.EntityHelper; import cc.smtweb.framework.core.db.impl.DefaultEntity; +import cc.smtweb.framework.core.exception.BizException; /** * Created by Akmm at 2022/3/3 20:04 diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java index d9c0db4..61ac47c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/DefaultSaveHandler.java @@ -4,15 +4,15 @@ import cc.smtweb.framework.core.cache.AbstractCache; import cc.smtweb.framework.core.cache.CacheManager; import cc.smtweb.framework.core.common.R; import cc.smtweb.framework.core.common.SwEnum; -import cc.smtweb.framework.core.db.jdbc.IDbWorker; -import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.db.EntityDao; import cc.smtweb.framework.core.db.cache.ModelTableCache; import cc.smtweb.framework.core.db.impl.DefaultEntity; +import cc.smtweb.framework.core.db.jdbc.IDbWorker; import cc.smtweb.framework.core.db.vo.ModelField; import cc.smtweb.framework.core.db.vo.ModelIndex; import cc.smtweb.framework.core.db.vo.ModelTable; +import cc.smtweb.framework.core.exception.BizException; import org.apache.commons.lang3.StringUtils; import java.util.List; @@ -21,7 +21,7 @@ import java.util.List; * Created by Akmm at 2022/3/2 19:52 * 默认实体实现 */ -public class DefaultSaveHandler extends AbstractHandler{ +public class DefaultSaveHandler extends AbstractHandler { protected String tableName; protected T bean; @@ -35,7 +35,7 @@ public class DefaultSaveHandler extends AbstractHandler ModelTable table = ModelTableCache.getInstance().getByName(tableName); long id = params.readLong(table.getIdField()); boolean isNew = params.readBool(DefaultEntity.statusKey) || id <= 0L; - + final EntityDao dao = DbEngine.getInstance().findDao(tableName); if (isNew) { bean = dao.createBean(us.getUserId()); @@ -47,17 +47,17 @@ public class DefaultSaveHandler extends AbstractHandler checkValid(); DbEngine.getInstance().doTrans(new IDbWorker() { @Override - public void work(){ + public void work() { saveDb(); } @Override - public void doAfterDbCommit(){ + public void doAfterDbCommit() { saveSuccess(); } @Override - public void doAfterDbRollback(){ + public void doAfterDbRollback() { saveFailed(); } }); @@ -69,7 +69,7 @@ public class DefaultSaveHandler extends AbstractHandler bean.readFromMap(params); } - protected void checkValid() { + protected void checkValid() { ModelTable table = ModelTableCache.getInstance().getByName(tableName); for (ModelField field : table.getFields()) { if (field.isNotNull() && StringUtils.isEmpty(bean.getStr(field.getName()))) { @@ -88,7 +88,7 @@ public class DefaultSaveHandler extends AbstractHandler } } - protected void saveDb() { + protected void saveDb() { EntityDao dao = DbEngine.getInstance().findDao(tableName); if (bean.isNew()) { insertBean(dao); @@ -139,7 +139,7 @@ public class DefaultSaveHandler extends AbstractHandler } //树,改变父亲 - public R changeParent(){ + public R changeParent() { ModelTable table = ModelTableCache.getInstance().getByName(tableName); if (table.getType() != SwEnum.TableType.TYPE_TREE.value) throw new BizException("非树型表,不支持更改父节点"); @@ -166,7 +166,7 @@ public class DefaultSaveHandler extends AbstractHandler } @Override - public void doAfterDbCommit(){ + public void doAfterDbCommit() { saveSuccess(); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/IWorker.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/IWorker.java index 027a28c..72832e7 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/IWorker.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/IWorker.java @@ -7,5 +7,5 @@ import cc.smtweb.framework.core.common.R; * 所有handler的接口 */ public interface IWorker { - R doWork(T handler); + R doWork(T handler); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java index 36885a2..029b469 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/service/TreeHelper.java @@ -4,14 +4,13 @@ import cc.smtweb.framework.core.cache.AbstractCache; import cc.smtweb.framework.core.cache.CacheManager; import cc.smtweb.framework.core.common.SwConsts; import cc.smtweb.framework.core.common.SwEnum; -import cc.smtweb.framework.core.exception.BizException; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.db.EntityDao; import cc.smtweb.framework.core.db.cache.ModelTableCache; import cc.smtweb.framework.core.db.impl.DefaultEntity; -import cc.smtweb.framework.core.db.vo.ModelField; import cc.smtweb.framework.core.db.vo.ModelTable; +import cc.smtweb.framework.core.exception.BizException; +import cc.smtweb.framework.core.exception.SwException; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -22,10 +21,12 @@ import java.util.concurrent.ConcurrentHashMap; public class TreeHelper { private static Map> mapDef; private static Map mapInstance; + static { mapDef = new HashMap<>(); mapInstance = new ConcurrentHashMap<>(); } + private String tableName; private ModelTable table; @@ -95,7 +96,7 @@ public class TreeHelper { List list = set == null ? new ArrayList<>(): new ArrayList<>(set); if (comparator != null) - list.sort(comparator); + list.sort(comparator); return list; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/variable/ICalcVar.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/variable/ICalcVar.java index 4a85ec9..4c90a3f 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/variable/ICalcVar.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/variable/ICalcVar.java @@ -10,8 +10,9 @@ import cc.smtweb.framework.core.session.UserSession; public interface ICalcVar { /** * 计算并返回变量值 + * * @param params 参数 - * @param us 用户会话信息 + * @param us 用户会话信息 * @return */ Object calcVar(SwMap params, UserSession us); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/variable/SwVariableFactory.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/variable/SwVariableFactory.java index dfbb34e..216a062 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/variable/SwVariableFactory.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/mvc/variable/SwVariableFactory.java @@ -1,8 +1,7 @@ package cc.smtweb.framework.core.mvc.variable; -import cc.smtweb.framework.core.exception.BizException; -import cc.smtweb.framework.core.exception.SwException; import cc.smtweb.framework.core.common.SwMap; +import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.framework.core.util.DateUtil; @@ -15,6 +14,7 @@ import java.util.Map; */ public class SwVariableFactory { private static SwVariableFactory instance; + static { instance = new SwVariableFactory(); } @@ -25,6 +25,7 @@ public class SwVariableFactory { //记录变量信息 private Map map = new HashMap<>(); + private SwVariableFactory() { regVariable("SYS_DATE", "当前日期", "YYYYMMDD格式", (params, us) -> DateUtil.nowDateLong()); regVariable("CUR_USER_ID", "当前操作员id", "当前操作员主键", (params, us) -> us.getUserId()); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionManager.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionManager.java index b03e1c4..9e0d621 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionManager.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionManager.java @@ -11,63 +11,64 @@ import org.springframework.web.context.request.RequestContextHolder; import java.util.Random; public class SessionManager { - private final RedisManager redisManager; - private final IdGenerator idGenerator; + private final RedisManager redisManager; + private final IdGenerator idGenerator; - public SessionManager(RedisManager redisManager, IdGenerator idGenerator) { - this.redisManager = redisManager; - this.idGenerator = idGenerator; - } - - // 登录,产生session - public String login(UserSession userSession) { - if (userSession != null) { - String sid = RedisManager.PREFIX_SESSION + Long.toHexString(idGenerator.nextId()) + "_" + Integer.toHexString(new Random().nextInt()); + public SessionManager(RedisManager redisManager, IdGenerator idGenerator) { + this.redisManager = redisManager; + this.idGenerator = idGenerator; + } - redisManager.set(sid, userSession, RedisManager.SESSION_EXPIRE_SEC); + // 登录,产生session + public String login(UserSession userSession) { + if (userSession != null) { + String sid = RedisManager.PREFIX_SESSION + Long.toHexString(idGenerator.nextId()) + "_" + Integer.toHexString(new Random().nextInt()); - return sid; - } + redisManager.set(sid, userSession, RedisManager.SESSION_EXPIRE_SEC); - return null; - } + return sid; + } - public void logout() { - String sid = (String)RequestContextHolder.currentRequestAttributes().getAttribute(IEditor.USER_TOKEN, RequestAttributes.SCOPE_REQUEST); - if (StringUtils.isNoneBlank(sid)) { - redisManager.del(sid); + return null; } - } - // token延时 - public boolean flush(String token) { - if (token != null) { - // 更新Token redis TTL - return redisManager.expire(token, RedisManager.SESSION_EXPIRE_SEC); + public void logout() { + String sid = (String) RequestContextHolder.currentRequestAttributes().getAttribute(IEditor.USER_TOKEN, RequestAttributes.SCOPE_REQUEST); + if (StringUtils.isNoneBlank(sid)) { + redisManager.del(sid); + } } - return false; - } + // token延时 + public boolean flush(String token) { + if (token != null) { + // 更新Token redis TTL + return redisManager.expire(token, RedisManager.SESSION_EXPIRE_SEC); + } - /** - * 清除指定用户权限本地缓存 - * @param userId 用户ID - */ - public void removePermits(long userId) { - RedisBroadcastEvent event = new RedisBroadcastEvent(); - event.setAction(RedisBroadcastEvent.CODE_REMOVE); - event.setIdent("ReamlCache"); - event.setKey(userId + ""); - redisManager.publish(event); - } + return false; + } - /** - * 清除所有用户权限本地缓存 - */ - public void clearPermits() { - RedisBroadcastEvent event = new RedisBroadcastEvent(); - event.setAction(RedisBroadcastEvent.CODE_CLEAR); - event.setKey("ReamlCache"); - redisManager.publish(event); - } + /** + * 清除指定用户权限本地缓存 + * + * @param userId 用户ID + */ + public void removePermits(long userId) { + RedisBroadcastEvent event = new RedisBroadcastEvent(); + event.setAction(RedisBroadcastEvent.CODE_REMOVE); + event.setIdent("ReamlCache"); + event.setKey(userId + ""); + redisManager.publish(event); + } + + /** + * 清除所有用户权限本地缓存 + */ + public void clearPermits() { + RedisBroadcastEvent event = new RedisBroadcastEvent(); + event.setAction(RedisBroadcastEvent.CODE_CLEAR); + event.setKey("ReamlCache"); + redisManager.publish(event); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionUtil.java index 09e63a6..2237a24 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionUtil.java @@ -15,51 +15,51 @@ import javax.servlet.http.HttpServletRequest; * @since 1.0.0 */ public class SessionUtil { - private SessionUtil() { - } + private SessionUtil() { + } - public static Object getSession() { - return RequestContextHolder.currentRequestAttributes().getAttribute(IEditor.USER_SESSION, 0); - } + public static Object getSession() { + return RequestContextHolder.currentRequestAttributes().getAttribute(IEditor.USER_SESSION, 0); + } - public static String readToken(HttpServletRequest request) { - String token = request.getHeader("Auth-Token"); + public static String readToken(HttpServletRequest request) { + String token = request.getHeader("Auth-Token"); - if (token == null) { - token = request.getParameter("auth_token"); + if (token == null) { + token = request.getParameter("auth_token"); + } + return token; } - return token; - } - public static UserSession checkSession(HttpServletRequest request, RedisManager redisManager) { - String token = readToken(request); + public static UserSession checkSession(HttpServletRequest request, RedisManager redisManager) { + String token = readToken(request); - if (StringUtils.isBlank(token)) { - throw new UnauthenticatedException("not find Auth-Token in header"); - } + if (StringUtils.isBlank(token)) { + throw new UnauthenticatedException("not find Auth-Token in header"); + } - UserSession us = redisManager.get(token, UserSession.class); - if (us == null) { - throw new UnauthenticatedException("not find UserSession by token: " + token); + UserSession us = redisManager.get(token, UserSession.class); + if (us == null) { + throw new UnauthenticatedException("not find UserSession by token: " + token); + } + + return us; } - return us; - } + public static UserSession checkSession(String accessToken, RedisManager redisManager) { + if (StringUtils.isBlank(accessToken)) { + throw new UnauthenticatedException("not find Auth-Token in header"); + } - public static UserSession checkSession(String accessToken, RedisManager redisManager) { - if (StringUtils.isBlank(accessToken)) { - throw new UnauthenticatedException("not find Auth-Token in header"); - } + UserSession us = redisManager.get(accessToken, UserSession.class); + if (us == null) { + throw new UnauthenticatedException("not find UserSession by token: " + accessToken); + } - UserSession us = redisManager.get(accessToken, UserSession.class); - if (us == null) { - throw new UnauthenticatedException("not find UserSession by token: " + accessToken); + return us; } - return us; - } - // private static Session getShiroSession() { // Session session = SecurityUtils.getSubject().getSession(); // if (session == null) { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/UserSessionArgumentResolver.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/UserSessionArgumentResolver.java index fc9e21c..a2fa5d3 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/UserSessionArgumentResolver.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/UserSessionArgumentResolver.java @@ -10,6 +10,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; /** * spring 参数拦截器,提供UserSession在@Service的函数参数中@Param使用 + * * @author kevin */ public class UserSessionArgumentResolver implements HandlerMethodArgumentResolver { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/systask/ISysTask.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/systask/ISysTask.java index cb5d8ec..fb96bcc 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/systask/ISysTask.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/systask/ISysTask.java @@ -4,5 +4,5 @@ package cc.smtweb.framework.core.systask; * 任务接口 */ public interface ISysTask { - int run(); + int run(); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/systask/SysTaskManager.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/systask/SysTaskManager.java index 2a5a5c1..f32ff36 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/systask/SysTaskManager.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/systask/SysTaskManager.java @@ -10,21 +10,21 @@ import java.util.List; @Service public class SysTaskManager { - @Autowired - private ApplicationContext applicationContext; + @Autowired + private ApplicationContext applicationContext; - private List tasks = new ArrayList<>(); + private List tasks = new ArrayList<>(); - public void add(ISysTask task) { - tasks.add(task); - } + public void add(ISysTask task) { + tasks.add(task); + } - @EventListener - public void onTaskStartEvent(TaskStartEvent event) { - runAll(); - } + @EventListener + public void onTaskStartEvent(TaskStartEvent event) { + runAll(); + } - // 每隔60秒定时执行 + // 每隔60秒定时执行 // @Scheduled(fixedRate = 60000) // public void fixedRateJob() { // System.out.println("fixedRate 每隔60秒" + new java.util.Date()); @@ -32,9 +32,9 @@ public class SysTaskManager { // runAll(); // } - private void runAll() { - for (ISysTask task : tasks) { - task.run(); + private void runAll() { + for (ISysTask task : tasks) { + task.run(); + } } - } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/CommUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/CommUtil.java index c4bb2cd..3e0cc71 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/CommUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/CommUtil.java @@ -21,6 +21,7 @@ import java.util.Set; public class CommUtil { /** * 找指定类的泛型类 + * * @param cls * @param * @return @@ -38,6 +39,7 @@ public class CommUtil { /** * 序列化对象 + * * @param obj * @param * @return @@ -48,6 +50,7 @@ public class CommUtil { /** * 反序列化 + * * @param data * @param clazz * @param @@ -72,6 +75,7 @@ public class CommUtil { /** * 从DefaultEntity实体转成自己的对象类 + * * @param bean * @param clazz * @param diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/DateUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/DateUtil.java index 46811f3..9dcb23c 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/DateUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/DateUtil.java @@ -15,9 +15,9 @@ import java.util.TimeZone; * 日期工具类 */ public class DateUtil { -// private static ThreadLocal stdTimeFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("HH:mm:ss")); - private static ThreadLocal stdDateFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); - private static ThreadLocal stdDatetimeFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); + // private static ThreadLocal stdTimeFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("HH:mm:ss")); + private static ThreadLocal stdDateFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); + private static ThreadLocal stdDatetimeFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); // private static ThreadLocal stdLongDatetimeFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")); private static ThreadLocal simpleWeekFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat("EEEE")); @@ -37,15 +37,18 @@ public class DateUtil { private static TimeZone mTimeZone = TimeZone.getTimeZone("Asia/Shanghai"); - private DateUtil(){} + private DateUtil() { + } + /** * 取得系统今天的时间串 * * @return current datetime, pattern: "yyyy-MM-dd HH:mm:ss". */ public static String nowStdDateTimeString() { - return stdDatetimeFormat.get().format(nowTimestamp()); + return stdDatetimeFormat.get().format(nowTimestamp()); } + /** * Return a Timestamp for right now * @@ -54,6 +57,7 @@ public class DateUtil { public static Timestamp nowTimestamp() { return new Timestamp(System.currentTimeMillis()); } + /** * 得到如下格式字符串 "YYYY-MM-DD" * @@ -62,8 +66,9 @@ public class DateUtil { */ public static String toStdDateString(Date d) { if (d == null) return ""; - return stdDateFormat.get().format(d); + return stdDateFormat.get().format(d); } + /** * 比较两个日期是否相等 */ @@ -77,6 +82,7 @@ public class DateUtil { String strb = toStdDateString(b); return stra.compareTo(strb); } + /** * 获取当前时间数字串,例如20100909121359 标识2010年09月09日 12时13分59秒 * @@ -85,14 +91,16 @@ public class DateUtil { public static Long nowDateTimeNumber() { return Long.valueOf(nowDateTimeString()); } + /** * 取得系统今天的时间串 * * @return current datetime, pattern:"yyyyMMddHHmmss" */ public static String nowDateTimeString() { - return simpleDatetimeFormat.get().format(nowTimestamp()); + return simpleDatetimeFormat.get().format(nowTimestamp()); } + /** * 将yyyyMMdd变为yyyy-mm-dd * @@ -104,6 +112,7 @@ public class DateUtil { if (s.contains("-")) return s; return toStdDateString(s, "-", false); } + /** * 将yyyyMMdd日期串用分隔符进行分割 * @@ -116,13 +125,14 @@ public class DateUtil { if (StringUtil.isEmpty(s)) return ""; try { if (s == null || s.length() < 8) { - return returnEmptyIfErrDate ? "" : s; + return returnEmptyIfErrDate ? "": s; } return s.substring(0, 4) + split + s.substring(4, 6) + split + s.substring(6, 8); } catch (Exception e) { return ""; } } + /** * 得到如下字符串 "YYYY-dd * @@ -130,9 +140,10 @@ public class DateUtil { * @return 日期时间串,如:2011-03 */ public static String toStdYd(String d) { - if (d == null || d.length() <6) return ""; - return d.substring(0, 4)+"-"+d.substring(4,6); + if (d == null || d.length() < 6) return ""; + return d.substring(0, 4) + "-" + d.substring(4, 6); } + /** * @param datetime 时间戳,例如20110304131101; * @return 毫秒数 @@ -140,9 +151,9 @@ public class DateUtil { public static long getTimeInMillis(String datetime) { if (datetime == null) return 0L; try { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(stdDatetimeFormat.get().parse(datetime)); - return calendar.getTimeInMillis(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(stdDatetimeFormat.get().parse(datetime)); + return calendar.getTimeInMillis(); } catch (Exception e) { return 0L; } @@ -155,6 +166,7 @@ public class DateUtil { int i = compareDate(a, new java.sql.Date(System.currentTimeMillis())); return i < 0; } + /** * a是否小于b */ @@ -162,6 +174,7 @@ public class DateUtil { int i = compareDate(a, b); return i < 0; } + /** * 检查beging + days 是否在end前[包括end];(如:招行开始日期与结束日期之差只能在100以内) * @@ -175,6 +188,7 @@ public class DateUtil { Date addDate = gc.getTime(); return (end.compareTo(addDate) <= 0); } + /** * 得到如下字符串 "YYYY-MM-DD HH:MM:SS" * @@ -183,8 +197,9 @@ public class DateUtil { */ public static String toStdDateTimeString(Date d) { if (d == null) return ""; - return stdDatetimeFormat.get().format(d); + return stdDatetimeFormat.get().format(d); } + /** * 得到如下字符串 "YYYY-MM-DD HH:MM:SS" * @@ -194,6 +209,7 @@ public class DateUtil { public static String toStdDateTimeString(long d) { return toStdDateTimeString(String.valueOf(d)); } + /** * 得到如下字符串 "YYYY-MM-DD HH:MM:SS" * @@ -204,6 +220,7 @@ public class DateUtil { if (d == null || d.length() != 14) return ""; return toStdDateString(d.substring(0, 8)) + " " + d.substring(8, 10) + ":" + d.substring(10, 12) + ":" + d.substring(12); } + /** * 得到如下字符串 "MM-DD HH:MM" * @@ -214,6 +231,7 @@ public class DateUtil { if (d == null || d.length() != 14) return ""; return toStdDateString(d.substring(0, 8)).substring(5) + " " + d.substring(8, 10) + ":" + d.substring(10, 12); } + /** * 得到如下字符串 "YYYY-MM-DD HH:MM" * @@ -224,77 +242,86 @@ public class DateUtil { if (d == null || d.length() != 14) return ""; return toStdDateString(d.substring(0, 8)) + " " + d.substring(8, 10) + ":" + d.substring(10, 12); } + /** * 获取星期几 - * */ public static String getWeekOfDay() { - return simpleWeekFormat.get().format(nowTimestamp()); - } - /** - * 获取当前时间 - * @return - */ - public static Date now() { - return new Date(System.currentTimeMillis()); - } - - /** - * 按yyyy-MM-dd格式化 - * @param date - * @return - */ - public static String formatDate(Date date) { - return stdDateFormat.get().format(date); - } - - /** - * 按yyyy-MM-dd HH:mm:ss格式化 - * @param date - * @return - */ - public static String formatDateTime(Date date) { - return stdDatetimeFormat.get().format(date); - } - - /** - * 格式化 - * @param date YYYYMMDD格式 - * @return - */ - public static String formatDate(long date) { - return formatDate(String.valueOf(date)); - } - public static String formatDate(String d) { - if(d.length() < 8) return d; //就是2011-03-04 13:11:01这种形式 - return d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8); - } - - public static String formatDateTime(long date) { - return formatDateTime(String.valueOf(date)); - } - public static String formatDateTime(String d) { - if(d.length() < 8) return d; //就是2011-03-04 13:11:01这种形式 - if(d.length() < 14) return d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8); - return d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8) + " " + d.substring(8, 10) + ":" + d.substring(10, 12) + ":" + d.substring(12); - } - - public static String formatTime(long date) { - return formatTime(String.valueOf(date)); - } - public static String formatTime(String d) { - if(d.length() < 6) return d; //就是13:11:01这种形式 - return d.substring(0, 2) + ":" + d.substring(2, 4) + ":" + d.substring(4); - } - - /** - * 按yyyyMMdd格式化 - * @param date - * @return - */ - public static String formatSimpleDate(Date date) { - return simpleDateFormat.get().format(date); - } + return simpleWeekFormat.get().format(nowTimestamp()); + } + + /** + * 获取当前时间 + * + * @return + */ + public static Date now() { + return new Date(System.currentTimeMillis()); + } + + /** + * 按yyyy-MM-dd格式化 + * + * @param date + * @return + */ + public static String formatDate(Date date) { + return stdDateFormat.get().format(date); + } + + /** + * 按yyyy-MM-dd HH:mm:ss格式化 + * + * @param date + * @return + */ + public static String formatDateTime(Date date) { + return stdDatetimeFormat.get().format(date); + } + + /** + * 格式化 + * + * @param date YYYYMMDD格式 + * @return + */ + public static String formatDate(long date) { + return formatDate(String.valueOf(date)); + } + + public static String formatDate(String d) { + if (d.length() < 8) return d; //就是2011-03-04 13:11:01这种形式 + return d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8); + } + + public static String formatDateTime(long date) { + return formatDateTime(String.valueOf(date)); + } + + public static String formatDateTime(String d) { + if (d.length() < 8) return d; //就是2011-03-04 13:11:01这种形式 + if (d.length() < 14) return d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8); + return d.substring(0, 4) + "-" + d.substring(4, 6) + "-" + d.substring(6, 8) + " " + d.substring(8, 10) + ":" + d.substring(10, 12) + ":" + d.substring(12); + } + + public static String formatTime(long date) { + return formatTime(String.valueOf(date)); + } + + public static String formatTime(String d) { + if (d.length() < 6) return d; //就是13:11:01这种形式 + return d.substring(0, 2) + ":" + d.substring(2, 4) + ":" + d.substring(4); + } + + /** + * 按yyyyMMdd格式化 + * + * @param date + * @return + */ + public static String formatSimpleDate(Date date) { + return simpleDateFormat.get().format(date); + } /** * 按yyyyMMddHHmmss格式化 @@ -573,9 +600,9 @@ public class DateUtil { } - public static Long getMonthLastDayLong(String ym) { - return Long.parseLong(getMonthLastDay(ym).replaceAll("-","")); - } + public static Long getMonthLastDayLong(String ym) { + return Long.parseLong(getMonthLastDay(ym).replaceAll("-", "")); + } /** @@ -653,6 +680,7 @@ public class DateUtil { java.sql.Date ret = new java.sql.Date(dy.getTimeInMillis()); return ret.toString(); } + /** * 取与指定日期间隔年的日期 * @@ -758,6 +786,7 @@ public class DateUtil { return false; } } + /** * 将日期变为"yyyyMMdd" * @@ -765,9 +794,10 @@ public class DateUtil { * @return 字符串,如果传入参数为null,则返回当前日期; */ public static String toDateString(Date date) { - if (date == null) date = new java.sql.Date(System.currentTimeMillis()); - return simpleDateFormat.get().format(date); + if (date == null) date = new java.sql.Date(System.currentTimeMillis()); + return simpleDateFormat.get().format(date); } + /** * 得到如下字符串 "HHmmss" * @@ -775,11 +805,12 @@ public class DateUtil { * @return 时间串 */ public static String toTimeString(Date date) { - if (date == null) new java.sql.Date(System.currentTimeMillis()); + if (date == null) new java.sql.Date(System.currentTimeMillis()); synchronized (simpleTimeFormat) { return simpleTimeFormat.get().format(date); } } + /** * 得到长日期时间字符[yyyyMMddHHmmss] * @@ -787,9 +818,10 @@ public class DateUtil { * @return 日期时间串 */ public static String toDateTimeString(Date date) { - if (date == null) date = new java.sql.Date(System.currentTimeMillis()); - return simpleDatetimeFormat.get().format(date); + if (date == null) date = new java.sql.Date(System.currentTimeMillis()); + return simpleDatetimeFormat.get().format(date); } + public static java.sql.Date toDate(Timestamp datetime) { if (datetime == null) return null; return new java.sql.Date(datetime.getTime()); @@ -803,6 +835,7 @@ public class DateUtil { } return month; } + /** * 将字符串转换成Java.sql.Date,不能转换,这返回null * @@ -832,6 +865,7 @@ public class DateUtil { public static String toDateTimeString(Timestamp date) { return toDateTimeString(toDate(date)); } + /** * 得到长日期时间字符[yyyyMMddHHmmss] * @@ -853,7 +887,7 @@ public class DateUtil { * @return 日期时间串,长 */ public static String toLongDateTimeString(Date date) { - if (date == null) date = new java.sql.Date(System.currentTimeMillis()); + if (date == null) date = new java.sql.Date(System.currentTimeMillis()); synchronized (simpleLongDatetimeFormat) { return simpleLongDatetimeFormat.get().format(date); } @@ -872,6 +906,7 @@ public class DateUtil { // return null; // } // } + /** * 用中方格式化年月日 * @@ -882,6 +917,7 @@ public class DateUtil { return String.format("%s年%s月", yearMonth.substring(0, 4), yearMonth.substring(4)); return ""; } + /** * 用中方格式化年月日 * @@ -900,6 +936,7 @@ public class DateUtil { public static String fmtZHCNYearMonthDay(String stdYearMonthDay) { return String.format("%s年%s月%s日", stdYearMonthDay.substring(0, 4), stdYearMonthDay.substring(5, 7), stdYearMonthDay.substring(8)); } + public synchronized static Date getSeasonBegin(Calendar now) { int curYear = now.get(Calendar.YEAR); int curMonth = now.get(Calendar.MONTH); @@ -916,12 +953,14 @@ public class DateUtil { calendar.set(Calendar.AM_PM, Calendar.AM); return new Timestamp(calendar.getTime().getTime()); } + //季度开始 public synchronized static Date getSeasonBegin() { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); return getSeasonBegin(calendar); } + public synchronized static java.sql.Date getAfterDate(Date dt, int days) { if (dt == null) return null; GregorianCalendar gc = new GregorianCalendar(); @@ -954,8 +993,9 @@ public class DateUtil { * @return 今日日期字符串 yyyyMMdd; */ public static String nowDateString() { - return simpleDateFormat.get().format(nowTimestamp()); + return simpleDateFormat.get().format(nowTimestamp()); } + //获取年度结束年月,YYYYMM格式 public static String getYearEndYm() { return nowYear() + "12"; @@ -968,6 +1008,7 @@ public class DateUtil { return nowYear() + "12"; } } + /** * 得到本季度的第一天 * @@ -984,6 +1025,7 @@ public class DateUtil { public static String getYearLastDay() { return nowYear() + "-12-31"; } + /** * 取得当月最后一天YYYY-MM-DD * @@ -1001,6 +1043,7 @@ public class DateUtil { public static String getMonthEnd(Date d) { return getAfterDays(getAfterMonth(getMonthStart(d), 1), -1); } + /** * 返回当前标准年月 * @@ -1009,6 +1052,7 @@ public class DateUtil { public static String nowStdYearMonth() { return nowStdDateString().substring(0, 7); } + /** * 取得当月第一天日期串YYYY-MM-DD * @@ -1017,6 +1061,7 @@ public class DateUtil { public static String getMonthStart() { return nowStdYearMonth() + "-01"; } + /** * 取得指定日期所在月第一天日期串YYYY-MM-DD * @@ -1045,6 +1090,7 @@ public class DateUtil { String s = toStdDateString(getNextSeasonBegin()); return getAfterDays(s, -1); } + //下个季度开始 public synchronized static Date getNextSeasonBegin() { Calendar calendar = Calendar.getInstance(); @@ -1073,19 +1119,23 @@ public class DateUtil { public static String getSeasonBeginYm() { return getDateYm(getSeasonBegin()); } + //获取年月,YYYYMM格式 public static String getNowYm() { return getDateYm(nowTimestamp()); } + public static String getNextYear(String year, int add) { if (StringUtil.isEmpty(year)) return year; int curYear = Integer.parseInt(year) - 1; return curYear + ""; } + //获取上一月,YYYYMM格式 public static String getPrevYear(String year) { return getNextYear(year, -1); } + //获取上一月,YYYYMM格式 public static String getPrevYm(String period_id) { return getNextYm(period_id, -1); @@ -1096,6 +1146,7 @@ public class DateUtil { public static String getNextYm(String period_id) { return getNextYm(period_id, 1); } + //获取年月,YYYYMM格式 public static String getPrevYm() { return getPrevYm(getNowYm()); @@ -1110,6 +1161,7 @@ public class DateUtil { public static String getNextYm() { return getNextYm(getNowYm()); } + public static String getNextYm(String period_id, int add) { if (StringUtil.isEmpty(period_id)) return period_id; int curYear = Integer.parseInt(period_id.substring(0, 4)); @@ -1127,6 +1179,7 @@ public class DateUtil { } return curYear + StringUtil.getRight("00" + curMonth, 2); } + /** * 得到当前日期所在周次的星期一 * @@ -1206,6 +1259,7 @@ public class DateUtil { return ymPeriod; } } + public static String getHalfEndYm() { return getHalfEndYm(DateUtil.getNowYm()); } @@ -1224,6 +1278,7 @@ public class DateUtil { } return dt.substring(0, 6); } + public static void main(String[] args) { System.out.println(getTimesmorning()); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/EmojiFilter.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/EmojiFilter.java index 51e465a..ca88df5 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/EmojiFilter.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/EmojiFilter.java @@ -9,11 +9,12 @@ public class EmojiFilter { /** * 过滤emoji 或者 其他非文字类型的字符 + * * @param source 需要过滤的字符串 * @return */ public static String filterEmoji(String source) { - if(StringUtil.isEmpty(source)){ + if (StringUtil.isEmpty(source)) { return ""; } if (!containsEmoji(source)) { @@ -46,6 +47,7 @@ public class EmojiFilter { /** * 检测是否有emoji字符 + * * @param source 需要判断的字符串 * @return 一旦含有就抛出 */ @@ -62,6 +64,7 @@ public class EmojiFilter { /** * 非emoji表情字符判断 + * * @param codePoint * @return */ diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/HttpUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/HttpUtil.java index 0e47993..e9e7759 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/HttpUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/HttpUtil.java @@ -144,10 +144,10 @@ public class HttpUtil { entity.setContentType("application/json"); String json_resp = post(url, null, null, entity, charset); if (encode && !json_resp.startsWith("{")) {//加密传输时,解密 - json_resp = new String(Base64.decodeBase64(json_resp),charset); + json_resp = new String(Base64.decodeBase64(json_resp), charset); } if (StringUtils.isEmpty(json_resp) || !json_resp.startsWith("{")) return null; - return (SwMap)JsonUtil.parseMap(json_resp); + return (SwMap) JsonUtil.parseMap(json_resp); } /** @@ -166,14 +166,14 @@ public class HttpUtil { public static SwMap post(String url, Map paras, boolean encode, String charset) throws Exception { String json_resp = post(url, null, paras, null, charset); if (encode) { - json_resp = new String(Base64.decodeBase64(json_resp),charset); + json_resp = new String(Base64.decodeBase64(json_resp), charset); } if (StringUtils.isEmpty(json_resp) || !json_resp.startsWith("{")) return null; - return (SwMap)JsonUtil.parseMap(json_resp); + return (SwMap) JsonUtil.parseMap(json_resp); } - public static SwMap post(String url,Map header, Map paras) throws Exception { + public static SwMap post(String url, Map header, Map paras) throws Exception { String json_resp = post(url, header, paras, null); if (StringUtils.isEmpty(json_resp) || !json_resp.startsWith("{")) return null; return (SwMap) JsonUtil.parseMap(json_resp); @@ -192,9 +192,11 @@ public class HttpUtil { public static String post(String url, Map header, Map param, HttpEntity entity) throws Exception { return post(url, header, param, entity, null); } + public static String post(String url, Map header, Map param, HttpEntity entity, String charset) throws Exception { - return postEx(url,header,param,entity,charset,null); + return postEx(url, header, param, entity, charset, null); } + public static String postEx(String url, Map header, Map param, HttpEntity entity, String charset, Consumer headerWorker) throws Exception { if (StringUtils.isEmpty(charset)) charset = "UTF-8"; String result = ""; @@ -204,13 +206,13 @@ public class HttpUtil { httpClient = getHttpClient(); HttpPost httpPost = getHttpPost(url); // 设置头信息 - if (header!=null && header.size()>0) { + if (header != null && header.size() > 0) { for (Map.Entry entry : header.entrySet()) { httpPost.addHeader(entry.getKey(), entry.getValue()); } } // 设置请求参数 - if (param!=null && param.size()>0) { + if (param != null && param.size() > 0) { List formparams = new ArrayList<>(); for (Map.Entry entry : param.entrySet()) { //给参数赋值 @@ -226,7 +228,7 @@ public class HttpUtil { httpResponse = httpClient.execute(httpPost); int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { - if(headerWorker!=null){ + if (headerWorker != null) { headerWorker.accept(httpResponse.getAllHeaders()); } HttpEntity resEntity = httpResponse.getEntity(); @@ -236,7 +238,7 @@ public class HttpUtil { result = readHttpResponse(httpResponse); } } catch (Exception e) { - log.error("POST_ERROR:",e); + log.error("POST_ERROR:", e); } finally { if (httpClient != null) { httpClient.close(); @@ -268,7 +270,7 @@ public class HttpUtil { HttpGet httpGet = new HttpGet(url); httpGet.setConfig(requestConfig); // 设置头信息 - if (header!=null && header.size()>0) { + if (header != null && header.size() > 0) { for (Map.Entry entry : header.entrySet()) { httpGet.addHeader(entry.getKey(), entry.getValue()); } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/IpAddrUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/IpAddrUtil.java index 9ba2642..f3484fc 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/IpAddrUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/IpAddrUtil.java @@ -63,7 +63,7 @@ public class IpAddrUtil { public static long getLongIp(HttpServletRequest request) { try { String ipAddr = getIpAddr(request); - return StringUtils.isBlank(ipAddr) ? 0L : ip2Long(ipAddr); + return StringUtils.isBlank(ipAddr) ? 0L: ip2Long(ipAddr); } catch (Exception var2) { return 0L; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/JsonUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/JsonUtil.java index 74c5d6f..f4cf0dc 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/JsonUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/JsonUtil.java @@ -4,9 +4,7 @@ import cc.smtweb.framework.core.common.SwMap; import cc.smtweb.framework.core.exception.JsonParseException; import cc.smtweb.framework.core.util.jackson.*; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; @@ -116,11 +114,12 @@ public class JsonUtil { /** * 解析指定json节点 - * @param str 完整json串 + * + * @param str 完整json串 * @param nodePath 待解析节点路径,如a.b.c - * @param clazz - * @return + * @param clazz * @param + * @return */ public static T parse(String str, String nodePath, Class clazz) { try { @@ -129,7 +128,7 @@ public class JsonUtil { } JsonNode node = OBJECT_MAPPER.readTree(str); String[] nodes = nodePath.split("\\."); - for (String s: nodes) { + for (String s : nodes) { node = node.get(s); if (node == null) return null; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/PersonUIDUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/PersonUIDUtil.java index 52bc69c..687cbb3 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/PersonUIDUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/PersonUIDUtil.java @@ -158,7 +158,7 @@ public final class PersonUIDUtil { genderCode = uid.charAt(OLD_CARD_NUMBER_LENGTH - 1);*/ else return -1;//throw new IllegalArgumentException("非法的居民身份证号[" + uid + "]!"); - return (genderCode - '0' & 0x1) == 0x01 ? 1 : 0; + return (genderCode - '0' & 0x1) == 0x01 ? 1: 0; } /** @@ -349,27 +349,28 @@ public final class PersonUIDUtil { /** * 显示uid的时候保密,用一些**符号 + * * @param person_uid * @return */ - public static String secretPersonUID(String person_uid){ - return secretPersonUID(person_uid,8); + public static String secretPersonUID(String person_uid) { + return secretPersonUID(person_uid, 8); } - public static String secretPersonUID(String person_uid,int secretLength){ - if(person_uid.length()>14){ - String head = person_uid.substring(0,6); - String tail = person_uid.substring(14,person_uid.length()); + public static String secretPersonUID(String person_uid, int secretLength) { + if (person_uid.length() > 14) { + String head = person_uid.substring(0, 6); + String tail = person_uid.substring(14, person_uid.length()); StringBuilder sb = new StringBuilder(); sb.append(head); - int i=0; - while (i T getBean(String name) { - return (T)applicationContext.getBean(name); + return (T) applicationContext.getBean(name); } public static T getBean(Class clazz) { diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/SqlUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/SqlUtil.java index 0d45675..fe54704 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/SqlUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/SqlUtil.java @@ -17,6 +17,7 @@ import java.util.List; public abstract class SqlUtil { /** * 将sql中的表名替换成schema.table的格式 + * * @param sql * @return */ @@ -92,7 +93,7 @@ public abstract class SqlUtil { public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { if (StringUtil.isNotEmpty(condition_value)) { //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); + condition_value = condition_value.replaceAll("_", "\\\\_"); if (!where_is_exist) { sql.append(" WHERE "); where_is_exist = true; @@ -108,7 +109,7 @@ public abstract class SqlUtil { public static boolean addSql_LIKE_Pre(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { if (StringUtil.isNotEmpty(condition_value)) { //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); + condition_value = condition_value.replaceAll("_", "\\\\_"); if (!where_is_exist) { sql.append(" WHERE "); where_is_exist = true; @@ -130,7 +131,7 @@ public abstract class SqlUtil { if (db_field_name == null || db_field_name.length == 0) return where_is_exist; if (StringUtil.isNotEmpty(condition_value)) { //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); + condition_value = condition_value.replaceAll("_", "\\\\_"); if (!where_is_exist) { sql.append(" WHERE "); where_is_exist = true; @@ -163,7 +164,7 @@ public abstract class SqlUtil { public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { if (StringUtil.isNotEmpty(condition_value)) { //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); + condition_value = condition_value.replaceAll("_", "\\\\_"); if (!where_is_exist) { sql.append(" WHERE "); where_is_exist = true; @@ -180,7 +181,7 @@ public abstract class SqlUtil { public static boolean addSql_LIKE_Expr(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { if (StringUtil.isNotEmpty(condition_value)) { //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); + condition_value = condition_value.replaceAll("_", "\\\\_"); if (!where_is_exist) { sql.append(" WHERE "); where_is_exist = true; @@ -206,7 +207,7 @@ public abstract class SqlUtil { public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List args, String db_field_name, String condition_value) { if (StringUtil.isNotEmpty(condition_value)) { //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); + condition_value = condition_value.replaceAll("_", "\\\\_"); if (!where_is_exist) { sql.append(" WHERE "); where_is_exist = true; @@ -222,7 +223,7 @@ public abstract class SqlUtil { public static boolean addSql_LIKE(boolean where_is_exist, StringBuilder sql, List args, String[] db_field_names, String condition_value) { if (StringUtil.isNotEmpty(condition_value)) { //mysq _ 是一个占位符需要加\进行处理 - condition_value = condition_value.replaceAll("_", "\\\\_"); + condition_value = condition_value.replaceAll("_", "\\\\_"); if (!where_is_exist) { sql.append(" WHERE "); where_is_exist = true; diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/StringUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/StringUtil.java index eac0ee3..1e9ee00 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/StringUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/StringUtil.java @@ -490,7 +490,7 @@ public class StringUtil { * @return str */ public static String checkNull(String strValue, String defaultValue) { - return strValue == null ? defaultValue : strValue; + return strValue == null ? defaultValue: strValue; } /** diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/VariableUtil.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/VariableUtil.java index a425403..da74b36 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/VariableUtil.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/VariableUtil.java @@ -4,62 +4,63 @@ package cc.smtweb.framework.core.util; * 变量命名规则工具类 */ public class VariableUtil { - private VariableUtil() {} + private VariableUtil() { + } - /*** - * 下划线命名转为驼峰命名 - * - * @param para - * 下划线命名的字符串 - */ - public static String underlineToHump(String para){ - StringBuilder result = new StringBuilder(); - String[] a = para.split("_"); - for(String s:a){ - if(result.length()==0){ - result.append(s.toLowerCase()); - }else{ - result.append(s.substring(0, 1).toUpperCase()); - result.append(s.substring(1).toLowerCase()); - } + /*** + * 下划线命名转为驼峰命名 + * + * @param para + * 下划线命名的字符串 + */ + public static String underlineToHump(String para) { + StringBuilder result = new StringBuilder(); + String[] a = para.split("_"); + for (String s : a) { + if (result.length() == 0) { + result.append(s.toLowerCase()); + } else { + result.append(s.substring(0, 1).toUpperCase()); + result.append(s.substring(1).toLowerCase()); + } + } + return result.toString(); } - return result.toString(); - } - /*** - * 下划线命名转为大写驼峰命名 - * 大驼峰式命名法(upper camel case) - * - * @param para - * 下划线命名的字符串 - */ - public static String underlineToUpperHump(String para){ - StringBuilder result=new StringBuilder(); - String[] a = para.split("_"); - for(String s : a){ - result.append(s.substring(0, 1).toUpperCase()); - result.append(s.substring(1).toLowerCase()); + /*** + * 下划线命名转为大写驼峰命名 + * 大驼峰式命名法(upper camel case) + * + * @param para + * 下划线命名的字符串 + */ + public static String underlineToUpperHump(String para) { + StringBuilder result = new StringBuilder(); + String[] a = para.split("_"); + for (String s : a) { + result.append(s.substring(0, 1).toUpperCase()); + result.append(s.substring(1).toLowerCase()); + } + return result.toString(); } - return result.toString(); - } - /*** - * 驼峰命名转为下划线命名 - * - * @param para - * 驼峰命名的字符串 - */ - public static String humpToUnderline(String para){ - StringBuilder sb = new StringBuilder(para); - //偏移量,第i个下划线的位置是 当前的位置+ 偏移量(i-1),第一个下划线偏移量是0 - int temp = 0; - for(int i = 0; i map) { - for (String s: map.keySet()) { + for (String s : map.keySet()) { Element e = pnode.addElement(s); final Object o = map.get(s); - e.setText(o != null ? o.toString() : ""); + e.setText(o != null ? o.toString(): ""); } } //添加节点 - public static void addNode(Element pnode, String name, Object value){ + public static void addNode(Element pnode, String name, Object value) { Element e = pnode.addElement(name); - e.setText(value != null ? value.toString() : ""); + e.setText(value != null ? value.toString(): ""); } - + public static void main(String[] args) { try { Document doc = readXmlDocument("f:\\temp\\plugin-developer.xml"); diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/BaseBeanSerializer.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/BaseBeanSerializer.java index b0e6b4e..82e7b4b 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/BaseBeanSerializer.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/BaseBeanSerializer.java @@ -10,14 +10,14 @@ import java.io.IOException; public class BaseBeanSerializer extends JsonSerializer { - @Override - public void serialize(BaseBean value, JsonGenerator gen, - SerializerProvider serializers) throws IOException, + @Override + public void serialize(BaseBean value, JsonGenerator gen, + SerializerProvider serializers) throws IOException, JsonProcessingException { - if (value == null) { - gen.writeNull(); - } else { - gen.writeObject(value.getData()); - } - } + if (value == null) { + gen.writeNull(); + } else { + gen.writeObject(value.getData()); + } + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/DateSerializer.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/DateSerializer.java index c0e3961..e8ade82 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/DateSerializer.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/DateSerializer.java @@ -10,21 +10,21 @@ import java.util.Date; public class DateSerializer extends JsonSerializer { - @Override - public void serialize(Date value, JsonGenerator gen, - SerializerProvider serializers) throws IOException, + @Override + public void serialize(Date value, JsonGenerator gen, + SerializerProvider serializers) throws IOException, JsonProcessingException { - if (value == null) { - gen.writeNull(); - } else { - gen.writeString(toString(value)); + if (value == null) { + gen.writeNull(); + } else { + gen.writeString(toString(value)); // gen.writeNumber(value); // gen.writeString("\""); - } - } + } + } @SuppressWarnings("deprecation") - public String toString (Date value) { + public String toString(Date value) { int year = value.getYear() + 1900; int month = value.getMonth() + 1; int day = value.getDate(); @@ -37,8 +37,8 @@ public class DateSerializer extends JsonSerializer { if (year < 1000) { // Add leading zeros yearString = "" + year; - yearString = yearZeros.substring(0, (4-yearString.length())) + - yearString; + yearString = yearZeros.substring(0, (4 - yearString.length())) + + yearString; } else { yearString = "" + year; } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/NullSerializer.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/NullSerializer.java index 1c57c81..8f3aade 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/NullSerializer.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/NullSerializer.java @@ -7,9 +7,9 @@ import com.fasterxml.jackson.databind.SerializerProvider; import java.io.IOException; public class NullSerializer extends JsonSerializer { - @Override - public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) - throws IOException { - jgen.writeString(""); - } + @Override + public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) + throws IOException { + jgen.writeString(""); + } } diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/TimeSerializer.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/TimeSerializer.java index ffc457b..65d0c8d 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/TimeSerializer.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/util/jackson/TimeSerializer.java @@ -10,21 +10,21 @@ import java.util.Date; public class TimeSerializer extends JsonSerializer { - @Override - public void serialize(Date value, JsonGenerator gen, - SerializerProvider serializers) throws IOException, + @Override + public void serialize(Date value, JsonGenerator gen, + SerializerProvider serializers) throws IOException, JsonProcessingException { - if (value == null) { - gen.writeNull(); - } else { - gen.writeString(toString(value)); + if (value == null) { + gen.writeNull(); + } else { + gen.writeString(toString(value)); // gen.writeNumber(value); // gen.writeString("\""); - } - } + } + } @SuppressWarnings("deprecation") - public String toString (Date value) { + public String toString(Date value) { int hour = value.getHours(); int minute = value.getMinutes(); int second = value.getSeconds(); diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/CronExpression.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/CronExpression.java index 8439758..e796086 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/CronExpression.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/CronExpression.java @@ -6,9 +6,8 @@ import java.util.*; /** * Significant portions of this code (i.e. most of it) were lifted from the Quartz scheduling library for Java. * - * @see http://www.quartz-scheduler.org/api/2.1.0/ - * * @author Matthew Lohbihler (edits to make compatible with this package) + * @see http://www.quartz-scheduler.org/api/2.1.0/ */ public class CronExpression implements Cloneable { protected static final int YEAR_AT_WHICH_TO_GIVE_UP_SCHEDULING = 2299; @@ -27,6 +26,7 @@ public class CronExpression implements Cloneable { protected static final Map monthMap = new HashMap(20); protected static final Map dayMap = new HashMap(60); + static { monthMap.put("JAN", new Integer(0)); monthMap.put("FEB", new Integer(1)); @@ -69,10 +69,8 @@ public class CronExpression implements Cloneable { /** * Constructs a new CronExpression based on the specified parameter. * - * @param cronExpression - * String representation of the cron expression the new object should represent - * @throws ParseException - * if the string expression cannot be parsed into a valid CronExpression + * @param cronExpression String representation of the cron expression the new object should represent + * @throws ParseException if the string expression cannot be parsed into a valid CronExpression */ public CronExpression(String cronExpression) throws ParseException { if (cronExpression == null) { @@ -88,8 +86,7 @@ public class CronExpression implements Cloneable { * Indicates whether the given date satisfies the cron expression. Note that milliseconds are ignored, so two Dates * falling on different milliseconds of the same second will always have the same result here. * - * @param date - * the date to evaluate + * @param date the date to evaluate * @return a boolean indicating whether the given date satisfies the cron expression */ public boolean isSatisfiedBy(Date date) { @@ -108,8 +105,7 @@ public class CronExpression implements Cloneable { /** * Returns the next date/time after the given date/time which satisfies the cron expression. * - * @param date - * the date/time at which to begin the search for the next valid date/time + * @param date the date/time at which to begin the search for the next valid date/time * @return the next valid date/time */ public Date getNextValidTimeAfter(Date date) { @@ -119,8 +115,7 @@ public class CronExpression implements Cloneable { /** * Returns the next date/time after the given date/time which does not satisfy the expression * - * @param date - * the date/time at which to begin the search for the next invalid date/time + * @param date the date/time at which to begin the search for the next invalid date/time * @return the next valid date/time */ public Date getNextInvalidTimeAfter(Date date) { @@ -184,16 +179,14 @@ public class CronExpression implements Cloneable { /** * Indicates whether the specified cron expression can be parsed into a valid cron expression * - * @param cronExpression - * the expression to evaluate + * @param cronExpression the expression to evaluate * @return a boolean indicating whether the given expression is a valid cron expression */ public static boolean isValidExpression(String cronExpression) { try { new CronExpression(cronExpression); - } - catch (ParseException pe) { + } catch (ParseException pe) { return false; } @@ -277,19 +270,15 @@ public class CronExpression implements Cloneable { if (dayOfMSpec && !dayOfWSpec) { // skip - } - else if (dayOfWSpec && !dayOfMSpec) { + } else if (dayOfWSpec && !dayOfMSpec) { // skip - } - else { + } else { throw new ParseException( "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.", 0); } - } - catch (ParseException pe) { + } catch (ParseException pe) { throw pe; - } - catch (Exception e) { + } catch (Exception e) { throw new ParseException("Illegal cron expression format (" + e.toString() + ")", 0); } } @@ -322,8 +311,7 @@ public class CronExpression implements Cloneable { } } } - } - else if (type == DAY_OF_WEEK) { + } else if (type == DAY_OF_WEEK) { sval = getDayOfWeekNumber(sub); if (sval < 0) { throw new ParseException("Invalid Day-of-Week value: '" + sub + "'", i); @@ -337,27 +325,23 @@ public class CronExpression implements Cloneable { if (eval < 0) { throw new ParseException("Invalid Day-of-Week value: '" + sub + "'", i); } - } - else if (c == '#') { + } else if (c == '#') { try { i += 4; nthdayOfWeek = Integer.parseInt(s.substring(i)); if (nthdayOfWeek < 1 || nthdayOfWeek > 5) { throw new Exception(); } - } - catch (Exception e) { + } catch (Exception e) { throw new ParseException("A numeric value between 1 and 5 must follow the '#' option", i); } - } - else if (c == 'L') { + } else if (c == 'L') { lastdayOfWeek = true; i++; } } - } - else { + } else { throw new ParseException("Illegal characters for this position: '" + sub + "'", i); } if (eval != -1) { @@ -390,11 +374,9 @@ public class CronExpression implements Cloneable { if (c == '*' && (i + 1) >= s.length()) { addToSet(ALL_SPEC_INT, -1, incr, type); return i + 1; - } - else if (c == '/' && ((i + 1) >= s.length() || s.charAt(i + 1) == ' ' || s.charAt(i + 1) == '\t')) { + } else if (c == '/' && ((i + 1) >= s.length() || s.charAt(i + 1) == ' ' || s.charAt(i + 1) == '\t')) { throw new ParseException("'/' must be followed by an integer.", i); - } - else if (c == '*') { + } else if (c == '*') { i++; } c = s.charAt(i); @@ -412,28 +394,22 @@ public class CronExpression implements Cloneable { } if (incr > 59 && (type == SECOND || type == MINUTE)) { throw new ParseException("Increment > 60 : " + incr, i); - } - else if (incr > 23 && (type == HOUR)) { + } else if (incr > 23 && (type == HOUR)) { throw new ParseException("Increment > 24 : " + incr, i); - } - else if (incr > 31 && (type == DAY_OF_MONTH)) { + } else if (incr > 31 && (type == DAY_OF_MONTH)) { throw new ParseException("Increment > 31 : " + incr, i); - } - else if (incr > 7 && (type == DAY_OF_WEEK)) { + } else if (incr > 7 && (type == DAY_OF_WEEK)) { throw new ParseException("Increment > 7 : " + incr, i); - } - else if (incr > 12 && (type == MONTH)) { + } else if (incr > 12 && (type == MONTH)) { throw new ParseException("Increment > 12 : " + incr, i); } - } - else { + } else { incr = 1; } addToSet(ALL_SPEC_INT, -1, incr, type); return i; - } - else if (c == 'L') { + } else if (c == 'L') { i++; if (type == DAY_OF_MONTH) { lastdayOfMonth = true; @@ -449,14 +425,12 @@ public class CronExpression implements Cloneable { } } return i; - } - else if (c >= '0' && c <= '9') { + } else if (c >= '0' && c <= '9') { int val = Integer.parseInt(String.valueOf(c)); i++; if (i >= s.length()) { addToSet(val, -1, -1, type); - } - else { + } else { c = s.charAt(i); if (c >= '0' && c <= '9') { ValueSet vs = getValue(val, s, i); @@ -466,8 +440,7 @@ public class CronExpression implements Cloneable { i = checkNext(i, s, val, type); return i; } - } - else { + } else { throw new ParseException("Unexpected character: " + c, i); } @@ -489,8 +462,7 @@ public class CronExpression implements Cloneable { if (c == 'L') { if (type == DAY_OF_WEEK) { lastdayOfWeek = true; - } - else { + } else { throw new ParseException("'L' option is not valid here. (pos=" + i + ")", i); } TreeSet set = getSet(type); @@ -502,8 +474,7 @@ public class CronExpression implements Cloneable { if (c == 'W') { if (type == DAY_OF_MONTH) { nearestWeekday = true; - } - else { + } else { throw new ParseException("'W' option is not valid here. (pos=" + i + ")", i); } TreeSet set = getSet(type); @@ -522,8 +493,7 @@ public class CronExpression implements Cloneable { if (nthdayOfWeek < 1 || nthdayOfWeek > 5) { throw new Exception(); } - } - catch (Exception e) { + } catch (Exception e) { throw new ParseException("A numeric value between 1 and 5 must follow the '#' option", i); } @@ -722,23 +692,19 @@ public class CronExpression implements Cloneable { if ((val < 0 || val > 59 || end > 59) && (val != ALL_SPEC_INT)) { throw new ParseException("Minute and Second values must be between 0 and 59", -1); } - } - else if (type == HOUR) { + } else if (type == HOUR) { if ((val < 0 || val > 23 || end > 23) && (val != ALL_SPEC_INT)) { throw new ParseException("Hour values must be between 0 and 23", -1); } - } - else if (type == DAY_OF_MONTH) { + } else if (type == DAY_OF_MONTH) { if ((val < 1 || val > 31 || end > 31) && (val != ALL_SPEC_INT) && (val != NO_SPEC_INT)) { throw new ParseException("Day of month values must be between 1 and 31", -1); } - } - else if (type == MONTH) { + } else if (type == MONTH) { if ((val < 1 || val > 12 || end > 12) && (val != ALL_SPEC_INT)) { throw new ParseException("Month values must be between 1 and 12", -1); } - } - else if (type == DAY_OF_WEEK) { + } else if (type == DAY_OF_WEEK) { if ((val == 0 || val > 7 || end > 7) && (val != ALL_SPEC_INT) && (val != NO_SPEC_INT)) { throw new ParseException("Day-of-Week values must be between 1 and 7", -1); } @@ -747,8 +713,7 @@ public class CronExpression implements Cloneable { if ((incr == 0 || incr == -1) && val != ALL_SPEC_INT) { if (val != -1) { set.add(new Integer(val)); - } - else { + } else { set.add(NO_SPEC); } @@ -770,40 +735,35 @@ public class CronExpression implements Cloneable { if (startAt == -1 || startAt == ALL_SPEC_INT) { startAt = 0; } - } - else if (type == HOUR) { + } else if (type == HOUR) { if (stopAt == -1) { stopAt = 23; } if (startAt == -1 || startAt == ALL_SPEC_INT) { startAt = 0; } - } - else if (type == DAY_OF_MONTH) { + } else if (type == DAY_OF_MONTH) { if (stopAt == -1) { stopAt = 31; } if (startAt == -1 || startAt == ALL_SPEC_INT) { startAt = 1; } - } - else if (type == MONTH) { + } else if (type == MONTH) { if (stopAt == -1) { stopAt = 12; } if (startAt == -1 || startAt == ALL_SPEC_INT) { startAt = 1; } - } - else if (type == DAY_OF_WEEK) { + } else if (type == DAY_OF_WEEK) { if (stopAt == -1) { stopAt = 7; } if (startAt == -1 || startAt == ALL_SPEC_INT) { startAt = 1; } - } - else if (type == YEAR) { + } else if (type == YEAR) { if (stopAt == -1) { stopAt = YEAR_AT_WHICH_TO_GIVE_UP_SCHEDULING; } @@ -818,28 +778,28 @@ public class CronExpression implements Cloneable { int max = -1; if (stopAt < startAt) { switch (type) { - case SECOND: - max = 60; - break; - case MINUTE: - max = 60; - break; - case HOUR: - max = 24; - break; - case MONTH: - max = 12; - break; - case DAY_OF_WEEK: - max = 7; - break; - case DAY_OF_MONTH: - max = 31; - break; - case YEAR: - throw new IllegalArgumentException("Start year must be less than stop year"); - default: - throw new IllegalArgumentException("Unexpected type encountered"); + case SECOND: + max = 60; + break; + case MINUTE: + max = 60; + break; + case HOUR: + max = 24; + break; + case MONTH: + max = 12; + break; + case DAY_OF_WEEK: + max = 7; + break; + case DAY_OF_MONTH: + max = 31; + break; + case YEAR: + throw new IllegalArgumentException("Start year must be less than stop year"); + default: + throw new IllegalArgumentException("Unexpected type encountered"); } stopAt += max; } @@ -848,8 +808,7 @@ public class CronExpression implements Cloneable { if (max == -1) { // ie: there's no max to overflow over set.add(new Integer(i)); - } - else { + } else { // take the modulus to get the real value int i2 = i % max; @@ -865,22 +824,22 @@ public class CronExpression implements Cloneable { protected TreeSet getSet(int type) { switch (type) { - case SECOND: - return seconds; - case MINUTE: - return minutes; - case HOUR: - return hours; - case DAY_OF_MONTH: - return daysOfMonth; - case MONTH: - return months; - case DAY_OF_WEEK: - return daysOfWeek; - case YEAR: - return years; - default: - return null; + case SECOND: + return seconds; + case MINUTE: + return minutes; + case HOUR: + return hours; + case DAY_OF_MONTH: + return daysOfMonth; + case MONTH: + return months; + case DAY_OF_WEEK: + return daysOfWeek; + case YEAR: + return years; + default: + return null; } } @@ -897,7 +856,7 @@ public class CronExpression implements Cloneable { } ValueSet val = new ValueSet(); - val.pos = (i < s.length()) ? i : i + 1; + val.pos = (i < s.length()) ? i: i + 1; val.value = Integer.parseInt(s1); return val; } @@ -965,8 +924,7 @@ public class CronExpression implements Cloneable { st = seconds.tailSet(new Integer(sec)); if (st != null && st.size() != 0) { sec = (st.first()).intValue(); - } - else { + } else { sec = (seconds.first()).intValue(); min++; cl.set(Calendar.MINUTE, min); @@ -982,8 +940,7 @@ public class CronExpression implements Cloneable { if (st != null && st.size() != 0) { t = min; min = (st.first()).intValue(); - } - else { + } else { min = (minutes.first()).intValue(); hr++; } @@ -1004,8 +961,7 @@ public class CronExpression implements Cloneable { if (st != null && st.size() != 0) { t = hr; hr = (st.first()).intValue(); - } - else { + } else { hr = (hours.first()).intValue(); day++; } @@ -1034,8 +990,7 @@ public class CronExpression implements Cloneable { if (!nearestWeekday) { t = day; day = getLastDayOfMonth(mon, cl.get(Calendar.YEAR)); - } - else { + } else { t = day; day = getLastDayOfMonth(mon, cl.get(Calendar.YEAR)); @@ -1052,14 +1007,11 @@ public class CronExpression implements Cloneable { if (dow == Calendar.SATURDAY && day == 1) { day += 2; - } - else if (dow == Calendar.SATURDAY) { + } else if (dow == Calendar.SATURDAY) { day -= 1; - } - else if (dow == Calendar.SUNDAY && day == ldom) { + } else if (dow == Calendar.SUNDAY && day == ldom) { day -= 2; - } - else if (dow == Calendar.SUNDAY) { + } else if (dow == Calendar.SUNDAY) { day += 1; } @@ -1074,8 +1026,7 @@ public class CronExpression implements Cloneable { mon++; } } - } - else if (nearestWeekday) { + } else if (nearestWeekday) { t = day; day = (daysOfMonth.first()).intValue(); @@ -1092,14 +1043,11 @@ public class CronExpression implements Cloneable { if (dow == Calendar.SATURDAY && day == 1) { day += 2; - } - else if (dow == Calendar.SATURDAY) { + } else if (dow == Calendar.SATURDAY) { day -= 1; - } - else if (dow == Calendar.SUNDAY && day == ldom) { + } else if (dow == Calendar.SUNDAY && day == ldom) { day -= 2; - } - else if (dow == Calendar.SUNDAY) { + } else if (dow == Calendar.SUNDAY) { day += 1; } @@ -1113,8 +1061,7 @@ public class CronExpression implements Cloneable { day = (daysOfMonth.first()).intValue(); mon++; } - } - else if (st != null && st.size() != 0) { + } else if (st != null && st.size() != 0) { t = day; day = (st.first()).intValue(); // make sure we don't over-run a short month, such as february @@ -1123,8 +1070,7 @@ public class CronExpression implements Cloneable { day = (daysOfMonth.first()).intValue(); mon++; } - } - else { + } else { day = (daysOfMonth.first()).intValue(); mon++; } @@ -1139,8 +1085,7 @@ public class CronExpression implements Cloneable { // are 1-based continue; } - } - else if (dayOfWSpec && !dayOfMSpec) { // get day by day of week rule + } else if (dayOfWSpec && !dayOfMSpec) { // get day by day of week rule if (lastdayOfWeek) { // are we looking for the last XXX day of // the month? int dow = (daysOfWeek.first()).intValue(); // desired @@ -1184,8 +1129,7 @@ public class CronExpression implements Cloneable { continue; } - } - else if (nthdayOfWeek != 0) { + } else if (nthdayOfWeek != 0) { // are we looking for the Nth XXX day in the month? int dow = (daysOfWeek.first()).intValue(); // desired // d-o-w @@ -1193,8 +1137,7 @@ public class CronExpression implements Cloneable { int daysToAdd = 0; if (cDow < dow) { daysToAdd = dow - cDow; - } - else if (cDow > dow) { + } else if (cDow > dow) { daysToAdd = dow + (7 - cDow); } @@ -1219,8 +1162,7 @@ public class CronExpression implements Cloneable { cl.set(Calendar.MONTH, mon); // no '- 1' here because we are promoting the month continue; - } - else if (daysToAdd > 0 || dayShifted) { + } else if (daysToAdd > 0 || dayShifted) { cl.set(Calendar.SECOND, 0); cl.set(Calendar.MINUTE, 0); cl.set(Calendar.HOUR_OF_DAY, 0); @@ -1229,8 +1171,7 @@ public class CronExpression implements Cloneable { // '- 1' here because we are NOT promoting the month continue; } - } - else { + } else { int cDow = cl.get(Calendar.DAY_OF_WEEK); // current d-o-w int dow = (daysOfWeek.first()).intValue(); // desired // d-o-w @@ -1258,8 +1199,7 @@ public class CronExpression implements Cloneable { cl.set(Calendar.MONTH, mon); // no '- 1' here because we are promoting the month continue; - } - else if (daysToAdd > 0) { // are we swithing days? + } else if (daysToAdd > 0) { // are we swithing days? cl.set(Calendar.SECOND, 0); cl.set(Calendar.MINUTE, 0); cl.set(Calendar.HOUR_OF_DAY, 0); @@ -1270,8 +1210,7 @@ public class CronExpression implements Cloneable { continue; } } - } - else { // dayOfWSpec && !dayOfMSpec + } else { // dayOfWSpec && !dayOfMSpec throw new UnsupportedOperationException( "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented."); // TODO: @@ -1295,8 +1234,7 @@ public class CronExpression implements Cloneable { if (st != null && st.size() != 0) { t = mon; mon = (st.first()).intValue(); - } - else { + } else { mon = (months.first()).intValue(); year++; } @@ -1323,8 +1261,7 @@ public class CronExpression implements Cloneable { if (st != null && st.size() != 0) { t = year; year = (st.first()).intValue(); - } - else { + } else { return null; // ran out of years... } @@ -1383,32 +1320,32 @@ public class CronExpression implements Cloneable { protected int getLastDayOfMonth(int monthNum, int year) { switch (monthNum) { - case 1: - return 31; - case 2: - return (isLeapYear(year)) ? 29 : 28; - case 3: - return 31; - case 4: - return 30; - case 5: - return 31; - case 6: - return 30; - case 7: - return 31; - case 8: - return 31; - case 9: - return 30; - case 10: - return 31; - case 11: - return 30; - case 12: - return 31; - default: - throw new IllegalArgumentException("Illegal month number: " + monthNum); + case 1: + return 31; + case 2: + return (isLeapYear(year)) ? 29: 28; + case 3: + return 31; + case 4: + return 30; + case 5: + return 31; + case 6: + return 30; + case 7: + return 31; + case 8: + return 31; + case 9: + return 30; + case 10: + return 31; + case 11: + return 30; + case 12: + return 31; + default: + throw new IllegalArgumentException("Illegal month number: " + monthNum); } } @@ -1416,8 +1353,7 @@ public class CronExpression implements Cloneable { stream.defaultReadObject(); try { buildExpression(cronExpression); - } - catch (Exception ignore) { + } catch (Exception ignore) { // never happens } } @@ -1429,8 +1365,7 @@ public class CronExpression implements Cloneable { copy = new CronExpression(getCronExpression()); if (getTimeZone() != null) copy.setTimeZone((TimeZone) getTimeZone().clone()); - } - catch (ParseException ex) { // never happens since the source is valid... + } catch (ParseException ex) { // never happens since the source is valid... throw new IncompatibleClassChangeError("Not Cloneable."); } return copy; diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/FixedRateTrigger.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/FixedRateTrigger.java index 0e778e2..a57b177 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/FixedRateTrigger.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/FixedRateTrigger.java @@ -10,8 +10,7 @@ public class FixedRateTrigger extends AbstractTimerTrigger { * * @param period * @param now - * @param quantize - * unused. Required for signature uniqueness. + * @param quantize unused. Required for signature uniqueness. */ public FixedRateTrigger(long period, long now, boolean quantize) { this(new Date(now + period - (now % period)), period); diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/ModelTimeoutTask.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/ModelTimeoutTask.java index 5f5438d..7bb175c 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/ModelTimeoutTask.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/ModelTimeoutTask.java @@ -5,9 +5,8 @@ import java.util.Date; /** * A parameterizable one-time task. Allows the pass-through of a model to the target. * - * @author Matthew - * * @param + * @author Matthew */ public class ModelTimeoutTask extends TimerTask { private final ModelTimeoutClient client; diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/NamedRunnable.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/NamedRunnable.java index 6d4b116..4609894 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/NamedRunnable.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/NamedRunnable.java @@ -23,8 +23,7 @@ public class NamedRunnable implements Runnable { try { // Ok, go ahead and run the thingy. runnable.run(); - } - finally { + } finally { // Return the name to its original. Thread.currentThread().setName(originalName); } diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/NonConcurrentTask.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/NonConcurrentTask.java index 37229a4..f3a66aa 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/NonConcurrentTask.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/NonConcurrentTask.java @@ -39,8 +39,7 @@ abstract public class NonConcurrentTask extends TimerTask { thread = Thread.currentThread(); threadRuntime = runtime; runNonConcurrent(runtime); - } - finally { + } finally { thread = null; } } diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/RealTimeTimer.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/RealTimeTimer.java index 22f43b3..0396014 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/RealTimeTimer.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/RealTimeTimer.java @@ -101,10 +101,8 @@ public class RealTimeTimer extends AbstractTimer { * one-time execution. Time is specified in Date.getTime() format. This method checks timer state, task state, and * initial execution time, but not period. * - * @throws IllegalArgumentException - * if time() is negative. - * @throws IllegalStateException - * if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated. + * @throws IllegalArgumentException if time() is negative. + * @throws IllegalStateException if task was already scheduled or cancelled, timer was cancelled, or timer thread terminated. */ @Override protected void scheduleImpl(TimerTask task) { diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/ScheduledNamedRunnable.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/ScheduledNamedRunnable.java index 0f75b9c..b1ce9c0 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/ScheduledNamedRunnable.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/ScheduledNamedRunnable.java @@ -24,8 +24,7 @@ public class ScheduledNamedRunnable implements ScheduledRunnable { try { // Ok, go ahead and run the thingy. runnable.run(fireTime); - } - finally { + } finally { // Return the name to its original. Thread.currentThread().setName(originalName); } diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/SimulationTimer.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/SimulationTimer.java index 542691c..ef9c19c 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/SimulationTimer.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/SimulationTimer.java @@ -43,8 +43,7 @@ public class SimulationTimer extends AbstractTimer { if (next <= 0) { // Non-repeating, remove queue.remove(0); task.state = TimerTask.EXECUTED; - } - else { + } else { // Repeating task, reschedule task.trigger.nextExecutionTime = next; updateQueue(); diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/TaskQueue.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/TaskQueue.java index 92cf612..7ae5bdd 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/TaskQueue.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/TaskQueue.java @@ -100,7 +100,7 @@ class TaskQueue { /** * Establishes the heap invariant (described above) assuming the heap satisfies the invariant except possibly for * the leaf-node indexed by k (which may have a nextExecutionTime less than its parent's). - * + *

* This method functions by "promoting" queue[k] up the hierarchy (by swapping it with its parent) repeatedly until * queue[k]'s nextExecutionTime is greater than or equal to that of its parent. */ @@ -119,7 +119,7 @@ class TaskQueue { /** * Establishes the heap invariant (described above) in the subtree rooted at k, which is assumed to satisfy the heap * invariant except possibly for node k itself (which may have a nextExecutionTime greater than its children's). - * + *

* This method functions by "demoting" queue[k] down the hierarchy (by swapping it with its smaller child) * repeatedly until queue[k]'s nextExecutionTime is less than or equal to those of its children. */ diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerTask.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerTask.java index 17648d8..f7570b5 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerTask.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerTask.java @@ -79,9 +79,9 @@ public abstract class TimerTask implements Runnable { * This method may be called repeatedly; the second and subsequent calls have no effect. * * @return true if this task is scheduled for one-time execution and has not yet run, or this task is scheduled for - * repeated execution. Returns false if the task was scheduled for one-time execution and has already run, - * or if the task was never scheduled, or if the task was already cancelled. (Loosely speaking, this method - * returns true if it prevents one or more scheduled executions from taking place.) + * repeated execution. Returns false if the task was scheduled for one-time execution and has already run, + * or if the task was never scheduled, or if the task was already cancelled. (Loosely speaking, this method + * returns true if it prevents one or more scheduled executions from taking place.) */ public boolean cancel() { synchronized (lock) { @@ -91,12 +91,10 @@ public abstract class TimerTask implements Runnable { try { cancelLock.writeLock().lock(); state = CANCELLED; - } - finally { + } finally { cancelLock.writeLock().unlock(); } - } - else + } else state = CANCELLED; return result; @@ -133,16 +131,13 @@ public abstract class TimerTask implements Runnable { cancelLock.readLock().lock(); if (state != CANCELLED) run(t); - } - finally { + } finally { cancelLock.readLock().unlock(); } - } - else + } else // Ok, go ahead and run the thingy. run(t); - } - finally { + } finally { if (originalName != null) // Return the name to its original. Thread.currentThread().setName(originalName); diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerThread.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerThread.java index 5c52599..c3f51c1 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerThread.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerThread.java @@ -35,11 +35,9 @@ class TimerThread extends Thread { public void run() { try { mainLoop(); - } - catch (Throwable t) { + } catch (Throwable t) { LOG.fatal("TimerThread failed", t); - } - finally { + } finally { // Someone killed this Thread, behave as if Timer was cancelled synchronized (queue) { newTasksMayBeScheduled = false; @@ -94,8 +92,7 @@ class TimerThread extends Thread { if (next <= 0) { // Non-repeating, remove queue.removeMin(); task.state = TimerTask.EXECUTED; - } - else + } else // Repeating task, reschedule queue.rescheduleMin(next); } @@ -110,13 +107,11 @@ class TimerThread extends Thread { // Task fired; run it, holding no locks try { executorService.execute(task); - } - catch (RejectedExecutionException e) { + } catch (RejectedExecutionException e) { LOG.warn("Rejected task: " + task, e); } } - } - catch (InterruptedException e) { + } catch (InterruptedException e) { // no op } } diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerTrigger.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerTrigger.java index be2e734..6a2ab92 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerTrigger.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/TimerTrigger.java @@ -39,12 +39,12 @@ abstract public class TimerTrigger { * // Perform the task * } * - * + *

* This method is typically not used in conjunction with fixed-delay execution repeating tasks, as * their scheduled execution times are allowed to drift over time, and so are not terribly significant. * * @return the time at which the most recent execution of this task was scheduled to occur, in the format returned - * by Date.getTime(). The return value is undefined if the task has yet to commence its first execution. + * by Date.getTime(). The return value is undefined if the task has yet to commence its first execution. * @see Date#getTime() */ abstract public long mostRecentExecutionTime(); diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/AsyncJobSink.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/AsyncJobSink.java index b506920..7910904 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/AsyncJobSink.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/AsyncJobSink.java @@ -23,8 +23,7 @@ public class AsyncJobSink implements Runnable { running = false; try { thread.join(); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { // no op } thread = null; @@ -46,15 +45,13 @@ public class AsyncJobSink implements Runnable { if (event != null) { System.out.println("Processed " + event.getId()); processed++; - } - else if (!running) + } else if (!running) break; else { System.out.println("null"); try { Thread.sleep(50); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { // no op } } diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/SingleExecutorSingleWaiter.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/SingleExecutorSingleWaiter.java index b087ad6..21004d2 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/SingleExecutorSingleWaiter.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/SingleExecutorSingleWaiter.java @@ -53,15 +53,13 @@ public class SingleExecutorSingleWaiter { public void run() { try { command.run(); - } - finally { + } finally { synchronized (lock) { if (waiting != null) { executing = waiting; waiting = null; executeImpl(); - } - else + } else executing = null; } } diff --git a/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/Synchronizer.java b/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/Synchronizer.java index 5a9e7c4..ea47225 100644 --- a/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/Synchronizer.java +++ b/smtweb-framework/core/src/main/java/com/serotonin/timer/sync/Synchronizer.java @@ -13,14 +13,12 @@ import java.util.concurrent.Executors; * This class acts as a synchronizing monitor where an arbitrary number of tasks can be added with string identifiers. * Then, the tasks can be executed using the provided executor and the calling thread will be blocked until they are all * completed, after which then tasks can be asked for by name to get their results. - * + *

* This allows parts of processing that would benefit from being asynchronous - such as database concurrency - to easily * be managed by a controlling thread. * + * @param a task object that implements Runnable * @author Matthew Lohbihler - * - * @param - * a task object that implements Runnable */ public class Synchronizer { private final List tasks = new ArrayList(); @@ -55,8 +53,7 @@ public class Synchronizer { for (TaskWrapper tw : tasks) timer.execute(tw); running = tasks; - } - else { + } else { List remaining = new ArrayList(tasks); running = new ArrayList(); @@ -90,8 +87,7 @@ public class Synchronizer { // No tasks completed, so wait for a notification. try { multiLock.wait(); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { // no op } } @@ -107,8 +103,7 @@ public class Synchronizer { // System.out.println("Waiting on " + tw.task); tw.wait(); } - } - catch (InterruptedException e) { + } catch (InterruptedException e) { // no op } } @@ -152,8 +147,7 @@ public class Synchronizer { public void run() { try { task.run(); - } - finally { + } finally { synchronized (this) { complete = true; notify(); @@ -220,8 +214,7 @@ public class Synchronizer { System.out.println((System.currentTimeMillis() - start) + ": started " + id); try { Thread.sleep(sleepTime); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { // no op } System.out.println((System.currentTimeMillis() - start) + ": ended " + id); From f6a3659aa9894c946ffbdecaed23a2e8c435ca93 Mon Sep 17 00:00:00 2001 From: zhenggm Date: Tue, 6 Sep 2022 20:39:15 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=B5=81=E7=A8=8B=EF=BC=9A=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E4=BB=BB=E5=8A=A1=EF=BC=8C=E4=B8=8D=E8=A6=81=E5=88=87?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/bpm/web/engine/flow/FlowInstance.java | 29 ++-------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java index 6f95a8e..13f83cd 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/engine/flow/FlowInstance.java @@ -260,23 +260,11 @@ public class FlowInstance { String sqlIn = ""; for (Task act : list) { //如果办理人是当前用户,则置此任务为当前任务 -// if (act_inst == null) { //我办理中的任务:非待办,且是我的任务 - if (act.getStatu() != FlowConst.ActivityStatu.WAIT.value) { - if (us.getUserId() == act.getHandler()) { - actInst = act; - } - } else if (FlowHelper.isMyWaitedTask(act.getId(), us.getUserId())) { - //我的待办任务 - actInst = act; + if (act.getStatu() == FlowConst.ActivityStatu.WAIT.value && FlowHelper.isMyWaitedTask(act.getId(), us.getUserId())) { + //我的待办任务,设下值,为后面的按钮判断减轻负担 act.setHandler(us.getUserId()); - } else { - Activity ae = procDef.getProcInfo().findActivity(act.getActId()); - if (ae != null && ae.getType() == FlowConst.ActivityType.END.value) { - actInst = act; - } } -// } //如果当前任务为待办理,那么要找其前置任务,作为活动任务,方便取回 if (act.getStatu() == FlowConst.ActivityStatu.WAIT.value && !act.isReject() && !act.isRetake()) { sqlIn += "," + act.getEntityId(); @@ -286,19 +274,6 @@ public class FlowInstance { if (StringUtils.isNotEmpty(sqlIn)) { List list1 = provider.findBeforeTasks(sqlIn.substring(1)); listTask.addAll(list1); - if (actInst == null) { - for (Task act : list1) { - //如果办理人是当前用户,则置此任务为当前任务 - if (us.getUserId() == act.getHandler()) { - actInst = act; - break; - } - } - } - } - //没有我的处理任务,用流程当前任务来 - if (actInst == null) { - actInst = provider.findTask(procInst.getTaskId()); } listTask.addAll(list);