diff --git a/src/com/engine/organization/entity/chart/CompanyTreePO.java b/src/com/engine/organization/entity/chart/CompanyTreePO.java new file mode 100644 index 00000000..7ba03b5a --- /dev/null +++ b/src/com/engine/organization/entity/chart/CompanyTreePO.java @@ -0,0 +1,34 @@ +package com.engine.organization.entity.chart; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import weaver.conn.RecordSet; + +/** + * @author:dxfeng + * @createTime: 2023/06/26 + * @version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CompanyTreePO { + private String id; + private String pId; + private String value; + private String title; + private boolean isLeaf; + + public boolean getIsLeaf() { + RecordSet rs = new RecordSet(); + rs.executeQuery("select id from hrmsubcompany where (canceled is null or canceled != '1') and supsubcomid = ?",id); + return rs.next(); + } + + public String getpId() { + return pId; + } +} diff --git a/src/com/engine/organization/service/OrgChartService.java b/src/com/engine/organization/service/OrgChartService.java index 8c013c9c..dd93b604 100644 --- a/src/com/engine/organization/service/OrgChartService.java +++ b/src/com/engine/organization/service/OrgChartService.java @@ -21,6 +21,14 @@ public interface OrgChartService { */ Map getOptionCondition(Map request2Map, User user); + /** + * 分部树下级数据 + * @param params [params] + * @return java.util.Map + */ + Map getSubCompanyTree(Map params); + + /** * @Description: 组织架构图 * @Author: liang.cheng diff --git a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java index 25350f40..51dc36b7 100644 --- a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java +++ b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java @@ -3,6 +3,7 @@ package com.engine.organization.service.impl; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateUtil; import com.engine.core.impl.Service; +import com.engine.organization.entity.chart.CompanyTreePO; import com.engine.organization.entity.map.JclOrgMap; import com.engine.organization.entity.scheme.po.GradePO; import com.engine.organization.entity.scheme.po.LevelPO; @@ -46,13 +47,13 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { List> fclasslist = new ArrayList<>(); Map defaultItem = new HashMap<>(); int fkey = 0; - defaultItem.put("key",fkey++); + defaultItem.put("key", fkey++); defaultItem.put("id", "0"); defaultItem.put("companyname", "行政维度"); fclasslist.add(defaultItem); while (rs.next()) { Map item = new HashMap<>(); - item.put("key",fkey++); + item.put("key", fkey++); item.put("id", rs.getString("id")); item.put("companyname", rs.getString("companyname")); fclasslist.add(item); @@ -80,9 +81,40 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.setFname(rs.getString("fname")); companySet.add(item); } + + List companyTree = new ArrayList<>(); + sql = "select id as 'id', id as 'value', subcompanyname as 'title', supsubcomid as 'pId' from hrmsubcompany where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcomid", "0") + " = '0'"; + rs.executeQuery(sql); + while (rs.next()) { + companyTree.add(CompanyTreePO.builder().id(rs.getString("id")).pId(rs.getString("pId")).value(rs.getString("value")).title(rs.getString("title")).build()); + } result.put("api_status", true); result.put("fclasslist", fclasslist); result.put("companylist", companySet); + result.put("companyTree", companyTree); + return result; + } + + @Override + public Map getSubCompanyTree(Map params) { + Map result = new HashMap<>(2); + + RecordSet rs = new RecordSet(); + List companyTree = new ArrayList<>(); + String subcompany = Util.null2String(params.get("subcompany")); + if (StringUtils.isBlank(subcompany)) { + subcompany = "0"; + } + String fclass = Util.null2String(params.get("fclass")); + String sql = "select id as 'id', id as 'value', subcompanyname as 'title', supsubcomid as 'pId' from hrmsubcompany where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcomid", "0") + " = '" + subcompany + "'"; + if (StringUtils.isNotBlank(fclass) && !"0".equals(fclass)) { + sql = "select id as 'id', id as 'value', subcompanyname as 'title', supsubcomid as 'pId' from hrmsubcompanyvirtual where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcomid", "0") + " = '" + subcompany + "' and companyid = '" + fclass + "'"; + } + rs.executeQuery(sql); + while (rs.next()) { + companyTree.add(CompanyTreePO.builder().id(rs.getString("id")).pId(rs.getString("pId")).value(rs.getString("value")).title(rs.getString("title")).build()); + } + result.put("companyTree", companyTree); return result; } @@ -100,7 +132,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { String whereSql = " where 1 = 1 "; if (DBType.isOracle()) { whereSql += " and ((fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and fdateend >= to_date('" + date + "','yyyy-MM-DD')) or (fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and fdateend is null )) "; - }else { + } else { whereSql += " and ((fdatebegin <= '" + date + "' and fdateend >= '" + date + "') or (fdatebegin <= '" + date + "' and fdateend is null )) "; } whereSql += " and fclass = " + fclass + " "; @@ -227,7 +259,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { 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 { + } else { whereSql += " and ((t.fdatebegin <= '" + date + "' and t.fdateend >= '" + date + "') or (t.fdatebegin <= '" + date + "' and t.fdateend is null )) "; } whereSql += " and t.fclass = " + fclass + " "; diff --git a/src/com/engine/organization/web/OrgChartController.java b/src/com/engine/organization/web/OrgChartController.java index e17d79af..a469d751 100644 --- a/src/com/engine/organization/web/OrgChartController.java +++ b/src/com/engine/organization/web/OrgChartController.java @@ -47,6 +47,25 @@ public class OrgChartController { return JSONObject.toJSONString(apidatas); } + @GET + @Path("/getSubCompanyTree") + @Produces(MediaType.APPLICATION_JSON) + public String getSubCompanyTree(@Context HttpServletRequest request, @Context HttpServletResponse response) { + Map apidatas = new HashMap<>(); + try { + User user = HrmUserVarify.getUser(request, response); + //实例化Service 并调用业务类处理 + apidatas = getOrgChartWrapper(user).getSubCompanyTree(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); + } + /** * 组织架构数据 */ diff --git a/src/com/engine/organization/wrapper/OrgChartWrapper.java b/src/com/engine/organization/wrapper/OrgChartWrapper.java index 3cc23ad0..6388a796 100644 --- a/src/com/engine/organization/wrapper/OrgChartWrapper.java +++ b/src/com/engine/organization/wrapper/OrgChartWrapper.java @@ -24,6 +24,10 @@ public class OrgChartWrapper extends Service { return getOrgChartService(user).getOptionCondition(request2Map, user); } + public Map getSubCompanyTree(Map request2Map, User user) { + return getOrgChartService(user).getSubCompanyTree(request2Map); + } + public Map getCompanyData(Map request2Map, User user) { return getOrgChartService(user).getCompanyData(request2Map, user); }