|
@ -34,9 +34,12 @@ import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
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; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.dto.IcResiUserDTO; |
|
|
import com.epmet.dto.IcResiUserDTO; |
|
@ -44,9 +47,11 @@ import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.enums.IcResiUserTableEnums; |
|
|
import com.epmet.enums.IcResiUserTableEnums; |
|
|
import com.epmet.feign.OperCustomizeOpenFeignClient; |
|
|
import com.epmet.feign.OperCustomizeOpenFeignClient; |
|
|
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
import com.epmet.service.IcResiUserImportService; |
|
|
import com.epmet.service.IcResiUserImportService; |
|
|
import com.epmet.service.IcResiUserService; |
|
|
import com.epmet.service.IcResiUserService; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
import org.apache.commons.io.FilenameUtils; |
|
|
import org.apache.commons.io.FilenameUtils; |
|
|
import org.apache.commons.io.IOUtils; |
|
|
import org.apache.commons.io.IOUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
@ -57,10 +62,7 @@ import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.io.FileOutputStream; |
|
|
import java.io.*; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
|
import java.net.URLEncoder; |
|
|
import java.net.URLEncoder; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Files; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Path; |
|
@ -81,7 +83,21 @@ import java.util.concurrent.atomic.AtomicInteger; |
|
|
public class IcResiUserController { |
|
|
public class IcResiUserController { |
|
|
private static final String BASE_TABLE_NAME = "ic_resi_user"; |
|
|
private static final String BASE_TABLE_NAME = "ic_resi_user"; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 居民上传临时目录 |
|
|
|
|
|
*/ |
|
|
private Path IC_RESI_UPLOAD_DIR; |
|
|
private Path IC_RESI_UPLOAD_DIR; |
|
|
|
|
|
/** |
|
|
|
|
|
* 居民下载模版临时目录 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String OSS_TEMP_RESI_TEMP_DIR = "file-temp/resi-temp/"; |
|
|
|
|
|
/** |
|
|
|
|
|
* 本地模版缓存目录 |
|
|
|
|
|
*/ |
|
|
|
|
|
private Path IC_RESI_DOWNLOAD_DIR; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient; |
|
|
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient; |
|
@ -89,6 +105,8 @@ public class IcResiUserController { |
|
|
private IcResiUserService icResiUserService; |
|
|
private IcResiUserService icResiUserService; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private IcResiUserImportService icResiUserImportService; |
|
|
private IcResiUserImportService icResiUserImportService; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
// 初始化上传目录
|
|
|
// 初始化上传目录
|
|
@ -101,7 +119,15 @@ public class IcResiUserController { |
|
|
log.error("创建数字赋能平台上传目录失败"); |
|
|
log.error("创建数字赋能平台上传目录失败"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
IC_RESI_UPLOAD_DIR = importDir; |
|
|
Path exportDir = Paths.get(home, "epmet_files", "ic_user_export"); |
|
|
|
|
|
if (Files.notExists(exportDir)) { |
|
|
|
|
|
try { |
|
|
|
|
|
Files.createDirectories(exportDir); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
log.error("创建数字赋能平台下载目录失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
IC_RESI_DOWNLOAD_DIR = exportDir; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@PostMapping("delete") |
|
|
@PostMapping("delete") |
|
@ -248,11 +274,10 @@ public class IcResiUserController { |
|
|
/*List<FormItemResult> resiFormAllItems = getResiFormAllItems(pageFormDTO.getCustomerId()); |
|
|
/*List<FormItemResult> resiFormAllItems = getResiFormAllItems(pageFormDTO.getCustomerId()); |
|
|
resiFormAllItems.stream().collect(Collectors.groupingBy(e ->e.get));*/ |
|
|
resiFormAllItems.stream().collect(Collectors.groupingBy(e ->e.get));*/ |
|
|
|
|
|
|
|
|
//读取模版
|
|
|
//获取模版文件
|
|
|
String templatePath = "excel/ic_resi_info_cid_for_easy_excel.xlsx"; |
|
|
File file = getExportTemplateFile(customerId); |
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(templatePath); |
|
|
ExcelWriter excelWriter = EasyExcel.write(getOutputStream("居民基本信息.xlsx", response)).withTemplate(file).build(); |
|
|
String fileName = "居民基本信息.xlsx"; |
|
|
|
|
|
ExcelWriter excelWriter = EasyExcel.write(getOutputStream(fileName, response)).withTemplate(inputStream).build(); |
|
|
|
|
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build(); |
|
|
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build(); |
|
|
IcResiUserTableEnums tableEnums = IcResiUserTableEnums.getObjectByTableName(BASE_TABLE_NAME); |
|
|
IcResiUserTableEnums tableEnums = IcResiUserTableEnums.getObjectByTableName(BASE_TABLE_NAME); |
|
|
WriteSheet fistSheet = EasyExcel.writerSheet(tableEnums.getSheetNo()).build(); |
|
|
WriteSheet fistSheet = EasyExcel.writerSheet(tableEnums.getSheetNo()).build(); |
|
@ -269,8 +294,6 @@ public class IcResiUserController { |
|
|
if (resiMainTableMap.keySet().size() < pageFormDTO.getPageSize()) { |
|
|
if (resiMainTableMap.keySet().size() < pageFormDTO.getPageSize()) { |
|
|
stopSearchSet.add(BASE_TABLE_NAME); |
|
|
stopSearchSet.add(BASE_TABLE_NAME); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
System.out.println("===resiMainTableMap===" + " " + JSON.toJSONString(resiMainTableMap.values())); |
|
|
|
|
|
//写入数据
|
|
|
//写入数据
|
|
|
excelWriter.fill(new FillWrapper("t1", resiMainTableMap.values()), fillConfig, fistSheet); |
|
|
excelWriter.fill(new FillWrapper("t1", resiMainTableMap.values()), fillConfig, fistSheet); |
|
|
pageFormDTO.setPageNo(pageFormDTO.getPageNo() + 1); |
|
|
pageFormDTO.setPageNo(pageFormDTO.getPageNo() + 1); |
|
@ -301,9 +324,8 @@ public class IcResiUserController { |
|
|
if (resiChildMap.keySet().size() < pageFormDTO.getPageSize()) { |
|
|
if (resiChildMap.keySet().size() < pageFormDTO.getPageSize()) { |
|
|
stopSearchSet.add(tableName); |
|
|
stopSearchSet.add(tableName); |
|
|
} |
|
|
} |
|
|
System.out.println("===resiChildMap===" + tableName + " " + JSON.toJSONString(resiChildMap.values())); |
|
|
|
|
|
tableEnums = IcResiUserTableEnums.getObjectByTableName(tableName); |
|
|
tableEnums = IcResiUserTableEnums.getObjectByTableName(tableName); |
|
|
if (tableEnums == null){ |
|
|
if (tableEnums == null) { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
//构建新的sheet
|
|
|
//构建新的sheet
|
|
@ -323,6 +345,64 @@ public class IcResiUserController { |
|
|
excelWriter.finish(); |
|
|
excelWriter.finish(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* desc:根据客户id 下载模版文件 如果不存在则返回null |
|
|
|
|
|
* |
|
|
|
|
|
* @param customerId |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private File getExportTemplateFile(String customerId) throws Exception{ |
|
|
|
|
|
String fileType = ".xlsx"; |
|
|
|
|
|
String fileName = customerId + fileType; |
|
|
|
|
|
File file = new File(IC_RESI_DOWNLOAD_DIR.resolve(fileName).toString()); |
|
|
|
|
|
String isChanged = redisUtils.getString(RedisKeys.getResiTempChangedKey(customerId)); |
|
|
|
|
|
//如果 本地文件不存在 或者已经变动 则重新下载
|
|
|
|
|
|
if (!file.exists() || NumConstant.ONE_STR.equals(isChanged)) { |
|
|
|
|
|
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); |
|
|
|
|
|
String defaultTemplatePath = "excel/ic_resi_info_cid_for_easy_excel.xlsx"; |
|
|
|
|
|
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(defaultTemplatePath); |
|
|
|
|
|
FileUtils.copyInputStreamToFile(resourceAsStream,file); |
|
|
|
|
|
log.warn("getExportTemplateFile copy default file to template,customerId:{}",customerId); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.warn("getExportTemplateFile reload file form oss default file to template,customerId:{}",customerId); |
|
|
|
|
|
FileUtils.writeByteArrayToFile(file,result.getData()); |
|
|
|
|
|
} |
|
|
|
|
|
redisUtils.setString(RedisKeys.getResiTempChangedKey(customerId), NumConstant.ZERO_STR); |
|
|
|
|
|
return file; |
|
|
|
|
|
} |
|
|
|
|
|
return file; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
String home = System.getProperty("user.home"); |
|
|
|
|
|
Path exportDir = Paths.get(home, "epmet_files", "ic_user_export"); |
|
|
|
|
|
if (Files.notExists(exportDir)) { |
|
|
|
|
|
try { |
|
|
|
|
|
Files.createDirectories(exportDir); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
log.error("创建数字赋能平台下载目录失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
Path IC_RESI_DOWNLOAD_DIR = exportDir; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String fileType = ".xlsx"; |
|
|
|
|
|
String fileName = "customerId" + fileType; |
|
|
|
|
|
File file = new File(IC_RESI_DOWNLOAD_DIR.resolve(fileName).toString()); |
|
|
|
|
|
System.out.println("file路径:" + file); |
|
|
|
|
|
System.out.println(file.exists()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@NotNull |
|
|
@NotNull |
|
|
private Map<String, Map<String, FormItemResult>> buildItemMap(CustomerFormResultDTO resiFormItems) { |
|
|
private Map<String, Map<String, FormItemResult>> buildItemMap(CustomerFormResultDTO resiFormItems) { |
|
|
Map<String, Map<String, FormItemResult>> otherSheetItems = new HashMap<>(); |
|
|
Map<String, Map<String, FormItemResult>> otherSheetItems = new HashMap<>(); |
|
|