package com.engine.organization.service.impl; import com.api.browser.bean.SearchConditionItem; import com.engine.core.impl.Service; import com.engine.organization.entity.TopTab; import com.engine.organization.entity.codesetting.po.CodeRulePO; import com.engine.organization.entity.extend.ExtendInfoOperateType; import com.engine.organization.entity.extend.bo.ExtendInfoBO; import com.engine.organization.entity.extend.po.ExtendGroupPO; import com.engine.organization.entity.extend.po.ExtendInfoPO; import com.engine.organization.entity.extend.po.ExtendTitlePO; import com.engine.organization.mapper.codesetting.CodeRuleMapper; import com.engine.organization.mapper.extend.*; import com.engine.organization.service.ExtService; import com.engine.organization.util.OrganizationAssert; import com.engine.organization.util.db.MapperProxyFactory; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import weaver.general.Util; import weaver.hrm.User; import java.util.*; import java.util.stream.Collectors; /** * @description: * @author:dxfeng * @createTime: 2022/05/24 * @version: 1.0 */ public class ExtServiceImpl extends Service implements ExtService { private static final Integer BROWSER_TYPE = 3; /** * 分组类型 * 1:分部 * 2:部门 * 3:岗位 */ private static final String TYPE_JOB = "3"; private ExtendInfoMapper getExtendInfoMapper() { return MapperProxyFactory.getProxy(ExtendInfoMapper.class); } private ExtendGroupMapper getExtendGroupMapper() { return MapperProxyFactory.getProxy(ExtendGroupMapper.class); } private ExtendTitleMapper getExtendTitleMapper() { return MapperProxyFactory.getProxy(ExtendTitleMapper.class); } private ExtDTMapper getExtDTMapper() { return MapperProxyFactory.getProxy(ExtDTMapper.class); } private ExtMapper getExtMapper() { return MapperProxyFactory.getProxy(ExtMapper.class); } @Override public List getExtForm(User user, String extendType, String tableName, int viewAttr, long id, String groupId, String... readOnlyFields) { List conditionItems = new ArrayList<>(); // 2编辑 1查看 OrganizationAssert.notNull(groupId, "请选择对应的拓展页"); List infoPOList = getExtendInfoMapper().listFields(extendType, groupId, tableName, ExtendInfoOperateType.EDIT.getValue()); String fields = infoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.joining(",")); if (StringUtils.isEmpty(fields)) { return conditionItems; } Map compExtMap = getExtMapper().listExt(tableName, fields, id); List readOnlyFieldList = Arrays.asList(readOnlyFields); // 组装拓展页内容 for (ExtendInfoPO extendInfoPO : infoPOList) { SearchConditionItem item = ExtendInfoBO.getSearchConditionItem(user, viewAttr, extendInfoPO, null == compExtMap ? null : compExtMap.get(extendInfoPO.getFieldName())); item.setFieldcol(16); if (2 == viewAttr) { if (readOnlyFieldList.contains(extendInfoPO.getFieldName())) { item.setViewAttr(1); } else if (1 == extendInfoPO.getIsrequired()) { item.setViewAttr(3); item.setRules("required"); } } conditionItems.add(item); } return conditionItems; } @Override public List getExtSaveForm(User user, String extendType, String tableName, int viewAttr, String groupId, String autoNoField, String serialType) { List conditionItems = new ArrayList<>(); // 2编辑 1查看 OrganizationAssert.notNull(groupId, "请选择对应的拓展页"); List infoPOList = getExtendInfoMapper().listFields(extendType, groupId, tableName, ExtendInfoOperateType.ADD.getValue()); // 组装拓展页内容 for (ExtendInfoPO extendInfoPO : infoPOList) { SearchConditionItem item = ExtendInfoBO.getSearchConditionItem(user, viewAttr, extendInfoPO, null); item.setFieldcol(16); if (1 == extendInfoPO.getIsrequired()) { item.setViewAttr(3); item.setRules("required"); } if (extendInfoPO.getFieldName().equals(autoNoField)) { // 判断是否开启自动编号 CodeRulePO codeRuleByType = MapperProxyFactory.getProxy(CodeRuleMapper.class).getCodeRuleByType(serialType); if (null != codeRuleByType && "1".equals(codeRuleByType.getSerialEnable())) { item.setViewAttr(2); item.setHelpfulTip("编号为空,则按照指定规则自动生成编号"); item.setRules(""); } } conditionItems.add(item); } return conditionItems; } @Override public List> getExtendTables(User user, String extendType, Long groupId, String tableName, long id, int viewAttr, boolean showLabel) { List> tables = new ArrayList<>(); List infoPOList = new ArrayList<>(); // 查询明细表 List extendGroupList = getExtendGroupMapper().listGroupByPid(groupId); for (ExtendGroupPO extendGroup : extendGroupList) { infoPOList.addAll(getExtendInfoMapper().listFields(extendType, extendGroup.getId() + "", tableName, "")); } // 查询所有分布模块,拓展明细表信息 Map> groupMap = infoPOList.stream().collect(Collectors.groupingBy(ExtendInfoPO::getExtendGroupId)); // 遍历Map,组装数据 for (Map.Entry> entry : groupMap.entrySet()) { Map tableMap = new HashMap<>(); tableMap.put("hide", false); tableMap.put("tabname", getExtendGroupMapper().getGroupNameById(entry.getKey() + "")); Map tabinfoMap = new HashMap<>(); tabinfoMap.put("columns", ExtendInfoBO.convertInfoListToTable(user, entry.getValue(), viewAttr, showLabel)); tabinfoMap.put("rownum", "rownum" + entry.getKey()); // 浏览按钮添加filespan字段 String fields = entry.getValue().stream().map(item -> { if (BROWSER_TYPE.equals(item.getControlType())) { return item.getFieldName() + "," + item.getFieldName() + "span"; } return item.getFieldName(); }).collect(Collectors.joining(",")); // 去除null 元素 List> maps = getExtDTMapper().listCompExtDT(tableName, id, fields); maps.removeIf(Objects::isNull); tabinfoMap.put("datas", maps); tableMap.put("tabinfo", tabinfoMap); tables.add(tableMap); } return tables; } /** * 拓展页面分组 * * @return */ public List getTabInfo(String extendType, String tableName) { List topTabs = new ArrayList<>(); List infoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, ExtendInfoOperateType.EDIT.getValue()); List infoPOList1 = getExtendInfoMapper().listFields(extendType, "", tableName.toLowerCase().replace("ext", ""), ExtendInfoOperateType.EDIT.getValue()); infoPOList.addAll(infoPOList1); List ids = infoPOList.stream().map(ExtendInfoPO::getExtendGroupId).collect(Collectors.toList()); List extendTitles = getExtendTitleMapper().getTitlesByIds(ids); Set groupIds = extendTitles.stream().map(ExtendTitlePO::getGroupId).collect(Collectors.toSet()); List extendGroupList = getExtendGroupMapper().listByType(Integer.parseInt(extendType)); // 拓展信息 if (CollectionUtils.isNotEmpty(extendGroupList) && CollectionUtils.isNotEmpty(groupIds)) { for (ExtendGroupPO extendGroup : extendGroupList) { if (groupIds.contains(extendGroup.getId())) { topTabs.add(TopTab.builder().color("#000000").groupId(extendGroup.getId().toString()).showcount(false).title(extendGroup.getGroupName()).viewCondition(extendGroup.getId().toString()).build()); } } } return topTabs; } @Override public int updateExtForm(User user, String extendType, String tableName, Map params, String groupId, Long id) { int updateBaseComp; List extInfoPOList = getExtendInfoMapper().listFields(extendType, groupId, tableName, ExtendInfoOperateType.EDIT.getValue()); Map map = new HashMap<>(); for (ExtendInfoPO extendInfoPO : extInfoPOList) { String key = extendInfoPO.getFieldName(); Object value = params.get(extendInfoPO.getFieldName()); if (null == value) { if ("int".equals(extendInfoPO.getFieldType())) { value = null; } if ("text".equals(extendInfoPO.getFieldType())) { value = ""; } } map.put(key, value); } if (null != id) { // 判断更新还是插入 int count = getExtMapper().countExtById(tableName, id); if (count > 0) { map.put("update_time", new Date()); updateBaseComp = getExtMapper().updateExt(tableName, id, map); } else { map.put("creator", user.getUID()); map.put("delete_type", 0); map.put("create_time", new Date()); map.put("update_time", new Date()); map.put("id", id); updateBaseComp = getExtMapper().insertExt(tableName, map); } } else { map.put("forbidden_tag", 0); map.put("creator", user.getUID()); map.put("delete_type", 0); map.put("create_time", new Date()); map.put("update_time", new Date()); updateBaseComp = getExtMapper().insertExt(tableName, map); } return updateBaseComp; } @Override public void updateExtDT(User user, String extendType, String tableName, Map params, Long id) { List dtInfoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, ""); List groupIds = dtInfoPOList.stream().map(ExtendInfoPO::getExtendGroupId).distinct().collect(Collectors.toList()); Map> poMaps = dtInfoPOList.stream().collect(Collectors.groupingBy(ExtendInfoPO::getExtendGroupId)); // 删除原有明细表数据 getExtDTMapper().deleteByMainID(tableName, id); for (Long groupId : groupIds) { int rowNum = Util.getIntValue((String) params.get("rownum" + groupId)); List filterS = poMaps.get(groupId); for (int i = 0; i < rowNum; i++) { Map map = new HashMap<>(); for (ExtendInfoPO extendInfoPO : filterS) { if (BROWSER_TYPE.equals(extendInfoPO.getControlType())) { map.put(extendInfoPO.getFieldName() + "span", params.get(extendInfoPO.getFieldName() + "span_" + i)); } map.put(extendInfoPO.getFieldName(), params.get(extendInfoPO.getFieldName() + "_" + i)); } map.put("mainid", id); map.put("creator", user.getUID()); map.put("delete_type", 0); map.put("create_time", new Date()); map.put("update_time", new Date()); getExtDTMapper().insertCompExtDT(tableName, map); } } } }