|
|
@ -43,6 +43,7 @@ import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.security.user.LoginUserUtil; |
|
|
|
import com.epmet.commons.tools.utils.*; |
|
|
|
import com.epmet.commons.tools.utils.poi.excel.FreezeAndFilter; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.constant.SystemMessageType; |
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
@ -50,6 +51,8 @@ import com.epmet.dto.IcResiUserDTO; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.enums.IcResiUserTableEnum; |
|
|
|
import com.epmet.excel.PartyMemberAgeExportExcel; |
|
|
|
import com.epmet.excel.PartyMemberEducationExportExcel; |
|
|
|
import com.epmet.excel.support.ExportResiUserItemDTO; |
|
|
|
import com.epmet.feign.EpmetMessageOpenFeignClient; |
|
|
|
import com.epmet.feign.OperCustomizeOpenFeignClient; |
|
|
@ -59,6 +62,7 @@ import com.epmet.service.IcResiUserService; |
|
|
|
import feign.RequestInterceptor; |
|
|
|
import jodd.io.FileUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
import org.apache.commons.io.FilenameUtils; |
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
@ -72,6 +76,7 @@ import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.File; |
|
|
@ -84,6 +89,7 @@ import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -135,7 +141,7 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
* 模板枚举 |
|
|
|
*/ |
|
|
|
public enum IcUserTemplateEnums { |
|
|
|
IC_RESI_IMPORT_TEMPLATE("excel/ic_resi_info_import_cid_for_easy_excel.xls", "居民信息导入模板.xls"), |
|
|
|
IC_RESI_IMPORT_TEMPLATE("excel/ic_resi_import_template.xls", "居民信息导入模板.xls"), |
|
|
|
IC_RESI_EXPORT_TEMPLATE("excel/ic_resi_info_cid_for_easy_excel.xlsx", "居民信息导出模板.xlsx"); |
|
|
|
|
|
|
|
private String pathInApp; |
|
|
@ -157,18 +163,13 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
|
|
|
|
{ |
|
|
|
// 初始化上传目录
|
|
|
|
String home = System.getProperty("user.home"); |
|
|
|
Path importDir = Paths.get(home, "epmet_files", "ic_user_import"); |
|
|
|
if (Files.notExists(importDir)) { |
|
|
|
try { |
|
|
|
Files.createDirectories(importDir); |
|
|
|
IC_RESI_UPLOAD_DIR = com.epmet.commons.tools.utils.FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_user_import"); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("创建数字赋能平台上传目录失败"); |
|
|
|
log.error("初始化居民信息上传目录失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
} |
|
|
|
} |
|
|
|
IC_RESI_UPLOAD_DIR = importDir; |
|
|
|
|
|
|
|
Path exportDir = Paths.get(home, "epmet_files", "ic_user_export"); |
|
|
|
Path exportDir = Paths.get(System.getProperty("user.home"), "epmet_files", "ic_user_export"); |
|
|
|
if (Files.notExists(exportDir)) { |
|
|
|
try { |
|
|
|
Files.createDirectories(exportDir); |
|
|
@ -469,10 +470,10 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
|
|
|
|
// 三.异步执行导入
|
|
|
|
executorService.execute(() -> { |
|
|
|
|
|
|
|
boolean isAllSuccess = false; |
|
|
|
try { |
|
|
|
List<FormItemResult> formItemList = icResiUserService.listFormItems(customerId,IcFormCodeEnum.RESI_BASE_INFO.getCode()); |
|
|
|
icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); |
|
|
|
isAllSuccess = icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); |
|
|
|
} catch (Throwable e) { |
|
|
|
String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e); |
|
|
|
log.error("【导入居民信息失败】导入失败:{}", errorMsg); |
|
|
@ -488,8 +489,13 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
icResiUserImportService.finishImportTask(importTaskId, operatorId, ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL, resultDesc, null); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
// 都导入成功了没问题,才删除
|
|
|
|
if (importTempFileSavePath != null){ |
|
|
|
if (isAllSuccess) { |
|
|
|
Files.delete(importTempFileSavePath); |
|
|
|
} else { |
|
|
|
log.error("【导入居民信息】未完全成功,上传文件:{}", importTempFileSavePath); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("【导入居民信息失败】清理上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
@ -531,8 +537,24 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
*/ |
|
|
|
@PostMapping("searchbyname") |
|
|
|
public Result<PageData<SearchByNameResultDTO>> searchByName(@RequestBody SearchByNameFormDTO formDTO, @LoginUser TokenDto tokenDto) { |
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
formDTO.setUserId(tokenDto.getUserId()); |
|
|
|
ValidatorUtils.validateEntity(formDTO, SearchByNameFormDTO.SearchByNameForm.class); |
|
|
|
return new Result<PageData<SearchByNameResultDTO>>().ok(icResiUserService.searchByName(formDTO, tokenDto)); |
|
|
|
return new Result<PageData<SearchByNameResultDTO>>().ok(icResiUserService.searchByName(formDTO)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 需求: http://zentao.elinkservice.cn/task-view-4193.html 第11条
|
|
|
|
* @param formDTO |
|
|
|
* @param tokenDto |
|
|
|
* @return 根据分类搜索 |
|
|
|
*/ |
|
|
|
@PostMapping("searchbycategory") |
|
|
|
public Result<PageData<SearchByNameResultDTO>> search(@RequestBody SearchByNameFormDTO formDTO, @LoginUser TokenDto tokenDto) { |
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
formDTO.setUserId(tokenDto.getUserId()); |
|
|
|
ValidatorUtils.validateEntity(formDTO, SearchByNameFormDTO.SearchByCategoryForm.class); |
|
|
|
return new Result<PageData<SearchByNameResultDTO>>().ok(icResiUserService.searchByName(formDTO)); |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
@ -585,28 +607,30 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
|
|
|
|
/** |
|
|
|
* 下载ic居民信息导入excel模板 |
|
|
|
* @param loginUserInfo |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("import/download-template") |
|
|
|
public ResponseEntity<byte[]> downloadIcResiDownloadTemplate(@LoginUser TokenDto loginUserInfo) { |
|
|
|
String customerId = loginUserInfo.getCustomerId(); |
|
|
|
|
|
|
|
public void downloadIcResiDownloadTemplate(HttpServletResponse response) { |
|
|
|
InputStream is = null; |
|
|
|
ServletOutputStream os = null; |
|
|
|
try { |
|
|
|
File icResiImportTemplateFile = getIcResiTemplateFile(customerId, IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE); |
|
|
|
os = response.getOutputStream(); |
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.add("Access-Control-Expose-Headers", "Content-Disposition"); |
|
|
|
headers.add("content-Type", "application/vnd.ms-excel"); |
|
|
|
headers.add("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getTemplateName(), "UTF-8")); |
|
|
|
is = this.getClass().getClassLoader().getResourceAsStream(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getPathInApp()); |
|
|
|
|
|
|
|
return new ResponseEntity<>(FileUtil.readBytes(icResiImportTemplateFile), headers, HttpStatus.OK); |
|
|
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
|
|
|
response.setHeader("content-Type", "application/vnd.ms-excel"); |
|
|
|
response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getTemplateName(), "UTF-8")); |
|
|
|
|
|
|
|
IOUtils.copy(is, os); |
|
|
|
} catch (Exception e) { |
|
|
|
String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
|
|
|
|
log.error("下载IC居民信息导入模板失败:{}", errorStackTrace); |
|
|
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "下载IC居民信息导入模板失败"); |
|
|
|
} finally { |
|
|
|
org.apache.poi.util.IOUtils.closeQuietly(is); |
|
|
|
org.apache.poi.util.IOUtils.closeQuietly(os); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -637,6 +661,56 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
return new Result<PageData<PartyMemberAgeResultDTO>>().ok(icResiUserService.getPartyMemberAgeList(formDTO)); |
|
|
|
} |
|
|
|
|
|
|
|
@NoRepeatSubmit |
|
|
|
@PostMapping("partymemberagelist/export") |
|
|
|
public void partyMemberAgeListExport(@LoginUser TokenDto tokenDto, @RequestBody PartyMemberListFormDTO formDTO, HttpServletResponse response) { |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
formDTO.setPageSize(NumConstant.TEN_THOUSAND); |
|
|
|
formDTO.setIsPage(false); |
|
|
|
List<PartyMemberAgeExportExcel> exportList = new ArrayList<>(); |
|
|
|
try { |
|
|
|
String fileName = ""; |
|
|
|
switch (formDTO.getCode()) { |
|
|
|
case NumConstant.ZERO_STR: |
|
|
|
fileName = "50岁以下党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.ONE_STR: |
|
|
|
fileName = "50-59岁党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.TWO_STR: |
|
|
|
fileName = "60-69岁党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.THREE_STR: |
|
|
|
fileName = "70-79岁党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.FOUR_STR: |
|
|
|
fileName = "80岁以上党员信息.xlsx"; |
|
|
|
break; |
|
|
|
default: |
|
|
|
fileName = "党员年龄信息.xlsx"; |
|
|
|
break; |
|
|
|
} |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), PartyMemberAgeExportExcel.class).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("党员列表").registerWriteHandler(new FreezeAndFilter()).build(); |
|
|
|
List<PartyMemberAgeResultDTO> list = icResiUserService.getPartyMemberAgeList(formDTO).getList(); |
|
|
|
AtomicInteger i = new AtomicInteger(1); |
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
exportList = list.stream().map(item -> { |
|
|
|
PartyMemberAgeExportExcel excel = ConvertUtils.sourceToTarget(item, PartyMemberAgeExportExcel.class); |
|
|
|
excel.setIndex(i.getAndIncrement()); |
|
|
|
return excel; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
excelWriter.write(exportList, writeSheet); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("export exception", e); |
|
|
|
} finally { |
|
|
|
if (excelWriter != null) { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 党员学历统计 |
|
|
|
* @Param formDTO |
|
|
@ -663,6 +737,62 @@ public class IcResiUserController implements ResultDataResolver { |
|
|
|
return new Result<PageData<PartyMemberEducationResultDTO>>().ok(icResiUserService.getPartyMemberEducationList(formDTO)); |
|
|
|
} |
|
|
|
|
|
|
|
@NoRepeatSubmit |
|
|
|
@PostMapping("partymembereducationlist/export") |
|
|
|
public void partyMemberEducationListExport(@LoginUser TokenDto tokenDto, @RequestBody PartyMemberListFormDTO formDTO, HttpServletResponse response) { |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
formDTO.setPageSize(NumConstant.TEN_THOUSAND); |
|
|
|
formDTO.setIsPage(false); |
|
|
|
List<PartyMemberEducationExportExcel> exportList = new ArrayList<>(); |
|
|
|
try { |
|
|
|
String fileName = ""; |
|
|
|
switch (formDTO.getCode()) { |
|
|
|
case NumConstant.ZERO_STR: |
|
|
|
fileName = "小学及文盲党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.ONE_STR: |
|
|
|
fileName = "初中学历党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.TWO_STR: |
|
|
|
fileName = "高中学历党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.THREE_STR: |
|
|
|
fileName = "大专学历党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.FOUR_STR: |
|
|
|
fileName = "本科学历党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.FIVE_STR: |
|
|
|
fileName = "硕士学历党员信息.xlsx"; |
|
|
|
break; |
|
|
|
case NumConstant.SIX_STR: |
|
|
|
fileName = "博士学历党员信息.xlsx"; |
|
|
|
break; |
|
|
|
default: |
|
|
|
fileName = "党员学历信息.xlsx"; |
|
|
|
break; |
|
|
|
} |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel(fileName, response), PartyMemberEducationExportExcel.class).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("党员列表").registerWriteHandler(new FreezeAndFilter()).build(); |
|
|
|
List<PartyMemberEducationResultDTO> list = icResiUserService.getPartyMemberEducationList(formDTO).getList(); |
|
|
|
AtomicInteger i = new AtomicInteger(1); |
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
exportList = list.stream().map(item -> { |
|
|
|
PartyMemberEducationExportExcel excel = ConvertUtils.sourceToTarget(item, PartyMemberEducationExportExcel.class); |
|
|
|
excel.setIndex(i.getAndIncrement()); |
|
|
|
return excel; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
excelWriter.write(exportList, writeSheet); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("export exception", e); |
|
|
|
} finally { |
|
|
|
if (excelWriter != null) { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据居民id查询居民信息简介 |
|
|
|
* @param resiUserId |
|
|
|