¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.basic.service.impl; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import cn.hutool.poi.excel.ExcelUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.mapper.StandardMethodMapper; |
| | | import com.ruoyi.basic.mapper.StandardProductListMapper; |
| | | import com.ruoyi.basic.mapper.StructureItemParameterMapper; |
| | | import com.ruoyi.basic.pojo.StandardMethod; |
| | | import com.ruoyi.basic.pojo.StandardProductList; |
| | | import com.ruoyi.basic.pojo.StructureItemParameter; |
| | | import com.ruoyi.basic.service.StandardMethodService; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.basic.service.StandardProductListService; |
| | | import com.ruoyi.basic.service.StructureItemParameterService; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | |
| | | /** |
| | | * @author Administrator |
| | | * @description é对表ãstandard_method(æ åæ¹æ³)ãçæ°æ®åºæä½Serviceå®ç° |
| | | * @createDate 2024-03-03 19:21:41 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class StandardMethodServiceImpl extends ServiceImpl<StandardMethodMapper, StandardMethod> |
| | | implements StandardMethodService { |
| | | |
| | | |
| | | private StandardMethodMapper standardMethodMapper; |
| | | |
| | | StandardProductListMapper standardProductListMapper; |
| | | StandardProductListService standardProductListService; |
| | | |
| | | StructureItemParameterMapper structureItemParameterMapper; |
| | | StructureItemParameterService structureItemParameterService; |
| | | |
| | | @Override |
| | | public IPage<StandardMethod> selectStandardMethodList(Page page, StandardMethod standardMethod) { |
| | | return standardMethodMapper.selectStandardMethodList(page, QueryWrappers.queryWrappers(standardMethod)); |
| | | } |
| | | |
| | | @Override |
| | | public List<StandardMethod> selectStandardMethods() { |
| | | return standardMethodMapper.selectList(Wrappers.<StandardMethod>lambdaQuery().select(StandardMethod::getId, StandardMethod::getCode, StandardMethod::getName).ne(StandardMethod::getId, 0)); |
| | | } |
| | | |
| | | @Override |
| | | public int addStandardMethod(StandardMethod standardMethod) { |
| | | int insert = standardMethodMapper.insert(standardMethod); |
| | | return insert; |
| | | } |
| | | |
| | | @Override |
| | | public int delStandardMethod(Integer id) { |
| | | int i = standardMethodMapper.deleteById(id); |
| | | return i; |
| | | } |
| | | |
| | | @Override |
| | | public int upStandardMethod(StandardMethod standardMethod) { |
| | | StandardMethod oldStandardMethod = standardMethodMapper.selectById(standardMethod.getId()); |
| | | if (!oldStandardMethod.getCode().equals(standardMethod.getCode())) { |
| | | CompletableFuture.supplyAsync(() -> replaceMethod(oldStandardMethod.getCode(), standardMethod.getCode())); |
| | | } |
| | | int i = standardMethodMapper.updateById(standardMethod); |
| | | return i; |
| | | } |
| | | |
| | | //ç¼è¾methodåå
¨é¨æ¿æ¢ |
| | | public String replaceMethod(String oldCode, String code) { |
| | | //æ¥è¯¢StandardProductList䏿æMethod妿å
å«ä¹åçåæ¿æ¢ |
| | | List<StandardProductList> standardProductLists = standardProductListMapper.selectList(null); |
| | | for (StandardProductList standardProductList : standardProductLists) { |
| | | if (standardProductList.getMethod().contains(oldCode)) { |
| | | String[] split = standardProductList.getMethod().split(","); |
| | | String a = null; |
| | | for (int i = 0; i < split.length; i++) { |
| | | String methodName = split[i].substring(1, split[i].length() - 1); |
| | | if (i == 0) { |
| | | methodName = split[i].substring(2, split[i].length() - 1); |
| | | } else if (i == split.length - 1) { |
| | | methodName = split[i].substring(1, split[i].length() - 2); |
| | | } |
| | | if (methodName.equals(oldCode)) { |
| | | methodName = code; |
| | | } |
| | | a += "\"" + methodName + "\","; |
| | | } |
| | | String method = "[\"" + a.substring(0, a.length() - 1) + "\"]"; |
| | | standardProductList.setMethod(method); |
| | | } |
| | | } |
| | | standardProductListService.updateBatchById(standardProductLists); |
| | | //æ¥è¯¢StructureItemParameter䏿æMethod妿å
å«ä¹åçåæ¿æ¢ |
| | | List<StructureItemParameter> structureItemParameters = structureItemParameterMapper.selectList(null); |
| | | for (StructureItemParameter structureItemParameter : structureItemParameters) { |
| | | if (structureItemParameter.getMethod().contains(oldCode)) { |
| | | String[] split = structureItemParameter.getMethod().split(","); |
| | | String a = null; |
| | | for (int i = 0; i < split.length; i++) { |
| | | String methodName = split[i].substring(1, split[i].length() - 1); |
| | | if (i == 0) { |
| | | methodName = split[i].substring(2, split[i].length() - 1); |
| | | } else if (i == split.length - 1) { |
| | | methodName = split[i].substring(1, split[i].length() - 2); |
| | | } |
| | | if (methodName.equals(oldCode)) { |
| | | methodName = code; |
| | | } |
| | | a += "\"" + methodName + "\","; |
| | | } |
| | | String method = "[\"" + a.substring(0, a.length() - 1) + "\"]"; |
| | | structureItemParameter.setMethod(method); |
| | | } |
| | | } |
| | | structureItemParameterService.updateBatchById(structureItemParameters); |
| | | return "æ¿æ¢å®æ¯!"; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void inputExcel(MultipartFile file) throws IOException { |
| | | // å卿£æµå¯¹è±¡List |
| | | List<Object> structureTestObjectIdList = new ArrayList<>(); |
| | | List<StandardMethod> result = new ArrayList<>(); |
| | | ExcelUtil.readBySax(file.getInputStream(), 0, (i, l, list) -> { |
| | | // å»é¤ç¬¬ä¸è¡è¡¨å¤´ |
| | | if (l == 0) { |
| | | return; |
| | | } |
| | | // åå¨å¯ä¸æ£æµå¯¹è±¡ |
| | | if (!structureTestObjectIdList.contains(list.get(2))) { |
| | | structureTestObjectIdList.add(list.get(2)); |
| | | } |
| | | StandardMethod standardMethod = formatData(list); |
| | | result.add(standardMethod); |
| | | }); |
| | | addStructureTest(structureTestObjectIdList, result); |
| | | } |
| | | |
| | | // æ ¼å¼åæ°æ® |
| | | public StandardMethod formatData(List<Object> list) { |
| | | StandardMethod standardMethod = new StandardMethod(); |
| | | standardMethod.setField(list.get(1).toString()); |
| | | // é æ ¼å¼ |
| | | List<List<Object>> structureTestObjectId = new ArrayList<>(); |
| | | if (ObjectUtils.isEmpty(list.get(3))) { |
| | | structureTestObjectId.add(Arrays.asList(list.get(2))); |
| | | } else { |
| | | structureTestObjectId.add(Arrays.asList(list.get(2), list.get(3))); |
| | | } |
| | | standardMethod.setStructureTestObjectId(JSONUtil.toJsonStr(structureTestObjectId)); |
| | | standardMethod.setCode(list.get(4).toString()); |
| | | standardMethod.setName(list.get(5).toString()); |
| | | standardMethod.setNameEn(list.get(6).toString()); |
| | | if (!Objects.equals(list.get(7), null)) { |
| | | standardMethod.setRemark(list.get(7).toString()); |
| | | } |
| | | standardMethod.setQualificationId(list.get(8).toString()); |
| | | if (ObjectUtils.isNotEmpty(list.get(9))) { |
| | | if (list.get(9).equals("æ¯")) { |
| | | standardMethod.setIsProduct(1); |
| | | } else if (list.get(9).equals("å¦")) { |
| | | standardMethod.setIsProduct(0); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(list.get(10))) { |
| | | if (list.get(10).equals("æ¯")) { |
| | | standardMethod.setIsUse(1); |
| | | } else if (list.get(9).equals("å¦")) { |
| | | standardMethod.setIsUse(0); |
| | | } |
| | | } |
| | | return standardMethod; |
| | | } |
| | | |
| | | // æ°å¢æ°æ® |
| | | public void addStructureTest(List<Object> structureTestObjectIdList, List<StandardMethod> standardMethodList) { |
| | | List<StandardMethod> updateList = new ArrayList<>(); |
| | | List<Integer> deleteListId = new ArrayList<>(); |
| | | List<StandardMethod> addList = new ArrayList<>(); |
| | | if (!structureTestObjectIdList.isEmpty()) { |
| | | // 循ç¯exceléé¢çåç» |
| | | structureTestObjectIdList.forEach(j -> { |
| | | // 以excelä¸çç»åæ¥è¯¢æ°æ®åºä¸çåç» |
| | | List<StandardMethod> standardMethods = baseMapper.selectList(Wrappers.<StandardMethod>lambdaQuery() |
| | | .like(StandardMethod::getStructureTestObjectId, "\"" + j + "\"")); |
| | | // å°ç»æå¾ªç¯å¹é
|
| | | for (int i = 0; i < standardMethods.size(); i++) { |
| | | boolean isExistence = false; |
| | | for (int i1 = 0; i1 < standardMethodList.size(); i1++) { |
| | | // æ´æ° |
| | | if (standardMethods.get(i).getStructureTestObjectId().equals(standardMethodList.get(i1).getStructureTestObjectId()) |
| | | && standardMethods.get(i).getCode().equals(standardMethodList.get(i1).getCode()) |
| | | && standardMethods.get(i).getField().equals(standardMethodList.get(i1).getField())) { |
| | | // ç»excelæ°æ®èµå¼idåæ´æ° |
| | | standardMethodList.get(i1).setId(standardMethods.get(i).getId()); |
| | | // æ´æ° |
| | | updateList.add(standardMethodList.get(i1)); |
| | | isExistence = true; |
| | | break; |
| | | } |
| | | } |
| | | // å é¤ |
| | | if (!isExistence) { |
| | | deleteListId.add(standardMethods.get(i).getId()); |
| | | } |
| | | } |
| | | for (int i = 0; i < standardMethodList.size(); i++) { |
| | | if (standardMethodList.get(i).getStructureTestObjectId().contains("\"" + j + "\"")) { |
| | | boolean isExistence = false; |
| | | for (int i1 = 0; i1 < standardMethods.size(); i1++) { |
| | | if (standardMethods.get(i1).getStructureTestObjectId().equals(standardMethodList.get(i).getStructureTestObjectId()) |
| | | && standardMethods.get(i1).getCode().equals(standardMethodList.get(i).getCode()) |
| | | && standardMethods.get(i1).getField().equals(standardMethodList.get(i).getField())) { |
| | | isExistence = true; |
| | | break; |
| | | } |
| | | } |
| | | // æ°å¢ |
| | | if (!isExistence) { |
| | | addList.add(standardMethodList.get(i)); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | if (!addList.isEmpty()) { |
| | | // æ°å¢ |
| | | baseMapper.insertBatchSomeColumn(addList); |
| | | } |
| | | |
| | | if (!deleteListId.isEmpty()) { |
| | | // å é¤ |
| | | baseMapper.deleteBatchIds(deleteListId); |
| | | } |
| | | |
| | | if (!updateList.isEmpty()) { |
| | | // æ´æ° |
| | | updateList.forEach(i -> { |
| | | baseMapper.updateById(i); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |