cl
19 小时以前 8943a4e9f5ee1455c56ac4af60d941fa23731051
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
package com.vincent.rsf.openApi.controller;
 
import com.fasterxml.jackson.databind.JsonNode;
import com.vincent.rsf.openApi.service.RcsTvCallbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.Map;
 
/**
 * RCS 向 WMS 推送:输送线异常、站点任务号;写入与电视机后台相同的 Redis(电视机与 zy-monitor-admin 不改代码)
 */
@Slf4j
@RestController
@Api(tags = "RCS电视机回调")
@RequestMapping("/rcs/callback/tv")
public class RcsTvCallbackController {
 
    @Resource
    private RcsTvCallbackService rcsTvCallbackService;
 
    @PostMapping("/station/error")
    @ApiOperation("输送线异常推送:写入 Redis tvManualErrorMsg")
    public Map<String, Object> stationError(
            @RequestHeader(value = "X-Rcs-Token", required = false) String rcsToken,
            @RequestBody(required = false) JsonNode body) {
        try {
            rcsTvCallbackService.assertToken(rcsToken);
            return rcsTvCallbackService.handleStationError(body);
        } catch (IllegalArgumentException e) {
            return rcsFail(500, e.getMessage());
        } catch (Exception e) {
            log.error("RCS station/error 处理失败", e);
            return rcsFail(500, e.getMessage() != null ? e.getMessage() : "处理失败");
        }
    }
 
    @PostMapping("/station/taskNo")
    @ApiOperation("输送线任务号推送:写入 Redis Hash tvRcsStationTaskNo")
    public Map<String, Object> stationTaskNo(
            @RequestHeader(value = "X-Rcs-Token", required = false) String rcsToken,
            @RequestBody(required = false) JsonNode body) {
        try {
            rcsTvCallbackService.assertToken(rcsToken);
            return rcsTvCallbackService.handleStationTaskNo(body);
        } catch (IllegalArgumentException e) {
            return rcsFail(500, e.getMessage());
        } catch (Exception e) {
            log.error("RCS station/taskNo 处理失败", e);
            return rcsFail(500, e.getMessage() != null ? e.getMessage() : "处理失败");
        }
    }
 
    private static Map<String, Object> rcsFail(int code, String message) {
        Map<String, Object> m = new LinkedHashMap<>();
        m.put("code", code);
        m.put("message", message != null ? message : "失败");
        m.put("timestamp", System.currentTimeMillis());
        m.put("data", null);
        return m;
    }
}