liu 2 лет назад
Родитель
Сommit
d6220cef90

+ 4 - 0
src/main/java/com/template/api/SmartVisitorControllerAPI.java

@@ -131,5 +131,9 @@ public interface SmartVisitorControllerAPI {
     @ApiOperation(value = "访客预约数据", notes = "访客预约数据", httpMethod = "GET")
     CommonResult getPage(@RequestParam int currentPage, @RequestParam int pageCount,@RequestParam Integer type,String keyWord,Integer status,String startTime,String endTime,String visitorStartTime,String visitorEndTime);
 
+    @GetMapping(value = "/parentsAudit")
+    @ApiOperation(value = "家长审核", notes = "家长审核", httpMethod = "GET")
+    CommonResult parentsAudit(@RequestParam int id,@RequestParam int type);
+
 
 }

+ 154 - 3
src/main/java/com/template/controller/SmartVisitorController.java

@@ -3,6 +3,7 @@ package com.template.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -86,6 +87,9 @@ public class SmartVisitorController implements SmartVisitorControllerAPI {
     @Autowired
     SmartVisitorParentsConfigService smartVisitorParentsConfigService;
 
+    @Autowired
+    SmartVisitorRestsConfigService smartVisitorRestsConfigService;
+
     /**
      * 新增访客预约
      *
@@ -240,9 +244,71 @@ public class SmartVisitorController implements SmartVisitorControllerAPI {
 //                核销
                 Integer appCancelConfig = svpc.getAppCancelConfig();
                 if (6==appCancelConfig) {//需要核销
-
+                    sv.setStatu(7);
+                }else {//不需要核销
+                    sv.setStatu(9);
+                }
+//                门禁配置
+                Integer accessConfig = svpc.getAccessConfig();
+                if (0==accessConfig) {
+                    try {
+                        if (!ObjectUtils.isEmpty(sv.getCarNum())) {
+                            String appId = parkConfig.getAppId();
+                            String carNo = sv.getCarNum();
+                            String parkKey = parkConfig.getParkKey();
+                            String rand = String.valueOf(Math.random());
+                            String reserveTime = TimeExchange.DateToString(sv.getVisitorTime(), "yyyy-MM-dd HH:mm:ss");
+                            String reserveEndTime = TimeExchange.DateToString(sv.getVisitorDeadline(), "yyyy-MM-dd HH:mm:ss");
+                            String version = "v1.0";
+                            String appSecret = parkConfig.getAppSecret();
+                            String url = parkConfig.getUrl() + "Inform/Reservation";
+
+                            JSONObject jsonobject = new JSONObject();
+                            jsonobject.put("appid", appId);
+                            jsonobject.put("carNo", carNo);
+                            jsonobject.put("parkKey", parkKey);
+                            jsonobject.put("rand", rand);
+                            jsonobject.put("reserveEndTime", reserveEndTime);
+                            jsonobject.put("reserveTime", reserveTime);
+                            jsonobject.put("version", "v1.0");
+
+                            //appid=ymdd36ed157ac423e2&carNo=赣U123659&parkKey=wdcmq9rc&rand=9.94995525689689966&reserveEndTime=2023-12-22 20:12:10&reserveTime=2023-12-21 18:12:10&version=v1.0&50596cd243dc4547b4c05f01f8ea02a4
+                            String md5Str = "appid=" + appId + "&carNo=" + carNo + "&parkKey=" + parkKey + "&rand=" + rand + "&reserveEndTime=" + reserveEndTime + "&reserveTime=" + reserveTime + "&version=" + version + "&" + appSecret;
+                            String sign = CommonUtil.MD5(md5Str);
+                            //sign签名
+                            jsonobject.put("sign", sign);
+
+                            //返回的结果中 code为1表示成功
+                            String result = RequestUtils.httpPost(url, jsonobject.toJSONString());
+
+                            logger.info(result);
+
+                            if (!result.contains("预约成功")) {
+                                throw new Exception("审核失败");
+                            }
+
+                            ObjectMapper objectMapper = new ObjectMapper();
+                            BsReservationVo reservation = objectMapper.readValue(result, BsReservationVo.class);
+                            sv.setBsOrderNo(reservation.getData().getReOrderNo());
+                        } else {
+                            List<SmartDevice> devices = smartDeviceService.queryOnLineDevice();
+                            String visitorNo = getUUIDBits(16);
+                            //region 将访客数据下发到设备
+                            for (SmartDevice device : devices) {
+                                CommonResult<String> insertVisitor = bsInsertVisitor(su, TimeExchange.DateToString(sv.getVisitorTime()), TimeExchange.DateToString(sv.getVisitorDeadline()), device.getNum(), visitorNo);
+                                if (!insertVisitor.isSuccess()) {
+                                    throw new Exception(insertVisitor.getMessage());
+                                }
+                                sv.setVisitorsync(sv.getVisitorsync() == null ? insertVisitor.getData() : (sv.getVisitorsync() + "," + insertVisitor.getData()));
+                                sv.setDeviceNum(sv.getDeviceNum() == null ? device.getNum() : (sv.getDeviceNum() + "," + device.getNum()));
+                            }
+                            String code = GetVertifyCode.getRandomNumCode(6);
+                            sv.setVisitorCode(code);
+                        }
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
                 }
-
             }
 
             svs.add(sv);
@@ -255,6 +321,7 @@ public class SmartVisitorController implements SmartVisitorControllerAPI {
         return result ? CommonResult.ok("预约成功,等待审批通过") : CommonResult.fail("预约失败");
     }
 
+
     @Override
     @DESRespondSecret(validated = true)
     public CommonResult otherAppointment(otherAppointmentRequest oar, BindingResult bindingResult) {
@@ -288,13 +355,92 @@ public class SmartVisitorController implements SmartVisitorControllerAPI {
         sv.setPeerNum(oar.getPeerNum());
         sv.setCarNum(oar.getCarNum());
         sv.setVisitReason(oar.getVisitReason());
-        sv.setStatu(eApproveStatu.Audit.getValue());
+//        sv.setStatu(eApproveStatu.Audit.getValue());
         sv.setVisitorTime(TimeExchange.StringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
         sv.setVisitorDeadline(TimeExchange.StringToDate(endTime, "yyyy-MM-dd HH:mm:ss"));
         sv.setRespondentName(oar.getRespondentName());
         sv.setRespondentPhone(oar.getRespondentPhone());
         sv.setVisitorType(eVisitorType.Other.getValue());
 
+        List<SmartVisitorRestsConfig> list = smartVisitorRestsConfigService.list(new LambdaQueryWrapper<>());
+        SmartVisitorRestsConfig smartVisitorRestsConfig = list.get(0);
+        Integer auditConfig = smartVisitorRestsConfig.getAuditConfig();
+        if (1==auditConfig) {//需要审核
+            sv.setStatu(1);
+        }else if (9==auditConfig){
+            sv.setStatu(9);
+            Integer accessConfig = smartVisitorRestsConfig.getAccessConfig();
+            if (0==accessConfig) {//推送到门禁
+                try {
+                    if (!ObjectUtils.isEmpty(sv.getCarNum())) {
+                        String appId = parkConfig.getAppId();
+                        String carNo = sv.getCarNum();
+                        String parkKey = parkConfig.getParkKey();
+                        String rand = String.valueOf(Math.random());
+                        String reserveTime = TimeExchange.DateToString(sv.getVisitorTime(), "yyyy-MM-dd HH:mm:ss");
+                        String reserveEndTime = TimeExchange.DateToString(sv.getVisitorDeadline(), "yyyy-MM-dd HH:mm:ss");
+                        String version = "v1.0";
+                        String appSecret = parkConfig.getAppSecret();
+                        String url = parkConfig.getUrl() + "Inform/Reservation";
+
+                        JSONObject jsonobject = new JSONObject();
+                        jsonobject.put("appid", appId);
+                        jsonobject.put("carNo", carNo);
+                        jsonobject.put("parkKey", parkKey);
+                        jsonobject.put("rand", rand);
+                        jsonobject.put("reserveEndTime", reserveEndTime);
+                        jsonobject.put("reserveTime", reserveTime);
+                        jsonobject.put("version", "v1.0");
+
+                        //appid=ymdd36ed157ac423e2&carNo=赣U123659&parkKey=wdcmq9rc&rand=9.94995525689689966&reserveEndTime=2023-12-22 20:12:10&reserveTime=2023-12-21 18:12:10&version=v1.0&50596cd243dc4547b4c05f01f8ea02a4
+                        String md5Str = "appid=" + appId + "&carNo=" + carNo + "&parkKey=" + parkKey + "&rand=" + rand + "&reserveEndTime=" + reserveEndTime + "&reserveTime=" + reserveTime + "&version=" + version + "&" + appSecret;
+                        String sign = CommonUtil.MD5(md5Str);
+                        //sign签名
+                        jsonobject.put("sign", sign);
+
+                        //返回的结果中 code为1表示成功
+                        String result = RequestUtils.httpPost(url, jsonobject.toJSONString());
+
+                        logger.info(result);
+
+                        if (!result.contains("预约成功")) {
+                            throw new Exception("审核失败");
+                        }
+
+                        ObjectMapper objectMapper = new ObjectMapper();
+                        BsReservationVo reservation = objectMapper.readValue(result, BsReservationVo.class);
+                        sv.setBsOrderNo(reservation.getData().getReOrderNo());
+                    } else {
+                        List<SmartDevice> devices = smartDeviceService.queryOnLineDevice();
+                        String visitorNo = getUUIDBits(16);
+                        //region 将访客数据下发到设备
+                        for (SmartDevice device : devices) {
+                            CommonResult<String> insertVisitor = bsInsertVisitor(su, TimeExchange.DateToString(sv.getVisitorTime()), TimeExchange.DateToString(sv.getVisitorDeadline()), device.getNum(), visitorNo);
+                            if (!insertVisitor.isSuccess()) {
+                                throw new Exception(insertVisitor.getMessage());
+                            }
+                            sv.setVisitorsync(sv.getVisitorsync() == null ? insertVisitor.getData() : (sv.getVisitorsync() + "," + insertVisitor.getData()));
+                            sv.setDeviceNum(sv.getDeviceNum() == null ? device.getNum() : (sv.getDeviceNum() + "," + device.getNum()));
+                        }
+                        String code = GetVertifyCode.getRandomNumCode(6);
+                        sv.setVisitorCode(code);
+                    }
+
+                    //发送短信给其他访客用户
+                    if (!ObjectUtils.isEmpty(sv.getVisitorCode())) {
+                        String message = SendSms.sendVisitorSms("+86" + sv.getUserPhone(), TimeExchange.getYear(sv.getVisitorTime()), TimeExchange.getMonth(sv.getVisitorTime()), TimeExchange.getDay(sv.getVisitorTime()), TimeExchange.getTime(sv.getVisitorTime()), TimeExchange.getTime(sv.getVisitorDeadline()),sv.getVisitorCode());
+                        if (!message.contains("success")) {
+                            throw new Exception("发送失败");
+                        }
+                    }
+
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+
+            }
+        }
+
         int result = smartVisitorService.insertSmartVisitor(sv);
 
         return result > 0 ? CommonResult.ok("预约成功,等待审批通过") : CommonResult.ok("预约失败");
@@ -463,6 +609,11 @@ public class SmartVisitorController implements SmartVisitorControllerAPI {
         return CommonResult.ok(page);
     }
 
+    @Override
+    public CommonResult parentsAudit(int id, int type) {
+        return null;
+    }
+
     /**
      * 1、学生请假:
      * 我们这边调用请假接口之后,把请假数据写到了百胜系统的"学生请假登记"页面中,那到时候学生是通过任意设备都能进出吗?