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