package com.steerinfo.dil.service.impl; import com.google.gson.JsonObject; import com.steerinfo.dil.mapper.StatisticalReportMapper; import com.steerinfo.dil.service.IStatisticalReportService; import com.steerinfo.dil.util.DataChange; import com.steerinfo.dil.util.PageListAdd; import com.steerinfo.framework.controller.RESTfulResult; import oracle.sql.DATE; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestBody; import java.math.BigDecimal; import java.util.*; /** * @ author :TXF * @ time :2021/12/14 15:26 */ @Service public class StatisticalReportImpl implements IStatisticalReportService { @Autowired StatisticalReportMapper statisticalReportMapper; /** * 计算相差时间 * @return */ public void calculateDifferenceTime(Map mesMap){ Object resultEntryGateTime = mesMap.get("resultEntryGateTime"); Object resultOutGateTime = mesMap.get("resultOutGateTime"); if(resultEntryGateTime != null && resultOutGateTime != null){ Date enterDate = (Date) resultEntryGateTime; Date outDate = (Date) resultOutGateTime; //计算相差时间 long dTime = outDate.getTime() - enterDate.getTime(); mesMap.put("inPlantDwellTime", dTime / 60000 + "分钟"); } if(resultEntryGateTime != null && resultOutGateTime == null){ //如果没有出厂时间则以当前时间减去进厂时间 Date enterDate = (Date) resultEntryGateTime; long dTime = new Date().getTime() - enterDate.getTime(); mesMap.put("inPlantDwellTime", dTime / 60000 + "分钟"); } } /** * 查询采购统计报表 * @Author TXF * @Date 2022/1/6 9:52 * @param map * @return **/ public List> getRLFLReport(Map map){ List> mapList = null; if(DataChange.dataToBigDecimal(map.get("orderTypee")).intValue() == 5){ mapList = statisticalReportMapper.getFuPurchaseFLRLReport(map); }else { mapList = statisticalReportMapper.getAllPurchaseFLRLReport(map); } return mapList; } @Override public List> getAllPurchaseFLRLReport(Map map) { return statisticalReportMapper.getAllPurchaseFLRLReport(map); } /** * 查询销售统计报表 * @param map * @return */ @Override public List> getAllSaleReport(Map map) { List> mapList = statisticalReportMapper.getAllSaleReport(map); /*for(Map map1 : mapList) { if ( map1.get("resultEntryGateTime") == null) { map1.put("transportStatus", "未进厂"); continue; } if (map1.get("resultOutGateTime") == null) { map1.put("transportStatus", "已进厂"); continue; } if (map1.get("arrivalAddress") == null) { map1.put("transportStatus", "已出厂"); continue; } if (map1.get("receiptAddress") == null) { map1.put("transportStatus", "已抵达"); continue; } else{ map1.put("transportStatus", "已签收"); } }*/ for (Map mesMap : mapList) { calculateDifferenceTime(mesMap); } return mapList; } @Override public List> getAllSaleReportNum(Map map) { List> listMap = statisticalReportMapper.getAllSaleReport(map); return listMap; } /** * 查询零星物资进厂统计报表 */ @Override public List> getSporadicSuppliesReportNum1(Map mapValue) { return statisticalReportMapper.getSporadicSuppliesReport1(mapValue); } @Override public List> getSporadicSuppliesReport1(Map mapValue) { List> mapList = statisticalReportMapper.getSporadicSuppliesReport1(mapValue); for (Map mesMap : mapList) { calculateDifferenceTime(mesMap); } return mapList; } /** * 查询零星物资出厂统计报表 */ @Override public List> getSporadicSuppliesReportNum2(Map mapValue) { return statisticalReportMapper.getSporadicSuppliesReport2(mapValue); } @Override public List> getSporadicSuppliesReport2(Map mapValue) { List> mapList = statisticalReportMapper.getSporadicSuppliesReport2(mapValue); for (Map mesMap : mapList) { calculateDifferenceTime(mesMap); } return mapList; } //采购内转统计报表 @Override public List> getPurInwardReport( Map mapValue) { List> inwardReportResult = statisticalReportMapper.getInwardReportResult(mapValue); for (MapinwardReport:inwardReportResult ) { if(DataChange.dataToBigDecimal(inwardReport.get("orderType")).intValue() == 10){ inwardReport.put("transRange","化工园区铁专线-焦化二厂"); }else{ inwardReport.put("transRange","化工园区铁专线-达钢厂区"); } BigDecimal netWeightSecond = DataChange.dataToBigDecimal(inwardReport.get("netWeightSecond")); BigDecimal netWeightFirst = DataChange.dataToBigDecimal(inwardReport.get("netWeightFirst")); BigDecimal netTract = netWeightSecond.subtract(netWeightFirst).divide(new BigDecimal(1), 2, 4); //第二次净重减第一次净重 inwardReport.put("newTract",netTract); calculateDifferenceTime(inwardReport); } return inwardReportResult; } //采购内转统计报表 @Override public List> getLXInwardReport( Map mapValue) { List> lxReportResult = statisticalReportMapper.getLXReportResult(mapValue); for (MapinwardReport:lxReportResult ) { BigDecimal netWeightSecond = DataChange.dataToBigDecimal(inwardReport.get("netWeightSecond")); BigDecimal netWeightFirst = DataChange.dataToBigDecimal(inwardReport.get("netWeightFirst")); BigDecimal netTract = netWeightSecond.subtract(netWeightFirst).divide(new BigDecimal(1), 2, 4); //第二次净重减第一次净重 inwardReport.put("newTract",netTract); calculateDifferenceTime(inwardReport); } return lxReportResult; } @Override public List> getInwardReport(Map mapValue) { return statisticalReportMapper.getInwardReport(mapValue); } @Override public List> getLoading(Map mapValue) { return statisticalReportMapper.getLoading(mapValue); } @Override public List> getUnLoading(Map mapValue) { return statisticalReportMapper.getUnLoading(mapValue); } @Override public List> getLoaderResult(Map mapValue) { return statisticalReportMapper.getLoaderResult(mapValue); } @Override public List> getCapacityByDefend(Map map) { return statisticalReportMapper.getCapacityByDefend(map); } @Override public List> getInwardReportForAssemble(Map mapValue) { return statisticalReportMapper.getInwardReportForAssemble(mapValue); } @Override public List> getLoaderForResultDetail(Map mapValue) { //判断是否含有装机备注 return statisticalReportMapper.getLoaderForResultDetail(mapValue); } //查看该组织架构下的销售订单统计报表 @Override public List> getSaleOrderList(Map mapValue) { return statisticalReportMapper.getSaleOrderList(mapValue); } //查看该组织架构下的采购订单统计报表 @Override public List> getPurchaseOrderList(Map mapValue) { return statisticalReportMapper.getPurchaseOrderList(mapValue); } //查看该组织架构下的采购内转统计报表 @Override public List> getPurchaseInwardList(Map mapValue) { return statisticalReportMapper.getPurchaseInwardList(mapValue); } //查看该组织架构下的内转统计报表 @Override public List> getInwardInFactory(Map mapValue) { return statisticalReportMapper.getInwardInFactory(mapValue); } @Override public List> getOutFactoryInwardList(Map mapValue) { return statisticalReportMapper.getOutFactoryInwardList(mapValue); } @Override public List> getSaleSteelReport(Map mapValue) { List> saleSteelReport = statisticalReportMapper.getSaleSteelReport(mapValue); HashSet set = new HashSet<>(); HashSet> filterConsigneeList = new HashSet<>(); HashSet> filterCarrierList = new HashSet<>(); HashSet> filterCapacityList = new HashSet<>(); HashSet> filtermaterialNameList = new HashSet<>(); HashSet> filterorderStatus = new HashSet<>(); HashSet> filteraddressPlace = new HashSet<>(); HashSet> filtermaterialSpe = new HashSet<>(); HashSet> filterSaleRemark = new HashSet<>(); int totalNumber = 0; for (int j = 0; j < saleSteelReport.size();j++) { Map stringObjectMap = saleSteelReport.get(j); stringObjectMap.put("rowKey",j + 1); if(j == 0) { stringObjectMap.put("group",j); }else{ if((saleSteelReport.get(j-1).get("saleOrderMaterialId")).equals(stringObjectMap.get("saleOrderMaterialId"))){ stringObjectMap.put("group",saleSteelReport.get(j-1).get("group")); }else{ stringObjectMap.put("group",Integer.parseInt(saleSteelReport.get(j-1).get("group").toString()) + 1); } } if( !"取消".equals(stringObjectMap.get("capacityNo")) && !"反审批".equals(stringObjectMap.get("saleOrderStatus")) && !"已关闭".equals(stringObjectMap.get("orderStatus"))) { set.add(stringObjectMap.get("saleOrderMaterialId")); } calculateDifferenceTime(stringObjectMap); //收货客户筛选 Map filterConsigneeMap = new HashMap<>(); filterConsigneeMap.put("text",stringObjectMap.get("consigneeName")); filterConsigneeMap.put("value",stringObjectMap.get("consigneeName")); filterConsigneeList.add(filterConsigneeMap); //承运商筛选 Map filterCarrierMap = new HashMap<>(); filterCarrierMap.put("text",stringObjectMap.get("carrierName")); filterCarrierMap.put("value",stringObjectMap.get("carrierName")); filterCarrierList.add(filterCarrierMap); //车牌号筛选 Map filterCapacityMap = new HashMap<>(); filterCapacityMap.put("text",stringObjectMap.get("newCapacityNo")); filterCapacityMap.put("value",stringObjectMap.get("newCapacityNo")); filterCapacityList.add(filterCapacityMap); //物资筛选 Map filtermaterialNameMap = new HashMap<>(); filtermaterialNameMap.put("text",stringObjectMap.get("materialName")); filtermaterialNameMap.put("value",stringObjectMap.get("materialName")); filtermaterialNameList.add(filtermaterialNameMap); //运单状态筛选 Map filterorderStatusMap = new HashMap<>(); filterorderStatusMap.put("text",stringObjectMap.get("orderStatus")); filterorderStatusMap.put("value",stringObjectMap.get("orderStatus")); filterorderStatus.add(filterorderStatusMap); //收货地址筛选 Map filteraddressPlaceMap = new HashMap<>(); filteraddressPlaceMap.put("text",stringObjectMap.get("addressPlace")); filteraddressPlaceMap.put("value",stringObjectMap.get("addressPlace")); filteraddressPlace.add(filteraddressPlaceMap); //物资规格筛选 Map filtermaterialSpeMap = new HashMap<>(); filtermaterialSpeMap.put("text",stringObjectMap.get("materialSpe")); filtermaterialSpeMap.put("value",stringObjectMap.get("materialSpe")); filtermaterialSpe.add(filtermaterialSpeMap); //摘要筛选 Map filterSaleRemarkMap = new HashMap<>(); filterSaleRemarkMap.put("text",stringObjectMap.get("saleRemark")); filterSaleRemarkMap.put("value",stringObjectMap.get("saleRemark")); filterSaleRemark.add(filterSaleRemarkMap); totalNumber += Integer.parseInt(stringObjectMap.get("materialNum").toString()); String capacityNumbers= (String) stringObjectMap.get("capacityNumbers"); //确认是否有多个收货单位 //if (shippingAddressIds !=null && !("".equals(shippingAddressIds))){ // String[] split = shippingAddressIds.split(","); // String address=""; // int i=0; // for (String s : split) { // i++; // String getaddress = getaddress(DataChange.dataToBigDecimal(s)); // if (i==1){ // address+="旧地址:"+getaddress+","; // }else if (i==2){ // address+="新地址:"+getaddress; // } // } // stringObjectMap.put("addressPlace",address); //} //确认是否有多个车牌号 if (capacityNumbers!=null &&!("".equals(capacityNumbers))){ String[] split = capacityNumbers.split(","); String capacityNumber=""; int flag=0; for (String s : split) { flag++; String s1 = getcapacityNumber(DataChange.dataToBigDecimal(s)); if (flag==1){ capacityNumber+="旧车号:"+s1+","; }else if (flag==2){ capacityNumber+="新车号:"+s1; break; } } stringObjectMap.put("capacityNo",capacityNumber); } } if(saleSteelReport.size() > 0 && saleSteelReport.get(0) != null){ saleSteelReport.get(0).put("totalCapacity",set.size()); saleSteelReport.get(0).put("totalNumber",totalNumber); saleSteelReport.get(0).put("filterConsigneeList",filterConsigneeList); saleSteelReport.get(0).put("filtermaterialNameList",filtermaterialNameList); saleSteelReport.get(0).put("filterorderStatus",filterorderStatus); saleSteelReport.get(0).put("filteraddressPlace",filteraddressPlace); saleSteelReport.get(0).put("filtermaterialSpe",filtermaterialSpe); saleSteelReport.get(0).put("filterCapacityList",filterCapacityList); saleSteelReport.get(0).put("filterCarrierList",filterCarrierList); saleSteelReport.get(0).put("filterSaleRemark",filterSaleRemark); } return saleSteelReport; } private Set> setListMap(List> list, String name) { Set> setString = new HashSet<>(); for (Map map : list) {//遍历每条数据 Map map1 = new HashMap<>(); //map.get(name)获取每条数据中对应表头字段的数据 map1.put("text", map.get(name)); if (map.get(name) != null) { map1.put("value", map.get(name)); setString.add(map1); } } return setString; } //public PageListAdd tableColumnData(Integer apiId, List> list, List> data) { // for (Map columnData : columnDataList) { // //每个表头字段的过滤条件 // columnData.put("filters", setListMap(data, columnData.get("prop").toString())); // } // PageListAdd pageList = new PageListAdd(data); // pageList.setColumnData(columnDataList); // return pageList; //} @Override public List> getSaleSteelSpellingReport(Map mapValue) { List> saleSteelReport = statisticalReportMapper.getSaleSteelSpellingReport(mapValue); return saleSteelReport; } @Override public List> getSaleSteelReportNew(Map mapValue) { List> saleSteelReport = statisticalReportMapper.getSaleSteelReportNew(mapValue); return saleSteelReport; } @Override public List> getSettledSaleSteelReportNew(Map mapValue) { List> saleSteelReport = statisticalReportMapper.getSettledSaleSteelReportNew(mapValue); return saleSteelReport; } @Override public List> getInwardSaleSteelReport(Map map) { return statisticalReportMapper.getInwardSaleSteelReport(map); } @Override public List> getInwardSaleSteelOrder(Map map) { List> results=statisticalReportMapper.getInwardSaleSteelOrder(map); if(results!=null){ //遍历找到所有已使用的分录 Set saleMaterialIds=new HashSet<>(); for(Map temp:results){ if(temp.get("orderId")!=null){ saleMaterialIds.add(DataChange.dataToBigDecimal(temp.get("saleMaterialId"))); } } //查询分录已使用但订单id为null的记录 List> disResults=new ArrayList<>(); for(Map temp:results){ if(temp.get("orderId")==null && saleMaterialIds.contains(DataChange.dataToBigDecimal(temp.get("saleMaterialId")))){ disResults.add(temp); } } //删除这些记录,防止重复派单 results.removeAll(disResults); } return results; } @Override public Map getSteelReportDetailsBySmId(BigDecimal saleOrderMaterialId) { //获取主表数据 Map map = statisticalReportMapper.getSteelReportDetailsBySmId(saleOrderMaterialId); //获取子表数据 List> mapList = statisticalReportMapper.getSteelReportDetailsListBySmId(saleOrderMaterialId); if (map != null){ if(DataChange.dataToBigDecimal(map.get("orderStatu")).intValue() == 5 && map.get("queueStartTime") != null && DataChange.dataToBigDecimal(map.get("lineSqe")).intValue() == 0){ map.put("orderStatus","排队中"); map.put("orderStatusTime",map.get("queueStartTime")); }else if(DataChange.dataToBigDecimal(map.get("orderStatu")).intValue() == 5 && DataChange.dataToBigDecimal(map.get("lineSqe")).intValue() != 0 && map.get("outGateTime") == null){ map.put("orderStatus","已进厂"); map.put("orderStatusTime",map.get("entryGateTime")); }else if(DataChange.dataToBigDecimal(map.get("orderStatu")).intValue() == 5 && map.get("outGateTime") != null){ map.put("orderStatus","已出厂"); map.put("orderStatusTime",map.get("outGateTime")); } map.put("mapList",mapList); } return map; } @Override public String getaddress(BigDecimal addressid) { String address = statisticalReportMapper.queryAddress(addressid); return address; } //获取单价 @Override public BigDecimal getHistoryPrice(BigDecimal priceId) { BigDecimal bigDecimal = statisticalReportMapper.queryHistoryPrice(priceId); return bigDecimal; } @Override public String getcapacityNumber(BigDecimal capacitynumber) { String s = statisticalReportMapper.queryCapacityNumber(capacitynumber); return s; } @Override public List> loadingSaleSteelReport(Map map) { List> saleSteelReport = statisticalReportMapper.loadingSaleSteelReport(map); return saleSteelReport; } @Override public String getStatus(BigDecimal orderId) { return statisticalReportMapper.getStatus(orderId); } @Override public List getSaleAreaRemark(String saler) { return statisticalReportMapper.getSaleAreaRemark(saler); } @Override public List> getSaleSteelReportForFinance(Map map) { List> saleSteelReport = statisticalReportMapper.getSaleSteelReportForFinance(map); return saleSteelReport; } @Override public List> steelTransportReport(Map map) { List> saleSteelReport = statisticalReportMapper.steelTransportReport(map); return saleSteelReport; } public int testTb() { //首先查询已经完成的销售钢材有净重的没有saleMaterialId的数据 List> mapList = statisticalReportMapper.getNoSaleterialIdWeight(); for (Map map :mapList) { BigDecimal orderId = DataChange.dataToBigDecimal(map.get("orderId")); BigDecimal weightTaskId = DataChange.dataToBigDecimal(map.get("weightTaskId")); BigDecimal materialId = DataChange.dataToBigDecimal(map.get("materialId")); //根据运输订单号和物资id去查询saleMaterialId的数量,若数量为1则更新,否则记录下来不更新 List saleMaterialIds = statisticalReportMapper.getSaleMaterialIds(orderId,materialId); if(saleMaterialIds.size() > 1) { System.out.println("该车有问题:" + map.toString()); continue; }else if(saleMaterialIds.size() ==1 && saleMaterialIds.get(0) != null){ //否则更新计量实绩表 System.out.println("该车正常更新:"+ map.toString()); statisticalReportMapper.updateTw(weightTaskId,DataChange.dataToBigDecimal(saleMaterialIds.get(0))); }else{ System.out.println("查不到数据"+ map.toString()); } } return 0; } }