春风项目四线(合箱线、总装线)
懒羊羊
2024-01-22 55b0cb49a929591ebb18df62aa5d68636d4c7e9c
定时任务
已修改3个文件
已添加1个文件
209 ■■■■■ 文件已修改
jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReceivingServices.java 66 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReportingForWork.java 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-quartz/pom.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-quartz/src/main/java/com/jcdm/quartz/task/RyTask.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReceivingServices.java
@@ -2,6 +2,9 @@
import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.jcdm.main.da.collectionParamConf.service.IDaCollectionParamConfService;
@@ -40,16 +43,28 @@
//        test1();
//        String serviceUrl = "http://podqapp.cfmoto.com.cn:50200/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_MES_005_SYN_OUT&interfaceNamespace=http://cfmoto.com/xi/MES";
//
//        String serviceUrl = "http://podqapp.cfmoto.com.cn:50200/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_BC_001_SYN_OUT&interfaceNamespace=http://cfmoto.com/xi/MES";
////        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_CF_MES_005>\n" +
////                "         <!--Optional:-->\n" +
////                "         <IV_WERKS>1000</IV_WERKS>\n" +
////                "         <!--Optional:-->\n" +
////                "         <IV_ZSCTZD>A0055577</IV_ZSCTZD>\n" +
////                "      </urn:ZPP_CF_MES_005>\n" +
////                "   </soapenv:Body>\n" +
////                "</soapenv:Envelope>";
//        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_CF_MES_005>\n" +
//                "         <!--Optional:-->\n" +
//                "         <IV_WERKS>1000</IV_WERKS>\n" +
//                "         <!--Optional:-->\n" +
//                "         <IV_ZSCTZD>A0055577</IV_ZSCTZD>\n" +
//                "      </urn:ZPP_CF_MES_005>\n" +
//                "      <urn:ZPP_BC_001>\n" +
//                "         <IV_AUFNR>000010569212</IV_AUFNR>\n" +
//                "          <IV_VORNR>0010</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>";
//        // HttpClient发送SOAP请求
@@ -79,10 +94,10 @@
//            InputStream is = postMethod.getResponseBodyAsStream();
//            // èŽ·å–请求结果字符串
//            String result = IOUtils.toString(is);
//            String jsonStr = xmlToJSON2(result);
//            Gson gson = new Gson();
//            // å°†json字符串转换成对象
//            ItemList itemList = gson.fromJson(jsonStr, ItemList.class);
////            String jsonStr = xmlToJSON2(result);
////            Gson gson = new Gson();
////            // å°†json字符串转换成对象
////            ItemList itemList = gson.fromJson(jsonStr, ItemList.class);
//            System.out.println("返回结果:" + result);
//        } else {
//            System.out.println("错误代码:" + status + ":" + postMethod.getResponseBodyAsString());
@@ -195,4 +210,33 @@
        return etData.toString();
    }
    /**
     * æ–¹å¼--è´°
     * ä½¿ç”¨hutool工具包中的工具转化
     * @param xmlStr
     * @return
     */
    public static String xmlToJSON3(String xmlStr){
        String status = "";
        if(xmlStr.contains("EV_STATUS")){
            JSONObject jsonObject1 = cn.hutool.json.XML.toJSONObject(xmlStr, true);
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode rootNode = null;
            try {
                rootNode = objectMapper.readTree(String.valueOf(jsonObject1));
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
            String evStatus = rootNode
                    .path("SOAP:Envelope")
                    .path("SOAP:Body")
                    .path("n0:ZPP_BC_001.Response")
                    .path("EV_STATUS")
                    .asText();
            status = evStatus;
        }
        return status;
    }
}
jcdm-main/src/main/java/com/jcdm/main/webservice/service/ReportingForWork.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,78 @@
package com.jcdm.main.webservice.service;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
public class ReportingForWork {
    public static void main(String[] args) throws IOException {
        String serviceUrl = "http://podqapp.cfmoto.com.cn:50200/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_BC_001_SYN_OUT&interfaceNamespace=http://cfmoto.com/xi/MES";
//        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_CF_MES_005>\n" +
//                "         <!--Optional:-->\n" +
//                "         <IV_WERKS>1000</IV_WERKS>\n" +
//                "         <!--Optional:-->\n" +
//                "         <IV_ZSCTZD>A0055577</IV_ZSCTZD>\n" +
//                "      </urn:ZPP_CF_MES_005>\n" +
//                "   </soapenv:Body>\n" +
//                "</soapenv:Envelope>";
        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>000010569212</IV_AUFNR>\n" +
                "          <IV_VORNR>0010</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>";
        // HttpClient发送SOAP请求
        int timeout = 10000;
        HttpClient client = new HttpClient();
        //如果需要用户名密码验证;不需要验证登录则不需要以下4行
        String username = "POMESUSER";
        String password = "12345tgb";
        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
        client.getState().setCredentials(AuthScope.ANY, creds);
        PostMethod postMethod = new PostMethod(serviceUrl);
        // è®¾ç½®è¿žæŽ¥è¶…æ—¶
        client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
        // è®¾ç½®è¯»å–时间超时
        client.getHttpConnectionManager().getParams().setSoTimeout(timeout);
        // ç„¶åŽæŠŠSoap请求数据添加到PostMethod中
        RequestEntity requestEntity = new StringRequestEntity(content, "text/xml", "UTF-8");
        // è®¾ç½®è¯·æ±‚头部,否则可能会报 â€œno SOAPAction header” çš„错误
        postMethod.setRequestHeader("SOAPAction", "");
        // è®¾ç½®è¯·æ±‚体
        postMethod.setRequestEntity(requestEntity);
        int status = client.executeMethod(postMethod);
        if (status == 200) {// æˆåŠŸ
            InputStream is = postMethod.getResponseBodyAsStream();
            // èŽ·å–请求结果字符串
            String result = IOUtils.toString(is);
//            String jsonStr = xmlToJSON2(result);
//            Gson gson = new Gson();
//            // å°†json字符串转换成对象
//            ItemList itemList = gson.fromJson(jsonStr, ItemList.class);
            System.out.println("返回结果:" + result);
        } else {
            System.out.println("错误代码:" + status + ":" + postMethod.getResponseBodyAsString());
        }
    }
}
jcdm-quartz/pom.xml
@@ -35,6 +35,11 @@
            <artifactId>jcdm-common</artifactId>
        </dependency>
        <dependency>
            <groupId>com.jcdm</groupId>
            <artifactId>jcdm-main</artifactId>
        </dependency>
    </dependencies>
</project>
jcdm-quartz/src/main/java/com/jcdm/quartz/task/RyTask.java
@@ -1,7 +1,13 @@
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.webservice.service.ReceivingServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.jcdm.common.utils.StringUtils;
import java.util.List;
/**
 * å®šæ—¶ä»»åŠ¡è°ƒåº¦æµ‹è¯•
@@ -25,4 +31,58 @@
    {
        System.out.println("执行无参方法");
    }
    @Autowired
    private IBsOrderSchedulingService bsOrderSchedulingService;
    String url = "http://podqapp.cfmoto.com.cn:50200/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);
        for (BsOrderScheduling orderScheduling : bsOrderSchedulings) {
            String xmlResult = ReceivingServices.getInterfaceInformationXml(url, getProductionPlanInformationXml(orderScheduling.getOrderNo(), "0010"));
            String status = ReceivingServices.xmlToJSON3(xmlResult);
            if(status.equals("1")){
                orderScheduling.setReport10("1");
                int i = bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling);
                System.out.println("更新状态成功");
            }
        }
    }
    public void report20(){
        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(), "0790"));
            String status = ReceivingServices.xmlToJSON3(xmlResult);
            if(status.equals("1")){
                orderScheduling.setReport10("1");
                int i = bsOrderSchedulingService.updateBsOrderScheduling(orderScheduling);
                System.out.println("更新状态成功");
            }
        }
    }
    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>";
        return content;
    }
}