main
gaoshuguang 11 months ago
parent 9ece80f4f4
commit 9535d94676

@ -0,0 +1,16 @@
package com.nmgs.entity.split;
import lombok.Data;
/**
* @author: shuguang
* @date: 20241225 9:20
* @description:
*/
@Data
public class ClearItems {
private String fileId;
private Integer fileType;
private Integer count;
private Integer amount;
}

@ -0,0 +1,52 @@
package com.nmgs.entity.split;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* @author: shuguang
* @date: 20240527 11:41
* @description: 306
*/
@Data
@TableName("CT_REFUND_LATERPAY_SUM")
public class CtRefundLaterpaySum {
@TableField( "CLEARDATE")
private Date clearDate;
@TableField("PROCESSTIME")
private Date processTime;
@TableField("RECEIVEAMOUNT")
private Integer receiveAmount;
@TableField("PAYAMOUNT")
private Integer payAmount;
@TableField("AMOUNT")
private Integer amount;
@TableField("REFUNDCOUNT")
private Integer refundCount;
@TableField("RESTITUTIONCOUNT")
private Integer restitutionCount;
@TableField("RECEIVEDETAIL")
private String receiveDetail;
@TableField("PAYDETAIL")
private String payDetail;
@TableField("BASICFILENAME")
private String basicFilename;
@TableField("DATEMARK")
private Date dateMark;
@TableField("ISSPLIT")
private Integer isSplit;
@TableField("PROVRESTITUTIONCOUNT")
private Integer provrestitutionCount;
@TableField("PROVRECEIVEAMOUT")
private Integer provreceiveAmout;
@TableField("PROVREFUNDCOUNT")
private Integer provrefundCount;
@TableField("PROVPAYAMOUT")
private Integer provpayAmout;
}

@ -0,0 +1,18 @@
package com.nmgs.entity.split;
import lombok.Data;
/**
* @author: shuguang
* @date: 20240603 14:57
* @description: 306CT_REFUND_LATERPAY_SUMPAYDETAILjson
*/
@Data
public class PayDetail {
private Long amount;
private String clearItems;
private String receiverId;
private Integer receiverType;
private Integer refundCount;
private Integer restitutionCount;
}

@ -0,0 +1,18 @@
package com.nmgs.entity.split;
import lombok.Data;
/**
* @author: shuguang
* @date: 20240603 15:03
* @description: 306CT_REFUND_LATERPAY_SUMRECEIVEDETAILjson
*/
@Data
public class ReceiveDetail {
private Long amount;
private String clearItems;
private String payerId;
private Integer payerType;
private Integer refundCount;
private Integer restitutionCount;
}

@ -0,0 +1,107 @@
package com.nmgs.test;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.nmgs.entity.split.ClearItems;
import com.nmgs.entity.split.CtRefundLaterpaySum;
import com.nmgs.entity.split.PayDetail;
import com.nmgs.entity.split.ReceiveDetail;
import com.nmgs.util.DBUtil;
import com.nmgs.util.DateTimeUtil;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author: shuguang
* @date: 20240902 17:18
* @description:
*/
public class Test241225 {
public static void main(String[] args) throws Exception{
JdbcTemplate jdbcTemplate = new JdbcTemplate(new DBUtil().Hikar_DataSource_MPAY());
long startAll = System.currentTimeMillis();
int count = 0;
try {
String sql = "SELECT * FROM CT_REFUND_LATERPAY_SUM WHERE CLEARDATE > TO_DATE('2024-06-25', 'YYYY-MM-DD') ORDER BY CLEARDATE";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
if (list.size() > 0) {
for (Map<String, Object> objectMap : list) {
int provrefundCount=0;
int provpayAmout=0;
int provrestitutionCount=0;
int provreceiveAmout = 0;
Date clearDate = (Date)objectMap.get("CLEARDATE");
String date = DateTimeUtil.getFormateString(clearDate,"yyyy-MM-dd HH:mm:ss");
String payDetail = (String)objectMap.get("PAYDETAIL");
String receiveDetail = (String)objectMap.get("RECEIVEDETAIL");
List<PayDetail> jsonPayList = JSON.parseObject(payDetail, new TypeReference<List<PayDetail>>() {
});
List<ReceiveDetail> jsonReceiverList = JSON.parseObject(receiveDetail, new TypeReference<List<ReceiveDetail>>() {
});
if (jsonPayList != null && jsonPayList.size() > 0) {
for (PayDetail res : jsonPayList) {
List<ClearItems> payClearItems = JSON.parseObject(res.getClearItems(), new TypeReference<List<ClearItems>>() {
});
// 使用流来过滤fileType为2的ClearItems对象并计算count和amount的总和
provrefundCount += payClearItems.stream()
.filter(ci -> ci.getFileType() == 2)
.mapToInt(ClearItems::getCount)
.sum();
provpayAmout += payClearItems.stream()
.filter(ci -> ci.getFileType() == 2)
.mapToInt(ClearItems::getAmount)
.sum();
}
}
if (jsonReceiverList != null && jsonReceiverList.size() > 0) {
for (ReceiveDetail res : jsonReceiverList) {
List<ClearItems> receiveClearItems = JSON.parseObject(res.getClearItems(), new TypeReference<List<ClearItems>>() {
});
// 使用流来过滤fileType为3的ClearItems对象并计算count和amount的总和
provrestitutionCount += receiveClearItems.stream()
.filter(ci -> ci.getFileType() == 3)
.mapToInt(ClearItems::getCount)
.sum();
provreceiveAmout += receiveClearItems.stream()
.filter(ci -> ci.getFileType() == 3)
.mapToInt(ClearItems::getAmount)
.sum();
}
}
String updateSql = "UPDATE ct_refund_laterpay_sum SET PROVREFUNDCOUNT = " + provrefundCount + ",PROVPAYAMOUT = " + provpayAmout + ",PROVRESTITUTIONCOUNT = " + provrestitutionCount + ",PROVRECEIVEAMOUT = " + provreceiveAmout + " WHERE CLEARDATE = TO_DATE('" + date +"', 'yyyy-MM-dd HH24:mi:ss')";
System.out.println(updateSql);
int update = jdbcTemplate.update(updateSql);
System.out.println("更新行数"+update);
count++;
}
}
} catch (Exception e) {
System.out.println("程序错误:" + e.getMessage());
}
long endAll = System.currentTimeMillis();
System.out.println("累积更新行数"+count+"------------处理总耗时:"+(endAll-startAll)+"毫秒");
}
}
Loading…
Cancel
Save