From 2a64b537e8e3bce9ce030585a3da17d48379c0ad Mon Sep 17 00:00:00 2001 From: sfd <sun.sunshine@163.com> Date: 星期一, 26 五月 2025 15:04:45 +0800 Subject: [PATCH] 修改json类型转换错误 --- aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsWeldSeamServiceImpl.java | 265 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 225 insertions(+), 40 deletions(-) diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsWeldSeamServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsWeldSeamServiceImpl.java index 172c122..761f9b4 100644 --- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsWeldSeamServiceImpl.java +++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsWeldSeamServiceImpl.java @@ -1,66 +1,71 @@ package com.aps.core.service.impl; -import java.util.List; - import com.aps.common.core.utils.DateUtils; import com.aps.common.core.utils.StringUtils; import com.aps.common.core.utils.uuid.IdUtils; -import com.aps.core.domain.*; +import com.aps.common.security.utils.SecurityUtils; +import com.aps.core.domain.ApsWeldSeam; +import com.aps.core.domain.ApsWeldSeamStatistics; +import com.aps.core.domain.ApsWeldSeamTemp; +import com.aps.core.mapper.ApsWeldSeamMapper; +import com.aps.core.mapper.ApsWeldSeamStatisticsMapper; import com.aps.core.mapper.ApsWeldSeamTempMapper; +import com.aps.core.service.IApsWeldSeamService; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.aps.core.mapper.ApsWeldSeamMapper; -import com.aps.core.service.IApsWeldSeamService; import org.springframework.transaction.annotation.Transactional; + +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; /** * 鐒婄紳Service涓氬姟灞傚鐞� - * + * * @author wwj * @date 2025-04-09 */ @Service -public class ApsWeldSeamServiceImpl implements IApsWeldSeamService -{ +public class ApsWeldSeamServiceImpl implements IApsWeldSeamService { @Autowired private ApsWeldSeamMapper apsWeldSeamMapper; @Autowired private ApsWeldSeamTempMapper apsWeldSeamTempMapper; + @Autowired + private ApsWeldSeamStatisticsMapper apsWeldSeamStatisticsMapper; /** * 鏌ヨ鐒婄紳 - * + * * @param id 鐒婄紳涓婚敭 * @return 鐒婄紳 */ @Override - public ApsWeldSeam selectApsWeldSeamById(String id) - { + public ApsWeldSeam selectApsWeldSeamById(String id) { return apsWeldSeamMapper.selectApsWeldSeamById(id); } /** * 鏌ヨ鐒婄紳鍒楄〃 - * + * * @param apsWeldSeam 鐒婄紳 * @return 鐒婄紳 */ @Override - public List<ApsWeldSeam> selectApsWeldSeamList(ApsWeldSeam apsWeldSeam) - { + public List<ApsWeldSeam> selectApsWeldSeamList(ApsWeldSeam apsWeldSeam) { return apsWeldSeamMapper.selectApsWeldSeamList(apsWeldSeam); } /** * 鏂板鐒婄紳 - * + * * @param apsWeldSeam 鐒婄紳 * @return 缁撴灉 */ @Override - public int insertApsWeldSeam(ApsWeldSeam apsWeldSeam) - { + public int insertApsWeldSeam(ApsWeldSeam apsWeldSeam) { apsWeldSeam.setId(IdUtils.fastUUID()); apsWeldSeam.setCreateTime(DateUtils.getNowDate()); return apsWeldSeamMapper.insertApsWeldSeam(apsWeldSeam); @@ -68,70 +73,250 @@ /** * 淇敼鐒婄紳 - * + * * @param apsWeldSeam 鐒婄紳 * @return 缁撴灉 */ @Override - public int updateApsWeldSeam(ApsWeldSeam apsWeldSeam) - { + public int updateApsWeldSeam(ApsWeldSeam apsWeldSeam) { return apsWeldSeamMapper.updateApsWeldSeam(apsWeldSeam); } /** * 鎵归噺鍒犻櫎鐒婄紳 - * + * * @param ids 闇�瑕佸垹闄ょ殑鐒婄紳涓婚敭 * @return 缁撴灉 */ @Override - public int deleteApsWeldSeamByIds(String[] ids) - { + public int deleteApsWeldSeamByIds(String[] ids) { return apsWeldSeamMapper.deleteApsWeldSeamByIds(ids); } /** * 鍒犻櫎鐒婄紳淇℃伅 - * + * * @param id 鐒婄紳涓婚敭 * @return 缁撴灉 */ @Override - public int deleteApsWeldSeamById(String id) - { + public int deleteApsWeldSeamById(String id) { return apsWeldSeamMapper.deleteApsWeldSeamById(id); } + @Transactional @Override public int confirmWeldSeam(ApsWeldSeamTemp apsWeldSeamTemp) { //鏌ヨ涓存椂琛ㄦ暟鎹� - List<ApsWeldSeamTemp> apsWeldSeamTemps=apsWeldSeamTempMapper.selectApsWeldSeamTempList(apsWeldSeamTemp); - int count=0; - String[] ids=new String[apsWeldSeamTemps.size()]; - for (int i = 0; i <apsWeldSeamTemps.size() ; i++) { + List<ApsWeldSeamTemp> apsWeldSeamTemps = apsWeldSeamTempMapper.selectApsWeldSeamTempList(apsWeldSeamTemp); + int count = 0; + String[] ids = new String[apsWeldSeamTemps.size()]; + apsWeldSeamMapper.removeLastBatch(); + for (int i = 0; i < apsWeldSeamTemps.size(); i++) { //璁板綍涓存椂琛╥d - ids[i]=apsWeldSeamTemps.get(i).getId(); - ApsWeldSeam apsWeldSeam=new ApsWeldSeam(); + ids[i] = apsWeldSeamTemps.get(i).getId(); + ApsWeldSeam apsWeldSeam = new ApsWeldSeam(); BeanUtils.copyProperties(apsWeldSeamTemps.get(i), apsWeldSeam); //閫氳繃宸ュ崟鍙锋煡璇㈡槸鍚﹀瓨鍦ㄦ暟鎹� - ApsWeldSeam apsWeldSeam1=apsWeldSeamMapper.selectApsWeldSeamByWorkOrderNo(apsWeldSeam.getWorkOrderNo()); + /*ApsWeldSeam apsWeldSeam1 = apsWeldSeamMapper.selectApsWeldSeamByWorkOrderNo(apsWeldSeam.getWorkOrderNo()); //褰撳伐鍗曞彿瀛樺湪鍒欐洿鏂版暟鎹惁鍒欐彃鍏ユ暟鎹� - if(StringUtils.isNotEmpty(apsWeldSeam1.getId())){ + if (apsWeldSeam1!=null&&apsWeldSeam1.getId()!=null) { apsWeldSeam.setId(apsWeldSeam1.getId()); apsWeldSeamMapper.updateApsWeldSeam(apsWeldSeam); - }else { + } else {*/ //鎻掑叆姝e紡琛紝骞惰褰� - apsWeldSeam.setId(IdUtils.fastUUID()); - apsWeldSeamMapper.insertApsWeldSeam(apsWeldSeam); - } + apsWeldSeam.setId(IdUtils.fastUUID()); + apsWeldSeamMapper.insertApsWeldSeam(apsWeldSeam); + //} count++; } //鎻掑叆鏁伴噺涓庝复鏃惰〃鏌ヨ涓�鐩村垯鍒犻櫎涓存椂琛ㄦ暟鎹� - if (count==apsWeldSeamTemps.size()) { + if (count == apsWeldSeamTemps.size()) { apsWeldSeamTempMapper.deleteApsWeldSeamTempByIds(ids); } + /*鍒犻櫎鏃ф暟鎹�*/ + apsWeldSeamStatisticsMapper.removeLastBatch(); //鎻掑叆鐒婄紳缁熻琛� - List<ApsWeldSeamStatistics> apsWeldSeamStatistics=apsWeldSeamMapper.weldSeamStat(apsWeldSeamTemps); + List<ApsWeldSeamStatistics> apsWeldSeamStatistics = apsWeldSeamMapper.weldSeamStat(apsWeldSeamTemps); + + List<Long> years = apsWeldSeamStatistics.stream().map(ApsWeldSeamStatistics::getYear).distinct().toList(); + List<Long> months = apsWeldSeamStatistics.stream().map(ApsWeldSeamStatistics::getMonth).distinct().toList(); + List<String> bases = apsWeldSeamStatistics.stream().map(ApsWeldSeamStatistics::getProductionBase).distinct().toList(); + /*宸ュ崟绫诲瀷锛氳鍗�*/ + String WorkOrderType_Order="0"; + /*宸ュ崟绫诲瀷锛氶娴�*/ + String WorkOrderType_Prediction="1"; + /*绫诲瀷锛氭皵浣�*/ + String Classification_Gas="0"; + /*绫诲瀷锛氱璺�*/ + String Classification_Piping="1"; + for (Long year : years) { + for (Long month : months) { + for (String basis : bases) { + List<ApsWeldSeamStatistics> list = apsWeldSeamStatistics.stream() + .filter(x -> x.getYear().equals(year) && x.getMonth().equals(month) && x.getProductionBase().equals(basis)).toList(); + + long gasOrderRequirement = list.stream().filter(x -> x.getWorkOrderType().equals(WorkOrderType_Order) && x.getClassification().equals(Classification_Gas)) + .mapToLong(ApsWeldSeamStatistics::getTotal).sum(); + long gasPredictionRequirement = list.stream().filter(x -> x.getWorkOrderType().equals(WorkOrderType_Prediction) && x.getClassification().equals(Classification_Gas)) + .mapToLong(ApsWeldSeamStatistics::getTotal).sum(); + long pipingOrderRequirement = list.stream().filter(x -> x.getWorkOrderType().equals(WorkOrderType_Order) && x.getClassification().equals(Classification_Piping)) + .mapToLong(ApsWeldSeamStatistics::getTotal).sum(); + long pipingPredictionRequirement = list.stream().filter(x -> x.getWorkOrderType().equals(WorkOrderType_Prediction) && x.getClassification().equals(Classification_Piping)) + .mapToLong(ApsWeldSeamStatistics::getTotal).sum(); + long total = gasOrderRequirement + gasPredictionRequirement + pipingOrderRequirement + pipingPredictionRequirement; + if(total>0) { + ApsWeldSeamStatistics seamStatistics = new ApsWeldSeamStatistics(); + seamStatistics.setId(IdUtils.fastSimpleUUID()); + seamStatistics.setYear(year); + seamStatistics.setMonth(month); + seamStatistics.setProductionBase(basis); + seamStatistics.setPipingOrderRequirement(pipingOrderRequirement); + seamStatistics.setPipingPredictionRequirement(pipingPredictionRequirement); + seamStatistics.setGasOrderRequirement(gasOrderRequirement); + seamStatistics.setGasPredictionRequirement(gasPredictionRequirement); + seamStatistics.setTotal(total); + seamStatistics.setCreateTime(DateUtils.getNowDate()); + seamStatistics.setCreateBy(SecurityUtils.getUsername()); + apsWeldSeamStatisticsMapper.insertApsWeldSeamStatistics(seamStatistics); + } + } + } + + } + + + /*for (int i = 0; i < apsWeldSeamStatistics.size(); i++) { + List<ApsWeldSeamStatistics> apsWeldSeamStatistics1 = apsWeldSeamStatisticsMapper.selectApsWeldSeamStatisticsList(apsWeldSeamStatistics.get(i)); + if (apsWeldSeamStatistics1.size() > 0) { + + ApsWeldSeamStatistics apsWeldSeamStatistics2 = apsWeldSeamStatistics1.get(0); + + apsWeldSeamStatistics2.setPipingOrderRequirement(apsWeldSeamStatistics.get(i).getPipingOrderRequirement()); + apsWeldSeamStatistics2.setGasOrderRequirement(apsWeldSeamStatistics.get(i).getGasOrderRequirement()); + apsWeldSeamStatistics2.setPipingPredictionRequirement(apsWeldSeamStatistics.get(i).getPipingPredictionRequirement()); + apsWeldSeamStatistics2.setGasPredictionRequirement(apsWeldSeamStatistics.get(i).getGasPredictionRequirement()); + + //棰勭暀绱ф�ヨ鍗曚骇鍑烘槸鍚︿负绌� + if (apsWeldSeamStatistics2.getReserveEmergencyOrderOutput() != null) { + apsWeldSeamStatistics2.setTotal(apsWeldSeamStatistics2.getPipingOrderRequirement() + apsWeldSeamStatistics2.getPipingPredictionRequirement() + apsWeldSeamStatistics2.getGasOrderRequirement() + apsWeldSeamStatistics2.getGasPredictionRequirement() + apsWeldSeamStatistics2.getReserveEmergencyOrderOutput()); + //澶╂暟涓嶄负绌鸿绠楅渶姹傛棩鐒婄紳 + if(apsWeldSeamStatistics2.getDays()!=null){ + // 杞崲涓� double 绫诲瀷杩涜闄ゆ硶杩愮畻 + double result = (double) apsWeldSeamStatistics2.getTotal() / apsWeldSeamStatistics2.getDays(); + // 鍥涜垗浜斿叆 + long roundedResult = Math.round(result); + apsWeldSeamStatistics2.setRequirementDayWeldSeam(roundedResult); + //鍒ゆ柇鐢熶骇鏃ョ剨缂濅笉涓虹┖璁$畻鏄惁婊¤冻 + if(apsWeldSeamStatistics2.getProductionDayWeldSeam()!=null){ + if(apsWeldSeamStatistics2.getProductionDayWeldSeam()>=apsWeldSeamStatistics2.getRequirementDayWeldSeam()){ + apsWeldSeamStatistics2.setIsSatisfy("鏄�"); + }else{ + apsWeldSeamStatistics2.setIsSatisfy("鍚�"); + } + } + } + } + apsWeldSeamStatisticsMapper.updateApsWeldSeamStatistics(apsWeldSeamStatistics2); + }else { + apsWeldSeamStatistics.get(i).setId(IdUtils.fastUUID()); + apsWeldSeamStatistics.get(i).setCreateTime(DateUtils.getNowDate()); + apsWeldSeamStatisticsMapper.insertApsWeldSeamStatistics(apsWeldSeamStatistics.get(i)); + } + + }*/ return 1; } + + @Override + public List<List<String>> weldSeamEchartsList(ApsWeldSeam apsWeldSeam) { + + List<ApsWeldSeam> queryDataList = new ArrayList<>(); + Map<String, Object> params = apsWeldSeam.getParams(); + if(ObjectUtils.isNotEmpty(params)){ + String startDay = params.get("startDay").toString(); + String endDay = params.get("endDay").toString(); + List<String> dateList = getMonthBetweenDate(startDay,endDay); + dateList.forEach(item->{ + ApsWeldSeam weldSeam = new ApsWeldSeam(); + String queryYear = item.substring(0,4); + String queryMonth = item.substring(6,7); + weldSeam.setProduceYear(Long.valueOf(queryYear)); + weldSeam.setProduceMonth(Long.valueOf(queryMonth)); + queryDataList.add(weldSeam); + }); + } + List<Map> mapList =apsWeldSeamMapper.weldSeamEcharts(queryDataList); + Set monthSet=mapList.stream().map(e->e.get("produce_month")).collect(Collectors.toSet()); + List monthList = new ArrayList(monthSet); + Collections.sort(monthList); + + List<List<String>> echartsList = new ArrayList<>(); + + Set<String> titleSet = new HashSet<>(); + mapList.forEach(item->{ + StringBuilder sb = new StringBuilder(); + sb.append(item.get("production_base")); + sb.append("-"); + sb.append(item.get("work_order_name")); + sb.append("-"); + sb.append(item.get("classification_name")); + titleSet.add(sb.toString()); + }); + List<String> title = new ArrayList<>(); + title.add("product"); + title.addAll(titleSet); + echartsList.add(title); + monthList.forEach(month->{ + List<String> table = new ArrayList<>(); + table.add(month+"鏈�"); + for (int i=1;i<title.size();i++){ + for(int j=0;j<mapList.size();j++){ + Map value =mapList.get(j); + StringBuilder sb = new StringBuilder(); + sb.append(value.get("production_base")); + sb.append("-"); + sb.append(value.get("work_order_name")); + sb.append("-"); + sb.append(value.get("classification_name")); + if(sb.toString().equals(title.get(i)) && month==value.get("produce_month")){ + table.add(value.get("total_weld_seam").toString()); + } + } + } + echartsList.add(table); + }); + return echartsList; + } + + public static List<String> getMonthBetweenDate(String startTime, String endTime) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); + // 澹版槑淇濆瓨鏃ユ湡闆嗗悎 + List<String> list = new ArrayList<>(); + try { + // 杞寲鎴愭棩鏈熺被鍨� + Date startDate = sdf.parse(startTime); + Date endDate = sdf.parse(endTime); + + //鐢–alendar 杩涜鏃ユ湡姣旇緝鍒ゆ柇 + Calendar calendar = Calendar.getInstance(); + while (startDate.getTime() <= endDate.getTime()) { + + // 鎶婃棩鏈熸坊鍔犲埌闆嗗悎 + list.add(sdf.format(startDate)); + + // 璁剧疆鏃ユ湡 + calendar.setTime(startDate); + + //鎶婃湀鏁板鍔� 1 + calendar.add(Calendar.MONTH, 1); + + // 鑾峰彇澧炲姞鍚庣殑鏃ユ湡 + startDate = calendar.getTime(); + } + } catch (Exception e) { + e.printStackTrace(); + } + return list; + } } -- Gitblit v1.9.3