You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-hrm-organization/src/com/engine/organization/service/impl/ExtServiceImpl.java

257 lines
12 KiB
Java

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;
/**
3 years ago
* @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<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, "请选择对应的拓展页");
List<ExtendInfoPO> 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<String, Object> compExtMap = getExtMapper().listExt(tableName, fields, id);
List<String> 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);
3 years ago
item.setRules("required");
}
}
conditionItems.add(item);
}
return conditionItems;
}
@Override
public List<SearchConditionItem> getExtSaveForm(User user, String extendType, String tableName, int viewAttr, String groupId, String autoNoField, String serialType) {
List<SearchConditionItem> conditionItems = new ArrayList<>();
// 2编辑 1查看
OrganizationAssert.notNull(groupId, "请选择对应的拓展页");
List<ExtendInfoPO> 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);
3 years ago
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<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<>();
// 查询明细表
List<ExtendGroupPO> extendGroupList = getExtendGroupMapper().listGroupByPid(groupId);
for (ExtendGroupPO extendGroup : extendGroupList) {
infoPOList.addAll(getExtendInfoMapper().listFields(extendType, extendGroup.getId() + "", tableName, ""));
}
// 查询所有分布模块,拓展明细表信息
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);
tableMap.put("tabname", getExtendGroupMapper().getGroupNameById(entry.getKey() + ""));
Map<String, Object> 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<Map<String, Object>> 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<TopTab> getTabInfo(String extendType, String tableName) {
List<TopTab> topTabs = new ArrayList<>();
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, "", tableName, ExtendInfoOperateType.EDIT.getValue());
List<ExtendInfoPO> infoPOList1 = getExtendInfoMapper().listFields(extendType, "", tableName.toLowerCase().replace("ext", ""), ExtendInfoOperateType.EDIT.getValue());
infoPOList.addAll(infoPOList1);
List<Long> ids = infoPOList.stream().map(ExtendInfoPO::getExtendGroupId).collect(Collectors.toList());
List<ExtendTitlePO> extendTitles = getExtendTitleMapper().getTitlesByIds(ids);
Set<Long> groupIds = extendTitles.stream().map(ExtendTitlePO::getGroupId).collect(Collectors.toSet());
3 years ago
List<ExtendGroupPO> 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<String, Object> params, String groupId, Long id) {
int updateBaseComp;
List<ExtendInfoPO> extInfoPOList = getExtendInfoMapper().listFields(extendType, groupId, tableName, ExtendInfoOperateType.EDIT.getValue());
Map<String, Object> map = new HashMap<>();
for (ExtendInfoPO extendInfoPO : extInfoPOList) {
String key = extendInfoPO.getFieldName();
Object value = params.get(extendInfoPO.getFieldName());
if ("int".equals(extendInfoPO.getFieldType()) && StringUtils.isEmpty((String) value)) {
value = null;
}
3 years ago
if ("text".equals(extendInfoPO.getFieldType()) && null == value) {
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<String, Object> params, Long id) {
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));
// 删除原有明细表数据
getExtDTMapper().deleteByMainID(tableName, id);
for (Long groupId : groupIds) {
int rowNum = Util.getIntValue((String) params.get("rownum" + groupId));
List<ExtendInfoPO> filterS = poMaps.get(groupId);
for (int i = 0; i < rowNum; i++) {
Map<String, Object> 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);
}
}
}
}