| | |
| | | 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); |
| | |
| | | |
| | | /** |
| | | * 修改焊缝 |
| | | * |
| | | * |
| | | * @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++) { |
| | | //记录临时表id |
| | | 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 {*/ |
| | | //插入正式表,并记录 |
| | | 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); |
| | | |
| | | //用Calendar 进行日期比较判断 |
| | | 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; |
| | | } |
| | | } |