|
|
@ -17,41 +17,56 @@ |
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
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.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.FileUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.UserDemandConstant; |
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
|
import com.epmet.dao.IcSocietyOrgDao; |
|
|
|
import com.epmet.dto.CustomerStaffDTO; |
|
|
|
import com.epmet.dto.IcSocietyOrgDTO; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.form.demand.ServiceQueryFormDTO; |
|
|
|
import com.epmet.dto.result.GetListSocietyOrgResultDTO; |
|
|
|
import com.epmet.dto.result.OrgInfoResultDTO; |
|
|
|
import com.epmet.dto.result.SocietyOrgListResultDTO; |
|
|
|
import com.epmet.dto.result.StaffSinGridResultDTO; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.dto.result.demand.OptionDTO; |
|
|
|
import com.epmet.entity.IcSocietyOrgEntity; |
|
|
|
import com.epmet.excel.IcSocietyOrgExcel; |
|
|
|
import com.epmet.excel.IcSocietyOrgImportExcelDTO; |
|
|
|
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
|
import com.epmet.service.IcSocietyOrgService; |
|
|
|
import com.epmet.service.IcUserDemandRecService; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
import org.apache.commons.fileupload.FileItemFactory; |
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -71,6 +86,10 @@ public class IcSocietyOrgServiceImpl extends BaseServiceImpl<IcSocietyOrgDao, Ic |
|
|
|
private IcUserDemandRecService icUserDemandRecService; |
|
|
|
@Autowired |
|
|
|
private GovOrgOpenFeignClient govOrgOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
@ -308,4 +327,97 @@ public class IcSocietyOrgServiceImpl extends BaseServiceImpl<IcSocietyOrgDao, Ic |
|
|
|
return ConvertUtils.sourceToTarget(entity,IcSocietyOrgDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入社会组织,之前的废弃了 |
|
|
|
* |
|
|
|
* @param filePath |
|
|
|
* @param importTaskId |
|
|
|
* @param customerId |
|
|
|
* @param userId |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void execAsyncExcelImport(Path filePath, String importTaskId,String customerId,String userId) { |
|
|
|
try { |
|
|
|
//获取当前登录用户所属组织id
|
|
|
|
CustomerStaffInfoCacheResult staffInfo= queryCurrentStaff(customerId,userId); |
|
|
|
|
|
|
|
// todo
|
|
|
|
/*IcEnterpriseExcelImportListener listener = new IcEnterpriseExcelImportListener(customerId,staffInfo, this); |
|
|
|
EasyExcel.read(filePath.toFile(), IcSocietyOrgImportExcelDTO.class, listener).headRowNumber(1).sheet(0).doRead();*/ |
|
|
|
|
|
|
|
Path errorDescFile = null; |
|
|
|
String errorDesFileUrl = null; |
|
|
|
List<IcSocietyOrgImportExcelDTO.ErrorRow> errorRows = null;// todo listener.getErrorRows();
|
|
|
|
|
|
|
|
boolean failed = errorRows.size() > 0; |
|
|
|
if (failed) { |
|
|
|
// 生成并上传错误文件
|
|
|
|
try { |
|
|
|
// 文件生成
|
|
|
|
Path errorDescDir = FileUtils.getAndCreateDirUnderEpmetFilesDir("ic_enterprise", "import", "error_des"); |
|
|
|
String fileName = UUID.randomUUID().toString().concat(".xlsx"); |
|
|
|
errorDescFile = errorDescDir.resolve(fileName); |
|
|
|
|
|
|
|
FileItemFactory factory = new DiskFileItemFactory(16, errorDescDir.toFile()); |
|
|
|
FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, fileName); |
|
|
|
OutputStream os = fileItem.getOutputStream(); |
|
|
|
|
|
|
|
EasyExcel.write(os, IcSocietyOrgImportExcelDTO.ErrorRow.class).sheet("导入失败列表").doWrite(errorRows); |
|
|
|
|
|
|
|
// 文件上传oss
|
|
|
|
Result<UploadImgResultDTO> errorDesFileUploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); |
|
|
|
if (errorDesFileUploadResult.success()) { |
|
|
|
errorDesFileUrl = errorDesFileUploadResult.getData().getUrl(); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
if (Files.exists(errorDescFile)) { |
|
|
|
Files.delete(errorDescFile); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO(); |
|
|
|
importFinishTaskForm.setTaskId(importTaskId); |
|
|
|
importFinishTaskForm.setProcessStatus(failed ? ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL : ImportTaskConstants.PROCESS_STATUS_FINISHED_SUCCESS); |
|
|
|
importFinishTaskForm.setOperatorId(userId); |
|
|
|
importFinishTaskForm.setResultDesc(""); |
|
|
|
importFinishTaskForm.setResultDescFilePath(errorDesFileUrl); |
|
|
|
|
|
|
|
Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm); |
|
|
|
if (!result.success()) { |
|
|
|
log.error("【社会组织】finishImportTask失败"); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
String errorMsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
log.error("【社会组织】出错:{}", errorMsg); |
|
|
|
|
|
|
|
ImportTaskCommonFormDTO importFinishTaskForm = new ImportTaskCommonFormDTO(); |
|
|
|
importFinishTaskForm.setTaskId(importTaskId); |
|
|
|
importFinishTaskForm.setProcessStatus(ImportTaskConstants.PROCESS_STATUS_FINISHED_FAIL); |
|
|
|
importFinishTaskForm.setOperatorId(userId); |
|
|
|
importFinishTaskForm.setResultDesc("导入失败"); |
|
|
|
|
|
|
|
Result result = commonServiceOpenFeignClient.finishImportTask(importFinishTaskForm); |
|
|
|
if (!result.success()) { |
|
|
|
log.error("【社会组织】导入记录状态修改为'完成'失败"); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
// 删除临时文件
|
|
|
|
if (Files.exists(filePath)) { |
|
|
|
try { |
|
|
|
Files.delete(filePath); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("method exception", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private CustomerStaffInfoCacheResult queryCurrentStaff(String customerId, String userId) { |
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId); |
|
|
|
if (null == staffInfo) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询工作人员缓存信息异常", EpmetErrorCode.SERVER_ERROR.getMsg()); |
|
|
|
} |
|
|
|
return staffInfo; |
|
|
|
} |
|
|
|
} |
|
|
|