Commit 50ea7b4a authored by chenzhao's avatar chenzhao

增加聚富通导出 增加定时获取回盘文件

parent 5a4cb052
## DB properties hygf
## db1-production database
spring.db1.datasource.type: com.alibaba.druid.pool.DruidDataSource
spring.db1.datasource.url=jdbc:mysql://47.92.234.253:13306/amos_openapi?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.db1.datasource.url=jdbc:kingbase8://39.98.224.23:54321/amos_openapi_47?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.db1.datasource.username=root
spring.db1.datasource.password=Yeejoin_1234
spring.db1.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.db1.datasource.password=Yeejoin@2020
spring.db1.datasource.driver-class-name=com.kingbase8.Driver
## db2-sync_data
spring.db2.datasource.type: com.alibaba.druid.pool.DruidDataSource
spring.db2.datasource.url=jdbc:mysql://47.92.234.253:13306/amos_project?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.db2.datasource.url=jdbc:kingbase8://39.98.224.23:54321/amos_project_47?allowMultiQueries=true&serverTimezone=GMT%2B8&characterEncoding=utf8
spring.db2.datasource.username=root
spring.db2.datasource.password=Yeejoin_1234
spring.db2.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.db2.datasource.password=Yeejoin@2020
spring.db2.datasource.driver-class-name=com.kingbase8.Driver
## db3-taosiData
spring.db3.datasource.type: com.alibaba.druid.pool.DruidDataSource
spring.db3.datasource.url=jdbc:TAOS-RS://47.92.234.253:6041/house_pv_data?user=root&password=taosdata&characterEncoding=utf8
......
......@@ -56,7 +56,7 @@ public class HygfIcbcRecordExportDTO {
/**
* 聚富通电子账户账号
*/
@ExcelProperty(value = "银行卡号", index = 4)
@ExcelProperty(value = "聚富通账户", index = 4)
@ApiModelProperty (value = "聚富通电子账户账号")
private String mediumId;
......@@ -74,7 +74,12 @@ public class HygfIcbcRecordExportDTO {
@ApiModelProperty (value = "协议状态, 0-未生效,1-已生效,2-过期,3-作废,4-待短信确认")
private String protocolStatus;
/**
* 协议状态, 0-未生效,1-已生效,2-过期,3-作废,4-待短信确认
*/
@ExcelProperty(value = "扣款总金额", index = 7)
@ApiModelProperty (value = "扣款总金额")
private double paymentAmount;
}
\ No newline at end of file
package com.yeejoin.amos.boot.module.hygf.api.dto;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* (hygf_icbc_record)实体类
*
* @author yangyang
* @description
* @since 2024-07-18 11:40:46
*/
@Data
@NoArgsConstructor
@ApiModel (value = "HygfIcbcRecordExportDTO", description = "聚富通钱包开户DTO")
public class HygfIcbcWithholdRecordExportDTO {
@ExcelIgnore
private static final long serialVersionUID = 1L;
@ExcelIgnore
protected Long sequenceNbr;
@ExcelProperty(value = "开户名", index = 0)
@ApiModelProperty (value = "开户名")
private String custName;
/**
* 身份证号
*/
@ExcelProperty(value = "项目公司", index = 1)
@ApiModelProperty(value = "项目公司")
private String regionalCompaniesName;
/**
* 手机号码
*/
@ExcelProperty(value = "批次号", index = 2)
@ApiModelProperty (value = "批次号")
private String batchNo;
/**
* 聚富通电子账户账号
*/
@ExcelProperty(value = "聚富通账户", index = 3)
@ApiModelProperty (value = "聚富通电子账户账号")
private String mediumId;
/**
*
*/
@ExcelProperty(value = "扣款金额", index = 4)
@ApiModelProperty (value = "扣款金额")
private double paymentAmount;
@ExcelProperty(value = "扣款状态", index = 5)
@ApiModelProperty (value = "扣款状态")
private String withholdStatus;
@ExcelProperty(value = "扣款时间", index = 6)
@ApiModelProperty (value = "扣款时间")
private Date paymentTime;
@ExcelProperty(value = "操作人", index = 7)
@ApiModelProperty (value = "操作人")
private String uploader;
@ExcelProperty(value = "说明", index =8)
@ApiModelProperty (value = "说明")
private String desc;
}
\ No newline at end of file
......@@ -114,7 +114,7 @@ public class IcbcWithhold extends BaseEntity {
private String paymentErrorDesc;
/**
* 户主icbcid
* 户主icbcid 弃用冗余 传递导出参数使用
*/
@TableField("icbc_id")
private String icbcId;
......
......@@ -32,4 +32,7 @@ public interface HygfIcbcRecordMapper extends BaseMapper<HygfIcbcRecord> {
@UserEmpower (field = {"ph.regional_companies_code"}, dealerField = {"ph.developer_code", "ph.regional_companies_code", "ph.developer_user_id"}, fieldConditions = {"in", "in", "in"}, relationship = "and")
List<HygfIcbcRecordExportDTO> exportTotal(String developerCode, String regionalCompaniesCode, String province, String city, String district);
@UserEmpower (field = {"ph.regional_companies_code"}, dealerField = {"ph.developer_code", "ph.regional_companies_code", "ph.developer_user_id"}, fieldConditions = {"in", "in", "in"}, relationship = "and")
List<HygfIcbcRecordExportDTO> paymentAmountExport(String developerCode, String regionalCompaniesCode, String province, String city, String district);
}
......@@ -316,7 +316,7 @@ public class SFTPUtil {
// return success;
// }
public boolean downloadAndZipFiles(String remotePath, String filenamePattern, String localZipPath) {
public boolean downloadAndZipFiles(String remotePath, String filenamePattern, String localZipPath,Boolean flag) {
boolean success = false;
Path tempDir = null;
try {
......@@ -336,7 +336,10 @@ public class SFTPUtil {
downloadedFiles.add(localFilePath);
}
}
disconnect();
if (flag){
disconnect();
}
// 确保本地ZIP路径的父目录存在
Path localZipFilePath = Paths.get(localZipPath);
Path parentDir = localZipFilePath.getParent();
......
......@@ -180,10 +180,13 @@
'待短信确认' ELSE''
END
) AS protocolStatus,
MAX( CASE re.open_account_status WHEN 02 THEN '开户成功' WHEN 03 THEN '开户失败' ELSE'未开户' END ) AS openAccountStatus
MAX( CASE re.open_account_status WHEN 02 THEN '开户成功' WHEN 03 THEN '开户失败' ELSE'未开户' END ) AS openAccountStatus,
SUM(iw.payment_amount) as paymentAmount
FROM
`hygf_peasant_household` ph
LEFT JOIN hygf_icbc_record re ON re.amos_user_id = ph.amos_user_id
LEFT JOIN hygf_icbc_withhold_record iw ON re.amos_user_id = iw.amos_user_id
<where>
<if test="developerCode != null and developerCode != ''">
AND ph.developer_code = #{developerCode}
......@@ -204,4 +207,67 @@
GROUP BY
ph.amos_user_id
</select>
<select id="paymentAmountExport" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.HygfIcbcRecordExportDTO">
WITH PaymentAmounts AS (
SELECT
iw.amos_user_id,
SUM(iw.payment_amount) AS paymentAmount
FROM
hygf_icbc_withhold_record iw
WHERE
iw.withhold_status = '成功'
GROUP BY
iw.amos_user_id
)
SELECT
MAX(ph.owners_name) AS custName,
MAX(ph.telephone) AS phone,
MAX(ph.id_card) AS idCard,
MAX(ph.regional_companies_name) AS regionalCompaniesName,
MAX(re.medium_id) AS mediumId,
MAX(
CASE re.protocol_status
WHEN 0 THEN '未生效'
WHEN 1 THEN '已生效'
WHEN 2 THEN '过期'
WHEN 3 THEN '作废'
WHEN 4 THEN '待短信确认'
ELSE ''
END
) AS protocolStatus,
MAX(
CASE re.open_account_status
WHEN '02' THEN '开户成功'
WHEN '03' THEN '开户失败'
ELSE '未开户'
END
) AS openAccountStatus,
pa.paymentAmount AS paymentAmount
FROM
`hygf_peasant_household` ph
LEFT JOIN
hygf_icbc_record re ON re.amos_user_id = ph.amos_user_id
LEFT JOIN
PaymentAmounts pa ON pa.amos_user_id = ph.amos_user_id
<where>
<if test="developerCode != null and developerCode != ''">
AND ph.developer_code = #{developerCode}
</if>
<if test="regionalCompaniesCode != null and regionalCompaniesCode != ''">
AND ph.regional_companies_code = #{regionalCompaniesCode}
</if>
<if test="province != null and province != ''">
AND ph.project_address LIKE CONCAT ('%',#{province},'%')
</if>
<if test="city != null and city != ''">
AND ph.project_address LIKE CONCAT ('%',#{city},'%')
</if>
<if test="district != null and district != ''">
AND ph.project_address LIKE CONCAT ('%',#{district},'%')
</if>
</where>
GROUP BY
ph.amos_user_id, pa.paymentAmount;
</select>
</mapper>
\ No newline at end of file
......@@ -8,6 +8,7 @@ import com.yeejoin.amos.boot.module.hygf.api.dto.IcbcWithholdRecordDto;
import com.yeejoin.amos.boot.module.hygf.api.entity.IcbcWithhold;
import com.yeejoin.amos.boot.module.hygf.api.entity.IcbcWithholdRecord;
import com.yeejoin.amos.boot.module.hygf.api.util.CommonResponseNewUtil;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
......@@ -16,6 +17,8 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import com.yeejoin.amos.boot.module.hygf.biz.service.impl.IcbcWithholdServiceImpl;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
......@@ -157,9 +160,11 @@ public class IcbcWithholdController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "POST",value = " 聚富通代扣信息文件生成", notes = " 聚富通代扣信息文件生成")
@PostMapping(value = "/fileGeneration")
public ResponseModel fileGeneration(@RequestBody IcbcWithhold model ) throws Exception {
icbcWithholdServiceImpl.fileGeneration(model);
@Transactional
public ResponseModel fileGeneration(@RequestBody List<IcbcWithhold> models ) throws Exception {
for (IcbcWithhold model : models) {
icbcWithholdServiceImpl.fileGeneration(model);
}
return CommonResponseNewUtil.success();
}
/**
......@@ -170,9 +175,12 @@ public class IcbcWithholdController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET",value = " 聚富通代扣信息文件上传", notes = " 聚富通代扣信息文件上传")
@GetMapping(value = "/sftpUploadAndUnzip")
public ResponseModel sftpUploadAndUnzip( String fileUrl,String batchNo ) throws Exception {
@Transactional
public ResponseModel sftpUploadAndUnzip(List<Map<String,String>> maps) throws Exception {
ReginParams reginParams = getSelectedOrgInfo();
icbcWithholdServiceImpl.sftpUploadAndUnzip(fileUrl,batchNo,reginParams.getUserModel().getRealName());
for (Map<String, String> map : maps) {
icbcWithholdServiceImpl.sftpUploadAndUnzip(map.get("fileUrl"),map.get("batchNo"),reginParams.getUserModel().getRealName());
}
return CommonResponseNewUtil.success();
}
......@@ -207,7 +215,7 @@ public class IcbcWithholdController extends BaseController {
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "POST",value = "批次人员信息下载", notes = "批次人员信息下载")
@ApiOperation(httpMethod = "POST",value = "批次明细信息下载", notes = "批次明细信息下载")
@PostMapping(value = "/export")
public void downTemplate(HttpServletResponse response, @RequestBody IcbcWithhold model ) {
......
......@@ -91,6 +91,8 @@ public class IcbcWithholdServiceImpl extends BaseService<IcbcWithholdDto,IcbcWit
public String sftpIp;
@Value("${icbc.Withhold.sftpPort}")
public int sftpPort;
@Autowired
IcbcWithholdRecordMapper icbcWithholdRecordMapper;
@Value("${icbc.Withhold.sftpUserName}")
public String sftpUserName;
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
......@@ -125,6 +127,7 @@ public class IcbcWithholdServiceImpl extends BaseService<IcbcWithholdDto,IcbcWit
* 生成文件
*
*/
public void fileGeneration(IcbcWithhold model) throws Exception {
model.setUploadStatus(UploadStatusEnum.未上传.getName());
int billNo = 0;
......@@ -381,57 +384,124 @@ public class IcbcWithholdServiceImpl extends BaseService<IcbcWithholdDto,IcbcWit
IcbcWithhold model = this.getBaseMapper().selectById(sequenceNbr);
if (StringUtils.isNotEmpty(model.getReceiptFile())){
this.downloadAndSaveZipFile(model.getReceiptFile(),batchNo,"回盘文件",response);
}else {
String path = new ClassPathResource(file+"secretKey/登录-gxjrid_rsa").getPath();
SFTPUtil sftp = new SFTPUtil(sftpIp, sftpPort,
sftpUserName,
path, null);
logger.info(String.valueOf(new StringBuffer().append("服务器地址: ")
.append(sftp.getHostName()).append(" 端口:")
.append(sftp.getPort()).append("用户名:")
.append(sftp.getUserName()).append("密钥文件:")
.append(sftp.getPriKeyFile())));
sftp.priKeyConnect();
Path currentWorkingDir = Paths.get("");
Path dirPath = currentWorkingDir.resolve(batchNo);
try {
if (!Files.exists(dirPath)) {
Files.createDirectories(dirPath);
System.out.println("Directory created: " + dirPath);
} else {
System.out.println("Directory already exists: " + dirPath);
}
} catch (IOException e) {
e.printStackTrace();
System.err.println("Failed to create directory: " + dirPath);
}
System.out.println("Current working directory: " + System.getProperty("user.dir"));
if (sftp.isExist(downLoadPath)) {
sftp.downloadAndZipFiles(downLoadPath,batchNo,dirPath.toString()+"/"+batchNo+".zip",true);
logger.info("文件下载成功");
}
try {
MultipartFile multipartFile = fileToMultipartFile(new File(dirPath.toString() + "/" + batchNo + ".zip"));
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile);
if (result != null) {
for (String url : result.getResult().keySet()) {
model.setReceiptFile(url);
}
this.saveOrUpdate(model);
this.downloadAndSaveZipFile(model.getReceiptFile(),batchNo,"回盘文件",response);
}
} catch ( Exception e) {
logger.error("平台上传文件失败");
e.printStackTrace();
} finally {
cleanup(dirPath);
}
}
String path = new ClassPathResource(file+"secretKey/登录-gxjrid_rsa").getPath();
SFTPUtil sftp = new SFTPUtil(sftpIp, sftpPort,
}
@Scheduled(cron = "${withholdReceiptFileCron}")
void setReceiptFile() throws Exception {
String path = new ClassPathResource(file+"secretKey/登录-gxjrid_rsa").getPath();
SFTPUtil sftp = new SFTPUtil(sftpIp, sftpPort,
sftpUserName,
path, null);
path, null);
logger.info(String.valueOf(new StringBuffer().append("服务器地址: ")
.append(sftp.getHostName()).append(" 端口:")
.append(sftp.getPort()).append("用户名:")
.append(sftp.getUserName()).append("密钥文件:")
.append(sftp.getPriKeyFile())));
sftp.priKeyConnect();
Path currentWorkingDir = Paths.get("");
Path dirPath = currentWorkingDir.resolve(batchNo);
try {
if (!Files.exists(dirPath)) {
Files.createDirectories(dirPath);
System.out.println("Directory created: " + dirPath);
} else {
System.out.println("Directory already exists: " + dirPath);
}
} catch (IOException e) {
e.printStackTrace();
System.err.println("Failed to create directory: " + dirPath);
}
System.out.println("Current working directory: " + System.getProperty("user.dir"));
if (sftp.isExist(downLoadPath)) {
sftp.downloadAndZipFiles(downLoadPath,batchNo,dirPath.toString()+"/"+batchNo+".zip");
logger.info("文件下载成功");
}
try {
MultipartFile multipartFile = fileToMultipartFile(new File(dirPath.toString() + "/" + batchNo + ".zip"));
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile);
if (result != null) {
for (String url : result.getResult().keySet()) {
model.setReceiptFile(url);
//获取所有已上传但代扣状态为空的数据
LambdaQueryWrapper<IcbcWithhold> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IcbcWithhold::getWithholdStatus,UploadStatusEnum.成功.getName()).or().eq(IcbcWithhold::getWithholdStatus,UploadStatusEnum.失败.getName());
wrapper.isNull(IcbcWithhold::getReceiptFile);
List<IcbcWithhold> icbcWithholds = this.getBaseMapper().selectList(wrapper);
boolean flag = false;
Iterator<IcbcWithhold> iterator = icbcWithholds.iterator();
while (iterator.hasNext()){
IcbcWithhold model = iterator.next();
Path currentWorkingDir = Paths.get("");
Path dirPath = currentWorkingDir.resolve(model.getBatchNo());
//没有下一个元素的时候关闭连接
if (!iterator.hasNext()){
flag = true;
}
try {
if (!Files.exists(dirPath)) {
Files.createDirectories(dirPath);
System.out.println("Directory created: " + dirPath);
} else {
System.out.println("Directory already exists: " + dirPath);
}
} catch (IOException e) {
e.printStackTrace();
System.err.println("Failed to create directory: " + dirPath);
}
System.out.println("Current working directory: " + System.getProperty("user.dir"));
if (sftp.isExist(downLoadPath)) {
sftp.downloadAndZipFiles(downLoadPath,model.getBatchNo(),dirPath.toString()+"/"+model.getBatchNo()+".zip",flag);
logger.info("文件下载成功");
}
try {
MultipartFile multipartFile = fileToMultipartFile(new File(dirPath.toString() + "/" + model.getBatchNo() + ".zip"));
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile);
if (result != null) {
for (String url : result.getResult().keySet()) {
model.setReceiptFile(url);
}
this.saveOrUpdate(model);
}
} catch ( Exception e) {
logger.error("平台上传文件失败");
e.printStackTrace();
} finally {
cleanup(dirPath);
}
this.saveOrUpdate(model);
this.downloadAndSaveZipFile(model.getReceiptFile(),batchNo,"回盘文件",response);
}
} catch ( Exception e) {
logger.error("平台上传文件失败");
e.printStackTrace();
} finally {
cleanup(dirPath);
}
}
}
@Scheduled(cron = "${withholdStatusCron}")
public void updateWithholdStatus() throws Exception {
//获取所有已上传但代扣状态为空的数据
......@@ -519,6 +589,7 @@ public class IcbcWithholdServiceImpl extends BaseService<IcbcWithholdDto,IcbcWit
* @param fileUrl 文件url地址
* @param batchNo 批次号
*/
@Async
public void sftpUploadAndUnzip(String fileUrl,String batchNo,String uploader ) {
Path currentWorkingDir = Paths.get("");
Path dirPath = currentWorkingDir.resolve(batchNo);
......@@ -643,18 +714,25 @@ public class IcbcWithholdServiceImpl extends BaseService<IcbcWithholdDto,IcbcWit
public void exportData(HttpServletResponse response, IcbcWithhold icbcWithhold ){
List<HygfIcbcRecordExportDTO> dtos = new ArrayList<>();
JSONArray.parseArray(icbcWithhold.getIcbcRecordInfos(),IcbcWithholdRecord.class).forEach(e->{
HygfIcbcRecordExportDTO hygfIcbcRecordExportDTO = new HygfIcbcRecordExportDTO();
BeanUtil.copyProperties(e,hygfIcbcRecordExportDTO);
hygfIcbcRecordExportDTO.setOpenAccountStatus(e.getOpenAccountStatusName());
hygfIcbcRecordExportDTO.setProtocolStatus(e.getProtocolStatusName());
dtos.add(hygfIcbcRecordExportDTO);
});
List<HygfIcbcWithholdRecordExportDTO> datas = new ArrayList<>();
IcbcWithholdRecordDto dto = new IcbcWithholdRecordDto();
if (StringUtils.isNotEmpty(icbcWithhold.getBatchNo())){
dto.setBatchNo(icbcWithhold.getBatchNo());
}
if (StringUtils.isNotEmpty(icbcWithhold.getIcbcId())){
dto.setAmosUserId(icbcWithhold.getIcbcId());
}
List<IcbcWithholdRecordDto> dtos = icbcWithholdRecordMapper.exportTotal(null, null, null, null, null,null,null,null,dto);
for (IcbcWithholdRecordDto icbcWithholdRecordDto : dtos) {
HygfIcbcWithholdRecordExportDTO exportDTO = new HygfIcbcWithholdRecordExportDTO();
BeanUtil.copyProperties(icbcWithholdRecordDto,exportDTO);
exportDTO.setDesc(icbcWithhold.getDesc());
datas.add(exportDTO);
}
if (CollectionUtil.isNotEmpty(dtos)){
ExcelUtil.createTemplate(response,icbcWithhold.getBatchNo()+"人员信息",icbcWithhold.getBatchNo()+"人员信息",dtos,HygfIcbcRecordExportDTO.class,null,false);
if (CollectionUtil.isNotEmpty(datas)){
ExcelUtil.createTemplate(response,icbcWithhold.getBatchNo()+"人员信息",icbcWithhold.getBatchNo()+"人员信息",datas,HygfIcbcRecordExportDTO.class,null,false);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment