|
|
|
|
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.extend.bo.ExtendInfoBO;
|
|
|
|
|
import com.engine.organization.entity.extend.po.ExtendInfoPO;
|
|
|
|
|
import com.engine.organization.mapper.extend.ExtDTMapper;
|
|
|
|
|
import com.engine.organization.mapper.extend.ExtMapper;
|
|
|
|
|
import com.engine.organization.mapper.extend.ExtendGroupMapper;
|
|
|
|
|
import com.engine.organization.mapper.extend.ExtendInfoMapper;
|
|
|
|
|
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 weaver.general.Util;
|
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description: TODO
|
|
|
|
|
* @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 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) {
|
|
|
|
|
List<SearchConditionItem> conditionItems = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// 2编辑 1查看
|
|
|
|
|
OrganizationAssert.notNull(groupId, "请选择对应的拓展页");
|
|
|
|
|
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, groupId, tableName);
|
|
|
|
|
String fields = infoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.joining(","));
|
|
|
|
|
infoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.joining(","));
|
|
|
|
|
Map<String, Object> compExtMap = getExtMapper().listCompExt(tableName, fields, id);
|
|
|
|
|
// 组装拓展页内容
|
|
|
|
|
for (ExtendInfoPO extendInfoPO : infoPOList) {
|
|
|
|
|
SearchConditionItem item = ExtendInfoBO.getSearchConditionItem(user, viewAttr, extendInfoPO, null == compExtMap ? null : compExtMap.get(extendInfoPO.getFieldName()));
|
|
|
|
|
item.setFieldcol(16);
|
|
|
|
|
if (2 == viewAttr && 1 == extendInfoPO.getIsrequired()) {
|
|
|
|
|
item.setViewAttr(3);
|
|
|
|
|
item.setRules("required|string");
|
|
|
|
|
}
|
|
|
|
|
conditionItems.add(item);
|
|
|
|
|
}
|
|
|
|
|
return conditionItems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Map<String, Object>> getExtendTables(User user, String extendType, String tableName, long id, int viewAttr, boolean showLabel) {
|
|
|
|
|
List<Map<String, Object>> tables = new ArrayList<>();
|
|
|
|
|
// 查询所有分布模块,拓展明细表信息
|
|
|
|
|
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, "", 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 == 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<>();
|
|
|
|
|
// 基本信息
|
|
|
|
|
topTabs.add(TopTab.builder().color("#000000").groupId("0").showcount(false).title("基本信息").viewCondition("0").build());
|
|
|
|
|
|
|
|
|
|
List<ExtendInfoPO> infoPOList = getExtendInfoMapper().listFields(extendType, "", tableName);
|
|
|
|
|
List<Long> extendGroups = infoPOList.stream().map(ExtendInfoPO::getExtendGroupId).collect(Collectors.toList());
|
|
|
|
|
// 拓展信息
|
|
|
|
|
if (CollectionUtils.isNotEmpty(extendGroups)) {
|
|
|
|
|
for (Long groupId : extendGroups) {
|
|
|
|
|
topTabs.add(TopTab.builder().color("#000000").groupId(groupId + "").showcount(false).title(getExtendGroupMapper().getGroupNameById(groupId + "")).viewCondition(groupId + "").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);
|
|
|
|
|
List<String> extFields = extInfoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.toList());
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
for (String dtField : extFields) {
|
|
|
|
|
map.put(dtField, params.get(dtField));
|
|
|
|
|
}
|
|
|
|
|
// 判断更新还是插入
|
|
|
|
|
int count = getExtMapper().countCompExtById(tableName, id);
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
map.put("update_time", new Date());
|
|
|
|
|
updateBaseComp = getExtMapper().updateCompExt(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().insertCompExt(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 == 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|