no message
							parent
							
								
									1f6228b58c
								
							
						
					
					
						commit
						e1c7bc68c7
					
				| 
						 | 
				
			
			@ -1,19 +1,16 @@
 | 
			
		|||
package com.youchain.utils;
 | 
			
		||||
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.commons.compress.utils.IOUtils;
 | 
			
		||||
 | 
			
		||||
import java.io.DataOutputStream;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.net.URLConnection;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
 | 
			
		||||
@Slf4j
 | 
			
		||||
public class HttpPostUtil {
 | 
			
		||||
    public static String sendPostReq(String api_url, String request) {
 | 
			
		||||
        InputStream instr;
 | 
			
		||||
        String str = "";
 | 
			
		||||
        InputStream instr = null;
 | 
			
		||||
        String str = null;
 | 
			
		||||
        try {
 | 
			
		||||
            URL url = new URL(api_url);
 | 
			
		||||
            URLConnection urlCon = url.openConnection();
 | 
			
		||||
| 
						 | 
				
			
			@ -31,13 +28,14 @@ public class HttpPostUtil {
 | 
			
		|||
            printout.close();
 | 
			
		||||
            instr = urlCon.getInputStream();
 | 
			
		||||
            byte[] bis = IOUtils.toByteArray(instr);
 | 
			
		||||
            String ResponseString = new String(bis, StandardCharsets.UTF_8);
 | 
			
		||||
            if (StringUtils.isEmpty(ResponseString)) {
 | 
			
		||||
                log.error("返回空");
 | 
			
		||||
            String ResponseString = new String(bis, "UTF-8");
 | 
			
		||||
            if ((ResponseString == null) || ("".equals(ResponseString.trim()))) {
 | 
			
		||||
                System.out.println("返回空");
 | 
			
		||||
            }
 | 
			
		||||
            str = ResponseString;
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.error("接口异常!");
 | 
			
		||||
            System.out.println("接口异常!");
 | 
			
		||||
            // throw new Error(e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
        return str;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,8 +25,13 @@ import org.springframework.data.domain.Page;
 | 
			
		|||
import org.springframework.data.domain.Pageable;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.transaction.annotation.Transactional;
 | 
			
		||||
import org.w3c.dom.Document;
 | 
			
		||||
import org.w3c.dom.Element;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
import javax.xml.parsers.DocumentBuilder;
 | 
			
		||||
import javax.xml.parsers.DocumentBuilderFactory;
 | 
			
		||||
import java.io.ByteArrayInputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.sql.Timestamp;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
| 
						 | 
				
			
			@ -204,18 +209,29 @@ public class LesServiceImpl implements LesService {
 | 
			
		|||
 | 
			
		||||
            //返回结果
 | 
			
		||||
            resultJson = HttpPostUtil.sendPostReq(url, json);
 | 
			
		||||
            if (StringUtils.isEmpty(resultJson)) {
 | 
			
		||||
                throw new BadRequestException("LES返回信息:LES回传接口调用失败!");
 | 
			
		||||
            }
 | 
			
		||||
            JSONObject resulObject = JSON.parseObject(resultJson);
 | 
			
		||||
            if (resulObject == null) {
 | 
			
		||||
                throw new BadRequestException("LES返回信息:LES回传接口返回为空!");
 | 
			
		||||
            }
 | 
			
		||||
            log.info("LES返回报文:{}", resultJson);
 | 
			
		||||
            Map<String, String> result = parseResponse(resultJson);
 | 
			
		||||
            if (result == null) {
 | 
			
		||||
                if (StringUtils.isEmpty(resultJson)) {
 | 
			
		||||
                    throw new BadRequestException("LES返回信息:LES回传接口调用失败!");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            String resultCode = resulObject.getString("resultCode");
 | 
			
		||||
            String displayMsg = resulObject.getString("displayMsg");
 | 
			
		||||
            if (!"success".equals(resultCode)) {
 | 
			
		||||
                throw new BadRequestException("LES返回消息:" + displayMsg);
 | 
			
		||||
                JSONObject resulObject = JSON.parseObject(resultJson);
 | 
			
		||||
                if (resulObject == null) {
 | 
			
		||||
                    throw new BadRequestException("LES返回信息:LES回传接口返回为空!");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                String resultCode = resulObject.getString("resultCode");
 | 
			
		||||
                String displayMsg = resulObject.getString("displayMsg");
 | 
			
		||||
                if (!"success".equals(resultCode)) {
 | 
			
		||||
                    throw new BadRequestException("LES返回消息:" + displayMsg);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                String resultCode = result.get("resultCode");
 | 
			
		||||
                String displayMsg = result.get("displayMsg");
 | 
			
		||||
                if (!"success".equals(resultCode)) {
 | 
			
		||||
                    throw new BadRequestException("LES返回消息:" + displayMsg);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -226,6 +242,26 @@ public class LesServiceImpl implements LesService {
 | 
			
		|||
        lesRepository.save(les);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public static Map<String, String> parseResponse(String xmlString) {
 | 
			
		||||
        try {
 | 
			
		||||
            Map<String, String> map = new HashMap<>();
 | 
			
		||||
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 | 
			
		||||
            DocumentBuilder builder = factory.newDocumentBuilder();
 | 
			
		||||
            Document document = builder.parse(new ByteArrayInputStream(xmlString.getBytes()));
 | 
			
		||||
 | 
			
		||||
            Element root = document.getDocumentElement();
 | 
			
		||||
            String resultCode = root.getElementsByTagName("resultCode").item(0).getTextContent();
 | 
			
		||||
            String displayMsg = root.getElementsByTagName("displayMsg").item(0).getTextContent();
 | 
			
		||||
            map.put("resultCode", resultCode);
 | 
			
		||||
            map.put("displayMsg", displayMsg);
 | 
			
		||||
            return map;
 | 
			
		||||
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void arrivedLes(Long agvTaskId, String currentPositionCode) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue