package org.jeecg.modules.eam.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import org.checkerframework.checker.units.qual.C;
|
import org.jeecg.common.api.vo.CommonGenericTree;
|
import org.jeecg.modules.eam.entity.EquipmentCategory;
|
import org.jeecg.modules.eam.entity.FaultCause;
|
import org.jeecg.modules.eam.mapper.EquipmentCategoryMapper;
|
import org.jeecg.modules.eam.service.IEquipmentCategoryService;
|
import org.jeecg.modules.system.entity.SysDict;
|
import org.jeecg.modules.system.entity.SysDictItem;
|
import org.jeecg.modules.system.mapper.SysDictItemMapper;
|
import org.jeecg.modules.system.mapper.SysDictMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Description: mom_eam_equipment_category
|
* @Author: jeecg-boot
|
* @Date: 2023-03-08
|
* @Version: V1.0
|
*/
|
@Service
|
public class EquipmentCategoryServiceImpl extends ServiceImpl<EquipmentCategoryMapper, EquipmentCategory> implements IEquipmentCategoryService {
|
@Autowired
|
private SysDictItemMapper sysDictItemMapper;
|
|
@Autowired
|
private SysDictMapper sysDictMapper;
|
|
@Override
|
public List<CommonGenericTree> loadTree() {
|
List<EquipmentCategory> equipmentCategoryList = this.lambdaQuery().eq(EquipmentCategory::getDelFlag, "0").list();
|
List<CommonGenericTree> commonGenericTrees = loadTree(equipmentCategoryList);
|
return commonGenericTrees;
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
public List<CommonGenericTree> loadTree(List<EquipmentCategory> EquipmentCategory) {
|
@SuppressWarnings("unused")
|
EquipmentCategory equipmentCategory = new EquipmentCategory();
|
List<CommonGenericTree> list = new ArrayList<>();
|
Map<String, CommonGenericTree> map = new HashMap<>();
|
Map<String, CommonGenericTree> map2 = new HashMap<>();
|
Map<String, CommonGenericTree> map3 = new HashMap<>();
|
Map<String, CommonGenericTree> map4 = new HashMap<>();
|
Map<String, CommonGenericTree> map5 = new HashMap<>();
|
Map<String, CommonGenericTree> map6 = new HashMap<>();
|
Map<String, CommonGenericTree> map7 = new HashMap<>();
|
CommonGenericTree<EquipmentCategory> node = new CommonGenericTree<>();
|
node.setKey("-1");
|
node.setValue("-1");
|
node.setTitle("设备分类");
|
node.setRField1("-1");
|
node.setRField2("设备分类");
|
node.setDisabled(false);
|
node.setEntity(new EquipmentCategory());
|
list.add(node);
|
if (CollectionUtils.isNotEmpty(list)) {
|
CommonGenericTree<EquipmentCategory> pcNode;
|
for (EquipmentCategory category : EquipmentCategory) {
|
if (category.getParentId().equals("-1")) {
|
pcNode = new CommonGenericTree<>();
|
pcNode.setKey(category.getId());
|
pcNode.setTitle(category.getNum() + "/" + category.getName());
|
pcNode.setParentId(node.getKey());
|
pcNode.setIcon("");
|
pcNode.setType(0);
|
pcNode.setValue(category.getId());
|
pcNode.setDisabled(false);
|
pcNode.setRField1(category.getNum());
|
pcNode.setRField2(category.getName());
|
pcNode.setEntity(category);
|
node.addChildren(pcNode);
|
map.put(category.getId(), pcNode);
|
}
|
}
|
CommonGenericTree<EquipmentCategory> childNode;
|
for (EquipmentCategory category : EquipmentCategory) {
|
if (map.containsKey(category.getParentId())) {
|
pcNode = map.get(category.getParentId());
|
childNode = new CommonGenericTree<>();
|
childNode.setKey(category.getId());
|
childNode.setTitle(category.getNum() + "/" + category.getName());
|
childNode.setParentId(category.getParentId());
|
childNode.setIcon("");
|
childNode.setType(0);
|
childNode.setValue(category.getId());
|
childNode.setDisabled(false);
|
childNode.setRField1(category.getNum());
|
childNode.setRField2(category.getName());
|
childNode.setEntity(category);
|
pcNode.addChildren(childNode);
|
map2.put(category.getId(), childNode);
|
}
|
}
|
if(map2.size()>0){
|
CommonGenericTree<EquipmentCategory> child2Node;
|
for (EquipmentCategory category : EquipmentCategory) {
|
if (map2.containsKey(category.getParentId())) {
|
pcNode = map2.get(category.getParentId());
|
child2Node = new CommonGenericTree<>();
|
child2Node.setKey(category.getId());
|
child2Node.setTitle(category.getNum() + "/" + category.getName());
|
child2Node.setParentId(category.getParentId());
|
child2Node.setIcon("");
|
child2Node.setType(0);
|
child2Node.setValue(category.getId());
|
child2Node.setDisabled(false);
|
child2Node.setRField1(category.getNum());
|
child2Node.setRField2(category.getName());
|
child2Node.setEntity(category);
|
pcNode.addChildren(child2Node);
|
map3.put(category.getId(), child2Node);
|
}
|
}
|
if(map3.size()>0){
|
CommonGenericTree<EquipmentCategory> child3Node;
|
for (EquipmentCategory category : EquipmentCategory) {
|
if (map3.containsKey(category.getParentId())) {
|
pcNode = map3.get(category.getParentId());
|
child3Node = new CommonGenericTree<>();
|
child3Node.setKey(category.getId());
|
child3Node.setTitle(category.getNum() + "/" + category.getName());
|
child3Node.setParentId(category.getParentId());
|
child3Node.setIcon("");
|
child3Node.setType(0);
|
child3Node.setValue(category.getId());
|
child3Node.setDisabled(false);
|
child3Node.setRField1(category.getNum());
|
child3Node.setRField2(category.getName());
|
child3Node.setEntity(category);
|
pcNode.addChildren(child3Node);
|
map4.put(category.getId(), child3Node);
|
}
|
}
|
if(map4.size()>0){
|
CommonGenericTree<EquipmentCategory> child4Node;
|
for (EquipmentCategory category : EquipmentCategory) {
|
if (map4.containsKey(category.getParentId())) {
|
pcNode = map4.get(category.getParentId());
|
child4Node = new CommonGenericTree<>();
|
child4Node.setKey(category.getId());
|
child4Node.setTitle(category.getNum() + "/" + category.getName());
|
child4Node.setParentId(category.getParentId());
|
child4Node.setIcon("");
|
child4Node.setType(0);
|
child4Node.setValue(category.getId());
|
child4Node.setDisabled(false);
|
child4Node.setRField1(category.getNum());
|
child4Node.setRField2(category.getName());
|
child4Node.setEntity(category);
|
pcNode.addChildren(child4Node);
|
map5.put(category.getId(), child4Node);
|
}
|
}
|
if(map5.size()>0){
|
CommonGenericTree<EquipmentCategory> child5Node;
|
for (EquipmentCategory category : EquipmentCategory) {
|
if (map5.containsKey(category.getParentId())) {
|
pcNode = map5.get(category.getParentId());
|
child5Node = new CommonGenericTree<>();
|
child5Node.setKey(category.getId());
|
child5Node.setTitle(category.getNum() + "/" + category.getName());
|
child5Node.setParentId(category.getParentId());
|
child5Node.setIcon("");
|
child5Node.setType(0);
|
child5Node.setValue(category.getId());
|
child5Node.setDisabled(false);
|
child5Node.setRField1(category.getNum());
|
child5Node.setRField2(category.getName());
|
child5Node.setEntity(category);
|
pcNode.addChildren(child5Node);
|
map6.put(category.getId(), child5Node);
|
}
|
}
|
if(map6.size()>0){
|
CommonGenericTree<EquipmentCategory> child6Node;
|
for (EquipmentCategory category : EquipmentCategory) {
|
if (map6.containsKey(category.getParentId())) {
|
pcNode = map6.get(category.getParentId());
|
child6Node = new CommonGenericTree<>();
|
child6Node.setKey(category.getId());
|
child6Node.setTitle(category.getNum() + "/" + category.getName());
|
child6Node.setParentId(category.getParentId());
|
child6Node.setIcon("");
|
child6Node.setType(0);
|
child6Node.setValue(category.getId());
|
child6Node.setDisabled(false);
|
child6Node.setRField1(category.getNum());
|
child6Node.setRField2(category.getName());
|
child6Node.setEntity(category);
|
pcNode.addChildren(child6Node);
|
map7.put(category.getId(), child6Node);
|
}
|
}
|
if(map7.size()>0){
|
CommonGenericTree<EquipmentCategory> child7Node;
|
for (EquipmentCategory category : EquipmentCategory) {
|
if (map.containsKey(category.getParentId())) {
|
pcNode = map7.get(category.getParentId());
|
child7Node = new CommonGenericTree<>();
|
child7Node.setKey(category.getId());
|
child7Node.setTitle(category.getNum() + "/" + category.getName());
|
child7Node.setParentId(category.getParentId());
|
child7Node.setIcon("");
|
child7Node.setType(0);
|
child7Node.setValue(category.getId());
|
child7Node.setDisabled(false);
|
child7Node.setRField1(category.getNum());
|
child7Node.setRField2(category.getName());
|
child7Node.setEntity(category);
|
// pcNode.addChildren(child7Node);
|
// map7.put(cause.getId(), child7Node);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
return list;
|
}
|
|
@Transactional(rollbackFor = {Exception.class})
|
public void initRoot(){
|
SysDict rootSysDict = sysDictMapper.selectOne(new QueryWrapper<SysDict>().eq("dict_code","equipment_category"));
|
if(ObjectUtils.isNotNull(rootSysDict)){
|
List<SysDictItem> equipRoots = sysDictItemMapper.selectList(new QueryWrapper<SysDictItem>().eq("dict_id",rootSysDict.getId()));
|
List<EquipmentCategory> roots = new ArrayList<>();
|
for(SysDictItem rootSysDictItem:equipRoots){
|
EquipmentCategory root = new EquipmentCategory();
|
root.setId("root-"+rootSysDictItem.getItemValue());
|
root.setNum(rootSysDictItem.getItemValue());
|
root.setName(rootSysDictItem.getItemText());
|
root.setEquipmentCategoryUda1(rootSysDictItem.getItemValue());
|
root.setParentId("-1");
|
root.setDelFlag(0);
|
roots.add(root);
|
}
|
saveOrUpdateBatch(roots);
|
}
|
}
|
@Override
|
public List<CommonGenericTree> loadTreeByRecurrence() {
|
CommonGenericTree commonGenericTree = new CommonGenericTree();
|
commonGenericTree.setKey("-1");
|
commonGenericTree.setTitle("设备分类");
|
List<CommonGenericTree> children = getChildren(commonGenericTree);
|
if(children.size()==0){
|
commonGenericTree.setLeaf(true);
|
}
|
else {
|
commonGenericTree.setLeaf(false);
|
}
|
commonGenericTree.setChildren(children);
|
EquipmentCategory equipmentCategory = new EquipmentCategory();
|
equipmentCategory.setId("-1");
|
equipmentCategory.setName("设备分类");
|
equipmentCategory.setNum("root");
|
commonGenericTree.setEntity(equipmentCategory);
|
List<CommonGenericTree> list = new ArrayList<>();
|
list.add(commonGenericTree);
|
return list;
|
}
|
|
|
|
private List<CommonGenericTree> getChildren (CommonGenericTree commonGenericTree){
|
List<CommonGenericTree> children = baseMapper.getTreeByParentId(commonGenericTree.getKey());
|
for(CommonGenericTree child:children){
|
|
child.setEntity(baseMapper.selectById(child.getKey()));
|
List<CommonGenericTree> superChild = getChildren(child);
|
if(superChild.size()==0){
|
child.setLeaf(true);
|
}
|
else {
|
child.setLeaf(false);
|
}
|
child.setChildren(superChild);
|
}
|
return children;
|
}
|
@Override
|
public Page<EquipmentCategory> getAllChildren(Page<EquipmentCategory> page,EquipmentCategory equipmentCategory) {
|
QueryWrapper<EquipmentCategory>queryWrapper = new QueryWrapper();
|
if(StringUtils.isNotBlank(equipmentCategory.getParentId())){
|
List<String> ids = new ArrayList<>();
|
ids.add(equipmentCategory.getParentId());
|
ids = getChildren(equipmentCategory.getParentId(),ids);
|
if(ids.size()>1){
|
ids.remove(equipmentCategory.getParentId());
|
queryWrapper.in("id",ids);
|
}
|
else{
|
queryWrapper.eq("id","-1");
|
}
|
}
|
return baseMapper.selectPage(page,queryWrapper);
|
}
|
List<String> getChildren(String parentId,List<String> ids){
|
List<String> sons = new ArrayList<>();
|
for(String id:ids){
|
List<String> childrenIds = baseMapper
|
.selectList(new QueryWrapper<EquipmentCategory>()
|
.eq("parent_id",parentId).eq("del_flag",0)).stream()
|
.map(EquipmentCategory::getId)
|
.collect(Collectors.toList());
|
sons.addAll(getChildren(id,childrenIds));
|
sons.addAll(childrenIds);
|
}
|
ids.addAll(sons);
|
return ids;
|
}
|
|
}
|