春风项目四线(合箱线、总装线)
yyt
2024-06-29 c9745dfbbd9f64b1b84574446ab93f32a76896fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.jcdm.quartz.task;
 
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.webservice.service.ReceivingServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.jcdm.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.util.List;
 
/**
 * 定时任务调度测试
 * 
 * @author jc
 */
@Component("ryTask")
public class RyTask
{
    @Autowired
    private DaPassingStationCollectionServiceImpl passingStationCollectionServiceImpl;
    @Autowired
    private IBsOrderSchedulingService bsOrderSchedulingService;
    private static final Logger logger = LoggerFactory.getLogger("sys-user");
    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
    }
 
    public void ryParams(String params)
    {
        System.out.println("执行有参方法:" + params);
    }
 
    public void ryNoParams()
    {
        String a=passingStationCollectionServiceImpl.SelectSN("88","OP010");
        System.out.println("执行过程返回:" + a);
    }
 
    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();
    }
 
    public void report10(){
        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
        bsOrderScheduling.setReport10("0");
        List<BsOrderScheduling> bsOrderSchedulings = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
        String status="";
        String ev_meassage="";
        for (BsOrderScheduling orderScheduling : bsOrderSchedulings) {
            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);
                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);
            }
        }
    }
 
    public void report20(){
        BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
        bsOrderScheduling.setReport20("0");
        List<BsOrderScheduling> bsOrderSchedulings = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
        String status="";
        String ev_meassage="";
        for (BsOrderScheduling orderScheduling : bsOrderSchedulings) {
            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);
                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 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" +
                "   <soapenv:Body>\n" +
                "      <urn:ZPP_BC_001>\n" +
                "         <IV_AUFNR>"+orderNo+"</IV_AUFNR>\n" +
                "          <IV_VORNR>"+location+"</IV_VORNR>\n" +
                "           <IV_LMNGA>1</IV_LMNGA>\n" +
                "           <IV_XMNGA>0</IV_XMNGA>   \n" +
                "         <IV_STATU>1</IV_STATU>  \n" +
                "      </urn:ZPP_BC_001>\n" +
                "   </soapenv:Body>\n" +
                "</soapenv:Envelope>";
        //logger.info("{}",content);
        return content;
    }
}