From a6a8053578c20952b360725414fdbb3ad1fac903 Mon Sep 17 00:00:00 2001 From: dxfeng Date: Fri, 20 May 2022 17:34:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=8F=B8/=E5=88=86=E9=83=A8=20?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=A1=B5=E9=9D=A2=E6=8E=A5=E5=8F=A3=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/comp/CompExtMapper.java | 25 ++++++ .../mapper/comp/CompExtMapper.xml | 28 +++++++ .../service/impl/CompServiceImpl.java | 77 +++++++++++++------ 3 files changed, 108 insertions(+), 22 deletions(-) diff --git a/src/com/engine/organization/mapper/comp/CompExtMapper.java b/src/com/engine/organization/mapper/comp/CompExtMapper.java index d5b66dd1..ff6482d7 100644 --- a/src/com/engine/organization/mapper/comp/CompExtMapper.java +++ b/src/com/engine/organization/mapper/comp/CompExtMapper.java @@ -20,4 +20,29 @@ public interface CompExtMapper { * @return */ Map listCompExt(@Param("tableName") String tableName, @Param("fields") String fields, @Param("id") long id); + + /** + * 判断当前数据是否存在 + * + * @param tableName + * @param id + * @return + */ + int countCompExtById(@Param("tableName") String tableName, @Param("id") long id); + + /** + * 插入主表拓展表 + * + * @param map + * @return + */ + int insertCompExt(@Param("tableName") String tableName, @Param("map") Map map); + + /** + * 更新主表拓展表 + * + * @param map + * @return + */ + int updateCompExt(@Param("tableName") String tableName, @Param("id") long id, @Param("map") Map map); } diff --git a/src/com/engine/organization/mapper/comp/CompExtMapper.xml b/src/com/engine/organization/mapper/comp/CompExtMapper.xml index 3fa95837..e2305c1c 100644 --- a/src/com/engine/organization/mapper/comp/CompExtMapper.xml +++ b/src/com/engine/organization/mapper/comp/CompExtMapper.xml @@ -3,10 +3,38 @@ + + insert into ${tableName} ( + + ${key} + + ) + values ( + + #{value} + + ) + + + + update ${tableName} set + + ${key} = #{value} + + where id = #{id} + + + + \ No newline at end of file diff --git a/src/com/engine/organization/service/impl/CompServiceImpl.java b/src/com/engine/organization/service/impl/CompServiceImpl.java index 77db9804..78d72c6c 100644 --- a/src/com/engine/organization/service/impl/CompServiceImpl.java +++ b/src/com/engine/organization/service/impl/CompServiceImpl.java @@ -46,6 +46,22 @@ import java.util.stream.Collectors; * @version: 1.0 */ public class CompServiceImpl extends Service implements CompService { + /** + * 分组类型 + * 1:分部 + * 2:部门 + * 3:岗位 + */ + private static final String EXTEND_TYPE = "1"; + /** + * 主表拓展表 + */ + private static final String JCL_ORG_COMPEXT = "JCL_ORG_COMPEXT"; + /** + * 明细表拓展表 + */ + private static final String JCL_ORG_COMPEXT_DT1 = "JCL_ORG_COMPEXT_DT1"; + private CompMapper getCompMapper() { return MapperProxyFactory.getProxy(CompMapper.class); } @@ -122,18 +138,41 @@ public class CompServiceImpl extends Service implements CompService { @Override public int updateComp(Map params) { CompSearchParam searchParam = JSONObject.parseObject(JSONObject.toJSONString(params), CompSearchParam.class); - // 更新主表数据 + String groupId = (String) params.get("viewCondition"); + int updateBaseComp = 0; CompPO compPO = CompBO.convertParamToPO(searchParam, (long) user.getUID()); - int updateBaseComp = getCompMapper().updateBaseComp(compPO); + if (StringUtil.isEmpty(groupId) || "0".equals(groupId)) { + // 更新主表数据 + updateBaseComp = getCompMapper().updateBaseComp(compPO); + } else { + List extInfoPOList = getExtendInfoMapper().listFields(EXTEND_TYPE, groupId, JCL_ORG_COMPEXT); + List extFields = extInfoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.toList()); + Map map = new HashMap<>(); + for (String dtField : extFields) { + map.put(dtField, params.get(dtField)); + } + // 判断更新还是插入 + int count = getCompExtMapper().countCompExtById(JCL_ORG_COMPEXT, searchParam.getId()); + if (count > 0) { + map.put("update_time", compPO.getUpdateTime()); + updateBaseComp = getCompExtMapper().updateCompExt(JCL_ORG_COMPEXT, compPO.getId(), map); + } else { + map.put("creator", compPO.getCreator()); + map.put("delete_type", compPO.getDeleteType()); + map.put("create_time", compPO.getCreateTime()); + map.put("update_time", compPO.getUpdateTime()); + map.put("id", compPO.getId()); + updateBaseComp = getCompExtMapper().insertCompExt(JCL_ORG_COMPEXT, map); + } + } // 获取分部明细表的所有拓展列 - String tableName = "JCL_ORG_COMPEXT_DT1"; - List infoPOList = getExtendInfoMapper().listFields("1", "", tableName); - List dtFields = infoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.toList()); + List dtInfoPOList = getExtendInfoMapper().listFields(EXTEND_TYPE, "", JCL_ORG_COMPEXT_DT1); + List dtFields = dtInfoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.toList()); List> insertList = new ArrayList<>(); // 删除明细表数据 - getCompExtDTMapper().deleteByMainID(tableName, compPO.getId()); + getCompExtDTMapper().deleteByMainID(JCL_ORG_COMPEXT_DT1, compPO.getId()); // 处理明细表数据 int rowNum = Util.getIntValue((String) params.get("rownum")); for (int i = 0; i < rowNum; i++) { @@ -150,7 +189,7 @@ public class CompServiceImpl extends Service implements CompService { } // 更新拓展表数据 for (Map map : insertList) { - getCompExtDTMapper().insertCompExtDT(tableName, map); + getCompExtDTMapper().insertCompExtDT(JCL_ORG_COMPEXT_DT1, map); } return updateBaseComp; @@ -235,21 +274,17 @@ public class CompServiceImpl extends Service implements CompService { buttonsMap.put("hasEdit", true); buttonsMap.put("hasSave", true); - HashMap conditionsMap = new HashMap<>(); + List addGroups = new ArrayList<>(); if (StringUtil.isEmpty(groupId) || "0".equals(groupId)) { - conditionsMap.put("items", getBaseForm(viewAttr, id)); - conditionsMap.put("title", "基本信息"); + addGroups.add(new SearchConditionGroup("基本信息", true, getBaseForm(viewAttr, id))); } else { - conditionsMap.put("items", getExtForm(viewAttr, id, groupId)); - conditionsMap.put("title", getExtendGroupMapper().getGroupNameById(groupId)); + addGroups.add(new SearchConditionGroup(getExtendGroupMapper().getGroupNameById(groupId), true, getExtForm(viewAttr, id, groupId))); } - conditionsMap.put("hide", false); - conditionsMap.put("defaultshow", true); HashMap resultMap = new HashMap<>(); resultMap.put("buttons", buttonsMap); - resultMap.put("conditions", conditionsMap); + resultMap.put("conditions", addGroups); resultMap.put("id", id); resultMap.put("tabInfo", getTabInfo()); resultMap.put("tables", getExtendTables(id, viewAttr, false)); @@ -357,9 +392,8 @@ public class CompServiceImpl extends Service implements CompService { */ private List> getExtendTables(long id, int viewAttr, boolean showLabel) { List> tables = new ArrayList<>(); - String tableName = "JCL_ORG_COMPEXT_DT1"; // 查询所有分布模块,拓展明细表信息 - List infoPOList = getExtendInfoMapper().listFields("1", "", tableName); + List infoPOList = getExtendInfoMapper().listFields(EXTEND_TYPE, "", JCL_ORG_COMPEXT_DT1); Map> groupMap = infoPOList.stream().collect(Collectors.groupingBy(ExtendInfoPO::getExtendGroupId)); // 遍历Map,组装数据 for (Map.Entry> entry : groupMap.entrySet()) { @@ -371,7 +405,7 @@ public class CompServiceImpl extends Service implements CompService { tabinfoMap.put("rownum", "rownum"); String fields = entry.getValue().stream().map(ExtendInfoPO::getFieldName).collect(Collectors.joining(",")); - tabinfoMap.put("datas", getCompExtDTMapper().listCompExtDT(tableName, id, fields)); + tabinfoMap.put("datas", getCompExtDTMapper().listCompExtDT(JCL_ORG_COMPEXT_DT1, id, fields)); tableMap.put("tabinfo", tabinfoMap); tables.add(tableMap); } @@ -406,7 +440,7 @@ public class CompServiceImpl extends Service implements CompService { // 基本信息 topTabs.add(TopTab.builder().color("#000000").groupId("0").showcount(false).title("基本信息").viewCondition("0").build()); - List infoPOList = getExtendInfoMapper().listFields("1", "", "JCL_ORG_COMPEXT"); + List infoPOList = getExtendInfoMapper().listFields(EXTEND_TYPE, "", JCL_ORG_COMPEXT); List extendGroups = infoPOList.stream().map(ExtendInfoPO::getExtendGroupId).collect(Collectors.toList()); // 拓展信息 if (CollectionUtils.isNotEmpty(extendGroups)) { @@ -510,10 +544,9 @@ public class CompServiceImpl extends Service implements CompService { // 2编辑 1查看 OrganizationAssert.notNull(groupId, "请选择对应的拓展页"); - String tableName = "JCL_ORG_COMPEXT"; - List infoPOList = getExtendInfoMapper().listFields("1", groupId, tableName); + List infoPOList = getExtendInfoMapper().listFields(EXTEND_TYPE, groupId, JCL_ORG_COMPEXT); String fields = infoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.joining(",")); - Map compExtMap = getCompExtMapper().listCompExt(tableName, fields, id); + Map compExtMap = getCompExtMapper().listCompExt(JCL_ORG_COMPEXT, fields, id); // 组装拓展页内容 for (ExtendInfoPO extendInfoPO : infoPOList) {