update 后台管理系统出入账接口问题修复

This commit is contained in:
yyb
2025-08-27 15:03:11 +08:00
parent f8264b2df1
commit 981838726c
10 changed files with 164 additions and 50 deletions

View File

@@ -22,7 +22,7 @@ public abstract class AbstractMongoDbConfig {
return new SimpleMongoClientDatabaseFactory(connectionString);
}
public MongoDatabaseFactory mongoDatabaseNoUserFactory() {
public MongoDatabaseFactory mongoDatabaseNoUserFactory(String host, String port, String database) {
String connectionString = "mongodb://"+ host+":"+port +"/" + database;
return new SimpleMongoClientDatabaseFactory(connectionString);
}

View File

@@ -1,5 +1,6 @@
package com.m2pool.manage.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -11,13 +12,21 @@ import org.springframework.data.mongodb.core.MongoTemplate;
* @Date 2025/7/23 10:00
* @Author yyb
*/
@Data
@Configuration
@ConfigurationProperties("spring.data.mongodb.documentation")
public class MongoDbConfig extends AbstractMongoDbConfig{
@Primary
@Bean(name = "docMongoTemplate")
@Override
public MongoTemplate getMongoTemplate() {
return new MongoTemplate(mongoDatabaseNoUserFactory());
return new MongoTemplate(mongoDatabaseNoUserFactory(host, port, database));
}
private String database;
private String host;
private String port;
}

View File

@@ -18,9 +18,21 @@ import java.util.List;
public interface ManageWalletOutInMapper extends BaseMapper<ManageWalletOutIn> {
/**
* 获取入账信息
* @param startDate
* @return
*/
@DistributionDB
List<ManageWalletOutIn> getWalletInfo(
@Param("startDate") LocalDateTime startDate
);
List<ManageWalletOutIn> getWalletIn(@Param("startDate") LocalDateTime startDate);
/**
* 获取出账信息
* @param startDate
* @return
*/
@DistributionDB
List<ManageWalletOutIn> getWalletOut(@Param("startDate") LocalDateTime startDate);
}

View File

@@ -1,6 +1,7 @@
package com.m2pool.manage.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.m2pool.common.core.utils.DateUtils;
import com.m2pool.manage.entity.ManageWalletOutIn;
import com.m2pool.manage.mapper.ManageBroadcastMapper;
import com.m2pool.manage.mapper.ManageWalletOutInMapper;
@@ -12,9 +13,9 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @Description 后台管理系统 定时任务
@@ -36,23 +37,113 @@ public class ManageTask {
/**
* 存储交易记录定时任务
*/
@Scheduled(cron = "22 21 0/1 * * ?")
@Scheduled(cron = "22 17 0/1 * * ?")
//@Scheduled(cron = "0 0/1 * * * ?")
public void insertDataToWalletOutInDb(){
ManageWalletOutIn manageWalletOutIn = manageWalletOutInMapper.selectOne(new LambdaQueryWrapper<ManageWalletOutIn>().orderByDesc(
ManageWalletOutIn::getDate
ManageWalletOutIn manageWalletOutIn = manageWalletOutInMapper.selectOne(new LambdaQueryWrapper<ManageWalletOutIn>()
.orderByDesc(ManageWalletOutIn::getDate
).last("limit 1"));
LocalDateTime startDate = null;
List<ManageWalletOutIn> manageWalletOutIns = new ArrayList<>();
if (manageWalletOutIn != null){
startDate = manageWalletOutIn.getDate();
//获取startDate 后的数据,用于比对
manageWalletOutIns = manageWalletOutInMapper.selectList(new LambdaQueryWrapper<ManageWalletOutIn>()
.ge(ManageWalletOutIn::getDate, startDate.toLocalDate().atStartOfDay()));
}
List<ManageWalletOutIn> walletIn = manageWalletOutInMapper.getWalletIn(startDate);
List<ManageWalletOutIn> walletOut = manageWalletOutInMapper.getWalletOut(startDate);
Map<String, List<ManageWalletOutIn>> walletInMap = walletIn.stream()
.collect(Collectors.groupingBy(item ->
item.getUser() + item.getCoin() + item.getDate().toLocalDate().atStartOfDay()
));
Map<String, List<ManageWalletOutIn>> walletOutMap = walletOut.stream()
.collect(Collectors.groupingBy(item ->
item.getUser() + item.getCoin() + item.getDate().toLocalDate().atStartOfDay()
));
List<ManageWalletOutIn> walletInfo = new ArrayList<>();
//外层为out内层为in
for (Map.Entry<String, List<ManageWalletOutIn>> outEntry : walletOutMap.entrySet()) {
String key = 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());
}))
.collect(Collectors.toList());
walletInfo.addAll(updatedOutList);
// 处理 inList 中未匹配的项
List<ManageWalletOutIn> updatedInList = inList.stream()
.filter(inItem -> outList.stream()
.noneMatch(outItem -> outItem.getMaxHeight().equals(inItem.getMaxHeight())))
.collect(Collectors.toList());
walletInfo.addAll(updatedInList);
} else {
walletInfo.addAll(outList);
}
}
//外层为in内层为out -----新增当天只有walletIn,没有walletOut的数据
for (Map.Entry<String, List<ManageWalletOutIn>> inEntry : walletInMap.entrySet()) {
String key = inEntry.getKey();
if (!walletOutMap.containsKey(key)) {
walletInfo.addAll(inEntry.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) {
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()))
.findFirst()
.ifPresent(dbItem -> {
// 若找到匹配项,设置 id 并添加到 updateList
item.setId(dbItem.getId());
updateList.add(item);
});
if (item.getId() == null){
saveList.add(item);
}
}
if (!updateList.isEmpty()){
boolean update = manageWalletOutInService.updateBatchById(updateList);
System.out.println("walletOutIn 修改"+update);
}
if (!saveList.isEmpty()){
boolean save = manageWalletOutInService.saveBatch(saveList);
System.out.println("walletOutIn 新增"+save);
}
}else{
boolean b = manageWalletOutInService.saveBatch(collect);
System.out.println("初始化walletOutIn数据"+b);
}
List<ManageWalletOutIn> walletInfo = manageWalletOutInMapper.getWalletInfo(startDate);
boolean b = manageWalletOutInService.saveBatch(walletInfo);
System.out.println("walletOutIn 插入结果"+b);
}
/**
* 删除再离线数据
* 删除再离线数据(保留一月数据)
*/
@Scheduled(cron = "5 5 1 * * ?")
public void deleteOnlineAndOfflineDataForNexa(){

View File

@@ -36,7 +36,7 @@
`user`,
address,
`date`,
should_out_date as shouldOutDate,
DATE(`date`) 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 `should_out_date` >= #{startDate} and `should_out_date`<![CDATA[ <= ]]> #{endDate}
and DATE(`date`) >= #{startDate} and DATE(`date`) <![CDATA[ <= ]]> #{endDate}
</when>
<otherwise>
and `should_out_date` >= DATE_SUB(NOW(), INTERVAL 1 MONTH)
and `date` >= DATE_SUB(DATE(NOW()), INTERVAL 1 MONTH)
</otherwise>
</choose>
</where>

View File

@@ -5,46 +5,40 @@
<mapper namespace="com.m2pool.manage.mapper.ManageWalletOutInMapper">
<select id="getWalletInfo" resultType="com.m2pool.manage.entity.ManageWalletOutIn">
<select id="getWalletIn" resultType="com.m2pool.manage.entity.ManageWalletOutIn">
SELECT
wi.coin,
wi.`user`,
wi.should_out_date AS shouldOutDate,
wi.amount AS allocationAmount,
wo.address,
wo.`date`,
wo.max_height AS maxHeight,
wo.tx_id AS txId,
wo.amount AS transferAmount
wi.`create_date` as `date`,
wi.max_height AS maxHeight
FROM
wallet_in wi
LEFT JOIN wallet_outv2 wo
ON
DATE(wi.create_date) = DATE(wo.`date`) AND wi.coin = wo.coin AND wi.`user` = wo.`user`
<where>
wo.`date` <![CDATA[ <= ]]> NOW()
<if test="startDate != null">
AND wo.`date` > #{startDate}
</if>
<choose>
<when test="startDate != null">
wi.`create_date` >= DATE(#{startDate})
</when>
<otherwise>
wi.`create_date` <![CDATA[ <= ]]> NOW()
</otherwise>
</choose>
</where>
UNION
</select>
<select id="getWalletOut" resultType="com.m2pool.manage.entity.ManageWalletOutIn">
SELECT
wi.coin,
wi.`user`,
wi.should_out_date AS shouldOutDate,
wi.amount AS allocationAmount,
wo.coin,
wo.`user`,
wo.address,
wo.`date`,
wo.max_height AS maxHeight,
wo.tx_id AS txId,
wo.amount AS transferAmount
FROM
wallet_in wi
RIGHT JOIN wallet_outv2 wo
ON
DATE(wi.create_date) = DATE(wo.`date`) AND wi.coin = wo.coin AND wi.`user` = wo.`user`
wallet_outv2 wo
<where>
wo.`date` <![CDATA[ <= ]]> NOW()
AND wo.`date` <![CDATA[ <= ]]> NOW()
<if test="startDate != null">
AND wo.`date` > #{startDate}
</if>