CustomsLockController.java 3.7 KB
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");
    }

}