From 2e2eeeb8291415706f4941e55270a0b23e76bf23 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Fri, 04 Mar 2022 15:16:06 +0800
Subject: [PATCH] 20222223
---
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java | 220 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 197 insertions(+), 23 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java b/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
index 54eed4f..6b956fa 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -4,14 +4,19 @@
import java.text.SimpleDateFormat;
import java.util.*;
import javax.annotation.Resource;
+import javax.validation.Valid;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.date.DateUtil;
import com.xcong.excoin.modules.coin.dao.ZhiYaDao;
import com.xcong.excoin.modules.coin.dao.ZhiYaRecordDao;
-import com.xcong.excoin.modules.coin.entity.ZhiYaEntity;
-import com.xcong.excoin.modules.coin.entity.ZhiYaRecordEntity;
+import com.xcong.excoin.modules.coin.dao.ZhiyaRewardDao;
+import com.xcong.excoin.modules.coin.entity.*;
+import com.xcong.excoin.modules.coin.parameter.dto.CoinInListDto;
+import com.xcong.excoin.modules.coin.parameter.dto.ZhiyaRewardRecordsPageDto;
import com.xcong.excoin.modules.coin.parameter.vo.*;
+import com.xcong.excoin.modules.member.dao.*;
+import com.xcong.excoin.modules.member.entity.*;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -24,17 +29,9 @@
import com.xcong.excoin.common.enumerates.MemberWalletCoinEnum;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
-import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
-import com.xcong.excoin.modules.coin.entity.OrderCoinsDealEntity;
import com.xcong.excoin.modules.coin.mapper.MemberAccountMoneyChangeMapper;
import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto;
import com.xcong.excoin.modules.coin.service.CoinService;
-import com.xcong.excoin.modules.member.dao.MemberWalletAgentDao;
-import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
-import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
-import com.xcong.excoin.modules.member.entity.MemberWalletAgentEntity;
-import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
-import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
import com.xcong.excoin.utils.CoinTypeConvert;
import com.xcong.excoin.utils.MessageSourceUtils;
@@ -61,6 +58,12 @@
MemberWalletAgentDao memberWalletAgentDao;
@Resource
ZhiYaRecordDao zhiYaRecordDao;
+ @Resource
+ ZhiyaRewardDao zhiyaRewardDao;
+ @Resource
+ MemberCoinChargeDao memberCoinChargeDao;
+ @Resource
+ MemberCoinWithdrawDao memberCoinWithdrawDao;
@Resource
ZhiYaDao zhiYaDao;
@Resource
@@ -149,7 +152,7 @@
memberWalletCoinlist.add(coin);
// coin.setWalletCode(CoinTypeEnum.GUSD.toString());
// memberWalletCoinlist.add(coin);
- coin.setWalletCode(CoinTypeEnum.GOLDRICE.toString());
+ coin.setWalletCode(CoinTypeEnum.GRICE.toString());
memberWalletCoinlist.add(coin);
MemberWalletCoinVo memberWalletCoinVo = new MemberWalletCoinVo();
@@ -612,6 +615,7 @@
}
@Override
+ @Transactional
public Result usdtToGusd(BigDecimal balance,Integer type) {
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
@@ -722,6 +726,7 @@
}
@Override
+ @Transactional
public Result zhiYaGusd(BigDecimal balance) {
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
@@ -751,8 +756,8 @@
return Result.fail(MessageSourceUtils.getString("member_service_0096"));
}
//产生质押单,当前有的话,累加质押数量
- ZhiYaRecordEntity zhiYaRecord = zhiYaRecordDao.selectByMemberIdAndOrderStatus(memberId,1);
- if(ObjectUtil.isEmpty(zhiYaRecord)){
+// ZhiYaRecordEntity zhiYaRecord = zhiYaRecordDao.selectByMemberIdAndOrderStatus(memberId,1);
+// if(ObjectUtil.isEmpty(zhiYaRecord)){
//产生一条质押记录
ZhiYaRecordEntity zhiYaRecordEntity = new ZhiYaRecordEntity();
zhiYaRecordEntity.setMemberId(memberId);
@@ -764,18 +769,22 @@
Date newDate = DateUtil.offsetDay(date, 1);
zhiYaRecordEntity.setEffectDate(newDate);
zhiYaRecordDao.insert(zhiYaRecordEntity);
- }else{
- zhiYaRecord.setZhiyaCnt(zhiYaRecord.getZhiyaCnt().add(balance));
- Date date = new Date();
- Date newDate = DateUtil.offsetDay(date, 1);
- zhiYaRecord.setEffectDate(newDate);
- zhiYaRecordDao.updateById(zhiYaRecord);
- }
+// }else{
+// zhiYaRecord.setZhiyaCnt(zhiYaRecord.getZhiyaCnt().add(balance));
+// Date date = new Date();
+// Date newDate = DateUtil.offsetDay(date, 1);
+// zhiYaRecord.setEffectDate(newDate);
+// zhiYaRecordDao.updateById(zhiYaRecord);
+// }
+ //更新团队算力表
+ //只计算直属团队的算力信息
+
return Result.ok(MessageSourceUtils.getString("member_service_0024"));
}
@Override
+ @Transactional
public Result shuhuiGusd(BigDecimal balance,Long id) {
//获取用户ID
Long memberId = LoginUserUtils.getAppLoginUser().getId();
@@ -794,10 +803,11 @@
if(balance.compareTo(zhiyaCnt) > 0){
return Result.fail(MessageSourceUtils.getString("zhiya_service_0004"));
}
- zhiYaRecordEntity.setZhiyaCnt(zhiyaCnt.subtract(balance));
- if(zhiyaCnt.compareTo(balance) == 0){
- zhiYaRecordEntity.setOrderStatus(2);
+// zhiYaRecordEntity.setZhiyaCnt(zhiyaCnt.subtract(balance));
+ if(zhiyaCnt.compareTo(balance) != 0){
+ return Result.fail(MessageSourceUtils.getString("zhiya_service_0001"));
}
+ zhiYaRecordEntity.setOrderStatus(2);
zhiYaRecordDao.updateById(zhiYaRecordEntity);
//赎回Gusd,质押数量进入可用余额,
ZhiYaEntity zhiya = zhiYaDao.selectByMemberId(memberId);
@@ -856,6 +866,170 @@
return Result.ok(lists);
}
+ @Override
+ @Transactional
+ public void grantZhiyaAmount() {
+ //获取每日总产出
+ BigDecimal gusdReward = new BigDecimal(redisUtils.getString("GUSDREWARD"));
+ //获取每日质押总数
+ Long totalGusd = zhiYaRecordDao.selectTotalGusdByStatueAndTime(1,new Date());
+ BigDecimal totalGusdBigDecimal = new BigDecimal(totalGusd);
+ if(totalGusdBigDecimal.compareTo(BigDecimal.ZERO) > 0){
+ //平均一个获取奖励数量
+ BigDecimal divide = gusdReward.divide(totalGusdBigDecimal,2, BigDecimal.ROUND_HALF_UP);
+ //获取今天之前满足发放奖励的全部质押单
+ //生效时间小于当前时间
+ //状态为生效中
+ List<ZhiYaRecordEntity> lists = zhiYaRecordDao.selectZhiYaRewardByStatueAndTime(1,new Date());
+ if(CollUtil.isNotEmpty(lists)){
+ for(ZhiYaRecordEntity zhiYaRecordEntity : lists){
+ ZhiyaRewardEntity zhiyaRewardEntity = new ZhiyaRewardEntity();
+ zhiyaRewardEntity.setRecordId(zhiYaRecordEntity.getId());
+ zhiyaRewardEntity.setRecordNo(zhiYaRecordEntity.getOrderNo());
+ zhiyaRewardEntity.setMemberId(zhiYaRecordEntity.getMemberId());
+ zhiyaRewardEntity.setRewardAmout(divide.multiply(zhiYaRecordEntity.getZhiyaCnt()));
+ zhiyaRewardDao.insert(zhiyaRewardEntity);
+
+ //给团队上级发送奖励goldrice
+ //给账户的冻结
+
+ }
+ }
+ }
+ }
+
+ @Override
+ public Result getZhiyaReward(ZhiyaRewardRecordsPageDto recordsPageDto) {
+
+ //获取用户ID
+ Long memberId = LoginUserUtils.getAppLoginUser().getId();
+
+ Page<ZhiyaRewardVo> page = new Page<>(recordsPageDto.getPageNum(), recordsPageDto.getPageSize());
+ ZhiyaRewardEntity zhiyaRewardEntity = new ZhiyaRewardEntity();
+ zhiyaRewardEntity.setMemberId(memberId);
+ zhiyaRewardEntity.setRecordNo(recordsPageDto.getOrderNo());
+ IPage<ZhiyaRewardVo> lists = zhiYaRecordDao.selectZhiyaRewardByMemberIdInPage(page, zhiyaRewardEntity);
+ return Result.ok(lists);
+ }
+
+ @Override
+ public Result coinInList(@Valid CoinInListDto coinInListDto) {
+ //获取用户ID
+ Long memberId = LoginUserUtils.getAppLoginUser().getId();
+ int type = coinInListDto.getType();
+ //充币记录
+ if(type == 1) {
+ Page<MemberCoinChargeEntity> page = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ MemberCoinChargeEntity memberCoinChargeEntity = new MemberCoinChargeEntity();
+ memberCoinChargeEntity.setMemberId(memberId);
+ IPage<MemberCoinChargeEntity> memberCoinCharge = memberCoinChargeDao.findMemberCoinChargeInPage(page, memberCoinChargeEntity);
+ List<MemberCoinChargeEntity> records = memberCoinCharge.getRecords();
+
+ Page<CoinInListVo> responsePage = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ if(CollUtil.isNotEmpty(records)) {
+ ArrayList<CoinInListVo> arrayList = new ArrayList<>();
+ for(MemberCoinChargeEntity memberCoinChargeEntitys : records) {
+ CoinInListVo coinInListVo = new CoinInListVo();
+ coinInListVo.setSymbol(memberCoinChargeEntitys.getSymbol());
+ coinInListVo.setAmount(memberCoinChargeEntitys.getAmount().toPlainString());
+ coinInListVo.setContent("充币");
+ coinInListVo.setStatus(memberCoinChargeEntitys.getStatus());
+ coinInListVo.setUpdateTime(memberCoinChargeEntitys.getUpdateTime());
+ arrayList.add(coinInListVo);
+ }
+ responsePage.setRecords(arrayList);
+ }
+ return Result.ok(responsePage);
+ }
+ //提币记录
+ if(type == 2) {
+ Page<MemberCoinWithdrawEntity> page = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ MemberCoinWithdrawEntity memberCoinWithdrawEntity = new MemberCoinWithdrawEntity();
+ memberCoinWithdrawEntity.setMemberId(memberId);
+ IPage<MemberCoinWithdrawEntity> memberCoinWithdraw = memberCoinWithdrawDao.findMemberCoinWithdrawInPage(page, memberCoinWithdrawEntity);
+ List<MemberCoinWithdrawEntity> records = memberCoinWithdraw.getRecords();
+
+ Page<CoinInListVo> responsePage = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ if(CollUtil.isNotEmpty(records)) {
+ ArrayList<CoinInListVo> arrayList = new ArrayList<>();
+ for(MemberCoinWithdrawEntity memberCoinWithdrawEntitys : records) {
+ CoinInListVo coinInListVo = new CoinInListVo();
+ coinInListVo.setSymbol(memberCoinWithdrawEntitys.getSymbol());
+ coinInListVo.setAmount(memberCoinWithdrawEntitys.getAmount().toPlainString());
+ coinInListVo.setContent("提币");
+ int status = memberCoinWithdrawEntitys.getStatus();
+ int statusOut = 0;
+ if(status == 1) {
+ statusOut = 0;
+ }
+ if(status == 2) {
+ statusOut = 1;
+ }
+ if(status == 3) {
+ statusOut = 2;
+ }
+ coinInListVo.setStatus(statusOut);
+ coinInListVo.setUpdateTime(memberCoinWithdrawEntitys.getUpdateTime());
+ coinInListVo.setIsInside(memberCoinWithdrawEntitys.getIsInside());
+ arrayList.add(coinInListVo);
+ }
+ responsePage.setRecords(arrayList);
+ }
+ return Result.ok(responsePage);
+ }
+ //划转记录
+ if(type == 3) {
+ Page<MemberAccountMoneyChange> page = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ MemberAccountMoneyChange memberAccountMoneyChange = new MemberAccountMoneyChange();
+ memberAccountMoneyChange.setMemberId(memberId);
+ IPage<MemberAccountMoneyChange> list = memberAccountMoneyChangeDao.coinInList(page, memberAccountMoneyChange);
+ List<MemberAccountMoneyChange> records = list.getRecords();
+
+ Page<CoinInListVo> responsePage = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ if(CollUtil.isNotEmpty(records)) {
+ ArrayList<CoinInListVo> arrayList = new ArrayList<>();
+ for(MemberAccountMoneyChange memberAccountMoneyChanges : records) {
+ CoinInListVo coinInListVo = new CoinInListVo();
+ coinInListVo.setSymbol(memberAccountMoneyChanges.getSymbol());
+ coinInListVo.setAmount(memberAccountMoneyChanges.getAmount().toPlainString());
+ coinInListVo.setContent(memberAccountMoneyChanges.getContent());
+ coinInListVo.setStatus(memberAccountMoneyChanges.getStatus());
+ coinInListVo.setUpdateTime(memberAccountMoneyChanges.getUpdateTime());
+ arrayList.add(coinInListVo);
+ }
+ responsePage.setRecords(arrayList);
+ }
+ return Result.ok(responsePage);
+ }
+ //其他记录
+ if(type == 4) {
+ Page<OrderCoinsDealEntity> page = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ MemberAccountMoneyChange memberAccountMoneyChange = new MemberAccountMoneyChange();
+ memberAccountMoneyChange.setMemberId(memberId);
+ IPage<MemberAccountMoneyChange> list = memberAccountMoneyChangeDao.selectWalletAgentIntoRecordsByMemIdTypeSymbol(page, memberAccountMoneyChange);
+ List<MemberAccountMoneyChange> records = list.getRecords();
+
+ Page<CoinInListVo> responsePage = new Page<>(coinInListDto.getPageNum(), coinInListDto.getPageSize());
+ if(CollUtil.isNotEmpty(records)) {
+ ArrayList<CoinInListVo> arrayList = new ArrayList<>();
+ for(MemberAccountMoneyChange memberAccountMoneyChanges : records) {
+ CoinInListVo coinInListVo = new CoinInListVo();
+ coinInListVo.setSymbol(memberAccountMoneyChanges.getSymbol());
+ coinInListVo.setAmount(memberAccountMoneyChanges.getAmount().toPlainString());
+ coinInListVo.setContent(memberAccountMoneyChanges.getContent());
+ coinInListVo.setStatus(memberAccountMoneyChanges.getStatus());
+ coinInListVo.setUpdateTime(memberAccountMoneyChanges.getUpdateTime());
+ arrayList.add(coinInListVo);
+ }
+ responsePage.setRecords(arrayList);
+ }
+ return Result.ok(responsePage);
+ }
+
+ return Result.fail(MessageSourceUtils.getString("member_controller_0005"));
+
+ }
+
public String generateSimpleSerialno(String userId) {
StringBuilder sb = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
--
Gitblit v1.9.1