package com.qianwen.smartman.modules.smis.service.impl; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; import org.apache.commons.compress.utils.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import com.alibaba.excel.write.merge.AbstractMergeStrategy; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.qianwen.core.excel.util.ExcelUtil; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.support.Condition; import com.qianwen.core.oss.model.BladeFile; import com.qianwen.core.secure.utils.AuthUtil; import com.qianwen.core.tool.constant.BladeConstant; import com.qianwen.core.tool.node.ForestNodeMerger; import com.qianwen.core.tool.utils.CollectionUtil; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.common.constant.CommonConstant; import com.qianwen.smartman.common.constant.CommonGroupConstant; import com.qianwen.smartman.common.constant.ExcelConstant; import com.qianwen.smartman.common.enums.CommonGroupTypeEnum; import com.qianwen.smartman.common.utils.Lambda; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.smartman.common.utils.ValidatorUtils; import com.qianwen.smartman.modules.smis.convert.CommonGroupConvert; import com.qianwen.smartman.modules.smis.entity.CommonGroup; import com.qianwen.smartman.modules.smis.entity.CommonGroupOfItem; import com.qianwen.smartman.modules.smis.entity.CraftVersionLine; import com.qianwen.smartman.modules.smis.entity.Workstation; import com.qianwen.smartman.modules.smis.excel.CommonGroupImport; import com.qianwen.smartman.modules.smis.mapper.CommonGroupMapper; import com.qianwen.smartman.modules.smis.mapper.WorkstationMapper; import com.qianwen.smartman.modules.smis.service.ICommonGroupOfItemService; import com.qianwen.smartman.modules.smis.service.ICommonGroupService; import com.qianwen.smartman.modules.smis.service.ICraftVersionLineService; import com.qianwen.smartman.modules.smis.service.IWorkstationService; import com.qianwen.smartman.modules.smis.utils.ThrowFun; import com.qianwen.smartman.modules.smis.vo.CommonGroupFtpVO; import com.qianwen.smartman.modules.smis.vo.CommonGroupTypeVO; import com.qianwen.smartman.modules.smis.vo.CommonGroupVO; import com.qianwen.smartman.modules.smis.vo.JimuTreeVO; import com.qianwen.smartman.modules.smis.vo.MdcWorkStationGroupVO; import com.qianwen.smartman.modules.smis.vo.WorkstationGroupVO; import com.qianwen.smartman.modules.smis.vo.WorkstationInGroupVO; import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder; import com.qianwen.smartman.modules.system.entity.Dict; import com.qianwen.smartman.modules.system.entity.ParamBiz; import com.qianwen.smartman.modules.system.service.IDictService; import com.qianwen.smartman.modules.system.service.IParamBizService; @Service public class CommonGroupServiceImpl extends ServiceImpl implements ICommonGroupService { private static final String PARENT_ID = "parentId"; private static final String ROOT_NODE_CONFIGURE_ERROR = "The root node is not configured or configured incorrectly"; @Autowired @Lazy private IWorkstationService workstationService; @Autowired @Lazy private ICommonGroupOfItemService commonGroupOfItemService; @Autowired private OssBuilder ossBuilder; @Autowired private IParamBizService paramService; @Autowired private IDictService dictService; @Autowired private ICraftVersionLineService lineService; @Autowired private WorkstationMapper workstationMapper; @Override public Boolean changeStatus(List ids, Integer status) { return update(Wrappers.lambdaUpdate() .set(CommonGroup::getStatus, status) .in(CommonGroup::getId, ids)); } @Override public List getAllSubGroup(Long id, String groupType, Integer groupCategory) { return this.baseMapper.getAllSubGroup(id, groupType, groupCategory); } @Override public List lazyList(Long parentId, String groupType, Integer groupCategory, Map param) { if (Func.isEmpty(param.get(PARENT_ID)) && param.size() == 1) { parentId = BladeConstant.TOP_PARENT_ID; } if (Func.isEmpty(param.get(PARENT_ID)) && param.size() > 1 && Func.toLong(parentId) == BladeConstant.TOP_PARENT_ID.longValue()) { parentId = null; } return this.baseMapper.lazyList(AuthUtil.getTenantId(), parentId, groupType, groupCategory, param); } @Override public List tree(String tenantId, String groupType, Integer groupCategory) { return ForestNodeMerger.merge(this.baseMapper.tree(tenantId, groupType, groupCategory)); } @Override public List lazyTree(String tenantId, Long parentId) { if (AuthUtil.isAdministrator()) { tenantId = ""; } return ForestNodeMerger.merge(this.baseMapper.lazyTree(tenantId, parentId)); } @Override public String getGroupIds(String tenantId, String groupNames, String groupType, Integer groupCategory) { List commonList = this.baseMapper.selectList( Wrappers.query().lambda() .eq(CommonGroup::getTenantId, tenantId) .in(CommonGroup::getName, Func.toStrList(groupNames))); if (commonList != null && commonList.size() > 0) { return (String) commonList.stream().map(group -> { return Func.toStr(group.getId()); }).distinct().collect(Collectors.joining(",")); } return null; } @Override public String getGroupIdsByFuzzy(String tenantId, String groupNames, String groupType, Integer groupCategory) { LambdaQueryWrapper queryWrapper = Wrappers.query().lambda().eq(CommonGroup::getTenantId, tenantId).eq(CommonGroup::getGroupType, groupType).eq(CommonGroup::getGroupCategory, groupCategory); queryWrapper.and(wrapper -> { List names = Func.toStrList(groupNames); names.forEach(name -> { wrapper.like(CommonGroup::getName, name).or(); }); }); /* Wrapper wrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getTenantId(); }, tenantId)).eq((v0) -> { return v0.getGroupType(); }, groupType)).eq((v0) -> { return v0.getGroupCategory(); }, groupCategory); wrapper.and(wrapper2 -> { List names = Func.toStrList(groupNames); names.forEach(name -> { LambdaQueryWrapper lambdaQueryWrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) wrapper2.like((v0) -> { return v0.getName(); }, name)).or(); }); });*/ List groupList = this.baseMapper.selectList(queryWrapper); if (groupList != null && groupList.size() > 0) { return groupList.stream().map(group -> Func.toStr(group.getId())).distinct().collect(Collectors.joining(",")); } return null; } @Override public List getGroupNames(String groupIds) { return this.baseMapper.getGroupNames(Func.toLongArray(groupIds)); } @Override public boolean removeGroup(String ids) { Long cnt = this.baseMapper.selectCount(Wrappers.query().lambda().in(CommonGroup::getParentId, Func.toLongList(ids))); /* Long cnt = this.baseMapper.selectCount((Wrapper) Wrappers.query().lambda().in((v0) -> { return v0.getParentId(); }, Func.toLongList(ids)));*/ if (cnt.longValue() > 0) { throw new ServiceException(MessageUtils.message("cps.group.delete.child.node", new Object[0])); } return removeByIds(Func.toLongList(ids)); } @Override public CommonGroup insert(CommonGroup group) { if (Func.isEmpty(group.getParentId())) { group.setTenantId(AuthUtil.getTenantId()); group.setParentId(getRootNodeId(group.getGroupType(), group.getGroupCategory())); } String code = getNextChildCode(group.getParentId(), group.getGroupType(), group.getGroupCategory()); group.setCode(code); if (Func.isEmpty(group.getSort())) { group.setSort(Integer.valueOf(Integer.parseInt(code.substring(code.length() - 5)))); } group.setIsDeleted(0); if (CommonGroupTypeEnum.MACHINE.getName().equals(group.getGroupType())) { group.setExtendId(UUID.randomUUID().toString()); } validateGroup(group); validateUnableGroup(group); saveOrUpdate(group); return group; } @Override public CommonGroup update(CommonGroup group) { validateGroup(group); saveOrUpdate(group); return group; } @Override public void move(Long id, Long parentId, String groupType, Integer groupCategory) { CommonGroup group = (CommonGroup) getById(id); if (group.getParentId().equals(id)) { return; } String oldCode = group.getCode(); List children = getGroupChildren(id, true, groupType, groupCategory); group.setCode(getNextChildCode(parentId, groupType, groupCategory)); group.setParentId(parentId); validateGroup(group); children.forEach(g -> { g.setCode(CommonGroup.appendCode(group.getCode(), CommonGroup.getRelativeCode(g.getCode(), oldCode))); update(g); }); update(group); } @Override public List getGroupChildren(Long parentId, boolean recursive, String groupType, Integer groupCategory) { if (!recursive) { return this.baseMapper.selectList(Wrappers.query().lambda() .eq(CommonGroup::getParentId, parentId) .eq(CommonGroup::getGroupType, groupType) .eq(CommonGroup::getGroupCategory, groupCategory)); /* return this.baseMapper.selectList((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getParentId(); }, parentId)).eq((v0) -> { return v0.getGroupType(); }, groupType)).eq((v0) -> { return v0.getGroupCategory(); }, groupCategory));*/ } if (null == parentId) { return this.baseMapper.selectList( Wrappers.query().lambda() .eq(CommonGroup::getGroupType, groupType) .eq(CommonGroup::getGroupCategory, groupCategory)); /* return this.baseMapper.selectList((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getGroupType(); }, groupType)).eq((v0) -> { return v0.getGroupCategory(); }, groupCategory)); */ } String codeOrDefault = getCodeOrDefault(parentId); return this.baseMapper.selectList(Wrappers.query().lambda() .likeRight(CommonGroup::getCode, codeOrDefault) .ne(CommonGroup::getId, parentId)); /* return this.baseMapper.selectList((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().likeRight((v0) -> { return v0.getCode(); }, codeOrDefault)).ne((v0) -> { return v0.getId(); }, parentId));*/ } @Override public List search(String groupName, Long parentId, String groupType, Integer groupCategory) { LambdaQueryWrapper wrapper = Wrappers.query().lambda().eq(CommonGroup::getGroupType, groupType).eq(CommonGroup::getGroupCategory, groupCategory); /*Wrapper wrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getGroupType(); }, groupType)).eq((v0) -> { return v0.getGroupCategory(); }, groupCategory);*/ if (Func.isNotEmpty(groupName)) { wrapper.like((v0) -> { return v0.getName(); }, groupName); } if (Func.isNotEmpty(parentId) && parentId.longValue() > BladeConstant.TOP_PARENT_ID.longValue()) { wrapper.eq((v0) -> { return v0.getParentId(); }, parentId); } List groupList = this.baseMapper.selectList(wrapper); return CommonGroupConvert.INSTANCE.convert(groupList); } @Override public List getCommonGroupChildIds(String code, String groupType, Integer groupCategory) { List childList = getCommonGroupChildList(code, groupType, groupCategory, null); if (Func.isNotEmpty(childList)) { List groupIdList = childList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); return groupIdList; } return null; } private List getCommonGroupChildList(String code, String groupType, Integer groupCategory, Integer status) { return this.baseMapper.selectList(Wrappers.query().lambda().eq(CommonGroup::getGroupType, groupType) .eq(CommonGroup::getGroupCategory, groupCategory).eq(Func.isNotEmpty(status), CommonGroup::getStatus, status).likeRight(Func.isNotEmpty(code), CommonGroup::getCode, code)); } @Override public HashMap getCommonGroupNameMap(String groupType, Integer groupCategory) { return getCommonGroupMap(null, groupType, groupCategory, null); } @Override public HashMap getCommonGroupNameMap(String code, String groupType, Integer groupCategory) { return getCommonGroupMap(code, groupType, groupCategory, null); } @Override public HashMap getCommonGroupNameMap(String groupType, Integer groupCategory, Integer status) { return getCommonGroupMap(null, groupType, groupCategory, status); } @Override public HashMap getCommonGroupNameMap(String code, String groupType, Integer groupCategory, Integer status) { return getCommonGroupMap(code, groupType, groupCategory, status); } private HashMap getCommonGroupMap(String code, String groupType, Integer groupCategory, Integer status) { HashMap resultMap = new HashMap<>(16); List childList = getCommonGroupChildList(code, groupType, groupCategory, status); if (Func.isEmpty(childList)) { return resultMap; } Map> dataMap = childList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getParentId(); })); List commonGroups = dataMap.get(BladeConstant.TOP_PARENT_ID); if (Func.isEmpty(commonGroups)) { return resultMap; } if (commonGroups.size() > 1) { throw new IllegalArgumentException(ROOT_NODE_CONFIGURE_ERROR); } CommonGroup commonGroup = commonGroups.get(0); Long id = commonGroup.getId(); String parentName = commonGroup.getName(); if (Func.isNotEmpty(code)) { List codeList = new ArrayList<>(); String[] codes = code.split("-"); for (int i = 0; i < codes.length; i++) { codeList.add(code.substring(0, 5 * (i + 1))); } //CommonGroup::getCode List parentList = list( Wrappers.lambdaQuery().eq(CommonGroup::getGroupType, groupType) .eq(CommonGroup::getGroupCategory, groupCategory) .eq(Func.isNotEmpty(status), CommonGroup::getStatus, status) .in(CommonGroup::getCode, codeList)); if (Func.isNotEmpty(parentList)) { id = parentList.stream().filter(x -> x.getCode().equals(code)).map(CommonGroup::getId).findFirst().orElse(id); parentName = getParentName(codeList, parentList); } } buildCommonGroupNameMap(id, parentName, dataMap, resultMap); return resultMap; } @Override public CommonGroup getRootNode(String groupType, Integer groupCategory) { //CommonGroup::getParentId List commonGroupList = list(Wrappers.lambdaQuery().eq(CommonGroup::getGroupType, groupType) .eq(CommonGroup::getGroupCategory, groupCategory) .eq(CommonGroup::getParentId, BladeConstant.TOP_PARENT_ID)); if (Func.isEmpty(commonGroupList) || commonGroupList.size() > 1) { throw new IllegalArgumentException(ROOT_NODE_CONFIGURE_ERROR); } return commonGroupList.get(0); } @Override public Long getRootNodeId(String groupType, Integer groupCategory) { return getRootNode(groupType, groupCategory).getId(); } private String getParentName(List codeList, List parentList) { StringBuilder sb = new StringBuilder(); Map map = parentList.stream().filter(x -> { return !BladeConstant.TOP_PARENT_ID.equals(x.getParentId()); }).collect(Collectors.toMap((v0) -> { return v0.getCode(); }, (v0) -> { return v0.getName(); })); for (String code : codeList) { if (Func.isNotEmpty(map.get(code))) { sb.append(map.get(code)); } } return sb.toString(); } private void buildCommonGroupNameMap(Long parentId, String parentName, Map> dataMap, HashMap resultMap) { if (Func.isNotEmpty(parentName)) { resultMap.put(parentName, parentId); } List commonGroupList = dataMap.get(parentId); if (Func.isNotEmpty(commonGroupList)) { for (int i = 0; i < commonGroupList.size(); i++) { String prefix = Func.isEmpty(parentName) ? parentName : parentName + "-"; String name = prefix + commonGroupList.get(i).getName(); buildCommonGroupNameMap(commonGroupList.get(i).getId(), name, dataMap, resultMap); } } } @Override @Transactional(rollbackFor = {Exception.class}) public BladeFile importCommonGroup(List data, CommonGroupTypeVO commonGroupTypeVO) { if (Func.isEmpty(data)) { throw new ServiceException(MessageUtils.message("excel.import.data.can.not.be.null", new Object[0])); } if (data.size() > 200) { throw new ServiceException(MessageUtils.message("excel.import.size.failed", new Object[0])); } String rootName = getRootNode(commonGroupTypeVO.getGroupType(), commonGroupTypeVO.getGroupCategory()).getName(); Boolean flag = Boolean.TRUE; for (CommonGroupImport commonGroupImport : data) { importProcess(null, commonGroupImport.getName(), rootName, commonGroupTypeVO, commonGroupImport); if (Func.isNotEmpty(commonGroupImport.getFailReason())) { flag = Boolean.FALSE; } } if (!flag.booleanValue()) { MultipartFile multipartFile = ExcelUtil.exportFillTemplateToMultipartFile(ExcelConstant.DIRECTORY + "organizationFailTemplate" + ExcelConstant.SUFFIX, MessageUtils.message("excel.import.failed.report.name", new Object[0]) + ExcelConstant.SUFFIX, "部门信息表", data.stream().filter(x -> { return Func.isNotEmpty(x.getFailReason()); }).collect(Collectors.toList()), (Object) null, (AbstractMergeStrategy) null); BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile); return bladeFile; } return null; } @Override public List listWorkstationGroup(String groupType, String groupCategory, String groupTag) { List commonGroupList = list(Wrappers.lambdaQuery() .eq(Func.isNotBlank(groupType), CommonGroup::getGroupType, groupType) .eq(Func.isNotBlank(groupCategory), CommonGroup::getGroupCategory, groupCategory) .eq(Func.isNotBlank(groupTag), CommonGroup::getGroupTag, groupTag)); /* List commonGroupList = list(Wrappers.lambdaQuery().eq(Func.isNotBlank(groupType), (v0) -> { return v0.getGroupType(); }, groupType).eq(Func.isNotBlank(groupCategory), (v0) -> { return v0.getGroupCategory(); }, groupCategory).eq(Func.isNotBlank(groupTag), (v0) -> { return v0.getGroupTag(); }, groupTag));*/ List result = CommonGroupConvert.INSTANCE.convert1(commonGroupList); if (CollectionUtil.isNotEmpty(result)) { List codeList = result.stream().map((v0) -> { return v0.getCode(); }).distinct().collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(codeList)) { List groupList = list(Wrappers.lambdaQuery() .eq(Func.isNotBlank(groupType), CommonGroup::getGroupType, groupType) .eq(Func.isNotBlank(groupCategory), CommonGroup::getGroupCategory, groupCategory) .eq(Func.isNotBlank(groupTag),CommonGroup::getGroupTag, groupTag).in(CommonGroup::getCode, codeList)); Map map = groupList.stream().collect(Collectors.toMap(CommonGroup::getCode, CommonGroup::getName, (v1, v2) -> v1)); result.forEach(i -> { i.setPath(CommonGroup.appendName(i.getCode(), map)); }); } } return result; } @Override public List groupWorkstationListType(CommonGroupTypeVO commonGroupTypeVO) { List groupList = list(Wrappers.lambdaQuery() .eq(CommonGroup::getGroupType, commonGroupTypeVO.getGroupType()) .eq(CommonGroup::getGroupCategory, commonGroupTypeVO.getGroupCategory()) .orderByAsc(CommonGroup::getSort)); List groupIds = groupList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); List itemList = this.commonGroupOfItemService.list(Wrappers.lambdaQuery().in(Func.isNotEmpty(groupIds), CommonGroupOfItem::getGroupId, groupIds)); List workstations = this.workstationService.listMachine(commonGroupTypeVO.getStatus(), commonGroupTypeVO.getKeyword()); List list = groupList.stream().filter(o -> { return Func.isNotEmpty(o.getParentId()); }).map(o2 -> { return WorkstationInGroupVO.builder().id(o2.getId()).parentId(o2.getParentId()).title(o2.getName()).code("").isWorkstation(Boolean.FALSE).isGroup(Boolean.TRUE).groupTag(o2.getGroupTag()).build(); }).collect(Collectors.toList()); /* list.addAll( workstations.stream().flatMap(o1 -> { Long id = o1.getId(); return itemList.stream().filter(o22 -> { Integer distinguish = commonGroupTypeVO.getDistinguish(); boolean result = id.equals(o22.getItemId()); if (Func.isNotEmpty(distinguish)) { boolean equals = DncEnums.SupportCncRw.Support.getCode().equals(o1.getSupportCncRw()); return result && equals; ////false } return result; }).map(o23 -> { return WorkstationInGroupVO.builder().id(id).parentId(o23.getGroupId()).title(o1.getName()).code(o1.getCode()).isWorkstation(Boolean.TRUE).supportCncRw(o1.getSupportCncRw()).isGroup(Boolean.FALSE).avatar(o1.getAvatar()).ftpCatalogue(o1.getFtpCatalogue()).build(); }).distinct(); }).collect(Collectors.toList())); */ list.addAll( workstations.stream().flatMap(o1 -> { Long id = o1.getId(); return itemList.stream().filter(o22 -> { Integer distinguish = commonGroupTypeVO.getDistinguish(); boolean result = id.equals(o22.getItemId()); return result; }).map(o23 -> { return WorkstationInGroupVO.builder().id(id).parentId(o23.getGroupId()).title(o1.getName()).code(o1.getCode()).isWorkstation(Boolean.TRUE).isGroup(Boolean.FALSE).avatar(o1.getAvatar()).ftpCatalogue(o1.getFtpCatalogue()).build(); }).distinct(); }).collect(Collectors.toList())); return list; } @Override public List groupWorkstationListLazy(Long groupId) { //CommonGroup::getSort List commonGroupList = list(Wrappers.lambdaQuery().eq(CommonGroup::getParentId, groupId).orderByAsc(CommonGroup::getSort)); List collect = commonGroupList.stream().map(commonGroup -> { return WorkstationInGroupVO.builder().parentId(groupId).isWorkstation(false).isGroup(true).code(commonGroup.getCode()).title(commonGroup.getName()).groupTag(commonGroup.getGroupTag()).id(commonGroup.getId()).build(); }).collect(Collectors.toList()); //CommonGroupOfItem::getGroupType List commonGroupOfItemList = this.commonGroupOfItemService.list(Wrappers.lambdaQuery() .eq(CommonGroupOfItem::getGroupId, groupId).eq(CommonGroupOfItem::getGroupType, CommonGroupTypeEnum.WORKSTATION.getName())); Map workstationIdToGroupId = commonGroupOfItemList.stream().collect(Collectors.toMap(CommonGroupOfItem::getItemId, CommonGroupOfItem::getGroupId)); if (Func.isNotEmpty(commonGroupOfItemList)) { List workstationIds = commonGroupOfItemList.stream().map(CommonGroupOfItem::getItemId).collect(Collectors.toList()); /* List workstationIds = (List) commonGroupOfItemList.stream().map((v0) -> { return v0.getItemId(); }).collect(Collectors.toList());*/ List workstations = this.workstationService.listByIds(workstationIds).stream().filter(s -> { return CommonConstant.ENABLE.equals(s.getStatus()); }).filter((v0) -> { return Func.isNotEmpty(v0); }).collect(Collectors.toList()); List collect1 = workstations.stream().map(workstation -> { return WorkstationInGroupVO.builder().isWorkstation(true).isGroup(false).id(workstation.getId()).title(workstation.getName()).code(workstation.getName()).parentId((Long) workstationIdToGroupId.get(workstation.getId())).build(); }).collect(Collectors.toList()); if (Func.isNotEmpty(collect1)) { collect.addAll(collect1); } } return collect; } private List groupWorkstationList(Long groupId) { //CommonGroup::getSort List commonGroupList = list(Wrappers.lambdaQuery().eq(CommonGroup::getParentId, groupId).orderByAsc(CommonGroup::getSort)); List collect = Lists.newArrayList(); if (Func.isNotEmpty(commonGroupList)) { List ids = commonGroupList.stream().map((v0) -> { return v0.getId(); }).distinct().collect(Collectors.toList()); List commonGroupOfItemList = this.commonGroupOfItemService.list(Wrappers.lambdaQuery().in(CommonGroupOfItem::getGroupId, ids) .eq(CommonGroupOfItem::getGroupType, CommonGroupTypeEnum.WORKSTATION.getName())); /* List commonGroupOfItemList = this.commonGroupOfItemService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getGroupId(); }, ids)).eq((v0) -> { return v0.getGroupType(); }, CommonGroupTypeEnum.WORKSTATION.getName()));*/ Map workstationIdToGroupId = commonGroupOfItemList.stream().collect(Collectors.toMap((v0) -> { return v0.getItemId(); }, (v0) -> { return v0.getGroupId(); })); if (Func.isNotEmpty(commonGroupOfItemList)) { List workstationIds = commonGroupOfItemList.stream().map((v0) -> { return v0.getItemId(); }).collect(Collectors.toList()); List workstations = this.workstationService.listByIds(workstationIds).stream().filter(s -> { return CommonConstant.ENABLE.equals(s.getStatus()); }).filter((v0) -> { return Func.isNotEmpty(v0); }).collect(Collectors.toList()); List collect1 = workstations.stream().map(workstation -> { return WorkstationInGroupVO.builder().isWorkstation(true).isGroup(false).id(workstation.getId()).title(workstation.getName()).code(workstation.getName()).parentId((Long) workstationIdToGroupId.get(workstation.getId())).build(); }).collect(Collectors.toList()); if (Func.isNotEmpty(collect1)) { collect.addAll(collect1); } } } return collect; } /* @Override public List groupFtpDirectoryListLazy(Long groupId) { List commonGroupList = list(Wrappers.lambdaQuery().eq(CommonGroup::getParentId, groupId).orderByAsc(Arrays.asList(CommonGroup::getSort)) ); List collect = commonGroupList.stream().map(commonGroup -> { return WorkstationInGroupVO.builder().parentId(groupId).isWorkstation(false).isGroup(true).code(commonGroup.getCode()).title(commonGroup.getName()).groupTag(commonGroup.getGroupTag()).id(commonGroup.getId()).build(); }).collect(Collectors.toList()); List bindingFtps = this.wsRelationTdService.list().stream().map((v0) -> { return v0.getWorkstationId(); }).collect(Collectors.toList()); //CommonGroupOfItem::getGroupType List commonGroupOfItemList = this.commonGroupOfItemService.list(Wrappers.lambdaQuery() .eq(CommonGroupOfItem::getGroupId, groupId).eq(CommonGroupOfItem::getGroupType, CommonGroupTypeEnum.WORKSTATION.getName())); Map workstationIdToGroupId = commonGroupOfItemList.stream().collect(Collectors.toMap((v0) -> { return v0.getItemId(); }, (v0) -> { return v0.getGroupId(); })); if (Func.isNotEmpty(commonGroupOfItemList)) { List workstationIds = (commonGroupOfItemList.stream().map((v0) -> { return v0.getItemId(); }).collect(Collectors.toList())).stream().filter(item -> { return !bindingFtps.contains(item); }).collect(Collectors.toList()); List workstations = this.workstationService.listByIds(workstationIds).stream().filter((v0) -> { return Func.isNotEmpty(v0); }).collect(Collectors.toList()); List workstationInGroupVOList = workstations.stream().map(workstation -> { return WorkstationInGroupVO.builder().isWorkstation(true).isGroup(false).id(workstation.getId()).title(workstation.getName()).code(workstation.getName()).parentId((Long) workstationIdToGroupId.get(workstation.getId())).supportCncRw(workstation.getSupportCncRw()).build(); }).collect(Collectors.toList()); if (Func.isNotEmpty(workstationInGroupVOList)) { collect.addAll(workstationInGroupVOList); } } return collect; } */ /* @Override public List groupFtpDirectoryWorkstationList(CommonGroupFtpVO commonGroupFtpVO) { List groupList = list(Wrappers.lambdaQuery() .eq(CommonGroup::getGroupType, commonGroupFtpVO.getGroupType()) .eq(CommonGroup::getGroupCategory, commonGroupFtpVO.getGroupCategory()) .orderByAsc(CommonGroup::getSort)); List groupIds = groupList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); //CommonGroupOfItem::getGroupType List itemList = this.commonGroupOfItemService.list(Wrappers.lambdaQuery() .in(Func.isNotEmpty(groupIds), CommonGroupOfItem::getGroupId, groupIds) .eq(CommonGroupOfItem::getGroupType, commonGroupFtpVO.getGroupType())); List bindingFtps = this.wsRelationTdService.list().stream().map((v0) -> { return v0.getWorkstationId(); }).collect(Collectors.toList()); if (Func.isNotEmpty(commonGroupFtpVO.getTransferDirectorId())) { //DncWsRelationTd::getTransferDirectorId List list = this.wsRelationTdService.list(Wrappers.lambdaQuery() .eq(DncWsRelationTd::getTransferDirectorId, commonGroupFtpVO.getTransferDirectorId())); if (Func.isNotEmpty(list)) { List ftpRelationIds = list.stream().map((v0) -> { return v0.getWorkstationId(); }).collect(Collectors.toList()); if (Func.isNotEmpty(ftpRelationIds)) { bindingFtps = bindingFtps.stream().filter(s -> { return !ftpRelationIds.contains(s); }).collect(Collectors.toList()); } } } List finalBindingFtps = bindingFtps; //Workstation::getStatus List workstations = this.workstationService.list(Wrappers.lambdaQuery() .eq(Workstation::getStatus, commonGroupFtpVO.getStatus() == null ? CommonConstant.ENABLE : commonGroupFtpVO.getStatus())).stream().filter(item -> { return !finalBindingFtps.contains(item.getId()); }).collect(Collectors.toList()); List list2 = groupList.stream().filter(o -> { return Func.isNotEmpty(o.getParentId()); }).map(o2 -> { return WorkstationInGroupVO.builder().id(o2.getId()).parentId(o2.getParentId()).title(o2.getName()).code("").isWorkstation(Boolean.FALSE).isGroup(Boolean.TRUE).groupTag(o2.getGroupTag()).build(); }).collect(Collectors.toList()); list2.addAll(workstations.stream().flatMap(o1 -> { Long id = o1.getId(); return itemList.stream().filter(o22 -> { return id.equals(o22.getItemId()); }).map(o23 -> { return WorkstationInGroupVO.builder().id(id).parentId(o23.getGroupId()).title(o1.getName()).code(o1.getCode()).isWorkstation(Boolean.TRUE).isGroup(Boolean.FALSE).calendarCode(o1.getCalendarCode()).build(); }).distinct(); }).collect(Collectors.toList())); return list2; }*/ @Override public List getMdcGroup() { ParamBiz param = new ParamBiz(); param.setUserId(AuthUtil.getUserId()); param.setParamKey("mdc_chosen_groups"); ParamBiz detail = (ParamBiz) this.paramService.getOne(Condition.getQueryWrapper(param)); //CommonGroup::getGroupType List groupList = list(Wrappers.lambdaQuery().eq(CommonGroup::getGroupType, CommonGroupTypeEnum.WORKSTATION.getName())); if (detail == null) { return new ArrayList<>(); } List result = JSONArray.parseArray(detail.getParamValue(), MdcWorkStationGroupVO.class); if (CollectionUtil.isEmpty(result)) { return new ArrayList<>(); } Set groupIdSet = groupList.stream().map(CommonGroup::getId).collect(Collectors.toSet()); Iterator ite = result.iterator(); while (ite.hasNext()) { if (!groupIdSet.contains(ite.next().getGroupId())) { ite.remove(); } } return result; } @Override @Transactional(rollbackFor = {Exception.class}) public Boolean deleteGroup(Long groupId) { CommonGroup commonGroup = (CommonGroup) getOne(Wrappers.lambdaQuery().eq(CommonGroup::getId, groupId)); List dictItems = getDictItems(); deleteCheckGroup(commonGroup); verificationProductionLineCommonGroup(commonGroup); validCraftVersionBing(groupId); String groupTag = commonGroup.getGroupTag(); List groupIdList = this.baseMapper.getAllSubGroup(groupId, commonGroup.getGroupType(), commonGroup.getGroupCategory()).stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); //CommonGroupOfItem::getGroupId List commonGroupOfItemList = this.commonGroupOfItemService.list(Wrappers.lambdaQuery() .in(CommonGroupOfItem::getGroupId, groupIdList)); if (Func.isBlank(groupTag)) { CommonGroup rootNode = getDefaultGroup(commonGroup.getGroupType(), commonGroup.getGroupCategory()); String groupType = commonGroup.getGroupType(); if (Func.equals(groupType, CommonGroupConstant.NG_TYPE)) { //CommonGroup::getParentId List list = list(Wrappers.lambdaQuery().eq(CommonGroup::getParentId, groupId)); List commonGroupOfItemList2 = this.commonGroupOfItemService.list(Wrappers.lambdaQuery().eq(CommonGroupOfItem::getGroupId, groupId)); commonGroupOfItemList2.forEach(c -> { c.setGroupId(rootNode.getParentId()); }); this.commonGroupOfItemService.updateBatchById(commonGroupOfItemList2); list.forEach(item -> { item.setParentId(rootNode.getParentId()); }); updateBatchById(list); removeById(groupId); return true; } commonGroupOfItemList.forEach(c2 -> { c2.setGroupId(rootNode.getId()); }); this.commonGroupOfItemService.updateBatchById(commonGroupOfItemList); removeById(groupId); } else { if (!dictItems.contains(groupTag)) { CommonGroup rootNode2 = getDefaultGroup(commonGroup.getGroupType(), commonGroup.getGroupCategory()); commonGroupOfItemList.forEach(c3 -> { c3.setGroupId(rootNode2.getId()); }); this.commonGroupOfItemService.updateBatchById(commonGroupOfItemList); } removeBatchByIds(groupIdList); } return true; } private void validCraftVersionBing(Long groupId) { long count = this.lineService.count(Wrappers.lambdaQuery(CraftVersionLine.class).eq(CraftVersionLine::getGroupId, groupId)); ThrowFun.isTrue(count > 0).throwMessage(MessageUtils.message("cps.common.group.line.bind.version", new Object[0])); } private void verificationProductionLineCommonGroup(CommonGroup commonGroup) { boolean active = false; List dictItems = getDictItems(); String groupTag = commonGroup.getGroupTag(); if (dictItems.contains(groupTag)) { List workstationInGroups = groupWorkstationList(commonGroup.getId()); if (Func.isNotEmpty(workstationInGroups)) { long count = workstationInGroups.stream().filter(s -> { return Boolean.TRUE.equals(s.getIsWorkstation()); }).count(); if (count > 0) { active = true; } } if (active) { throw new ServiceException(MessageUtils.message("cps.common.group.production.line.delete.fail", new Object[0])); } } } public void deleteCheckGroup(CommonGroup commonGroup) { CommonGroup rootNode = getRootNode(commonGroup.getGroupType(), commonGroup.getGroupCategory()); CommonGroup defaultGroup = getDefaultGroup(commonGroup.getGroupType(), commonGroup.getGroupCategory()); if (rootNode.getId().equals(commonGroup.getId()) || defaultGroup.getId().equals(commonGroup.getId())) { throw new ServiceException(MessageUtils.message("cps.common.group.can.not.delete.root.or.default.group", new Object[0])); } } private List getDictItems() { List list = Lists.newArrayList(); List dictList = this.dictService.getList(CommonGroupConstant.PRODUCTION_LINE_DICT_KEY); if (Func.isNotEmpty(dictList)) { dictList.forEach(item -> { list.add(item.getDictKey()); }); } return list; } @Override public CommonGroup getDefaultGroup(String groupType, Integer groupCategory) { return (CommonGroup) getOne(Wrappers.lambdaQuery() .eq(CommonGroup::getGroupType, groupType) .eq(CommonGroup::getGroupCategory, groupCategory) .eq(CommonGroup::getCode, CommonGroupConstant.DEFAULT_CODE) .eq(CommonGroup::getName, CommonGroupConstant.WORKSTATION_TYPE.equals(groupType) ? CommonGroupConstant.DEFAULT_NAME : CommonGroupConstant.DEFAULT_GROUP_NAME)); } @Override public List groupWorkstationList(CommonGroupTypeVO commonGroupTypeVO) { List groupList = list(Wrappers.lambdaQuery().eq(CommonGroup::getGroupType, commonGroupTypeVO.getGroupType()) .eq(CommonGroup::getGroupCategory, commonGroupTypeVO.getGroupCategory()) .orderByAsc(CommonGroup::getSort)); List groupIds = groupList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); //CommonGroupOfItem::getId List itemList = this.commonGroupOfItemService.list(Wrappers.lambdaQuery() .in(Func.isNotEmpty(groupIds), CommonGroupOfItem::getGroupId, groupIds) .eq(CommonGroupOfItem::getGroupType, commonGroupTypeVO.getGroupType())); //Workstation::getDeviceType List workstations = this.workstationService.list(Wrappers.lambdaQuery() .eq(Workstation::getStatus, commonGroupTypeVO.getStatus() == null ? CommonConstant.ENABLE : commonGroupTypeVO.getStatus()) .eq(Func.isNotEmpty(commonGroupTypeVO.getWorkType()),Workstation::getDeviceType, commonGroupTypeVO.getWorkType()) .in(Func.isNotEmpty(commonGroupTypeVO.getWorkstationIdList()),Workstation::getId, commonGroupTypeVO.getWorkstationIdList())); Map groupMap = groupList.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, (v0) -> { return v0.getName(); })); List list = groupList.stream().filter(o -> { return Func.isNotEmpty(o.getParentId()); }).map(o2 -> { return WorkstationInGroupVO.builder().id(o2.getId()).parentId(o2.getParentId()).parentName((String) groupMap.get(o2.getParentId())).title(o2.getName()).code("").isWorkstation(Boolean.FALSE).isGroup(Boolean.TRUE).groupTag(o2.getGroupTag()).build(); }).collect(Collectors.toList()); list.addAll(workstations.stream().flatMap(o1 -> { Long id = o1.getId(); return itemList.stream().filter(o22 -> { return id.equals(o22.getItemId()); }).map(o23 -> { return WorkstationInGroupVO.builder().id(id).parentId(o23.getGroupId()).parentName((String) groupMap.get(o23.getGroupId())).title(o1.getName()).code(o1.getCode()).isWorkstation(Boolean.TRUE).isGroup(Boolean.FALSE).calendarCode(o1.getCalendarCode()).build(); }).distinct(); }).collect(Collectors.toList())); return list; } @Override public Map> groupWorkstationMap(List groupIds) { //CommonGroupOfItem::getGroupId List groupOfItems = this.commonGroupOfItemService.list(Wrappers.lambdaQuery() .in(Func.isNotEmpty(groupIds), CommonGroupOfItem::getGroupId, groupIds)); return groupOfItems.stream().collect(Collectors.groupingBy((v0) -> { return v0.getGroupId(); }, Collectors.mapping((v0) -> { return v0.getItemId(); }, Collectors.toSet()))); } @Override public List groupWorkstationListJimu(String pid) { List result = new ArrayList<>(); if (Func.isEmpty(pid)) { pid = String.valueOf(CommonGroupConstant.ROOT); } List groupList = list(Wrappers.lambdaQuery() .eq(CommonGroup::getGroupType, CommonGroupTypeEnum.WORKSTATION.getName()) .eq(CommonGroup::getGroupCategory, CommonGroupConstant.DEFAULT_CATEGORY) .eq(CommonGroup::getParentId, pid) .orderByAsc(CommonGroup::getSort)); List workstationList = this.workstationMapper.listWorkstationDataByGroup(pid); String finalPid = pid; if (Func.isNotEmpty(groupList)) { groupList.forEach(o -> { result.add(JimuTreeVO.builder().id(String.valueOf(o.getId())).pid(finalPid).title(o.getName()).value(String.valueOf(o.getId())).disabled(Boolean.TRUE.booleanValue()).build()); }); } if (Func.isNotEmpty(workstationList)) { workstationList.forEach(o2 -> { result.add(JimuTreeVO.builder().id(String.valueOf(o2.getId())).pid(finalPid).title(o2.getName()).value(String.valueOf(o2.getId())).disabled(Boolean.FALSE.booleanValue()).build()); }); } return result; } private void importProcess(Long parentId, String names, String rootName, CommonGroupTypeVO commonGroupTypeVO, CommonGroupImport excel) { String parent = names.split("-")[0].trim(); String child = names.substring(parent.length()); names.split("-"); if (Func.isEmpty(excel.getName())) { excel.setFailReason(MessageUtils.message("cps.organization.name.can.not.be.null", new Object[0])); } else if (Func.isEmpty(parentId) && !rootName.equals(parent)) { excel.setFailReason(MessageUtils.message("cps.organization.name.import.failed", new Object[0])); } else if (ValidatorUtils.checkContextLength(parent)) { excel.setFailReason(MessageUtils.message("cps.organization.name.can.not.exceed", new Object[0])); } else if (getOrCreateIdUnable(parentId, parent, commonGroupTypeVO)) { excel.setFailReason(MessageUtils.message("cps.organization.already.exist.stop.status", new Object[0])); } else { if (checkName(names).booleanValue()) { excel.setFailReason(MessageUtils.message("cps.organization.already.exist", new Object[0])); } Long id = getOrCreateId(parentId, parent, commonGroupTypeVO); if (Func.isNotBlank(child)) { importProcess(id, child.substring(1).trim(), rootName, commonGroupTypeVO, excel); } } } public Boolean checkName(String names) { HashMap commonGroupNameMap = getCommonGroupNameMap(CommonGroupTypeEnum.ORGANIZATION.getName(), 1); return Boolean.valueOf(commonGroupNameMap.containsKey(names)); } private boolean getOrCreateIdUnable(Long parentId, String name, CommonGroupTypeVO commonGroupTypeVO) { CommonGroup commonGroup = getOne(Wrappers.lambdaQuery() .eq(CommonGroup::getGroupType, commonGroupTypeVO.getGroupType()) .eq(CommonGroup::getGroupCategory, commonGroupTypeVO.getGroupCategory()) .eq(CommonGroup::getParentId, Func.isEmpty(parentId) ? BladeConstant.TOP_PARENT_ID : parentId) .eq(CommonGroup::getStatus, CommonConstant.DEACTIVATE) .eq(CommonGroup::getName, name)); /* CommonGroup commonGroup = (CommonGroup) getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getGroupType(); }, commonGroupTypeVO.getGroupType())).eq((v0) -> { return v0.getGroupCategory(); }, commonGroupTypeVO.getGroupCategory())).eq((v0) -> { return v0.getParentId(); }, Func.isEmpty(parentId) ? BladeConstant.TOP_PARENT_ID : parentId)).eq((v0) -> { return v0.getStatus(); }, CommonConstant.DEACTIVATE)).eq((v0) -> { return v0.getName(); }, name));*/ if (commonGroup != null) { return true; } return false; } private Long getOrCreateId(Long parentId, String name, CommonGroupTypeVO commonGroupTypeVO) { CommonGroup commonGroup = getOne(Wrappers.lambdaQuery() .eq(CommonGroup::getGroupType, commonGroupTypeVO.getGroupType()) .eq(CommonGroup::getGroupCategory, commonGroupTypeVO.getGroupCategory()) .eq(CommonGroup::getParentId, Func.isEmpty(parentId) ? BladeConstant.TOP_PARENT_ID : parentId) .eq(CommonGroup::getStatus, CommonConstant.ENABLE) .eq(CommonGroup::getName, name)); /* CommonGroup commonGroup = (CommonGroup) getOne((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getGroupType(); }, commonGroupTypeVO.getGroupType())).eq((v0) -> { return v0.getGroupCategory(); }, commonGroupTypeVO.getGroupCategory())).eq((v0) -> { return v0.getParentId(); }, Func.isEmpty(parentId) ? BladeConstant.TOP_PARENT_ID : parentId)).eq((v0) -> { return v0.getStatus(); }, CommonConstant.ENABLE)).eq((v0) -> { return v0.getName(); }, name));*/ if (Func.isNotEmpty(commonGroup)) { return commonGroup.getId(); } String code = getNextChildCode(parentId, commonGroupTypeVO.getGroupType(), commonGroupTypeVO.getGroupCategory()); CommonGroup commonGroup2 = CommonGroup.builder().groupType(commonGroupTypeVO.getGroupType()).groupCategory(commonGroupTypeVO.getGroupCategory()).parentId(parentId).code(code).name(name).fullName(name).sort(Integer.valueOf(Integer.parseInt(code.substring(code.length() - 5)))).remark("批量导入").isDeleted(0).build(); save(commonGroup2); return commonGroup2.getId(); } protected void validateGroup(CommonGroup commonGroup) { Long pId = Long.valueOf(Func.isEmpty(commonGroup.getParentId()) ? 0L : commonGroup.getParentId().longValue()); Long id = Long.valueOf(Func.isEmpty(commonGroup.getId()) ? 0L : commonGroup.getId().longValue()); List siblings = this.baseMapper.selectList( Wrappers.query().lambda() .eq(CommonGroup::getGroupType, commonGroup.getGroupType()) .eq(CommonGroup::getGroupCategory, commonGroup.getGroupCategory()) .eq(CommonGroup::getParentId, pId) .eq(CommonGroup::getStatus, CommonConstant.ENABLE) .ne(CommonGroup::getId, id)); /* List siblings = this.baseMapper.selectList((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getGroupType(); }, commonGroup.getGroupType())).eq((v0) -> { return v0.getGroupCategory(); }, commonGroup.getGroupCategory())).eq((v0) -> { return v0.getParentId(); }, pId)).eq((v0) -> { return v0.getStatus(); }, CommonConstant.ENABLE)).ne((v0) -> { return v0.getId(); }, id));*/ if (siblings.stream().anyMatch(g -> { return g.getName().equals(commonGroup.getName()); })) { throw new ServiceException(MessageUtils.message("cps.group.exist.same.name.group", new Object[0])); } if (commonGroup.getParentId().longValue() > 0 && Func.toLong(commonGroup.getParentId()) == Func.toLong(commonGroup.getId())) { throw new ServiceException(MessageUtils.message("cps.group.parent.can.not.choose.self", new Object[0])); } } protected void validateUnableGroup(CommonGroup commonGroup) { Long pId = Long.valueOf(Func.isEmpty(commonGroup.getParentId()) ? 0L : commonGroup.getParentId().longValue()); Long id = Long.valueOf(Func.isEmpty(commonGroup.getId()) ? 0L : commonGroup.getId().longValue()); List siblings = this.baseMapper.selectList( Wrappers.query().lambda() .eq(CommonGroup::getGroupType, commonGroup.getGroupType()) .eq(CommonGroup::getGroupCategory, commonGroup.getGroupCategory()) .eq(CommonGroup::getParentId, pId) .eq(CommonGroup::getStatus, CommonConstant.DEACTIVATE) .ne(CommonGroup::getId, id)); /* List siblings = this.baseMapper.selectList((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> { return v0.getGroupType(); }, commonGroup.getGroupType())).eq((v0) -> { return v0.getGroupCategory(); }, commonGroup.getGroupCategory())).eq((v0) -> { return v0.getParentId(); }, pId)).eq((v0) -> { return v0.getStatus(); }, CommonConstant.DEACTIVATE)).ne((v0) -> { return v0.getId(); }, id));*/ if (siblings.stream().anyMatch(g -> { return g.getName().equals(commonGroup.getName()); })) { throw new ServiceException(MessageUtils.message("cps.organization.already.exist.stop.status", new Object[0])); } } public String getNextChildCode(Long parentId, String groupType, Integer groupCategory) { CommonGroup lastChildOrNull = getLastChildOrNull(parentId, groupType, groupCategory); if (null != lastChildOrNull) { return CommonGroup.calculateNextCode(lastChildOrNull.getCode()); } String parentCode = parentId != null ? getCodeOrDefault(parentId) : null; return CommonGroup.appendCode(parentCode, CommonGroup.createCode(1)); } public String getCodeOrDefault(Long id) { CommonGroup commonGroup = (CommonGroup) this.baseMapper.selectById(id); if (commonGroup == null) { return null; } return commonGroup.getCode(); } public CommonGroup getLastChildOrNull(Long parentId, String groupType, Integer groupCategory) { return this.baseMapper.selectOne( Lambda.create() .eq(CommonGroup::getParentId, parentId) .eq(CommonGroup::getGroupType, groupType) .eq(CommonGroup::getGroupCategory, groupCategory) .eq(CommonGroup::getStatus, CommonConstant.ENABLE) .orderByDesc(CommonGroup::getCode) .limit(1)); /* return (CommonGroup) this.baseMapper.selectOne(((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) Lambda.create().eq((v0) -> { return v0.getParentId(); }, parentId)).eq((v0) -> { return v0.getGroupType(); }, groupType)).eq((v0) -> { return v0.getGroupCategory(); }, groupCategory)).eq((v0) -> { return v0.getStatus(); }, CommonConstant.ENABLE)).orderByDesc((v0) -> { return v0.getCode(); })).limit(1)); */ } }