Browse Source

1.连续正常天数排除非工作日及节假日。

zhengqiang 5 years ago
parent
commit
91342dea82

+ 5 - 0
common/pom.xml

@@ -156,6 +156,11 @@
             <version>3.1.0</version>
             <scope>provided</scope>
         </dependency>
+
+        <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 20 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/HolidayInfoDAO.java

@@ -0,0 +1,20 @@
+package com.jpsoft.smart.modules.base.dao;
+
+import java.util.Date;
+import java.util.List;
+import org.springframework.stereotype.Repository;
+import com.jpsoft.smart.modules.base.entity.HolidayInfo;
+import java.util.Map;
+import com.jpsoft.smart.modules.common.dto.Sort;
+
+@Repository
+public interface HolidayInfoDAO {
+	int insert(HolidayInfo entity);
+	int update(HolidayInfo entity);
+	int exist(String id);
+	HolidayInfo get(String id);
+	int delete(String id);
+	List<HolidayInfo> list();
+	List<HolidayInfo> search(Map<String,Object> searchParams,List<Sort> sortList);
+	List<HolidayInfo> findByDate(Date startDate, Date endDate);
+}

+ 5 - 4
common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonDeviceFilterLogDAO.java

@@ -47,13 +47,14 @@ public interface PersonDeviceFilterLogDAO {
 
     PersonDeviceFilterLog get(Long id);
 
-    long countByTimeRangeAndCompanyCode(String companyCode,Long personId,int status, Date startDate, Date endDate);
+    long countByTimeRangeAndCompanyCode(String companyCode,Long personId,int status,float temperatureMax, Date startDate, Date endDate);
     long countUndetectedByCompanyCode(String companyCode,Long personId, Date startTime, Date endTime);
 
-    Integer getDayAbnormalNum(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
+    Integer getDayAbnormalNum(@Param("startTime") Date startTime, @Param("endTime") Date endTime,float temperatureMax);
 
+    Integer getDayAbnormalNumByCompanyList(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("list") List<CompanyInfo> list,float temperatureMax);
 
-    Integer getDayAbnormalNumByCompanyList(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("list") List<CompanyInfo> list);
+    Integer getDayNormalNumByCompanyId( @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("companyId") String companyId,float temperatureMax);
 
-    Integer getDayNormalNumByCompanyId( @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("companyId") String companyId);
+    Integer countDayByPersonIdAndDate(Long personId, Date startDate, Date endDate);
 }

+ 72 - 0
common/src/main/java/com/jpsoft/smart/modules/base/entity/HolidayInfo.java

@@ -0,0 +1,72 @@
+package com.jpsoft.smart.modules.base.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.math.BigDecimal;
+import org.springframework.format.annotation.DateTimeFormat;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+  描述:base_holiday_info的实体类
+ */
+@Data
+@ApiModel(value = "base_holiday_info的实体类")
+public class HolidayInfo {
+	/**
+	 *主键
+	 */
+        @ApiModelProperty(value = "主键")
+	private String id;
+	/**
+	 *节假日名称
+	 */
+        @ApiModelProperty(value = "节假日名称")
+	private String holidayName;
+	/**
+	 *节假日开始日期
+	 */
+    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "节假日开始日期")
+	private Date beginDate;
+	/**
+	 *节假日结束日期
+	 */
+    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "节假日结束日期")
+	private Date endDate;
+	/**
+	 *创建人
+	 */
+        @ApiModelProperty(value = "创建人")
+	private String createBy;
+	/**
+	 *创建时间
+	 */
+    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "创建时间")
+	private Date createTime;
+	/**
+	 *更新人
+	 */
+        @ApiModelProperty(value = "更新人")
+	private String updateBy;
+	/**
+	 *更新时间
+	 */
+    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "更新时间")
+	private Date updateTime;
+	/**
+	 *是否删除
+	 */
+        @ApiModelProperty(value = "是否删除")
+	private Boolean delFlag;
+}

+ 4 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/AlarmConfigService.java

@@ -2,6 +2,8 @@ package com.jpsoft.smart.modules.base.service;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+
 import com.jpsoft.smart.modules.base.entity.AlarmConfig;
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.modules.common.dto.Sort;
@@ -16,4 +18,6 @@ public interface AlarmConfigService {
 	Page<AlarmConfig> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
 
     List<AlarmConfig> findByCompanyId(String companyId);
+
+    Set<Integer> getWeekdaySetByCompanyId(String companyId);
 }

+ 21 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/HolidayInfoService.java

@@ -0,0 +1,21 @@
+package com.jpsoft.smart.modules.base.service;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.jpsoft.smart.modules.base.entity.HolidayInfo;
+import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
+
+public interface HolidayInfoService {
+	HolidayInfo get(String id);
+	boolean exist(String id);
+	int insert(HolidayInfo model);
+	int update(HolidayInfo model);
+	int delete(String id);
+	List<HolidayInfo> list();
+	Page<HolidayInfo> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
+    Set<String> getHolidaySetByDate(Date startDate, Date endDate);
+}

+ 13 - 1
common/src/main/java/com/jpsoft/smart/modules/base/service/PersonDeviceFilterLogService.java

@@ -49,7 +49,17 @@ public interface PersonDeviceFilterLogService {
 
     PersonDeviceFilterLog get(Long id);
 
-    long countByTimeRangeAndCompanyCode(String companyCode,Long personId,int status,Date startTime, Date endTime);
+    /**
+     *
+     * @param companyCode
+     * @param personId
+     * @param status 1-正常,-1-不正常,0-不考虑温度
+     * @param temperatureMax
+     * @param startTime
+     * @param endTime
+     * @return
+     */
+    long countByTimeRangeAndCompanyCode(String companyCode,Long personId,int status,float temperatureMax,Date startTime, Date endTime);
     long countUndetectedByCompanyCode(String companyCode,Long personId, Date startTime, Date endTime);
 
     Integer getDayAbnormalNum(Date startTime, Date endTime);
@@ -57,4 +67,6 @@ public interface PersonDeviceFilterLogService {
     Integer getDayAbnormalNumByCompanyList(Date startTime, Date endTime, List<CompanyInfo> list);
 
     Integer getDayNormalNumByCompanyId(Date startTime,Date endTime, String companyId);
+
+    Integer countDayByPersonIdAndDate(Long personId, Date startDate, Date endDate);
 }

+ 35 - 3
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/AlarmConfigServiceImpl.java

@@ -1,9 +1,10 @@
 package com.jpsoft.smart.modules.base.service.impl;
 
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
 import javax.annotation.Resource;
+
+import com.jpsoft.smart.modules.base.dao.CompanyInfoDAO;
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.base.dao.AlarmConfigDAO;
@@ -19,6 +20,9 @@ public class AlarmConfigServiceImpl implements AlarmConfigService {
 	@Resource(name="alarmConfigDAO")
 	private AlarmConfigDAO alarmConfigDAO;
 
+	@Resource(name="companyInfoDAO")
+	private CompanyInfoDAO companyInfoDAO;
+
 	@Override
 	public AlarmConfig get(String id) {
 		// TODO Auto-generated method stub
@@ -72,4 +76,32 @@ public class AlarmConfigServiceImpl implements AlarmConfigService {
 	public List<AlarmConfig> findByCompanyId(String companyId) {
 		return alarmConfigDAO.findByCompanyId(companyId);
 	}
+
+	@Override
+	public Set<Integer> getWeekdaySetByCompanyId(String companyId) {
+		CompanyInfo companyInfo = companyInfoDAO.get(companyId);
+		String[] arr = companyInfo.getCode().split(",");
+
+		Set<Integer> weekdaySet = new TreeSet<>();
+
+		List<AlarmConfig> configList = null;
+
+		for (int i=arr.length-1;i>=0;i--) {
+			configList = findByCompanyId(arr[i]);
+
+			if (configList!=null && configList.size()>0){
+				break;
+			}
+		}
+
+		for (AlarmConfig alarmConfig : configList) {
+			String[] weekdays = alarmConfig.getWeekdays().split(",");
+
+			for (String weekday : weekdays) {
+				weekdaySet.add(Integer.valueOf(weekday));
+			}
+		}
+
+		return weekdaySet;
+	}
 }

+ 91 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/HolidayInfoServiceImpl.java

@@ -0,0 +1,91 @@
+package com.jpsoft.smart.modules.base.service.impl;
+
+import java.util.*;
+import javax.annotation.Resource;
+
+import org.joda.time.DateTime;
+import org.joda.time.Days;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import com.jpsoft.smart.modules.base.dao.HolidayInfoDAO;
+import com.jpsoft.smart.modules.base.entity.HolidayInfo;
+import com.jpsoft.smart.modules.base.service.HolidayInfoService;
+import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.common.dto.Sort;
+import com.github.pagehelper.PageHelper;
+
+@Transactional
+@Component(value="holidayInfoService")
+public class HolidayInfoServiceImpl implements HolidayInfoService {
+	@Resource(name="holidayInfoDAO")
+	private HolidayInfoDAO holidayInfoDAO;
+
+	@Override
+	public HolidayInfo get(String id) {
+		// TODO Auto-generated method stub
+		return holidayInfoDAO.get(id);
+	}
+
+	@Override
+	public int insert(HolidayInfo model) {
+		// TODO Auto-generated method stub
+		//model.setId(UUID.randomUUID().toString());
+		
+		return holidayInfoDAO.insert(model);
+	}
+
+	@Override
+	public int update(HolidayInfo model) {
+		// TODO Auto-generated method stub
+		return holidayInfoDAO.update(model);		
+	}
+
+	@Override
+	public int delete(String id) {
+		// TODO Auto-generated method stub
+		return holidayInfoDAO.delete(id);
+	}
+
+	@Override
+	public boolean exist(String id) {
+		// TODO Auto-generated method stub
+		int count = holidayInfoDAO.exist(id);
+		
+		return count > 0 ? true : false;
+	}
+	
+	@Override
+	public List<HolidayInfo> list() {
+		// TODO Auto-generated method stub
+		return holidayInfoDAO.list();
+	}
+		
+	@Override
+	public Page<HolidayInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
+        Page<HolidayInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
+            holidayInfoDAO.search(searchParams,sortList);
+        });
+        
+        return page;
+	}
+
+	@Override
+	public Set<String> getHolidaySetByDate(Date startDate,Date endDate) {
+		List<HolidayInfo> list = holidayInfoDAO.findByDate(startDate,endDate);
+
+		Set<String> holidaySet = new TreeSet<>();
+
+		for (HolidayInfo holidayInfo : list) {
+			DateTime beginTime = new DateTime(holidayInfo.getBeginDate());
+			DateTime endTime = new DateTime(holidayInfo.getEndDate());
+
+			int days = Days.daysBetween(beginTime,endTime).getDays();
+
+			for (int i = 0; i <= days; i++) {
+				holidaySet.add(beginTime.plusDays(i).toString("yyyy-MM-dd"));
+			}
+		}
+
+		return holidaySet;
+	}
+}

+ 10 - 6
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonDeviceFilterLogServiceImpl.java

@@ -38,7 +38,6 @@ import java.util.Map;
 @Transactional
 @Component(value = "personDeviceFilterLogService")
 public class PersonDeviceFilterLogServiceImpl implements PersonDeviceFilterLogService {
-
     @Autowired
     private OSSConfig ossConfig;
 
@@ -221,8 +220,8 @@ public class PersonDeviceFilterLogServiceImpl implements PersonDeviceFilterLogSe
     }
 
     @Override
-    public long countByTimeRangeAndCompanyCode(String companyCode, Long personId, int status, Date startDate, Date endDate) {
-        return personDeviceFilterLogDAO.countByTimeRangeAndCompanyCode(companyCode, personId, status, startDate, endDate);
+    public long countByTimeRangeAndCompanyCode(String companyCode, Long personId, int status,float temperatureMax, Date startDate, Date endDate) {
+        return personDeviceFilterLogDAO.countByTimeRangeAndCompanyCode(companyCode, personId, status,temperatureMax, startDate, endDate);
     }
 
     @Override
@@ -248,16 +247,21 @@ public class PersonDeviceFilterLogServiceImpl implements PersonDeviceFilterLogSe
 
     @Override
     public Integer getDayAbnormalNum(Date startTime, Date endTime) {
-        return personDeviceFilterLogDAO.getDayAbnormalNum(startTime,endTime);
+        return personDeviceFilterLogDAO.getDayAbnormalNum(startTime,endTime,temperatureConfig.getMax());
     }
 
     @Override
     public Integer getDayAbnormalNumByCompanyList(Date startTime, Date endTime, List<CompanyInfo> list) {
-        return personDeviceFilterLogDAO.getDayAbnormalNumByCompanyList(startTime,endTime,list);
+        return personDeviceFilterLogDAO.getDayAbnormalNumByCompanyList(startTime,endTime,list,temperatureConfig.getMax());
     }
 
     @Override
     public Integer getDayNormalNumByCompanyId(Date startTime,Date endTime, String companyId) {
-        return personDeviceFilterLogDAO.getDayNormalNumByCompanyId(startTime,endTime,companyId);
+        return personDeviceFilterLogDAO.getDayNormalNumByCompanyId(startTime,endTime,companyId,temperatureConfig.getMax());
+    }
+
+    @Override
+    public Integer countDayByPersonIdAndDate(Long personId, Date startDate, Date endDate) {
+        return personDeviceFilterLogDAO.countDayByPersonIdAndDate(personId,startDate,endDate);
     }
 }

+ 106 - 0
common/src/main/resources/mapper/base/HolidayInfo.xml

@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<!-- namespace必须指向DAO接口 -->
+<mapper namespace="com.jpsoft.smart.modules.base.dao.HolidayInfoDAO">
+    <resultMap id="HolidayInfoMap" type="com.jpsoft.smart.modules.base.entity.HolidayInfo">
+        <id property="id" column="id_"/>
+        <result property="holidayName" column="holiday_name"/>
+        <result property="beginDate" column="begin_date"/>
+        <result property="endDate" column="end_date"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="delFlag" column="del_flag"/>
+    </resultMap>
+    <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.HolidayInfo">
+        <!--
+        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+            select sys_guid() from dual
+        </selectKey>
+        -->
+        <![CDATA[
+		insert into base_holiday_info
+	    (id_,holiday_name,begin_date,end_date,create_by,create_time,update_by,update_time,del_flag)
+		values
+		(
+            #{id,jdbcType=VARCHAR}
+            ,#{holidayName,jdbcType=VARCHAR}
+            ,#{beginDate,jdbcType= TIMESTAMP }
+            ,#{endDate,jdbcType= TIMESTAMP }
+            ,#{createBy,jdbcType=VARCHAR}
+            ,#{createTime,jdbcType= TIMESTAMP }
+            ,#{updateBy,jdbcType=VARCHAR}
+            ,#{updateTime,jdbcType= TIMESTAMP }
+            ,#{delFlag,jdbcType= NUMERIC }
+		)
+	]]>
+    </insert>
+    <delete id="delete" parameterType="string">
+        delete from base_holiday_info where id_=#{id,jdbcType=VARCHAR}
+    </delete>
+    <update id="update" parameterType="com.jpsoft.smart.modules.base.entity.HolidayInfo">
+        update base_holiday_info
+        <set>
+            <if test="holidayName!=null">
+                holiday_name=#{holidayName,jdbcType=VARCHAR},
+            </if>
+            <if test="beginDate!=null">
+                begin_date=#{beginDate,jdbcType= TIMESTAMP },
+            </if>
+            <if test="endDate!=null">
+                end_date=#{endDate,jdbcType= TIMESTAMP },
+            </if>
+            <if test="createBy!=null">
+                create_by=#{createBy,jdbcType=VARCHAR},
+            </if>
+            <if test="createTime!=null">
+                create_time=#{createTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="updateBy!=null">
+                update_by=#{updateBy,jdbcType=VARCHAR},
+            </if>
+            <if test="updateTime!=null">
+                update_time=#{updateTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="delFlag!=null">
+                del_flag=#{delFlag,jdbcType= NUMERIC },
+            </if>
+        </set>
+        where id_=#{id}
+    </update>
+    <select id="get" parameterType="string" resultMap="HolidayInfoMap">
+        select
+        id_,holiday_name,begin_date,end_date,create_by,create_time,update_by,update_time,del_flag from base_holiday_info
+        where id_=#{0}
+    </select>
+    <select id="exist" parameterType="string" resultType="int">
+        select count(*) from base_holiday_info where id_=#{0}
+    </select>
+    <select id="list" resultMap="HolidayInfoMap">
+        select * from base_holiday_info
+    </select>
+    <select id="search" parameterType="hashmap" resultMap="HolidayInfoMap">
+        <![CDATA[
+			select * from base_holiday_info
+		]]>
+        <where>
+            <if test="searchParams.id != null">
+                and ID_ like #{searchParams.id}
+            </if>
+        </where>
+        <foreach item="sort" collection="sortList" open="order by" separator=",">
+            ${sort.name} ${sort.order}
+        </foreach>
+    </select>
+    <select id="findByDate" resultMap="HolidayInfoMap">
+        <![CDATA[
+            select * from base_holiday_info
+            where begin_date>=#{startDate}
+            and end_date<=#{endDate}
+            and del_flag=0
+            order by begin_date asc
+        ]]>
+    </select>
+</mapper>

+ 25 - 13
common/src/main/resources/mapper/base/PersonDeviceFilterLog.xml

@@ -140,7 +140,7 @@
 		<![CDATA[
            and record_time >= #{startDate} and record_time <= #{endDate}
         ]]>
-        order by temperature_ desc LIMIT 1
+        order by temperature_ desc limit 1
 	</select>
 
 
@@ -165,17 +165,14 @@
                   and a.record_time <= #{searchParams.endTime}
                 ]]>
             </if>
-            <if test="searchParams.abnormalFilter!=null">
-                and a.temperature_>37
-            </if>
             <if test="searchParams.fever==true">
                 <![CDATA[
-                and a.temperature_>37
+                and a.temperature_>#{searchParams.temperatureMax}
                 ]]>
             </if>
             <if test="searchParams.fever==false">
                 <![CDATA[
-                and a.temperature_<=37
+                and a.temperature_<={searchParams.temperatureMax}
                 ]]>
             </if>
         </where>
@@ -266,14 +263,14 @@
             )
         </if>
         )
-        <if test="status==-1">
+        <if test="status==1">
         <![CDATA[
-            and a.temperature_>=37
+            and a.temperature_<=#{temperatureMax}
         ]]>
         </if>
-        <if test="status==1">
+        <if test="status==-1">
         <![CDATA[
-            and a.temperature_<37
+            and a.temperature_>#{temperatureMax}
         ]]>
         </if>
     </select>
@@ -299,14 +296,19 @@
         )
     </select>
     <select id="getDayAbnormalNum" resultType="java.lang.Integer">
-        select count(DISTINCT person_id) from base_person_device_filter_log where record_time >=#{startTime} and record_time &lt;= #{endTime} and temperature_>37.3
+        <![CDATA[
+            select count(DISTINCT person_id) from base_person_device_filter_log
+            where record_time >=#{startTime}
+            and record_time <= #{endTime}
+            and temperature_>#{temperatureMax}
+        ]]>
     </select>
     <select id="getDayAbnormalNumByCompanyList" resultType="Integer">
         select count(DISTINCT person_id) from base_person_device_filter_log a left join base_person_info b
         on a.person_id = b.id_
         where a.record_time >=#{startTime}
         and a.record_time &lt;= #{endTime}
-        and a.temperature_>37.3
+        and a.temperature_>#{temperatureMax}
         and b.company_id in
         <foreach collection="list" index="index" item="item" open="(" separator="," close=")">   #{item.id}
         </foreach>
@@ -318,8 +320,18 @@
         on a.person_id = b.id_
         where a.record_time >=#{startTime}
         and a.record_time &lt;= #{endTime}
-        and a.temperature_&lt;= 37.3
+        and a.temperature_&lt;= #{temperatureMax}
         and b.company_id = #{companyId}
         and a.del_flag = 0
     </select>
+    <select id="countDayByPersonIdAndDate" resultType="Integer">
+        <![CDATA[
+            select count(distinct(DATE_FORMAT(a.record_time,'%y-%m-%d'))) from base_person_device_filter_log a
+            where a.person_id=#{personId}
+            and a.record_time>=#{startDate}
+            and a.record_time<#{endDate}
+            and a.del_flag=0
+            order by record_time asc
+        ]]>
+    </select>
 </mapper>

+ 1 - 1
common/src/main/resources/mapper/base/PersonInfo.xml

@@ -228,7 +228,7 @@
                     and c.company_id = a.company_id
                     and DATEDIFF(b.record_time,#{searchParams.abnormalDate})=0
                     and b.del_flag=0
-                    and b.temperature_>37
+                    and b.temperature_>#{searchParams.temperatureMax}
                 )
                 ]]>
             </if>

+ 87 - 55
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/IndividualLogApiController.java

@@ -2,10 +2,12 @@ package com.jpsoft.smart.modules.mobile.controller;
 
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.config.TemperatureConfig;
+import com.jpsoft.smart.modules.base.entity.AlarmConfig;
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.entity.PersonDeviceFilterLog;
 import com.jpsoft.smart.modules.base.entity.PersonInfo;
-import com.jpsoft.smart.modules.base.service.PersonDeviceFilterLogService;
-import com.jpsoft.smart.modules.base.service.PersonInfoService;
+import com.jpsoft.smart.modules.base.service.*;
+import com.jpsoft.smart.modules.business.service.WorkAttendanceService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.utils.PojoUtils;
@@ -18,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
+import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -27,11 +30,22 @@ import java.util.*;
 public class IndividualLogApiController {
     @Autowired
     private PersonInfoService personInfoService;
+
     @Autowired
     private PersonDeviceFilterLogService personDeviceFilterLogService;
+
     @Autowired
     private TemperatureConfig temperatureConfig;
 
+    @Autowired
+    private HolidayInfoService holidayInfoService;
+
+    @Autowired
+    private CompanyInfoService companyInfoService;
+
+    @Autowired
+    private AlarmConfigService alarmConfigService;
+
     @PostMapping("healthyPersonList")
     @ApiOperation(value="健康公示列表")
     @ApiImplicitParams({
@@ -101,53 +115,63 @@ public class IndividualLogApiController {
 
         try{
             PersonInfo person = personInfoService.get(Long.valueOf(personId));
+
             map.put("name",person.getName());
             map.put("faceImageUrl",person.getFaceImageUrl());
 
             PersonDeviceFilterLog personDeviceFilterLog = personDeviceFilterLogService.lastPersonLog(person.getId());
 
             BigDecimal lastTemperature =  personDeviceFilterLog.getTemperature();
-            String lastTemperatureStr = "";
-            double lastTemperatureDou = 0;
+            DecimalFormat df = new DecimalFormat("##.#");
+
             if(lastTemperature != null){
-                lastTemperatureStr = String.valueOf(lastTemperature);
-                lastTemperatureDou = Double.parseDouble(lastTemperatureStr);
+                map.put("lastTemperature",df.format(lastTemperature));
             }
             else{
-                lastTemperatureStr = "无记录";
+                map.put("lastTemperature","无记录");
             }
-            map.put("lastTemperature",lastTemperatureStr);
 
-            if(lastTemperatureDou>temperatureConfig.getMax()){
+            if(lastTemperature.floatValue() > temperatureConfig.getMax()){
                 map.put("isNormal",false);
             }
             else{
                 map.put("isNormal",true);
             }
 
-            double curTemperature = 0;
+            DateTime today = DateTime.now().withTimeAtStartOfDay();
 
-            int totalDays = 0;
+            //todo 最近14天未测体温数
+            Integer detectedCount = personDeviceFilterLogService.countDayByPersonIdAndDate(person.getId(),today.minusDays(13).toDate(),today.plusDays(1).toDate());
+            map.put("unDetectedCount",14 - detectedCount);
 
-            int i = 0;
+            //todo 获取连续检测天数
+            //最近一年的节假日
+            Set<String> holidaySet = holidayInfoService.getHolidaySetByDate(today.minusDays(364).toDate(),today.plusDays(1).toDate());
 
-            DateTime today = DateTime.now().withTimeAtStartOfDay();
+            //查询当前用户的考勤设置
+            Set<Integer> weekdaySet = alarmConfigService.getWeekdaySetByCompanyId(person.getCompanyId());
+
+            int totalDays = 0;
 
             //最多查一年
-            while (i<=365) {
-                DateTime startTime = today.minusDays(i+1);
-                DateTime endTime = today.minusDays(i);
+            for(int i=0;i<365;i++) {
+                DateTime startTime = today.minusDays(i);
+                DateTime endTime = today.minusDays(i-1);
+
+                //先排除一周非工作日
+                if (!weekdaySet.contains(startTime.getDayOfWeek())){
+                    continue;
+                }
 
-                //先排除星期天
-                if (startTime.getDayOfWeek()==7){
-                    i++;
+                //再排除节假日
+                if (holidaySet.contains(startTime.toString("yyyy-MM-dd"))){
                     continue;
                 }
 
                 PersonDeviceFilterLog item = personDeviceFilterLogService.findByPersonOrderTemperature(person.getId(), startTime.toString("yyyy-MM-dd"), endTime.toString("yyyy-MM-dd"));
 
                 if(item!=null){
-                    curTemperature = item.getTemperature().doubleValue();
+                    float curTemperature = item.getTemperature().floatValue();
 
                     if(curTemperature<=temperatureConfig.getMax()){
                         totalDays++;
@@ -159,8 +183,10 @@ public class IndividualLogApiController {
                     }
                 }
                 else{
-                    //无记录则跳出循环
-                    break;
+                    //之前无测温记录则跳出循环
+                    if(i!=0) {
+                        break;
+                    }
                 }
             }
 
@@ -196,54 +222,60 @@ public class IndividualLogApiController {
 
             PersonInfo person = personInfoService.get(Long.valueOf(personId));
 
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-            SimpleDateFormat f = new SimpleDateFormat("MM-dd");
-
-            for (int j = 2; j >=0;j--) {
-
-                Map<String, Object> map = new HashMap<>();
+            Map<String, Object> map = new HashMap<>();
+            DateTime now = DateTime.now();
+            DateTime startTime = now.minusDays(13);
+            DateTime endTime = now;
 
-                map.put("startDate", sdf.format(DateTime.now().plusDays(-14-(j*14)).toDate()));
-                map.put("endDate", sdf.format(DateTime.now().plusDays(-(j*14)).toDate()));
+            map.put("startDate", startTime.toString("yyyy-MM-dd"));
+            map.put("endDate", endTime.toString("yyyy-MM-dd"));
 
-                List<Map<String, Object>> list1 = new ArrayList<>();
+            List<Map<String, Object>> list1 = new ArrayList<>();
 
-                for (int i = 13; i >=0; i--) {
-                    Map<String, Object> map1 = new HashMap<>();
-
-                    String startDate = sdf.format(DateTime.now().plusDays( - i-(j*14)).toDate());
-
-                    String endDate = sdf.format(DateTime.now().plusDays(1 - i-(j*14)).toDate());
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            PersonDeviceFilterLog lastPersonLog = personDeviceFilterLogService.lastPersonLog(person.getId());
+            String lastDateStr = sdf.format(lastPersonLog.getRecordTime());
 
-                    PersonDeviceFilterLog personDeviceFilterLog = personDeviceFilterLogService.findByPersonOrderTemperature(person.getId(), startDate, endDate);
+            for (int i =0;i<14;i++) {
+                Map<String, Object> map1 = new HashMap<>();
+                DateTime today = startTime.plusDays(i);
 
-                    if (personDeviceFilterLog != null) {
+                String startDate = today.toString("yyyy-MM-dd");
+                String endDate = today.plusDays(1).toString("yyyy-MM-dd");
 
-                        Date recordTime = personDeviceFilterLog.getRecordTime();
-                        String hour = f.format(recordTime);
+                PersonDeviceFilterLog personDeviceFilterLog = null;
 
-                        boolean isDanger = false;
+                if (lastDateStr.equals(startDate)){
+                    personDeviceFilterLog = lastPersonLog;
+                }
+                else{
+                    personDeviceFilterLog  = personDeviceFilterLogService.findByPersonOrderTemperature(person.getId(), startDate, endDate);
+                }
 
-                        map1.put("name", hour);
-                        map1.put("value", personDeviceFilterLog.getTemperature());
-                        double temperatureDou = Double.parseDouble(personDeviceFilterLog.getTemperature().toString());
-                        if (temperatureDou > temperatureConfig.getMax()) {
-                            isDanger = true;
-                        }
+                if (personDeviceFilterLog != null) {
+                    boolean isDanger = false;
 
-                        map1.put("danger", isDanger);
+                    map1.put("name", today.toString("MM-dd"));
+                    map1.put("value", personDeviceFilterLog.getTemperature());
 
-                        list1.add(map1);
+                    if (personDeviceFilterLog.getTemperature().floatValue() > temperatureConfig.getMax()) {
+                        isDanger = true;
                     }
-                }
-
-                if(list1.size()>0) {
-                    map.put("list", list1);
 
-                    totalList.add(map);
+                    map1.put("danger", isDanger);
                 }
+                else{
+                    map1.put("name", today.toString("MM-dd"));
+                    map1.put("value", 0);
+                    map1.put("danger", false);
+                }
+
+                list1.add(map1);
             }
 
+            map.put("list", list1);
+            totalList.add(map);
+
             messageResult.setData(totalList);
             messageResult.setResult(true);
         }

+ 13 - 5
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonDeviceLogApiController.java

@@ -232,6 +232,7 @@ public class PersonDeviceLogApiController {
 
             if (StringUtils.isNotEmpty(filter) && "1".equals(filter)){
                 personSearchParam.put("abnormalDate",queryDate);
+                personSearchParam.put("temperature",temperatureConfig.getMax());
             }
 
             List<Sort> sortList1 = new ArrayList<>();
@@ -254,7 +255,8 @@ public class PersonDeviceLogApiController {
                 searchParams.put("endTime", startTime.plusDays(1).toDate());
 
                 if (StringUtils.isNotEmpty(filter) && "1".equals(filter)){
-                    searchParams.put("abnormalFilter","1");
+                    searchParams.put("fever",true);
+                    searchParams.put("temperatureMax",temperatureConfig.getMax());
                 }
 
                 List<Sort> sortList = new ArrayList<>();
@@ -426,9 +428,14 @@ public class PersonDeviceLogApiController {
                 endTime = new DateTime(endTime).plusDays(1).toDate();
             }
 
-            long normalCount = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",personInfo.getId(),1,startTime,endTime);
-            long abnormalCount = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",personInfo.getId(),-1,startTime,endTime);
-            long undetectedCount = personDeviceFilterLogService.countUndetectedByCompanyCode(companyInfo.getCode() + "%",personInfo.getId(), startTime,endTime);
+            long normalCount = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",personInfo.getId(),
+                    1,temperatureConfig.getMax(),startTime,endTime);
+
+            long abnormalCount = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",personInfo.getId(),
+                    -1,temperatureConfig.getMax(),startTime,endTime);
+
+            long undetectedCount = personDeviceFilterLogService.countUndetectedByCompanyCode(companyInfo.getCode() + "%",personInfo.getId(),
+                    startTime,endTime);
 
             Map<String,Object> map1 = new HashMap();
 
@@ -493,7 +500,8 @@ public class PersonDeviceLogApiController {
                 endTime = new DateTime(endTime).plusDays(1).toDate();
             }
 
-            long detected = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",personInfo.getId(),0,startTime,endTime);
+            long detected = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",personInfo.getId(),
+                    0,temperatureConfig.getMax(),startTime,endTime);
 
             Map map = new HashMap();
             map.put("detected",detected);