weaver-hrm-organization/src/com/engine/organization/service/impl/ExtServiceImpl.java

326 lines
16 KiB
Java
Raw Normal View History

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;
2022-06-23 16:55:26 +08:00
import com.engine.organization.entity.extend.param.ExtendInfoParams;
import com.engine.organization.entity.extend.po.ExtendGroupPO;
import com.engine.organization.entity.extend.po.ExtendInfoPO;
2022-06-14 13:58:58 +08:00
import com.engine.organization.entity.extend.po.ExtendTitlePO;
2022-06-24 18:26:15 +08:00
import com.engine.organization.enums.ModuleTypeEnum;
import com.engine.organization.mapper.codesetting.CodeRuleMapper;
2022-06-14 13:58:58 +08:00
import com.engine.organization.mapper.extend.*;
2022-11-11 09:09:53 +08:00
import com.engine.organization.mapper.hrmresource.HrmResourceMapper;
import com.engine.organization.service.ExtService;
import com.engine.organization.util.OrganizationAssert;
2022-08-11 10:43:52 +08:00
import com.engine.organization.util.db.DBType;
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;
/**
2022-06-14 11:07:48 +08:00
* @description:
* @author:dxfeng
* @createTime: 2022/05/24
* @version: 1.0
*/
public class ExtServiceImpl extends Service implements ExtService {
private static final Integer BROWSER_TYPE = 3;
private ExtendInfoMapper getExtendInfoMapper() {
return MapperProxyFactory.getProxy(ExtendInfoMapper.class);
}
private ExtendGroupMapper getExtendGroupMapper() {
return MapperProxyFactory.getProxy(ExtendGroupMapper.class);
}
2022-06-14 13:58:58 +08:00
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<SearchConditionItem> getExtForm(User user, String extendType, String tableName, int viewAttr, long id, String groupId, String... readOnlyFields) {
List<SearchConditionItem> conditionItems = new ArrayList<>();
// 2编辑 1查看
OrganizationAssert.notNull(groupId, "请选择对应的拓展页");
2022-09-05 15:58:46 +08:00
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, groupId, tableName, 1 == viewAttr ? ExtendInfoOperateType.LIST.getValue() : ExtendInfoOperateType.EDIT.getValue(), "1");
String fields = infoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.joining(","));
2022-06-15 11:25:23 +08:00
if (StringUtils.isEmpty(fields)) {
return conditionItems;
}
2022-11-11 09:09:53 +08:00
List<String> readOnlyFieldList = new ArrayList<>(Arrays.asList(readOnlyFields));
//TODO 细化权限
if ("4".equals(extendType) && !user.isAdmin()) {
String ecResourceId = MapperProxyFactory.getProxy(HrmResourceMapper.class).getEcResourceId(String.valueOf(id));
if (Util.null2String(user.getUID()).equals(ecResourceId)) {
List<String> readOnlyList = infoPOList.stream().filter(item -> !"1".equals(Util.null2String(item.getIsModify()))).map(ExtendInfoPO::getFieldName).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(readOnlyList)) {
readOnlyFieldList.addAll(readOnlyList);
}
} else {
viewAttr = 1;
}
}
2022-06-23 16:55:26 +08:00
ExtendInfoParams infoParams = ExtendInfoParams.builder().tableName(tableName).fields(fields).params(null).id(id).build();
Map<String, Object> compExtMap = getExtMapper().listExt(infoParams);
// 组装拓展页内容
for (ExtendInfoPO extendInfoPO : infoPOList) {
2022-08-11 15:14:54 +08:00
SearchConditionItem item = ExtendInfoBO.getSearchConditionItem(user, viewAttr, extendInfoPO, null == compExtMap ? null : compExtMap.get(DBType.isOracle() ? extendInfoPO.getFieldName().toUpperCase() : extendInfoPO.getFieldName()));
item.setFieldcol(16);
if (2 == viewAttr) {
2022-07-06 10:15:26 +08:00
if (CollectionUtils.isNotEmpty(readOnlyFieldList) && readOnlyFieldList.contains(extendInfoPO.getFieldName())) {
item.setViewAttr(1);
} else if (1 == extendInfoPO.getIsrequired()) {
item.setViewAttr(3);
2022-06-20 14:50:59 +08:00
item.setRules("required");
}
}
2022-06-24 18:26:15 +08:00
// 分部,上级部门添加提示信息
if (1 != viewAttr && ModuleTypeEnum.departmentfielddefined.getValue().toString().equals(groupId) && "parent_dept".equalsIgnoreCase(extendInfoPO.getFieldName())) {
item.setHelpfulTip("请先选择所属分部再选择" + extendInfoPO.getFieldNameDesc());
}
conditionItems.add(item);
}
return conditionItems;
}
@Override
public List<SearchConditionItem> getExtSaveForm(User user, String extendType, String tableName, int viewAttr, String groupId, String autoNoField, String serialType, Map<String, Object> params, String... readOnlyFields) {
List<SearchConditionItem> conditionItems = new ArrayList<>();
if (null == params) {
params = new HashMap<>();
}
// 2编辑 1查看
OrganizationAssert.notNull(groupId, "请选择对应的拓展页");
2022-08-01 09:09:39 +08:00
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, groupId, tableName, ExtendInfoOperateType.ADD.getValue(), "1");
// 组装拓展页内容
2022-07-06 10:15:26 +08:00
List<String> readOnlyFieldList = Arrays.asList(readOnlyFields);
for (ExtendInfoPO extendInfoPO : infoPOList) {
SearchConditionItem item = ExtendInfoBO.getSearchConditionItem(user, viewAttr, extendInfoPO, params.get(extendInfoPO.getFieldName()));
item.setFieldcol(16);
2022-07-06 10:15:26 +08:00
if (CollectionUtils.isNotEmpty(readOnlyFieldList) && readOnlyFieldList.contains(extendInfoPO.getFieldName())) {
item.setViewAttr(1);
} else if (1 == extendInfoPO.getIsrequired()) {
item.setViewAttr(3);
2022-06-20 15:08:18 +08:00
item.setRules("required");
}
2022-08-11 10:43:52 +08:00
if (StringUtils.isNotBlank(autoNoField) && extendInfoPO.getFieldName().equalsIgnoreCase(autoNoField)) {
// 判断是否开启自动编号
CodeRulePO codeRuleByType = MapperProxyFactory.getProxy(CodeRuleMapper.class).getCodeRuleByType(serialType);
if (null != codeRuleByType && "1".equals(codeRuleByType.getSerialEnable())) {
item.setViewAttr(2);
item.setHelpfulTip("编号为空,则按照指定规则自动生成编号");
item.setRules("");
}
}
2022-06-24 18:26:15 +08:00
// 分部,上级部门添加提示信息
if (ModuleTypeEnum.departmentfielddefined.getValue().toString().equals(groupId) && "parent_dept".equalsIgnoreCase(extendInfoPO.getFieldName())) {
item.setHelpfulTip("请先选择所属分部再选择" + extendInfoPO.getFieldNameDesc());
}
conditionItems.add(item);
}
return conditionItems;
}
@Override
public List<Map<String, Object>> getExtendTables(User user, String extendType, Long groupId, String tableName, long id, int viewAttr, boolean showLabel) {
List<Map<String, Object>> tables = new ArrayList<>();
List<ExtendInfoPO> infoPOList = new ArrayList<>();
// 查询明细表
2022-08-22 13:35:21 +08:00
List<ExtendGroupPO> extendGroupList = getExtendGroupMapper().listGroupByPid(groupId, "1");
for (ExtendGroupPO extendGroup : extendGroupList) {
2022-11-11 09:09:53 +08:00
List<ExtendInfoPO> extendInfoPOS = getExtendInfoMapper().listFields(extendType, extendGroup.getId() + "", tableName, "", "1");
if (CollectionUtils.isNotEmpty(extendInfoPOS)) {
infoPOList.addAll(extendInfoPOS);
}
}
2022-11-11 09:09:53 +08:00
Map<Long, List<ExtendInfoPO>> allFields = infoPOList.stream().collect(Collectors.groupingBy(ExtendInfoPO::getExtendGroupId));
//TODO 控制展示权限
boolean checkRight = true;
if ("4".equals(extendType) && !user.isAdmin()) {
checkRight = false;
2022-11-11 16:24:26 +08:00
String ecResourceId = MapperProxyFactory.getProxy(HrmResourceMapper.class).getEcResourceId(String.valueOf(id));
if (Util.null2String(user.getUID()).equals(ecResourceId)) {
infoPOList.removeIf(item -> !"1".equals(Util.null2String(item.getIsModify())));
}else{
infoPOList = new ArrayList<>();
}
2022-11-11 09:09:53 +08:00
}
// 查询所有分布模块,拓展明细表信息
Map<Long, List<ExtendInfoPO>> groupMap = infoPOList.stream().collect(Collectors.groupingBy(ExtendInfoPO::getExtendGroupId));
// 遍历Map,组装数据
for (Map.Entry<Long, List<ExtendInfoPO>> entry : groupMap.entrySet()) {
Map<String, Object> tableMap = new HashMap<>();
tableMap.put("hide", false);
2022-09-09 10:25:57 +08:00
tableMap.put("tabname", getExtendGroupMapper().getGroupNameById(Util.null2String(entry.getKey())));
Map<String, Object> tabinfoMap = new HashMap<>();
2022-11-11 09:09:53 +08:00
//TODO 需优化
tabinfoMap.put("columns", ExtendInfoBO.convertInfoListToTable(user, entry.getValue(), viewAttr, showLabel));
2022-05-25 10:56:53 +08:00
tabinfoMap.put("rownum", "rownum" + entry.getKey());
// 浏览按钮添加filespan字段
2022-11-11 09:09:53 +08:00
String fields = allFields.get(entry.getKey()).stream().map(item -> {
if (BROWSER_TYPE.equals(item.getControlType())) {
return item.getFieldName() + "," + item.getFieldName() + "span";
}
return item.getFieldName();
}).collect(Collectors.joining(","));
// 去除null 元素
List<Map<String, Object>> maps = getExtDTMapper().listCompExtDT(tableName, id, fields);
maps.removeIf(Objects::isNull);
2022-08-11 10:43:52 +08:00
// 兼容Oracle,map的key转换为小写
2022-11-11 09:09:53 +08:00
boolean finalCheckRight = checkRight;
2022-08-11 10:43:52 +08:00
List<Map<String, Object>> collect = maps.stream().map(item -> {
Map<String, Object> resultMap = new HashMap<>();
Set<String> keys = item.keySet();
for (String key : keys) {
resultMap.put(key.toLowerCase(), item.get(key));
}
2022-11-11 09:09:53 +08:00
resultMap.put("viewAttr", finalCheckRight ? 2 : 1);
2022-08-11 10:43:52 +08:00
return resultMap;
}).collect(Collectors.toList());
tabinfoMap.put("datas", collect);
tableMap.put("tabinfo", tabinfoMap);
tables.add(tableMap);
}
return tables;
}
/**
* 拓展页面分组
*
* @return
*/
public List<TopTab> getTabInfo(String extendType, String tableName) {
List<TopTab> topTabs = new ArrayList<>();
2022-08-01 09:09:39 +08:00
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, ExtendInfoOperateType.EDIT.getValue(), "1");
2022-08-11 10:43:52 +08:00
List<ExtendInfoPO> infoPOList1 = getExtendInfoMapper().listFields(extendType, "", tableName.toUpperCase().replace("EXT", ""), ExtendInfoOperateType.EDIT.getValue(), "1");
infoPOList.addAll(infoPOList1);
List<Long> ids = infoPOList.stream().map(ExtendInfoPO::getExtendGroupId).collect(Collectors.toList());
2022-08-01 09:09:39 +08:00
2022-06-14 13:58:58 +08:00
List<ExtendTitlePO> extendTitles = getExtendTitleMapper().getTitlesByIds(ids);
Set<Long> groupIds = extendTitles.stream().map(ExtendTitlePO::getGroupId).collect(Collectors.toSet());
2022-08-22 13:35:21 +08:00
List<ExtendGroupPO> extendGroupList = getExtendGroupMapper().listByType(Integer.parseInt(extendType), "1");
2022-06-14 13:58:58 +08:00
// 拓展信息
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
2022-06-23 16:55:26 +08:00
public Long updateExtForm(User user, String extendType, String tableName, Map<String, Object> params, String groupId, Long id) {
2022-07-27 16:47:19 +08:00
List<ExtendInfoPO> extInfoPOList = getExtendInfoMapper().listFields(extendType, groupId, tableName, "", "");
Map<String, Object> map = new HashMap<>();
// 遍历Map
Map<String, ExtendInfoPO> collect = extInfoPOList.stream().collect(Collectors.toMap(ExtendInfoPO::getFieldName, item -> item));
2022-08-26 15:36:06 +08:00
collect.put("uuid", new ExtendInfoPO());
for (Map.Entry<String, Object> entry : params.entrySet()) {
String key = entry.getKey();
if (collect.containsKey(key)) {
Object value = entry.getValue();
if (null != value && StringUtils.isBlank(value.toString())) {
2022-06-20 15:16:25 +08:00
value = null;
}
if (null == value) {
if ("int".equals(collect.get(key).getFieldType())) {
value = null;
}
// 兼容sqlServer数据库text字段类型
if ("text".equals(collect.get(key).getFieldType())) {
value = "";
}
2022-06-20 15:16:25 +08:00
}
map.put(key, value);
2022-06-20 14:50:59 +08:00
}
}
2022-06-23 16:55:26 +08:00
ExtendInfoParams infoParams = ExtendInfoParams.builder().tableName(tableName).params(map).id(id).build();
if (null != id) {
// 判断更新还是插入
2022-06-23 16:55:26 +08:00
int count = getExtMapper().countExtById(infoParams);
if (count > 0) {
map.put("update_time", new Date());
2022-08-12 09:34:19 +08:00
getExtMapper().updateTable(infoParams);
} 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);
2022-08-12 09:34:19 +08:00
getExtMapper().insertExtTable(infoParams);
}
} else {
if (!tableName.equals("JCL_ORG_HRMRESOURCE")) {
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());
2022-08-12 09:34:19 +08:00
getExtMapper().insertTable(infoParams);
}
2022-06-23 16:55:26 +08:00
return infoParams.getId();
}
@Override
public void updateExtDT(User user, String extendType, String tableName, Map<String, Object> params, Long id) {
2022-07-27 16:47:19 +08:00
List<ExtendInfoPO> dtInfoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, "", "");
List<Long> groupIds = dtInfoPOList.stream().map(ExtendInfoPO::getExtendGroupId).distinct().collect(Collectors.toList());
Map<Long, List<ExtendInfoPO>> poMaps = dtInfoPOList.stream().collect(Collectors.groupingBy(ExtendInfoPO::getExtendGroupId));
2022-05-25 10:56:53 +08:00
2022-09-23 09:19:42 +08:00
boolean deleteFlag = true;
for (Long groupId : groupIds) {
int rowNum = Util.getIntValue((String) params.get("rownum" + groupId));
2022-09-23 09:19:42 +08:00
if (deleteFlag && rowNum > 0) {
// 删除原有明细表数据
getExtDTMapper().deleteByMainID(tableName, id);
deleteFlag = false;
}
List<ExtendInfoPO> filterS = poMaps.get(groupId);
2022-05-25 10:56:53 +08:00
for (int i = 0; i < rowNum; i++) {
Map<String, Object> map = new HashMap<>();
for (ExtendInfoPO extendInfoPO : filterS) {
if (BROWSER_TYPE.equals(extendInfoPO.getControlType())) {
2022-05-25 10:56:53 +08:00
map.put(extendInfoPO.getFieldName() + "span", params.get(extendInfoPO.getFieldName() + "span_" + i));
}
map.put(extendInfoPO.getFieldName(), params.get(extendInfoPO.getFieldName() + "_" + i));
}
2022-05-25 10:56:53 +08:00
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);
}
}
}
}