|
|
@ -260,100 +260,101 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl<IcPartymember |
|
|
|
//@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Async |
|
|
|
public void importData(TokenDto tokenDto, HttpServletResponse response, MultipartFile file, String taskId) throws IOException { |
|
|
|
List<PartyMemberImportExcel> fileList = new ArrayList<>(); |
|
|
|
PartyMemberImportExcel excel = null; |
|
|
|
ExcelImportResult<IcPartymemberStyleImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartymemberStyleImportExcel.class); |
|
|
|
try { |
|
|
|
List<PartyMemberImportExcel> fileList = new ArrayList<>(); |
|
|
|
PartyMemberImportExcel excel = null; |
|
|
|
ExcelImportResult<IcPartymemberStyleImportExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcPartymemberStyleImportExcel.class); |
|
|
|
|
|
|
|
List<IcPartymemberStyleImportExcel> failList = importResult.getFailList(); |
|
|
|
//存放错误数据行号
|
|
|
|
List<Integer> numList = new ArrayList<>(); |
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(failList)) { |
|
|
|
for (IcPartymemberStyleImportExcel entity : failList) { |
|
|
|
//打印失败的行 和失败的信息
|
|
|
|
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); |
|
|
|
numList.add(entity.getRowNum()); |
|
|
|
excel = new PartyMemberImportExcel(); |
|
|
|
excel.setGridName(entity.getGridName()); |
|
|
|
excel.setName(entity.getName()); |
|
|
|
excel.setMainDeed(entity.getMainDeed()); |
|
|
|
excel.setCategoryName(entity.getCategoryName()); |
|
|
|
excel.setErrorInfo(entity.getErrorMsg()); |
|
|
|
fileList.add(excel); |
|
|
|
List<IcPartymemberStyleImportExcel> failList = importResult.getFailList(); |
|
|
|
//存放错误数据行号
|
|
|
|
List<Integer> numList = new ArrayList<>(); |
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(failList)) { |
|
|
|
for (IcPartymemberStyleImportExcel entity : failList) { |
|
|
|
//打印失败的行 和失败的信息
|
|
|
|
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg()); |
|
|
|
numList.add(entity.getRowNum()); |
|
|
|
excel = new PartyMemberImportExcel(); |
|
|
|
excel.setGridName(entity.getGridName()); |
|
|
|
excel.setName(entity.getName()); |
|
|
|
excel.setMainDeed(entity.getMainDeed()); |
|
|
|
excel.setCategoryName(entity.getCategoryName()); |
|
|
|
excel.setErrorInfo(entity.getErrorMsg()); |
|
|
|
fileList.add(excel); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
List<IcPartymemberStyleImportExcel> result = importResult.getList(); |
|
|
|
List<IcPartymemberStyleImportExcel> result = importResult.getList(); |
|
|
|
|
|
|
|
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
//获取组织下网格信息
|
|
|
|
GridOptionFormDTO formDTO = new GridOptionFormDTO(); |
|
|
|
formDTO.setAgencyId(staffInfoCache.getAgencyId()); |
|
|
|
Result<List<CustomerGridDTO>> gridOptionResult = govOrgOpenFeignClient.getGridIListByAgency(staffInfoCache.getAgencyId()); |
|
|
|
if (!gridOptionResult.success()) { |
|
|
|
throw new EpmetException(gridOptionResult.getCode(), gridOptionResult.getMsg()); |
|
|
|
} |
|
|
|
Map<String, String> gridMap = gridOptionResult.getData().stream().collect(Collectors.toMap(CustomerGridDTO::getGridName, CustomerGridDTO::getId)); |
|
|
|
//获取党员风采所有分类:key:分类名称;
|
|
|
|
Map<String,IcPartymemberStyleCategoryDictEntity> categoryDictMap=icPartymemberStyleCategoryDictService.getCategoryDictMap(tokenDto.getCustomerId()); |
|
|
|
//1.数据校验 只允许导入当前组织下的网格的数据
|
|
|
|
//网格名称不一样的数据舍弃或者分类名称不存在也舍弃
|
|
|
|
Iterator<IcPartymemberStyleImportExcel> iterator = result.iterator(); |
|
|
|
while (iterator.hasNext()) { |
|
|
|
IcPartymemberStyleImportExcel obj = iterator.next(); |
|
|
|
if (null == gridMap.get(obj.getGridName().trim())) { |
|
|
|
numList.add(obj.getRowNum()); |
|
|
|
log.warn(String.format("不是当前组织下可导入的数据,网格名称->%s,行号->%s", obj.getGridName(), obj.getRowNum())); |
|
|
|
excel = new PartyMemberImportExcel(); |
|
|
|
excel.setGridName(obj.getGridName()); |
|
|
|
excel.setName(obj.getName()); |
|
|
|
excel.setMainDeed(obj.getMainDeed()); |
|
|
|
excel.setCategoryName(obj.getCategoryName()); |
|
|
|
excel.setErrorInfo("不是当前组织下网格"); |
|
|
|
fileList.add(excel); |
|
|
|
iterator.remove(); |
|
|
|
continue; |
|
|
|
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId()); |
|
|
|
//获取组织下网格信息
|
|
|
|
GridOptionFormDTO formDTO = new GridOptionFormDTO(); |
|
|
|
formDTO.setAgencyId(staffInfoCache.getAgencyId()); |
|
|
|
Result<List<CustomerGridDTO>> gridOptionResult = govOrgOpenFeignClient.getGridIListByAgency(staffInfoCache.getAgencyId()); |
|
|
|
if (!gridOptionResult.success()) { |
|
|
|
throw new EpmetException(gridOptionResult.getCode(), gridOptionResult.getMsg()); |
|
|
|
} |
|
|
|
if (null == categoryDictMap.get(obj.getCategoryName().trim())) { |
|
|
|
numList.add(obj.getRowNum()); |
|
|
|
log.warn(String.format("分类名称【%s】不存在,不可导入,行号->%s", obj.getCategoryName(), obj.getRowNum())); |
|
|
|
excel = new PartyMemberImportExcel(); |
|
|
|
excel.setGridName(obj.getGridName()); |
|
|
|
excel.setName(obj.getName()); |
|
|
|
excel.setMainDeed(obj.getMainDeed()); |
|
|
|
excel.setCategoryName(obj.getCategoryName()); |
|
|
|
excel.setErrorInfo("分类名称不存在"); |
|
|
|
fileList.add(excel); |
|
|
|
iterator.remove(); |
|
|
|
Map<String, String> gridMap = gridOptionResult.getData().stream().collect(Collectors.toMap(CustomerGridDTO::getGridName, CustomerGridDTO::getId)); |
|
|
|
//获取党员风采所有分类:key:分类名称;
|
|
|
|
Map<String,IcPartymemberStyleCategoryDictEntity> categoryDictMap=icPartymemberStyleCategoryDictService.getCategoryDictMap(tokenDto.getCustomerId()); |
|
|
|
//1.数据校验 只允许导入当前组织下的网格的数据
|
|
|
|
//网格名称不一样的数据舍弃或者分类名称不存在也舍弃
|
|
|
|
Iterator<IcPartymemberStyleImportExcel> iterator = result.iterator(); |
|
|
|
while (iterator.hasNext()) { |
|
|
|
IcPartymemberStyleImportExcel obj = iterator.next(); |
|
|
|
if (null == gridMap.get(obj.getGridName().trim())) { |
|
|
|
numList.add(obj.getRowNum()); |
|
|
|
log.warn(String.format("不是当前组织下可导入的数据,网格名称->%s,行号->%s", obj.getGridName(), obj.getRowNum())); |
|
|
|
excel = new PartyMemberImportExcel(); |
|
|
|
excel.setGridName(obj.getGridName()); |
|
|
|
excel.setName(obj.getName()); |
|
|
|
excel.setMainDeed(obj.getMainDeed()); |
|
|
|
excel.setCategoryName(obj.getCategoryName()); |
|
|
|
excel.setErrorInfo("不是当前组织下网格"); |
|
|
|
fileList.add(excel); |
|
|
|
iterator.remove(); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (null == categoryDictMap.get(obj.getCategoryName().trim())) { |
|
|
|
numList.add(obj.getRowNum()); |
|
|
|
log.warn(String.format("分类名称【%s】不存在,不可导入,行号->%s", obj.getCategoryName(), obj.getRowNum())); |
|
|
|
excel = new PartyMemberImportExcel(); |
|
|
|
excel.setGridName(obj.getGridName()); |
|
|
|
excel.setName(obj.getName()); |
|
|
|
excel.setMainDeed(obj.getMainDeed()); |
|
|
|
excel.setCategoryName(obj.getCategoryName()); |
|
|
|
excel.setErrorInfo("分类名称不存在"); |
|
|
|
fileList.add(excel); |
|
|
|
iterator.remove(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (CollectionUtils.isEmpty(result)) { |
|
|
|
if (CollectionUtils.isEmpty(result)) { |
|
|
|
/*Collections.sort(numList); |
|
|
|
String subList = numList.stream().map(String::valueOf).collect(Collectors.joining("、")); |
|
|
|
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "第" + subList + "行未成功!");*/ |
|
|
|
erroeImport(fileList, taskId, tokenDto.getUserId()); |
|
|
|
return; |
|
|
|
} |
|
|
|
List<IcPartymemberStyleImageEntity> imageList = new ArrayList<>(); |
|
|
|
List<IcPartymemberStyleEntity> list = result.stream().map(item -> { |
|
|
|
IcPartymemberStyleEntity entity = new IcPartymemberStyleEntity(); |
|
|
|
entity.setId(UUID.randomUUID().toString().replace("-", "")); |
|
|
|
entity.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
entity.setAgencyId(staffInfoCache.getAgencyId()); |
|
|
|
entity.setGridId(gridMap.get(item.getGridName())); |
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(entity.getGridId()); |
|
|
|
if (null != gridInfo) { |
|
|
|
entity.setGridPids(gridInfo.getPids()); |
|
|
|
erroeImport(fileList); |
|
|
|
return; |
|
|
|
} |
|
|
|
entity.setName(item.getName()); |
|
|
|
entity.setMainDeed(item.getMainDeed()); |
|
|
|
IcPartymemberStyleCategoryDictEntity dictEntity=categoryDictMap.get(item.getCategoryName()); |
|
|
|
entity.setCategoryId(null == dictEntity ? StrConstant.EPMETY_STR : dictEntity.getId()); |
|
|
|
entity.setCategoryCode(null == dictEntity ? StrConstant.EPMETY_STR : dictEntity.getCategoryCode()); |
|
|
|
AtomicInteger i = new AtomicInteger(); |
|
|
|
return entity; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
List<IcPartymemberStyleImageEntity> imageList = new ArrayList<>(); |
|
|
|
List<IcPartymemberStyleEntity> list = result.stream().map(item -> { |
|
|
|
IcPartymemberStyleEntity entity = new IcPartymemberStyleEntity(); |
|
|
|
entity.setId(UUID.randomUUID().toString().replace("-", "")); |
|
|
|
entity.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
entity.setAgencyId(staffInfoCache.getAgencyId()); |
|
|
|
entity.setGridId(gridMap.get(item.getGridName())); |
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(entity.getGridId()); |
|
|
|
if (null != gridInfo) { |
|
|
|
entity.setGridPids(gridInfo.getPids()); |
|
|
|
} |
|
|
|
entity.setName(item.getName()); |
|
|
|
entity.setMainDeed(item.getMainDeed()); |
|
|
|
IcPartymemberStyleCategoryDictEntity dictEntity=categoryDictMap.get(item.getCategoryName()); |
|
|
|
entity.setCategoryId(null == dictEntity ? StrConstant.EPMETY_STR : dictEntity.getId()); |
|
|
|
entity.setCategoryCode(null == dictEntity ? StrConstant.EPMETY_STR : dictEntity.getCategoryCode()); |
|
|
|
AtomicInteger i = new AtomicInteger(); |
|
|
|
return entity; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
insertBatch(list); |
|
|
|
icPartymemberStyleImageService.insertBatch(imageList); |
|
|
|
insertBatch(list); |
|
|
|
icPartymemberStyleImageService.insertBatch(imageList); |
|
|
|
|
|
|
|
/*String str = String.format("共%s条,成功导入%s条。", numList.size() + result.size(), numList.size() + result.size() - numList.size()); |
|
|
|
if (numList.size() > NumConstant.ZERO) { |
|
|
@ -363,14 +364,19 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl<IcPartymember |
|
|
|
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), str + "第" + subList + "行未成功!"); |
|
|
|
} |
|
|
|
return new Result().ok(str);*/ |
|
|
|
erroeImport(fileList, taskId, tokenDto.getUserId()); |
|
|
|
String url = erroeImport(fileList); |
|
|
|
upImportTask(url, taskId, tokenDto.getUserId(), true); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("【党员风采信息导入】程序错误"); |
|
|
|
upImportTask(null, taskId, tokenDto.getUserId(), false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 党员风采导入,错误数据生成导入失败文件,修改导入任务为已结束 |
|
|
|
* @Description 党员风采导入,错误数据生成导入失败文件 |
|
|
|
**/ |
|
|
|
private void erroeImport(List<PartyMemberImportExcel> fileList, String importTaskId, String staffId) throws IOException { |
|
|
|
private String erroeImport(List<PartyMemberImportExcel> fileList) throws IOException { |
|
|
|
String url = ""; |
|
|
|
//1.有错误数据则生成错误数据存放文件传到阿里云服务
|
|
|
|
if (!org.springframework.util.CollectionUtils.isEmpty(fileList)) { |
|
|
@ -409,16 +415,24 @@ public class IcPartymemberStyleServiceImpl extends BaseServiceImpl<IcPartymember |
|
|
|
} |
|
|
|
url = uploadResult.getData().getUrl(); |
|
|
|
} |
|
|
|
//2.更新导入任务数据
|
|
|
|
return url; |
|
|
|
} |
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 党员风采导入修改导入任务状态 |
|
|
|
**/ |
|
|
|
private void upImportTask(String url, String importTaskId, String staffId, Boolean status) { |
|
|
|
//更新导入任务数据
|
|
|
|
ImportTaskCommonFormDTO importTaskForm = new ImportTaskCommonFormDTO(); |
|
|
|
importTaskForm.setOperatorId(staffId); |
|
|
|
importTaskForm.setBizType(ImportTaskConstants.BIZ_TYPE_PARTY_MEMBER); |
|
|
|
importTaskForm.setTaskId(importTaskId); |
|
|
|
importTaskForm.setResultDescFilePath(url); |
|
|
|
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS); |
|
|
|
if (StringUtils.isNotBlank(url)) { |
|
|
|
if (status && StringUtils.isBlank(url)) { |
|
|
|
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS); |
|
|
|
} else { |
|
|
|
importTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); |
|
|
|
importTaskForm.setResultDesc("党员风采导入存在错误数据"); |
|
|
|
importTaskForm.setResultDesc("党员风采导入存在错误"); |
|
|
|
} |
|
|
|
Result result = commonServiceOpenFeignClient.finishImportTask(importTaskForm); |
|
|
|
if (!result.success()) { |
|
|
|