package com.zy.asrs.task.handler;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.entity.WrkDetlLog;
|
import com.zy.asrs.entity.WrkMast;
|
import com.zy.asrs.service.ApiLogService;
|
import com.zy.asrs.service.WrkDetlLogService;
|
import com.zy.asrs.task.AbstractHandler;
|
import com.zy.asrs.task.core.ReturnT;
|
import com.zy.common.model.InventoryAdjustmentParam;
|
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;
|
|
@Slf4j
|
@Service
|
public class InventoryAdjustmentReportHandler extends AbstractHandler<String> {
|
|
@Autowired
|
private WrkDetlLogService wrkDetlLogService;
|
@Autowired
|
private ApiLogService apiLogService;
|
|
@Transactional
|
public ReturnT<String> report(WrkMast wrkMast){
|
WrkDetlLog wrkDetlLog = wrkDetlLogService.selectOne(new EntityWrapper<WrkDetlLog>().eq("wrk_no", wrkMast.getWrkNo()).eq("io_time", wrkMast.getIoTime()));
|
InventoryAdjustmentParam param = new InventoryAdjustmentParam();
|
param.setChangeType(wrkMast.getIoType()); // 调整类型
|
param.setWareHouseId("HLWMS"); // 仓库编码
|
param.setSourceLocId(wrkMast.getIoType() != 1 ? wrkMast.getSourceLocNo() : ""); // 源库位号
|
param.setTargetLocId(wrkMast.getIoType() != 101 ? wrkMast.getLocNo() : ""); // 目标库位号 移库时有
|
param.setMatNr(wrkDetlLog.getMatnr()); // 物料编码
|
param.setQty(wrkDetlLog.getAnfme().toString()); // 调整数量
|
param.setPalletId(wrkMast.getBarcode()); // 托盘号
|
|
String response = "";
|
boolean success = false;
|
try {
|
response = new HttpHandler.Builder()
|
.setUri("http://localhost:8080/api")
|
.setPath("/inventory/adjustment")
|
.setJson(JSON.toJSONString(param))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject.getInteger("code") == 200){
|
success = true;
|
}else {
|
log.error("请求接口失败!!!url:{};request:{};response:{}", "http://localhost:8080/api"+"/inventory/adjustment", JSON.toJSONString(param), response);
|
throw new CoolException("库存调整上报mes系统失败");
|
}
|
}catch (Exception e){
|
log.error("fail",e);
|
return FAIL.setMsg(e.getMessage());
|
}finally {
|
try {
|
// 保存接口日志
|
apiLogService.save(
|
"库存调整主动上报",
|
"http://localhost:8080/api/inventory/adjustment",
|
null,
|
"127.0.0.1",
|
JSON.toJSONString(param),
|
response,
|
success
|
);
|
}catch (Exception e) {
|
log.error("",e);
|
}
|
}
|
return SUCCESS;
|
}
|
}
|