jiangping
2025-01-16 f63d3a3be83fea258e7920efccd2567b6a511bb3
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
package com.doumee.cloud.admin;
 
import cn.hutool.core.io.IoUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.doumee.service.business.third.model.ApiResponse;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.dao.admin.request.InDeviceEntranceParam;
import com.doumee.dao.admin.response.DevWgDataResponseParam;
import com.doumee.dao.admin.response.DevWgResponseParam;
import com.doumee.dao.admin.response.DevWgYtjResponseParam;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.BookingsService;
import com.doumee.service.business.DevicesService;
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.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 * 微光二维码请求入口
 *
 * @author  lishuai
 * @email
 * @date 2022-12-12 14:30:50
 */
@Api(tags = "微光二维码请求入口接口",value = "")
@RestController
@RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX+"/business/wgListener")
@Slf4j
public class WgListenerCloudController {
    @Autowired
    private SystemUserService systemUserService;
    @Autowired
    private BookingsService bookingsService;
    @Autowired
    private DevicesService devicesService;
    @ApiOperation(value="微光二维码进场核销入口")
    @PostMapping("/qrcodeIn")
    public void qrcodeIn(HttpServletRequest request, HttpServletResponse response) throws  Exception{
        // 入口调用返回json
        response.setDateHeader("Expires", 0);
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        DevWgResponseParam json = reqJSONObject( request);
        log.info("打印json数据================="+json);
        if(null == json) {
            ApiResponse.outputCode(response,"-1");
            return;
        }
        try {
            if(StringUtils.equals("hello",json.getVgdecoderesult())){
                //如果是心跳设置
                devicesService.doHeartDeal(json.getDevicenumber());
                log.info("心跳成功================="+json.getDevicenumber());
                ApiResponse.outputCode(response,"-1");
            }else{
                bookingsService.openRoomDoor(json);
                log.info("扫码成功=================");
                ApiResponse.outputCode(response,"0000");
            }
        }catch (Exception e){
            e.printStackTrace();
            log.info("扫码异常================="+e.getMessage());
            ApiResponse.outputCode(response,"-1");
        }
    }
    @ApiOperation(value="微光一体机二维码进场核销入口")
    @PostMapping("/qrcodeInYtj")
    public void qrcodeInNew(HttpServletRequest request, HttpServletResponse response) throws  Exception{
        // 入口调用返回json
        response.setDateHeader("Expires", 0);
        response.setHeader("Content-Type", "text/html;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        DevWgResponseParam json = reqJSONObjectYtj( request);
        log.info("打印json数据================="+json);
        if(null == json) {
            ApiResponse.outputCode(response,"-1");
            return;
        }
        try {
            if(StringUtils.equals("hello",json.getVgdecoderesult())){
                //如果是心跳设置
                devicesService.doHeartDeal(json.getDevicenumber());
                log.info("心跳成功================="+json.getDevicenumber());
                ApiResponse.outputCode(response,-1,"心跳失败");
            }else{
                bookingsService.openRoomDoor(json);
                log.info("扫码成功=================");
                ApiResponse.outputCode(response,0,"认证成功");
            }
        }catch (Exception e){
            e.printStackTrace();
            log.info("扫码异常================="+e.getMessage());
            ApiResponse.outputCode(response,-1,e.getMessage());
        }
    }
 
    private DevWgResponseParam reqJSONObjectYtj(HttpServletRequest request)  throws  Exception{
        //"type":2,"data":"8tiDkHTlGJdmxP4yAkO7mPR2odwwPgtW","time":1692772938,"deviceSn":"C238180003"
        String input = IoUtil.read(request.getInputStream(), "utf-8");
        log.info("一体机读头设备返回的二维码信息==========="+input);
        DevWgYtjResponseParam param1 = JSONObject.toJavaObject(JSONObject.parseObject(input), DevWgYtjResponseParam.class);
        DevWgResponseParam param = new DevWgResponseParam();
        param.setVgdecoderesult(param1.getData());
        param.setDevicenumber(param1.getDeviceSn());
        log.info("一体机对象数据================="+param);
        //对象传json
        return param;
    }
 
    @ApiOperation(value="微光二维码出场核销出口")
    @PostMapping("/qrcodeOut")
    public void qrcodeOut( HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 出口调用返回json
        DevWgResponseParam json = reqJSONObject( request);
        log.info("打印json数据=================="+json);
        if(null == json) {
            return;
        }
        ApiResponse.outputCode(response,"0000");
    }
 
    /**
     * 微光二维码读头闸机请求,调用进出场接口json封装
     */
    private DevWgResponseParam reqJSONObject( HttpServletRequest request) throws  Exception{
        String input = IoUtil.read(request.getInputStream(), "utf-8");
        log.info("读头设备返回的二维码信息==========="+input);
        String[] split = input.split("&&");
        DevWgResponseParam param = new DevWgResponseParam();
        int indexOne = split[0].indexOf("=");
        int indexTwo = split[1].indexOf("=");
        param.setVgdecoderesult(split[0].substring(indexOne+1));
        param.setDevicenumber(split[1].substring(indexTwo+1));
        log.info("对象数据================="+param);
        //对象传json
//        JSONObject json =  getJSONObject(param);
        return param;
    }
 
    @ApiOperation(value="事件监听按类型处理---微光一体机进场")
    @PostMapping("/taskTwo")
    public void taskTwo( HttpServletRequest request, HttpServletResponse response) throws  Exception  {
        // 入口调用返回json
        JSONObject jsonObject = reqMachineJSONObject( request);
        log.info("参数================"+jsonObject);
        if(null == jsonObject) {
            return;
        }
        ApiResponse.outputCode(response,0,"success");
    }
 
    @ApiOperation(value="事件监听按类型处理---微光一体机出场")
    @PostMapping("/taskOutTwo")
    public void taskOutTwo( HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 入口调用返回json
        JSONObject jsonObject = reqMachineJSONObject(  request);
        log.info("参数================"+jsonObject);
        if(null == jsonObject) {
            return;
        }
 
        ApiResponse.outputCode(response,0,"success");
    }
 
    /**
     * 微光一体机闸机请求,调用进出场接口json封装
     * @return
     */
    private JSONObject reqMachineJSONObject( HttpServletRequest request)  throws Exception  {
 
        // 假设业务认证成功
        String input = IoUtil.read(request.getInputStream(), "utf-8");
        DevWgDataResponseParam responseParam = JSON.parseObject(input , DevWgDataResponseParam.class);
        //对象传json
        InDeviceEntranceParam param = new InDeviceEntranceParam();
        if("1".equals(responseParam.getType())) {  //人脸
            param.setFlag("2");
            param.setUserId(responseParam.getData());
        }else if("2".equals(responseParam.getType())) { //二维码
            param.setFlag("1");
            param.setCode(responseParam.getData());
        }else if("3".equals(responseParam.getType())) { //刷卡
            param.setFlag("3");
            // 根据会员实体卡号关联查询,会员工号
            SystemUser memberDo = systemUserService.findById(1);
            if(null != memberDo) {
                param.setUserId( memberDo.getEmpNo());
            }
            param.setCardNo(responseParam.getData());
 
        }
        param.setDeskId(responseParam.getDeviceSn());
        param.setInTime(DateUtil.getCurrDateTime());
        param.setOutTime(DateUtil.getCurrDateTime());
        JSONObject json =(JSONObject) JSONObject.toJSON(param);
        return (JSONObject)JSONObject.toJSON(param);
    }
}