浏览代码

监控管理

qzyReal 2 年之前
父节点
当前提交
a4ba087b31

+ 1 - 1
business-system/face-identify/src/main/java/com/pj/biz/TbPersonVisitRecordController.java

@@ -109,7 +109,7 @@ public class TbPersonVisitRecordController {
         SoMap so = SoMap.getRequestSoMap();
         String deptId = StpUserUtil.getDeptId();
         if (!StrUtil.equals(String.valueOf(StpUserUtil.ADMIN_DEPT_ID), deptId)) {
-            so.put("deptId", deptId);
+            so.put("deptIdList", StrUtil.splitTrim(deptId,","));
         }
         List<TbPersonVisitRecord> list = tbPersonVisitRecordService.getList(so.startPage());
         return AjaxJson.getPageData(so.getDataCount(), list);

+ 21 - 0
business-system/monitor-system/src/main/java/com/pj/MonitorController.java

@@ -0,0 +1,21 @@
+package com.pj;
+
+import com.pj.project.tb_person_visit_record.TbPersonVisitRecordService;
+import com.pj.utils.sg.AjaxJson;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@RestController
+@RequestMapping("monitor")
+public class MonitorController {
+
+    @Resource
+    private TbPersonVisitRecordService tbPersonVisitRecordService;
+
+    @RequestMapping("watch")
+    public AjaxJson monitor(){
+        return AjaxJson.getSuccessData(tbPersonVisitRecordService.getMonitor());
+    }
+}

+ 3 - 2
sp-admin/src/main/java/com/pj/project4sp/admin/SpAdminMapper.xml

@@ -38,7 +38,7 @@
 		<result property="id" column="id" />
 		<result property="name" column="name" />
 		<result property="deptId" column="dept_id" />
-        <result property="deptName" column="dept_name" />
+        <result property="deptName" column="deptName" />
 		<result property="avatar" column="avatar" />
 		<result property="password" column="password" />
 		<!-- <result property="pw" column="pw" /> -->
@@ -56,7 +56,8 @@
 	<!-- 查询sql -->
 	<sql id="select_sql">
 		select *,
-		(select name from sp_role where id = sp_admin.role_id) as role_name
+		(select name from sp_role where id = sp_admin.role_id) as role_name,
+		(select name from tb_dept where id=sp_admin.dept_id) as deptName
 		from sp_admin 
 	</sql>
 

+ 5 - 0
sp-core/src/main/java/com/pj/current/netty/command/handler/impl/CheckLogHandler.java

@@ -18,6 +18,7 @@ import com.pj.project.tb_person_visit_record.TbPersonVisitRecordService;
 import com.pj.project.tb_person_visit_record.task.ConvertBase64ToImage;
 import com.pj.project.tb_terminal.TbTerminal;
 import com.pj.project.tb_terminal.TbTerminalService;
+import com.pj.project4sp.spcfg.SpCfgUtil;
 import io.netty.channel.ChannelHandlerContext;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -78,6 +79,10 @@ public class CheckLogHandler implements IHandler {
         tbPersonVisitRecordService.saveOrUpdate(record);
         ctx.write(OKMsg.ok());
         ctx.flush();
+        String minTemperature= SpCfgUtil.getMinTemperature();
+        if (Double.valueOf(minTemperature)<Double.valueOf(dto.getTemperature())){
+            //todo 触发体温预警
+        }
         taskService.addTask(new ConvertBase64ToImage(RandomUtil.randomNumbers(8), 2000, record.getId(), dto.getPicture()));
     }
 }

+ 22 - 0
sp-core/src/main/java/com/pj/project/tb_person_visit_record/MonitorVO.java

@@ -0,0 +1,22 @@
+package com.pj.project.tb_person_visit_record;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+@Data
+@Accessors(chain = true)
+public class MonitorVO implements Serializable {
+    private long todayCount;
+    private long todayHealthErrorCount;
+    private long weekCount;
+    private long weekHealthErrorCount;
+    private long monthCount;
+    private long monthHealthErrorCount;
+    private long yearCount;
+    private long yearHealthErrorCount;
+    private long avg;
+    private long avgError;
+
+}

+ 2 - 0
sp-core/src/main/java/com/pj/project/tb_person_visit_record/TbPersonVisitRecordMapper.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper;
 
 import com.pj.utils.so.*;
 	import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 /**
@@ -25,4 +26,5 @@ public interface TbPersonVisitRecordMapper extends BaseMapper <TbPersonVisitReco
 List<TbPersonVisitRecord> getList(SoMap so);
 
 
+	long getMonitor(@Param("bDate") String bDate, @Param("eDate")String eDate,@Param("healthStatus")int healthStatus);
 }

+ 19 - 50
sp-core/src/main/java/com/pj/project/tb_person_visit_record/TbPersonVisitRecordMapper.xml

@@ -3,27 +3,6 @@
 <mapper namespace="com.pj.project.tb_person_visit_record.TbPersonVisitRecordMapper">
 
 
-	<!-- ================================== 查询相关 ================================== -->
-			<!-- select id, direction, dept_id, dept_name, name, picture, id_card, channel, venues, temperature, health_status, sn, visit_date, create_time from tb_person_visit_record  -->
-
-		<!-- 通用映射:手动模式 -->
-		<resultMap id="model" type="com.pj.project.tb_person_visit_record.TbPersonVisitRecord">
-				<result property="id" column="id" />
-				<result property="direction" column="direction" />
-				<result property="deptId" column="dept_id" />
-				<result property="deptName" column="dept_name" />
-				<result property="name" column="name" />
-				<result property="picture" column="picture" />
-				<result property="idCard" column="id_card" />
-				<result property="channel" column="channel" />
-				<result property="venues" column="venues" />
-				<result property="temperature" column="temperature" />
-				<result property="healthStatus" column="health_status" />
-				<result property="sn" column="sn" />
-				<result property="visitDate" column="visit_date" />
-				<result property="createTime" column="create_time" />
-                <result property="isNotify" column="is_notify" />
-		</resultMap>
 
 	<!-- 公共查询sql片段 -->
 	<sql id="select_sql">
@@ -34,12 +13,11 @@
 
 
 	<!-- 查集合 - 根据条件(参数为空时代表忽略指定条件) [G] -->
-	<select id="getList" resultMap="model">
+	<select id="getList" resultType="com.pj.project.tb_person_visit_record.TbPersonVisitRecord">
 		<include refid="select_sql"></include>
 		<where>
-						<if test=' this.has("id") '> and id = #{id} </if>
+			<if test=' this.has("id") '> and id = #{id} </if>
 			<if test=' this.has("direction") '> and direction = #{direction} </if>
-			<if test=' this.has("deptId") '> and dept_id in (${deptId}) </if>
 			<if test=' this.has("deptName") '> and dept_name = #{deptName} </if>
 			<if test=' this.has("name") '> and name like concat('%',#{name},'%') </if>
 			<if test=' this.has("idCard") '> and id_card = #{idCard} </if>
@@ -55,34 +33,25 @@
             <if test=' this.has("unhealthy") '> and health_status != '绿码' </if>
             <if test='dataType == 0'> and health_status = '绿码' </if>
             <if test='dataType == 1'> and health_status != '绿码' </if>
-
+             <if test="deptIdList !=null and deptIdList.size>0">
+             and dept_id in
+				 <foreach collection="deptIdList" open="(" separator="," close=")" item="deptId">
+					 #{deptId}
+				 </foreach>
+			 </if>
         </where>
-		order by
-		<choose>
-						<when test='sortType == 1'> id desc </when>
-			<when test='sortType == 2'> direction desc </when>
-			<when test='sortType == 3'> dept_id desc </when>
-			<when test='sortType == 4'> dept_name desc </when>
-			<when test='sortType == 5'> name desc </when>
-			<when test='sortType == 6'> id_card desc </when>
-			<when test='sortType == 7'> channel desc </when>
-			<when test='sortType == 8'> venues desc </when>
-			<when test='sortType == 9'> temperature desc </when>
-			<when test='sortType == 10'> health_status desc </when>
-			<when test='sortType == 11'> sn desc </when>
-			<when test='sortType == 12'> visit_date desc </when>
-			<when test='sortType == 13'> create_time desc </when>
-			<otherwise> id desc </otherwise>
-		</choose>
+		order by id desc
+	</select>
+	<select id="getMonitor" resultType="java.lang.Long">
+		SELECT count(id)
+		FROM tb_person_visit_record
+		WHERE
+		DATE_FORMAT(visit_date,'%Y-%m-%d') &gt;=#{bDate}
+		and DATE_FORMAT(visit_date,'%Y-%m-%d') &lt;=#{eDate}
+		<if test="healthStatus==0">
+			and health_status !='绿码' and health_status is not null
+		</if>
 	</select>
-
-
-
-
-
-
-
-
 
 
 </mapper>

+ 37 - 3
sp-core/src/main/java/com/pj/project/tb_person_visit_record/TbPersonVisitRecordService.java

@@ -1,15 +1,20 @@
 package com.pj.project.tb_person_visit_record;
 
 import java.io.File;
+import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.poi.excel.ExcelUtil;
@@ -23,6 +28,7 @@ import com.pj.project.tb_venues.TbVenues;
 import com.pj.project.tb_venues.TbVenuesService;
 import com.pj.project4sp.uploadfile.UploadConfig;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import com.pj.utils.so.*;
@@ -46,6 +52,7 @@ public class TbPersonVisitRecordService extends ServiceImpl<TbPersonVisitRecordM
     @Resource
     private UploadConfig uploadConfig;
     @Resource
+    @Lazy
     private TbVenuesService tbVenuesService;
 
 
@@ -80,9 +87,9 @@ public class TbPersonVisitRecordService extends ServiceImpl<TbPersonVisitRecordM
         } else if (direction.equals(TbPersonVisitRecord.DirectionEnum.OUT.getDirection())) {
             record.setVisitDate(t.getOutTime()).setTemperature(t.getOutTemperature());
         }
-        if(StrUtil.equals(record.getHealthStatus(), TbPersonVisitRecord.HealthEnum.GREEN.getStatus())){
+        if (StrUtil.equals(record.getHealthStatus(), TbPersonVisitRecord.HealthEnum.GREEN.getStatus())) {
             record.setWay("无需处置").setIsSolve(0).setIsNotify(0);
-        }else{
+        } else {
             record.setIsSolve(1).setIsNotify(1);
         }
         this.save(record);
@@ -156,7 +163,7 @@ public class TbPersonVisitRecordService extends ServiceImpl<TbPersonVisitRecordM
         return list.isEmpty() ? null : list.get(0);
     }
 
-    public void solve(SoMap so){
+    public void solve(SoMap so) {
         String id = so.getString("id");
         String way = so.getString("way");
         TbPersonVisitRecord t = getById(id);
@@ -164,4 +171,31 @@ public class TbPersonVisitRecordService extends ServiceImpl<TbPersonVisitRecordM
         this.updateById(t);
     }
 
+    public MonitorVO getMonitor() {
+        MonitorVO vo=new MonitorVO();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDate today = LocalDate.now();
+        String todayStr = today.format(formatter);
+        long todayCount = tbPersonVisitRecordMapper.getMonitor(today.format(formatter), todayStr,1);
+        long todayHealthErrorCount = tbPersonVisitRecordMapper.getMonitor(today.format(formatter), todayStr,0);
+        LocalDate week = today.minusDays(7);
+        long weekCount = tbPersonVisitRecordMapper.getMonitor(week.format(formatter), todayStr,1);
+        long weekHealthErrorCount = tbPersonVisitRecordMapper.getMonitor(week.format(formatter), todayStr,0);
+
+        LocalDate month = today.minusMonths(1);
+        long monthCount = tbPersonVisitRecordMapper.getMonitor(month.format(formatter), todayStr,1);
+        long monthHealthErrorCount = tbPersonVisitRecordMapper.getMonitor(month.format(formatter), todayStr,0);
+
+        LocalDate year = today.minusYears(1);
+        long yearCount = tbPersonVisitRecordMapper.getMonitor(year.format(formatter), todayStr,1);
+        long yearHealthErrorCount = tbPersonVisitRecordMapper.getMonitor(year.format(formatter), todayStr,0);
+        long avg = new BigDecimal(weekCount).divide(new BigDecimal(7),BigDecimal.ROUND_UP).longValue();
+        long avgError = new BigDecimal(weekHealthErrorCount).divide(new BigDecimal(7),BigDecimal.ROUND_UP).longValue();
+        vo.setTodayCount(todayCount).setTodayHealthErrorCount(todayHealthErrorCount)
+                .setWeekCount(weekCount).setWeekHealthErrorCount(weekHealthErrorCount)
+                .setMonthCount(monthCount).setMonthHealthErrorCount(monthHealthErrorCount)
+                .setYearCount(yearCount).setYearHealthErrorCount(yearHealthErrorCount)
+                .setAvg(avg).setAvgError(avgError);
+        return vo;
+    }
 }

+ 4 - 0
sp-core/src/main/java/com/pj/project4sp/spcfg/SpCfgUtil.java

@@ -70,6 +70,10 @@ public class SpCfgUtil {
 	public static String getFillingJudge() {
 		return SpCfgUtil.getServerCfg("fillingJudge", "1");
 	}
+	// 获取配置信息:备案审核 1审核 2不审核
+	public static String getMinTemperature() {
+		return SpCfgUtil.getServerCfg("minTemperature", "37");
+	}
 	
 	// ====================== 获取指定配置 ========================== 
 

+ 1 - 1
sp-start/src/main/resources/application-dev.yml

@@ -46,7 +46,7 @@ spring:
     myconfig:
         # 本项目部署到的服务器域名(文件上传等等模块  要用到)
         domain: http://192.168.1.3:8099
-        ip: 192.168.1.3
+        ip: 192.168.1.4
         heart-port: 9999
         command-port: 8888
         command-prefix: "command:"