|
|
@ -17,6 +17,10 @@ |
|
|
|
|
|
|
|
package com.elink.esua.epdc.modules.epidemic.service.impl; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.ExcelImportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams; |
|
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
@ -27,14 +31,14 @@ import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; |
|
|
|
import com.elink.esua.epdc.commons.tools.security.user.UserDetail; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.IdentityNoUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.*; |
|
|
|
import com.elink.esua.epdc.dto.PersonTestingDTO; |
|
|
|
import com.elink.esua.epdc.dto.PersonTestingPageDTO; |
|
|
|
import com.elink.esua.epdc.dto.UploadFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.result.EpdcPartyErroyResultDTO; |
|
|
|
import com.elink.esua.epdc.modules.epidemic.dao.PersonTestingDao; |
|
|
|
import com.elink.esua.epdc.modules.epidemic.entity.PersonTestingEntity; |
|
|
|
import com.elink.esua.epdc.modules.epidemic.excel.PersonTestingImportMoudleExcel; |
|
|
|
import com.elink.esua.epdc.modules.epidemic.feign.OssFeignClient; |
|
|
|
import com.elink.esua.epdc.modules.epidemic.redis.PersonTestingRedis; |
|
|
|
import com.elink.esua.epdc.modules.epidemic.service.PersonTestingService; |
|
|
@ -43,10 +47,19 @@ import com.elink.esua.epdc.vaccine.epidemic.entity.EpidemicUserInfoEntity; |
|
|
|
import com.elink.esua.epdc.vaccine.house.dao.PopulationInformationDao; |
|
|
|
import com.elink.esua.epdc.vaccine.house.entity.PopulationInformationEntity; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.hssf.usermodel.*; |
|
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
|
import org.apache.poi.ss.util.CellRangeAddressList; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.File; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
@ -385,5 +398,148 @@ public class PersonTestingServiceImpl extends BaseServiceImpl<PersonTestingDao, |
|
|
|
return age; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void exportExcelToTarget(HttpServletResponse response, String fileName, Collection<?> sourceList, |
|
|
|
Class<PersonTestingImportMoudleExcel> targetClass) throws Exception { |
|
|
|
List<Object> targetList = new ArrayList<>(sourceList.size()); |
|
|
|
for (Object source : sourceList) { |
|
|
|
Object target = targetClass.newInstance(); |
|
|
|
BeanUtils.copyProperties(source, target); |
|
|
|
targetList.add(target); |
|
|
|
} |
|
|
|
|
|
|
|
ExportParams exportParams = new ExportParams(); |
|
|
|
exportParams.setSheetName(fileName); |
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, targetClass, targetList); |
|
|
|
|
|
|
|
Sheet sheet1 = packageSheet(workbook); |
|
|
|
|
|
|
|
try { |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
|
|
|
response.setHeader("Content-Disposition", |
|
|
|
"attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xls"); |
|
|
|
ServletOutputStream out = response.getOutputStream(); |
|
|
|
workbook.write(out); |
|
|
|
out.flush(); |
|
|
|
out.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 设置Sheet页 格式及数据 |
|
|
|
* |
|
|
|
* @param workbook |
|
|
|
* @return org.apache.poi.ss.usermodel.Sheet |
|
|
|
* @Author zhangyong |
|
|
|
* @Date 14:53 2021-05-12 |
|
|
|
**/ |
|
|
|
public Sheet packageSheet(Workbook workbook) { |
|
|
|
Sheet sheet = workbook.getSheetAt(NumConstant.ZERO); |
|
|
|
sheet.setDefaultColumnWidth(1220 * 1256); |
|
|
|
sheet.setDefaultRowHeight((short)(2 * 256)); |
|
|
|
|
|
|
|
CellStyle style = workbook.createCellStyle(); |
|
|
|
DataFormat excelFormat = workbook.createDataFormat(); |
|
|
|
// 设置居中
|
|
|
|
style.setAlignment(HorizontalAlignment.CENTER); |
|
|
|
//自动换行
|
|
|
|
style.setWrapText(true); |
|
|
|
//文本格式
|
|
|
|
style.setDataFormat(excelFormat.getFormat("@")); |
|
|
|
sheet.setDefaultColumnStyle(NumConstant.ZERO, style); |
|
|
|
sheet.setDefaultColumnStyle(NumConstant.ONE, style); |
|
|
|
sheet.setDefaultColumnStyle(NumConstant.TWO, style); |
|
|
|
sheet.setDefaultColumnStyle(NumConstant.THREE, style); |
|
|
|
sheet.setDefaultColumnStyle(NumConstant.FOUR, style); |
|
|
|
return sheet; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result importExcel(MultipartFile file) { |
|
|
|
File f = StreamUtils.conversionFile(file); |
|
|
|
ImportParams importParams = new ImportParams(); |
|
|
|
|
|
|
|
List<PersonTestingImportMoudleExcel> excelList = ExcelImportUtil.importExcel(f, PersonTestingImportMoudleExcel.class, importParams); |
|
|
|
// 校验数据
|
|
|
|
List<EpdcPartyErroyResultDTO> erroys = this.checkExcel(excelList); |
|
|
|
if (erroys.size() > NumConstant.ZERO) { |
|
|
|
return new Result().ok(erroys); |
|
|
|
} |
|
|
|
saveList(excelList); |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装异常信息 |
|
|
|
* |
|
|
|
* @param errorline 异常列 |
|
|
|
* @param errorDescribe 异常描述 |
|
|
|
* @return com.elink.esua.epdc.dto.epdc.result.EpdcPartyErroyResultDTO |
|
|
|
* @Author zhangyong |
|
|
|
* @Date 15:40 2021-11-04 |
|
|
|
**/ |
|
|
|
private EpdcPartyErroyResultDTO packageErrorInfo(int errorline, String errorDescribe) { |
|
|
|
EpdcPartyErroyResultDTO errorLineinfoDto = new EpdcPartyErroyResultDTO(); |
|
|
|
errorLineinfoDto.setErroLine((errorline + NumConstant.TWO) + ""); |
|
|
|
errorLineinfoDto.setErrorInfo(errorDescribe); |
|
|
|
return errorLineinfoDto; |
|
|
|
} |
|
|
|
|
|
|
|
private List<EpdcPartyErroyResultDTO> checkExcel(List<PersonTestingImportMoudleExcel> excelList) { |
|
|
|
// 不匹配信息
|
|
|
|
List<EpdcPartyErroyResultDTO> errorLineinfoList = new ArrayList<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < excelList.size(); i++) { |
|
|
|
PersonTestingImportMoudleExcel data = excelList.get(i); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(data.getName())) { |
|
|
|
errorLineinfoList.add(packageErrorInfo(i, "姓名为空")); |
|
|
|
} else { |
|
|
|
data.setName(data.getName().trim()); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(data.getIdcard())) { |
|
|
|
errorLineinfoList.add(packageErrorInfo(i, "身份证号为空")); |
|
|
|
} else { |
|
|
|
data.setIdcard(data.getIdcard().trim()); |
|
|
|
// 是否存在
|
|
|
|
List<PersonTestingDTO> details = baseDao.getDetailByIdCardOrName(data.getIdcard(), null); |
|
|
|
if (NumConstant.ZERO < details.size()) { |
|
|
|
errorLineinfoList.add(packageErrorInfo(i, "身份证号已存在")); |
|
|
|
} |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(data.getTestingTimeStr())) { |
|
|
|
errorLineinfoList.add(packageErrorInfo(i, "核酸检测时间为空")); |
|
|
|
} else { |
|
|
|
if (DateUtils.DATE_TIME_PATTERN.length() != data.getTestingTimeStr().length()) { |
|
|
|
errorLineinfoList.add(packageErrorInfo(i, "核酸检测时间格式不匹配")); |
|
|
|
} else { |
|
|
|
data.setTestingTime(DateUtils.stringToDate(data.getTestingTimeStr(), DateUtils.DATE_TIME_PATTERN)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return errorLineinfoList; |
|
|
|
} |
|
|
|
|
|
|
|
public void saveList(List<PersonTestingImportMoudleExcel> excelList) { |
|
|
|
List<PersonTestingEntity> entitys = new ArrayList<>(); |
|
|
|
List<PersonTestingDTO> dtos = ConvertUtils.sourceToTarget(excelList, PersonTestingDTO.class); |
|
|
|
|
|
|
|
for (PersonTestingDTO dto : dtos) { |
|
|
|
// 0女;1男
|
|
|
|
String sex = IdentityNoUtils.getSex(dto.getIdcard()); |
|
|
|
dto.setSex(NumConstant.ONE_STR.equals(sex) ? "男" : "女"); |
|
|
|
String birthday = IdentityNoUtils.getBirthday(dto.getIdcard()); |
|
|
|
dto.setBirthday(DateUtils.stringToDate(birthday, DateUtils.DATE_PATTERN)); |
|
|
|
|
|
|
|
saveScanningInfoForUserV1(dto); |
|
|
|
|
|
|
|
PersonTestingEntity entity = ConvertUtils.sourceToTarget(dto, PersonTestingEntity.class); |
|
|
|
entitys.add(entity); |
|
|
|
} |
|
|
|
insertBatch(entitys); |
|
|
|
} |
|
|
|
} |
|
|
|