Przeglądaj źródła

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

jz.kai 5 lat temu
rodzic
commit
c8827b2879

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

@@ -12,6 +12,7 @@ public interface DeviceInfoDAO {
 	int update(DeviceInfo entity);
 	int exist(String id);
 	DeviceInfo get(String id);
+	DeviceInfo getByDeviceNo(String deviceNo);
 	int delete(String id);
 	List<DeviceInfo> list();
 	List<DeviceInfo> search(Map<String, Object> searchParams, List<Sort> sortList);

+ 6 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonDeviceLogDAO.java

@@ -1,8 +1,12 @@
 package com.jpsoft.smart.modules.base.dao;
 
 import com.jpsoft.smart.modules.base.entity.PersonDeviceLog;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author 墨鱼_mo
  * @date 2020-3-15 14:22
@@ -12,4 +16,6 @@ public interface PersonDeviceLogDAO {
 
 
     void insert(PersonDeviceLog personDeviceLog);
+
+    List<PersonDeviceLog> search(Map<String, Object> searchParams, List<Sort> sortList);
 }

+ 16 - 0
common/src/main/java/com/jpsoft/smart/modules/base/entity/PersonDeviceLog.java

@@ -1,8 +1,10 @@
 package com.jpsoft.smart.modules.base.entity;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -28,6 +30,9 @@ public class PersonDeviceLog {
     @ApiModelProperty(value = "设备序列号")
     private String deviceNo;
 
+    @ApiModelProperty(value = "设备信息")
+    private DeviceInfo device;
+
 
     /**
      * 人员id
@@ -35,6 +40,9 @@ public class PersonDeviceLog {
     @ApiModelProperty(value = "人员id")
     private Integer personId;
 
+    @ApiModelProperty(value = "人员信息")
+    private PersonInfo person;
+
     /**
      * 记录温度
      */
@@ -70,6 +78,9 @@ public class PersonDeviceLog {
     /**
      * 记录时间
      */
+
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone ="GMT+8")
     @ApiModelProperty(value = "记录时间")
     private Date recordTime;
 
@@ -88,6 +99,8 @@ public class PersonDeviceLog {
     /**
      * 创建时间
      */
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
     @ApiModelProperty(value = "创建时间")
     private Date createTime;
 
@@ -100,6 +113,9 @@ public class PersonDeviceLog {
     /**
      * 更新时间
      */
+
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
     @ApiModelProperty(value = "更新时间")
     private Date updateTime;
 

+ 7 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/PersonDeviceLogService.java

@@ -1,10 +1,15 @@
 package com.jpsoft.smart.modules.base.service;
 
 import cn.hutool.json.JSONObject;
+import com.jpsoft.smart.modules.base.entity.PersonDeviceLog;
+import com.jpsoft.smart.modules.common.dto.Sort;
+import com.github.pagehelper.Page;
 
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author 墨鱼_mo
@@ -21,4 +26,6 @@ public interface PersonDeviceLogService {
      * @param matchPersonInfo
      */
     void deviceInsertLog(String deviceNo, BigDecimal temperature, JSONObject faceImageJson, JSONObject libMatInfoListJson, JSONObject matchPersonInfo, Date date) ;
+
+    Page<PersonDeviceLog> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
 }

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

@@ -1,11 +1,14 @@
 package com.jpsoft.smart.modules.base.service.impl;
 
 import cn.hutool.json.JSONObject;
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
 import com.jpsoft.smart.config.OSSConfig;
 import com.jpsoft.smart.modules.base.dao.AlarmInfoDAO;
 import com.jpsoft.smart.modules.base.dao.PersonDeviceLogDAO;
 import com.jpsoft.smart.modules.base.entity.PersonDeviceLog;
 import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.utils.BASE64DecodedMultipartFile;
 import com.jpsoft.smart.modules.common.utils.Base64;
 import com.jpsoft.smart.modules.common.utils.IApiUtil;
@@ -24,6 +27,8 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 /**
@@ -106,4 +111,16 @@ public class PersonDeviceLogServiceImpl implements PersonDeviceLogService {
         personDeviceLog.setFaceImage(retFileUrl);
         personDeviceLogDAO.insert(personDeviceLog);
     }
+
+    @Override
+    public Page<PersonDeviceLog> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
+        Page<PersonDeviceLog> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
+            personDeviceLogDAO.search(searchParams,sortList);
+        });
+
+        return page;
+    }
+
+
+
 }

+ 4 - 0
common/src/main/resources/mapper/base/DeviceInfo.xml

@@ -118,6 +118,10 @@
 	<select id="get" parameterType="string" resultMap="DeviceInfoMap">
 		select 
 id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,code_address,ip_address,port_,type_,is_auto_update,del_flag,create_by,create_time,update_by,update_time		from base_device_info where id_=#{0}
+	</select>
+	<select id="getByDeviceNo" parameterType="string" resultMap="DeviceInfoMap">
+		select
+id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,code_address,ip_address,port_,type_,is_auto_update,del_flag,create_by,create_time,update_by,update_time		from base_device_info where device_no=#{0}
 	</select>
 	<select id="exist" parameterType="string" resultType="int">
 		select count(*) from base_device_info where id_=#{0} and  del_flag=false

+ 42 - 0
common/src/main/resources/mapper/base/PersonDeviceLog.xml

@@ -18,6 +18,10 @@
         <result property="matchFaceId" column="match_face_id" />
         <result property="faceImage" column="face_image" />
         <result property="recordTime" column="record_time" />
+        <association property="device" column="device_no"
+                     select="com.jpsoft.smart.modules.base.dao.DeviceInfoDAO.getByDeviceNo"></association>
+        <association property="person" column="person_id"
+                     select="com.jpsoft.smart.modules.base.dao.PersonInfoDAO.get"></association>
     </resultMap>
     <insert id="insert" parameterType="PersonDeviceLog">
         <!--
@@ -47,5 +51,43 @@
 		)
 	]]>
     </insert>
+    <select id="search" parameterType="hashmap" resultMap="PersonDeviceLogMap">
+        <![CDATA[
+			select * from base_person_device_log a left join base_device_info b
+			on  a.device_no = b.device_no left join base_person_info c
+			on a.person_id = c.id_
+		]]>
+        <where>
+            and a.del_flag = false and b.del_flag=false and c.del_flag=false
+            <if test="searchParams.companyId != null">
+                and c.company_id = #{searchParams.companyId}
+            </if>
+            <if test="searchParams.deviceNo != null">
+                and a.device_no like #{searchParams.deviceNo}
+            </if>
+            <if test="searchParams.aliasName != null">
+                and b.alias_name like #{searchParams.aliasName}
+            </if>
+            <if test="searchParams.personName != null">
+                and c.name_ like #{searchParams.personName}
+            </if>
+            <if test="searchParams.matchStatus != null">
+                and a.match_status = #{searchParams.matchStatus}
+            </if>
+            <if test="searchParams.beginTime != null">
+                <![CDATA[
+                  and a.record_time >= #{searchParams.beginTime}
+                ]]>
+            </if>
+            <if test="searchParams.endTime != null">
+                <![CDATA[
+                  and a.record_time <= #{searchParams.endTime}
+                ]]>
+            </if>
+        </where>
+        <foreach item="sort" collection="sortList"  open="order by" separator=",">
+            ${sort.name} ${sort.order}
+        </foreach>
+    </select>
 
 </mapper>

+ 89 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceLogController.java

@@ -0,0 +1,89 @@
+package com.jpsoft.smart.modules.base.controller;
+
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.util.StringUtil;
+import com.jpsoft.smart.modules.base.entity.PersonDeviceLog;
+import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
+import com.jpsoft.smart.modules.common.dto.MessageResult;
+import com.jpsoft.smart.modules.common.dto.Sort;
+import com.jpsoft.smart.modules.common.utils.PojoUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/personDeviceLog")
+@Api(description = "日志台账")
+public class PersonDeviceLogController {
+    @Autowired
+    private PersonDeviceLogService personDeviceLogService;
+
+    @ApiOperation(value="列表")
+    @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "companyId",value = "企业ID", paramType = "query"),
+            @ApiImplicitParam(name = "deviceNo",value = "设备编号", paramType = "query"),
+            @ApiImplicitParam(name = "aliasName",value = "设备别名", paramType = "query"),
+            @ApiImplicitParam(name = "personName",value = "人员姓名", paramType = "query"),
+            @ApiImplicitParam(name = "matchStatus",value = "开门类型", paramType = "query"),
+            @ApiImplicitParam(name = "beginTime",value = "开始时间", paramType = "query"),
+            @ApiImplicitParam(name = "endTime",value = "结束时间", paramType = "query")
+    })
+    public MessageResult<Map> pageList(
+            String companyId,
+            String deviceNo,String aliasName,String personName,
+            String matchStatus,String beginTime,String endTime,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            @RequestAttribute String subject){
+
+        //当前用户ID
+        System.out.println(subject);
+
+        MessageResult<Map> msgResult = new MessageResult<>();
+
+        Map<String,Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("a.record_time","desc"));
+
+        if(StringUtil.isNotEmpty(companyId)){
+            searchParams.put("companyId",companyId);
+        }
+        if(StringUtil.isNotEmpty(deviceNo)){
+            searchParams.put("deviceNo","%"+deviceNo+"%");
+        }
+        if(StringUtil.isNotEmpty(aliasName)){
+            searchParams.put("aliasName","%"+aliasName+"%");
+        }
+        if(StringUtil.isNotEmpty(personName)){
+            searchParams.put("personName","%"+personName+"%");
+        }
+        if(StringUtil.isNotEmpty(matchStatus)){
+            searchParams.put("matchStatus",matchStatus);
+        }
+        if(StringUtil.isNotEmpty(beginTime)){
+            searchParams.put("beginTime",beginTime);
+        }
+        if(StringUtil.isNotEmpty(endTime)){
+            searchParams.put("endTime",endTime);
+        }
+
+        Page<PersonDeviceLog> page = personDeviceLogService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
+
+        msgResult.setResult(true);
+        msgResult.setData(PojoUtils.pageWrapper(page));
+
+        return msgResult;
+    }
+}

+ 65 - 6
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -1,6 +1,7 @@
 package com.jpsoft.smart.modules.base.controller;
 
 import com.github.pagehelper.Page;
+import com.github.pagehelper.util.StringUtil;
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
 import com.jpsoft.smart.modules.base.service.DeviceInfoService;
 import com.jpsoft.smart.modules.common.utils.PojoUtils;
@@ -50,12 +51,19 @@ public class PersonDeviceRelationController {
         MessageResult<PersonDeviceRelation> msgResult = new MessageResult<>();
 
         try {
-            personDeviceRelation.setId(UUID.randomUUID().toString());
-            personDeviceRelation.setDelFlag(false);
-            personDeviceRelation.setCreateBy(subject);
-            personDeviceRelation.setCreateTime(new Date());
-            
-            int affectCount = personDeviceRelationService.insert(personDeviceRelation);
+            int affectCount = 0;
+
+            PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(personDeviceRelation.getDeviceId(),personDeviceRelation.getPersonId());
+
+            if(item == null) {
+
+                personDeviceRelation.setId(UUID.randomUUID().toString());
+                personDeviceRelation.setDelFlag(false);
+                personDeviceRelation.setCreateBy(subject);
+                personDeviceRelation.setCreateTime(new Date());
+
+                affectCount = personDeviceRelationService.insert(personDeviceRelation);
+            }
 
             if (affectCount > 0) {
                 msgResult.setResult(true);
@@ -75,6 +83,57 @@ public class PersonDeviceRelationController {
         return msgResult;
     }
 
+
+    @ApiOperation(value="人员与设备批量绑定")
+    @PostMapping("batchBindDevice")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "personId",value = "人员ID", required = true,paramType = "query"),
+            @ApiImplicitParam(name = "devices",value = "设备ID(多个设备)", required = true, paramType = "query")
+    })
+    public MessageResult<Integer> batchBindDevice(Long personId,String devices,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+        int affectCount = 0;
+
+        try {
+            if(StringUtil.isNotEmpty(devices)){
+               String[] deviceArray = devices.split(",");
+
+               for (String deviceId:deviceArray) {
+
+                   PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(deviceId,personId);
+
+                   if(item == null) {
+                       item = new PersonDeviceRelation();
+                       item.setId(UUID.randomUUID().toString());
+                       item.setDeviceId(deviceId);
+                       item.setPersonId(personId);
+                       item.setDelFlag(false);
+                       item.setCreateBy(subject);
+                       item.setCreateTime(new Date());
+
+                       affectCount += personDeviceRelationService.insert(item);
+                   }
+               }
+            }
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库添加失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
     @ApiOperation(value="获取人员和设备绑定信息")
     @GetMapping("edit/{id}")
     public MessageResult<PersonDeviceRelation> edit(@PathVariable("id") String id){