package org.jeecg.modules.eam.service.impl;
|
|
|
import org.jeecg.common.api.vo.CommonGenericTree;
|
import org.jeecg.common.system.api.ISysBaseAPI;
|
//import org.jeecg.modules.base.service.IUnitService;
|
import org.jeecg.modules.eam.entity.ProcessParameters;
|
import org.jeecg.modules.eam.entity.ProcessParametersCategory;
|
import org.jeecg.modules.eam.mapper.ProcessParametersMapper;
|
import org.jeecg.modules.eam.service.IProcessParametersCategoryService;
|
import org.jeecg.modules.eam.service.IProcessParametersService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* @Description: 工艺参数
|
* @Author: houjie
|
* @Date: 2023-03-07
|
* @Version: V1.0
|
*/
|
@Service
|
public class ProcessParametersServiceImpl extends ServiceImpl<ProcessParametersMapper, ProcessParameters> implements IProcessParametersService {
|
|
@Autowired
|
private IProcessParametersCategoryService processParametersCategoryService;
|
|
// @Autowired
|
// private IUnitService unitService;
|
@Autowired
|
private ISysBaseAPI sysBaseApi;
|
|
@Override
|
public List<CommonGenericTree> loadTree() {
|
// 根节点
|
CommonGenericTree rootNode = initRootNode();
|
// 工艺参数类别
|
List<ProcessParametersCategory> processParametersCategoryList = processParametersCategoryService.list();
|
List<CommonGenericTree> processParametersCategoryTree = new ArrayList<CommonGenericTree>();
|
for (ProcessParametersCategory processParametersCategory : processParametersCategoryList) {
|
processParametersCategoryTree.add(processParametersCategory2Tree(processParametersCategory));
|
}
|
// 工艺参数
|
List<ProcessParameters> processParametersList = this.list();
|
List<CommonGenericTree> processParametersTree = new ArrayList<CommonGenericTree>();
|
for (ProcessParameters processParameters : processParametersList) {
|
String unitName = sysBaseApi.getUnitNameById(processParameters.getUnitId());
|
processParameters.setUnit(unitName);
|
processParametersTree.add(processParameters2Tree(processParameters));
|
}
|
processParametersCategoryTree = this.list2Tree(processParametersCategoryTree, processParametersTree);
|
for (CommonGenericTree temp : processParametersCategoryTree) {
|
rootNode.addChildren(temp);
|
}
|
// 返回的结果是list
|
List<CommonGenericTree> list = new ArrayList<>();
|
list.add(rootNode);
|
return list;
|
}
|
|
private CommonGenericTree initRootNode() {
|
CommonGenericTree node = new CommonGenericTree<>();
|
node.setKey("-1");
|
node.setTitle("工艺参数类别");
|
node.setType(0);
|
node.setDisabled(true);
|
node.setEntity(null);
|
node.setValue("-1");
|
return node;
|
}
|
|
private List<CommonGenericTree> list2Tree(List<CommonGenericTree> parentList, List<CommonGenericTree> childList) {
|
for (CommonGenericTree tree : parentList) {
|
String id = tree.getKey();
|
for (CommonGenericTree cTree : childList) {
|
if (id.equals(cTree.getParentId())) {
|
tree.addChildren(cTree);
|
}
|
}
|
}
|
return parentList;
|
}
|
|
private CommonGenericTree processParametersCategory2Tree(ProcessParametersCategory processParametersCategory) {
|
CommonGenericTree<ProcessParametersCategory> processParametersCategoryNode = new CommonGenericTree<>();
|
processParametersCategoryNode.setKey(processParametersCategory.getId());
|
processParametersCategoryNode.setTitle(processParametersCategory.getNum() + "/" + processParametersCategory.getName());
|
processParametersCategoryNode.setParentId("-1");
|
processParametersCategoryNode.setIcon("");
|
processParametersCategoryNode.setType(1);
|
processParametersCategoryNode.setDisabled(true);
|
processParametersCategoryNode.setEntity(processParametersCategory);
|
processParametersCategoryNode.setValue(processParametersCategory.getId());
|
return processParametersCategoryNode;
|
}
|
|
private CommonGenericTree processParameters2Tree(ProcessParameters processParameters) {
|
CommonGenericTree<ProcessParameters> processParametersNode = new CommonGenericTree<>();
|
processParametersNode.setKey(processParameters.getId());
|
processParametersNode.setTitle(processParameters.getNum() + "/" + processParameters.getName());
|
processParametersNode.setParentId(processParameters.getProcessParametersCategoryId());
|
processParametersNode.setIcon("");
|
processParametersNode.setType(2);
|
processParametersNode.setDisabled(false);
|
processParametersNode.setEntity(processParameters);
|
processParametersNode.setValue(processParameters.getId());
|
return processParametersNode;
|
}
|
}
|