| | |
| | | package com.zy.asrs.task.handler; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class MesPakinHandler extends AbstractHandler<String> { |
| | | @Value("${mes.pakin.url}") |
| | | private String url; |
| | | private String uri; |
| | | |
| | | @Value("${mes.pakin.path}") |
| | | private String path; |
| | |
| | | @Transactional |
| | | public ReturnT<String> start() { |
| | | boolean success = true; |
| | | log.info("url:" + url + path); |
| | | log.info("url:" + uri + path); |
| | | JSONObject jsonObject = null; |
| | | try { |
| | | jsonObject = doGetJsonData(); |
| | | jsonObject = doPostJsonData(); |
| | | log.info("MesPakinHandler jsonObject:" + jsonObject); |
| | | } catch (IOException e) { |
| | | success = false; |
| | | e.printStackTrace(); |
| | |
| | | int code = jsonObject.getInteger("code"); |
| | | |
| | | if(code == 200){ |
| | | JSONObject jsonData = jsonObject.getJSONObject("data"); |
| | | String orderNo = jsonData.getString("orderNo"); |
| | | Order o = insertOrder(jsonData,orderNo); |
| | | insertOrUpdateOrderDetl(jsonData, o); |
| | | if(!Cools.isEmpty(jsonObject.getString("data")) && jsonObject.getString("data").length()>2){ |
| | | |
| | | JSONArray jsonArray = jsonObject.getJSONArray("data"); |
| | | List<JSONObject> jsonDataList = jsonArray.toJavaList(JSONObject.class); |
| | | |
| | | jsonDataList.forEach(data -> { |
| | | String orderNo = data.getString("orderNo"); |
| | | Order o = insertOrder(data,orderNo); |
| | | insertOrUpdateOrderDetl(data, o); |
| | | }); |
| | | } |
| | | }else { |
| | | success = false; |
| | | log.error("请求mes接口响应错误,响应码为: " + code); |
| | |
| | | private void saveApiLog(String response, boolean success){ |
| | | apiLogService.save( |
| | | "生成入库单据", |
| | | url + path, |
| | | uri + path, |
| | | null, |
| | | "127.0.0.1", |
| | | null, |
| | |
| | | } |
| | | |
| | | /* |
| | | 发起一个doGet请求 |
| | | 发起一个请求来获取未获取过的单据信息 |
| | | */ |
| | | private JSONObject doGetJsonData() throws IOException { |
| | | private JSONObject doPostJsonData() throws IOException { |
| | | |
| | | Map<String, Object> requestParamMap = MesSyncUtil.getRequestParamMap(); |
| | | //获取未获取过的所有单据 |
| | | requestParamMap.put("type",0); |
| | | |
| | | return JSON.parseObject( new HttpHandler.Builder() |
| | | .setUri(url) |
| | | .setUri(uri) |
| | | .setPath(path) |
| | | .setParams(MesSyncUtil.getRequestParamMap()) |
| | | .setParams(requestParamMap) |
| | | .build() |
| | | .doGet()); |
| | | .doPostWithParam()); |
| | | } |
| | | |
| | | /* |
| | |
| | | o.setOrderTime(jsonData.getString("orderTime")); |
| | | //单据类型 |
| | | DocType docType = docTypeService.selectOrAdd(jsonData.getString("orderType"), Boolean.TRUE); |
| | | //入库库房名称(立体库名称) |
| | | jsonData.getString("storage"); |
| | | //物流名称 -- 入库库房名称(立体库名称) |
| | | o.setShipName(jsonData.getString("storage")); |
| | | o.setDocType(docType.getDocId()); |
| | | o.setCreateTime(new Date()); |
| | | o.setUpdateTime(new Date()); |