Kaynağa Gözat

导入带图像

suntianwu 3 yıl önce
ebeveyn
işleme
65e6117d9e

+ 24 - 1
src/main/java/com/iden/bms/controller/CrowdController.java

@@ -3,6 +3,7 @@ package com.iden.bms.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.iden.bms.service.CrowdService;
+import com.iden.bms.service.PersonService;
 import com.iden.common.annotation.Permission;
 import com.iden.common.exception.BDException;
 import com.iden.common.logaspect.LogAnnotation;
@@ -20,6 +21,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.List;
@@ -38,6 +40,8 @@ public class CrowdController {
 
     @Autowired
     private CrowdService crowdService;
+    @Autowired
+    private PersonService personService;
 
     @GetMapping("/listCrowd")
     @ApiOperation(value = "人群列表分页 ")
@@ -61,6 +65,23 @@ public class CrowdController {
         }
     }
 
+
+    @ApiOperation(value = "导入Excel")
+    @PostMapping(value = "/importWithExcel",  headers = "content-type=multipart/form-data")
+    public Result<List<Long>> importWithExcel( @RequestHeader(name = "token") String token,
+                                           @RequestParam(value = "file") MultipartFile multipartFile) {
+        try {
+            List<Long>  personIdList = personService.importWithExcel(multipartFile);
+            return  Result.success("导入成功!",personIdList);
+        } catch (BDException e) {
+            log.error("导入人员列表出现异常",e);
+            return Result.error(e.getMessage());
+        } catch (Exception e) {
+            log.error("人员管理: 导入人员列表出现异常",e);
+            return Result.error("导入人员失败!");
+        }
+    }
+
     @PostMapping("/addCrowd")
     @ApiOperation(value = "新增人群")
     @LogAnnotation(
@@ -78,7 +99,9 @@ public class CrowdController {
                 return  Result.error("名称已存在!");
             }  if (flag == 2) {
                 return  Result.error("编码已存在!");
-            }  else if (flag == 0) {
+            } if (flag == 3) {
+                return  Result.error("人员列表不能为空!");
+            } else if (flag == 0) {
                 return  Result.success("新增成功!");
             } else {
                 return  Result.error("新增失败!");

+ 36 - 1
src/main/java/com/iden/bms/service/CrowdService.java

@@ -9,7 +9,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.iden.common.entity.IdenCrowd;
+import com.iden.common.entity.IdenPersonCrowdRef;
 import com.iden.common.service.IdenCrowdService;
+import com.iden.common.service.IdenPersonCrowdRefService;
 import com.iden.common.util.MyBeanUtils;
 import com.iden.common.vo.CrowdVO;
 import com.iden.common.vo.PageReqVO;
@@ -33,7 +35,8 @@ public class CrowdService {
 
     @Resource
     private IdenCrowdService idenCrowdService;
-
+    @Resource
+    private IdenPersonCrowdRefService idenPersonCrowdRefService;
     
 
     /**
@@ -101,12 +104,29 @@ public class CrowdService {
         if(idenCrowdService.count(queryWrapper2) > 0){
             return 2;
         }
+        List<Long> personIdList = vo.getPersonIdList();
+        if(CollUtil.isEmpty(personIdList)){
+            return 3;
+        }
+
         //保存人群
         IdenCrowd idenCrowd = new IdenCrowd();
         BeanUtil.copyProperties(vo,idenCrowd);
         idenCrowd.setCreateTime(new Date());
 
         this.idenCrowdService.save(idenCrowd);
+
+        List<IdenPersonCrowdRef> idenPersonCrowdRefList = new ArrayList<>();
+        for(Long personId : personIdList){
+            IdenPersonCrowdRef idenPersonCrowdRef = new IdenPersonCrowdRef();
+            idenPersonCrowdRef.setCrowdId(idenCrowd.getId());
+            idenPersonCrowdRef.setPersonId(personId);
+            idenPersonCrowdRefList.add(idenPersonCrowdRef);
+        }
+        if(CollUtil.isNotEmpty(idenPersonCrowdRefList)){
+            //批量保存
+            this.idenPersonCrowdRefService.saveBatch(idenPersonCrowdRefList);
+        }
         return 0;
     }
 
@@ -122,6 +142,21 @@ public class CrowdService {
         idenCrowd.setModifyTime(new Date());
         this.idenCrowdService.updateById(idenCrowd);
 
+        List<Long> personIdList = vo.getPersonIdList();
+        if(CollUtil.isNotEmpty(personIdList)){
+            List<IdenPersonCrowdRef> idenPersonCrowdRefList = new ArrayList<>();
+            for(Long personId : personIdList){
+                IdenPersonCrowdRef idenPersonCrowdRef = new IdenPersonCrowdRef();
+                idenPersonCrowdRef.setCrowdId(idenCrowd.getId());
+                idenPersonCrowdRef.setPersonId(personId);
+                idenPersonCrowdRefList.add(idenPersonCrowdRef);
+            }
+            if(CollUtil.isNotEmpty(idenPersonCrowdRefList)){
+                //批量保存
+                this.idenPersonCrowdRefService.saveBatch(idenPersonCrowdRefList);
+            }
+        }
+
     }
 
 }

+ 6 - 3
src/main/java/com/iden/bms/service/PersonService.java

@@ -269,7 +269,8 @@ public class PersonService {
      * @throws Exception
      */
     @Transactional(rollbackFor = Exception.class)
-    public void importWithExcel(MultipartFile file) throws BDException {
+    public List<Long> importWithExcel(MultipartFile file) throws BDException {
+        List<Long> personIdList = new ArrayList<>();
             try {
 
                 //图片对应的行和图片数据
@@ -480,6 +481,7 @@ public class PersonService {
                         BeanUtil.copyProperties(item,idenPerson);
                         idenPersonService.save(idenPerson);
 
+                        personIdList.add(idenPerson.getId());
                         List<Long> crowdIds = item.getCrowdIds();
                         if(CollUtil.isNotEmpty(crowdIds)){
                             crowdIds.forEach(item1 ->{
@@ -495,6 +497,7 @@ public class PersonService {
                         //批量保存
                         this.idenPersonCrowdRefService.saveBatch(idenPersonCrowdRefList);
                     }
+
                 }
 
             } catch (Exception e) {
@@ -502,8 +505,8 @@ public class PersonService {
                 e.printStackTrace();
                 throw new BDException("导入异常:" + e.getMessage());
             }
-
-        }
+            return personIdList;
+    }
 
     private void savePic( PictureData picData,String savePath) throws Exception {
         byte[] data = picData.getData();

+ 3 - 1
src/main/java/com/iden/common/vo/CrowdVO.java

@@ -7,6 +7,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 人群表(IdenCrowd)实体类
@@ -59,5 +60,6 @@ public class CrowdVO implements Serializable {
     @ApiModelProperty("modifyTime")
     private Date modifyTime;
 
-
+    @ApiModelProperty("人员ID列表")
+    private List<Long> personIdList;
 }