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

210 lines
8.8 KiB
Java
Raw Normal View History

2022-06-14 09:36:47 +08:00
package com.engine.organization.service.impl;
2022-06-14 17:57:41 +08:00
import com.alibaba.fastjson.JSON;
2022-06-15 11:25:23 +08:00
import com.alibaba.fastjson.JSONArray;
2022-06-14 17:57:41 +08:00
import com.alibaba.fastjson.JSONObject;
2022-06-14 09:36:47 +08:00
import com.engine.core.impl.Service;
2022-06-15 18:03:01 +08:00
import com.engine.organization.entity.DeleteParam;
2022-06-14 16:10:26 +08:00
import com.engine.organization.entity.extend.bo.ExtendGroupBO;
2022-06-15 11:25:23 +08:00
import com.engine.organization.entity.extend.param.ExtendTitleSaveParam;
2022-06-14 16:10:26 +08:00
import com.engine.organization.entity.extend.po.ExtendGroupPO;
2022-06-14 17:57:41 +08:00
import com.engine.organization.entity.extend.po.ExtendTitlePO;
2022-06-15 11:36:48 +08:00
import com.engine.organization.entity.fieldset.param.FieldTypeTreeParam;
2022-06-14 16:10:26 +08:00
import com.engine.organization.entity.fieldset.vo.TypeTreeVO;
2022-06-15 17:17:34 +08:00
import com.engine.organization.enums.DeleteTypeEnum;
2022-06-14 16:10:26 +08:00
import com.engine.organization.enums.ModuleTypeEnum;
import com.engine.organization.mapper.extend.ExtendGroupMapper;
2022-06-14 17:57:41 +08:00
import com.engine.organization.mapper.extend.ExtendInfoMapper;
import com.engine.organization.mapper.extend.ExtendTitleMapper;
2022-06-14 09:36:47 +08:00
import com.engine.organization.service.FieldDefinedService;
2022-06-14 17:57:41 +08:00
import com.engine.organization.util.OrganizationAssert;
2022-06-14 15:29:22 +08:00
import com.engine.organization.util.db.MapperProxyFactory;
2022-06-15 11:25:23 +08:00
import org.apache.commons.collections.CollectionUtils;
2022-06-14 17:57:41 +08:00
import org.apache.commons.lang.StringUtils;
2022-06-15 11:25:23 +08:00
import weaver.general.Util;
2022-06-14 09:36:47 +08:00
2022-06-15 11:25:23 +08:00
import java.util.*;
import java.util.stream.Collectors;
2022-06-14 09:36:47 +08:00
/**
* @Author weaver_cl
2022-06-14 11:07:48 +08:00
* @Description:
2022-06-14 09:36:47 +08:00
* @Date 2022/6/13
* @Version V1.0
**/
public class FieldDefinedServiceImpl extends Service implements FieldDefinedService {
2022-06-15 11:36:48 +08:00
2022-06-15 18:03:01 +08:00
private ExtendGroupMapper getExtendGroupMapper() {
return MapperProxyFactory.getProxy(ExtendGroupMapper.class);
}
2022-06-14 15:29:22 +08:00
private ExtendTitleMapper getExtendTitleMapper() {
return MapperProxyFactory.getProxy(ExtendTitleMapper.class);
}
private ExtendInfoMapper getExtendInfoMapper() {
return MapperProxyFactory.getProxy(ExtendInfoMapper.class);
}
2022-06-14 09:36:47 +08:00
@Override
2022-06-14 16:10:26 +08:00
public List<TypeTreeVO> getTree(ModuleTypeEnum moduleTypeEnum) {
Integer extendType = moduleTypeEnum.getValue();
List<ExtendGroupPO> extendGroupPOS = MapperProxyFactory.getProxy(ExtendGroupMapper.class).listByType(extendType);
return ExtendGroupBO.buildTypeTree(extendGroupPOS);
2022-06-14 09:36:47 +08:00
}
2022-06-14 15:29:22 +08:00
@Override
public Map<String, Object> getTabInfo(String groupType) {
OrganizationAssert.notBlank(groupType, "分组信息有误,请确认");
Map<String, Object> datas = new HashMap<>();
Long groupId = Long.parseLong(groupType);
List<ExtendTitlePO> extendTitleList = getExtendTitleMapper().getTitlesByGroupID(groupId);
List<Map<String, Object>> tabs = new ArrayList<>();
int idx = 1;
for (ExtendTitlePO extendTitle : extendTitleList) {
Map<String, Object> tab = new HashMap<>();
tab.put("tabkey", idx++);
tab.put("title", extendTitle.getTitle());
tab.put("isShow", extendTitle.getIsShow());
tab.put("groupid", extendTitle.getGroupId());
tab.put("viewAttr", extendTitle.getGroupId() < 0 ? 1 : 2);
2022-06-15 18:03:01 +08:00
tab.put("editable", !(getExtendInfoMapper().countFieldsByGroupId(extendTitle.getId()) > 0));
2022-06-14 15:29:22 +08:00
tabs.add(tab);
}
datas.put("status", "1");
datas.put("tabs", tabs);
return datas;
}
@Override
public int saveFields(String data) {
if (StringUtils.isEmpty(data)) {
return 0;
}
JSONObject jsonObject = JSON.parseObject(data);
2022-06-15 18:03:01 +08:00
// extend_group主键
Long groupType = jsonObject.getLong("groupType");
ExtendGroupPO extendGroup = getExtendGroupMapper().getGroupById(groupType);
Integer extendType = extendGroup.getExtendType();
String tableName = ExtendGroupBO.getTableNameByGroupPO(extendGroup);
// 主表、主表拓展表为extend_title主键明细表为extend_group主键
Long extendGroupId = jsonObject.getLong("groupId");
JSONArray records = (JSONArray) jsonObject.get("records");
for (int i = 0; i < records.size(); i++) {
}
return 0;
}
2022-06-15 11:25:23 +08:00
@Override
public Map<String, Object> saveGroup(ExtendTitleSaveParam param) {
Map<String, Object> datas = new HashMap<>();
Long groupType = param.getGroupType();
Set<Long> lsDelGroupId = new HashSet<>();
List<ExtendTitlePO> extendTitleList = getExtendTitleMapper().getTitlesByGroupID(groupType);
extendTitleList.forEach(item -> lsDelGroupId.add(item.getId()));
String data = param.getData();
JSONObject jsonObject = JSON.parseObject(data);
Set<Long> ids = new HashSet<>();
JSONArray records = (JSONArray) jsonObject.get("records");
for (int i = 0; i < records.size(); i++) {
ExtendTitlePO extendTitle = new ExtendTitlePO();
JSONObject object = (JSONObject) records.get(i);
extendTitle.setId(object.getLong("id"));
extendTitle.setGroupId(groupType);
extendTitle.setIsShow(object.getString("isShow"));
extendTitle.setTitle(object.getString("groupName"));
extendTitle.setShowOrder(i + 1);
if (null != extendTitle.getId()) {
lsDelGroupId.remove(extendTitle.getId());
}
if (null == extendTitle.getId()) {
2022-06-15 17:56:29 +08:00
extendTitle.setCreator((long)user.getUID());
2022-06-15 11:25:23 +08:00
extendTitle.setCreateTime(new Date());
extendTitle.setDeleteType(0);
getExtendTitleMapper().insertIgnoreNull(extendTitle);
} else {
extendTitle.setUpdateTime(new Date());
getExtendTitleMapper().updateExtendTitle(extendTitle);
}
ids.add(extendTitle.getId());
}
if (CollectionUtils.isNotEmpty(lsDelGroupId)) {
getExtendTitleMapper().deleteExtendTitleByIds(lsDelGroupId);
}
datas.put("groupid", StringUtils.join(ids, ","));
datas.put("status", "1");
return datas;
}
@Override
public Map<String, Object> saveTitle(ExtendTitleSaveParam param) {
Map<String, Object> datas = new HashMap<>();
List<ExtendTitlePO> titlesByGroupID = getExtendTitleMapper().getTitlesByGroupID(param.getGroupType());
ExtendTitlePO extendTitlePO = titlesByGroupID.stream().max(Comparator.comparing(ExtendTitlePO::getShowOrder)).get();
Set<Long> ids = titlesByGroupID.stream().map(ExtendTitlePO::getId).collect(Collectors.toSet());
ExtendTitlePO extendTitle = new ExtendTitlePO();
extendTitle.setGroupId(param.getGroupType());
extendTitle.setIsShow(param.getIsShow());
extendTitle.setTitle(param.getGroupName());
extendTitle.setShowOrder(null == extendTitlePO ? 0 : extendTitlePO.getShowOrder() + 1);
2022-06-15 17:56:29 +08:00
extendTitle.setCreator((long)user.getUID());
2022-06-15 11:25:23 +08:00
extendTitle.setCreateTime(new Date());
extendTitle.setDeleteType(0);
getExtendTitleMapper().insertIgnoreNull(extendTitle);
ids.add(extendTitle.getId());
datas.put("groupid", StringUtils.join(ids, ","));
datas.put("status", "1");
return datas;
2022-06-14 15:29:22 +08:00
}
2022-06-15 11:36:48 +08:00
2022-06-15 17:17:34 +08:00
public void changeTree(ModuleTypeEnum moduleTypeEnum, FieldTypeTreeParam fieldTypeTreeParam) {
if (fieldTypeTreeParam.getId() == null) {
2022-06-15 17:56:29 +08:00
ExtendGroupPO extendGroupPO = buildExtendGroupType(moduleTypeEnum, fieldTypeTreeParam);
2022-06-15 17:17:34 +08:00
MapperProxyFactory.getProxy(ExtendGroupMapper.class).insertIgnoreNull(extendGroupPO);
2022-06-15 17:56:29 +08:00
//默认新增title
ExtendTitlePO extendTitlePO = buildExtendTitleType(extendGroupPO);
MapperProxyFactory.getProxy(ExtendTitleMapper.class).insertIgnoreNull(extendTitlePO);
2022-06-15 17:17:34 +08:00
}else {
MapperProxyFactory.getProxy(ExtendGroupMapper.class).update(fieldTypeTreeParam.getId(),fieldTypeTreeParam.getName());
}
2022-06-15 11:36:48 +08:00
}
2022-06-15 17:56:29 +08:00
private ExtendTitlePO buildExtendTitleType(ExtendGroupPO extendGroupPO) {
return ExtendTitlePO.builder()
.groupId(extendGroupPO.getId())
.title(extendGroupPO.getGroupName())
.showOrder(1)
.isShow("1")
.creator((long) user.getUID())
.deleteType(DeleteTypeEnum.NOT_DELETED.getValue())
.createTime(new Date())
.updateTime(new Date()).build();
2022-06-15 18:03:01 +08:00
}
2022-06-15 11:36:48 +08:00
2022-06-15 17:56:29 +08:00
private ExtendGroupPO buildExtendGroupType(ModuleTypeEnum moduleTypeEnum, FieldTypeTreeParam fieldTypeTreeParam) {
2022-06-15 17:17:34 +08:00
return ExtendGroupPO.builder()
.extendType(moduleTypeEnum.getValue())
.groupName(fieldTypeTreeParam.getName())
.creator((long) user.getUID())
.deleteType(DeleteTypeEnum.NOT_DELETED.getValue())
.createTime(new Date())
.updateTime(new Date())
.pid(fieldTypeTreeParam.getParentid())
.isShow(fieldTypeTreeParam.getIsShow() == null ? "1" : fieldTypeTreeParam.getIsShow()).build();
2022-06-15 18:03:01 +08:00
}
2022-06-15 11:36:48 +08:00
2022-06-14 09:36:47 +08:00
}