| | |
| | | package com.jcdm.quartz.task; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.jcdm.main.bs.beatSetting.domain.BsBeatSetting; |
| | | import com.jcdm.main.bs.beatSetting.domain.ProductNumTable; |
| | | import com.jcdm.main.bs.beatSetting.service.IBsBeatSettingService; |
| | | import com.jcdm.main.bs.beatSetting.service.ProductNumTableService; |
| | | import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling; |
| | | import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService; |
| | | import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService; |
| | | import com.jcdm.main.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl; |
| | | import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo; |
| | | import com.jcdm.main.om.productionOrde.service.impl.OmProductionOrdeInfoServiceImpl; |
| | | import com.jcdm.main.webservice.service.ReceivingServices; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import java.time.Duration; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 定时任务调度测试 |
| | |
| | | @Component("ryTask") |
| | | public class RyTask |
| | | { |
| | | @Autowired |
| | | private DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl; |
| | | @Autowired |
| | | private IBsOrderSchedulingService bsOrderSchedulingService; |
| | | |
| | | @Resource |
| | | private OmProductionOrdeInfoServiceImpl omProductionOrdeInfoService; |
| | | |
| | | @Resource |
| | | private IBsBeatSettingService bsBeatSettingService; |
| | | |
| | | @Resource |
| | | private ProductNumTableService productNumTableService; |
| | | |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger("sys-user"); |
| | | public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) |
| | | { |
| | |
| | | |
| | | public void ryNoParams() |
| | | { |
| | | System.out.println("执行无参方法"); |
| | | logger.info("执行定时任务开始"); |
| | | String a=passingStationCollectionServiceImpl.SelectSN("88","OP010"); |
| | | BsOrderScheduling bsOrderScheduling = new BsOrderScheduling(); |
| | | bsOrderScheduling.setRemarks("1"); |
| | | List<BsOrderScheduling> bsOrderSchedulingList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling); |
| | | if (CollUtil.isNotEmpty(bsOrderSchedulingList)){ |
| | | Map<String, List<BsOrderScheduling>> map = bsOrderSchedulingList.stream().collect(Collectors.groupingBy(BsOrderScheduling::getOrderNo)); |
| | | OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo(); |
| | | for (String s : map.keySet()) { |
| | | List<BsOrderScheduling> bsOrderSchedulings = map.get(s); |
| | | if (CollUtil.isNotEmpty(bsOrderSchedulings)){ |
| | | BsOrderScheduling scheduling = bsOrderSchedulings.get(0); |
| | | int size = bsOrderSchedulings.size(); |
| | | omProductionOrdeInfo.setPlanQty((long)size); |
| | | omProductionOrdeInfo.setActualQty((long)0); |
| | | omProductionOrdeInfo.setWorkOrderNo(s); |
| | | omProductionOrdeInfo.setProductCode(scheduling.getModel()); |
| | | omProductionOrdeInfo.setOrderStatus("2"); |
| | | omProductionOrdeInfo.setTypeZ(scheduling.getModel()); |
| | | omProductionOrdeInfoService.insertOmProductionOrdeInfo(omProductionOrdeInfo); |
| | | logger.info("插入工单,{}",s); |
| | | } |
| | | } |
| | | for (BsOrderScheduling scheduling : bsOrderSchedulingList) { |
| | | scheduling.setRemarks("0"); |
| | | scheduling.setProductionStatus("1"); |
| | | bsOrderSchedulingService.updateBsOrderScheduling(scheduling); |
| | | } |
| | | |
| | | } |
| | | System.out.println("执行过程返回:" + a); |
| | | logger.info("定时任务执行结束"); |
| | | } |
| | | |
| | | @Autowired |
| | | private IBsOrderSchedulingService bsOrderSchedulingService; |
| | | String url = "http://podqapp.cfmoto.com.cn:50100/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_BC_001_SYN_OUT&interfaceNamespace=http://cfmoto.com/xi/MES"; |
| | | public void workReportingTasks(){ |
| | | report10(); |
| | | report20(); |
| | | updateProductNum(); |
| | | } |
| | | |
| | | public void report10(){ |
| | | BsOrderScheduling bsOrderScheduling = new BsOrderScheduling(); |
| | | bsOrderScheduling.setReport10("0"); |
| | | List<BsOrderScheduling> bsOrderSchedulings = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling); |
| | | for (BsOrderScheduling orderScheduling : bsOrderSchedulings) { |
| | | String xmlResult = ReceivingServices.getInterfaceInformationXml(url, getProductionPlanInformationXml(orderScheduling.getOrderNo(), "0010")); |
| | | String status = ReceivingServices.xmlToJSON3(xmlResult); |
| | | if(status.equals("1")){ |
| | | String status=""; |
| | | String ev_meassage=""; |
| | | if (CollUtil.isNotEmpty(bsOrderSchedulings)){ |
| | | BsOrderScheduling orderScheduling = bsOrderSchedulings.get(0); |
| | | try { |
| | | String xmlResult = ReceivingServices.getInterfaceInformationXml(url, getProductionPlanInformationXml(orderScheduling.getOrderNo(), "0010")); |
| | | ev_meassage=ReceivingServices.xmlToJSON1(xmlResult); |
| | | status = ReceivingServices.xmlToJSON3(xmlResult); |
| | | } catch (Exception e) { |
| | | status="3"; |
| | | } |
| | | if(status.equals("1")) { |
| | | orderScheduling.setReport10("1"); |
| | | int i = bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling); |
| | | System.out.println("更新状态成功"); |
| | | //logger.info("{}合箱报工成功",orderScheduling.getOrderNo()); |
| | | logger.info("{}合箱报工成功",orderScheduling.getOrderNo()); |
| | | }else { |
| | | if(StringUtils.isEmpty(orderScheduling.getSpareField1())){ |
| | | orderScheduling.setSpareField1("1"); |
| | | bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling); |
| | | }else{ |
| | | if(Integer.valueOf(orderScheduling.getSpareField1())+1>=3) { |
| | | //累计报工异常超过3次 |
| | | orderScheduling.setReport10("3"); |
| | | orderScheduling.setSpareField1(String.valueOf(Integer.valueOf(orderScheduling.getSpareField1()) + 1)); |
| | | }else { |
| | | orderScheduling.setSpareField1(String.valueOf(Integer.valueOf(orderScheduling.getSpareField1()) + 1)); |
| | | } |
| | | bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling); |
| | | } |
| | | if(status.equals("3")) |
| | | logger.info("{}合箱报工因为网络原因,报工失败!",orderScheduling.getOrderNo()); |
| | | else |
| | | logger.info("{}合箱报工失败,原因:{}",orderScheduling.getOrderNo(),ev_meassage); |
| | | } |
| | | } |
| | | } |
| | |
| | | BsOrderScheduling bsOrderScheduling = new BsOrderScheduling(); |
| | | bsOrderScheduling.setReport20("0"); |
| | | List<BsOrderScheduling> bsOrderSchedulings = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling); |
| | | for (BsOrderScheduling orderScheduling : bsOrderSchedulings) { |
| | | String xmlResult = ReceivingServices.getInterfaceInformationXml(url, getProductionPlanInformationXml(orderScheduling.getOrderNo(), "0020")); |
| | | String status = ReceivingServices.xmlToJSON3(xmlResult); |
| | | String status=""; |
| | | String ev_meassage=""; |
| | | if (CollUtil.isNotEmpty(bsOrderSchedulings)){ |
| | | BsOrderScheduling orderScheduling = bsOrderSchedulings.get(0); |
| | | try { |
| | | String xmlResult = ReceivingServices.getInterfaceInformationXml(url, getProductionPlanInformationXml(orderScheduling.getOrderNo(), "0020")); |
| | | ev_meassage=ReceivingServices.xmlToJSON1(xmlResult); |
| | | status = ReceivingServices.xmlToJSON3(xmlResult); |
| | | } catch (Exception e) { |
| | | status="3"; |
| | | } |
| | | if(status.equals("1")){ |
| | | orderScheduling.setReport20("1"); |
| | | int i = bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling); |
| | | System.out.println("更新状态成功"); |
| | | //logger.info("{}总装报工成功",orderScheduling.getOrderNo()); |
| | | logger.info("{}总装报工成功",orderScheduling.getOrderNo()); |
| | | }else { |
| | | if(StringUtils.isEmpty(orderScheduling.getSpareField2())){ |
| | | orderScheduling.setSpareField2("1"); |
| | | bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling); |
| | | }else{ |
| | | if(Integer.valueOf(orderScheduling.getSpareField2())+1>=3) { |
| | | //累计报工异常超过3次 |
| | | orderScheduling.setReport20("3"); |
| | | orderScheduling.setSpareField2(String.valueOf(Integer.valueOf(orderScheduling.getSpareField2()) + 1)); |
| | | }else{ |
| | | orderScheduling.setSpareField2(String.valueOf(Integer.valueOf(orderScheduling.getSpareField2()) + 1)); |
| | | } |
| | | bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling); |
| | | if(status.equals("3")) |
| | | logger.info("{}总装报工因为网络原因,报工失败!",orderScheduling.getOrderNo()); |
| | | else |
| | | logger.info("{}总装报工失败,原因:{}",orderScheduling.getOrderNo(),ev_meassage); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void updateProductNum(){ |
| | | LocalDate now = LocalDate.now(); |
| | | ProductNumTable productNumTableQuery = new ProductNumTable(); |
| | | productNumTableQuery.setProductTime(now); |
| | | //已存在的统计数据 |
| | | List<ProductNumTable> productNumTableList = productNumTableService.selectProductList(productNumTableQuery); |
| | | String actModel; |
| | | //获取当天所有生产数据 |
| | | List<BsOrderScheduling> bsOrderSchedulingList = bsOrderSchedulingService.selectBsOrderSchedulingListForNum(); |
| | | if (CollUtil.isNotEmpty(bsOrderSchedulingList)){ |
| | | List<BsOrderScheduling> tempList = bsOrderSchedulingList.stream() |
| | | .filter(x -> ObjectUtil.isNotNull(x.getFinalAssemblyOfflineTime())) |
| | | .collect(Collectors.toList()); |
| | | List<BsOrderScheduling> collect2 = tempList.stream() |
| | | .sorted(Comparator.comparing(BsOrderScheduling::getFinalAssemblyOfflineTime).reversed()) |
| | | .collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(collect2)){ |
| | | BsOrderScheduling bsOrderScheduling = collect2.get(0); |
| | | actModel = bsOrderScheduling.getModel(); |
| | | } else { |
| | | actModel = null; |
| | | } |
| | | List<String> modelList = tempList.stream().map(BsOrderScheduling::getModel).distinct().collect(Collectors.toList()); |
| | | Integer modelNum = 0; |
| | | if (CollUtil.isNotEmpty(modelList)){ |
| | | modelNum = modelList.size(); |
| | | } |
| | | Integer productNumTheory = caculateProductNumTheory(actModel, now, modelNum); |
| | | List<ProductNumTable> saveDate = new ArrayList<>(); |
| | | Map<String, List<BsOrderScheduling>> collect = bsOrderSchedulingList.stream().collect(Collectors.groupingBy(BsOrderScheduling::getModel)); |
| | | for (String s : collect.keySet()) { |
| | | |
| | | List<BsOrderScheduling> bsOrderSchedulingList1 = collect.get(s); |
| | | //合箱上线 |
| | | long count1 = bsOrderSchedulingList1.stream().filter(x -> ObjectUtil.isNotNull(x.getBoxClosingOnlineTime())).count(); |
| | | //总装上线 |
| | | long count2 = bsOrderSchedulingList1.stream().filter(x -> ObjectUtil.isNotNull(x.getFinalAssemblyLaunchTime())).count(); |
| | | //总装下线 |
| | | long count3 = bsOrderSchedulingList1.stream().filter(x -> ObjectUtil.isNotNull(x.getFinalAssemblyOfflineTime())).count(); |
| | | //检查判断是更新还是插入 |
| | | List<ProductNumTable> collect1 = productNumTableList.stream().filter(x -> s.equals(x.getModel())).collect(Collectors.toList()); |
| | | if (CollUtil.isEmpty(collect1)){ |
| | | //插入 |
| | | ProductNumTable productNumTable = new ProductNumTable(); |
| | | UUID uuid = UUID.randomUUID(); |
| | | productNumTable.setId(uuid.getMostSignificantBits()); |
| | | productNumTable.setModel(s); |
| | | productNumTable.setHxOnlineNum((int) count1); |
| | | productNumTable.setZzOnlineNum((int) count2); |
| | | productNumTable.setZzOfflineNum((int) count3); |
| | | productNumTable.setProductTime(now); |
| | | productNumTable.setProductNumTheory(productNumTheory); |
| | | saveDate.add(productNumTable); |
| | | } else { |
| | | //更新 |
| | | //判断是否需要更新 |
| | | ProductNumTable productNumTable = collect1.get(0); |
| | | Integer hxOnlineNum = productNumTable.getHxOnlineNum(); |
| | | Integer zzOnlineNum = productNumTable.getZzOnlineNum(); |
| | | Integer zzOfflineNum = productNumTable.getZzOfflineNum(); |
| | | if (!hxOnlineNum.equals((int)count1) || !zzOnlineNum.equals((int) count2) || !zzOfflineNum.equals((int)count3)){ |
| | | //更新 |
| | | productNumTable.setHxOnlineNum((int) count1); |
| | | productNumTable.setZzOnlineNum((int) count2); |
| | | productNumTable.setZzOfflineNum((int) count3); |
| | | productNumTable.setProductNumTheory(productNumTheory); |
| | | productNumTableService.updateProductNum(productNumTable); |
| | | } |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(saveDate)){ |
| | | productNumTableService.insertProductList(saveDate); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private Integer caculateProductNumTheory(String actModel, LocalDate now,Integer modelNum) { |
| | | long l = System.currentTimeMillis(); |
| | | System.out.println("开始:----"+l); |
| | | //计算总产量数据 |
| | | String beat = ""; |
| | | List<BsBeatSetting> bsBeatSettings = bsBeatSettingService.selectBsBeatSettingList(new BsBeatSetting()); |
| | | if (ObjectUtil.isNotNull(actModel)){ |
| | | List<BsBeatSetting> collect = bsBeatSettings.stream().filter(x -> actModel.contains(x.getProductCode())).collect(Collectors.toList()); |
| | | if (CollUtil.isNotEmpty(collect)){ |
| | | BsBeatSetting bsBeatSetting = collect.get(0); |
| | | beat = bsBeatSetting.getBeat(); |
| | | } |
| | | } |
| | | |
| | | LocalDateTime nowTime = LocalDateTime.now(); |
| | | long workTime = 0; |
| | | LocalDateTime time1 = now.atTime(0, 0, 0); |
| | | LocalDateTime time_rest = now.atTime(0, 30, 0); |
| | | LocalDateTime time2 = now.atTime(3, 0, 0); |
| | | LocalDateTime time3 = now.atTime(3, 10, 0); |
| | | LocalDateTime time4 = now.atTime(5, 0, 0); |
| | | LocalDateTime time5 = now.atTime(5, 10, 0); |
| | | LocalDateTime time6 = now.atTime(7, 0, 0); |
| | | LocalDateTime time7 = now.atTime(8, 0, 0); |
| | | LocalDateTime time8 = now.atTime(10, 0, 0); |
| | | LocalDateTime time9 = now.atTime(10, 10, 0); |
| | | LocalDateTime time10 = now.atTime(11, 10, 0); |
| | | LocalDateTime time11 = now.atTime(12, 10, 0); |
| | | LocalDateTime time12 = now.atTime(15, 0, 0); |
| | | LocalDateTime time13 = now.atTime(15, 10, 0); |
| | | LocalDateTime time14 = now.atTime(20, 0, 0); |
| | | LocalDateTime time15 = now.atTime(20, 10, 0); |
| | | LocalDateTime time16 = now.atTime(22, 0, 0); |
| | | LocalDateTime time17 = now.atTime(22, 10, 0); |
| | | LocalDateTime time18 = now.atTime(23, 59, 59); |
| | | if (nowTime.isBefore(time_rest)){ |
| | | //0-0.30 |
| | | workTime = 0; |
| | | } else if (nowTime.isBefore(time2)){ |
| | | //0-3 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 1800; |
| | | } else if (nowTime.isBefore(time3)){ |
| | | //0-3.10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,time2) - 1800; |
| | | } else if (nowTime.isBefore(time4)){ |
| | | //0-5 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 2400; |
| | | } else if (nowTime.isBefore(time5)){ |
| | | //0-5.10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,time4) - 2400; |
| | | } else if (nowTime.isBefore(time6)){ |
| | | //0-7 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 3000; |
| | | } else if (nowTime.isBefore(time7)){ |
| | | //0-8 |
| | | workTime = ChronoUnit.SECONDS.between(time1,time6) - 3000; |
| | | } else if (nowTime.isBefore(time8)){ |
| | | //0-10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 6600; |
| | | } else if (nowTime.isBefore(time9)){ |
| | | //0-10.10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,time8) - 6600; |
| | | } else if (nowTime.isBefore(time10)){ |
| | | //0-11.10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 7200; |
| | | } else if (nowTime.isBefore(time11)){ |
| | | //0-12.10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,time10) - 7200; |
| | | } else if (nowTime.isBefore(time12)){ |
| | | //0-15 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 7200 - 3600; |
| | | } else if (nowTime.isBefore(time13)){ |
| | | //0-15.10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,time12) - 7200 - 3600; |
| | | } else if (nowTime.isBefore(time14)){ |
| | | //0-20 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 7200 - 3600 - 600; |
| | | } else if (nowTime.isBefore(time15)){ |
| | | //0-20.10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,time14) - 7200 - 3600 - 600; |
| | | } else if (nowTime.isBefore(time16)){ |
| | | //0-22 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 7200 - 3600 - 600 - 600; |
| | | } else if (nowTime.isBefore(time17)){ |
| | | //0-22.10 |
| | | workTime = ChronoUnit.SECONDS.between(time1,time16) - 7200 - 3600 - 600 - 600; |
| | | } else if (nowTime.isBefore(time18)){ |
| | | //0-24 |
| | | workTime = ChronoUnit.SECONDS.between(time1,nowTime) - 7200 - 3600 - 600 - 600 - 600; |
| | | } |
| | | if (modelNum > 1){ |
| | | workTime = workTime - 1800L *(modelNum-1); |
| | | if (workTime <0){ |
| | | workTime = 0; |
| | | } |
| | | } |
| | | System.out.println(workTime+"---------"); |
| | | long l2 = System.currentTimeMillis(); |
| | | System.out.println("结束:----"+l2); |
| | | long l1 = l2 - l; |
| | | System.out.println("耗费时间:----"+l1); |
| | | //理论产量 |
| | | Integer productNumTheory = 0; |
| | | if (StrUtil.isNotBlank(beat)){ |
| | | int i = Integer.parseInt(beat); |
| | | Integer workTimeInt = (int) workTime; |
| | | productNumTheory = Math.floorDiv(workTimeInt, i); |
| | | } |
| | | return productNumTheory; |
| | | } |
| | | |
| | | public static String getProductionPlanInformationXml(String orderNo,String location){ |
| | | String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" + |
| | | " <soapenv:Header/>\n" + |