部门管理模块接口 拓展表通用方法抽取
parent
cd6121f0b0
commit
cb1b37e05d
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.engine.organization.mapper.comp.CompExtMapper">
|
||||
<mapper namespace="com.engine.organization.mapper.extend.ExtMapper">
|
||||
|
||||
|
||||
<insert id="insertCompExt" parameterType="java.util.Map">
|
@ -0,0 +1,77 @@
|
||||
package com.engine.organization.service;
|
||||
|
||||
import com.api.browser.bean.SearchConditionItem;
|
||||
import com.engine.organization.entity.TopTab;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description: TODO
|
||||
* @author:dxfeng
|
||||
* @createTime: 2022/05/24
|
||||
* @version: 1.0
|
||||
*/
|
||||
public interface ExtService {
|
||||
|
||||
/**
|
||||
* 组装主表拓展表表单
|
||||
*
|
||||
* @param user
|
||||
* @param extendType
|
||||
* @param tableName
|
||||
* @param viewAttr
|
||||
* @param id
|
||||
* @param groupId
|
||||
* @return
|
||||
*/
|
||||
List<SearchConditionItem> getExtForm(User user, String extendType, String tableName, int viewAttr, long id, String groupId);
|
||||
|
||||
/**
|
||||
* 组装明细表表单
|
||||
*
|
||||
* @param user
|
||||
* @param extendType
|
||||
* @param tableName
|
||||
* @param id
|
||||
* @param viewAttr
|
||||
* @param showLabel
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getExtendTables(User user, String extendType, String tableName, long id, int viewAttr, boolean showLabel);
|
||||
|
||||
/**
|
||||
* 拓展页面分组
|
||||
*
|
||||
* @param extendType
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
List<TopTab> getTabInfo(String extendType, String tableName);
|
||||
|
||||
|
||||
/**
|
||||
* 更新主表拓展表
|
||||
*
|
||||
* @param user
|
||||
* @param extendType
|
||||
* @param tableName
|
||||
* @param params
|
||||
* @param groupId
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
int updateExtForm(User user, String extendType, String tableName, Map<String, Object> params, String groupId, Long id);
|
||||
|
||||
/**
|
||||
* 更新明细表
|
||||
*
|
||||
* @param user
|
||||
* @param extendType
|
||||
* @param tableName
|
||||
* @param params
|
||||
* @param id
|
||||
*/
|
||||
void updateExtDT(User user, String extendType, String tableName, Map<String, Object> params, Long id);
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
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 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, compExtMap.get(extendInfoPO.getFieldName()));
|
||||
item.setFieldcol(16);
|
||||
if (null != item && 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");
|
||||
|
||||
String fields = entry.getValue().stream().map(ExtendInfoPO::getFieldName).collect(Collectors.joining(","));
|
||||
tabinfoMap.put("datas", getExtDTMapper().listCompExtDT(tableName, id, fields));
|
||||
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<String> dtFields = dtInfoPOList.stream().map(ExtendInfoPO::getFieldName).collect(Collectors.toList());
|
||||
|
||||
List<Map<String, Object>> insertList = new ArrayList<>();
|
||||
// 删除明细表数据
|
||||
getExtDTMapper().deleteByMainID(tableName, id);
|
||||
// 处理明细表数据
|
||||
int rowNum = Util.getIntValue((String) params.get("rownum"));
|
||||
for (int i = 0; i < rowNum; i++) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (String dtField : dtFields) {
|
||||
map.put(dtField, params.get(dtField + "_" + 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());
|
||||
insertList.add(map);
|
||||
}
|
||||
// 更新拓展表数据
|
||||
for (Map<String, Object> map : insertList) {
|
||||
getExtDTMapper().insertCompExtDT(tableName, map);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue