You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

918 lines
40 KiB

4 years ago
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.controller;
4 years ago
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillWrapper;
import com.epmet.commons.rocketmq.messages.IcResiUserAddMQMsg;
4 years ago
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.annotation.MaskResponse;
4 years ago
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.constant.AppClientConstant;
import com.epmet.commons.tools.constant.Constant;
4 years ago
import com.epmet.commons.tools.constant.NumConstant;
4 years ago
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.dto.result.OptionDataResultDTO;
import com.epmet.commons.tools.enums.IcFormCodeEnum;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.feign.ResultDataResolver;
4 years ago
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
4 years ago
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.security.user.LoginUserUtil;
import com.epmet.commons.tools.utils.*;
3 years ago
import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter;
4 years ago
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.constant.SystemMessageType;
import com.epmet.constants.ImportTaskConstants;
4 years ago
import com.epmet.dto.IcResiUserDTO;
4 years ago
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;
4 years ago
import com.epmet.excel.support.ExportResiUserItemDTO;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.feign.OperCustomizeOpenFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.service.IcResiUserExportService;
import com.epmet.service.IcResiUserImportService;
4 years ago
import com.epmet.service.IcResiUserService;
import feign.RequestInterceptor;
4 years ago
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;
4 years ago
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
4 years ago
import org.jetbrains.annotations.NotNull;
4 years ago
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
4 years ago
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
4 years ago
import javax.servlet.http.HttpServletResponse;
4 years ago
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.file.Files;
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;
4 years ago
/**
* 用户基础信息
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-10-26
*/
4 years ago
@Slf4j
4 years ago
@RestController
@RequestMapping("icresiuser")
public class IcResiUserController implements ResultDataResolver {
4 years ago
/**
* 居民上传临时目录
*/
private Path IC_RESI_UPLOAD_DIR;
/**
* 居民下载模版临时目录
*/
private String OSS_TEMP_RESI_TEMP_DIR = "file-template/resi-template/";
/**
* 本地模版缓存目录
*/
private Path IC_RESI_DOWNLOAD_DIR;
@Autowired
private OssFeignClient ossFeignClient;
@Autowired
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient;
4 years ago
@Autowired
private IcResiUserService icResiUserService;
@Autowired
private IcResiUserImportService icResiUserImportService;
@Autowired
private IcResiUserExportService icResiUserExportService;
@Autowired
private RedisUtils redisUtils;
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Autowired
private LoginUserUtil loginUserUtil;
@Autowired
private RequestInterceptor requestInterceptor;
@Autowired
private ExecutorService executorService;
/**
* 模板枚举
*/
public enum IcUserTemplateEnums {
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;
private String templateName;
IcUserTemplateEnums(String pathInApp, String templateName) {
this.pathInApp = pathInApp;
this.templateName = templateName;
}
public String getPathInApp() {
return pathInApp;
}
public String getTemplateName() {
return templateName;
}
}
{
// 初始化上传目录
try {
IC_RESI_UPLOAD_DIR = com.epmet.commons.tools.utils.FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_user_import");
} catch (IOException e) {
log.error("初始化居民信息上传目录失败:{}", ExceptionUtils.getErrorStackTrace(e));
}
Path exportDir = Paths.get(System.getProperty("user.home"), "epmet_files", "ic_user_export");
if (Files.notExists(exportDir)) {
try {
Files.createDirectories(exportDir);
} catch (IOException e) {
log.error("创建数字赋能平台下载目录失败");
}
}
IC_RESI_DOWNLOAD_DIR = exportDir;
}
4 years ago
4 years ago
@NoRepeatSubmit
@PostMapping("delete")
public Result delete(@LoginUser TokenDto tokenDto, @RequestBody DelIcResiUserFormDTO formDTO) {
formDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(formDTO, DelIcResiUserFormDTO.IdGroup.class);
4 years ago
formDTO.getUserIds().forEach(userId -> {
4 years ago
formDTO.setIcResiUserId(userId);
icResiUserService.delete(formDTO);
4 years ago
//推送MQ事件
IcResiUserAddMQMsg mqMsg = new IcResiUserAddMQMsg();
mqMsg.setCustomerId(tokenDto.getCustomerId());
mqMsg.setIcResiUser(userId);
SystemMsgFormDTO form = new SystemMsgFormDTO();
form.setMessageType(SystemMessageType.IC_RESI_USER_DEL);
form.setContent(mqMsg);
epmetMessageOpenFeignClient.sendSystemMsgByMQ(form);
});
return new Result();
}
4 years ago
/**
* @Author sun
* @Description 党建互联平台--保存居民信息
**/
4 years ago
@NoRepeatSubmit
4 years ago
@PostMapping("add")
4 years ago
public Result add(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) {
String resiUserId = icResiUserService.add(tokenDto, formDTO);
//推送MQ事件
IcResiUserAddMQMsg mqMsg = new IcResiUserAddMQMsg();
mqMsg.setCustomerId(tokenDto.getCustomerId());
mqMsg.setIcResiUser(resiUserId);
SystemMsgFormDTO form = new SystemMsgFormDTO();
form.setMessageType(SystemMessageType.IC_RESI_USER_ADD);
form.setContent(mqMsg);
epmetMessageOpenFeignClient.sendSystemMsgByMQ(form);
4 years ago
return new Result();
}
/**
* @Author sun
* @Description 党建互联平台--修改居民信息
**/
4 years ago
@NoRepeatSubmit
4 years ago
@PostMapping("edit")
4 years ago
public Result edit(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) {
String resiUserId = icResiUserService.edit(tokenDto, formDTO);
//推送MQ事件
IcResiUserAddMQMsg mqMsg = new IcResiUserAddMQMsg();
mqMsg.setCustomerId(tokenDto.getCustomerId());
4 years ago
log.info("customer id is {}",tokenDto.getCustomerId());
mqMsg.setIcResiUser(resiUserId);
SystemMsgFormDTO form = new SystemMsgFormDTO();
form.setMessageType(SystemMessageType.IC_RESI_USER_EDIT);
form.setContent(mqMsg);
epmetMessageOpenFeignClient.sendSystemMsgByMQ(form);
4 years ago
return new Result();
}
/**
* @Description 根据房间号查人
* @Param formDTO
* @Return {@link Result<List<HomeUserResultDTO>>}
* @Author zhaoqifeng
* @Date 2021/11/1 11:04
*/
@PostMapping("getpeoplebyroom")
public Result<List<HomeUserResultDTO>> getPeopleByRoom(@RequestBody IcResiUserDTO formDTO) {
return new Result<List<HomeUserResultDTO>>().ok(icResiUserService.getPeopleByRoom(formDTO.getHomeId()));
}
/**
* 根据ic_resi_user找家属
* @param icResiUserId
* @return
*/
@GetMapping("findfamilymem/{icResiUserId}")
public Result<IcResiUserBriefDTO> findFamilyMem(@PathVariable("icResiUserId") String icResiUserId){
if(StringUtils.isNotBlank(icResiUserId)){
return new Result<IcResiUserBriefDTO>().ok(icResiUserService.findFamilyMem(icResiUserId));
}
return new Result<>();
}
4 years ago
@PostMapping("listresi")
@MaskResponse(fieldNames = { "MOBILE", "ID_CARD" }, fieldsMaskType = { MaskResponse.MASK_TYPE_MOBILE, MaskResponse.MASK_TYPE_ID_CARD })
public Result<PageData<Map<String, Object>>> queryListResi1(@LoginUser TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO) {
4 years ago
//pageFormDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
pageFormDTO.setCustomerId(tokenDto.getCustomerId());
pageFormDTO.setStaffId(tokenDto.getUserId());
ValidatorUtils.validateEntity(pageFormDTO, IcResiUserPageFormDTO.AddUserInternalGroup.class);
if(null==pageFormDTO.getConditions()){
pageFormDTO.setConditions(new ArrayList<>());
}
return new Result<PageData<Map<String, Object>>>().ok(icResiUserService.pageResiMap(pageFormDTO));
4 years ago
}
4 years ago
/**
* 编辑页面显示居民信息详情
*
* @param pageFormDTO
* @return com.epmet.commons.tools.utils.Result
4 years ago
* @author yinzuomei
* @date 2021/10/28 10:29 上午
*/
@PostMapping("detail")
public Result queryIcResiDetail(@LoginUser TokenDto tokenDto, @RequestBody IcResiDetailFormDTO pageFormDTO) {
4 years ago
//pageFormDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
pageFormDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(pageFormDTO, IcResiDetailFormDTO.AddUserInternalGroup.class);
4 years ago
return new Result().ok(icResiUserService.queryIcResiDetail(pageFormDTO));
}
4 years ago
4 years ago
/**
* desc: 导出居民信息
*
* @param customerId
* @param tokenDto
* @param pageFormDTO
* @param response
* @return void
* @author LiuJanJun
* @date 2021/11/19 4:24 下午
4 years ago
* @remark:分页批量导出 oss目录在 各个环境对应的前缀文件夹/file-template/resi-template/客户ID.xlsx,
* 如果某个客户需要更新模版 则替换掉上面的模版文件然后 更新缓存里的值或者删除也行 再导出就会下载新的模版了
4 years ago
*/
4 years ago
@NoRepeatSubmit
@RequestMapping(value = "/exportExcel")
public void exportExcelByEasyExcel(@RequestHeader String customerId,@LoginUser TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws Exception {
//tokenDto.setUserId("9e37adcce6472152e6508a19d3683e02");
long startM = System.currentTimeMillis();
CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(customerId, tokenDto.getUserId());
String staffOrgPath = null;
if (StringUtils.isNotBlank(staffInfoCacheResult.getAgencyPIds()) && !NumConstant.ZERO_STR.equals(staffInfoCacheResult.getAgencyPIds())) {
4 years ago
staffOrgPath = staffInfoCacheResult.getAgencyPIds().concat(StrConstant.COLON).concat(staffInfoCacheResult.getAgencyId());
} else {
staffOrgPath = staffInfoCacheResult.getAgencyId();
}
pageFormDTO.setCustomerId(customerId);
pageFormDTO.setIsPage(false);
//获取模版文件
File file = getIcResiTemplateFile(customerId, IcUserTemplateEnums.IC_RESI_EXPORT_TEMPLATE);
ExcelWriter excelWriter = null;
try {
4 years ago
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("居民基本信息.xlsx", response)).withTemplate(file).build();
//子表是否停止查询
Set<String> stopSearchSet = new HashSet<>();
4 years ago
//获取表单项
List<FormItemResult> resiFormAllItems = icResiUserService.listFormItems(customerId, IcFormCodeEnum.RESI_BASE_INFO.getCode());
4 years ago
Map<String, FormItemResult> allItemMap = resiFormAllItems.stream().collect(Collectors.toMap(FormItemResult::getItemId, o -> o));
Map<String, ExportResiUserItemDTO> map = new HashMap<>();
allItemMap.values().forEach(item->{
String tableName = item.getTableName();
ExportResiUserItemDTO exportItem = map.getOrDefault(tableName, new ExportResiUserItemDTO());
map.putIfAbsent(tableName,exportItem);
String columnName = item.getColumnName().concat(item.getColumnNum() == NumConstant.ZERO ? StrConstant.EPMETY_STR : item.getColumnNum().toString());
exportItem.getItemMap().put(columnName,item);
if (Constant.OPITON_SOURCE_REMOTE.equals(item.getOptionSourceType())&&item.getOptionSourceValue().contains(StrConstant.QUESTION_MARK)){
4 years ago
//多个参数
String[] paramArr = item.getOptionSourceValue().split(StrConstant.QUESTION_MARK_TRANSFER)[NumConstant.ONE].split(StrConstant.AND_MARK);
Arrays.stream(paramArr).forEach(o->{
FormItemResult value = allItemMap.get(o);
if (value == null){
return;
}
Set<FormItemResult> conditionSet = exportItem.getRemoteItemConditionMap().getOrDefault(item.getItemId(),new HashSet<>());
conditionSet.add(value);
exportItem.getRemoteItemConditionMap().putIfAbsent(item.getItemId(),conditionSet);
});
}
});
4 years ago
//每个表对应的 item ;key:表名,value:<字段名:item对象>
Map<String, WriteSheet> childTableWriteSheetMap = new HashMap<>();
//表数据写入
//通过枚举获取相关表并按照sheetNo排序
4 years ago
List<IcResiUserTableEnum> resiTableList = Arrays.stream(IcResiUserTableEnum.values())
.filter((v) -> v.getSheetNo() != null)
4 years ago
.sorted(Comparator.comparing(IcResiUserTableEnum::getSheetNo))
.collect(Collectors.toList());
4 years ago
List<Map<String, Object>> resiResultList = null;
4 years ago
pageFormDTO.setPageSize(NumConstant.ONE_THOUSAND);
for (IcResiUserTableEnum tableEnum : resiTableList) {
String tableName = tableEnum.getTableName();
pageFormDTO.setPageNo(NumConstant.ONE);
4 years ago
//循环一次 写入一个sheet
do {
4 years ago
resiResultList = icResiUserService.getDataForExport(map.get(tableName), tableName, pageFormDTO, staffInfoCacheResult.getAgencyId(), staffOrgPath);
//如果 返回的条数小于每页显示的数 则退出查询
4 years ago
if (resiResultList.size() < pageFormDTO.getPageSize()) {
stopSearchSet.add(tableName);
}
4 years ago
//如果没有 构建新的writeSheet
WriteSheet writeSheet = childTableWriteSheetMap.getOrDefault(tableName,EasyExcel.writerSheet(tableEnum.getSheetNo()).build());
childTableWriteSheetMap.putIfAbsent(tableName, writeSheet);
//写入数据
4 years ago
excelWriter.fill(new FillWrapper("t" + (tableEnum.getSheetNo() + NumConstant.ONE), resiResultList), writeSheet);
pageFormDTO.setPageNo(pageFormDTO.getPageNo() + NumConstant.ONE);
//重置数据
4 years ago
resiResultList.clear();
//如果包含则说明子表的数据 已经查询完毕 无需再继续查询了
} while (!stopSearchSet.contains(tableName));
}
} finally {
if (excelWriter != null){
excelWriter.finish();
}
log.info("exportExcelByEasyExcel resi info cost time:{}s",(System.currentTimeMillis()-startM)/NumConstant.ONE_THOUSAND);
}
}
/**
* desc: 自定义导出居民信息
*
* @param tokenDto
* @param pageFormDTO
* @param response
* @return void
* @author LiuJanJun
* @date 2021/11/19 4:24 下午
* @remark:分页批量导出 oss目录在 各个环境对应的前缀文件夹/file-template/resi-template/客户ID.xlsx,
* 如果某个客户需要更新模版 则替换掉上面的模版文件然后 更新缓存里的值或者删除也行 再导出就会下载新的模版了
*/
@NoRepeatSubmit
@RequestMapping(value = "/exportExcelCustom")
3 years ago
public void exportExcelCustom(@LoginUser TokenDto tokenDto, @RequestBody ExportResiUserFormDTO pageFormDTO, HttpServletResponse response) {
//获取导出配置
3 years ago
icResiUserExportService.exportIcResiUser(tokenDto,pageFormDTO,response);
}
/**
3 years ago
* desc:根据客户id 先从oss下载模版,如果有没有则使用系统默认模板 如果不存在则返回null
*
* @param customerId
* @return
*/
private File getIcResiTemplateFile(String customerId, IcUserTemplateEnums template) throws Exception{
String fileType = ".xlsx";
String fileName = customerId + fileType;
File file = new File(IC_RESI_DOWNLOAD_DIR.resolve(fileName).toString());
String serverIp = IpUtils.getServerIp();
Object isChanged = redisUtils.hGet(RedisKeys.getResiTempChangedKey(customerId), serverIp);
//如果 redis 不存在这个机器的key 或者值为1 则重新下载
4 years ago
if (!file.exists() || isChanged == null || NumConstant.ONE_STR.equals(isChanged.toString())) {
if (file.exists()) {
file.delete();
}
String ossFilePath = OSS_TEMP_RESI_TEMP_DIR + fileName;
Result<String> fileUrlResult = ossFeignClient.getOssFileUrl(ossFilePath, null);
Result<byte[]> result = HttpClientManager.getInstance().getDownloadFilebytes(fileUrlResult.getData(), null);
//获取模版失败 则把默认文件写入
if (result == null || !result.success()) {
log.warn("获取居民模版失败,path:{},走默认模版", ossFilePath);
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(template.getPathInApp());
FileUtils.copyInputStreamToFile(resourceAsStream,file);
log.warn("getIcResiTemplateFile copy default file to template,customerId:{}",customerId);
} else {
log.warn("getIcResiTemplateFile reload file form oss default file to template,customerId:{}",customerId);
FileUtils.writeByteArrayToFile(file,result.getData());
}
redisUtils.hSet(RedisKeys.getResiTempChangedKey(customerId), serverIp, NumConstant.ZERO_STR);
return file;
}
return file;
}
/**
* excel导入居民基本信息
*
* @return
*/
4 years ago
@NoRepeatSubmit
4 years ago
@PostMapping("importExcel")
public Result importExcelByEasyExcel(@RequestHeader("customerId") String customerId,@RequestPart("file") MultipartFile file, HttpServletRequest multipartRequest, HttpServletResponse response) {
if (file.isEmpty()) {
throw new RenException("请上传文件");
}
String originalFilename = file.getOriginalFilename();
// 一.校验文件类型
String extension = FilenameUtils.getExtension(originalFilename);
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
throw new RenException("文件类型不匹配");
}
String operatorId = loginUserUtil.getLoginUserId();
String importTaskId = icResiUserImportService.createImportTaskRecord(operatorId, ImportTaskConstants.BIZ_TYPE_RESI, originalFilename);
// 二.缓存上传的文件
Path importTempFileSavePath;
try {
String fileName = UUID.randomUUID().toString().concat(".").concat(extension);
importTempFileSavePath = IC_RESI_UPLOAD_DIR.resolve(fileName);
IOUtils.copy(file.getInputStream(), new FileOutputStream(importTempFileSavePath.toString()));
} catch (Exception e) {
log.error("【上传居民信息】保存上传的文件失败:{}", ExceptionUtils.getErrorStackTrace(e));
throw new RenException("上传失败");
}
// 三.异步执行导入
executorService.execute(() -> {
boolean isAllSuccess = false;
try {
List<FormItemResult> formItemList = icResiUserService.listFormItems(customerId,IcFormCodeEnum.RESI_BASE_INFO.getCode());
isAllSuccess = icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR);
} catch (Throwable e) {
String errorMsg = ExceptionUtils.getThrowableErrorStackTrace(e);
log.error("【导入居民信息失败】导入失败:{}", errorMsg);
String resultDesc;
if (e instanceof OfficeXmlFileException) {
resultDesc = "文件格式异常,请确保使用下载的模板文件";
} else {
resultDesc = "系统异常,请查看系统日志";
}
// 要将导入任务状态设置为结束但不成功。不报错即成功,没有返回值
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));
}
//推送MQ事件
IcResiUserAddMQMsg mqMsg = new IcResiUserAddMQMsg();
mqMsg.setCustomerId(EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID));
//mqMsg.setIcResiUser(resiUserId);
SystemMsgFormDTO form = new SystemMsgFormDTO();
form.setMessageType(SystemMessageType.IC_RESI_USER_ADD);
form.setContent(mqMsg);
epmetMessageOpenFeignClient.sendSystemMsgByMQ(form);
}
});
return new Result();
}
4 years ago
/**
* @param formDTO
* @Description 查询个人数据
4 years ago
* @author zxc
* @date 2021/11/3 9:21 上午
*/
@PostMapping("persondata")
public Result<PersonDataResultDTO> personData(@LoginUser TokenDto tokenDto,@RequestBody PersonDataFormDTO formDTO) {
formDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(formDTO,PersonDataFormDTO.PersonDataForm.class);
4 years ago
return new Result<PersonDataResultDTO>().ok(icResiUserService.personData(formDTO));
}
/**
* @param formDTO
* @param tokenDto
* @Description 根据名字搜索
4 years ago
* @author zxc
* @date 2021/11/3 1:42 下午
*/
@PostMapping("searchbyname")
public Result<PageData<SearchByNameResultDTO>> searchByName(@RequestBody SearchByNameFormDTO formDTO, @LoginUser TokenDto tokenDto) {
3 years ago
formDTO.setCustomerId(tokenDto.getCustomerId());
formDTO.setUserId(tokenDto.getUserId());
4 years ago
ValidatorUtils.validateEntity(formDTO, SearchByNameFormDTO.SearchByNameForm.class);
3 years ago
return new Result<PageData<SearchByNameResultDTO>>().ok(icResiUserService.searchByName(formDTO));
}
/**
* 需求 http://zentao.elinkservice.cn/task-view-4193.html 第11条
* @param formDTO
* @param tokenDto
* @return 根据分类搜索
*/
3 years ago
@PostMapping("searchbycategory")
3 years ago
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
private CustomerFormResultDTO getResiFormAddItems(String customerId) {
CustomerFormQueryDTO queryDTO = new CustomerFormQueryDTO();
queryDTO.setFormCode(IcFormCodeEnum.RESI_BASE_INFO.getCode());
queryDTO.setCustomerId(customerId);
Result<CustomerFormResultDTO> resultForm = operCustomizeOpenFeignClient.getCustomerForm(queryDTO);
if (resultForm == null || !resultForm.success() || resultForm.getData() == null) {
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
}
return resultForm.getData();
4 years ago
}
/**
* @Description 个人信息-家庭关系
* @Param formDTO
* @Return {@link Result< OwnerRelationResultDTO>}
* @Author zhaoqifeng
* @Date 2021/11/5 11:13
*/
@PostMapping("ownerrelation")
public Result<OwnerRelationResultDTO> getOwnerRelation(@RequestBody PersonDataFormDTO formDTO) {
return new Result<OwnerRelationResultDTO>().ok(icResiUserService.getOwnerRelation(formDTO.getUserId()));
}
/**
* @Description 获取一栋楼每个房间人员分类的数量
* @Param formDTO
* @Return {@link Result< Map< String, Map< String, String>>>}
* @Author zhaoqifeng
* @Date 2021/11/5 15:10
*/
@PostMapping("categorycount")
public Result<Map<String, Map<String, String>>> getHomeUserCategoryCount(@RequestBody IcResiUserDTO formDTO) {
return new Result<Map<String, Map<String, String>>>().ok(icResiUserService.getHomeUserCategoryCount(formDTO.getBuildId()));
}
4 years ago
/**
* @LoginUser TokenDto tokenDto,
* 新增需求需求人列表展示当前工作人员所属组织+页面已选择所属网格 下的居民列表
* @param formDTO
* @return
*/
@PostMapping("demandusers")
public Result<List<DemandUserResDTO>> queryDemandUsers(@RequestBody DemandUserFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO, DemandUserFormDTO.InternalGroup.class);
return new Result<List<DemandUserResDTO>>().ok(icResiUserService.queryDemandUsers(formDTO));
}
/**
* 下载ic居民信息导入excel模板
* @return
*/
@PostMapping("import/download-template")
public void downloadIcResiDownloadTemplate(HttpServletResponse response) {
InputStream is = null;
ServletOutputStream os = null;
try {
os = response.getOutputStream();
is = this.getClass().getClassLoader().getResourceAsStream(IcUserTemplateEnums.IC_RESI_IMPORT_TEMPLATE.getPathInApp());
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);
}
}
/**
* 党员年龄范围统计
* @Param formDTO
* @Return {@link Result< List< OptionDataResultDTO >>}
* @Author zhaoqifeng
* @Date 2021/12/10 15:52
*/
@PostMapping("partymemberagestatistics")
public Result<List<OptionDataResultDTO>> partyMemberAgeStatistics(@RequestBody PartyMemberStatisticsFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
return new Result<List<OptionDataResultDTO>>().ok(icResiUserService.partyMemberAgeStatistics(formDTO));
}
/**
* 党员年龄列表
* @Param formDTO
* @Return {@link Result< PageData< PartyMemberEducationResultDTO>>}
* @Author zhaoqifeng
* @Date 2021/12/10 17:54
*/
@PostMapping("partymemberagelist")
@MaskResponse(fieldNames = { "mobile" }, fieldsMaskType = { MaskResponse.MASK_TYPE_MOBILE })
public Result<PageData<PartyMemberAgeResultDTO>> partyMemberAgelist(@RequestBody PartyMemberListFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
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
* @Return {@link Result< List< OptionDataResultDTO>>}
* @Author zhaoqifeng
* @Date 2021/12/10 17:58
*/
@PostMapping("partymembereducationstatistics")
public Result<List<OptionDataResultDTO>> partyMemberEducationStatistics(@RequestBody PartyMemberStatisticsFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
return new Result<List<OptionDataResultDTO>>().ok(icResiUserService.partyMemberEducationStatistics(formDTO));
}
/**
* 党员学历列表
* @Param formDTO
* @Return {@link Result< PageData< PartyMemberEducationResultDTO>>}
* @Author zhaoqifeng
* @Date 2021/12/10 17:58
*/
@PostMapping("partymembereducationlist")
@MaskResponse(fieldNames = { "mobile" }, fieldsMaskType = { MaskResponse.MASK_TYPE_MOBILE })
public Result<PageData<PartyMemberEducationResultDTO>> partyMemberEducationlist(@RequestBody PartyMemberListFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
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
* @return
*/
@PostMapping("resi-brief/{resi-user-id}")
public Result<IcResiUserBriefDTO> getResiBrief(@PathVariable("resi-user-id") String resiUserId, @LoginUser TokenDto loginUser) {
String customerId = loginUser.getCustomerId();
IcResiUserBriefDTO r = icResiUserService.getResiBrief(resiUserId, customerId);
return new Result<IcResiUserBriefDTO>().ok(r);
}
/**
* 获取ic_resi_user
* @param icResiUserId
* @return
*/
@PostMapping("geticresiuser/{icResiUserId}")
public Result<IcResiUserDTO> getIcResiUserDTO(@PathVariable("icResiUserId") String icResiUserId){
if(StringUtils.isNotBlank(icResiUserId)){
return new Result<IcResiUserDTO>().ok(icResiUserService.get(icResiUserId));
}
return new Result<>();
}
/**
* 社区查询搜索居民们
* @param input
* @return
*/
@PostMapping("search")
public Result<PageData<Map<String, Object>>> searchResi(@RequestBody IcResiUserPageFormDTO input, @LoginUser TokenDto loginUser) {
if (StringUtils.isBlank(input.getKeyword())) {
4 years ago
PageData<Map<String, Object>> r = new PageData<Map<String, Object>>(new ArrayList<>(), NumConstant.ZERO_L);
return new Result<PageData<Map<String, Object>>>().ok(r);
}
input.setKeyword(input.getKeyword().trim());
input.setCustomerId(loginUser.getCustomerId());
input.setStaffId(loginUser.getUserId());
input.setFormCode(IcFormCodeEnum.RESI_BASE_INFO.getCode());
input.setConditions(new ArrayList<>());
if (input.getPageNo() == null) {
4 years ago
input.setPageNo(NumConstant.ONE);
}
if (input.getPageSize() == null) {
4 years ago
input.setPageSize(NumConstant.TWENTY);
}
PageData<Map<String, Object>> r = icResiUserService.pageResiMap(input);
return new Result<PageData<Map<String, Object>>>().ok(r);
}
/**
* @Description 社区查询人员预警右侧列表
* @param formDTO
* @param tokenDto
* @author zxc
* @date 2022/1/17 4:25 下午
*/
@PostMapping("personwarn/rightlist")
@MaskResponse(fieldNames = "mobile", fieldsMaskType = { MaskResponse.MASK_TYPE_MOBILE })
public Result<PersonWarnRightListResultDTO> personWarnRightList(@RequestBody PersonWarnRightListFormDTO formDTO,@LoginUser TokenDto tokenDto){
ValidatorUtils.validateEntity(formDTO, PersonWarnRightListFormDTO.PersonWarnRightListForm.class);
return new Result<PersonWarnRightListResultDTO>().ok(icResiUserService.personWarnRightList(formDTO,tokenDto));
}
4 years ago
/**
* Desc: 根据房屋IDs查询房屋下是否有存在居民的
* @param ids
* @author zxc
* @date 2022/3/2 10:32 上午
*/
@PostMapping("getexistuserbyhouseids")
public Result<List<String>> getExistUserByHouseIds(@RequestBody List<String> ids){
return new Result<List<String>>().ok(icResiUserService.getExistUserByHouseIds(ids));
}
/**
* @Author sun
* @Description 人房居民总数饼图
**/
@PostMapping("userchart")
public Result<UserChartResultDTO> userChart(@LoginUser TokenDto tokenDto, @RequestBody UserChartFormDTO formDTO) {
formDTO.setCustomerId(tokenDto.getCustomerId());
formDTO.setUserId(tokenDto.getUserId());
return new Result<UserChartResultDTO>().ok(icResiUserService.userChart(formDTO));
}
/**
* @Author sun
* @Description 人房居民总数列表数据
**/
@PostMapping("userchartlist")
public Result<List<UserChartResultDTO>> userChartList(@RequestBody UserChartFormDTO formDTO) {
return new Result<List<UserChartResultDTO>>().ok(icResiUserService.userChartList(formDTO));
}
}