xiao547607 há 5 anos atrás
pai
commit
6b454c6db1

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

@@ -18,6 +18,8 @@ public interface CompanyDeviceRelationDAO {
 	List<CompanyDeviceRelation> list();
 	List<CompanyDeviceRelation> search(Map<String,Object> searchParams,List<Sort> sortList);
     List<DeviceInfo> findDeviceByCompanyId(String companyId);
+	CompanyDeviceRelation findByCompanyIdAndDeviceId(String companyId, String deviceId);
+	List<CompanyDeviceRelation> findByCompanyId(String companyId);
 	int deleteByCompanyId(String companyId);
     int deleteByCompanyIdAndDeviceId(String companyId, String deviceId);
 }

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

@@ -13,6 +13,8 @@ public interface PersonCompanyDAO {
 	int exist(String id);
 	PersonCompany get(String id);
 	int delete(String id);
+    int deleteByPersonId(Long personId);
+	List<PersonCompany> findByPersonId(Long personId);
 	List<PersonCompany> list();
 	List<PersonCompany> search(Map<String,Object> searchParams,List<Sort> sortList);
 }

+ 7 - 1
common/src/main/java/com/jpsoft/smart/modules/base/entity/CompanyDeviceRelation.java

@@ -58,6 +58,12 @@ public class CompanyDeviceRelation {
 	/**
 	 *是否删除
 	 */
-        @ApiModelProperty(value = "是否删除")
+	@ApiModelProperty(value = "是否删除")
 	private Boolean delFlag;
+
+	/**
+	 *人脸库ID
+	 */
+	@ApiModelProperty(value = "人脸库ID")
+	private String libraryId;
 }

+ 3 - 0
common/src/main/java/com/jpsoft/smart/modules/base/entity/PersonInfo.java

@@ -146,4 +146,7 @@ public class PersonInfo {
     private BigDecimal lastTemperatureLog;
 
     private Boolean isNormal;
+
+    @ApiModelProperty(value="子公司ID")
+    private String personCompany;
 }

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

@@ -16,6 +16,8 @@ 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);
+	CompanyDeviceRelation findByCompanyIdAndDeviceId(String companyId, String deviceId);
+	List<CompanyDeviceRelation> findByCompanyId(String companyId);
 	int deleteByCompanyId(String companyId);
     int deleteByCompanyIdAndDeviceId(String companyId, String deviceId);
 }

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

@@ -12,6 +12,8 @@ public interface PersonCompanyService {
 	int insert(PersonCompany model);
 	int update(PersonCompany model);
 	int delete(String id);
+    int deleteByPersonId(Long personId);
+	List<PersonCompany> findByPersonId(Long personId);
 	List<PersonCompany> list();
 	Page<PersonCompany> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
 }

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

@@ -74,6 +74,16 @@ public class CompanyDeviceRelationServiceImpl implements CompanyDeviceRelationSe
 		return companyDeviceRelationDAO.findDeviceByCompanyId(companyId);
 	}
 
+	@Override
+	public CompanyDeviceRelation findByCompanyIdAndDeviceId(String companyId, String deviceId){
+		return companyDeviceRelationDAO.findByCompanyIdAndDeviceId(companyId,deviceId);
+	}
+
+	@Override
+	public List<CompanyDeviceRelation> findByCompanyId(String companyId){
+		return companyDeviceRelationDAO.findByCompanyId(companyId);
+	}
+
 	@Override
 	public int deleteByCompanyId(String companyId) {
 		return companyDeviceRelationDAO.deleteByCompanyId(companyId);

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

@@ -45,6 +45,11 @@ public class PersonCompanyServiceImpl implements PersonCompanyService {
 		return personCompanyDAO.delete(id);
 	}
 
+    @Override
+    public int deleteByPersonId(Long personId){
+        return personCompanyDAO.deleteByPersonId(personId);
+    }
+
 	@Override
 	public boolean exist(String id) {
 		// TODO Auto-generated method stub
@@ -52,6 +57,11 @@ public class PersonCompanyServiceImpl implements PersonCompanyService {
 		
 		return count > 0 ? true : false;
 	}
+
+	@Override
+	public List<PersonCompany> findByPersonId(Long personId){
+		return personCompanyDAO.findByPersonId(personId);
+	}
 	
 	@Override
 	public List<PersonCompany> list() {

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

@@ -12,6 +12,7 @@
         <result property="updateBy" column="update_by"/>
         <result property="updateTime" column="update_time"/>
         <result property="delFlag" column="del_flag"/>
+        <result property="libraryId" column="library_id"/>
     </resultMap>
     <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.CompanyDeviceRelation">
         <!--
@@ -21,7 +22,7 @@
         -->
         <![CDATA[
 		insert into base_company_device_relation
-	    (id_,company_id,device_id,create_by,create_time,update_by,update_time,del_flag)
+	    (id_,company_id,device_id,create_by,create_time,update_by,update_time,del_flag,library_id)
 		values
 		(
 			#{id,jdbcType=VARCHAR}
@@ -32,6 +33,7 @@
 			,#{updateBy,jdbcType=VARCHAR}
 			,#{updateTime,jdbcType= TIMESTAMP }
 			,#{delFlag,jdbcType= NUMERIC }
+			,#{libraryId,jdbcType=VARCHAR}
 		)
 	]]>
     </insert>
@@ -69,6 +71,9 @@
             <if test="delFlag!=null">
                 del_flag=#{delFlag,jdbcType= NUMERIC },
             </if>
+            <if test="libraryId!=null">
+                library_id=#{libraryId,jdbcType= VARCHAR },
+            </if>
         </set>
         where id_=#{id}
     </update>
@@ -100,4 +105,15 @@
         select b.* from base_company_device_relation a,base_device_info b
         where a.device_id=b.id_ and a.company_id=#{0} order by b.create_time asc
     </select>
+
+    <select id="findByCompanyIdAndDeviceId" parameterType="string" resultMap="CompanyDeviceRelationMap">
+        select * from base_company_device_relation
+        where device_id=#{deviceId} and company_id=#{companyId}
+    </select>
+
+    <select id="findByCompanyId" parameterType="string" resultMap="CompanyDeviceRelationMap">
+        select * from base_company_device_relation
+        where company_id=#{companyId}
+    </select>
+
 </mapper>

+ 9 - 0
common/src/main/resources/mapper/base/PersonCompany.xml

@@ -92,4 +92,13 @@ id_,person_id,company_id,del_flag,create_by,create_time,update_by,update_time		f
 	        ${sort.name} ${sort.order}
 	 	</foreach>
 	</select>
+	<select id="findByPersonId" resultMap="PersonCompanyMap" parameterType="long">
+		select * from base_person_company where del_flag =0 and person_id=#{personId}
+	</select>
+
+	<update id="deleteByPersonId" parameterType="long">
+		update base_person_company
+		set del_flag = 1
+		where person_id = #{personId}
+	</update>
 </mapper>

+ 41 - 4
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -7,6 +7,8 @@ import com.jpsoft.smart.modules.base.service.*;
 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.lapi.service.ILapiService;
+import com.jpsoft.smart.modules.lapi.vo.LapiResult;
 import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.UserService;
 import com.rabbitmq.client.AMQP;
@@ -52,6 +54,9 @@ public class CompanyInfoController {
     @Autowired
     private DeviceInfoService deviceInfoService;
 
+    @Autowired
+    private ILapiService lapiService;
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<CompanyInfoDTO> create(){
@@ -235,6 +240,15 @@ public class CompanyInfoController {
             }
             map.put("companyPosition",companyPosition);
 
+            //更新设备人脸库
+            //查询公司绑定的设备
+            List<CompanyDeviceRelation> relations = companyDeviceRelationService.findByCompanyId(companyInfoDTO.getId());
+            for(CompanyDeviceRelation relation : relations) {
+                //修改不捕获异常,发送请求就行
+                lapiService.updateCompanyLib(relation.getCompanyId(), relation.getDeviceId(),relation.getLibraryId());
+            }
+
+
             if (affectCount > 0) {
                 msgResult.setResult(true);
                 msgResult.setData(map);
@@ -461,7 +475,7 @@ public class CompanyInfoController {
             String[] arr = deviceIds.split(",");
 
 //            companyDeviceRelationService.deleteByCompanyId(companyId);
-
+            String libraryId = "";
             for (String deviceId : arr) {
                 CompanyDeviceRelation cdr = new CompanyDeviceRelation();
                 cdr.setId(UUID.randomUUID().toString());
@@ -471,6 +485,21 @@ public class CompanyInfoController {
                 cdr.setCreateBy(subject);
                 cdr.setCreateTime(new Date());
 
+                //设备添加人脸库
+                List<LapiResult> lapiResults= lapiService.addCompanyLib(companyId,deviceId);
+                for (int i = 0; i < lapiResults.size(); i++) {
+                    LapiResult lapiResult = lapiResults.get(i);
+
+                    if (lapiResult.isSuccess()) {
+                        //默认人脸库ID defaultFaceLibraryId
+                        //LibraryId
+                        HashMap dataMap = (HashMap) lapiResult.getData();
+                        libraryId = dataMap.get("LibraryId").toString();
+                        System.out.println("LibraryId=============" + libraryId);
+                    }
+                }
+
+                cdr.setLibraryId(libraryId);
                 companyDeviceRelationService.insert(cdr);
             }
 
@@ -489,16 +518,24 @@ public class CompanyInfoController {
 
     @Transactional(rollbackFor = Exception.class)
     @PostMapping("unbindDevice")
-    public MessageResult<String> unbindDevice(String companyId,String deviceIds,@ModelAttribute String subject){
+    public MessageResult<String> unbindDevice(String companyId,String deviceIds,@ModelAttribute String subject) {
         MessageResult<String> messageResult = new MessageResult<>();
 
         try {
             String[] arr = deviceIds.split(",");
 
             for (String deviceId : arr) {
-                companyDeviceRelationService.deleteByCompanyIdAndDeviceId(companyId,deviceId);
+                //companyDeviceRelationService.deleteByCompanyIdAndDeviceId(companyId,deviceId);
+                CompanyDeviceRelation companyDeviceRelation = companyDeviceRelationService.findByCompanyIdAndDeviceId(companyId, deviceId);
+                if (companyDeviceRelation != null) {
+                    //设备添加人脸库
+                    LapiResult lapiResult = lapiService.deleteCompanyLib(deviceId, companyDeviceRelation.getLibraryId());
+                    if (lapiResult.isSuccess()) {
+                        //删除成功
+                        companyDeviceRelationService.deleteByCompanyIdAndDeviceId(companyId, deviceId);
+                    }
+                }
             }
-
             messageResult.setResult(true);
         }
         catch (Exception ex){

+ 66 - 1
web/src/main/java/com/jpsoft/smart/modules/base/controller/DeviceInfoController.java

@@ -1,13 +1,19 @@
 package com.jpsoft.smart.modules.base.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.modules.base.entity.AlarmInfo;
+import com.jpsoft.smart.modules.base.entity.CompanyDeviceRelation;
+import com.jpsoft.smart.modules.base.service.CompanyDeviceRelationService;
 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.DeviceInfo;
 import com.jpsoft.smart.modules.base.service.DeviceInfoService;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
+import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
+import com.jpsoft.smart.modules.lapi.vo.LapiResult;
 import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.DataDictionaryService;
 import com.jpsoft.smart.modules.sys.service.UserService;
@@ -16,9 +22,13 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
 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;
@@ -43,7 +53,13 @@ public class DeviceInfoController {
     @Autowired
     private UserService userService;
 
+    @Autowired
+    private CompanyDeviceRelationService companyDeviceRelationService;
+
+
+
     @ApiOperation(value="添加设备")
+    @Transactional(rollbackFor = Exception.class)
     @PostMapping("add")
     public MessageResult<DeviceInfo> add(@RequestBody DeviceInfo deviceInfo,@RequestAttribute String subject){
         MessageResult<DeviceInfo> msgResult = new MessageResult<>();
@@ -60,6 +76,34 @@ public class DeviceInfoController {
 
                 int affectCount = deviceInfoService.insert(deviceInfo);
 
+                //设备添加人脸库
+                List<LapiResult> lapiResults= lapiService.addCompanyLib(deviceInfo.getCompanyId(),deviceInfo.getId());
+                for (int i = 0; i < lapiResults.size(); i++) {
+                    LapiResult lapiResult = lapiResults.get(i);
+
+                    if (lapiResult.isSuccess()) {
+                        //默认人脸库ID defaultFaceLibraryId
+                        //LibraryId
+                        //LibraryId -> 1585025356
+                        HashMap dataMap = (HashMap) lapiResult.getData();
+                        String libraryId = dataMap.get("LibraryId").toString();
+                        System.out.println("LibraryId=============" + libraryId);
+
+                        //添加信息到设备与公司关联表
+                        //先查关联表是否存在数据
+                        CompanyDeviceRelation companyDeviceRelation = companyDeviceRelationService.findByCompanyIdAndDeviceId(deviceInfo.getCompanyId(),deviceInfo.getId());
+                        if(companyDeviceRelation == null ){
+                            companyDeviceRelation = new CompanyDeviceRelation();
+                            companyDeviceRelation.setId(UUID.randomUUID().toString());
+                        }
+                        companyDeviceRelation.setCompanyId(deviceInfo.getCompanyId());
+                        companyDeviceRelation.setDeviceId(deviceInfo.getId());
+                        //保存人脸库ID
+                        companyDeviceRelation.setLibraryId(libraryId);
+                        companyDeviceRelationService.insert(companyDeviceRelation);
+                    }
+                }
+
                 if (affectCount > 0) {
                     msgResult.setResult(true);
                     msgResult.setData(deviceInfo);
@@ -74,6 +118,7 @@ public class DeviceInfoController {
             }
         }
         catch(Exception ex){
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             logger.error(ex.getMessage(),ex);
             msgResult.setResult(false);
             msgResult.setMessage(ex.getMessage());
@@ -172,10 +217,30 @@ public class DeviceInfoController {
 
         try {
             DeviceInfo deviceInfo = deviceInfoService.get(id);
+//            //删除所有设备人脸库
+              //清除人脸数据
+              //危险操作
+//            List<LapiResult> lapiResults= lapiService.deleteDeviceAllCompanyLib(id);
+//            for (int i = 0; i < lapiResults.size(); i++) {
+//                LapiResult lapiResult = lapiResults.get(i);
+//                if (lapiResult.isSuccess()) {
+//                    Object obj = lapiResult.getData();
+//                    //默认人脸库ID defaultFaceLibraryId
+//                    //LibraryId
+//                    //LibraryId -> 1585025356
+//
+//                    //设备上的人脸库删除成功后
+//                    //执行删除设备
+//                    deviceInfo.setDelFlag(true);
+//                    deviceInfo.setUpdateBy(subject);
+//                    deviceInfo.setUpdateTime(new Date());
+//                    affectCount = deviceInfoService.update(deviceInfo);
+//                }
+//            }
+
             deviceInfo.setDelFlag(true);
             deviceInfo.setUpdateBy(subject);
             deviceInfo.setUpdateTime(new Date());
-
             int affectCount = deviceInfoService.update(deviceInfo);
 
             if (affectCount > 0) {

+ 50 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -4,8 +4,10 @@ import com.github.pagehelper.Page;
 import com.jpsoft.smart.config.OSSConfig;
 import com.jpsoft.smart.modules.base.dto.PersonInfoDTO;
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
+import com.jpsoft.smart.modules.base.entity.PersonCompany;
 import com.jpsoft.smart.modules.base.entity.PersonDeviceRelation;
 import com.jpsoft.smart.modules.base.service.DeviceInfoService;
+import com.jpsoft.smart.modules.base.service.PersonCompanyService;
 import com.jpsoft.smart.modules.base.service.PersonDeviceRelationService;
 import com.jpsoft.smart.modules.common.utils.CheckIdCard;
 import com.jpsoft.smart.modules.common.utils.OSSUtil;
@@ -62,6 +64,8 @@ public class PersonInfoController {
     private PersonDeviceRelationService personDeviceRelationService;
     @Autowired
     private DeviceInfoService deviceInfoService;
+    @Autowired
+    private PersonCompanyService personCompanyService;
 
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
@@ -129,6 +133,23 @@ public class PersonInfoController {
             int affectCount = personInfoService.insert(personInfo);
 
             if (affectCount > 0) {
+                String personCompany = personInfo.getPersonCompany();
+                String[] pcs = personCompany.split(",");
+                PersonCompany classPersonCompany = null;
+                //查找新创建用户ID
+                personInfo = personInfoService.findByNameAndPhone(personInfo.getName(), personInfo.getPhone());
+                for(String pc : pcs){
+                    //添加
+                    classPersonCompany = new PersonCompany();
+                    classPersonCompany.setId(UUID.randomUUID().toString());
+                    classPersonCompany.setCompanyId(pc);
+                    classPersonCompany.setPersonId(personInfo.getId());
+                    classPersonCompany.setDelFlag(false);
+                    classPersonCompany.setCreateBy(subject);
+                    classPersonCompany.setCreateTime(new Date());
+                    personCompanyService.insert(classPersonCompany);
+                }
+
                 msgResult.setResult(true);
                 msgResult.setData(personInfo);
             } else {
@@ -155,6 +176,17 @@ public class PersonInfoController {
             PersonInfo personInfo = personInfoService.get(id);
 
             if (personInfo != null) {
+
+                //查询用户关联子公司表
+                List<PersonCompany> personCompanyList = personCompanyService.findByPersonId(id);
+                String pc = "";
+                for(PersonCompany personCompany : personCompanyList){
+                    pc += personCompany.getCompanyId() + ",";
+                }
+                if(pc.length() > 0) {
+                    pc = pc.substring(0, pc.length() - 1);
+                }
+                personInfo.setPersonCompany(pc);
                 msgResult.setResult(true);
                 msgResult.setData(personInfo);
             } else {
@@ -184,6 +216,24 @@ public class PersonInfoController {
 
             int affectCount = personInfoService.update(personInfo);
 
+            String personCompany = personInfo.getPersonCompany();
+            String[] pcs = personCompany.split(",");
+            //删除
+            personCompanyService.deleteByPersonId(personInfo.getId());
+            PersonCompany classPersonCompany = null;
+            for(String pc : pcs){
+                //添加
+                classPersonCompany = new PersonCompany();
+                classPersonCompany.setId(UUID.randomUUID().toString());
+                classPersonCompany.setCompanyId(pc);
+                classPersonCompany.setPersonId(personInfo.getId());
+                classPersonCompany.setDelFlag(false);
+                classPersonCompany.setCreateBy(subject);
+                classPersonCompany.setCreateTime(new Date());
+                personCompanyService.insert(classPersonCompany);
+            }
+
+
             if (affectCount > 0) {
                 msgResult.setResult(true);
                 msgResult.setData(personInfo);