|
@@ -0,0 +1,379 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.manager.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.manager.dto.SignConfigDTO;
|
|
|
+import org.springblade.manager.entity.SignConfig;
|
|
|
+import org.springblade.manager.entity.SignConfigRelation;
|
|
|
+import org.springblade.manager.entity.TableInfo;
|
|
|
+import org.springblade.manager.entity.WbsFormElement;
|
|
|
+import org.springblade.manager.mapper.SignConfigMapper;
|
|
|
+import org.springblade.manager.mapper.WbsFormElementMapper;
|
|
|
+import org.springblade.manager.service.ISignConfigRelationService;
|
|
|
+import org.springblade.manager.service.ISignConfigService;
|
|
|
+import org.springblade.manager.service.ITableInfoService;
|
|
|
+import org.springblade.manager.utils.WbsElementUtil;
|
|
|
+import org.springblade.manager.vo.SignConfigVO;
|
|
|
+import org.springblade.manager.vo.TextdictInfoVO;
|
|
|
+import org.springblade.manager.vo.WbsFormElementVO3;
|
|
|
+import org.springblade.manager.wrapper.SignConfigWrapper;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springblade.system.vo.RoleVO;
|
|
|
+import org.springblade.system.vo.RoleVO2;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.support.TransactionTemplate;
|
|
|
+
|
|
|
+import javax.validation.constraints.NotEmpty;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 电签配置 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2025-05-27
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class SignConfigServiceImpl extends BaseServiceImpl<SignConfigMapper, SignConfig> implements ISignConfigService {
|
|
|
+
|
|
|
+ private final ITableInfoService tableInfoService;
|
|
|
+
|
|
|
+ private final WbsFormElementMapper wbsFormElementMapper;
|
|
|
+
|
|
|
+ private final TransactionTemplate transactionTemplate;
|
|
|
+
|
|
|
+ private final ISignConfigRelationService signConfigRelationService;
|
|
|
+
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RoleVO2> getRoleList(Integer relationType, String roleName) {
|
|
|
+ return this.baseMapper.getRoleList(relationType, roleName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SignConfigRelation> getSignConfigRelationListByConfId(Long confId, Integer type) {
|
|
|
+ return this.baseMapper.getSignConfigRelationListByConfId(confId, type);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean addOrEdit(List<SignConfigDTO> signConfigDTOs) {
|
|
|
+ signConfigDTOs.forEach(signConfigDTO -> {
|
|
|
+ SignConfig config = new SignConfig();
|
|
|
+ BeanUtil.copyProperties(signConfigDTO, config);
|
|
|
+ if (signConfigDTO.getElementId() == null) {
|
|
|
+ if (signConfigDTO.getEId() == null) {
|
|
|
+ throw new ServiceException("请选择元素");
|
|
|
+ }
|
|
|
+ signConfigDTO.setElementId(signConfigDTO.getEId() + "");
|
|
|
+ }
|
|
|
+ WbsFormElement element = wbsFormElementMapper.selectById(signConfigDTO.getElementId());
|
|
|
+ if (element == null) {
|
|
|
+ throw new ServiceException("未查找到该元素,请重新选择");
|
|
|
+ }
|
|
|
+ config.setEId(element.getId());
|
|
|
+ config.setTenantId(AuthUtil.getTenantId());
|
|
|
+ config.setEKey(element.getEKey());
|
|
|
+ config.setElementType(element.getEType());
|
|
|
+ config.setEName(element.getEName());
|
|
|
+ List<String> roleIds = signConfigDTO.getRoleIds();
|
|
|
+ List<SignConfigRelation> signConfigRelationsByRoles = new ArrayList<>();
|
|
|
+ List<SignConfigRelation> signConfigRelationsByTables = new ArrayList<>();
|
|
|
+ if (roleIds != null && !roleIds.isEmpty()) {
|
|
|
+ R<List<RoleVO>> roleResult = sysClient.search();
|
|
|
+ if (!roleResult.isSuccess() || roleResult.getData() == null || roleResult.getData().isEmpty()) {
|
|
|
+ throw new ServiceException("获取岗位信息失败");
|
|
|
+ }
|
|
|
+ List<RoleVO> data = roleResult.getData();
|
|
|
+ Map<String, RoleVO> roleVOMap = new HashMap<>();
|
|
|
+ //先处理管理员
|
|
|
+ for (RoleVO vos : data) {
|
|
|
+ if (vos.getRoleName().contains("施工方") || vos.getRoleName().contains("监理方") || vos.getRoleName().contains("业主方")) {
|
|
|
+ List<RoleVO> children = vos.getChildren();
|
|
|
+ roleVOMap.put(vos.getId() + "", vos);
|
|
|
+ if (children != null && !children.isEmpty()) {
|
|
|
+ children.forEach(child -> roleVOMap.put(child.getId() + "", child));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String roleId : roleIds) {
|
|
|
+ RoleVO roleVO = roleVOMap.get(roleId);
|
|
|
+ if (roleVO != null) {
|
|
|
+ SignConfigRelation signConfigRelation = new SignConfigRelation();
|
|
|
+ signConfigRelation.setRelationId(Long.valueOf(roleId));
|
|
|
+ signConfigRelation.setType(1);
|
|
|
+ signConfigRelation.setRelationName(roleVO.getRoleName());
|
|
|
+ RoleVO parent = roleVOMap.get(roleVO.getParentId() + "");
|
|
|
+ if (parent != null) {
|
|
|
+ if (parent.getRoleName().contains("施工方")) {
|
|
|
+ signConfigRelation.setRelationType(1);
|
|
|
+ }
|
|
|
+ if (parent.getRoleName().contains("监理方")) {
|
|
|
+ signConfigRelation.setRelationType(2);
|
|
|
+ }
|
|
|
+ if (parent.getRoleName().contains("业主方")) {
|
|
|
+ signConfigRelation.setRelationType(3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ signConfigRelationsByRoles.add(signConfigRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> tableIds = signConfigDTO.getTableIds();
|
|
|
+ if (tableIds != null && !tableIds.isEmpty()) {
|
|
|
+ List<TableInfo> tableInfos = tableInfoService.list(Wrappers.<TableInfo>lambdaQuery().select(TableInfo::getTabChName, TableInfo::getId, TableInfo::getTabType).in(TableInfo::getId, tableIds));
|
|
|
+ if (tableInfos == null || tableInfos.isEmpty()) {
|
|
|
+ throw new ServiceException("获取元素表信息失败");
|
|
|
+ }
|
|
|
+ Map<String, TableInfo> tableMap = tableInfos.stream().collect(Collectors.toMap(tableInfo -> tableInfo.getId() + "", tab -> tab, (v1, v2) -> v1));
|
|
|
+ for (String tableId : tableIds) {
|
|
|
+ TableInfo tableInfo = tableMap.get(tableId);
|
|
|
+ if (tableInfo != null) {
|
|
|
+ SignConfigRelation signConfigRelation = new SignConfigRelation();
|
|
|
+ signConfigRelation.setRelationId(Long.valueOf(tableId));
|
|
|
+ signConfigRelation.setType(0);
|
|
|
+ signConfigRelation.setRelationName(tableInfo.getTabChName());
|
|
|
+ signConfigRelation.setRelationType(tableInfo.getTabType());
|
|
|
+ signConfigRelationsByTables.add(signConfigRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ config.setTableType(1);
|
|
|
+ } else {
|
|
|
+ config.setTableType(0);
|
|
|
+ }
|
|
|
+ transactionTemplate.execute(transactionStatus -> {
|
|
|
+ if (config.getId() != null) {
|
|
|
+ this.updateById(config);
|
|
|
+ if (!signConfigRelationsByTables.isEmpty()) {
|
|
|
+ signConfigRelationService.remove(Wrappers.<SignConfigRelation>lambdaQuery().eq(SignConfigRelation::getConfId, config.getId()).eq(SignConfigRelation::getType, 0));
|
|
|
+ }
|
|
|
+ if (!signConfigRelationsByRoles.isEmpty()) {
|
|
|
+ signConfigRelationService.remove(Wrappers.<SignConfigRelation>lambdaQuery().eq(SignConfigRelation::getConfId, config.getId()).eq(SignConfigRelation::getType, 1));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.save(config);
|
|
|
+ }
|
|
|
+ if (!signConfigRelationsByRoles.isEmpty()) {
|
|
|
+ signConfigRelationsByRoles.forEach(signConfigRelation -> signConfigRelation.setConfId(config.getId()));
|
|
|
+ this.signConfigRelationService.saveBatch(signConfigRelationsByRoles);
|
|
|
+ }
|
|
|
+ if (!signConfigRelationsByTables.isEmpty()) {
|
|
|
+ signConfigRelationsByTables.forEach(signConfigRelation -> signConfigRelation.setConfId(config.getId()));
|
|
|
+ this.signConfigRelationService.saveBatch(signConfigRelationsByTables);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<WbsFormElementVO3> elementList() {
|
|
|
+ List<WbsFormElement> list = wbsFormElementMapper.selectList(Wrappers.<WbsFormElement>lambdaQuery().select(WbsFormElement::getEName, WbsFormElement::getId, WbsFormElement::getEType)
|
|
|
+ .eq(WbsFormElement::getEType, WbsElementUtil.getElementType("签名")).groupBy(WbsFormElement::getEName));
|
|
|
+ List<WbsFormElementVO3> result = list.stream().map(element -> {
|
|
|
+ WbsFormElementVO3 vo = new WbsFormElementVO3();
|
|
|
+ vo.setId(element.getId());
|
|
|
+ vo.setEName(element.getEName());
|
|
|
+ vo.setEType(element.getEType());
|
|
|
+ vo.setETypeName(WbsElementUtil.getElementTypeName(element.getEType()));
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<SignConfigVO> selectPageByRoleId(IPage<SignConfig> page, Long roleId, String keyword) {
|
|
|
+ if (roleId == null && (keyword == null || keyword.trim().isEmpty())) {
|
|
|
+ page = this.page(page);
|
|
|
+ } else {
|
|
|
+ List<SignConfig> signConfigs = baseMapper.selectPageByRoleId(page, roleId, keyword);
|
|
|
+ page.setRecords(signConfigs);
|
|
|
+ }
|
|
|
+ IPage<SignConfigVO> pageVO = SignConfigWrapper.build().pageVO(page);
|
|
|
+ List<SignConfigVO> records = pageVO.getRecords();
|
|
|
+ List<Long> ids = records.stream().map(SignConfigVO::getId).collect(Collectors.toList());
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ List<SignConfigRelation> signConfigRelations = signConfigRelationService.list(Wrappers.<SignConfigRelation>lambdaQuery().select(SignConfigRelation::getConfId, SignConfigRelation::getRelationId, SignConfigRelation::getType)
|
|
|
+ .in(SignConfigRelation::getConfId, ids).eq(SignConfigRelation::getIsDeleted, 0));
|
|
|
+ Map<Long, Map<Integer, List<SignConfigRelation>>> map = signConfigRelations.stream().collect(Collectors.groupingBy(SignConfigRelation::getConfId, Collectors.groupingBy(SignConfigRelation::getType)));
|
|
|
+ records.forEach(record -> {
|
|
|
+ Map<Integer, List<SignConfigRelation>> listMap = map.get(record.getId());
|
|
|
+ if (listMap != null) {
|
|
|
+ List<SignConfigRelation> list = listMap.get(1);
|
|
|
+ if (list != null) {
|
|
|
+ record.setRoleIds(list.stream().map(SignConfigRelation::getRelationId).map(String::valueOf).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ list = listMap.get(0);
|
|
|
+ if (list != null) {
|
|
|
+ record.setTableIds(list.stream().map(SignConfigRelation::getRelationId).map(String::valueOf).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return pageVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RoleVO> queryAllRoleList(Integer type, String roleName) {
|
|
|
+ //获取当前系统配置的角色划分
|
|
|
+ R<List<RoleVO>> result = this.sysClient.search();
|
|
|
+ if (!result.isSuccess() || result.getData() == null || result.getData().isEmpty()) {
|
|
|
+ throw new ServiceException("获取岗位信息失败");
|
|
|
+ }
|
|
|
+ List<RoleVO> roleVOS = result.getData();
|
|
|
+ List<RoleVO> roles = new ArrayList<>();
|
|
|
+ //先处理管理员
|
|
|
+ for (RoleVO vos : roleVOS) {
|
|
|
+ if (vos.getRoleName().contains("施工方") || vos.getRoleName().contains("监理方") || vos.getRoleName().contains("业主方")) {
|
|
|
+ if (type != null ) {
|
|
|
+ if (type == 1 && vos.getRoleName().contains("施工方")) {
|
|
|
+ roles = vos.getChildren();
|
|
|
+ } else if (type == 2 && vos.getRoleName().contains("监理方")) {
|
|
|
+ roles = vos.getChildren();
|
|
|
+ } else if (type == 3 && vos.getRoleName().contains("业主方")) {
|
|
|
+ roles = vos.getChildren();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ roles.addAll(vos.getChildren());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (roleName != null && !roleName.isEmpty()) {
|
|
|
+ if (roles != null && !roles.isEmpty()) {
|
|
|
+ List<RoleVO> temp = new ArrayList<>();
|
|
|
+ for (RoleVO role : roles) {
|
|
|
+ if (role.getRoleName().contains(roleName)) {
|
|
|
+ temp.add(role);
|
|
|
+ List<RoleVO> children = role.getChildren();
|
|
|
+ if (children != null && !children.isEmpty()) {
|
|
|
+ List<RoleVO> temp1 = new ArrayList<>();
|
|
|
+ for (RoleVO child2 : children) {
|
|
|
+ if (child2.getRoleName().contains(roleName)) {
|
|
|
+ temp1.add(child2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ role.setChildren(temp1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return temp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return roles;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TableInfo> tableList(Integer tableType, String name) {
|
|
|
+ List<TableInfo> tableInfos = this.tableInfoService.list(Wrappers.<TableInfo>lambdaQuery().eq(tableType != null, TableInfo::getTabType, tableType).like(name != null && !name.isEmpty(), TableInfo::getTabChName, name));
|
|
|
+ tableInfos.sort(Comparator.comparingInt(TableInfo::getTabType));
|
|
|
+ return tableInfos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TextdictInfoVO> hasSignConfig(String initTableName, List<String> keyNames, TextdictInfoVO vo) {
|
|
|
+ List<TextdictInfoVO> textdictInfoVOS = new ArrayList<>();
|
|
|
+ if (keyNames == null || keyNames.isEmpty()) {
|
|
|
+ return textdictInfoVOS;
|
|
|
+ }
|
|
|
+ Map<String, String> keyMap = keyNames.stream().collect(Collectors.toMap(key -> key.split("__")[0], key -> key, (key1, key2) -> key1));
|
|
|
+ List<TableInfo> tableInfos = this.tableInfoService.list(Wrappers.<TableInfo>lambdaQuery().select(TableInfo::getId).eq(TableInfo::getTabEnName, initTableName));
|
|
|
+ if (tableInfos == null || tableInfos.isEmpty()) {
|
|
|
+ return textdictInfoVOS;
|
|
|
+ }
|
|
|
+ List<WbsFormElement> list = this.wbsFormElementMapper.selectList(Wrappers.<WbsFormElement>lambdaQuery().select(WbsFormElement::getEName, WbsFormElement::getEKey)
|
|
|
+ .eq(WbsFormElement::getFId, tableInfos.get(0)).in(WbsFormElement::getEKey, keyMap.keySet()));
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return textdictInfoVOS;
|
|
|
+ }
|
|
|
+ Set<String> names = list.stream().map(WbsFormElement::getEName).collect(Collectors.toSet());
|
|
|
+ List<SignConfigVO> signConfigs = this.baseMapper.getConfigByENames(names);
|
|
|
+ if (signConfigs == null || signConfigs.isEmpty()) {
|
|
|
+ return textdictInfoVOS;
|
|
|
+ }
|
|
|
+ Map<String, List<SignConfigVO>> map = signConfigs.stream().collect(Collectors.groupingBy(SignConfigVO::getEName));
|
|
|
+ Map<String, String> keyNameMap = list.stream().collect(Collectors.toMap(WbsFormElement::getEKey, WbsFormElement::getEName));
|
|
|
+ keyMap.forEach((key, value) -> {
|
|
|
+ String colName = keyNameMap.get(key);
|
|
|
+ if (colName == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<SignConfigVO> signConfigVOS = map.get(colName);
|
|
|
+ if (signConfigVOS == null || signConfigVOS.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Long> roleIds = new ArrayList<>();
|
|
|
+ List<String> roleNames = new ArrayList<>();
|
|
|
+ signConfigVOS.forEach(signConfigVO -> {
|
|
|
+ List<SignConfigRelation> relations = signConfigVO.getRelations();
|
|
|
+ if (relations != null && !relations.isEmpty()) {
|
|
|
+ Map<Integer, List<SignConfigRelation>> collect = relations.stream().collect(Collectors.groupingBy(SignConfigRelation::getType));
|
|
|
+ // 部分表,判断tableInfos是否在其中
|
|
|
+ if (signConfigVO.getTableType() == 1) {
|
|
|
+ List<SignConfigRelation> tables = collect.get(0);
|
|
|
+ if (tables == null || tables.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<Long, SignConfigRelation> tableMap = tables.stream().collect(Collectors.toMap(SignConfigRelation::getRelationId, v -> v, (v1, v2) -> v1));
|
|
|
+ SignConfigRelation relation = tableMap.get(tableInfos.get(0).getId());
|
|
|
+ if (relation == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<SignConfigRelation> roles = collect.get(1);
|
|
|
+ if (roles != null && !roles.isEmpty()) {
|
|
|
+ roles.forEach(role -> {
|
|
|
+ roleIds.add(role.getRelationId());
|
|
|
+ roleNames.add(role.getRelationName());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (!roleIds.isEmpty()) {
|
|
|
+ TextdictInfoVO textdictInfoVO = new TextdictInfoVO();
|
|
|
+ if (vo != null) {
|
|
|
+ BeanUtil.copy(vo, textdictInfoVO);
|
|
|
+ }
|
|
|
+ textdictInfoVO.setId(null);
|
|
|
+ textdictInfoVO.setColKey(value);
|
|
|
+ textdictInfoVO.setColName(colName);
|
|
|
+ textdictInfoVO.setIsSystem(1);
|
|
|
+ textdictInfoVO.setSigRoleId(StringUtil.join(roleIds, ","));
|
|
|
+ textdictInfoVO.setSigRoleName(StringUtil.join(roleNames, ","));
|
|
|
+ textdictInfoVOS.add(textdictInfoVO);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return textdictInfoVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean deleteLogic(@NotEmpty List<Long> ids) {
|
|
|
+ return super.deleteLogic(ids);
|
|
|
+ }
|
|
|
+}
|