From 71f44d71edeabfdcc83366127a2f1f40f5a8de3e Mon Sep 17 00:00:00 2001 From: 123456 <123456> Date: 星期三, 17 七月 2024 16:08:32 +0800 Subject: [PATCH] 费用统计分页查询功能修改 --- inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java | 156 +++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 123 insertions(+), 33 deletions(-) diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java index 7ad21ac..2e1b90b 100644 --- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java +++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderServiceImpl.java @@ -21,6 +21,7 @@ import com.yuanchu.mom.vo.SampleDefectsFatherVo; import lombok.AllArgsConstructor; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -147,8 +148,35 @@ } insSampleMapper.insert(a); if (ObjectUtil.isNotEmpty(a.getInsProduct())) { - //鏅�氭楠岄」鐩�(闄や簡鍏夌氦鎺ュご鎹熻��)鐨勬坊鍔� - addInsProductMethod(a.getId(), a.getInsProduct(), null, 0); + addInsProductMethod(a.getId(), a.getInsProduct(), null, 0, false); + if (ObjectUtil.isNotEmpty(a.getBushing())) { + for (BushingDto bushingDto : a.getBushing()) { + bushingDto.setInsSampleId(a.getId()); + insBushingMapper.insert(bushingDto); + if (bushingDto.getFiber().size() != 0) { + for (FiberDto fiberDto : bushingDto.getFiber()) { + fiberDto.setInsBushingId(bushingDto.getId()); + insFiberMapper.insert(fiberDto); + addInsProductMethod(a.getId(), a.getInsProduct(), fiberDto.getId(), 2, true); + addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false); + } + } else { + for (FibersDto fibersDto : bushingDto.getFibers()) { + fibersDto.setInsBushingId(bushingDto.getId()); + fibersDto.setCode(this.giveCode.giveCode("", "ins_fibers", "", "yyMMdd")); + insFibersMapper.insert(fibersDto); + for (FiberDto fiberDto : fibersDto.getFiber()) { + fiberDto.setInsFibersId(fibersDto.getId()); + insFiberMapper.insert(fiberDto); + addInsProductMethod(a.getId(), a.getInsProduct(), fiberDto.getId(), 2, true); + addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false); + } + //addInsProductMethod(a.getId(), a.getInsProduct(), fibersDto.getId(), 1); + addInsProductMethod(a.getId(), fibersDto.getProductList(), fibersDto.getId(), 1, false); + } + } + } + } } if (ObjectUtil.isNotEmpty(a.getInsulating())) { List<InsProduct> ip2 = new ArrayList<>(); @@ -158,13 +186,13 @@ for (InsProduct product : ip2) { product.setStandardMethodListId(a.getInsulating().getStandardMethodListId()); } - addInsProductMethod(a.getId(), ip2, null, 0); + addInsProductMethod(a.getId(), ip2, null, 0, false); } if (ObjectUtil.isNotEmpty(a.getSheath())) { for (InsProduct product : a.getSheath().getInsProduct()) { product.setStandardMethodListId(a.getSheath().getStandardMethodListId()); } - addInsProductMethod(a.getId(), a.getSheath().getInsProduct(), null, 0); + addInsProductMethod(a.getId(), a.getSheath().getInsProduct(), null, 0, false); } if (ObjectUtil.isNotEmpty(a.getChildSampleList())) { for (SampleProductDto b : a.getChildSampleList()) { @@ -177,12 +205,12 @@ } insSampleMapper.insert(b); if (ObjectUtil.isNotEmpty(b.getInsProduct())) { - addInsProductMethod(b.getId(), b.getInsProduct(), null, 0); + addInsProductMethod(b.getId(), b.getInsProduct(), null, 0, false); } } } } - if (ObjectUtil.isNotEmpty(a.getBushing())) { + if (ObjectUtil.isEmpty(a.getInsProduct()) && ObjectUtil.isNotEmpty(a.getBushing())) { for (BushingDto bushingDto : a.getBushing()) { bushingDto.setInsSampleId(a.getId()); insBushingMapper.insert(bushingDto); @@ -190,7 +218,7 @@ for (FiberDto fiberDto : bushingDto.getFiber()) { fiberDto.setInsBushingId(bushingDto.getId()); insFiberMapper.insert(fiberDto); - addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2); + addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false); } } else { for (FibersDto fibersDto : bushingDto.getFibers()) { @@ -200,9 +228,9 @@ for (FiberDto fiberDto : fibersDto.getFiber()) { fiberDto.setInsFibersId(fibersDto.getId()); insFiberMapper.insert(fiberDto); - addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2); + addInsProductMethod(a.getId(), fiberDto.getProductList(), fiberDto.getId(), 2, false); } - addInsProductMethod(a.getId(), fibersDto.getProductList(), fibersDto.getId(), 1); + addInsProductMethod(a.getId(), fibersDto.getProductList(), fibersDto.getId(), 1, false); } } } @@ -226,7 +254,7 @@ return insOrder.getId(); } - private void addInsProductMethod(Integer sampleId, List<InsProduct> productList, Integer id, Integer type) { + private void addInsProductMethod(Integer sampleId, List<InsProduct> productList, Integer id, Integer type, Boolean is) { InsOrder insOrder = insOrderMapper.selectById(insSampleMapper.selectById(sampleId).getInsOrderId()); for (InsProduct product : productList) { if (product.getState() == 1 && !product.getInspectionItem().equals("鍏夌氦鎺ュご鎹熻��")) { @@ -235,7 +263,9 @@ List<InsProduct> insProductes = new ArrayList<>(); List<InsProduct> insProducts = new ArrayList<>(); String[] strings = product.getAsk().split(";"); + for (int i = 0; i < strings.length; i++) { + int count = Integer.parseInt(strings[strings.length - 1]); if (i != strings.length - 1) { InsProduct insProduct = new InsProduct(); switch (type) { @@ -247,23 +277,40 @@ break; } String[] split = strings[i].split(","); - insProduct.setInspectionItem("1娆�");//妫�楠岄」--寰幆娆℃暟 + if (split[0].equals("20鈩�")) { + insProduct.setInspectionItem(count + "");//妫�楠岄」--寰幆娆℃暟 + } else { + insProduct.setInspectionItem("1");//妫�楠岄」--寰幆娆℃暟 + } insProduct.setInspectionItemSubclass(split[0]);//妫�楠岄」--娓╁害 insProduct.setInspectionItemClass(split[1]);//妫�楠岄」--鍏夌氦椤圭洰 insProduct.setAsk(split[2]);//妫�楠岃姹� insProduct.setTell(strings[i]);//妫�楠屾弿杩� + insProduct.setInsSampleId(sampleId); + insProduct.setState(1); + insProduct.setFactory(product.getFactory()); + insProduct.setLaboratory(product.getLaboratory()); + insProduct.setSampleType(product.getSampleType()); + insProduct.setSample(product.getSample()); + insProduct.setModel(product.getModel()); + insProduct.setSonLaboratory(product.getSonLaboratory()); + insProduct.setUnit(product.getUnit()); + insProduct.setManHourGroup(product.getManHourGroup()); + insProduct.setInspectionItemType("0"); + insProduct.setInspectionValueType("1"); insProducts.add(insProduct); insProductes.add(insProduct); } else { //鏈�鍚庝竴涓暟鎹槸璇存槑浼氬惊鐜灏戞 - int count = Integer.parseInt(strings[i]); if (count > 1) { //寰幆瓒呰繃1娆� for (int j = 2; j <= count; j++) { for (InsProduct insProduct : insProducts) { - if (!insProduct.getInspectionItemSubclass().equals("20鈩�")) { - insProduct.setInspectionItem(j + "娆�"); - insProductes.add(insProduct); + if (!insProduct.getInspectionItemSubclass().equals("20鈩�") && !insProduct.getInspectionItemSubclass().equals("20鈩�(甯告俯)")) { + InsProduct insProduct1 = new InsProduct(); + BeanUtils.copyProperties(insProduct, insProduct1); + insProduct1.setInspectionItem(j + ""); + insProductes.add(insProduct1); } } } @@ -272,24 +319,26 @@ } insProductService.saveBatch(insProductes); } else { - switch (type) { - case 1: - product.setInsFibersId(id); - break; - case 2: - product.setInsFiberId(id); - break; + if (!is) { + switch (type) { + case 1: + product.setInsFibersId(id); + break; + case 2: + product.setInsFiberId(id); + break; + } + product.setId(null); + product.setCreateTime(null); + product.setUpdateTime(null); + product.setUpdateTime(null); + product.setUpdateUser(null); + product.setInsSampleId(sampleId); + if (product.getInspectionItemSubclass() == null) { + product.setInspectionItemSubclass(""); + } + insProductMapper.insert(product); } - product.setId(null); - product.setCreateTime(null); - product.setUpdateTime(null); - product.setUpdateTime(null); - product.setUpdateUser(null); - product.setInsSampleId(sampleId); - if (product.getInspectionItemSubclass() == null) { - product.setInspectionItemSubclass(""); - } - insProductMapper.insert(product); } } } @@ -350,7 +399,48 @@ map.put("head", PrintChina.printChina(CostStatisticsDto.class)); Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("costStatistics"); if (map1.get("look") == 1) costStatisticsDto.setCreateUser(map1.get("userId")); - map.put("body", insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59"))); + IPage<CostStatisticsDto> costStatisticsDtoIPage = insOrderMapper.selectCostStatistics(page, QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59")); + List<CostStatisticsDto> costStatisticsDtoList = costStatisticsDtoIPage.getRecords(); + for (CostStatisticsDto statisticsDto : costStatisticsDtoList) { + statisticsDto.setNum(1); + } + List<CostStatisticsDto> costStatisticsDtoList1 = deduplicateAndSumCounts(costStatisticsDtoList); + costStatisticsDtoIPage.setRecords(costStatisticsDtoList1); + map.put("body", costStatisticsDtoIPage); + return map; + } + private static List<CostStatisticsDto> deduplicateAndSumCounts(List<CostStatisticsDto> list) { + // 浣跨敤涓�涓� Map 鏉ュ瓨鏀惧凡缁忓嚭鐜拌繃鐨� inspectionItem + entrustCode + sample 鐨勭粍鍚� + Map<String, CostStatisticsDto> map = new HashMap<>(); + // 閬嶅巻鍒楄〃杩涜鍘婚噸鍜岃鏁� + for (CostStatisticsDto dto : list) { + String key = dto.getInspectionItem() + dto.getEntrustCode() + dto.getSample(); + if (map.containsKey(key)) { + // 濡傛灉宸茬粡瀛樺湪锛屽垯绱姞鏁伴噺 + CostStatisticsDto existingDto = map.get(key); + existingDto.setNum(existingDto.getNum() + dto.getNum()); + existingDto.setPrice(existingDto.getPrice().add(dto.getPrice())); + } else { + // 濡傛灉涓嶅瓨鍦紝鍒欐斁鍏� Map 涓� + map.put(key, dto); + } + } + // 灏� Map 涓殑鍊艰浆涓� List 杩斿洖 + return new ArrayList<>(map.values()); + } + + @Override + public Map<String, Object> costStatistics2(CostStatisticsDto costStatisticsDto) { + Map<String, Object> map = new HashMap<>(); + String dates = costStatisticsDto.getDates(); + String[] split = dates.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(","); + costStatisticsDto.setDates(null); + List<CostStatisticsDto> costStatisticsDtos = insOrderMapper.selectCostStatistics2(QueryWrappers.queryWrappers(costStatisticsDto).ge("create_time", split[0]).le("create_time", split[1] + " 23:59:59")); + double totalPrice = costStatisticsDtos.stream() + .filter(dto -> dto.getPrice() != null) // 杩囨护鎺変环鏍间负 null 鐨勫璞� + .mapToDouble(value -> value.getPrice().doubleValue()) + .sum(); + map.put("total",totalPrice); return map; } -- Gitblit v1.9.3