doum
2025-09-12 7d28e7367852aaa35587e4fd1bf29674ac17d5f6
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.doumee.cloud.openapi;
 
import com.alibaba.fastjson.JSONObject;
import com.doumee.api.BaseController;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.config.annotation.LoginNoRequired;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.exception.BusinessException;
import com.doumee.service.business.third.model.ApiResponse;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DESUtil;
import com.doumee.dao.openapi.request.*;
import com.doumee.dao.openapi.response.*;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.*;
import com.doumee.service.system.SystemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
/**
 * @author 江蹄蹄
 * @date 2023/11/30 15:33
 */
@Api(tags = "提供安防平台对接接口(数据大屏基础数据等)")
@RestController
@Slf4j
@RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX+"/hk/api")
public class HkOpenApiController extends BaseController {
 
    @Autowired
    private PlatformService platformService;
    @Autowired
    private InterfaceLogService interfaceLogService;
 
    @Autowired
    private PlatformLogService platformLogService;
 
    @Autowired
    private PlatformJobService platformJobService;
 
    @Autowired
    private PlatformWarnEventService platformWarnEventService;
 
    @Autowired
    private PlatformWaterGasService platformWaterGasService;
 
    @Autowired
    private SystemUserService systemUserService;
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;
 
    @LoginNoRequired
    @ApiOperation("token解析")
    @GetMapping("/water/decodeToken")
    public Map<String,Object> decodeToken(@RequestParam String token) {
        log.info("【安防平台单点登录token解析】================="+token);
        int success = Constants.ZERO;
        Map<String,Object>  result = new HashMap<>() ;
        try {
            HkBaseTokenRequest hkBaseTokenRequest = new HkBaseTokenRequest();
            hkBaseTokenRequest.setToken(token);
            result = this.decodeTokenForHk(hkBaseTokenRequest);
        }catch (BusinessException e){
            log.error("【安防平台】单点登录token解===失败:"+e.getMessage());
            success = Constants.ONE;
        }catch (Exception e){
            log.error("【安防平台】单点登录token解析===失败:"+e.getMessage());
            e.printStackTrace();
            success = Constants.ONE;
        }finally {
            interfaceLogService.saveInterfaceLog("/hk/api/water/decodeToken", "【安防平台】单点登录token解析",token,
                    success, JSONObject.toJSONString(result),Constants.ZERO);
        }
        return result;
    }
 
    public Map<String,Object> decodeTokenForHk(HkBaseTokenRequest hkBaseTokenRequest)   {
        Map<String,Object> result = new HashMap<>();
        result.put("code","0");
        result.put("msg","success");
        if(Objects.isNull(hkBaseTokenRequest)||StringUtils.isBlank(hkBaseTokenRequest.getToken())){
            result.put("code","-1");
            result.put("msg","token参数为空");
            return result;
        }
        String redisToken = (String) redisTemplate.opsForValue().get(Constants.REDIS_HK_TOKEN_KEY+hkBaseTokenRequest.getToken());
        if(StringUtils.isBlank(redisToken)){
            result.put("code","-1");
            result.put("msg","token无效!");
            return result;
        }
        String userName = DESUtil.verifyHkToken( redisToken);;
        if(StringUtils.isBlank(userName)){
            result.put("code","-1");
            result.put("msg","token参数为空");
            return result;
        }
        //查询用户信息是否存在
        SystemUser systemUser = new SystemUser();
        systemUser.setUsername(userName);
        systemUser.setDeleted(Boolean.FALSE);
        SystemUser queryBean = systemUserService.findOne(systemUser);
        if(Objects.isNull(queryBean)){
            result.put("code","-1");
            result.put("msg","token参数为空");
            return result;
        }
        if(Constants.equalsInteger(queryBean.getStatus(),Constants.ONE)){
            result.put("code","-2");
            result.put("msg","用户已禁用");
            return result;
        }
        redisTemplate.delete(Constants.REDIS_HK_TOKEN_KEY+hkBaseTokenRequest.getToken());
        Map<String,Object> data = new HashMap<>();
        data.put("userId",userName);
        result.put("data",data);
        return result;
    }
 
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【用水量】本月、上月和去年同月")
    @PostMapping("/water/dataByMonth")
    public ApiResponse<WaterByMonthResponse> waterDataByMonth(@RequestBody WaterByMonthRequest param) {
        return ApiResponse.success(platformWaterGasService.waterDataByMonth(param));
    }
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【用水量】近12个月用水量信息列表")
    @PostMapping("/water/lastMonthsDataList")
    public ApiResponse<List<PlatformLastMonthListResponse>> lastMonthsWaterList() {
        return ApiResponse.success(platformWaterGasService.getPlatformLastMonthListResponse(Constants.ZERO));
    }
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【用气量】本月、上月和去年同月")
    @PostMapping("/gas/dataByMonth")
    public ApiResponse<GasByMonthResponse> gasDataByMonth(@RequestBody GasByMonthRequest param) {
        return ApiResponse.success(platformWaterGasService.gasDataByMonth(param));
    }
 
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【用气量】近12个月用气量信息列表")
    @PostMapping("/gas/lastMonthsDataList")
    public ApiResponse<List<PlatformLastMonthListResponse>> lastMonthsGasList () {
        return ApiResponse.success(platformWaterGasService.getPlatformLastMonthListResponse(Constants.ONE));
    }
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】按天统计运单请求参数")
    @PostMapping("/platform/orderNumByDate")
    public ApiResponse<PlatformOrderNumByDateResponse> orderNumByDate(@RequestBody PlatformOrderNumByDateRequest param) {
        return ApiResponse.success(platformJobService.orderNumByDate(param));
    }
 
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】月台状态数量统计")
    @PostMapping("/platform/totalNumByStatus")
    public ApiResponse<PlatformNumByStatusResponse> totalNumByStatus(@RequestBody PlatformNumByStatusRequest param) {
        return ApiResponse.success(platformService.getPlatformNumByStatusResponse());
    }
 
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】月台当前作业信息列表")
    @PostMapping("/platform/workingDataList")
    public ApiResponse<List<PlatformDataListResponse>> workingDataList(@RequestBody PlatformDataListRequest param) {
        return ApiResponse.success(platformJobService.platformWorkingDataList(param));
    }
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】月台作业详情信息")
    @PostMapping("/platform/workDataInfo")
    public ApiResponse<PlatformDataInfoResponse> workDataInfo(@RequestBody PlatformDataInfoRequest param) {
        return ApiResponse.success(platformJobService.platformWorkingDataList(param));
    }
 
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】当前车辆状态数量统计")
    @PostMapping("/platform/carStatusNum")
    public ApiResponse<CarNumByStatusResponse> carStatusNum(@RequestBody CarNumByStatusRequest param) {
        return ApiResponse.success(platformJobService.carStatusNum(param));
    }
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】车辆事件列表数据集合(最新N条)")
    @PostMapping("/platform/carLogsList")
    public ApiResponse<List<CarLogsListResponse>> carLogsList(@RequestBody CarLogsListRequest param) {
        return ApiResponse.success(platformLogService.getCarLogsListResponse(param));
    }
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】排队队列列表集合")
    @PostMapping("/platform/queueList")
    public ApiResponse<PlatformQueuingListResponse> queueList(@RequestBody PlatformQueuingListRequest param) {
        return ApiResponse.success(platformJobService.queueList(param));
    }
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】预警事件集合列表")
    @PostMapping("/platform/warningEventList")
    public ApiResponse<List<PlatformWarnEventListResponse>> warningEventList(@RequestBody PlatformWarnEventListRequest param) {
        return ApiResponse.success(platformWarnEventService.findListToHk());
    }
 
    @LoginNoRequired
    @PreventRepeat
    @ApiOperation("【月台】月台状态")
    @PostMapping("/platform/getStatusList")
    public ApiResponse<List<PlatformStatusListResponse>> getStatusList() {
        return ApiResponse.success(platformService.getPlatformStatusList());
    }
 
}