From 0ee5bda97dccc75810926c88375ba9937cfe6ead Mon Sep 17 00:00:00 2001 From: Mlin Date: Tue, 7 Mar 2023 18:13:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=9B=E5=88=9B=E5=9B=BD=E9=99=85=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E9=80=8F=E8=A7=86=E5=9B=BE=EF=BC=9A=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=A1=86=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=90=8C=E6=AD=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/junchuang/web/OrgChartController.java | 12 + .../junchuang/common/LocalDateRange.java | 28 ++ .../engine/junchuang/entity/JclOrgMap.java | 52 ++ .../OrganizationRunTimeException.java | 18 + .../junchuang/service/OrgChartService.java | 17 + .../service/OrgChartServiceImpl.java | 414 ++++++++++++++++ .../engine/junchuang/util/HasRightUtil.java | 29 ++ .../junchuang/util/OrganizationAssert.java | 162 ++++++ .../junchuang/util/OrganizationDateUtil.java | 460 ++++++++++++++++++ .../junchuang/util/db/DBOperateAdapter.java | 11 + src/com/engine/junchuang/util/db/DBType.java | 92 ++++ .../junchuang/util/db/MapperProxyFactory.java | 74 +++ .../junchuang/util/detach/DetachUtil.java | 40 ++ .../junchuang/util/response/ResultCode.java | 38 ++ .../junchuang/util/response/ReturnResult.java | 197 ++++++++ .../junchuang/web/OrgChartController.java | 73 +++ .../junchuang/wrapper/OrgChartWrapper.java | 30 ++ 17 files changed, 1747 insertions(+) create mode 100644 src/com/api/junchuang/web/OrgChartController.java create mode 100644 src/com/engine/junchuang/common/LocalDateRange.java create mode 100644 src/com/engine/junchuang/entity/JclOrgMap.java create mode 100644 src/com/engine/junchuang/exception/OrganizationRunTimeException.java create mode 100644 src/com/engine/junchuang/service/OrgChartService.java create mode 100644 src/com/engine/junchuang/service/OrgChartServiceImpl.java create mode 100644 src/com/engine/junchuang/util/HasRightUtil.java create mode 100644 src/com/engine/junchuang/util/OrganizationAssert.java create mode 100644 src/com/engine/junchuang/util/OrganizationDateUtil.java create mode 100644 src/com/engine/junchuang/util/db/DBOperateAdapter.java create mode 100644 src/com/engine/junchuang/util/db/DBType.java create mode 100644 src/com/engine/junchuang/util/db/MapperProxyFactory.java create mode 100644 src/com/engine/junchuang/util/detach/DetachUtil.java create mode 100644 src/com/engine/junchuang/util/response/ResultCode.java create mode 100644 src/com/engine/junchuang/util/response/ReturnResult.java create mode 100644 src/com/engine/junchuang/web/OrgChartController.java create mode 100644 src/com/engine/junchuang/wrapper/OrgChartWrapper.java diff --git a/src/com/api/junchuang/web/OrgChartController.java b/src/com/api/junchuang/web/OrgChartController.java new file mode 100644 index 0000000..62f4765 --- /dev/null +++ b/src/com/api/junchuang/web/OrgChartController.java @@ -0,0 +1,12 @@ +package com.api.junchuang.web; +import javax.ws.rs.Path; + +/** + * @Author ml + * @Date 2023/2/27 17:17 + * @Description 君创组织透视图接口 + * @Since version-1.0 + */ +@Path("/bs/junchuangorgchart") +public class OrgChartController extends com.engine.junchuang.web.OrgChartController { +} diff --git a/src/com/engine/junchuang/common/LocalDateRange.java b/src/com/engine/junchuang/common/LocalDateRange.java new file mode 100644 index 0000000..f5e1fd8 --- /dev/null +++ b/src/com/engine/junchuang/common/LocalDateRange.java @@ -0,0 +1,28 @@ +package com.engine.junchuang.common; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.util.Date; + +@Data +@Builder +@Accessors(chain = true) +@NoArgsConstructor +@AllArgsConstructor +public class LocalDateRange { + + //"开始日期 + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date fromDate; + + //结束日期 + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date endDate; + + +} diff --git a/src/com/engine/junchuang/entity/JclOrgMap.java b/src/com/engine/junchuang/entity/JclOrgMap.java new file mode 100644 index 0000000..5228bcf --- /dev/null +++ b/src/com/engine/junchuang/entity/JclOrgMap.java @@ -0,0 +1,52 @@ +package com.engine.junchuang.entity; + +import lombok.Data; + +import java.sql.Date; + +/** + * @author:dxfeng + * @createTime: 2022/09/01 + * @version: 1.0 + */ +@Data +public class JclOrgMap { + Integer fId; + Integer id; + Integer fType; + Integer fObjId; + Integer fEcId; + String uuid; + Integer fClass; + String fClassName; + String fNumber; + String fName; + Integer fLeader; + String fLeaderImg; + String fLeaderName; + Integer fLeaderJobId; + String fLeaderJob; + String fLeaderLv; + String fLeaderSt; + Integer fParentId; + Integer fObjParentId; + Integer fPlan; + Integer fOnJob; + Integer fIsVitual; + Date fDateBegin; + Date fDateEnd; + + public Integer getFPlan() { + if (null == fPlan) { + fPlan = 0; + } + return fPlan; + } + + public Integer getFOnJob() { + if (null == fOnJob) { + fOnJob = 0; + } + return fOnJob; + } +} diff --git a/src/com/engine/junchuang/exception/OrganizationRunTimeException.java b/src/com/engine/junchuang/exception/OrganizationRunTimeException.java new file mode 100644 index 0000000..9145647 --- /dev/null +++ b/src/com/engine/junchuang/exception/OrganizationRunTimeException.java @@ -0,0 +1,18 @@ +package com.engine.junchuang.exception; + +/** + * @Author weaver_cl + * @description: + * @Date 2022/4/26 + * @Version V1.0 + **/ +public class OrganizationRunTimeException extends RuntimeException{ + + public OrganizationRunTimeException(String message) { + super(message); + } + + public OrganizationRunTimeException(Throwable cause) { + super(cause); + } +} diff --git a/src/com/engine/junchuang/service/OrgChartService.java b/src/com/engine/junchuang/service/OrgChartService.java new file mode 100644 index 0000000..5770f57 --- /dev/null +++ b/src/com/engine/junchuang/service/OrgChartService.java @@ -0,0 +1,17 @@ +package com.engine.junchuang.service; + +import weaver.hrm.User; + +import java.util.Map; + +public interface OrgChartService { + + Map getOptionCondition(Map request2Map, User user); + + Map getUserData(Map request2Map, User user); + + Map asyncUserData(Map request2Map, User user); + + String syncOrgMapData(Map request2Map, User user); + +} diff --git a/src/com/engine/junchuang/service/OrgChartServiceImpl.java b/src/com/engine/junchuang/service/OrgChartServiceImpl.java new file mode 100644 index 0000000..6cf66d9 --- /dev/null +++ b/src/com/engine/junchuang/service/OrgChartServiceImpl.java @@ -0,0 +1,414 @@ +package com.engine.junchuang.service; + +import cn.hutool.core.date.DateField; +import cn.hutool.core.date.DateUtil; +import com.engine.core.impl.Service; +import com.engine.junchuang.entity.JclOrgMap; +import com.engine.junchuang.util.HasRightUtil; +import com.engine.junchuang.util.OrganizationDateUtil; +import com.engine.junchuang.util.db.DBType; +import com.engine.junchuang.util.db.MapperProxyFactory; +import com.engine.junchuang.util.detach.DetachUtil; +import org.apache.commons.lang3.StringUtils; +import org.apache.xpath.operations.Bool; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.User; + +import java.util.*; +import java.util.stream.Collectors; + +public class OrgChartServiceImpl extends Service implements OrgChartService { + private RecordSet grs = new RecordSet(); + private static final String COMPANY_RIGHT = "OrgChart:All"; + private static final String USER_RIGHT = "OrgPerspective:All"; + private final String level = getFieldName("职等"); + private final String grade = getFieldName("职级"); + + @Override + public Map getOptionCondition(Map request2Map, User user) { + Map result = new HashMap<>(); + RecordSet rs = new RecordSet(); + rs.executeQuery("select id, companyname from HrmCompanyVirtual order by id"); + List> fclasslist = new ArrayList<>(); + Map defaultItem = new HashMap<>(); + defaultItem.put("id", "0"); + defaultItem.put("companyname", "行政维度"); + fclasslist.add(defaultItem); + while (rs.next()) { + Map item = new HashMap<>(); + item.put("id", rs.getString("id")); + item.put("companyname", rs.getString("companyname")); + fclasslist.add(item); + } + String sql = "select id, fnumber, fname, ftype from jcl_org_map where ftype in (0, 1) "; + + // 分部分权过滤 + DetachUtil detachUtil = new DetachUtil(user.getUID()); + if (detachUtil.isDETACH()) { + String jclRoleLevels = detachUtil.getJclRoleLevels(); + if (StringUtils.isNotBlank(jclRoleLevels)) { + sql = "select id, fnumber, fname, ftype from jcl_org_map where (ftype = 0 or (ftype = 1 and fobjid in(" + jclRoleLevels + "))) "; + } else { + sql = "select id, fnumber, fname, ftype from jcl_org_map where ftype = 0 "; + } + } + rs.executeQuery(sql + " and fdateend > " + DBType.get(new RecordSet().getDBType()).currentDate() + " order by ftype , id,fdateend desc "); + Set companySet = new HashSet<>(); + while (rs.next()) { + OrgSelectItem item = new OrgSelectItem(); + item.setId(rs.getString("id")); + item.setFnumber(rs.getString("fnumber")); + item.setFname(rs.getString("fname")); + companySet.add(item); + } + result.put("api_status", true); + result.put("fclasslist", fclasslist); + result.put("companylist", companySet); + return result; + } + + @Override + public Map getUserData(Map request2Map, User user) { + Map result = new HashMap<>(); + boolean hasRight = HasRightUtil.hasRight(user, USER_RIGHT, true); + result.put("hasRight", hasRight); + if (!hasRight) { + return result; + } + String root = (String) request2Map.get("root"); // 根节点 + String level = (String) request2Map.get("level"); // 显示层级 + if (StringUtils.isBlank(level)) { + level = "3"; + } + + String whereSql = userWhereSql(request2Map); + + String whereItemSql = " "; + if ("0".equals(root)) { // 集团的情况 + whereItemSql += " and t.ftype = 0 "; + } else { + whereItemSql += " and t.id = '" + root + "' "; + } + + // 获取根节点 + RecordSet rs = new RecordSet(); + rs.executeQuery("select t.id, t.fname, t.ftype, t.fparentid, t.fleadername,t.fobjid,t.fecid, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader, t.fleaderlv, t.fleaderst, t.fecid, t.fisvitual,this_dept from jcl_org_map t " + whereSql + whereItemSql); + List> list = new ArrayList<>(); + String id = null; + if (rs.next()) { + Map item = new HashMap<>(); + id = rs.getString("id"); + item.put("id", rs.getString("id")); + item.put("fname", rs.getString("fname")); + item.put("ftype", rs.getString("ftype")); + item.put("parentId", null); + if ("0".equals(id)) { + item.put("fleadername", ""); + item.put("fleaderimg", ""); + item.put("fleaderjob", ""); + item.put("fleader", ""); + } else { + item.put("fleadername", rs.getString("fleadername")); + item.put("fleaderimg", rs.getString("fleaderimg")); + item.put("fleaderjob", rs.getString("fleaderjob")); + item.put("fleader", rs.getString("fleader")); + } + item.put("fplan", rs.getString("fplan")); + item.put("fonjob", rs.getString("fonjob")); + item.put("hasChildren", hasChildren(rs.getString("id"), false)); + item.put("expand", "1"); + item.put("fnumber", rs.getString("fnumber")); + item.put("fobjid", rs.getString("fobjid")); + //职等职级丢弃 +// item.put("fleaderlv", convertLevel(rs.getString("fleaderlv"))); +// item.put("fleaderst", convertGrade(rs.getString("fleaderst"))); + item.put("fecid", rs.getString("fecid")); + item.put("fisvitual", rs.getString("fisvitual")); + item.put("this_dept",rs.getString("this_dept")); + list.add(item); + } + + int currentLevel = 1; + findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level)); + + // 分部数据,构建层级关系 + reBuildTreeList(list, root); + + result.put("api_status", true); + result.put("data", list); + return result; + } + + @Override + public Map asyncUserData(Map request2Map, User user) { + return null; + } + + @Override + public String syncOrgMapData(Map request2Map, User user) { + String currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date()); + java.sql.Date date = new java.sql.Date(OrganizationDateUtil.stringToDate(currentDate).getTime()); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + Calendar calendar = weaver.common.DateUtil.addDay(cal, -1); + java.sql.Date yesterday = new java.sql.Date(calendar.getTime().getTime()); + + RecordSet rs = new RecordSet(); + // 1、清空当天所有数据 + rs.execute("delete from jcl_org_map where fdatebegin = '"+date+"'"); + // 2、修改所有失效数据 + rs.execute("update jcl_org_map set fdateend='"+yesterday+"' where fdateend > '"+date+"'"); + // 3、同步集团数据 + String jtSql = "INSERT INTO jcl_org_map ( id, ftype, fobjid, uuid,fclass, fclassname, fnumber, fname,\n" + + " fleader, fleaderimg, fleadername, fleaderjobid, fleaderjob, fparentid,fobjparentid,\n" + + " fplan, fonjob, fisvitual, fdatebegin, fdateend)\n" + + " SELECT 0, 0, 0, uuid, 0, '行政维度', '00', companyname,\n" + + " 0, NULL, NULL, 0, NULL, -1, 0,\n" + + " 0, 0, 0, TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd') FROM hrmcompany"; + rs.execute(jtSql); + // 4、同步分部数据 + String fbSql = "insert into jcl_org_map\n" + + " (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,\n" + + " fleadername,fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,\n" + + " fplan,fonjob,fisvitual,fdatebegin,fdateend)\n" + + " select a.id,1,a.id,a.uuid,0,'行政维度', '',a.subcompanyname,null,'',\n" + + " '',NULL,'','','',nvl(a.supsubcomid,0),nvl(a.supsubcomid,0),\n" + + " 0,0,0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd') from hrmsubcompany a\n" + + " where nvl(a.canceled,0) <> 1"; + rs.execute(fbSql); + // 5、同步部门数据 + String bmSql = "insert into jcl_org_map\n" + + "(id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,\n" + + " fleadername,fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" + + " fplan,fonjob,fisvitual,fdatebegin,fdateend)\n" + + "select a.id+100000000,2,a.id,a.uuid,0,'行政维度',a.DEPARTMENTCODE,a.departmentname,to_char(b.BMFZR),c.messagerurl,\n" + + " c.lastname,c.jobtitle,d.jobtitlemark,\n" + + " (case nvl(a.supdepid,0) when 0 then a.subcompanyid1 else a.supdepid+100000000 end),\n" + + " (case nvl(a.supdepid,0) when 0 then a.subcompanyid1 else a.supdepid end),\n" + + " 0,0,0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\n" + + "from HrmDepartment a\n" + + "left join hrmdepartmentdefined b on a.id=b.deptid\n" + + "left join hrmresource c on to_char(b.BMFZR)=to_char(c.ID)\n" + + "left join hrmjobtitles d on c.JOBTITLE=d.id\n" + + "where nvl(a.canceled,0) <> 1"; + rs.execute(bmSql); + // 6、同步人员数据 + String queryDept = "select id from hrmdepartment a where nvl(a.canceled,0)='0' "; + RecordSet recordSet = new RecordSet(); + recordSet.execute(queryDept); + while (recordSet.next()){ + String deptId = Util.null2String(recordSet.getString("id")); + // 找出没有下级的人员 + String noHaveChildSql = "select a.id,a.managerid from hrmresource a\n" + + "inner join (select id from hrmresource\n" + + "MINUS \n" + + "select distinct(managerid) id from hrmresource) b on a.id=b.id\n" + + "and a.departmentid='"+deptId+"'"; + rs.execute(noHaveChildSql); + while (rs.next()){ + String id = Util.null2String(rs.getString("id")); + String managerid = Util.null2String(rs.getString("managerid")); + handleSuperior(id,managerid,deptId); + } + } + + + return "同步成功"; + } + + /** + * @Author ml + * @Date 2023/3/7 15:47 + * @Description 处理上级 + */ + private void handleSuperior(String id,String managerid,String deptId){ + // 校验当前人员的直接上级是否在同一部门,如不在当前部门,map表中的上级应为部门id+ + RecordSet rs = new RecordSet(); + Boolean flag = checkManager(rs,managerid,deptId); + if (flag) { + rs.execute("insert into jcl_org_map\n" + + " (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,\n" + + " fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" + + " fisvitual,fdatebegin,fdateend)\n" + + "select a.id+200000000,4,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" + + " b.id,b.jobtitlename, nvl( a.managerid, '' ) +200000000,a.managerid,\n" + + " 0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\n" + + "from hrmresource a\n" + + "left join hrmjobtitles b on a.jobtitle=b.id\n" + + "where a.status < 4 and a.id='"+id+"'"); + // 找上级的上级 + rs.execute("select id,managerid,departmentid from hrmresource where id='"+managerid+"'"); + if (rs.next()){ + String supId = Util.null2String(rs.getString("id")); + String supManagerId = Util.null2String(rs.getString("managerid")); + String departmentid = Util.null2String(rs.getString("departmentid")); + handleSuperior(supId,supManagerId,departmentid); + } + } else { + rs.execute("insert into jcl_org_map\n" + + " (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,\n" + + " fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" + + " fisvitual,fdatebegin,fdateend)\n" + + "select a.id+200000000,4,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" + + " b.id,b.jobtitlename, nvl( a.departmentid, '' ) +100000000,a.departmentid,\n" + + " 0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\n" + + "from hrmresource a\n" + + "left join hrmjobtitles b on a.jobtitle=b.id\n" + + "where a.status < 4 and a.id='"+id+"'"); + } + } + + /** + * @Author ml + * @Date 2023/3/7 17:14 + * @Description 校验上级是不在当前部门 + */ + private Boolean checkManager(RecordSet recordSet,String managerid,String deptId){ + Boolean flag = false; + recordSet.execute("select departmentid from hrmresource where id='"+managerid+"'"); + if (recordSet.next()){ + if (deptId.equals(Util.null2String(recordSet.getString("departmentid")))) { + flag = true; + } + } + return flag; + } + + private String userWhereSql(Map request2Map) { + // 数据日期 + String date = (String) request2Map.get("date"); + if (StringUtils.isBlank(date)) { + date = DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, 1), "yyyy-MM-dd"); + } + // 维度 + String fclass = (String) request2Map.get("fclass"); + // 是否显示虚拟组织 + String fisvitual = (String) request2Map.get("fisvitual"); + if (StringUtils.isBlank(fisvitual)) { + fisvitual = "0"; + } + + String whereSql = " where 1 = 1 "; + if (DBType.isOracle()) { + whereSql += " and ((t.fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and t.fdateend >= to_date('" + date + "','yyyy-MM-DD')) or (t.fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and t.fdateend is null )) "; + } else { + whereSql += " and ((t.fdatebegin <= '" + date + "' and t.fdateend >= '" + date + "') or (t.fdatebegin <= '" + date + "' and t.fdateend is null )) "; + } + whereSql += " and t.fclass = " + fclass + " "; + + if ("0".equals(fisvitual)) { + whereSql += " and t.fisvitual = 0 "; + } else { + whereSql += " and t.fisvitual in (0, 1) "; + } + return whereSql; + } + + private boolean hasChildren(String id, boolean isCompany) { + String whereSql = " where fparentid = " + id + " "; + if (isCompany) { + whereSql += " and ftype in (0, 1, 2) "; + } + grs.executeQuery("select count(1) as count from jcl_org_map " + whereSql); + String count = "0"; + if (grs.next()) { + count = grs.getString("count"); + } + return !"0".equals(count); + } + + private String getFieldName(String fieldabel) { + RecordSet recordSet = new RecordSet(); + String fieldname = null; + recordSet.executeQuery("select fieldname from jcl_org_field where fieldlabel='" + fieldabel+"'"); + if (recordSet.next()) { + fieldname = recordSet.getString("fieldname"); + } + return fieldname; + } + + private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql, boolean expand) { + String sql = "select t.id, t.fname, t.ftype, t.fparentid, t.fobjparentid, t.fleader, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fobjid, t.fecid, t.fleaderlv, t.fleaderst, t.fisvitual, t.this_dept from jcl_org_map t " + whereSql; + DetachUtil detachUtil = new DetachUtil(user.getUID()); + if (detachUtil.isDETACH()) { + if ("0".equals(id)) { + sql += " and t.ftype = 1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")"; + } else { + sql += " and t.fparentid = " + id + " and t.ftype !=1"; + } + } else { + sql += " and t.fparentid = " + id; + } + rs.executeQuery(sql); + List> currentList = new ArrayList<>(); + while (rs.next()) { + Map item = new HashMap<>(); + item.put("id", rs.getString("id")); + item.put("fname", rs.getString("fname")); + item.put("ftype", rs.getString("ftype")); + item.put("parentId", rs.getString("fparentid")); + item.put("fobjparentId", rs.getString("fobjparentid")); + item.put("fplan", rs.getString("fplan")); + item.put("fonjob", rs.getString("fonjob")); + item.put("fnumber", rs.getString("fnumber")); + item.put("expand", expand ? "1" : "0"); + item.put("fobjid", rs.getString("fobjid")); + item.put("fecid", rs.getString("fecid")); + if (rs.getString("ftype").equals("2")) { + //多个部门负责人 +// JclOrgMap jclOrgMap = getBmfzrInfo(rs.getString("fleader")); +// item.put("fleader", jclOrgMap.getFLeader() == null ? "" : String.valueOf(jclOrgMap.getFLeader())); +// item.put("fleaderimg", jclOrgMap.getFLeaderImg()); +// item.put("fleadername", jclOrgMap.getFLeaderName() == null ? "" : jclOrgMap.getFLeaderName()); +// item.put("fleaderjob", jclOrgMap.getFLeaderJob()); +// item.put("fleaderlv", convertLevel(rs.getString("fleaderlv"))); +// item.put("fleaderst", convertGrade(rs.getString("fleaderst"))); + } else { + item.put("fleader", rs.getString("fleader")); + item.put("fleaderimg", rs.getString("fleaderimg")); + item.put("fleadername", rs.getString("fleadername")); + item.put("fleaderjob", rs.getString("fleaderjob")); +// item.put("fleaderlv", convertLevel(rs.getString("fleaderlv"))); +// item.put("fleaderst", convertGrade(rs.getString("fleaderst"))); + } + item.put("fisvitual", rs.getString("fisvitual")); + item.put("this_dept", rs.getString("this_dept")); + item.put("hasChildren", hasChildren(rs.getString("id"), false)); + currentList.add(item); + } + } + private void reBuildTreeList(List> list, String root) { + // 分部数据,构建层级关系 + Set idSet = list.stream().filter(item -> "1".equals(Util.null2String(item.get("ftype")))).map(item -> Util.null2String(item.get("id"))).collect(Collectors.toSet()); + list.forEach(item -> { + if (!root.equals(Util.null2String(item.get("id"))) && "1".equals(Util.null2String(item.get("ftype"))) && !idSet.contains(Util.null2String(item.get("parentId")))) { + item.put("parentId", root); + item.put("fobjparentId", root); + } + }); + } + static class OrgSelectItem { + private String id; + private String fnumber; + private String fname; + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getFnumber() { + return fnumber; + } + public void setFnumber(String fnumber) { + this.fnumber = fnumber; + } + public String getFname() { + return fname; + } + public void setFname(String fname) { + this.fname = fname; + } + } +} diff --git a/src/com/engine/junchuang/util/HasRightUtil.java b/src/com/engine/junchuang/util/HasRightUtil.java new file mode 100644 index 0000000..e036b8d --- /dev/null +++ b/src/com/engine/junchuang/util/HasRightUtil.java @@ -0,0 +1,29 @@ +package com.engine.junchuang.util; + +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +/** + * @description: + * @author:dxfeng + * @createTime: 2022/06/07 + * @version: 1.0 + */ +public class HasRightUtil { + + /** + * 判断是否拥有对应权限 + * + * @param user + * @param rightName + * @param isReturnFalse + * @return + */ + public static boolean hasRight(User user, String rightName, boolean isReturnFalse) { + boolean hasRight = HrmUserVarify.checkUserRight(rightName, user); + if (!isReturnFalse) { + OrganizationAssert.isTrue(hasRight, "暂无权限访问"); + } + return hasRight; + } +} diff --git a/src/com/engine/junchuang/util/OrganizationAssert.java b/src/com/engine/junchuang/util/OrganizationAssert.java new file mode 100644 index 0000000..32dcdd0 --- /dev/null +++ b/src/com/engine/junchuang/util/OrganizationAssert.java @@ -0,0 +1,162 @@ +package com.engine.junchuang.util; + +import com.engine.junchuang.exception.OrganizationRunTimeException; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; + +import java.util.Collection; +import java.util.Map; + +/** + * @Author weaver_cl + * @description: + * @Date 2022/4/26 + * @Version V1.0 + **/ +public abstract class OrganizationAssert { + /** + * 判断入参不为null + * + * @param object 待检查参数 + * @param message 检查失败返回的异常信息 + */ + public static void notNull(Object object, String message) { + if (object == null) { + throw new OrganizationRunTimeException(message); + } + } + + /** + * 判断多个入参不为null + * + * @param message 检查失败返回的异常信息 + * @param objects 待检查参数 + */ + public static void notNull(String message, Object... objects) { + for (Object obj : objects) { + if (obj == null) { + throw new OrganizationRunTimeException(message); + } + } + } + + /** + * 判断入参为null + * + * @param object 待检查参数 + * @param message 检查失败返回的异常信息 + */ + public static void isNull(Object object, String message) { + if (object != null) { + throw new OrganizationRunTimeException(message); + } + } + + /** + * 判断集合是否为空 + * + * @param collection 待检查参数 + * @param message 检查失败返回的异常信息 + */ + public static void isEmpty(Collection collection, String message) { + if (!CollectionUtils.isEmpty(collection)) { + throw new OrganizationRunTimeException(message); + } + } + + /** + * 判断集合不为空 + * + * @param collection 待检查参数 + * @param message 检查失败返回的异常信息 + */ + public static void notEmpty(Collection collection, String message) { + if (CollectionUtils.isEmpty(collection)) { + throw new OrganizationRunTimeException(message); + } + } + + /** + * 判断数组是否为空 + * + * @param arr 待检查参数 + * @param message 检查失败返回的异常信息 + */ + public static void notEmpty(Object[] arr, String message) { + if (ObjectUtils.isEmpty(arr)) { + throw new OrganizationRunTimeException(message); + } + } + + /** + * 判断map是否为空 + * + * @param map 待检查参数 + * @param message 检查失败返回的异常信息 + */ + public static void notEmpty(Map map, String message) { + if (CollectionUtils.isEmpty(map)) { + throw new OrganizationRunTimeException(message); + } + } + + /** + * 判断数组元素是否为空 + * + * @param arr 待检查参数 + * @param message 检查失败返回的异常信息 + */ + public static void notNullElement(Object[] arr, String message) { + if (arr != null) { + for (Object obj : arr) { + if (obj == null) { + throw new OrganizationRunTimeException(message); + } + } + } + } + + /** + * 判断boolean + * + * @param expression 待检查参数 + * @param message 检查失败返回的异常信息 + */ + public static void isTrue(boolean expression, String message) { + if (!expression) { + throw new OrganizationRunTimeException(message); + } + } + + public static void isFalse(boolean expression, String message) { + if (expression) { + throw new OrganizationRunTimeException(message); + } + } + + public static void isBlank(CharSequence cs, String message) { + int strLen; + if (cs != null && (strLen = cs.length()) != 0) { + for (int i = 0; i < strLen; ++i) { + if (!Character.isWhitespace(cs.charAt(i))) { + throw new OrganizationRunTimeException(message); + } + } + } + } + + public static void notBlank(CharSequence cs, String message) { + int strLen; + if (cs != null && (strLen = cs.length()) != 0) { + for (int i = 0; i < strLen; ++i) { + if (Character.isWhitespace(cs.charAt(i))) { + throw new OrganizationRunTimeException(message); + } + } + } + if (cs == null || cs.length() == 0) { + throw new OrganizationRunTimeException(message); + } + + } +} diff --git a/src/com/engine/junchuang/util/OrganizationDateUtil.java b/src/com/engine/junchuang/util/OrganizationDateUtil.java new file mode 100644 index 0000000..45f7012 --- /dev/null +++ b/src/com/engine/junchuang/util/OrganizationDateUtil.java @@ -0,0 +1,460 @@ +package com.engine.junchuang.util; + +import com.engine.junchuang.common.LocalDateRange; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; +import org.apache.commons.lang3.time.FastDateFormat; +import weaver.general.BaseBean; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.util.Calendar; +import java.util.Date; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +@Slf4j +public class OrganizationDateUtil { + + public static final ZoneId CTT = ZoneId.of(ZoneId.SHORT_IDS.get("CTT")); + public static final ZoneOffset SHANGHAI_ZONE_OFF_SET = ZoneOffset.ofHours(8); + + public static final FastDateFormat DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd"); + public static final FastDateFormat DATETIME_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); + + public static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM"); + public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + public static final String MONTH_FORMATTER_PATTERN = "yyyy-MM"; + public static final String DATE_FORMATTER_PATTERN = "yyyy-MM-dd"; + public static final String DATE_TIME_FORMATTER_PATTERN = "yyyy-MM-dd HH:mm:ss"; + /** + * yyyy-MM + **/ + private static final String MONTH_REGEX = "^([1-9]\\d{3})-(([0]{0,1}[1-9])|([1][0-2]))$"; + /** + * yyyy-MM-dd + **/ + private static final String DAY_REGEX = "^[1-9]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$"; + /** + * 含斜杠日期格式 + */ + private static final String DAY_BAR_REGEX = "^[1-9]\\d{3}/([1-9]|1[0-2])/([1-9]|[1-2][0-9]|3[0-1])$"; + + public static Long localDate2EpochMilli(LocalDate localDate) { + if (localDate == null) { + return NumberUtils.LONG_ZERO; + } + return localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); + } + + public static Long localDateTime2EpochMilli(LocalDateTime localDateTime) { + if (localDateTime == null) { + return NumberUtils.LONG_ZERO; + } + return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + } + + public static Long localDateTime2EpochMilli(Date localDateTime) { + if (localDateTime == null) { + return NumberUtils.LONG_ZERO; + } + return localDateTime.getTime(); + } + + public static String getFormatYearMonth(LocalDate localDate) { + if (localDate == null) { + return StringUtils.EMPTY; + } + try { + return localDate.format(MONTH_FORMATTER); + } catch (Exception e) { + log.warn("格式化月份错误", e); + return StringUtils.EMPTY; + } + } + + + public static String getFormatYearMonth(Date localDate) { + if (localDate == null) { + return StringUtils.EMPTY; + } + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(MONTH_FORMATTER_PATTERN); + return simpleDateFormat.format(localDate); + } catch (Exception e) { + log.warn("格式化月份错误", e); + return StringUtils.EMPTY; + } + } + + public static String getFormatLocalDate(LocalDate localDate) { + if (localDate == null) { + return StringUtils.EMPTY; + } + try { + return localDate.format(DATE_FORMATTER); + } catch (Exception e) { + log.warn("格式化日期错误", e); + return StringUtils.EMPTY; + } + } + + public static String getFormatLocalDate(LocalDateTime localDateTime) { + if (localDateTime == null) { + return StringUtils.EMPTY; + } + try { + return localDateTime.format(DATE_FORMATTER); + } catch (Exception e) { + log.warn("格式化日期错误", e); + return StringUtils.EMPTY; + } + } + + public static String getFormatLocalDateTime(LocalDateTime localDateTime) { + if (localDateTime == null) { + return StringUtils.EMPTY; + } + try { + return localDateTime.format(DATE_TIME_FORMATTER); + } catch (Exception e) { + log.warn("格式化日期错误", e); + return StringUtils.EMPTY; + } + } + + public static String getFormatLocalDateTime(Date localDateTime) { + if (localDateTime == null) { + return StringUtils.EMPTY; + } + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_TIME_FORMATTER_PATTERN); + return simpleDateFormat.format(localDateTime); + } catch (Exception e) { + log.warn("格式化日期错误", e); + return StringUtils.EMPTY; + } + } + + public static LocalDateTime dateToLocalDateTime(Date date) { + Instant instant = date.toInstant(); + ZoneId zone = ZoneId.systemDefault(); + return LocalDateTime.ofInstant(instant, zone); + } + + public static LocalDate dateToLocalDate(Date date) { + return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + } + + public static Date localDateToDate(LocalDate localDate) { + if (null == localDate) { + return null; + } + ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault()); + return Date.from(zonedDateTime.toInstant()); + } + + public static Date localDateTimeToDate(LocalDateTime localDateTime) { + if (null == localDateTime) { + return null; + } + return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + } + + public static String getFormatLocalDate(Date date) { + if (date == null) { + return StringUtils.EMPTY; + } + LocalDateTime localDateTime = dateToLocalDateTime(date); + return getFormatLocalDate(localDateTime); + } + + public static YearMonth localDate2YearMonth(Date localDate) { + if (localDate == null) { + return null; + } + Calendar c = Calendar.getInstance(); + c.setTime(localDate); + int year = c.get(Calendar.YEAR); + int month = c.get(Calendar.MONTH) + 1; + return YearMonth.of(year, month); + } + + public static YearMonth String2YearMonth(String localDate) { + if (checkDay(localDate)) { + return null; + } + + return YearMonth.parse(localDate); + } + + public static LocalDateRange localDate2Range(Date localDate) { + if (localDate == null) { + return null; + } + return LocalDateRange.builder() + .fromDate(getFirstDayDateOfMonth(localDate)) + .endDate(getLastDayOfMonth(localDate)) + .build(); + } + + public static LocalDateRange localDate2YearRange(Date localDate) { + if (localDate == null) { + return null; + } + return LocalDateRange.builder() + .fromDate(getFirstDayDateOfYear(localDate)) + .endDate(getLastDayOfYear(localDate)) + .build(); + } + + public static Date getFirstDayDateOfMonth(final Date date) { + final Calendar cal = Calendar.getInstance(); + cal.setTime(date); + final int last = cal.getActualMinimum(Calendar.DAY_OF_MONTH); + cal.set(Calendar.DAY_OF_MONTH, last); + return cal.getTime(); + } + + public static Date getLastDayOfMonth(final Date date) { + final Calendar cal = Calendar.getInstance(); + cal.setTime(date); + final int last = cal.getActualMaximum(Calendar.DAY_OF_MONTH); + cal.set(Calendar.DAY_OF_MONTH, last); + return cal.getTime(); + } + + public static Date getFirstDayDateOfYear(final Date date) { + final Calendar cal = Calendar.getInstance(); + cal.setTime(date); + final int last = cal.getActualMinimum(Calendar.DAY_OF_YEAR); + cal.set(Calendar.DAY_OF_YEAR, last); + return cal.getTime(); + } + + public static Date getLastDayOfYear(final Date date) { + final Calendar cal = Calendar.getInstance(); + cal.setTime(date); + final int last = cal.getActualMaximum(Calendar.DAY_OF_YEAR); + cal.set(Calendar.DAY_OF_YEAR, last); + return cal.getTime(); + } + + public static String getMonthBegin(String specifiedDay) { + int year; + int month; + Pattern pattern = Pattern.compile("\\d+-\\d+"); + Matcher matcher = pattern.matcher(specifiedDay); + if (StringUtils.isEmpty(specifiedDay) || !matcher.matches()) { + return null; + } else { + year = Integer.parseInt(specifiedDay.split("-")[0]); + month = Integer.parseInt(specifiedDay.split("-")[1]); + } + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month - 1); + calendar.set(Calendar.DAY_OF_MONTH, 1); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + Date startDate = calendar.getTime(); + return sdf.format(startDate); + } + + public static String getYearMonth(int yearNum, int monthNum) { + LocalDateTime dateTime = LocalDateTime.now(); + int year = dateTime.getYear() + yearNum; + int month = dateTime.getMonthValue() + monthNum; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month - 1); + calendar.set(Calendar.DAY_OF_MONTH, 1); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + Date startDate = calendar.getTime(); + return sdf.format(startDate); + } + + /** + * 检查年月格式 + * + * @param yearMonth + * @return + */ + public static boolean checkYearMonth(String yearMonth) { + return Pattern.matches(MONTH_REGEX, yearMonth); + } + + /** + * 检查日期格式 + * + * @param day + * @return + */ + public static boolean checkDay(String day) { + return Pattern.matches(DAY_REGEX, day) || Pattern.matches(DAY_BAR_REGEX, day); + } + + public static Date parse(String date, String pattern) { + SimpleDateFormat format = new SimpleDateFormat(pattern); + try { + return format.parse(date); + } catch (ParseException e) { + new BaseBean().writeLog(String.format("日期解析异常: %s, %s", date, pattern)); + } + return null; + } + + + /** + * LocalDate转YearMonth + * + * @param localDate + * @return + */ + public static YearMonth toYearMonth(LocalDate localDate) { + Objects.requireNonNull(localDate, "localDate"); + return YearMonth.of(localDate.getYear(), localDate.getMonthValue()); + } + + + /** + * YearMonth转Date + * 注意dayOfMonth范围:1到31之间,最大值根据月份确定特殊情况,如2月闰年29,非闰年28 + * 如果要转换为当月最后一天,可以使用下面方法:toDateEndOfMonth(YearMonth) + * + * @param yearMonth + * @param dayOfMonth + * @return + */ + public static Date toDate(YearMonth yearMonth, int dayOfMonth) { + Objects.requireNonNull(yearMonth, "yearMonth"); + return localDateToDate(yearMonth.atDay(dayOfMonth)); + } + + /** + * YearMonth转Date,转换为当月第一天 + * + * @param yearMonth + * @return + */ + public static Date toDateStartOfMonth(YearMonth yearMonth) { + return toDate(yearMonth, 1); + } + + /** + * YearMonth转Date,转换为当月最后一天 + * + * @param yearMonth + * @return + */ + public static Date toDateEndOfMonth(YearMonth yearMonth) { + Objects.requireNonNull(yearMonth, "yearMonth"); + return localDateToDate(yearMonth.atEndOfMonth()); + } + + + /** + * YearMonth转LocalDate + * 注意dayOfMonth范围:1到31之间,最大值根据月份确定特殊情况,如2月闰年29,非闰年28 + * 如果要转换为当月最后一天,可以使用下面方法:toLocalDateEndOfMonth(YearMonth) + * + * @param yearMonth + * @param dayOfMonth + * @return + */ + public static LocalDate toLocalDate(YearMonth yearMonth, int dayOfMonth) { + Objects.requireNonNull(yearMonth, "yearMonth"); + return yearMonth.atDay(dayOfMonth); + } + + /** + * YearMonth转LocalDate,转换为当月第一天 + * + * @param yearMonth + * @return + */ + public static LocalDate toLocalDateStartOfMonth(YearMonth yearMonth) { + return toLocalDate(yearMonth, 1); + } + + /** + * YearMonth转LocalDate,转换为当月最后一天 + * + * @param yearMonth + * @return + */ + public static LocalDate toLocalDateEndOfMonth(YearMonth yearMonth) { + Objects.requireNonNull(yearMonth, "yearMonth"); + return yearMonth.atEndOfMonth(); + } + + /** + * String转Date + * + * @param date + * @return + */ + public static Date stringToDateTime(String date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + Date parse = null; + if (date != null) { + try { + parse = sdf.parse(date); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + return parse; + } + + public static Date stringToDate(String date) { + return dateStrToLocalDate(date); + } + + //格式化日期 + public static String strToDateLong(String strDate) { + Date date = new Date(); + try { + date = new SimpleDateFormat("yyyyMMddHHmmss").parse(strDate + "000000");//先按照原格式转换为时间 + } catch (ParseException e) { + e.printStackTrace(); + } + String str = new SimpleDateFormat("yyyy-MM").format(date);//再将时间转换为对应格式字符串 + return str; + } + + private static Date dateStrToLocalDate(String date) { + Date localDate = null; + try { + date = date.substring(0, 10); + if (date.contains("/")) { + SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); + localDate = format.parse(date); + } else if (date.contains("-")) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + localDate = format.parse(date); + } + } catch (Exception e) { + log.error("日期解析异常,{}", date); + localDate = null; + } + + return localDate; + } +} + + diff --git a/src/com/engine/junchuang/util/db/DBOperateAdapter.java b/src/com/engine/junchuang/util/db/DBOperateAdapter.java new file mode 100644 index 0000000..f7938f1 --- /dev/null +++ b/src/com/engine/junchuang/util/db/DBOperateAdapter.java @@ -0,0 +1,11 @@ +package com.engine.junchuang.util.db; + +public interface DBOperateAdapter { + String like(String some); + + String concat(String some); + + String currentDate(); + + String ifNull(String some, String defaultValue); +} diff --git a/src/com/engine/junchuang/util/db/DBType.java b/src/com/engine/junchuang/util/db/DBType.java new file mode 100644 index 0000000..eed3598 --- /dev/null +++ b/src/com/engine/junchuang/util/db/DBType.java @@ -0,0 +1,92 @@ +package com.engine.junchuang.util.db; + + +import com.engine.junchuang.exception.OrganizationRunTimeException; +import weaver.conn.RecordSet; + +public enum DBType implements DBOperateAdapter { + MYSQL("mysql") { + @Override + public String like(String some) { + return " like '%" + some + "%' "; + } + + @Override + public String concat(String some) { + return " concat(','," + some + ",',') "; + } + + @Override + public String currentDate() { + return "now()"; + } + + @Override + public String ifNull(String some, String defaultValue) { + return " ifnull(" + some + ",'" + defaultValue + "')"; + } + }, + SQLSERVER("sqlserver") { + @Override + public String like(String some) { + return " like '%" + some + "%' "; + } + + @Override + public String concat(String some) { + return " ','+" + some + "+',' "; + } + + @Override + public String currentDate() { + return "GETDATE()"; + } + + @Override + public String ifNull(String some, String defaultValue) { + return " isnull(" + some + ",'" + defaultValue + "')"; + } + }, + ORACLE("oracle") { + @Override + public String like(String some) { + return " like '%" + some + "%' "; + } + + @Override + public String concat(String some) { + return " ',' ||" + some + "|| ',' "; + } + + @Override + public String currentDate() { + return "SYSDATE"; + } + + @Override + public String ifNull(String some, String defaultValue) { + return " NVL(" + some + ",'" + defaultValue + "')"; + } + }; + + private String dbtype; + + DBType(String dbtype) { + this.dbtype = dbtype; + } + + public static DBType get(String dbtype) { + for (DBType t : DBType.values()) { + if (t.dbtype.equalsIgnoreCase(dbtype)) { + return t; + } + } + throw new OrganizationRunTimeException("不支持的数据库类型"); + } + + public static boolean isOracle() { + return DBType.get(new RecordSet().getDBType()).equals(DBType.ORACLE); + } + + +} diff --git a/src/com/engine/junchuang/util/db/MapperProxyFactory.java b/src/com/engine/junchuang/util/db/MapperProxyFactory.java new file mode 100644 index 0000000..0198d78 --- /dev/null +++ b/src/com/engine/junchuang/util/db/MapperProxyFactory.java @@ -0,0 +1,74 @@ +/** + * + */ +package com.engine.junchuang.util.db; + +import org.apache.ibatis.session.SqlSession; +import weaver.conn.mybatis.MyBatisFactory; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + + +public class MapperProxyFactory implements InvocationHandler { + private Class clazz; + private boolean enableTransactions = false; + private SqlSession session; + + public MapperProxyFactory(Class clazz) { + this.clazz = clazz; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Exception { + if (this.session == null) { + this.session = MyBatisFactory.sqlSessionFactory.openSession(); + } + try { + Object target = session.getMapper(clazz); + return method.invoke(target, args); + } finally { + if (!enableTransactions) { + session.commit(); + session.close(); + } + } + } + + public Object getProxy() { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + Class[] interfaces = new Class[1]; + interfaces[0] = this.clazz; + return Proxy.newProxyInstance(loader, interfaces, this); + } + + public Object getProxy(boolean enableTransactions) { + this.enableTransactions = enableTransactions; + return this.getProxy(); + } + + public void commit() { + if (this.session != null) { + this.session.commit(); + this.session.close(); + } + } + + public void rollback() { + if (this.session != null) { + this.session.rollback(); + this.session.close(); + } + } + + public static T getProxy(Class clazz) { + MapperProxyFactory handle = new MapperProxyFactory(clazz); + return (T) handle.getProxy(); + } + + public static T getProxy(Class clazz, boolean enableTransactions) { + MapperProxyFactory handle = new MapperProxyFactory(clazz); + return (T) handle.getProxy(enableTransactions); + } +} diff --git a/src/com/engine/junchuang/util/detach/DetachUtil.java b/src/com/engine/junchuang/util/detach/DetachUtil.java new file mode 100644 index 0000000..99d2fa1 --- /dev/null +++ b/src/com/engine/junchuang/util/detach/DetachUtil.java @@ -0,0 +1,40 @@ +package com.engine.junchuang.util.detach; + +import weaver.conn.RecordSet; + +/** + * @author:dxfeng + * @createTime: 2022/10/28 + * @version: 1.0 + */ +public class DetachUtil { + private boolean DETACH = true; + + private String jclRoleLevels; + + public DetachUtil(Integer uId) { + if (1 == uId) { + DETACH = false; + } + if (DETACH) { + RecordSet rs = new RecordSet(); + String sql = "select a.RESOURCEID,b.ROLEID,GROUP_CONCAT(b.SUBCOMPANYID SEPARATOR ',') SUBCOMPANYID\n" + + "from hrmrolemembers a, SysRoleSubcomRight b where a.ROLEID=b.ROLEID\n" + + "and a.RESOURCEID="+uId+"; "; + rs.executeQuery(sql); + if(rs.next()){ + jclRoleLevels = rs.getString("SUBCOMPANYID"); + } + } else { + jclRoleLevels = null; + } + } + + public String getJclRoleLevels() { + return jclRoleLevels; + } + + public boolean isDETACH() { + return DETACH; + } +} diff --git a/src/com/engine/junchuang/util/response/ResultCode.java b/src/com/engine/junchuang/util/response/ResultCode.java new file mode 100644 index 0000000..c6b464e --- /dev/null +++ b/src/com/engine/junchuang/util/response/ResultCode.java @@ -0,0 +1,38 @@ +package com.engine.junchuang.util.response; + +public enum ResultCode implements IErrorCode { + SUCCESS(200,"操作成功"), + FAILED(500,"操作失败"), + VALIDATE_FAILED(404,"参数检验失败"), + UNAUTHORIZED(401,"暂未登陆或相关token已经过期"), + FORBIDDEN(403,"没有相关权限"), + + + BODY_NOT_MATCH(400,"请求的数据格式不符!"), + INTERNAL_SERVER_ERROR(500, "服务器内部错误!"), + SERVER_BUSY(503,"服务器正忙,请稍后再试!"); + private long code; + private String msg; + + ResultCode(long code, String msg) { + this.code = code; + this.msg = msg; + } + + @Override + public long getCode() { + return code; + } + + @Override + public String getMessage() { + return msg; + } +} + +interface IErrorCode { + long getCode(); + + String getMessage(); +} + diff --git a/src/com/engine/junchuang/util/response/ReturnResult.java b/src/com/engine/junchuang/util/response/ReturnResult.java new file mode 100644 index 0000000..1119888 --- /dev/null +++ b/src/com/engine/junchuang/util/response/ReturnResult.java @@ -0,0 +1,197 @@ +package com.engine.junchuang.util.response; + +/** + * @Author weaver_cl + * @description: + * @Date 2022/4/26 + * @Version V1.0 + **/ + +import weaver.general.BaseBean; + +import java.io.Serializable; + +public class ReturnResult implements Serializable { + private static final long serialVersionUID = 1L; + + private long code; + private T data; + private String msg; + + public ReturnResult() { + this.code = ResultCode.SUCCESS.getCode(); + this.msg = ResultCode.SUCCESS.getMessage(); + } + + /** + * @param code + * @param msg + * @param data + */ + + public ReturnResult(long code, String msg, T data) { + this.code = code; + this.data = data; + this.msg = msg; + } + + /** + * 返回 code 和 data + * + * @param data + */ + public ReturnResult(T data) { + this.code = ResultCode.SUCCESS.getCode(); + this.data = data; + } + + /** + * 返回 code 和 msg + * + * @param code + * @param msg + */ + public ReturnResult(long code, String msg) { + this.code = code; + this.msg = msg; + } + + public long getCode() { + return code; + } + + public void setCode(long code) { + this.code = code; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + + public ReturnResult Msg(String msg) { + this.setMsg(msg); + return this; + } + + + public ReturnResult Code(long code) { + this.setCode(code); + return this; + } + + + public ReturnResult Data(T data) { + this.setData(data); + return this; + } + + /** + * 返回默认状态 + */ + public static ReturnResult successed() { + return new ReturnResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage()); + } + + /** + * 成功返回 + * + * @param data + * @return + */ + public static ReturnResult successed(T data) { + + return new ReturnResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); + } + + /** + * 失败返回结果 + * + * @param errorCode + * @param + * @return + */ + public static ReturnResult failed(IErrorCode errorCode) { + return new ReturnResult<>(errorCode.getCode(), errorCode.getMessage(), null); + } + + /** + * 返回失败状态 + * + * @param msg + * @return + */ + public static ReturnResult failed(String msg) { + return failed(ResultCode.FAILED); + } + + + /** + * 参数验证失败 + * + * @param + * @return + */ + public static ReturnResult validateFailed() { + return failed(ResultCode.VALIDATE_FAILED); + } + + /** + * 参数验证失败,返回信息 + * + * @param msg + * @param + * @return + */ + public static ReturnResult validateFailed(String msg) { + return new ReturnResult<>(ResultCode.VALIDATE_FAILED.getCode(), msg); + } + + /** + * 异常处理 + * + * @param e + * @param + * @return + */ + public static ReturnResult exceptionHandle(Exception e) { + new BaseBean().writeLog(e); + return new ReturnResult<>(ResultCode.FAILED.getCode(), e.getMessage()); + } + + /** + * 未登录返回结果 。 token过期.. + * + * @param data + * @param + * @return + */ + public static ReturnResult unauthorized(T data) { + return new ReturnResult<>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data); + } + + /** + * 未授权返回结果 + * + * @param data + * @param + * @return + */ + public static ReturnResult forbiden(T data) { + return new ReturnResult<>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data); + } + + +} diff --git a/src/com/engine/junchuang/web/OrgChartController.java b/src/com/engine/junchuang/web/OrgChartController.java new file mode 100644 index 0000000..a42ea1a --- /dev/null +++ b/src/com/engine/junchuang/web/OrgChartController.java @@ -0,0 +1,73 @@ +package com.engine.junchuang.web; + +import com.alibaba.fastjson.JSONObject; +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.junchuang.util.response.ReturnResult; +import com.engine.junchuang.wrapper.OrgChartWrapper; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author ml + * @Date 2023/2/27 17:30 + * @Description This is description of class + * @Since version-1.0 + */ +public class OrgChartController { + + public OrgChartWrapper getOrgChartWrapper(User user) { + return ServiceUtil.getService(OrgChartWrapper.class, user); + } + + /** + * 获取组织维度信息 + */ + @GET + @Path("/getCondition") + @Produces(MediaType.APPLICATION_JSON) + public String getCondition(@Context HttpServletRequest request, @Context HttpServletResponse + response) { + Map apidatas = new HashMap(); + try { + User user = HrmUserVarify.getUser(request, response); + //实例化Service 并调用业务类处理 + apidatas = getOrgChartWrapper(user).getOptionCondition(ParamUtil.request2Map(request), user); + } catch (Exception e) { + //异常处理 + e.printStackTrace(); + apidatas.put("api_status", false); + apidatas.put("api_errormsg", "catch exception : " + e.getMessage()); + } + //数据转换 + return JSONObject.toJSONString(apidatas); + } + + /** + * 异步透视图数据 + */ + @GET + @Path("/syncOrgMapData") + @Produces(MediaType.APPLICATION_JSON) + public ReturnResult synchronousData(@Context HttpServletRequest request, @Context HttpServletResponse + response) { + try { + User user = HrmUserVarify.getUser(request, response); + Map params = ParamUtil.request2Map(request); + return ReturnResult.successed(getOrgChartWrapper(user).syncOrgMapData(params)); + } catch (Exception e) { + return ReturnResult.exceptionHandle(e); + } + } + +} diff --git a/src/com/engine/junchuang/wrapper/OrgChartWrapper.java b/src/com/engine/junchuang/wrapper/OrgChartWrapper.java new file mode 100644 index 0000000..9d6d036 --- /dev/null +++ b/src/com/engine/junchuang/wrapper/OrgChartWrapper.java @@ -0,0 +1,30 @@ +package com.engine.junchuang.wrapper; + +import com.engine.common.util.ServiceUtil; +import com.engine.core.impl.Service; +import com.engine.junchuang.service.OrgChartService; +import com.engine.junchuang.service.OrgChartServiceImpl; +import weaver.hrm.User; + +import java.util.Map; + +/** + * @Author ml + * @Date 2023/3/2 14:29 + * @Description This is description of class + * @Since version-1.0 + */ +public class OrgChartWrapper extends Service { + + private OrgChartService getOrgChartService(User user) { + return ServiceUtil.getService(OrgChartServiceImpl.class, user); + } + + public Map getOptionCondition(Map request2Map, User user) { + return getOrgChartService(user).getOptionCondition(request2Map, user); + } + + public String syncOrgMapData(Map request2Map) { + return getOrgChartService(user).syncOrgMapData(request2Map, user); + } +}