春风项目四线(合箱线、总装线)
wujian
2024-10-23 2c65c31aceb16c1d06c692266e3fb555ecafdfb5
提交 | 用户 | 时间
fd2207 1 package com.jcdm.quartz.task;
2
1e3074 3 import cn.hutool.core.collection.CollUtil;
2c65c3 4 import cn.hutool.core.util.ObjectUtil;
W 5 import cn.hutool.core.util.StrUtil;
6 import com.jcdm.main.bs.beatSetting.domain.BsBeatSetting;
7 import com.jcdm.main.bs.beatSetting.domain.ProductNumTable;
8 import com.jcdm.main.bs.beatSetting.service.IBsBeatSettingService;
9 import com.jcdm.main.bs.beatSetting.service.ProductNumTableService;
55b0cb 10 import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
11 import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
04b8ef 12 import com.jcdm.main.da.passingStationCollection.service.IDaPassingStationCollectionService;
Y 13 import com.jcdm.main.da.passingStationCollection.service.impl.DaPassingStationCollectionServiceImpl;
1e3074 14 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
W 15 import com.jcdm.main.om.productionOrde.service.impl.OmProductionOrdeInfoServiceImpl;
55b0cb 16 import com.jcdm.main.webservice.service.ReceivingServices;
17 import org.springframework.beans.factory.annotation.Autowired;
fd2207 18 import org.springframework.stereotype.Component;
19 import com.jcdm.common.utils.StringUtils;
1a444b 20 import org.slf4j.Logger;
Y 21 import org.slf4j.LoggerFactory;
55b0cb 22
1e3074 23 import javax.annotation.Resource;
2c65c3 24 import java.time.Duration;
W 25 import java.time.LocalDate;
26 import java.time.LocalDateTime;
27 import java.time.temporal.ChronoUnit;
28 import java.util.*;
1e3074 29 import java.util.stream.Collectors;
fd2207 30
31 /**
32  * 定时任务调度测试
33  * 
34  * @author jc
35  */
36 @Component("ryTask")
37 public class RyTask
38 {
04b8ef 39     @Autowired
Y 40     private DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl;
41     @Autowired
42     private IBsOrderSchedulingService bsOrderSchedulingService;
1e3074 43
W 44     @Resource
45     private OmProductionOrdeInfoServiceImpl omProductionOrdeInfoService;
2c65c3 46
W 47     @Resource
48     private IBsBeatSettingService bsBeatSettingService;
49
50     @Resource
51     private ProductNumTableService productNumTableService;
1e3074 52
W 53
1a444b 54     private static final Logger logger = LoggerFactory.getLogger("sys-user");
fd2207 55     public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
56     {
57         System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
58     }
59
60     public void ryParams(String params)
61     {
62         System.out.println("执行有参方法:" + params);
63     }
64
65     public void ryNoParams()
66     {
1e3074 67         logger.info("执行定时任务开始");
04b8ef 68         String a=passingStationCollectionServiceImpl.SelectSN("88","OP010");
1e3074 69         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
W 70         bsOrderScheduling.setRemarks("1");
71         List<BsOrderScheduling> bsOrderSchedulingList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
72         if (CollUtil.isNotEmpty(bsOrderSchedulingList)){
73             Map<String, List<BsOrderScheduling>> map = bsOrderSchedulingList.stream().collect(Collectors.groupingBy(BsOrderScheduling::getOrderNo));
74             OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
75             for (String s : map.keySet()) {
76                 List<BsOrderScheduling> bsOrderSchedulings = map.get(s);
77                 if (CollUtil.isNotEmpty(bsOrderSchedulings)){
78                     BsOrderScheduling scheduling = bsOrderSchedulings.get(0);
79                     int size = bsOrderSchedulings.size();
80                     omProductionOrdeInfo.setPlanQty((long)size);
81                     omProductionOrdeInfo.setActualQty((long)0);
82                     omProductionOrdeInfo.setWorkOrderNo(s);
83                     omProductionOrdeInfo.setProductCode(scheduling.getModel());
84                     omProductionOrdeInfo.setOrderStatus("2");
85                     omProductionOrdeInfo.setTypeZ(scheduling.getModel());
86                     omProductionOrdeInfoService.insertOmProductionOrdeInfo(omProductionOrdeInfo);
87                     logger.info("插入工单,{}",s);
88                 }
89             }
90             for (BsOrderScheduling scheduling : bsOrderSchedulingList) {
91                 scheduling.setRemarks("0");
49ca7c 92                 scheduling.setProductionStatus("1");
1e3074 93                 bsOrderSchedulingService.updateBsOrderScheduling(scheduling);
W 94             }
95
96         }
04b8ef 97         System.out.println("执行过程返回:" + a);
1e3074 98         logger.info("定时任务执行结束");
fd2207 99     }
55b0cb 100
282556 101     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";
55b0cb 102     public void workReportingTasks(){
103         report10();
104         report20();
2c65c3 105         updateProductNum();
55b0cb 106     }
107
108     public void report10(){
109         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
110         bsOrderScheduling.setReport10("0");
111         List<BsOrderScheduling> bsOrderSchedulings = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
5030f3 112         String status="";
Y 113         String ev_meassage="";
51b05b 114         if (CollUtil.isNotEmpty(bsOrderSchedulings)){
W 115             BsOrderScheduling orderScheduling = bsOrderSchedulings.get(0);
5030f3 116             try {
Y 117                 String xmlResult = ReceivingServices.getInterfaceInformationXml(url, getProductionPlanInformationXml(orderScheduling.getOrderNo(), "0010"));
118                 ev_meassage=ReceivingServices.xmlToJSON1(xmlResult);
119                 status = ReceivingServices.xmlToJSON3(xmlResult);
120             } catch (Exception e) {
121                 status="3";
122             }
123             if(status.equals("1")) {
55b0cb 124                 orderScheduling.setReport10("1");
125                 int i = bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling);
5030f3 126                 logger.info("{}合箱报工成功",orderScheduling.getOrderNo());
Y 127             }else {
128                 if(StringUtils.isEmpty(orderScheduling.getSpareField1())){
129                     orderScheduling.setSpareField1("1");
130                     bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling);
131                 }else{
132                     if(Integer.valueOf(orderScheduling.getSpareField1())+1>=3) {
133                         //累计报工异常超过3次
134                         orderScheduling.setReport10("3");
135                         orderScheduling.setSpareField1(String.valueOf(Integer.valueOf(orderScheduling.getSpareField1()) + 1));
136                     }else {
137                         orderScheduling.setSpareField1(String.valueOf(Integer.valueOf(orderScheduling.getSpareField1()) + 1));
138                     }
139                     bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling);
140                 }
141                 if(status.equals("3"))
142                     logger.info("{}合箱报工因为网络原因,报工失败!",orderScheduling.getOrderNo());
143                 else
144                     logger.info("{}合箱报工失败,原因:{}",orderScheduling.getOrderNo(),ev_meassage);
55b0cb 145             }
146         }
147     }
148
149     public void report20(){
150         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
151         bsOrderScheduling.setReport20("0");
152         List<BsOrderScheduling> bsOrderSchedulings = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
5030f3 153         String status="";
Y 154         String ev_meassage="";
51b05b 155         if (CollUtil.isNotEmpty(bsOrderSchedulings)){
W 156             BsOrderScheduling orderScheduling = bsOrderSchedulings.get(0);
5030f3 157             try {
Y 158                 String xmlResult = ReceivingServices.getInterfaceInformationXml(url, getProductionPlanInformationXml(orderScheduling.getOrderNo(), "0020"));
159                 ev_meassage=ReceivingServices.xmlToJSON1(xmlResult);
160                 status = ReceivingServices.xmlToJSON3(xmlResult);
161             } catch (Exception e) {
162                 status="3";
163             }
55b0cb 164             if(status.equals("1")){
1a444b 165                 orderScheduling.setReport20("1");
55b0cb 166                 int i = bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling);
5030f3 167                 logger.info("{}总装报工成功",orderScheduling.getOrderNo());
Y 168             }else {
169                 if(StringUtils.isEmpty(orderScheduling.getSpareField2())){
170                     orderScheduling.setSpareField2("1");
171                     bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling);
172                 }else{
173                     if(Integer.valueOf(orderScheduling.getSpareField2())+1>=3) {
174                         //累计报工异常超过3次
175                         orderScheduling.setReport20("3");
176                         orderScheduling.setSpareField2(String.valueOf(Integer.valueOf(orderScheduling.getSpareField2()) + 1));
177                     }else{
178                         orderScheduling.setSpareField2(String.valueOf(Integer.valueOf(orderScheduling.getSpareField2()) + 1));
179                     }
180                     bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling);
181                     if(status.equals("3"))
182                         logger.info("{}总装报工因为网络原因,报工失败!",orderScheduling.getOrderNo());
183                     else
184                         logger.info("{}总装报工失败,原因:{}",orderScheduling.getOrderNo(),ev_meassage);
185                 }
55b0cb 186             }
187         }
188     }
189
2c65c3 190     public void updateProductNum(){
W 191         LocalDate now = LocalDate.now();
192         ProductNumTable productNumTableQuery = new ProductNumTable();
193         productNumTableQuery.setProductTime(now);
194         //已存在的统计数据
195         List<ProductNumTable> productNumTableList = productNumTableService.selectProductList(productNumTableQuery);
196         String actModel;
197         //获取当天所有生产数据
198         List<BsOrderScheduling> bsOrderSchedulingList = bsOrderSchedulingService.selectBsOrderSchedulingListForNum();
199         if (CollUtil.isNotEmpty(bsOrderSchedulingList)){
200             List<BsOrderScheduling> tempList = bsOrderSchedulingList.stream()
201                     .filter(x -> ObjectUtil.isNotNull(x.getFinalAssemblyOfflineTime()))
202                     .collect(Collectors.toList());
203             List<BsOrderScheduling> collect2 = tempList.stream()
204                     .sorted(Comparator.comparing(BsOrderScheduling::getFinalAssemblyOfflineTime).reversed())
205                     .collect(Collectors.toList());
206             if (CollUtil.isNotEmpty(collect2)){
207                 BsOrderScheduling bsOrderScheduling = collect2.get(0);
208                 actModel = bsOrderScheduling.getModel();
209             } else {
210                 actModel = null;
211             }
212             List<String> modelList = tempList.stream().map(BsOrderScheduling::getModel).distinct().collect(Collectors.toList());
213             Integer modelNum = 0;
214             if (CollUtil.isNotEmpty(modelList)){
215                 modelNum = modelList.size();
216             }
217             Integer productNumTheory = caculateProductNumTheory(actModel, now, modelNum);
218             List<ProductNumTable> saveDate = new ArrayList<>();
219             Map<String, List<BsOrderScheduling>> collect = bsOrderSchedulingList.stream().collect(Collectors.groupingBy(BsOrderScheduling::getModel));
220             for (String s : collect.keySet()) {
221
222                 List<BsOrderScheduling> bsOrderSchedulingList1 = collect.get(s);
223                 //合箱上线
224                 long count1 = bsOrderSchedulingList1.stream().filter(x -> ObjectUtil.isNotNull(x.getBoxClosingOnlineTime())).count();
225                 //总装上线
226                 long count2 = bsOrderSchedulingList1.stream().filter(x -> ObjectUtil.isNotNull(x.getFinalAssemblyLaunchTime())).count();
227                 //总装下线
228                 long count3 = bsOrderSchedulingList1.stream().filter(x -> ObjectUtil.isNotNull(x.getFinalAssemblyOfflineTime())).count();
229                 //检查判断是更新还是插入
230                 List<ProductNumTable> collect1 = productNumTableList.stream().filter(x -> s.equals(x.getModel())).collect(Collectors.toList());
231                 if (CollUtil.isEmpty(collect1)){
232                     //插入
233                     ProductNumTable productNumTable = new ProductNumTable();
234                     UUID uuid = UUID.randomUUID();
235                     productNumTable.setId(uuid.getMostSignificantBits());
236                     productNumTable.setModel(s);
237                     productNumTable.setHxOnlineNum((int) count1);
238                     productNumTable.setZzOnlineNum((int) count2);
239                     productNumTable.setZzOfflineNum((int) count3);
240                     productNumTable.setProductTime(now);
241                     productNumTable.setProductNumTheory(productNumTheory);
242                     saveDate.add(productNumTable);
243                 } else {
244                     //更新
245                     //判断是否需要更新
246                     ProductNumTable productNumTable = collect1.get(0);
247                     Integer hxOnlineNum = productNumTable.getHxOnlineNum();
248                     Integer zzOnlineNum = productNumTable.getZzOnlineNum();
249                     Integer zzOfflineNum = productNumTable.getZzOfflineNum();
250                     if (!hxOnlineNum.equals((int)count1) || !zzOnlineNum.equals((int) count2) || !zzOfflineNum.equals((int)count3)){
251                         //更新
252                         productNumTable.setHxOnlineNum((int) count1);
253                         productNumTable.setZzOnlineNum((int) count2);
254                         productNumTable.setZzOfflineNum((int) count3);
255                         productNumTable.setProductNumTheory(productNumTheory);
256                         productNumTableService.updateProductNum(productNumTable);
257                     }
258                 }
259             }
260             if (CollUtil.isNotEmpty(saveDate)){
261                 productNumTableService.insertProductList(saveDate);
262             }
263         }
264
265
266
267     }
268
269     private Integer caculateProductNumTheory(String actModel, LocalDate now,Integer modelNum) {
270         long l = System.currentTimeMillis();
271         System.out.println("开始:----"+l);
272         //计算总产量数据
273         String beat = "";
274         List<BsBeatSetting> bsBeatSettings = bsBeatSettingService.selectBsBeatSettingList(new BsBeatSetting());
275         if (ObjectUtil.isNotNull(actModel)){
276             List<BsBeatSetting> collect = bsBeatSettings.stream().filter(x -> actModel.contains(x.getProductCode())).collect(Collectors.toList());
277             if (CollUtil.isNotEmpty(collect)){
278                 BsBeatSetting bsBeatSetting = collect.get(0);
279                 beat = bsBeatSetting.getBeat();
280             }
281         }
282
283         LocalDateTime nowTime = LocalDateTime.now();
284         long workTime = 0;
285         LocalDateTime time1 = now.atTime(0, 0, 0);
286         LocalDateTime time_rest = now.atTime(0, 30, 0);
287         LocalDateTime time2 = now.atTime(3, 0, 0);
288         LocalDateTime time3 = now.atTime(3, 10, 0);
289         LocalDateTime time4 = now.atTime(5, 0, 0);
290         LocalDateTime time5 = now.atTime(5, 10, 0);
291         LocalDateTime time6 = now.atTime(7, 0, 0);
292         LocalDateTime time7 = now.atTime(8, 0, 0);
293         LocalDateTime time8 = now.atTime(10, 0, 0);
294         LocalDateTime time9 = now.atTime(10, 10, 0);
295         LocalDateTime time10 = now.atTime(11, 10, 0);
296         LocalDateTime time11 = now.atTime(12, 10, 0);
297         LocalDateTime time12 = now.atTime(15, 0, 0);
298         LocalDateTime time13 = now.atTime(15, 10, 0);
299         LocalDateTime time14 = now.atTime(20, 0, 0);
300         LocalDateTime time15 = now.atTime(20, 10, 0);
301         LocalDateTime time16 = now.atTime(22, 0, 0);
302         LocalDateTime time17 = now.atTime(22, 10, 0);
303         LocalDateTime time18 = now.atTime(23, 59, 59);
304         if (nowTime.isBefore(time_rest)){
305             //0-0.30
306             workTime = 0;
307         } else if (nowTime.isBefore(time2)){
308             //0-3
309             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 1800;
310         } else if (nowTime.isBefore(time3)){
311             //0-3.10
312             workTime = ChronoUnit.SECONDS.between(time1,time2)  - 1800;
313         } else if (nowTime.isBefore(time4)){
314             //0-5
315             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 2400;
316         } else if (nowTime.isBefore(time5)){
317             //0-5.10
318             workTime = ChronoUnit.SECONDS.between(time1,time4)  - 2400;
319         } else if (nowTime.isBefore(time6)){
320             //0-7
321             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 3000;
322         } else if (nowTime.isBefore(time7)){
323             //0-8
324             workTime = ChronoUnit.SECONDS.between(time1,time6)  - 3000;
325         } else if (nowTime.isBefore(time8)){
326             //0-10
327             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 6600;
328         } else if (nowTime.isBefore(time9)){
329             //0-10.10
330             workTime = ChronoUnit.SECONDS.between(time1,time8)  - 6600;
331         } else if (nowTime.isBefore(time10)){
332             //0-11.10
333             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 7200;
334         } else if (nowTime.isBefore(time11)){
335             //0-12.10
336             workTime = ChronoUnit.SECONDS.between(time1,time10)  - 7200;
337         }  else if (nowTime.isBefore(time12)){
338             //0-15
339             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 7200 - 3600;
340         } else if (nowTime.isBefore(time13)){
341             //0-15.10
342             workTime = ChronoUnit.SECONDS.between(time1,time12)  - 7200 - 3600;
343         } else if (nowTime.isBefore(time14)){
344             //0-20
345             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 7200 - 3600 - 600;
346         } else if (nowTime.isBefore(time15)){
347             //0-20.10
348             workTime = ChronoUnit.SECONDS.between(time1,time14)  - 7200 - 3600 - 600;
349         } else if (nowTime.isBefore(time16)){
350             //0-22
351             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 7200 - 3600 - 600 - 600;
352         } else if (nowTime.isBefore(time17)){
353             //0-22.10
354             workTime = ChronoUnit.SECONDS.between(time1,time16)  - 7200 - 3600 - 600 - 600;
355         } else if (nowTime.isBefore(time18)){
356             //0-24
357             workTime = ChronoUnit.SECONDS.between(time1,nowTime)  - 7200 - 3600 - 600 - 600 - 600;
358         }
359         if (modelNum > 1){
360             workTime = workTime - 1800L *(modelNum-1);
361             if (workTime <0){
362                 workTime = 0;
363             }
364         }
365         System.out.println(workTime+"---------");
366         long l2 = System.currentTimeMillis();
367         System.out.println("结束:----"+l2);
368         long l1 = l2 - l;
369         System.out.println("耗费时间:----"+l1);
370         //理论产量
371         Integer productNumTheory = 0;
372         if (StrUtil.isNotBlank(beat)){
373             int i = Integer.parseInt(beat);
374             Integer workTimeInt = (int) workTime;
375             productNumTheory = Math.floorDiv(workTimeInt, i);
376         }
377         return productNumTheory;
378     }
379
55b0cb 380     public static String getProductionPlanInformationXml(String orderNo,String location){
381         String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" +
382                 "   <soapenv:Header/>\n" +
383                 "   <soapenv:Body>\n" +
384                 "      <urn:ZPP_BC_001>\n" +
385                 "         <IV_AUFNR>"+orderNo+"</IV_AUFNR>\n" +
386                 "          <IV_VORNR>"+location+"</IV_VORNR>\n" +
387                 "           <IV_LMNGA>1</IV_LMNGA>\n" +
388                 "           <IV_XMNGA>0</IV_XMNGA>   \n" +
389                 "         <IV_STATU>1</IV_STATU>  \n" +
390                 "      </urn:ZPP_BC_001>\n" +
391                 "   </soapenv:Body>\n" +
392                 "</soapenv:Envelope>";
d4f437 393         //logger.info("{}",content);
55b0cb 394         return content;
395     }
fd2207 396 }