java110
2020-12-28 5e0d835fcf76cbd2f94fba1d589dea79a23ed15e
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
package com.java110.common.api;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.common.bmo.machine.IMachineOpenDoorBMO;
import com.java110.common.bmo.machine.ISaveMachineRecordBMO;
import com.java110.common.bmo.machine.IUpdateMachineTransactionStateBMO;
import com.java110.common.bmo.machineTranslateError.IGetMachineTranslateErrorBMO;
import com.java110.dto.machine.MachineRecordDto;
import com.java110.dto.machine.MachineTranslateDto;
import com.java110.dto.machineTranslateError.MachineTranslateErrorDto;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
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.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * 设备相关接口类
 * <p>
 * add by 吴学文 2020-12-28
 */
@RestController
@RequestMapping(value = "/machine")
public class MachineApi {
 
    private static final String USER_ROLE_OWNER = "owner";
    @Autowired
    private IMachineOpenDoorBMO machineOpenDoorBMOImpl;
 
    @Autowired
    private IGetMachineTranslateErrorBMO getMachineTranslateErrorBMOImpl;
 
    @Autowired
    private ISaveMachineRecordBMO saveMachineRecordBMOImpl;
 
    @Autowired
    private IUpdateMachineTransactionStateBMO updateMachineTransactionStateBMOImpl;
 
    /**
     * 设备开门功能
     *
     * @param reqJson
     * @return
     * @serviceCode /machine/openDoor
     * @path /app/machine/openDoor
     */
    @RequestMapping(value = "/openDoor", method = RequestMethod.POST)
    public ResponseEntity<String> openDoor(@RequestBody JSONObject reqJson,
                                           @RequestHeader(value = "user-id", required = false) String userId) {
        Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含小区信息");
        Assert.hasKeyAndValue(reqJson, "machineCode", "请求报文中未包含设备信息");
        Assert.hasKeyAndValue(reqJson, "userRole", "请求报文中未包含用户角色");
        if (!USER_ROLE_OWNER.equals(reqJson.getString("userRole"))) { //这种为 员工的情况呢
            reqJson.put("userId", userId);
        }
        Assert.hasKeyAndValue(reqJson, "userId", "请求报文中未包含设备信息");
        return machineOpenDoorBMOImpl.openDoor(reqJson);
    }
 
    /**
     * 设备开门功能
     *
     * @param reqJson
     * @return
     * @serviceCode /machine/restartMachine
     * @path /app/machine/restartMachine
     */
    @RequestMapping(value = "/restartMachine", method = RequestMethod.POST)
    public ResponseEntity<String> restartMachine(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含小区信息");
        Assert.hasKeyAndValue(reqJson, "machineCode", "请求报文中未包含设备信息");
        return machineOpenDoorBMOImpl.restartMachine(reqJson);
    }
 
 
    /**
     * 重新送物联网系统
     *
     * @param reqJson
     * @return
     * @serviceCode /machine/resendIot
     * @path /app/machine/resendIot
     */
    @RequestMapping(value = "/resendIot", method = RequestMethod.POST)
    public ResponseEntity<String> resendIot(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "machineTranslateId", "未包含同步ID");
        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区ID");
        return machineOpenDoorBMOImpl.resendIot(reqJson);
    }
 
    /**
     * 微信删除消息模板
     *
     * @param communityId 小区ID
     * @return
     * @serviceCode /machine/queryMachineTranslateError
     * @path /app/machine/queryMachineTranslateError
     */
    @RequestMapping(value = "/queryMachineTranslateError", method = RequestMethod.GET)
    public ResponseEntity<String> queryMachineTranslateError(@RequestParam(value = "communityId") String communityId,
                                                             @RequestParam(value = "page") int page,
                                                             @RequestParam(value = "row") int row) {
        MachineTranslateErrorDto machineTranslateErrorDto = new MachineTranslateErrorDto();
        machineTranslateErrorDto.setPage(page);
        machineTranslateErrorDto.setRow(row);
        machineTranslateErrorDto.setCommunityId(communityId);
        return getMachineTranslateErrorBMOImpl.get(machineTranslateErrorDto);
    }
 
    /**
     * 重新送物联网系统
     *
     * @param reqJson
     * @return
     * @serviceCode /machine/openDoorLog
     * @path /app/machine/openDoorLog
     */
    @RequestMapping(value = "/openDoorLog", method = RequestMethod.POST)
    public ResponseEntity<String> openDoorLog(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "userId", "未包含用户信息");
        Assert.hasKeyAndValue(reqJson, "userName", "未包含用户名称");
        Assert.hasKeyAndValue(reqJson, "machineCode", "未包含设备编码");
        Assert.hasKeyAndValue(reqJson, "openTypeCd", "未包含开门方式");
        Assert.hasKeyAndValue(reqJson, "similar", "未包含开门相似度");
        Assert.hasKeyAndValue(reqJson, "photo", "未包含抓拍照片");
        Assert.hasKeyAndValue(reqJson, "dateTime", "未包含开门时间");
        Assert.hasKeyAndValue(reqJson, "extCommunityId", "未包含小区信息");
        Assert.hasKeyAndValue(reqJson, "recordTypeCd", "未包含记录类型");
        MachineRecordDto machineRecordDto = BeanConvertUtil.covertBean(reqJson, MachineRecordDto.class);
        machineRecordDto.setCommunityId(reqJson.getString("extCommunityId"));
        machineRecordDto.setName(reqJson.getString("userName"));
        return saveMachineRecordBMOImpl.saveRecord(machineRecordDto);
    }
 
    /**
     * 物联网系统指令执行情况
     *
     * @param reqJson
     * @return
     * @serviceCode /machine/cmdResult
     * @path /app/machine/cmdResult
     */
    @RequestMapping(value = "/cmdResult", method = RequestMethod.POST)
    public ResponseEntity<String> cmdResult(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "taskId", "未包含任务信息");
        Assert.hasKeyAndValue(reqJson, "code", "未包含结果编码");
        Assert.hasKeyAndValue(reqJson, "msg", "未包含结果说明");
        MachineTranslateDto machineRecordDto = new MachineTranslateDto();
        machineRecordDto.setMachineTranslateId(reqJson.getString("taskId"));
        machineRecordDto.setState(reqJson.getIntValue("code") == 0
                ? MachineTranslateDto.STATE_SUCCESS : MachineTranslateDto.STATE_ERROR);
        machineRecordDto.setRemark(reqJson.getString("msg"));
        return updateMachineTransactionStateBMOImpl.update(machineRecordDto);
    }
 
}