package org.jeecg.modules.eam.service.impl;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import org.jeecg.common.api.vo.CommonGenericTree;
|
import org.jeecg.modules.eam.entity.InspectionProjectCategory;
|
import org.jeecg.modules.eam.entity.TransferMethodCategory;
|
import org.jeecg.modules.eam.mapper.TransferMethodCategoryMapper;
|
import org.jeecg.modules.eam.service.ITransferMethodCategoryService;
|
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_transfer_method_category
|
* @Author: jeecg-boot
|
* @Date: 2023-03-15
|
* @Version: V1.0
|
*/
|
@Service
|
public class TransferMethodCategoryServiceImpl extends ServiceImpl<TransferMethodCategoryMapper, TransferMethodCategory> implements ITransferMethodCategoryService {
|
|
// 初始化工装类别
|
private static final String initTransferMethodCategory = "01-增加,02-减少";
|
|
@Override
|
public List<CommonGenericTree> loadTree() {
|
List<TransferMethodCategory> transferMethodCategoryList = this.lambdaQuery().eq(TransferMethodCategory::getDelFlag, "0").list();
|
List<CommonGenericTree> commonGenericTrees = loadTree(transferMethodCategoryList);
|
return commonGenericTrees;
|
}
|
|
@SuppressWarnings("unchecked")
|
public List<CommonGenericTree> loadTree(List<TransferMethodCategory> transferMethodCategoryList) {
|
@SuppressWarnings("unused")
|
TransferMethodCategory transferMethodCategory = new TransferMethodCategory();
|
List<CommonGenericTree> list = new ArrayList<>();
|
Map<String, CommonGenericTree> map = new HashMap<>();
|
CommonGenericTree<TransferMethodCategory> node = new CommonGenericTree<>();
|
node.setKey("-1");
|
node.setValue("-1");
|
node.setTitle("增减方式分类");
|
node.setRField1("");
|
node.setRField2("");
|
node.setDisabled(false);
|
node.setEntity(new TransferMethodCategory());
|
list.add(node);
|
if (CollectionUtils.isNotEmpty(list)) {
|
CommonGenericTree<TransferMethodCategory> pcNode;
|
for (TransferMethodCategory tfc : transferMethodCategoryList) {
|
if (tfc.getParentId().equals("-1")) {
|
pcNode = new CommonGenericTree<>();
|
pcNode.setKey(tfc.getId());
|
pcNode.setTitle(tfc.getNum() + "/" + tfc.getName());
|
pcNode.setParentId(node.getKey());
|
pcNode.setIcon("");
|
pcNode.setType(0);
|
pcNode.setValue(tfc.getId());
|
pcNode.setDisabled(false);
|
pcNode.setRField1(tfc.getNum());
|
pcNode.setRField2(tfc.getName());
|
pcNode.setEntity(tfc);
|
node.addChildren(pcNode);
|
map.put(tfc.getId(), pcNode);
|
}
|
}
|
CommonGenericTree<TransferMethodCategory> childNode;
|
for (TransferMethodCategory tfc : transferMethodCategoryList) {
|
if (map.containsKey(tfc.getParentId())) {
|
pcNode = map.get(tfc.getParentId());
|
childNode = new CommonGenericTree<>();
|
childNode.setKey(tfc.getId());
|
childNode.setTitle(tfc.getNum() + "/" + tfc.getName());
|
childNode.setParentId(tfc.getParentId());
|
childNode.setIcon("");
|
childNode.setType(0);
|
childNode.setValue(tfc.getId());
|
childNode.setDisabled(false);
|
childNode.setRField1(tfc.getNum());
|
childNode.setRField2(tfc.getName());
|
childNode.setEntity(tfc);
|
pcNode.addChildren(childNode);
|
}
|
}
|
}
|
return list;
|
}
|
|
@Override
|
public void initFristTransferMethodCategory() {
|
String[] initList = initTransferMethodCategory.split(",");
|
if (initList.length > 0) {
|
TransferMethodCategory transferMethodCategory;
|
for (String categoryNumAndName : initList) {
|
if (CollectionUtils.isEmpty(
|
listByNumAndName(categoryNumAndName.split("-")[0], categoryNumAndName.split("-")[1]))) {
|
transferMethodCategory = new TransferMethodCategory();
|
transferMethodCategory.setParentId("-1");
|
transferMethodCategory.setNum(categoryNumAndName.split("-")[0]);
|
transferMethodCategory.setName(categoryNumAndName.split("-")[1]);
|
save(transferMethodCategory);
|
}
|
}
|
}
|
}
|
|
@Override
|
public List<TransferMethodCategory> listByNumAndName(String num, String name) {
|
return super.lambdaQuery().eq(TransferMethodCategory::getNum, num).eq(TransferMethodCategory::getName, name)
|
.orderByAsc(TransferMethodCategory::getNum).list();
|
}
|
|
|
@Override
|
public List<TransferMethodCategory> listByType(String type) {
|
return super.lambdaQuery().eq(TransferMethodCategory::getType, type)
|
.orderByAsc(TransferMethodCategory::getNum).list();
|
}
|
}
|