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;
|
}
|
}
|