xiao547607 5 years ago
parent
commit
372ebd0a66

+ 17 - 4
common/src/main/resources/mapper/base/MessageNotice.xml

@@ -92,12 +92,20 @@ id_,title_,content_,sender_id,recipient_id,status_,del_flag,create_by,create_tim
 	</select>
 	<select id="search" parameterType="hashmap" resultMap="MessageNoticeMap">
 		<![CDATA[
-			select * from base_message_notice
+			select * from base_message_notice a
+			LEFT JOIN base_message_notice_company b ON a.id_ = b.notice_id
+			LEFT JOIN base_company_info c ON b.company_id = c.id_
 		]]>
 		<where>
-			and del_flag = false
+			and a.del_flag = false
 			<if test="searchParams.title != null">
-				and title_ like #{searchParams.title}
+				and a.title_ like #{searchParams.title}
+			</if>
+			<if test="searchParams.companyId != null">
+				and b.company_id = #{searchParams.companyId}
+			</if>
+			<if test="searchParams.companyCode != null">
+				and c.code_ like #{searchParams.companyCode}
 			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
@@ -106,7 +114,9 @@ id_,title_,content_,sender_id,recipient_id,status_,del_flag,create_by,create_tim
 	</select>
 	<select id="searchShort" parameterType="hashmap" resultMap="MessageNoticeMap">
 		<![CDATA[
-			select a.id_,a.title_,a.create_time from base_message_notice a LEFT JOIN base_message_notice_company b ON a.id_ = b.notice_id
+			select a.id_,a.title_,a.create_time from base_message_notice a
+			LEFT JOIN base_message_notice_company b ON a.id_ = b.notice_id
+			LEFT JOIN base_company_info c ON b.company_id = c.id_
 		]]>
 		<where>
 			and a.del_flag = false
@@ -116,6 +126,9 @@ id_,title_,content_,sender_id,recipient_id,status_,del_flag,create_by,create_tim
 			<if test="searchParams.companyId != null">
 				and b.company_id like #{searchParams.companyId}
 			</if>
+			<if test="searchParams.companyCode != null">
+				and c.code_ like #{searchParams.companyCode}
+			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
 			${sort.name} ${sort.order}

+ 31 - 1
web/src/main/java/com/jpsoft/smart/modules/base/controller/MessageNoticeController.java

@@ -1,14 +1,18 @@
 package com.jpsoft.smart.modules.base.controller;
 
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.entity.MessageNoticeCompany;
 import com.jpsoft.smart.modules.base.entity.PersonCompany;
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
 import com.jpsoft.smart.modules.base.service.MessageNoticeCompanyService;
 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.MessageNotice;
 import com.jpsoft.smart.modules.base.service.MessageNoticeService;
+import com.jpsoft.smart.modules.sys.entity.User;
+import com.jpsoft.smart.modules.sys.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
@@ -33,6 +37,13 @@ public class MessageNoticeController {
     @Autowired
     private MessageNoticeCompanyService messageNoticeCompanyService;
 
+    @Autowired
+    private CompanyInfoService companyInfoService;
+
+    @Autowired
+    private UserService userService;
+
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<MessageNotice> create(){
@@ -245,24 +256,43 @@ public class MessageNoticeController {
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
     public MessageResult<Map> pageList(
             String title,
+            String companyId,
+            String companyCode,
             @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
             @RequestParam(value="pageSize",defaultValue="20") int pageSize,
             @RequestAttribute String subject){
 
         //当前用户ID
         System.out.println(subject);
+        //当前用户ID
+        User user = userService.get(subject);
+
+        CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
 
         MessageResult<Map> msgResult = new MessageResult<>();
 
         Map<String,Object> searchParams = new HashMap<>();
 
         List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("create_time","desc"));
+        sortList.add(new Sort("a.create_time","desc"));
 
         if (StringUtils.isNotEmpty(title)) {
             searchParams.put("title","%" + title + "%");
         }
 
+        if (StringUtils.isNotEmpty(title)) {
+            searchParams.put("title","%" + title + "%");
+        }
+
+        if (StringUtils.isEmpty(companyCode)){
+            if (!userService.hasRole(subject,"SYSADMIN")) {
+                searchParams.put("companyCode", companyInfo.getCode() + "%");
+            }
+        }
+        else{
+            searchParams.put("companyCode", companyCode + "%");
+        }
+
         Page<MessageNotice> page = messageNoticeService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
 
         msgResult.setResult(true);

+ 130 - 37
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -93,13 +93,17 @@ public class PersonDeviceRelationController {
 
             if (affectCount > 0) {
                 //往设备库传输人脸信息
-                List<LapiMsgResult> lapiResults = lapiService.addPersonForDeviceIds(personDeviceRelation.getPersonId(),personDeviceRelation.getDeviceId());
-                for (int i = 0; i < lapiResults.size(); i++) {
-                    LapiMsgResult lapiMsgResult = lapiResults.get(i);
-                    if (lapiMsgResult.isSuccess()) {
-                        msgResult.setResult(true);
-                    }else{
-                        throw new Exception("添加失败:" + lapiMsgResult.getMsg());
+                PersonInfo personInfo = personInfoService.get(personDeviceRelation.getPersonId());
+                //如果人员照片不为空
+                if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())){
+                    List<LapiMsgResult> lapiResults = lapiService.addPersonForDeviceIds(personDeviceRelation.getPersonId(),personDeviceRelation.getDeviceId());
+                    for (int i = 0; i < lapiResults.size(); i++) {
+                        LapiMsgResult lapiMsgResult = lapiResults.get(i);
+                        if (lapiMsgResult.isSuccess()) {
+                            msgResult.setResult(true);
+                        }else{
+                            throw new Exception("添加失败:" + lapiMsgResult.getMsg());
+                        }
                     }
                 }
                 msgResult.setResult(true);
@@ -158,37 +162,40 @@ public class PersonDeviceRelationController {
                 //往设备库传输人脸信息
                 //批量操作
                 int addCount = 0;
-                List<LapiResult> lapiResults = lapiService.addPerson(personId);
-                for (int i = 0; i < lapiResults.size(); i++) {
-                    LapiResult lapiResult = lapiResults.get(i);
-                    if (lapiResult.isSuccess()) {
-                        msgResult.setResult(true);
-                    }else{
-
-                        PersonInfo personInfo = personInfoService.get(personId);
-                        String personName = "";
-                        if(personInfo != null){
-                            personName = personInfo.getName();
+                //往设备库传输人脸信息
+                PersonInfo personInfo = personInfoService.get(personId);
+                //如果人员照片不为空
+                if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())) {
+                    List<LapiResult> lapiResults = lapiService.addPerson(personId);
+                    for (int i = 0; i < lapiResults.size(); i++) {
+                        LapiResult lapiResult = lapiResults.get(i);
+                        if (lapiResult.isSuccess()) {
+                            msgResult.setResult(true);
+                        } else {
+                            String personName = "";
+                            if (personInfo != null) {
+                                personName = personInfo.getName();
+                            }
+                            Map resultMap = (Map) lapiResult.getData();
+                            HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
+                            HSSFCell cell1 = row.createCell(0);
+                            cell1.setCellValue(personName);
+                            HSSFCell cell2 = row.createCell(1);
+                            cell2.setCellValue(resultMap.get("deviceAliasName").toString());
+                            HSSFCell cell3 = row.createCell(2);
+                            cell3.setCellValue("添加失败:");
+                            HSSFCell cell4 = row.createCell(3);
+                            cell4.setCellValue(lapiResult.getMsg());
+
+                            //删除绑定关系
+                            PersonDeviceRelation personDeviceRelation = personDeviceRelationService.findByDeviceIdAndPersonId(resultMap.get("deviceId").toString(), personId);
+                            personDeviceRelation.setDelFlag(true);
+                            personDeviceRelation.setUpdateBy(subject);
+                            personDeviceRelation.setUpdateTime(new Date());
+
+                            personDeviceRelationService.update(personDeviceRelation);
+                            addCount++;
                         }
-                        Map resultMap = (Map)lapiResult.getData();
-                        HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
-                        HSSFCell cell1 = row.createCell(0);
-                        cell1.setCellValue(personName);
-                        HSSFCell cell2 = row.createCell(1);
-                        cell2.setCellValue(resultMap.get("deviceAliasName").toString());
-                        HSSFCell cell3 = row.createCell(2);
-                        cell3.setCellValue("添加失败:");
-                        HSSFCell cell4 = row.createCell(3);
-                        cell4.setCellValue(lapiResult.getMsg());
-
-                        //删除绑定关系
-                        PersonDeviceRelation personDeviceRelation = personDeviceRelationService.findByDeviceIdAndPersonId(resultMap.get("deviceId").toString(),personId);
-                        personDeviceRelation.setDelFlag(true);
-                        personDeviceRelation.setUpdateBy(subject);
-                        personDeviceRelation.setUpdateTime(new Date());
-
-                        personDeviceRelationService.update(personDeviceRelation);
-                        addCount ++;
                     }
                 }
 //
@@ -266,6 +273,13 @@ public class PersonDeviceRelationController {
                         affectCount += personDeviceRelationService.insert(item);
                         //往设备库传输人脸信息
                         //批量操作
+
+                        PersonInfo personInfo = personInfoService.get(personId);
+                        //如果人员照片为空
+                        if(StringUtils.isEmpty(personInfo.getFaceImageUrl())){
+                            continue;
+                        }
+
                         List<LapiMsgResult> lapiResults = lapiService.addPersonForDeviceIds(personId,deviceId);
 
                         for (int i = 0; i < lapiResults.size(); i++) {
@@ -327,6 +341,63 @@ public class PersonDeviceRelationController {
         return msgResult;
     }
 
+    @ApiOperation(value="多个人员与设备批量解除绑定")
+    @PostMapping("batchUnBindPerson")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "persons",value = "人员ID(多个人员)", required = true,paramType = "query"),
+            @ApiImplicitParam(name = "deviceId",value = "设备ID", required = true, paramType = "query")
+    })
+    public MessageResult<Integer> batchUnBindPerson(String persons,String deviceId,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+        int affectCount = 0;
+
+        try {
+            if(StringUtil.isNotEmpty(persons)){
+
+                String[] personArray = persons.split(",");
+
+                for (String strPersonId:personArray) {
+
+                    long personId = Long.parseLong(strPersonId);
+
+                    PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(deviceId,personId);
+
+                    if(item != null) {
+                        item.setDelFlag(true);
+                        item.setUpdateBy(subject);
+                        item.setUpdateTime(new Date());
+                        affectCount += personDeviceRelationService.update(item);
+                        //删除设备上的信息
+                        new Thread(()->{
+                            try {
+                                lapiService.deleteDevicePerson(personId,deviceId);
+                            }
+                            catch (Exception ex){
+                                logger.error(ex.getMessage(),ex);
+                            }
+                        }).start();
+                    }
+                }
+            }
+
+            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){
@@ -398,6 +469,16 @@ public class PersonDeviceRelationController {
             int affectCount = personDeviceRelationService.update(personDeviceRelation);
 
             if (affectCount > 0) {
+                //删除设备上的信息
+                new Thread(()->{
+                    try {
+                        lapiService.deleteDevicePerson(personDeviceRelation.getPersonId(),personDeviceRelation.getDeviceId());
+                    }
+                    catch (Exception ex){
+                        logger.error(ex.getMessage(),ex);
+                    }
+                }).start();
+
                 msgResult.setResult(true);
                 msgResult.setData(affectCount);
             } else {
@@ -435,6 +516,7 @@ public class PersonDeviceRelationController {
                 affectCount = personDeviceRelationService.update(personDeviceRelation);
             }
 
+
             if (affectCount > 0) {
                 msgResult.setResult(true);
                 msgResult.setData(affectCount);
@@ -549,6 +631,17 @@ public class PersonDeviceRelationController {
                 affectCount += personDeviceRelationService.update(personDeviceRelation);
             }
 
+
+            //删除所有设备上的信息
+            new Thread(()->{
+                try {
+                    lapiService.deletePerson(personId);
+                }
+                catch (Exception ex){
+                    logger.error(ex.getMessage(),ex);
+                }
+            }).start();
+
             if (affectCount > 0) {
                 msgResult.setResult(true);
                 msgResult.setData(affectCount);

+ 10 - 0
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/MessageNoticeApiController.java

@@ -1,9 +1,11 @@
 package com.jpsoft.smart.modules.mobile.controller;
 
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.entity.MessageNotice;
 import com.jpsoft.smart.modules.base.entity.MessageNoticeCompany;
 import com.jpsoft.smart.modules.base.entity.PersonInfo;
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
 import com.jpsoft.smart.modules.base.service.MessageNoticeService;
 import com.jpsoft.smart.modules.base.service.PersonInfoService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
@@ -31,6 +33,9 @@ public class MessageNoticeApiController {
     private MessageNoticeService messageNoticeService;
     @Autowired
     private PersonInfoService personInfoService;
+    @Autowired
+    private CompanyInfoService companyService;
+
 
     @ApiOperation(value="获取信息")
     @RequestMapping(value = "detail",method = RequestMethod.POST)
@@ -114,6 +119,11 @@ public class MessageNoticeApiController {
         List<Sort> sortList = new ArrayList<>();
         sortList.add(new Sort("create_time","desc"));
 
+        //获取公司CODE
+        CompanyInfo company = companyService.get(personInfo.getCompanyId());
+        //包含下级公司
+        searchParams.put("companyCode", company.getCode() + "%");
+
         Page<MessageNotice> page = messageNoticeService.pageSearchShort(searchParams,pageIndex,pageSize,true,sortList);
 
         msgResult.setResult(true);