CustomsLockController.java
3.7 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.sy.controller;
import com.alibaba.fastjson.JSON;
import com.sy.model.GatherInfo;
import com.sy.model.LockFeedBack;
import com.sy.model.LockFeignResponse;
import com.sy.model.NoticeLock;
import com.sy.response.ResultJson;
import com.sy.service.CommandLogService;
import com.sy.service.CustomsLockService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
@RestController
@RequestMapping("/lock")
@Slf4j
public class CustomsLockController {
    @Autowired
    CustomsLockService customsLockService;
    @Autowired
    CommandLogService commandLogService;
    @PostMapping("response")
    public ResultJson lockResponse(@RequestBody LockFeedBack feedBack){
        if (StringUtils.isEmpty(feedBack.barcode)){
            return  new ResultJson("400","缺少二维码信息","缺少二维码信息");
        }
        log.info("收到关锁通知");
        StringBuilder sb = new StringBuilder();
//        sb.append("施解封时间:").append(feedBack.locktime).append("\n")
//                .append("关锁秘钥:").append(feedBack.secret).append("\n")
//                .append("施解封内容:").append(feedBack.feedbackconten).append("\n")
//                .append("施解封状态:").append(feedBack.feedbackcode).append("\n");
        String LOCK_TYPE_UNLOCK = "2";
        /**
         * 关锁施解封类型
         * 1 施封
         * 2 解封
         */
        String LOCK_TYPE_LOCK = "1";
        if (LOCK_TYPE_LOCK.equals(feedBack.type)){
            sb.append("施解封类型:").append("施封").append("\n");
        }else if (LOCK_TYPE_UNLOCK.equals(feedBack.type)){
            sb.append("施解封类型:").append("解封").append("\n");
        }else {
            sb.append("施解封类型:").append("未知").append("\n");
            sb.append("施解封类型:").append(feedBack.type).append("\n");
        }
        //判定关锁返回结果,结果正常,继续走抬杆指令,结果异常 不走抬杆指令,转人工抬杆
        /**
         * 关锁通知施解封状态
         * 01 成功
         * 02 失败
         */
        String LOCK_SUCCESS = "01";
        if(LOCK_SUCCESS.equals(feedBack.feedbackcode)){
            //读取缓存
            GatherInfo gatherInfo = customsLockService.cacheRead(feedBack.barcode);
            sb.append("成功");
            if (gatherInfo!=null){
                commandLogService.commandlog(gatherInfo,true,sb.toString(),null,null,0.0,0.0,0.0,0.0);
                customsLockService.localGatherInfoHandle(gatherInfo);
            }else {
                sb.append("关锁缓存信息读取失败");
                gatherInfo = new GatherInfo();
                gatherInfo.setBarcode(feedBack.barcode);
                gatherInfo.setGrosswt(new BigDecimal(0));
                commandLogService.commandlog(gatherInfo,false,sb.toString(),null,null,0.0,0.0,0.0,0.0);
                log.info("[LOCK-RSP]-关锁缓存信息读取失败");
            }
        }else {
            sb.append("关锁施解封失败");
            GatherInfo gatherInfo = new GatherInfo();
            gatherInfo.setBarcode(feedBack.barcode);
            gatherInfo.setGrosswt(new BigDecimal(0));
            commandLogService.commandlog(gatherInfo,false,sb.toString(),null,null,0.0,0.0,0.0,0.0);
            log.info("[LOCK-RSP]-关锁施解封失败");
        }
        return  new ResultJson("200","success");
    }
}