package com.zy.asrs.task.handler; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.core.exception.CoolException; import com.zy.asrs.entity.param.ArmPrecomputeParam; import com.zy.asrs.entity.param.OrderToLine; import com.zy.asrs.service.ApiLogService; import com.zy.asrs.service.BasArmRulesService; import com.zy.asrs.service.OrderService; 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; @Slf4j @Service @Transactional public class OrderToLineHandler extends AbstractHandler { @Autowired private ApiLogService apiLogService; @Autowired private OrderService orderService; @Value("${line.address.URL}") //端口 private String URL; @Value("${line.address.PATH}") //审核地址 private String Path; public ReturnT start(OrderToLine orderToline) { try{ String response = ""; boolean success = false; try { response = new HttpHandler.Builder() .setUri(URL) .setPath(Path) .setJson(JSON.toJSONString(orderToline)) .build() .doPost(); JSONObject jsonObject = JSON.parseObject(response); if (jsonObject.getInteger("code").equals(200)) { success = true; orderService.updateOrderStatus(orderToline.getOrderNo()); //更新订单状态 0 -> 1 } else { log.error("下发单据!!!url:{};request:{};response:{}", URL+Path, JSON.toJSONString(orderToline), response); throw new CoolException("下发单据失败"); } } catch (Exception e) { log.error("fail", e); return FAIL.setMsg(e.getMessage()); } finally { try { // 保存接口日志 apiLogService.save( "下发单据至分拣线", URL + Path, null, "127.0.0.1", JSON.toJSONString(orderToline), response, success ); } catch (Exception e) { log.error("", e); } } }catch (Exception e){ } return SUCCESS; } }