| package com.doumee.api.business; | 
|   | 
| import cn.hutool.core.io.IoUtil; | 
| import com.alibaba.fastjson.JSON; | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.doumee.core.model.ApiResponse; | 
| 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; | 
| import java.io.IOException; | 
| import java.io.PrintWriter; | 
|   | 
| /** | 
|  * 微光二维码请求入口 | 
|  * | 
|  * @author  lishuai | 
|  * @email | 
|  * @date 2022-12-12 14:30:50 | 
|  */ | 
| @Api(tags = "微光二维码请求入口接口",value = "") | 
| @RestController | 
| @RequestMapping("/wgListener") | 
| @Slf4j | 
| public class WgListenerController { | 
|     @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); | 
|     } | 
| } |