update 新增算法sha3x xtm币种,后台管理系统优化钱包出入账信息

This commit is contained in:
yyb
2025-09-28 13:48:27 +08:00
parent ef395c5253
commit 2efa65222d
22 changed files with 670 additions and 92 deletions

View File

@@ -2,11 +2,9 @@ package com.m2pool.manage.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@@ -19,9 +17,13 @@ import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ManageWalletOutIn {
@EqualsAndHashCode(callSuper = false)
public class ManageWalletOutIn implements Serializable {
private static final long serialVersionUID=1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private Long id;
private String coin;
@@ -29,7 +31,9 @@ public class ManageWalletOutIn {
private String address;
private LocalDateTime date;
private LocalDateTime dateIn;
private LocalDateTime dateOut;
private LocalDateTime shouldOutDate;

View File

@@ -137,6 +137,7 @@ public class ManageDocumentsServiceImpl extends ServiceImpl<ManageDocumentsMappe
@Override
public R<String> deleteDocument(ManageBaseVo manageBaseVo) {
//int i = manageDocumentsMapper.updateById(ManageDocuments.builder().id(manageBaseVo.getId()).del(true).build());
int delete = manageDocumentsMapper.deleteById(manageBaseVo.getId());
DeleteResult remove = mongoTemplate.remove(new Query(Criteria.where("id").is(manageBaseVo.getId())), "documents");
if (delete > 0){

View File

@@ -1,5 +1,6 @@
package com.m2pool.manage.task;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.m2pool.common.core.utils.DateUtils;
import com.m2pool.manage.entity.ManageWalletOutIn;
@@ -42,88 +43,88 @@ public class ManageTask {
/**
* 存储交易记录定时任务
*/
//@Scheduled(cron = "22 58 0/1 * * ?")
//@Scheduled(cron = "22 25 0/1 * * ?")
@Scheduled(cron = "0 0/1 * * * ?")
@DSTransactional
public void insertDataToWalletOutInDb(){
LocalDateTime maxDateData = manageWalletOutInMapper.getMaxDateData();
LocalDateTime startDate = null;
List<ManageWalletOutIn> manageWalletOutIns = new ArrayList<>();
if (maxDateData != null){
startDate = LocalDateTime.now().toLocalDate().atStartOfDay();
//获取startDate 后的数据,用于比对
manageWalletOutIns = manageWalletOutInMapper.selectList(new LambdaQueryWrapper<ManageWalletOutIn>()
.ge(ManageWalletOutIn::getDate, startDate));
.ge(ManageWalletOutIn::getDateIn, maxDateData));
}
List<ManageWalletOutIn> walletIn = manageWalletOutInMapper.getWalletIn(startDate);
List<ManageWalletOutIn> walletOut = manageWalletOutInMapper.getWalletOut(startDate);
List<ManageWalletOutIn> walletIn = manageWalletOutInMapper.getWalletIn(maxDateData);
List<ManageWalletOutIn> walletOut = manageWalletOutInMapper.getWalletOut(maxDateData);
//date_in 是in表实际入账时间;in表带有预计转账时间should_out_date
Map<String, List<ManageWalletOutIn>> walletInMap = walletIn.stream()
.collect(Collectors.groupingBy(item ->
item.getUser() + item.getCoin() + item.getDate().toLocalDate().atStartOfDay()
item.getUser() + item.getCoin() + item.getShouldOutDate().toLocalDate().atStartOfDay()
));
//date_out 是out表实际转账时间
Map<String, List<ManageWalletOutIn>> walletOutMap = walletOut.stream()
.collect(Collectors.groupingBy(item ->
item.getUser() + item.getCoin() + item.getDate().toLocalDate().atStartOfDay()
item.getUser() + item.getCoin() + item.getDateOut().toLocalDate().atStartOfDay()
));
List<ManageWalletOutIn> walletInfo = new ArrayList<>();
//外层为out内层为in
// 比较 out 和 in 表的 date_out 和 date_in 以及 max_height 字段,如果都相同,则组合成一条数据
for (Map.Entry<String, List<ManageWalletOutIn>> outEntry : walletOutMap.entrySet()) {
String key = outEntry.getKey();
String outKey = outEntry.getKey();
List<ManageWalletOutIn> outList = outEntry.getValue();
if (walletInMap.containsKey(key)) {
List<ManageWalletOutIn> inList = walletInMap.get(key);
// 处理 outList 与 inList 匹配的项
List<ManageWalletOutIn> updatedOutList = outList.stream()
.peek(outItem -> inList.stream()
.filter(inItem -> outItem.getMaxHeight().equals(inItem.getMaxHeight()))
.findFirst()
.ifPresent(inItem -> {
outItem.setShouldOutDate(inItem.getShouldOutDate());
outItem.setAllocationAmount(inItem.getAllocationAmount());
}))
// inList 中包含 outMap 的 key则说明有相同的数据这个时候比对 max_height
if (walletInMap.containsKey(outKey)) {
List<ManageWalletOutIn> inList = walletInMap.get(outKey);
List<ManageWalletOutIn> insertOutList = outList.stream()
.peek(outItem -> {
outItem.setDateIn(outItem.getDateOut());
inList.stream()
.filter(inItem -> outItem.getMaxHeight().equals(inItem.getMaxHeight()))
.findFirst()
.ifPresent(inItem -> {
// 前期一些 in 表没有 should_out_date 存储为空
LocalDateTime shouldOutDate = inItem.getShouldOutDate();
outItem.setShouldOutDate(shouldOutDate != null ? shouldOutDate : outItem.getDateOut().toLocalDate().atStartOfDay());
outItem.setDateIn(inItem.getDateIn());
outItem.setAllocationAmount(inItem.getAllocationAmount());
});
})
.collect(Collectors.toList());
walletInfo.addAll(updatedOutList);
walletInfo.addAll(insertOutList);
// 处理 inList 中未匹配的项
List<ManageWalletOutIn> updatedInList = inList.stream()
// inList 中如果没有任何匹配的 outList 数据,则把 inList 数据添加到 walletInfo 中
List<ManageWalletOutIn> insertInList = inList.stream()
.filter(inItem -> outList.stream()
.noneMatch(outItem -> outItem.getMaxHeight().equals(inItem.getMaxHeight())))
.noneMatch(outItem -> inItem.getMaxHeight().equals(outItem.getMaxHeight())))
.collect(Collectors.toList());
walletInfo.addAll(updatedInList);
walletInfo.addAll(insertInList);
} else {
List<ManageWalletOutIn> collect = outList.stream().peek(outItem -> {
if (outItem.getShouldOutDate() == null) {
outItem.setShouldOutDate(outItem.getDate().toLocalDate().atStartOfDay());
}
}).collect(Collectors.toList());
walletInfo.addAll(collect);
// 只有 walletOut没有对应的 walletIn
walletInfo.addAll(outList);
}
}
//外层为in内层为out -----新增当天只有walletIn,没有walletOut的数据
for (Map.Entry<String, List<ManageWalletOutIn>> inEntry : walletInMap.entrySet()) {
String key = inEntry.getKey();
// 当天只有 walletIn没有 walletOut 的数据
for (Map.Entry<String, List<ManageWalletOutIn>> outEntry : walletInMap.entrySet()) {
String key = outEntry.getKey();
if (!walletOutMap.containsKey(key)) {
walletInfo.addAll(inEntry.getValue());
walletInfo.addAll(outEntry.getValue());
}
}
List<ManageWalletOutIn> collect = walletInfo.stream().sorted(Comparator.comparing(ManageWalletOutIn::getDate)).collect(Collectors.toList());
//查询ManageWalletOutIn 数据,比对是否修改
if (!manageWalletOutIns.isEmpty()){
List<ManageWalletOutIn> updateList = new ArrayList<>();
List<ManageWalletOutIn> saveList = new ArrayList<>();
for (ManageWalletOutIn item : collect) {
for (ManageWalletOutIn item : walletInfo) {
manageWalletOutIns.stream()
.filter(dbItem -> dbItem.getCoin().equals(item.getCoin())
&& dbItem.getUser().equals(item.getUser())
&& dbItem.getMaxHeight().equals(item.getMaxHeight())
&& dbItem.getDate().toLocalDate().atStartOfDay().equals(item.getDate().toLocalDate().atStartOfDay()))
&& dbItem.getDateIn().toLocalDate().atStartOfDay().equals(item.getDateIn().toLocalDate().atStartOfDay()))
.findFirst()
.ifPresent(dbItem -> {
// 若找到匹配项,设置 id 并添加到 updateList
@@ -136,15 +137,16 @@ public class ManageTask {
}
}
if (!updateList.isEmpty()){
boolean update = manageWalletOutInService.updateBatchById(updateList);
System.out.println("walletOutIn 修改"+update);
System.out.println("walletOutIn 修改"+updateList.size());
}
if (!saveList.isEmpty()){
boolean save = manageWalletOutInService.saveBatch(saveList);
System.out.println("walletOutIn 新增"+save);
System.out.println("walletOutIn 新增"+saveList.size());
}
}else{
boolean b = manageWalletOutInService.saveBatch(collect);
boolean b = manageWalletOutInService.saveOrUpdateBatch(walletInfo);
System.out.println("初始化walletOutIn数据"+b);
}
}

View File

@@ -35,8 +35,8 @@
coin,
`user`,
address,
`date`,
COALESCE(DATE(`should_out_date`),DATE(`date`)) as shouldOutDate,
`date_in` as `date`,
COALESCE(DATE(`should_out_date`),DATE(`date_in`),DATE(`date_out`)) as shouldOutDate,
max_height,
allocation_amount as allocationAmount,
transfer_amount as transferAmount
@@ -46,10 +46,10 @@
coin = #{coin} AND `user` = #{user}
<choose>
<when test="startDate != null and endDate != null">
and DATE(`date`) >= #{startDate} and DATE(`date`) <![CDATA[ <= ]]> #{endDate}
and DATE(`date_in`) >= #{startDate} and DATE(`date_in`) <![CDATA[ <= ]]> #{endDate}
</when>
<otherwise>
and `date` >= DATE_SUB(DATE(NOW()), INTERVAL 1 MONTH)
and `date_in` >= DATE_SUB(DATE(NOW()), INTERVAL 1 MONTH)
</otherwise>
</choose>
</where>

View File

@@ -7,23 +7,18 @@
<select id="getWalletIn" resultType="com.m2pool.manage.entity.ManageWalletOutIn">
SELECT
wi.coin,
wi.`user`,
COALESCE(wi.`should_out_date`, wi.`create_date`) as `date`,
wi.amount AS allocationAmount,
wi.should_out_date AS `shouldOutDate`,
wi.max_height AS maxHeight
coin,
`user`,
create_date as dateIn,
amount AS allocationAmount,
COALESCE(should_out_date,create_date) AS `shouldOutDate`,
max_height AS maxHeight
FROM
wallet_in wi
wallet_in
<where>
<choose>
<when test="startDate != null">
wi.`create_date` >= DATE(#{startDate})
</when>
<otherwise>
wi.`create_date` <![CDATA[ <= ]]> NOW()
</otherwise>
</choose>
<if test="startDate != null">
`create_date` >= DATE(#{startDate})
</if>
</where>
</select>
<select id="getWalletOut" resultType="com.m2pool.manage.entity.ManageWalletOutIn">
@@ -31,16 +26,16 @@
wo.coin,
wo.`user`,
wo.address,
wo.`date`,
wo.`date` as dateIn,
wo.`date` as dateOut,
wo.max_height AS maxHeight,
wo.tx_id AS txId,
wo.amount AS transferAmount
FROM
wallet_outv2 wo
<where>
AND wo.`date` <![CDATA[ <= ]]> NOW()
<if test="startDate != null">
AND wo.`date` > #{startDate}
wo.`date` >= #{startDate}
</if>
</where>
</select>
@@ -48,6 +43,6 @@
select coin, max(max_height) as maxHeight, max(should_out_date) AS shouldOutDate, `user`, sum(amount) as needPayAmount from wallet_in where state = 2 group by coin,`user`
</select>
<select id="getMaxDateData" resultType="java.time.LocalDateTime">
select `date` from manage_wallet_out_in order by `date` desc limit 1
select DATE(`date_in`) from manage_wallet_out_in order by `date_in` desc limit 1
</select>
</mapper>