package com.ruoyi.basic.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.basic.mapper.StandardMethodListMapper; import com.ruoyi.basic.mapper.StandardProductListMapper; import com.ruoyi.basic.mapper.WorkShopMapper; import com.ruoyi.basic.pojo.StandardMethodList; import com.ruoyi.basic.pojo.StandardProductList; import com.ruoyi.basic.pojo.WorkShop; import com.ruoyi.basic.service.StandardMethodListService; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author Administrator * @description 针对表【standard_method_list(标准树下的标准列表)】的数据库操作Service实现 * @createDate 2024-03-04 13:44:04 */ @Service @AllArgsConstructor public class StandardMethodListServiceImpl extends ServiceImpl implements StandardMethodListService{ private StandardMethodListMapper standardMethodListMapper; private StandardProductListMapper standardProductListMapper; @Autowired private WorkShopMapper workShopMapper; @Override public Map> selectsStandardMethodByFLSSM(String tree) { // 判断是否包含车间 boolean workshopExist = existWorkShop(tree); Map> map = new HashMap<>(); String str = ""; List standardMethodLists = new ArrayList<>(); String[] trees = tree.split(" - "); if(trees != null && trees.length >= 4){ // 判断是否有车间 if(workshopExist){ switch (trees.length - 4){ case 3: str += "\"" + trees[4] + "\",\"" + trees[5] + "\",\"" + trees[6] + "\""; standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists(str)); standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[4] + "\",\"" + trees[5] + "\"")); standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[4] + "\"")); break; case 2: str += "\"" + trees[4] + "\",\"" + trees[5] + "\""; standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists(str)); standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[4] + "\"")); break; case 1: str += "\"" + trees[4] + "\""; standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists3(str)); break; default: map.put("standardMethodList", null); return map; } }else { switch (trees.length - 4){ case 2: str += "\"" + trees[3] + "\",\"" + trees[4] + "\",\"" + trees[5] + "\""; standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists(str)); standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[3] + "\",\"" + trees[4] + "\"")); standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[3] + "\"")); break; case 1: str += "\"" + trees[3] + "\",\"" + trees[4] + "\""; standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists(str)); standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[3] + "\"")); break; case 0: str += "\"" + trees[3] + "\""; standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists3(str)); break; default: map.put("standardMethodList", null); return map; } } }else { standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodListsByNull(str)); } map.put("standardMethodList", standardMethodLists); return map; } @Override public List selectStandardMethodEnum() { return standardMethodListMapper.selectListEnum(); } @Override public Integer getStandardMethodId(String code) { return baseMapper.getStandardMethodId(code); } /** * 判断是否包含车间 * * @param tree * @return */ @Override public boolean existWorkShop(String tree){ QueryWrapper queryWrapper = new QueryWrapper<>(); List workShopList = workShopMapper.selectList(queryWrapper); String[] trees = tree.split(" - "); if(trees != null && trees.length > 0){ for (int i = 0; i < trees.length; i++) { for (WorkShop workShop : workShopList) { if(workShop.getName().equals(trees[i].trim())){ return true; } } } } return false; } }