|
@@ -2,18 +2,30 @@ package com.iden.bms.service;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.iden.bms.face.FaceIdenService;
|
|
import com.iden.bms.face.FaceIdenTool;
|
|
import com.iden.bms.face.FaceIdenTool;
|
|
import com.iden.common.entity.IdenCommunity;
|
|
import com.iden.common.entity.IdenCommunity;
|
|
import com.iden.common.entity.IdenCrowd;
|
|
import com.iden.common.entity.IdenCrowd;
|
|
import com.iden.common.entity.IdenPerson;
|
|
import com.iden.common.entity.IdenPerson;
|
|
|
|
|
|
import com.iden.common.entity.IdenPersonCrowdRef;
|
|
import com.iden.common.entity.IdenPersonCrowdRef;
|
|
|
|
+import com.iden.common.enums.CredentialsTyoeEnum;
|
|
|
|
+import com.iden.common.enums.GenderEnum;
|
|
import com.iden.common.enums.PersonTypeEnum;
|
|
import com.iden.common.enums.PersonTypeEnum;
|
|
import com.iden.common.enums.PopulationTypeEnum;
|
|
import com.iden.common.enums.PopulationTypeEnum;
|
|
|
|
+import com.iden.common.exceltool.CommonExcelParse;
|
|
|
|
+import com.iden.common.exceltool.ExcelUtil;
|
|
|
|
+import com.iden.common.exceltool.IExcelParser;
|
|
|
|
+import com.iden.common.exceltool.MultipartFileToFile;
|
|
import com.iden.common.exception.BDException;
|
|
import com.iden.common.exception.BDException;
|
|
import com.iden.common.service.IdenCommunityService;
|
|
import com.iden.common.service.IdenCommunityService;
|
|
import com.iden.common.service.IdenCrowdService;
|
|
import com.iden.common.service.IdenCrowdService;
|
|
@@ -22,11 +34,15 @@ import com.iden.common.service.IdenPersonService;
|
|
import com.iden.common.util.DateUtils;
|
|
import com.iden.common.util.DateUtils;
|
|
import com.iden.common.util.ImgUtil;
|
|
import com.iden.common.util.ImgUtil;
|
|
import com.iden.common.util.MyBeanUtils;
|
|
import com.iden.common.util.MyBeanUtils;
|
|
-import com.iden.common.vo.PersonStaVO;
|
|
|
|
-import com.iden.common.vo.PersonVO;
|
|
|
|
-import com.iden.common.vo.PageReqVO;
|
|
|
|
-import com.iden.common.vo.UserLoginedConvertVO;
|
|
|
|
|
|
+import com.iden.common.vo.*;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
|
+import org.apache.poi.POIXMLDocumentPart;
|
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
|
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -34,8 +50,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.net.URL;
|
|
|
|
+import java.net.URLEncoder;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -61,6 +82,7 @@ public class PersonService {
|
|
@Value("${file.url:#{null}}")
|
|
@Value("${file.url:#{null}}")
|
|
private String fileUrl;
|
|
private String fileUrl;
|
|
|
|
|
|
|
|
+ private static final Logger logger = LogManager.getLogger(PersonService.class);
|
|
|
|
|
|
public PersonStaVO getPersonStaVO(String type, String nameOrCred, String district, String subdistrict, Long communityId, Long crowdId, String address, String gender, String populationType, UserLoginedConvertVO loginUser) {
|
|
public PersonStaVO getPersonStaVO(String type, String nameOrCred, String district, String subdistrict, Long communityId, Long crowdId, String address, String gender, String populationType, UserLoginedConvertVO loginUser) {
|
|
QueryWrapper<IdenPerson> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<IdenPerson> queryWrapper = new QueryWrapper<>();
|
|
@@ -142,7 +164,21 @@ public class PersonService {
|
|
BeanUtils.copyProperties(item,resVO);
|
|
BeanUtils.copyProperties(item,resVO);
|
|
resVO.setPopulationTypeName(PopulationTypeEnum.getValueToName(resVO.getPopulationType()));
|
|
resVO.setPopulationTypeName(PopulationTypeEnum.getValueToName(resVO.getPopulationType()));
|
|
resVO.setTypeName(PersonTypeEnum.getValueToName(resVO.getType()));
|
|
resVO.setTypeName(PersonTypeEnum.getValueToName(resVO.getType()));
|
|
|
|
+ resVO.setGenderName(GenderEnum.getValueToName(resVO.getGender()));
|
|
|
|
+ resVO.setCredentialsTyoeName(CredentialsTyoeEnum.getValueToName(resVO.getCredentialsTyoe()));
|
|
|
|
|
|
|
|
+ try {
|
|
|
|
+ resVO.setImageUrl(new URL(resVO.getImage()));
|
|
|
|
+ } catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ Long communityId1 = resVO.getCommunityId();
|
|
|
|
+ if(communityId1 != null){
|
|
|
|
+ IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId1);
|
|
|
|
+ if(idenCommunity != null) {
|
|
|
|
+ resVO.setCommunityName(idenCommunity.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
QueryWrapper<IdenPersonCrowdRef> queryWrapper1 = new QueryWrapper<>();
|
|
QueryWrapper<IdenPersonCrowdRef> queryWrapper1 = new QueryWrapper<>();
|
|
queryWrapper1.lambda().eq(IdenPersonCrowdRef::getPersonId,resVO.getId());
|
|
queryWrapper1.lambda().eq(IdenPersonCrowdRef::getPersonId,resVO.getId());
|
|
List<IdenPersonCrowdRef> listIdenPersonCrowdRef = idenPersonCrowdRefService.list(queryWrapper1);
|
|
List<IdenPersonCrowdRef> listIdenPersonCrowdRef = idenPersonCrowdRefService.list(queryWrapper1);
|
|
@@ -167,6 +203,221 @@ public class PersonService {
|
|
return results;
|
|
return results;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void exportToExcel(String type, String nameOrCred, String district, String subdistrict, Long communityId, Long crowdId, String address, String gender, String populationType, UserLoginedConvertVO loginUser, HttpServletResponse response) throws Exception {
|
|
|
|
+ QueryWrapper<IdenPerson> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().like(IdenPerson::getType,type)
|
|
|
|
+ .like(StrUtil.isNotEmpty(address), IdenPerson::getAddress,address)
|
|
|
|
+ .eq(StrUtil.isNotEmpty(gender),IdenPerson::getGender,gender)
|
|
|
|
+ .eq(StrUtil.isNotEmpty(populationType),IdenPerson::getPopulationType,populationType)
|
|
|
|
+ .eq(StrUtil.isNotEmpty(district),IdenPerson::getDistrict,district)
|
|
|
|
+ .eq(StrUtil.isNotEmpty(subdistrict),IdenPerson::getSubdistrict,subdistrict)
|
|
|
|
+ .eq(communityId != null,IdenPerson::getCommunityId,communityId)
|
|
|
|
+ .and(StrUtil.isNotEmpty(nameOrCred),wrapper -> wrapper.like(IdenPerson::getName,nameOrCred)
|
|
|
|
+ .or().like(IdenPerson::getCredentialsCode,nameOrCred))
|
|
|
|
+ .orderByDesc(IdenPerson::getModifyTime)
|
|
|
|
+ .orderByDesc(IdenPerson::getCreateTime);
|
|
|
|
+
|
|
|
|
+ if (crowdId != null) {
|
|
|
|
+ queryWrapper.apply(" in ( select person_id from iden_person_crowd_ref ipcr where ipcr.crowd_id = "+ crowdId + ")");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<IdenPerson> list = this.idenPersonService.list(queryWrapper);
|
|
|
|
+ List<PersonVO> records = new ArrayList<>();
|
|
|
|
+ if (CollUtil.isNotEmpty(list)) {
|
|
|
|
+ list.forEach(item->{
|
|
|
|
+ PersonVO resVO = new PersonVO();
|
|
|
|
+ BeanUtils.copyProperties(item,resVO);
|
|
|
|
+ resVO.setPopulationTypeName(PopulationTypeEnum.getValueToName(resVO.getPopulationType()));
|
|
|
|
+ resVO.setTypeName(PersonTypeEnum.getValueToName(resVO.getType()));
|
|
|
|
+ resVO.setGenderName(GenderEnum.getValueToName(resVO.getGender()));
|
|
|
|
+ resVO.setCredentialsTyoeName(CredentialsTyoeEnum.getValueToName(resVO.getCredentialsTyoe()));
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ resVO.setImageUrl(new URL(resVO.getImage()));
|
|
|
|
+ } catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ Long communityId1 = resVO.getCommunityId();
|
|
|
|
+ if(communityId1 != null){
|
|
|
|
+ IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId1);
|
|
|
|
+ if(idenCommunity != null) {
|
|
|
|
+ resVO.setCommunityName(idenCommunity.getName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ QueryWrapper<IdenPersonCrowdRef> queryWrapper1 = new QueryWrapper<>();
|
|
|
|
+ queryWrapper1.lambda().eq(IdenPersonCrowdRef::getPersonId,resVO.getId());
|
|
|
|
+ List<IdenPersonCrowdRef> listIdenPersonCrowdRef = idenPersonCrowdRefService.list(queryWrapper1);
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ if (CollUtil.isNotEmpty(listIdenPersonCrowdRef)) {
|
|
|
|
+ for(IdenPersonCrowdRef idenPersonCrowdRef : listIdenPersonCrowdRef){
|
|
|
|
+ IdenCrowd idenCrowd = idenCrowdService.getById(idenPersonCrowdRef.getCrowdId());
|
|
|
|
+ if(idenCrowd != null) {
|
|
|
|
+ sb.append(idenCrowd.getName()).append(",");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String crowdName = sb.toString();
|
|
|
|
+ if(crowdName != null && crowdName.endsWith(",")) {
|
|
|
|
+ crowdName = crowdName.substring(0, crowdName.length() - 1);
|
|
|
|
+ }
|
|
|
|
+ resVO.setCrowdName(crowdName);
|
|
|
|
+ records.add(resVO);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ response.reset(); // 非常重要
|
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
+ final String fileName = URLEncoder.encode("人员表", "UTF-8");
|
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");
|
|
|
|
+
|
|
|
|
+ EasyExcel.write(response.getOutputStream(), PersonVO.class).sheet("人员表").doWrite(records);
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 导入
|
|
|
|
+ * @param file
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public void importWithExcel(MultipartFile file) throws BDException {
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ //上传的目录
|
|
|
|
+ String uploadSubDir = "data/final/person/image";
|
|
|
|
+
|
|
|
|
+ //图片对应的行和图片数据
|
|
|
|
+ Map<Integer, PictureData> sheetIndexPicMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ //图片对应的行和存放路径
|
|
|
|
+ Map<Integer, String> path = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ Sheet sheet = null;
|
|
|
|
+ if (file.getName().substring(file.getName().length() - 4).equals("xlsx")) {
|
|
|
|
+ XSSFWorkbook workBook = new XSSFWorkbook(file.getInputStream());
|
|
|
|
+ sheet = workBook.getSheetAt(0);
|
|
|
|
+
|
|
|
|
+ //读取sheet的图片放入Map
|
|
|
|
+ for (POIXMLDocumentPart dr : ((XSSFSheet) sheet).getRelations()) {
|
|
|
|
+ if (dr instanceof XSSFDrawing) {
|
|
|
|
+ XSSFDrawing drawing = (XSSFDrawing) dr;
|
|
|
|
+ List<XSSFShape> shapes = drawing.getShapes();
|
|
|
|
+ for (XSSFShape shape : shapes) {
|
|
|
|
+ XSSFPicture pic = (XSSFPicture) shape;
|
|
|
|
+ XSSFClientAnchor anchor = pic.getPreferredSize();
|
|
|
|
+ CTMarker ctMarker = anchor.getFrom();
|
|
|
|
+ sheetIndexPicMap.put(ctMarker.getRow(), pic.getPictureData());
|
|
|
|
+
|
|
|
|
+ //获取图片格式
|
|
|
|
+ String ext = pic.getPictureData().suggestFileExtension();
|
|
|
|
+ if(!"jpg".equalsIgnoreCase(ext)){
|
|
|
|
+ throw new BDException("Excel中只能放jpg格式图像");
|
|
|
|
+ }
|
|
|
|
+ //保存的文件名
|
|
|
|
+ String fileName = UUID.randomUUID().toString() + "." + ext;
|
|
|
|
+
|
|
|
|
+ path.put(ctMarker.getRow(), uploadSubDir + "/" + fileName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new BDException("导入Excel只支持xlsx格式");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (sheet.getLastRowNum() == 0) {
|
|
|
|
+ logger.error("表中无数据!");
|
|
|
|
+ throw new BDException("表中无数据");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //定义数据集合存放excel所有数据
|
|
|
|
+ List<IdenPerson> idenPersonList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ for (int i = 1; i <= sheet.getLastRowNum(); i++) {
|
|
|
|
+
|
|
|
|
+ //错误提示消息
|
|
|
|
+ StringBuffer msg = new StringBuffer();
|
|
|
|
+
|
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
|
+
|
|
|
|
+ if (null == row)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ IdenPerson idenPerson = new IdenPerson();
|
|
|
|
+
|
|
|
|
+ idenPerson.setImage(path.get(i));
|
|
|
|
+
|
|
|
|
+ for (int j = 0; j < 23; j++) {
|
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
|
+
|
|
|
|
+ String value = null;
|
|
|
|
+
|
|
|
|
+ if (null != cell) {
|
|
|
|
+ //全部作为文本处理
|
|
|
|
+ cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
|
+
|
|
|
|
+ value = cell.getStringCellValue();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (1 == j) {//姓名
|
|
|
|
+ if (StringUtils.isNotBlank(value)){
|
|
|
|
+ idenPerson.setName(value);
|
|
|
|
+ }else {
|
|
|
|
+ msg.append("请填写姓名!\n");
|
|
|
|
+ }
|
|
|
|
+ } else if (2 == j) {//备注
|
|
|
|
+ idenPerson.setRemark(value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!StringUtils.isBlank(msg.toString())) {
|
|
|
|
+ logger.error("第\t" + i + "行: " + msg.toString());
|
|
|
|
+ throw new BDException("第\\t" + i + "行: " + msg.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ idenPersonList.add(idenPerson);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!idenPersonList.isEmpty()) {
|
|
|
|
+
|
|
|
|
+ if (!sheetIndexPicMap.isEmpty()) {
|
|
|
|
+
|
|
|
|
+ for (Map.Entry<Integer, PictureData> map : sheetIndexPicMap.entrySet()) {
|
|
|
|
+
|
|
|
|
+ // 获取图片流
|
|
|
|
+ PictureData pic = map.getValue();
|
|
|
|
+
|
|
|
|
+ byte[] data = pic.getData();
|
|
|
|
+
|
|
|
|
+ //输出全路径
|
|
|
|
+ String outPath = idenRoot + path.get(map.getKey());
|
|
|
|
+
|
|
|
|
+ FileOutputStream out = new FileOutputStream(outPath);
|
|
|
|
+ out.write(data);
|
|
|
|
+ out.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //批量保存
|
|
|
|
+ this.idenPersonService.saveBatch(idenPersonList);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logger.error("导入异常", e);
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new BDException("导入异常:" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 删除人员
|
|
* 删除人员
|
|
* @param id
|
|
* @param id
|