package org.jeecg.modules.eam.service.impl;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import org.jeecg.common.api.vo.CommonGenericTree;
|
import org.jeecg.common.constant.CommonConstant;
|
import org.jeecg.modules.eam.entity.FaultCause;
|
import org.jeecg.modules.eam.mapper.FaultCauseMapper;
|
import org.jeecg.modules.eam.service.IFaultCauseService;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Description: mom_eam_fault_cause
|
* @Author: jeecg-boot
|
* @Date: 2023-03-07
|
* @Version: V1.0
|
*/
|
@Service
|
public class FaultCauseServiceImpl extends ServiceImpl<FaultCauseMapper, FaultCause> implements IFaultCauseService {
|
|
@Override
|
public List<CommonGenericTree> loadTree() {
|
List<FaultCause> faultCauseList = this.lambdaQuery().eq(FaultCause::getDelFlag, "0").list();
|
List<CommonGenericTree> commonGenericTrees = loadTree(faultCauseList);
|
return commonGenericTrees;
|
}
|
|
@SuppressWarnings("unchecked")
|
public List<CommonGenericTree> loadTree(List<FaultCause> faultCauseList) {
|
@SuppressWarnings("unused")
|
FaultCause faultCause = new FaultCause();
|
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<FaultCause> node = new CommonGenericTree<>();
|
node.setKey("-1");
|
node.setValue("-1");
|
node.setTitle("故障原因");
|
node.setRField1("-1");
|
node.setRField2("故障原因");
|
node.setDisabled(false);
|
node.setEntity(new FaultCause());
|
list.add(node);
|
if (CollectionUtils.isNotEmpty(list)) {
|
CommonGenericTree<FaultCause> pcNode;
|
for (FaultCause cause : faultCauseList) {
|
if (cause.getParentId().equals("-1")) {
|
pcNode = new CommonGenericTree<>();
|
pcNode.setKey(cause.getId());
|
pcNode.setTitle(cause.getNum() + "/" + cause.getName());
|
pcNode.setParentId(node.getKey());
|
pcNode.setIcon("");
|
pcNode.setType(0);
|
pcNode.setValue(cause.getId());
|
pcNode.setDisabled(false);
|
pcNode.setRField1(cause.getNum());
|
pcNode.setRField2(cause.getName());
|
pcNode.setEntity(cause);
|
node.addChildren(pcNode);
|
map.put(cause.getId(), pcNode);
|
}
|
}
|
CommonGenericTree<FaultCause> childNode;
|
for (FaultCause cause : faultCauseList) {
|
if (map.containsKey(cause.getParentId())) {
|
pcNode = map.get(cause.getParentId());
|
childNode = new CommonGenericTree<>();
|
childNode.setKey(cause.getId());
|
childNode.setTitle(cause.getNum() + "/" + cause.getName());
|
childNode.setParentId(cause.getParentId());
|
childNode.setIcon("");
|
childNode.setType(0);
|
childNode.setValue(cause.getId());
|
childNode.setDisabled(false);
|
childNode.setRField1(cause.getNum());
|
childNode.setRField2(cause.getName());
|
childNode.setEntity(cause);
|
pcNode.addChildren(childNode);
|
map2.put(cause.getId(), childNode);
|
}
|
}
|
if(map2.size()>0){
|
CommonGenericTree<FaultCause> child2Node;
|
for (FaultCause cause : faultCauseList) {
|
if (map2.containsKey(cause.getParentId())) {
|
pcNode = map2.get(cause.getParentId());
|
child2Node = new CommonGenericTree<>();
|
child2Node.setKey(cause.getId());
|
child2Node.setTitle(cause.getNum() + "/" + cause.getName());
|
child2Node.setParentId(cause.getParentId());
|
child2Node.setIcon("");
|
child2Node.setType(0);
|
child2Node.setValue(cause.getId());
|
child2Node.setDisabled(false);
|
child2Node.setRField1(cause.getNum());
|
child2Node.setRField2(cause.getName());
|
child2Node.setEntity(cause);
|
pcNode.addChildren(child2Node);
|
map3.put(cause.getId(), child2Node);
|
}
|
}
|
if(map3.size()>0){
|
CommonGenericTree<FaultCause> child3Node;
|
for (FaultCause cause : faultCauseList) {
|
if (map3.containsKey(cause.getParentId())) {
|
pcNode = map3.get(cause.getParentId());
|
child3Node = new CommonGenericTree<>();
|
child3Node.setKey(cause.getId());
|
child3Node.setTitle(cause.getNum() + "/" + cause.getName());
|
child3Node.setParentId(cause.getParentId());
|
child3Node.setIcon("");
|
child3Node.setType(0);
|
child3Node.setValue(cause.getId());
|
child3Node.setDisabled(false);
|
child3Node.setRField1(cause.getNum());
|
child3Node.setRField2(cause.getName());
|
child3Node.setEntity(cause);
|
pcNode.addChildren(child3Node);
|
map4.put(cause.getId(), child3Node);
|
}
|
}
|
if(map4.size()>0){
|
CommonGenericTree<FaultCause> child4Node;
|
for (FaultCause cause : faultCauseList) {
|
if (map4.containsKey(cause.getParentId())) {
|
pcNode = map4.get(cause.getParentId());
|
child4Node = new CommonGenericTree<>();
|
child4Node.setKey(cause.getId());
|
child4Node.setTitle(cause.getNum() + "/" + cause.getName());
|
child4Node.setParentId(cause.getParentId());
|
child4Node.setIcon("");
|
child4Node.setType(0);
|
child4Node.setValue(cause.getId());
|
child4Node.setDisabled(false);
|
child4Node.setRField1(cause.getNum());
|
child4Node.setRField2(cause.getName());
|
child4Node.setEntity(cause);
|
pcNode.addChildren(child4Node);
|
map5.put(cause.getId(), child4Node);
|
}
|
}
|
if(map5.size()>0){
|
CommonGenericTree<FaultCause> child5Node;
|
for (FaultCause cause : faultCauseList) {
|
if (map5.containsKey(cause.getParentId())) {
|
pcNode = map5.get(cause.getParentId());
|
child5Node = new CommonGenericTree<>();
|
child5Node.setKey(cause.getId());
|
child5Node.setTitle(cause.getNum() + "/" + cause.getName());
|
child5Node.setParentId(cause.getParentId());
|
child5Node.setIcon("");
|
child5Node.setType(0);
|
child5Node.setValue(cause.getId());
|
child5Node.setDisabled(false);
|
child5Node.setRField1(cause.getNum());
|
child5Node.setRField2(cause.getName());
|
child5Node.setEntity(cause);
|
pcNode.addChildren(child5Node);
|
map6.put(cause.getId(), child5Node);
|
}
|
}
|
if(map6.size()>0){
|
CommonGenericTree<FaultCause> child6Node;
|
for (FaultCause cause : faultCauseList) {
|
if (map6.containsKey(cause.getParentId())) {
|
pcNode = map6.get(cause.getParentId());
|
child6Node = new CommonGenericTree<>();
|
child6Node.setKey(cause.getId());
|
child6Node.setTitle(cause.getNum() + "/" + cause.getName());
|
child6Node.setParentId(cause.getParentId());
|
child6Node.setIcon("");
|
child6Node.setType(0);
|
child6Node.setValue(cause.getId());
|
child6Node.setDisabled(false);
|
child6Node.setRField1(cause.getNum());
|
child6Node.setRField2(cause.getName());
|
child6Node.setEntity(cause);
|
pcNode.addChildren(child6Node);
|
map7.put(cause.getId(), child6Node);
|
}
|
}
|
if(map7.size()>0){
|
CommonGenericTree<FaultCause> child7Node;
|
for (FaultCause cause : faultCauseList) {
|
if (map.containsKey(cause.getParentId())) {
|
pcNode = map7.get(cause.getParentId());
|
child7Node = new CommonGenericTree<>();
|
child7Node.setKey(cause.getId());
|
child7Node.setTitle(cause.getNum() + "/" + cause.getName());
|
child7Node.setParentId(cause.getParentId());
|
child7Node.setIcon("");
|
child7Node.setType(0);
|
child7Node.setValue(cause.getId());
|
child7Node.setDisabled(false);
|
child7Node.setRField1(cause.getNum());
|
child7Node.setRField2(cause.getName());
|
child7Node.setEntity(cause);
|
// pcNode.addChildren(child7Node);
|
// map7.put(cause.getId(), child7Node);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
return list;
|
}
|
}
|