package com.zy.asrs.task.handler;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.*;
|
import com.zy.asrs.service.ApiLogService;
|
import com.zy.asrs.service.DocTypeService;
|
import com.zy.asrs.service.OrderDetlPakinService;
|
import com.zy.asrs.service.OrderPakinService;
|
import com.zy.asrs.task.AbstractHandler;
|
import com.zy.asrs.task.core.ReturnT;
|
import com.zy.common.constant.ApiInterfaceConstant;
|
import com.zy.common.constant.MesConstant;
|
import com.zy.common.model.MesPakinParam;
|
import com.zy.common.utils.HttpHandler;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* Created by vincent on 2020/7/7
|
*/
|
@Slf4j
|
@Service
|
public class OrderPakinSyncHandler extends AbstractHandler<String> {
|
|
@Autowired
|
private OrderPakinService orderPakinService;
|
@Autowired
|
private OrderDetlPakinService orderDetlPakinService;
|
@Autowired
|
private ApiLogService apiLogService;
|
@Autowired
|
private DocTypeService docTypeService;
|
|
|
@Transactional
|
public ReturnT<String> startOrderReport(OrderPakin order) {
|
|
DocType docType = docTypeService.selectById(order.getDocType());
|
if (null == docType) {
|
log.error("未找到对应的DocType,订单号:{},单据类型:{}", order.getOrderNo(), order.getDocType());
|
return FAIL.setMsg("未找到对应的单据类型:" + order.getOrderNo());
|
}
|
|
ErpReportDto param = new ErpReportDto();
|
param.setOrderDetails(new ArrayList<>());
|
List<OrderDetlPakin> orderDetls = orderDetlPakinService.selectByOrderId(order.getId());
|
for (OrderDetlPakin orderDetl : orderDetls) {
|
param.getOrderDetails().add(new ErpReportDto.DetlDto(orderDetl.getMatnr(),orderDetl.getQty()));
|
}
|
param.setOrderNo(order.getOrderNo());
|
|
String response = "";
|
boolean success = false;
|
ReturnT<String> result = SUCCESS;
|
try {
|
response = new HttpHandler.Builder()
|
.setUri(ApiInterfaceConstant.ERP_IP)
|
.setPath(ApiInterfaceConstant.PAKIN_PATH)
|
.setJson(JSON.toJSONString(param))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.getInteger("code").equals(200)) {
|
// 修改订单状态 4.完成 ===>> 6.已上报
|
orderPakinService.updateSettle(order.getId(), 6L, null);
|
success = true;
|
} else {
|
log.error("入库完成上报erp失败!url:{};request:{};response:{}", ApiInterfaceConstant.ERP_IP + ApiInterfaceConstant.PAKIN_PATH, JSON.toJSONString(param), response);
|
throw new CoolException("入库完成上报erp失败");
|
}
|
} catch (Exception e) {
|
log.error("入库完成上报erp异常", e);
|
result = FAIL.setMsg("入库完成上报异常:" + e.getMessage());
|
} finally {
|
try {
|
// 保存接口日志
|
apiLogService.save(
|
"入库完成上报",
|
ApiInterfaceConstant.ERP_IP + ApiInterfaceConstant.PAKIN_PATH,
|
null,
|
"127.0.0.1",
|
JSON.toJSONString(param),
|
response,
|
success
|
);
|
} catch (Exception e) {
|
log.error("入库保存接口日志异常", e);
|
}
|
}
|
|
return result;
|
}
|
|
}
|