Bladeren bron

Merge remote-tracking branch 'origin/V1' into V1

jz.kai 5 jaren geleden
bovenliggende
commit
ee87989b73

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/CompanyDeviceRelationDAO.java

@@ -18,4 +18,5 @@ public interface CompanyDeviceRelationDAO {
 	List<CompanyDeviceRelation> list();
 	List<CompanyDeviceRelation> search(Map<String,Object> searchParams,List<Sort> sortList);
     List<DeviceInfo> findDeviceByCompanyId(String companyId);
+	int deleteByCompanyId(String companyId);
 }

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

@@ -37,5 +37,9 @@ public interface PersonDeviceFilterLogDAO {
 
     List<Map<String, Object>> unusualStatistics(@Param("temperature")BigDecimal temperature,@Param("startDate")String startDate,@Param("endDate")String endDate);
 
+    PersonDeviceFilterLog lastPersonLog(Long personId);
+
+    PersonDeviceFilterLog getByPersonIdAndDate(@Param("personId")Long personId,@Param("startDate")String startDate, @Param("endDate")String endDate);
+
     PersonDeviceFilterLog get(Long id);
 }

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/CompanyDeviceRelationService.java

@@ -16,4 +16,5 @@ public interface CompanyDeviceRelationService {
 	List<CompanyDeviceRelation> list();
 	Page<CompanyDeviceRelation> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
 	List<DeviceInfo> findDeviceByCompanyId(String companyId);
+	int deleteByCompanyId(String companyId);
 }

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

@@ -38,5 +38,10 @@ public interface PersonDeviceFilterLogService {
 
     List<Map<String, Object>> unusualStatistics(BigDecimal temperature,String startDate,String endDate);
 
+    PersonDeviceFilterLog lastPersonLog(Long personId);
+
+    PersonDeviceFilterLog getByPersonIdAndDate(Long personId,String startDate,String endDate);
+
     PersonDeviceFilterLog get(Long id);
+
 }

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

@@ -74,4 +74,9 @@ public class CompanyDeviceRelationServiceImpl implements CompanyDeviceRelationSe
 	public List<DeviceInfo> findDeviceByCompanyId(String companyId) {
 		return companyDeviceRelationDAO.findDeviceByCompanyId(companyId);
 	}
+
+	@Override
+	public int deleteByCompanyId(String companyId) {
+		return companyDeviceRelationDAO.deleteByCompanyId(companyId);
+	}
 }

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

@@ -166,6 +166,16 @@ public class PersonDeviceFilterLogServiceImpl implements PersonDeviceFilterLogSe
         return personDeviceFilterLogDAO.temperatureUnusualStatistics(temperature,startDate,endDate);
     }
 
+    @Override
+    public PersonDeviceFilterLog lastPersonLog(Long personId){
+        return personDeviceFilterLogDAO.lastPersonLog(personId);
+    }
+
+    @Override
+    public PersonDeviceFilterLog getByPersonIdAndDate(Long personId,String startDate,String endDate){
+        return personDeviceFilterLogDAO.getByPersonIdAndDate(personId,startDate,endDate);
+    }
+
 
     @Override
     public List<PersonDeviceFilterLog> list(){

+ 3 - 0
common/src/main/resources/mapper/base/CompanyDeviceRelation.xml

@@ -38,6 +38,9 @@
     <delete id="delete" parameterType="string">
         delete from base_company_device_relation where id_=#{id,jdbcType=VARCHAR}
     </delete>
+    <delete id="deleteByCompanyId" parameterType="string">
+        delete from base_company_device_relation where company_id=#{0}
+    </delete>
     <update id="update" parameterType="com.jpsoft.smart.modules.base.entity.CompanyDeviceRelation">
         update base_company_device_relation
         <set>

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

@@ -190,5 +190,18 @@
         ]]>
         GROUP BY c.id_
     </select>
+    <select id="lastPersonLog"   resultMap="PersonDeviceFilterLogMap">
+        SELECT * FROM base_person_device_filter_log
+        WHERE del_flag = FALSE AND person_id = #{personId}
+        ORDER BY record_time desc LIMIT 1
+    </select>
+    <select id="getByPersonIdAndDate"   resultMap="PersonDeviceFilterLogMap">
+        SELECT * FROM base_person_device_filter_log
+        WHERE del_flag=FALSE AND person_id= #{personId}
+        <![CDATA[
+          AND record_time >= #{startDate} AND record_time < #{endDate}
+        ]]>
+        ORDER BY record_time desc LIMIT 1
+    </select>
 
 </mapper>

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

@@ -245,7 +245,7 @@
         left join base_company_info b on a.company_id = b.id_
         where a.open_id=#{openId} and a.del_flag = 0 limit 1
     </select>
-    <select id="findByCompanyId" resultType="com.jpsoft.smart.modules.base.entity.PersonInfo">
+    <select id="findByCompanyId" resultMap="PersonInfoMap">
         select a.* from base_person_info a
         where
         a.company_id=#{companyId} and a.del_flag = 0

+ 62 - 3
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -2,17 +2,17 @@ package com.jpsoft.smart.modules.base.controller;
 
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.modules.base.dto.CompanyInfoDTO;
-import com.jpsoft.smart.modules.base.entity.CompanyPosition;
-import com.jpsoft.smart.modules.base.entity.PersonInfo;
+import com.jpsoft.smart.modules.base.entity.*;
+import com.jpsoft.smart.modules.base.service.CompanyDeviceRelationService;
 import com.jpsoft.smart.modules.base.service.CompanyPositionService;
 import com.jpsoft.smart.modules.base.service.PersonInfoService;
 import com.jpsoft.smart.modules.common.utils.PojoUtils;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
-import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.service.CompanyInfoService;
 import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.UserService;
+import com.rabbitmq.client.AMQP;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -21,6 +21,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
@@ -47,6 +49,9 @@ public class CompanyInfoController {
     @Autowired
     private PersonInfoService personInfoService;
 
+    @Autowired
+    private CompanyDeviceRelationService companyDeviceRelationService;
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<CompanyInfoDTO> create(){
@@ -369,4 +374,58 @@ public class CompanyInfoController {
 
         return msgResult;
     }
+
+    @GetMapping("queryBindDeviceList")
+    public MessageResult<List> queryBindDeviceList(String companyId){
+        MessageResult<List> messageResult = new MessageResult<>();
+
+        try {
+            List<DeviceInfo> deviceList = companyDeviceRelationService.findDeviceByCompanyId(companyId);
+
+            messageResult.setData(deviceList);
+            messageResult.setResult(true);
+        }
+        catch (Exception ex){
+            logger.error(ex.getMessage(),ex);
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @PostMapping("bindDevice")
+    public MessageResult<String> bindDevice(String companyId,String deviceIds,@ModelAttribute String subject){
+        MessageResult<String> messageResult = new MessageResult<>();
+
+        try {
+            String[] arr = deviceIds.split(",");
+
+            companyDeviceRelationService.deleteByCompanyId(companyId);
+
+            for (String deviceId : arr) {
+                CompanyDeviceRelation cdr = new CompanyDeviceRelation();
+                cdr.setId(UUID.randomUUID().toString());
+                cdr.setCompanyId(companyId);
+                cdr.setDeviceId(deviceId);
+
+                cdr.setCreateBy(subject);
+                cdr.setCreateTime(new Date());
+
+                companyDeviceRelationService.insert(cdr);
+            }
+
+            messageResult.setResult(true);
+        }
+        catch (Exception ex){
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+
+            logger.error(ex.getMessage(),ex);
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
 }

+ 231 - 2
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/IndividualLogApiController.java

@@ -1,12 +1,241 @@
 package com.jpsoft.smart.modules.mobile.controller;
 
+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.common.dto.MessageResult;
+import com.jpsoft.smart.modules.common.dto.Sort;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 @Slf4j
 @RestController
 @RequestMapping("/mobile/IndividualLogApi")
 public class IndividualLogApiController {
+    @Autowired
+    private PersonInfoService personInfoService;
+    @Autowired
+    private PersonDeviceFilterLogService personDeviceFilterLogService;
+
+    @PostMapping("healthyPersonList")
+    @ApiOperation(value="健康公示列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form"),
+            @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
+    })
+    public MessageResult<List<PersonInfo>> healthyPersonList(
+            String token,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            @RequestAttribute String subject){
+        MessageResult<List<PersonInfo>> messageResult = new MessageResult<>();
+
+        try{
+            PersonInfo admin = personInfoService.get(Long.valueOf(subject));
+
+            String companyId = admin.getCompanyId();
+
+            Map<String,Object> searchParams = new HashMap<>();
+
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("a.create_time","desc"));
+
+            searchParams.put("companyId",companyId);
+
+            List<PersonInfo> personInfoList = personInfoService.pageSearch(searchParams,pageIndex,pageSize,false,sortList);
+
+            messageResult.setResult(true);
+            messageResult.setData(personInfoList);
+        }
+        catch (Exception ex){
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
+
+    @PostMapping("temperaturePersonDetail")
+    @ApiOperation(value="人员体温详情")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="personId",value = "人员ID",required = true,paramType = "form"),
+            @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form"),
+            @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
+    })
+    public MessageResult<Map> temperaturePersonDetail(
+            String personId, String token,
+            @RequestAttribute String subject){
+        MessageResult<Map> messageResult = new MessageResult<>();
+        Map<String,Object> map = new HashMap<>();
+
+        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;
+            if(lastTemperature != null){
+                lastTemperatureStr = String.valueOf(lastTemperature);
+                lastTemperatureDou = Double.parseDouble(lastTemperatureStr);
+            }
+            else{
+                lastTemperatureStr = "无记录";
+            }
+            map.put("lastTemperature",lastTemperatureStr);
+
+            if(lastTemperatureDou>=37){
+                map.put("isNormal","异常");
+            }
+            else{
+                map.put("isNormal","正常");
+            }
+
+            double curTemperature = 0;
+
+            int totalDays = 0;
+
+            int i = 0;
+
+            Date now = new Date();
+
+            while (curTemperature < 37) {
+
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+                Calendar rightNow = Calendar.getInstance();
+                rightNow.setTime(now);
+                rightNow.add(Calendar.DATE, -(i+1));
+                Date dt1 = rightNow.getTime();
+                String startDate = sdf.format(dt1);
+
+                Calendar rightNow2 = Calendar.getInstance();
+                rightNow2.setTime(now);
+                rightNow2.add(Calendar.DATE, -i);
+                Date dt2 = rightNow2.getTime();
+                String endDate = sdf.format(dt2);
+
+                PersonDeviceFilterLog item = personDeviceFilterLogService.getByPersonIdAndDate(person.getId(), startDate, endDate);
+
+                if(item!=null){
+                    String temperature = item.getTemperature().toString();
+
+                    curTemperature = Double.parseDouble(temperature);
+
+                    if(curTemperature<37){
+                        totalDays++;
+                        i++;
+                    }
+                    else{
+                        //有异常温度跳出循环
+                        break;
+                    }
+                }
+                else{
+                    //无记录则跳出循环
+                    break;
+                }
+            }
+
+            map.put("totalDays",totalDays);
+
+            messageResult.setResult(true);
+            messageResult.setData(map);
+        }
+        catch (Exception ex){
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
+
+    @PostMapping("temperaturePersonCurve")
+    @ApiOperation(value="人员温度曲线接口")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="personId",value = "人员ID",required = true,paramType = "form"),
+            @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form"),
+            @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
+    })
+    public MessageResult<List<Map<String,Object>>> temperaturePersonCurve(
+            String personId, String token,
+            @RequestAttribute String subject){
+
+        MessageResult<List<Map<String,Object>>> messageResult = new MessageResult<>();
+
+        try {
+            List<Map<String,Object>> totalList = new ArrayList<>();
+
+            Date now = new Date();
+            PersonInfo person = personInfoService.get(Long.valueOf(personId));
+
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            SimpleDateFormat f = new SimpleDateFormat("HH");
+
+            for (int i = 0;i < 14;i++) {
+                Map<String, Object> map = new HashMap<>();
+
+                Calendar rightNow = Calendar.getInstance();
+                rightNow.setTime(now);
+                rightNow.add(Calendar.DATE, -(i + 1));
+                Date dt1 = rightNow.getTime();
+                String startDate = sdf.format(dt1);
+
+                Calendar rightNow2 = Calendar.getInstance();
+                rightNow2.setTime(now);
+                rightNow2.add(Calendar.DATE, -i);
+                Date dt2 = rightNow2.getTime();
+                String endDate = sdf.format(dt2);
+
+                List<PersonDeviceFilterLog> personDeviceLogList = personDeviceFilterLogService.findByPersonAndDate(person.getId(),startDate,endDate);
+
+                map.put("date",startDate);
+
+                List<Map<String,Object>> list = new ArrayList<>();
+                boolean isDanger = false;
+                for (PersonDeviceFilterLog personDeviceFilterLog:personDeviceLogList) {
+                    Map<String, Object> mapChi = new HashMap<>();
+                    Date recordTime = personDeviceFilterLog.getRecordTime();
+                    String hour = f.format(recordTime);
+
+                    mapChi.put("name",hour+"时");
+                    mapChi.put("value",personDeviceFilterLog.getTemperature());
+                    double temperatureDou = Double.parseDouble(personDeviceFilterLog.getTemperature().toString());
+                    if(temperatureDou>=37){
+                        isDanger = true;
+                    }
+                    list.add(mapChi);
+                }
+
+                map.put("list",list);
+                map.put("danger",isDanger);
+
+                totalList.add(map);
+            }
+
+            messageResult.setData(totalList);
+            messageResult.setResult(true);
+        }
+        catch (Exception ex){
+            messageResult.setMessage(ex.getMessage());
+            messageResult.setResult(false);
+        }
+
+        return messageResult;
 
+    }
 }