Bladeren bron

1.统计页面修改。

tomatozq 5 jaren geleden
bovenliggende
commit
000bdc652a

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/CompanyInfoDAO.java

@@ -25,4 +25,6 @@ public interface CompanyInfoDAO {
 	List<CompanyInfo> findByCompanyCode(String code);
 
 	long countByParentId(String parentId);
+
+	long countByCompanyCode(String code);
 }

+ 6 - 3
common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonDeviceFilterLogDAO.java

@@ -8,6 +8,7 @@ import com.jpsoft.smart.modules.common.dto.Sort;
 import org.springframework.stereotype.Repository;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -29,17 +30,19 @@ public interface PersonDeviceFilterLogDAO {
 
     List<PersonDeviceFilterLog> findByPersonAndDate(@Param("personId") Long personId, @Param("startDate")String startDate, @Param("endDate")String endDate);
 
-    List<PersonDeviceFilterLog> temperatureNormalStatistics(@Param("temperature")BigDecimal temperature, @Param("startDate")String startDate, @Param("endDate")String endDate);
+    List<PersonDeviceFilterLog> temperatureNormalStatistics(String companyCode,BigDecimal temperature, Date startDate, Date endDate);
 
-    List<PersonDeviceFilterLog> temperatureUnusualStatistics(@Param("temperature")BigDecimal temperature,@Param("startDate")String startDate, @Param("endDate")String endDate);
+    List<PersonDeviceFilterLog> temperatureUnusualStatistics(String companyCode,BigDecimal temperature,Date startDate,Date endDate);
 
     List<PersonDeviceFilterLog> list();
 
-    List<Map<String, Object>> unusualStatistics(@Param("temperature")BigDecimal temperature,@Param("startDate")String startDate,@Param("endDate")String endDate);
+    List<Map<String, Object>> unusualStatistics(String companyCode, BigDecimal temperature, Date startDate, Date endDate);
 
     PersonDeviceFilterLog lastPersonLog(Long personId);
 
     PersonDeviceFilterLog getByPersonIdAndDate(@Param("personId")Long personId,@Param("startDate")String startDate, @Param("endDate")String endDate);
 
     PersonDeviceFilterLog get(Long id);
+
+    long countByTimeRangeAndCompanyCode(String companyCode,int status, Date startDate, Date endDate);
 }

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonInfoDAO.java

@@ -21,4 +21,6 @@ public interface PersonInfoDAO {
 	PersonInfo findByOpenId(String openId);
 
     List<PersonInfo> findByCompanyId(String companyId);
+
+    long countByCompanyCode(String code);
 }

+ 2 - 3
common/src/main/java/com/jpsoft/smart/modules/base/service/CompanyInfoService.java

@@ -2,9 +2,6 @@ package com.jpsoft.smart.modules.base.service;
 
 import java.util.List;
 import java.util.Map;
-
-import com.jpsoft.smart.modules.base.dao.CompanyInfoDAO;
-import com.jpsoft.smart.modules.base.dto.CompanyInfoDTO;
 import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.modules.common.dto.Sort;
@@ -19,4 +16,6 @@ public interface CompanyInfoService {
 	Page<CompanyInfo> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,List<Sort> sortList);
     List<CompanyInfo> findByCompanyCode(String code);
     long countByParentId(String parentId);
+
+    long countByCompanyCode(String code);
 }

+ 4 - 3
common/src/main/java/com/jpsoft/smart/modules/base/service/PersonDeviceFilterLogService.java

@@ -32,11 +32,11 @@ public interface PersonDeviceFilterLogService {
 
     List<PersonDeviceFilterLog> list();
 
-    List<PersonDeviceFilterLog> temperatureNormalStatistics(BigDecimal temperature,String startDate,String endDate);
+    List<PersonDeviceFilterLog> temperatureNormalStatistics(String companyCode,BigDecimal temperature,Date startDate,Date endDate);
 
-    List<PersonDeviceFilterLog> temperatureUnusualStatistics(BigDecimal temperature,String startDate,String endDate);
+    List<PersonDeviceFilterLog> temperatureUnusualStatistics(String companyCode,BigDecimal temperature,Date startDate,Date endDate);
 
-    List<Map<String, Object>> unusualStatistics(BigDecimal temperature,String startDate,String endDate);
+    List<Map<String, Object>> unusualStatistics(String companyCode,BigDecimal temperature,Date startDate,Date endDate);
 
     PersonDeviceFilterLog lastPersonLog(Long personId);
 
@@ -44,4 +44,5 @@ public interface PersonDeviceFilterLogService {
 
     PersonDeviceFilterLog get(Long id);
 
+    long countByTimeRangeAndCompanyCode(String companyCode,int status,Date startTime, Date endTime);
 }

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/PersonInfoService.java

@@ -19,4 +19,6 @@ public interface PersonInfoService {
 	PersonInfo findByOpenId(String openId);
 
     List<PersonInfo> findByCompanyId(String companyId);
+
+    long countByCompanyCode(String code);
 }

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

@@ -77,4 +77,9 @@ public class CompanyInfoServiceImpl implements CompanyInfoService {
 	public long countByParentId(String parentId) {
 		return companyInfoDAO.countByParentId(parentId);
 	}
+
+	@Override
+	public long countByCompanyCode(String code) {
+		return companyInfoDAO.countByCompanyCode(code);
+	}
 }

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

@@ -155,17 +155,6 @@ public class PersonDeviceFilterLogServiceImpl implements PersonDeviceFilterLogSe
         return personDeviceFilterLogDAO.findByPersonAndDate(personId,startDate,endDate);
     }
 
-
-    @Override
-    public List<PersonDeviceFilterLog> temperatureNormalStatistics(BigDecimal temperature,String startDate,String endDate){
-        return personDeviceFilterLogDAO.temperatureNormalStatistics(temperature,startDate,endDate);
-    }
-
-    @Override
-    public List<PersonDeviceFilterLog> temperatureUnusualStatistics(BigDecimal temperature,String startDate,String endDate){
-        return personDeviceFilterLogDAO.temperatureUnusualStatistics(temperature,startDate,endDate);
-    }
-
     @Override
     public PersonDeviceFilterLog lastPersonLog(Long personId){
         return personDeviceFilterLogDAO.lastPersonLog(personId);
@@ -183,7 +172,23 @@ public class PersonDeviceFilterLogServiceImpl implements PersonDeviceFilterLogSe
     }
 
     @Override
-    public List<Map<String, Object>> unusualStatistics(BigDecimal temperature,String startDate,String endDate){
-        return personDeviceFilterLogDAO.unusualStatistics(temperature,startDate,endDate);
+    public long countByTimeRangeAndCompanyCode(String companyCode,int status, Date startDate, Date endDate) {
+        return personDeviceFilterLogDAO.countByTimeRangeAndCompanyCode(companyCode,status,startDate,endDate);
+    }
+
+    @Override
+    public List<PersonDeviceFilterLog> temperatureNormalStatistics(String companyCode, BigDecimal temperature, Date startDate, Date endDate) {
+
+        return personDeviceFilterLogDAO.temperatureNormalStatistics(companyCode,temperature,startDate,endDate);
+    }
+
+    @Override
+    public List<PersonDeviceFilterLog> temperatureUnusualStatistics(String companyCode, BigDecimal temperature, Date startDate, Date endDate) {
+        return personDeviceFilterLogDAO.temperatureUnusualStatistics(companyCode,temperature,startDate,endDate);
+    }
+
+    @Override
+    public List<Map<String, Object>> unusualStatistics(String companyCode, BigDecimal temperature, Date startDate, Date endDate) {
+        return personDeviceFilterLogDAO.unusualStatistics(companyCode,temperature,startDate,endDate);
     }
 }

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

@@ -82,4 +82,9 @@ public class PersonInfoServiceImpl implements PersonInfoService {
 	public List<PersonInfo> findByCompanyId(String companyId) {
 		return personInfoDAO.findByCompanyId(companyId);
 	}
+
+	@Override
+	public long countByCompanyCode(String code) {
+		return personInfoDAO.countByCompanyCode(code);
+	}
 }

+ 5 - 0
common/src/main/resources/mapper/base/CompanyInfo.xml

@@ -132,4 +132,9 @@
             </if>
         </where>
     </select>
+    <select id="countByCompanyCode" resultType="long">
+        select count(*)
+        from base_company_info
+        where code_ like #{code} and del_flag=0
+    </select>
 </mapper>

+ 50 - 10
common/src/main/resources/mapper/base/PersonDeviceFilterLog.xml

@@ -165,15 +165,27 @@
         </foreach>
     </select>
     <select id="temperatureNormalStatistics"   resultMap="PersonDeviceFilterLogMap">
-        select * from base_person_device_filter_log where del_flag=false
         <![CDATA[
-          and temperature_ < #{temperature} and record_time >= #{startDate} and record_time <= #{endDate}
+            select count(*) from base_person_device_filter_log a
+            LEFT JOIN base_person_info b on a.person_id=b.id_
+            LEFT JOIN base_company_info c on b.company_id=c.id_
+            where a.del_flag=false
+            and c.code_ like #{companyCode}
+            and a.temperature_ < #{temperature}
+            and a.record_time >= #{startDate}
+            and a.record_time <= #{endDate}
         ]]>
     </select>
     <select id="temperatureUnusualStatistics"   resultMap="PersonDeviceFilterLogMap">
-        select * from base_person_device_filter_log where del_flag=false
         <![CDATA[
-          and temperature_ >= #{temperature} and record_time >= #{startDate} and record_time <= #{endDate}
+            select count(*) from base_person_device_filter_log a
+            LEFT JOIN base_person_info b on a.person_id=b.id_
+            LEFT JOIN base_company_info c on b.company_id=c.id_
+            where a.del_flag=false
+            and c.code_ like #{companyCode}
+            and a.temperature_ >= #{temperature}
+            and a.record_time >= #{startDate}
+            and a.record_time <= #{endDate}
         ]]>
     </select>
     <select id="list"   resultMap="PersonDeviceFilterLogMap">
@@ -181,14 +193,22 @@
     </select>
 
     <select id="unusualStatistics"   resultType="java.util.HashMap">
-        select c.id_ as id, c.name_ as name,count(b.id_) as personCount from base_person_device_filter_log a
+        <![CDATA[
+        select
+        c.id_ as id,
+        c.name_ as name,
+        date_format(a.record_time,'%Y-%m-%d') as date,
+        count(b.id_) as personCount
+        from base_person_device_filter_log a
         LEFT JOIN base_person_info b on a.person_id=b.id_
         LEFT JOIN base_company_info c on b.company_id=c.id_
-        <![CDATA[
-            where a.del_flag=false and a.temperature_ >= #{temperature} and
-            a.record_time >= #{startDate} and a.record_time < #{endDate}
+            where a.del_flag=false
+            and c.code_ like #{companyCode}
+            and a.temperature_ >= #{temperature}
+            and a.record_time >= #{startDate}
+            and a.record_time < #{endDate}
+        GROUP BY c.id_,date_format(a.record_time,'%Y-%m-%d')
         ]]>
-        GROUP BY c.id_
     </select>
     <select id="lastPersonLog"   resultMap="PersonDeviceFilterLogMap">
         SELECT * FROM base_person_device_filter_log
@@ -203,5 +223,25 @@
         ]]>
         ORDER BY record_time desc LIMIT 1
     </select>
-
+    <select id="countByTimeRangeAndCompanyCode" resultType="long">
+        <![CDATA[
+            select count(*) from base_person_device_filter_log a
+            LEFT JOIN base_person_info b on a.person_id=b.id_
+            LEFT JOIN base_company_info c on b.company_id=c.id_
+            where a.del_flag=false
+            and c.code_ like #{companyCode}
+            and record_time >= #{startDate}
+            and record_time <= #{endDate}
+        ]]>
+        <if test="status==-1">
+        <![CDATA[
+            and a.temperature_>=37
+        ]]>
+        </if>
+        <if test="status==1">
+            <![CDATA[
+            and a.temperature_<37
+        ]]>
+        </if>
+    </select>
 </mapper>

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

@@ -251,4 +251,11 @@
         a.company_id=#{companyId} and a.del_flag = 0
         order by a.id_ asc
     </select>
+    <select id="countByCompanyCode" resultType="long">
+        select count(*)
+        from base_person_info a
+        left join base_company_info b on a.company_id = b.id_
+        where a.del_flag = 0
+        and b.code_ like #{0}
+    </select>
 </mapper>

+ 56 - 54
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonDeviceLogApiController.java

@@ -398,52 +398,40 @@ public class PersonDeviceLogApiController {
             @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
     })
     public MessageResult<List<Map>> temperaturePieChart(
-            String startTime,String endTime,
+            @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,
+            @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime,
             String token, @RequestAttribute String subject){
         MessageResult<List<Map>> msgResult = new MessageResult<>();
         List<Map> listMap = new ArrayList<>();
         try{
-            String startDate = "";
-            String endDate = "";
-            //37度以上为异常体温
-            BigDecimal bd = new BigDecimal(37);
+            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
+            CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
 
-            if(StringUtil.isNotEmpty(startTime)&&StringUtil.isNotEmpty(endTime)) {
-                startDate = startTime;
-                endDate = endTime;
+            if (startTime==null){
+                startTime = DateTime.now().plusDays(-14).toDate();
             }
-            else{
-                Date now = new Date();
-                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-
-                Calendar rightNow = Calendar.getInstance();
-                rightNow.setTime(now);
-                rightNow.add(Calendar.DATE, -14);
-
-                Calendar now1 = Calendar.getInstance();
-                now1.setTime(now);
-                now1.add(Calendar.DATE, 1);
 
-                Date dt1 = rightNow.getTime();
-                Date dt2 = now1.getTime();
-                startDate = sdf.format(dt1);
-                endDate = sdf.format(dt2);
+            if (endTime==null){
+                endTime = DateTime.now().plusDays(1).toDate();
+            }
+            else{
+                endTime = new DateTime(endTime).plusDays(1).toDate();
             }
 
-            List<PersonDeviceFilterLog> normalPersonDeviceFilterLogList = personDeviceFilterLogService.temperatureNormalStatistics(bd,startDate,endDate);
-            List<PersonDeviceFilterLog> unusualPersonDeviceFilterLogList = personDeviceFilterLogService.temperatureUnusualStatistics(bd,startDate,endDate);
+            long normalCount = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",1,startTime,endTime);
+            long abnormalCount = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",-1,startTime,endTime);
 
             Map<String,Object> map1 = new HashMap();
 
             map1.put("name","体温正常");
-            map1.put("value",normalPersonDeviceFilterLogList.size());
+            map1.put("value",normalCount);
 
             listMap.add(map1);
 
             Map<String,Object> map2 = new HashMap();
 
             map2.put("name","体温异常");
-            map2.put("value",unusualPersonDeviceFilterLogList.size());
+            map2.put("value",abnormalCount);
 
             listMap.add(map2);
 
@@ -462,25 +450,44 @@ public class PersonDeviceLogApiController {
     @ApiOperation(value="体温台账统计")
     @RequestMapping(value = "temperatureStatistics",method = RequestMethod.POST)
     @ApiImplicitParams({
+            @ApiImplicitParam(name="startTime",value = "开始时间(格式:yyyy-MM-dd)",paramType = "form"),
+            @ApiImplicitParam(name="endTime",value = "截止时间(格式:yyyy-MM-dd)",paramType = "form"),
             @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form"),
             @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
     })
     public MessageResult<List<Map>> temperatureStatistics(
+            @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,
+            @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime,
             String token, @RequestAttribute String subject){
         MessageResult<List<Map>> msgResult = new MessageResult<>();
         List<Map> listMap = new ArrayList<>();
 
         try{
-            List<PersonDeviceFilterLog> personDeviceFilterLogList = personDeviceFilterLogService.list();
+            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
+            CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
+
+            if (startTime==null){
+                startTime = DateTime.now().plusDays(-14).toDate();
+            }
+
+            if (endTime==null){
+                endTime = DateTime.now().plusDays(1).toDate();
+            }
+            else{
+                endTime = new DateTime(endTime).plusDays(1).toDate();
+            }
+
+            long detected = personDeviceFilterLogService.countByTimeRangeAndCompanyCode(companyInfo.getCode() + "%",0,startTime,endTime);
+
             Map map = new HashMap();
-            map.put("detected",personDeviceFilterLogList.size());
-            List<CompanyInfo> companyList = companyInfoService.list();
+            map.put("detected",detected);
 
-            map.put("companyCount",companyList.size());
+            long companyCount = companyInfoService.countByCompanyCode(companyInfo.getCode() + "%");
+            map.put("companyCount",companyCount);
 
-            List<PersonInfo> personInfo = personInfoService.list();
+            long personCount = personInfoService.countByCompanyCode(companyInfo.getCode() + "%");
+            map.put("personCount",personCount);
 
-            map.put("personCount",personInfo.size());
             listMap.add(map);
 
             msgResult.setResult(true);
@@ -505,41 +512,35 @@ public class PersonDeviceLogApiController {
             @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
     })
     public MessageResult<Map<String, Object>> unusualStatistics(
-            String startTime,String endTime,
+            @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,
+            @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime,
             String token, @RequestAttribute String subject) {
         MessageResult<Map<String, Object>> msgResult = new MessageResult<>();
 
         Map<String, Object> map = new HashMap<>();
 
         try{
+            PersonInfo personInfo = personInfoService.get(Long.valueOf(subject));
+            CompanyInfo companyInfo = companyInfoService.get(personInfo.getCompanyId());
+
             String startDate = "";
             String endDate = "";
+
             //37度以上为异常体温
-            BigDecimal bd = new BigDecimal(37);
+            BigDecimal standard = new BigDecimal(37);
 
-            if(StringUtil.isNotEmpty(startTime)&&StringUtil.isNotEmpty(endTime)) {
-                startDate = startTime;
-                endDate = endTime;
+            if (startTime==null){
+                startTime = DateTime.now().plusDays(-14).toDate();
             }
-            else{
-                Date now = new Date();
-                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-
-                Calendar rightNow = Calendar.getInstance();
-                rightNow.setTime(now);
-                rightNow.add(Calendar.DATE, -14);
 
-                Calendar now1 = Calendar.getInstance();
-                now1.setTime(now);
-                now1.add(Calendar.DATE, 1);
-
-                Date dt1 = rightNow.getTime();
-                Date dt2 = now1.getTime();
-                startDate = sdf.format(dt1);
-                endDate = sdf.format(dt2);
+            if (endTime==null){
+                endTime = DateTime.now().plusDays(1).toDate();
+            }
+            else{
+                endTime = new DateTime(endTime).plusDays(1).toDate();
             }
 
-            List<Map<String, Object>> mapList = personDeviceFilterLogService.unusualStatistics(bd,startDate,endDate);
+            List<Map<String, Object>> mapList = personDeviceFilterLogService.unusualStatistics(companyInfo.getCode() + "%",standard,startTime,endTime);
             List<Map<String, Object>> list = new ArrayList<>();
 
             int companyTotalCount = 0;
@@ -549,6 +550,7 @@ public class PersonDeviceLogApiController {
                 if(curMap.get("name")!=null){
                     list.add(curMap);
                     companyTotalCount++;
+
                     if(curMap.get("personCount")!=null){
                         String personCountStr = curMap.get("personCount").toString();
                         if(StringUtil.isNotEmpty(personCountStr)){