自动化立体仓库 - WMS系统
dubin
1 天以前 2a9f6d72baa207bc91c98d0a5cd2235be9816691
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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;
    }
}