package com.zy.asrs.task.handler; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.zy.asrs.entity.WrkMast; import com.zy.asrs.service.ApiLogService; import com.zy.asrs.service.WrkMastService; import com.zy.asrs.task.AbstractHandler; import com.zy.asrs.task.core.ReturnT; import com.zy.common.utils.HttpHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; @Slf4j @Service @Transactional public class OutWorkHandler extends AbstractHandler { @Autowired private ApiLogService apiLogService; @Value("${wcs.address.URL}") private String addrs; @Value("${wcs.address.outboundTaskSend}") private String outboundTaskSend; @Autowired private WrkMastService wrkMastService; public synchronized ReturnT start(WrkMast wrkMast) { HashMap map = new HashMap<>(); map.put("taskNo", wrkMast.getWrkNo()); map.put("taskPriority", 10); map.put("taskType", wrkMast.getIoType() == 11 ? 3 : 2); map.put("startPoint", wrkMast.getSourceLocNo()); map.put("targetPoint", wrkMast.getLocNo()); map.put("barcode", wrkMast.getBarcode()); String response =""; boolean bool =false; try { log.info("wms派发任务给wcs出库={}", JSON.toJSONString(map)); response = new HttpHandler.Builder() // .setHeaders(headParam) .setUri(addrs) .setPath(outboundTaskSend) .setJson(JSON.toJSONString(map)) .build() .doPost(); JSONObject jsonObject = JSON.parseObject(response); if(jsonObject.getInteger("code") == 200){ wrkMast.setWrkSts(12L); wrkMastService.updateById(wrkMast); bool = true; }else { log.error("wms派发任务给wcs出库失败{},返回值={}", JSON.toJSONString(wrkMast), response); } } catch (Exception e) { log.error("wms派发任务给wcs出库失败{},返回值={}", JSON.toJSONString(wrkMast), response); } finally { apiLogService.save("wms派发任务给wcs出库" , addrs + outboundTaskSend , null , "127.0.0.1" , JSON.toJSONString(map) , response , bool ); } return SUCCESS; } }