Parcourir la source

与sass本版代码同步

liujh il y a 3 ans
Parent
commit
c73b3c5c7a

+ 10 - 6
zd-modules/zd-algorithm/src/main/java/com/zd/alg/smartlock/controller/SlOpendoorApplyController.java

@@ -3,6 +3,7 @@ package com.zd.alg.smartlock.controller;
 import com.zd.alg.smartlock.domain.SlOpendoorApply;
 import com.zd.alg.smartlock.domain.vo.SlOpendoorApplyVo;
 import com.zd.alg.smartlock.service.ISlOpendoorApplyService;
+import com.zd.alg.smartlock.utils.SmartlockUtil;
 import com.zd.common.core.domain.per.PerFun;
 import com.zd.common.core.domain.per.PerPrefix;
 import com.zd.common.core.utils.poi.ExcelUtil;
@@ -41,6 +42,9 @@ public class SlOpendoorApplyController extends BaseController
     @Autowired
     private TokenService tokenService;
 
+    @Autowired
+    private SmartlockUtil smartlockUtil;
+
     /**
      * 查询申请开门列表
      */
@@ -51,12 +55,12 @@ public class SlOpendoorApplyController extends BaseController
     {
         //获取登录用户
         SysUser sysUser = tokenService.getLoginUser().getSysUser();
-        startPage();
+        startPage("creat_time","descending");
         List<SlOpendoorApplyVo> list = slOpendoorApplyService.selectSlOpendoorApplyList(slOpendoorApply);
         for (SlOpendoorApplyVo vo:list) {
-                if(vo.getLoseTime().getTime()<System.currentTimeMillis()){
-                    vo.setApplyStatus(2L);
-                }
+            if(vo.getLoseTime().getTime()<System.currentTimeMillis()){
+                vo.setApplyStatus(2L);
+            }
         }
         return getDataTable(list);
     }
@@ -72,7 +76,7 @@ public class SlOpendoorApplyController extends BaseController
         //获取登录用户
         SysUser sysUser = tokenService.getLoginUser().getSysUser();
         slOpendoorApply.setUserId(sysUser.getUserId());
-        startPage();
+        startPage("creat_time","descending");
         List<SlOpendoorApplyVo> list = slOpendoorApplyService.selectSlOpendoorApplyList(slOpendoorApply);
         for (SlOpendoorApplyVo vo:list) {
             if(vo.getLoseTime().getTime()<System.currentTimeMillis()){
@@ -93,7 +97,7 @@ public class SlOpendoorApplyController extends BaseController
         SysUser sysUser = tokenService.getLoginUser().getSysUser();
         slOpendoorApply.setUserId(sysUser.getUserId());
 
-        startPage();
+        startPage("creat_time","descending");
         List<SlOpendoorApplyVo> list = slOpendoorApplyService.selectSlOpendoorApplyListStudent(slOpendoorApply);
         for (SlOpendoorApplyVo vo:list) {
             if(vo.getLoseTime().getTime()<System.currentTimeMillis()){

+ 43 - 84
zd-modules/zd-algorithm/src/main/java/com/zd/alg/smartlock/controller/SlUserRelationController.java

@@ -1,9 +1,14 @@
 package com.zd.alg.smartlock.controller;
 
 import com.zd.alg.smartlock.domain.SlUserRelation;
+import com.zd.alg.smartlock.domain.api.SlLockOnline;
 import com.zd.alg.smartlock.domain.api.SlUser;
+import com.zd.alg.smartlock.domain.vo.SlSubjectRelationVo;
+import com.zd.alg.smartlock.service.ISlSubjectRelationService;
 import com.zd.alg.smartlock.service.ISlUserRelationService;
 import com.zd.alg.smartlock.utils.SmartlockUtil;
+import com.zd.common.core.constant.SecurityConstants;
+import com.zd.common.core.domain.R;
 import com.zd.common.core.utils.poi.ExcelUtil;
 import com.zd.common.core.web.controller.BaseController;
 import com.zd.common.core.web.domain.ResultData;
@@ -11,6 +16,8 @@ import com.zd.common.core.web.page.TableDataInfo;
 import com.zd.common.log.annotation.Log;
 import com.zd.common.log.enums.BusinessType;
 import com.zd.common.security.annotation.PreAuthorize;
+import com.zd.system.api.RemoteUserService;
+import com.zd.system.api.domain.SysUser;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -18,107 +25,59 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
- * 人员关联Controller
- *
- * @author xxf
- * @date 2022-09-02
+ * @Author: xxf
+ * @Date: 2022/09/07/9:43
+ * @Description:
  */
+
 @RestController
-@Api(tags = "【人员关联】")
-@RequestMapping("/userRelation")
+@Api(tags = "门锁相关信息查询")
+@RequestMapping("/lockinfo")
 public class SlUserRelationController extends BaseController
 {
-    @Autowired
-    private ISlUserRelationService slUserRelationService;
 
     @Autowired
+    private ISlSubjectRelationService slSubjectRelationService;
+    @Autowired
+    private RemoteUserService remoteUserService;
+    @Autowired
     private SmartlockUtil smartlockUtil;
 
     /**
-     * 查询人员关联列表
-     */
-    @PreAuthorize(hasPermi = "laboratory:relation:list")
-    @GetMapping("/list")
-    @ApiOperation(value = "查询人员关联列表")
-    public TableDataInfo<SlUserRelation> list(SlUserRelation slUserRelation)
-    {
-        startPage();
-        List<SlUserRelation> list = slUserRelationService.selectSlUserRelationList(slUserRelation);
-        return getDataTable(list);
-    }
-
-    /**
-     * 导出人员关联列表
-     */
-    @ApiOperation(value = "导出人员关联列表")
-    @PreAuthorize(hasPermi = "laboratory:relation:export")
-    @Log(title = "人员关联", businessType = BusinessType.EXPORT)
-    @PostMapping("/export")
-    public void export(HttpServletResponse response, SlUserRelation slUserRelation) throws IOException
-    {
-        List<SlUserRelation> list = slUserRelationService.selectSlUserRelationList(slUserRelation);
-        ExcelUtil<SlUserRelation> util = new ExcelUtil<SlUserRelation>(SlUserRelation.class);
-        util.exportExcel(response, list, "人员关联数据");
-    }
-
-    /**
-     * 获取人员关联详细信息
-     */
-    @ApiOperation(value = "获取人员关联详细信息")
-    @PreAuthorize(hasPermi = "laboratory:relation:query")
-    @GetMapping(value = "/{id}")
-    public ResultData<SlUserRelation> getInfo(@PathVariable("id") Long id)
-    {
-        return ResultData.success(slUserRelationService.selectSlUserRelationById(id));
-    }
-
-    /**
-     * 新增人员关联
+     * 查询实验室门锁信息
      */
-    @ApiOperation(value = "新增人员关联")
-    @PreAuthorize(hasPermi = "laboratory:relation:add")
-    @Log(title = "人员关联", businessType = BusinessType.INSERT)
-    @PostMapping
-    public ResultData add(@RequestBody SlUserRelation slUserRelation)
+    @GetMapping("/detalis")
+    @ApiOperation(value = "查询实验室门锁信息")
+    public TableDataInfo<SlLockOnline> list(Long subjectId)
     {
-        return ResultData.result(slUserRelationService.insertSlUserRelation(slUserRelation));
-    }
+        List<SlLockOnline> lockOnlineslist = new ArrayList<>();
 
-    /**
-     * 修改人员关联
-     */
-    @ApiOperation(value = "修改人员关联")
-    @PreAuthorize(hasPermi = "laboratory:relation:edit")
-    @Log(title = "人员关联", businessType = BusinessType.UPDATE)
-    @PutMapping
-    public ResultData edit(@RequestBody SlUserRelation slUserRelation)
-    {
-        return  ResultData.result(slUserRelationService.updateSlUserRelation(slUserRelation));
+        //查询实验室绑定的门锁集合
+        SlSubjectRelationVo subjectRelation = new SlSubjectRelationVo();
+        subjectRelation.setSubjectId(subjectId);
+        List<SlSubjectRelationVo> list = slSubjectRelationService.selectSlSubjectRelationList(subjectRelation);
+        for (SlSubjectRelationVo sub: list ) {
+            //查询门锁状态
+            SlLockOnline lockOnline = smartlockUtil.getRoomDetails(sub.getLockRoomId());
+            lockOnlineslist.add(lockOnline);
+        }
+        return getDataTable(lockOnlineslist);
     }
 
-    /**
-     * 删除人员关联
-     */
-    @ApiOperation(value = "删除人员关联")
-    @PreAuthorize(hasPermi = "laboratory:relation:remove")
-    @Log(title = "人员关联", businessType = BusinessType.DELETE)
-    @DeleteMapping("/{ids}")
-    public ResultData remove(@PathVariable Long[] ids)
-    {
-        return ResultData.result(slUserRelationService.deleteSlUserRelationByIds(ids));
-    }
-
-    /**
-     * 查询智能锁人员列表
-     */
-    @GetMapping("/listLockUser")
-    @ApiOperation(value = "查询智能锁人员列表")
-    public TableDataInfo<SlUser> listLockUser(SlUser sluser)
+    @GetMapping("/test")
+    public ResultData<Long> test()
     {
-        List<SlUser> list = smartlockUtil.getUser(sluser);
-        return getDataTable(list);
+        R<SysUser> r = remoteUserService.getUserInfoByUserId(1L, SecurityConstants.INNER);
+        logger.info(r.getData().toString());
+        logger.info(smartlockUtil.SERVICE_URL);
+        logger.info(smartlockUtil.USER_LOGIN);
+        logger.info(smartlockUtil.PASSWORD);
+        logger.info(smartlockUtil.AUTHS_LENGTH.toString());
+        logger.info(smartlockUtil.OPEN_COUNT.toString());
+        return ResultData.result(1L);
     }
 }

+ 2 - 2
zd-modules/zd-algorithm/src/main/java/com/zd/alg/smartlock/service/impl/SlApplyApprovalServiceImpl.java

@@ -344,7 +344,7 @@ public class SlApplyApprovalServiceImpl implements ISlApplyApprovalService
             log.info("=======人员1授权开始========");
             Map<String,Object> map1= smartlockUtil.addUser(user,listsubRla.get(0).getLockRoomId());
 
-            if(!SmartlockUtil.resultMsg.equals(map1.get("resultMsg").toString())){
+            if(!smartlockUtil.RESULT_MSG.equals(map1.get("resultMsg").toString())){
                 log.info("人员:"+opendoorApply.getUserName()+",授权失败,原因:"+map1.get("resultMsg")+",请联系管理员");
                 strMsg="人员:"+opendoorApply.getUserName()+",授权失败,原因:"+map1.get("resultMsg")+",请联系管理员";
                 return strMsg;
@@ -377,7 +377,7 @@ public class SlApplyApprovalServiceImpl implements ISlApplyApprovalService
             detalisMap.put("人员2",opendoorApply.getUserName());
             detalisMap.put("锁编2号",listsubRla.get(1).getLockCode());
             detalisMap.put("人员2密码",map2.get("password"));
-            if(!SmartlockUtil.resultMsg.equals(map2.get("resultMsg").toString())){
+            if(!smartlockUtil.RESULT_MSG.equals(map2.get("resultMsg").toString())){
                 log.info("人员2:"+opendoorApply.getUserName()+",授权失败,原因:"+map2.get("resultMsg")+",请联系管理员");
                 strMsg="人员:"+opendoorApply.getUserName()+",授权失败,原因:"+map2.get("resultMsg")+",请联系管理员";
                 return strMsg;

+ 112 - 5
zd-modules/zd-algorithm/src/main/java/com/zd/alg/smartlock/service/impl/SlOpendoorApplyServiceImpl.java

@@ -130,11 +130,21 @@ public class SlOpendoorApplyServiceImpl implements ISlOpendoorApplyService {
         slOpendoorApply.setUserSex(sysUser.getSex() == null ? 1 : Integer.valueOf(sysUser.getSex()));
         slOpendoorApply.setPhonenumber(sysUser.getPhonenumber());
         slOpendoorApply.setCreatTime(new Date());
-        slOpendoorApplyMapper.insertSlOpendoorApply(slOpendoorApply);
+
         try {
-            //授权并且发送短信通知实验室门锁对应的安全负责人
-           String msg=  authPowerNew(slOpendoorApply.getId());
-           log.info("授权或者短信通知结果:"+msg);
+            /*//授权并且发送短信通知实验室门锁对应的安全负责人
+           String msg=  authPowerNew(slOpendoorApply.getId());*/
+            //短信发送成功 数据入库
+            slOpendoorApplyMapper.insertSlOpendoorApply(slOpendoorApply);
+
+            String msg =sendMsgToSafeUser(slOpendoorApply.getId());
+            if(!"ok".equals(msg)){
+                //授权失败删除申请数据
+                slOpendoorApplyMapper.deleteSlOpendoorApplyById(slOpendoorApply.getId());
+                log.info("操作失败:"+msg);
+                return 0;
+            }
+            log.info("短信通知结果:"+msg);
         } catch (Exception e) {
             log.info("授权失败:"+e);
         }
@@ -195,6 +205,103 @@ public class SlOpendoorApplyServiceImpl implements ISlOpendoorApplyService {
         return str;
     }
 
+    /**
+     * 发送短信给相关门锁负责人
+     * @param applyId
+     * @return
+     * @throws Exception
+     */
+    public String sendMsgToSafeUser(Long applyId) throws Exception {
+        log.info("========开始发送短信===========");
+        //返回值
+        String strMsg="ok";
+        Map<String, Object> map = new HashMap<>();
+        try {
+            //查询申请记录
+            SlOpendoorApply opendoorApply = slOpendoorApplyMapper.selectSlOpendoorApplyById(applyId);
+            Map<String,Object> detalisMap = new HashMap<>();
+
+            //检查是否绑定双锁
+            SlSubjectRelationVo relationVo = new SlSubjectRelationVo();
+            relationVo.setSubjectId(opendoorApply.getSubjectId());
+            List<SlSubjectRelationVo> relist = slSubjectRelationMapper.selectSlSubjectRelationList(relationVo);
+            if(relist.size()<2){
+                strMsg="该实验室暂未关联双门锁。";
+                log.info("该实验室暂未关联双门锁。");
+                return strMsg;
+            }
+
+            //查询门锁负责人信息
+            SlSubjectRelationVo rv = new SlSubjectRelationVo();
+            rv.setSafeUserId(Long.valueOf(opendoorApply.getSafeUserId()));
+            rv.setSubjectId(opendoorApply.getSubjectId());
+            relist = slSubjectRelationMapper.selectSlSubjectRelationList(rv);
+
+            if(relist.size()==0){
+                strMsg="未查询到安全负责人关联的实验室信息。";
+                return strMsg;
+            }
+
+            //获取token
+            String token = smartlockUtil.getToken();
+            log.info("安全负责人电话:"+relist.get(0).getSafeUserPhone());
+
+            //查询用户是否存在授权
+            String authis = smartlockUtil.checkUserAuthExis(relist.get(0).getSafeUserPhone(), token);
+            log.info("权限id:"+authis);
+
+            if (StringUtils.isNotEmpty(authis)) {
+                /*//修改授权
+                map = SmartlockUtil.updateAuths(token, relist.get(0).getLockRoomId(), Integer.valueOf(authis+1));
+                log.info("授权修改结果:"+map.get("resultMsg"));
+                strMsg = map.get("resultMsg").toString();*/
+
+                //删除用户授权
+                map = smartlockUtil.deleteAuths(token, relist.get(0).getLockRoomId(), Integer.valueOf(authis) );
+                log.info("删除用户授权结果:"+map.get("resultMsg"));
+                if("ok".equals(map.get("resultMsg"))){
+                    strMsg="删除授权失败,"+map.get("resultMsg");
+                    return strMsg;
+                }
+
+                Thread.sleep(8000);//等待8秒,等待门锁指令发送完毕
+
+                //重新添加授权
+                map = smartlockUtil.addUserAuths(token,  relist.get(0).getSafeUserPhone(), relist.get(0).getLockRoomId());
+                log.info("重新添加授权结果:"+map.get("resultMsg"));
+                if("ok".equals(map.get("resultMsg"))){
+                    strMsg="添加授权失败,"+map.get("resultMsg");
+                    return strMsg;
+                }
+
+
+                log.info("=============下发短信================");
+                //人员1 备注详情
+                detalisMap.put("人员",opendoorApply.getUserName());
+                detalisMap.put("锁编号",relist.get(0).getLockCode());
+                detalisMap.put("人员密码",map.get("password"));
+
+                R r1= remoteStockService.sendSydSms(
+                        "【实验室安全系统】" + opendoorApply.getUserName() + "申请" +
+                                opendoorApply.getSubjectName() +
+                                "-门禁远程授权,手机号:"+opendoorApply.getPhonenumber()+",授权码:"+map.get("password")+
+                                "("+ smartlockUtil.AUTHS_LENGTH+"小时内有效),请勿泄露给他人。",
+                        3, opendoorApply.getId(), relist.get(0).getSafeUserPhone());
+                log.info("人员1短信发送结果:"+r1.getData());
+
+                //修改申请数据
+                opendoorApply.setIllustrate(detalisMap.toString());
+                slOpendoorApplyMapper.updateSlOpendoorApply(opendoorApply);
+            }else{
+                strMsg="用户暂无授权。";
+            }
+
+        }catch (Exception e){
+            log.info("=======人员授权失败========"+e);
+        }
+        return strMsg;
+    }
+
     /***
      * 审批通过后人员密码授权处理
      * @param applyId 申请id
@@ -231,7 +338,7 @@ public class SlOpendoorApplyServiceImpl implements ISlOpendoorApplyService {
             log.info("=======人员1授权开始========");
             Map<String,Object> map1= smartlockUtil.addUser(user,listsubRla.get(0).getLockRoomId());
 
-            if(!SmartlockUtil.resultMsg.equals(map1.get("resultMsg").toString())){
+            if(!smartlockUtil.RESULT_MSG.equals(map1.get("resultMsg").toString())){
                 log.info("人员:"+opendoorApply.getUserName()+",授权失败,原因:"+map1.get("resultMsg")+",请联系管理员");
                 strMsg="人员:"+opendoorApply.getUserName()+",授权失败,原因:"+map1.get("resultMsg")+",请联系管理员";
                 return strMsg;

+ 30 - 1
zd-modules/zd-algorithm/src/main/java/com/zd/alg/smartlock/utils/SmartlockUtil.java

@@ -25,7 +25,7 @@ import java.util.*;
 public class SmartlockUtil {
     private static final Logger logger = LoggerFactory.getLogger(SmartlockUtil.class);
 
-    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     /**
      * 服务访问地址
@@ -364,6 +364,35 @@ public class SmartlockUtil {
         return map;
     }
 
+
+    /***
+     *删除用户授权
+     * @param token
+     * @param roomid
+     * @param authid
+     * @return
+     */
+    public Map<String, Object> deleteAuths(String token, String roomid, Integer authid) {
+        Map<String, Object> map = new HashMap<>();
+        try {
+            String url2 = SERVICE_URL + "/lockauth/operate/5/deleteauths?token=" + token + "&roomid="+roomid ;
+            List<SlupdateAuths> list = new ArrayList<>();
+            SlupdateAuths slupdateAuths = new SlupdateAuths();
+            slupdateAuths.setAuthid(authid);//权限id
+            slupdateAuths.setRctype(3);//(1卡片,2指纹,3密码,4蓝牙,9人脸,10二维码)
+            list.add(slupdateAuths);
+
+            HttpRequest request2 = SmartlockUtil.httpSendPost(url2, JSONObject.toJSONString(list));
+            HttpResponse response2 = request2.execute();
+            String resultMsg = JSON.parseObject(response2.body()).get("resultMsg").toString();
+            map.put("resultMsg", resultMsg);
+            logger.info("删除用户授权结果:"+response2.body());
+        }catch (Exception e) {
+            logger.error("删除用户授权失败" + e);
+        }
+        return map;
+    }
+
     /***
      * 修改用户授权
      * @param token