Browse Source

扫码外出方法

peiguo 5 năm trước cách đây
mục cha
commit
74c0717229

+ 2 - 1
whepi-doc/login.sql

@@ -194,8 +194,9 @@ CREATE TABLE out_scan  (
   scan_id           bigint(20) NOT NULL DEFAULT 0 COMMENT '扫码ID',
   user_id           bigint(20) NOT NULL DEFAULT 0 COMMENT '人员会ID',
   uptown_id         bigint(20) NOT NULL DEFAULT 0 COMMENT '小区ID,下拉选ID',
-  door_id           bigint(20) NOT NULL DEFAULT 0 COMMENT '小区大门ID',
+  into_door_id      bigint(20) NOT NULL DEFAULT 0 COMMENT '进入小区大门ID',
   into_date         datetime(0) NOT NULL DEFAULT '0000-01-01 00:00:00' COMMENT '进入时间',
+  out_door_id       bigint(20) NOT NULL DEFAULT 0 COMMENT '出去小区大门ID',
   out_date          datetime(0) NOT NULL DEFAULT '0000-01-01 00:00:00' COMMENT '出去时间',
   user_create       bigint(20) NOT NULL DEFAULT 0 COMMENT '新增人',
   time_create       datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '新增时间',

+ 13 - 0
whepi-ui/templates/home/frag.head.ftl

@@ -34,6 +34,19 @@
             font-weight: 900;
             margin: 0 15%;
         }
+        .user-title-long {
+            text-align: center;
+            font-size: 15px;
+            color: #000000;
+            font-weight: 900;
+            margin: 0 15%;
+        }
+        .red {
+            color: red;
+        }
+        .green {
+            color: green;
+        }
         .user-hr {
             align: center;
             width: 100%;

+ 72 - 0
whepi-ui/templates/user/scan.ftl

@@ -0,0 +1,72 @@
+<#assign title="小区进出扫码"/>
+<#include "/home/frag.head.ftl" />
+
+<div class="weui-tab">
+    <div class="weui-tab__bd">
+        <input id="userId" type="text" hidden="hidden" value=${user_id!}/>
+        <input id="uptownId" type="text" hidden="hidden" value=${uptown_id!}/>
+        <input id="uptownName" type="text" hidden="hidden" value=${uptown_name!}/>
+        <div class="weui-tab__bd-item weui-tab__bd-item--active">
+            <div class="page__bd">
+                <header class="user-header">
+                    <br/>
+                    <br/>
+                    <br/>
+                    <br/>
+                    <br/>
+                    <p class="user-title-long">${doorplate!''}
+                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${name!''}</p>
+                    <br/>
+                    <h1 class="user-title-long ${collor!''}">${door!''}</h1>
+                    <br/>
+                    <h1 class="user-title ${collor!''}">${into!""}</h1>
+                    <br/>
+                    <br/>
+                    <p class="user-title-long  ${collor!''}">${errorMsg!""}</p>
+
+
+<#--                    <#if (inType?? )&&(inType = 1) >-->
+<#--                        <#if (type?? )&&(type !="1") ><h1 class="user-title green">可以进入</h1></#if>-->
+<#--                        <#if (type?? )&&(type ="-1") ><h1 class="user-title red">禁止进入</h1></#if>-->
+<#--                        <#if (type?? )&&(type ="-1") ><p class="user-title-long">非本小区居民,禁止进入。</p></#if>-->
+<#--                    </#if>-->
+<#--                    <#if (inType?? )&&(inType != 1) ><#if (type?? )&&(type ="1") ><h1 class="user-title green">可以外出</h1></#if>-->
+<#--                            <#if (type?? )&&(type !="1") ><h1 class="user-title red">禁止外出</h1></#if>-->
+
+<#--                    <#if (type?? )&&(type ="1") ><p class="user-title-long">请佩戴口罩,避免近距离接触,不得长时间在外逗留。</p></#if>-->
+<#--                    <#if (type?? )&&(type ="-1") ><p class="user-title-long">非本小区居民,禁止外出。</p></#if>-->
+<#--                    <#if (type?? )&&(type ="-2") ><p class="user-title-long">外出时间间隔不满三日,禁止外出,请配合,上次外出时间 ${lastTime!''}。</p></#if>-->
+<#--                    <#if (type?? )&&(type ="-3") ><p class="user-title-long">因近期您未提交健康日报,无法确认您当前健康状态,静止外出,请配合。</p></#if>-->
+
+<#--                    </#if>-->
+                    <br/>
+                    <br/>
+                </header>
+                <br/>
+                <br/>
+                <p class="user-title-long">${now!''}</p>
+            </div>
+        </div>
+    </div>
+</div>
+</div>
+</body>
+<#include "/home/frag.foot.ftl" />
+<script>
+
+    (function ($) {
+        if ($("#uptownId").val() == '1238790987234') {
+            $("#adminName").text('管理员');
+            $("#homeName").text('员工');
+        }
+    })(jQuery);
+
+    function yes() {
+        var userType = $('input:radio:checked').val();
+        if (!userType) {
+            $.alert("请选择用户角色!")
+            return false;
+        }
+        window.location.href = "/user/homeIndex.html?userId=" + $("#userId").val() + "&userType=" + userType;
+    }
+</script>

+ 12 - 0
whepi-web/src/main/java/com/bofeng/dao/MsReportMapper.java

@@ -41,4 +41,16 @@ public interface MsReportMapper extends BaseMapper<MsReport> {
     @Select("select count(suspected_id) from ms_suspected where report_id=#{reportId} and suspected_status=1")
     Integer selectisNoSuspectedNum(@Param("reportId") Long reportId);
 
+    /**
+     * 最近3天是否都有上报
+     * @param userId
+     * @return
+     */
+    @Select("select * from ms_report where report_status=1 and report_date=date_sub(curdate(),interval 1 day) and user_create=#{userId}\n" +
+            "union\n" +
+            "select * from ms_report where report_status=1 and report_date=date_sub(curdate(),interval 2 day) and user_create=#{userId}\n" +
+            "union\n" +
+            "select * from ms_report where report_status=1 and report_date=date_sub(curdate(),interval 3 day) and user_create=#{userId}")
+    List<MsReport> selectMsReportLate(@Param("userId") Long userId);
+
 }

+ 5 - 0
whepi-web/src/main/java/com/bofeng/dao/OutScanConfMapper.java

@@ -3,9 +3,14 @@ package com.bofeng.dao;
 import com.baomidou.mybatisplus.mapper.BaseMapper;
 import com.bofeng.entity.OutScanConf;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 import org.springframework.stereotype.Repository;
 
 @Mapper
 @Repository
 public interface OutScanConfMapper extends BaseMapper<OutScanConf> {
+
+    @Select("select* from out_scan_conf where uptown_id = #{uptownId}")
+    OutScanConf getOutScanConfByUptown(@Param("uptownId")Long uptownId);
 }

+ 5 - 0
whepi-web/src/main/java/com/bofeng/dao/OutScanMapper.java

@@ -3,9 +3,14 @@ package com.bofeng.dao;
 import com.baomidou.mybatisplus.mapper.BaseMapper;
 import com.bofeng.entity.OutScan;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 import org.springframework.stereotype.Repository;
 
 @Mapper
 @Repository
 public interface OutScanMapper extends BaseMapper<OutScan> {
+
+    @Select("SELECT s.* FROM out_scan s WHERE s.user_id = #{userId} ORDER BY s.time_create DESC LIMIT 1")
+    OutScan getOutScanByUserlimit(@Param("userId") Long userId);
 }

+ 3 - 2
whepi-web/src/main/java/com/bofeng/dao/UptownDoorMapper.java

@@ -11,7 +11,8 @@ import org.springframework.stereotype.Repository;
 @Repository
 public interface UptownDoorMapper extends BaseMapper<UptownDoor> {
 
-    @Select("select ud.door_id,u.uptown_id,u.uptown_name,ud.door_name from sys_uptown_door ud inner join " +
-            "sys_uptown u on u.uptown_id = ud.uptown_id where ud.door_id = #{doorId} and ud.status = 1")
+    @Select("SELECT ud.door_id,u.uptown_id,u.uptown_name,ud.door_name FROM sys_uptown_door ud INNER JOIN " +
+            "sys_uptown u ON u.uptown_id = ud.uptown_id WHERE ud.door_id = #{doorId} AND ud.STATUS = 1")
     UptownDoor getUptownDoorById(@Param("doorId") Long doorId);
+
 }

+ 7 - 3
whepi-web/src/main/java/com/bofeng/entity/OutScan.java

@@ -28,14 +28,18 @@ public class OutScan {
     @TableField("uptown_id")
     private Long uptownId;
 
-    @ApiModelProperty("小区大门ID")
-    @TableField("door_id")
-    private Long doorId;
+    @ApiModelProperty("进入小区大门ID")
+    @TableField("into_door_id")
+    private Long intoDoorId;
 
     @ApiModelProperty("进入时间")
     @TableField("into_date")
     private DateTime intoDate;
 
+    @ApiModelProperty("出去小区大门ID")
+    @TableField("out_door_id")
+    private Long outDoorId;
+
     @ApiModelProperty("出去时间")
     @TableField("out_date")
     private DateTime outDate;

+ 1 - 1
whepi-web/src/main/java/com/bofeng/entity/OutScanConf.java

@@ -26,7 +26,7 @@ public class OutScanConf {
 
     @ApiModelProperty("进出间隔时间")
     @TableField("go_out_fre")
-    private Long goOutFre;
+    private Integer goOutFre;
 
     @TableField(exist = false)
     private DateTime timeCreate;

+ 5 - 3
whepi-web/src/main/java/com/bofeng/entity/UptownDoor.java

@@ -38,9 +38,11 @@ public class UptownDoor {
     @TableField(exist = false)
     private DateTime timeUpdate;
 
-    /**
-     * 小区名称
-     */
+    @ApiModelProperty("小区名称")
     @TableField(exist = false)
     private String uptownName;
+
+    @ApiModelProperty("出门间隔时间")
+    @TableField(exist = false)
+    private Integer goOutFre;
 }

+ 59 - 0
whepi-web/src/main/java/com/bofeng/service/ScanService.java

@@ -0,0 +1,59 @@
+package com.bofeng.service;
+
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+import com.bofeng.dao.OutScanMapper;
+import com.bofeng.entity.OutScan;
+import org.joda.time.DateTime;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional(readOnly = true)
+public class ScanService {
+
+    @Autowired
+    private OutScanMapper outScanMapper;
+
+    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
+    public void saveOutScan(Long userId, Integer inType, Long uptownId, Long doorId) {
+        if (inType == 1) {
+            // 进出的时候修改数据,但若是第一次进去就需要加一条出去的数据
+            OutScan outScan1 = outScanMapper.getOutScanByUserlimit(userId);
+            if (outScan1 == null) {
+                OutScan outScan = new OutScan();
+                outScan.setScanId(IdWorker.getId());
+                outScan.setUserId(userId);
+                outScan.setUptownId(uptownId);
+                outScan.setIntoDoorId(doorId);
+                outScan.setIntoDate(new DateTime());
+                outScan.setOutDoorId(doorId);
+                outScan.setOutDate(new DateTime());
+                outScan.setUserCreate(userId);
+                outScan.setUserUpdate(userId);
+                outScanMapper.insert(outScan);
+            } else {
+                outScan1.setIntoDoorId(doorId);
+                outScan1.setIntoDate(new DateTime());
+                outScan1.setUserUpdate(userId);
+                outScanMapper.updateById(outScan1);
+            }
+        } else if (inType == 2) {
+            // 出去的时候添加数据
+            OutScan outScan = new OutScan();
+            outScan.setScanId(IdWorker.getId());
+            outScan.setUserId(userId);
+            outScan.setUptownId(uptownId);
+            outScan.setOutDoorId(doorId);
+            outScan.setOutDate(new DateTime());
+
+            outScan.setIntoDoorId(0L);
+            outScan.setIntoDate(null);
+
+            outScan.setUserCreate(userId);
+            outScan.setUserUpdate(userId);
+            outScanMapper.insert(outScan);
+        }
+    }
+}

+ 79 - 9
whepi-web/src/main/java/com/bofeng/wx/controller/ScanController.java

@@ -3,12 +3,14 @@ package com.bofeng.wx.controller;
 import com.bofeng.dao.*;
 import com.bofeng.entity.*;
 import com.bofeng.service.HomeService;
+import com.bofeng.service.ScanService;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.yvan.platform.JsonWapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -16,7 +18,11 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.servlet.ModelAndView;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
 @Api("进出扫码")
@@ -35,14 +41,23 @@ public class ScanController {
     private UptownUnitMapper uptownUnitMapper;
     @Autowired
     private UptownDoorMapper uptownDoorMapper;
+    @Autowired
+    private OutScanMapper outScanMapper;
+    @Autowired
+    private OutScanConfMapper outScanConfMapper;
+    @Autowired
+    private MsReportMapper msReportMapper;
+    @Autowired
+    private ScanService scanService;
 
     @ApiOperation("进出扫码页面")
     @GetMapping("/user/scan.html")
-    public ModelAndView home(ModelMap model, @RequestParam(value = "doorId", required = false, defaultValue = "0") Long doorId) {
-//        UserOpen userOpen = homeService.getUserOpen();
-//        List<UserRole> list = userRoleMapper.getUserRoleByUserId(userOpen.getUserId());
-        List<UserRole> list = userRoleMapper.getUserRoleByUserId(1L);
-        UserOpen userOpen = userOpenMapper.selectByUserId(1L);
+    public ModelAndView home(ModelMap model, @RequestParam(value = "doorId", required = false, defaultValue = "0") Long doorId,
+            @RequestParam(value = "inType", required = false, defaultValue = "0") Integer inType) {
+        UserOpen userOpen = homeService.getUserOpen();
+        List<UserRole> list = userRoleMapper.getUserRoleByUserId(userOpen.getUserId());
+//        List<UserRole> list = userRoleMapper.getUserRoleByUserId(1L);
+//        UserOpen userOpen = userOpenMapper.selectByUserId(1L);
         model.put("user", userOpen);
         model.put("user_id", "\"" + userOpen.getUserId() + "\"");
         if (list.size() == 0) {
@@ -51,14 +66,69 @@ public class ScanController {
             UptownDoor uptownDoor = uptownDoorMapper.getUptownDoorById(doorId);
             List<UptownHome> uptownHomes =  uptownHomeMapper.getUptownHomeByUserId(userOpen.getUserId());
             UptownUnit unit = uptownUnitMapper.getUptownUnitByUser(userOpen.getUserId());
-            if (!unit.getUptownId().equals(uptownDoor.getUptownId())) {
-                model.put("type", "-1");
-                return new ModelAndView("/user/scan.ftl", model);
-            }
             model.put("door", uptownDoor.getUptownName() + uptownDoor.getDoorName());
             model.put("doorplate", unit.getRidgepole() + "栋" + unit.getUnit() + "单元" +unit.getDoorplate());
             model.put("name", uptownHomes.get(0).getLinkman());
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            model.put("now", format.format(new Date()));
+            model.put("inType", inType);
+            if (!unit.getUptownId().equals(uptownDoor.getUptownId())) {
+                model.put("type", "-1");//小区不对
+                model.put("into", "禁止" + getMsg(inType));
+                model.put("collor", "red");
+                model.put("errorMsg", "非本小区居民,禁止" + getMsg(inType) + "。");
+                return new ModelAndView("/user/scan.ftl", model);
+            }
+            if (inType == 2) {
+                OutScanConf outScanConf = outScanConfMapper.getOutScanConfByUptown(uptownDoor.getUptownId());
+                OutScan outScan = outScanMapper.getOutScanByUserlimit(userOpen.getUserId());
+                if (outScan != null && !compareTime(new Date(), outScan.getOutDate(), outScanConf.getGoOutFre())) {
+                    model.put("type", "-2");//时间短了
+                    model.put("collor", "red");
+                    model.put("into", "禁止" + getMsg(inType));
+                    model.put("errorMsg", "外出时间间隔不满三日,禁止外出,请配合,上次外出时间 "+format.format(new Date(outScan.getOutDate().getMillis()))+"。");
+                    return new ModelAndView("/user/scan.ftl", model);
+                }
+                List<MsReport> msReports = msReportMapper.selectMsReportLate(userOpen.getUserId());
+                if (msReports.size() != 3) {
+                    model.put("type", "-3");//最近3天未提交健康日报
+                    model.put("collor", "red");
+                    model.put("into", "禁止" + getMsg(inType));
+                    model.put("errorMsg", "因近期您未提交健康日报,无法确认您当前健康状态,禁止外出,请配合。");
+                    return new ModelAndView("/user/scan.ftl", model);
+                }
+            }
+            model.put("type", "1");
+            model.put("collor", "green");
+            model.put("into", "可以" + getMsg(inType));
+            if (inType == 2) {
+                model.put("errorMsg", "请佩戴口罩,避免近距离接触,不得长时间在外逗留。");
+            }
+            scanService.saveOutScan(userOpen.getUserId(), inType, uptownDoor.getUptownId(), uptownDoor.getDoorId());
             return new ModelAndView("/user/scan.ftl", model);
         }
     }
+
+    public Boolean compareTime(Date time1, DateTime time2, Integer day) {
+        Date date = new Date(time2.getMillis() + 1000L*3600*24*day);
+        if (changeTime(date).equals(changeTime(time1))) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public String changeTime(Date date) {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        return format.format(date);
+    }
+
+    public String getMsg(Integer inType) {
+        if (inType == 1) {
+            return "进入";
+        } else if (inType == 2) {
+            return "外出";
+        }
+        return "";
+    }
 }