去除最终到期时间,改用委托次数判断

pull/520/head
dorion 2024-04-18 01:07:10 +08:00
parent 3704b2183e
commit 166b5ef6ad
8 changed files with 155 additions and 83 deletions

View File

@ -135,7 +135,7 @@
</plugin> -->
</plugins>
<finalName>${project.artifactId}</finalName>
<!-- <resources>
<!-- <resources>
<resource>
<directory>src/main/resources</directory>
<excludes>

View File

@ -67,6 +67,14 @@
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">状态:</label>
<div class="col-sm-8">
<select name="status" class="form-control m-b" th:with="type=${@dict.getType('sys_tenant_status')}">
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{status}"></option>
</select>
</div>
</div>
<input name="fcd" th:value="${#dates.format(tenantInfo.fcd, 'yyyy-MM-dd HH:mm:ss')}" type="hidden">
@ -86,11 +94,7 @@
}
}
$("input[name='finishTransferTime']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
$("input[name='fcd']").datetimepicker({
format: "yyyy-mm-dd",
@ -98,11 +102,7 @@
autoclose: true
});
$("input[name='lcd']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
</script>
</body>
</html>

View File

@ -61,6 +61,7 @@
var exchangeUnitDatas = [[${@dict.getType('sys_monitor_type')}]];
var isPaidDatas = [[${@dict.getType('sys_is_paid')}]];
var periodDatas = [[${@dict.getType('sys_lock_period_day')}]];
var statusDatas = [[${@dict.getType('sys_tenant_status')}]];
var prefix = ctx + "account/tenant";
$(function() {
@ -124,9 +125,17 @@
return $.table.selectDictLabel(periodDatas, value);
}
},
{
field: 'finishTransferTime',
title: '最终到期日期'
field: 'status',
title: '状态',
formatter: function(value, row, index) {
return $.table.selectDictLabel(statusDatas, value);
}
},
{
field: 'delegatedDays',
title: '已经委托天数'
},
{
field: 'fcd',

View File

@ -18,16 +18,16 @@
<label>转入账户:</label>
<input type="text" name="toAddress"/>
</li>
<li>
<!-- <li>
<label>实际出账账户:</label>
<input type="text" name="accountAddress"/>
</li>
</li>-->
<li>
<label>TRX订单</label>
<input type="text" name="trxTxId"/>
</li>
<br/> <br/> <br/>
<!-- <li>
<label>能量交易订单:</label>
<input type="text" name="delegateTxId"/>
@ -39,6 +39,7 @@
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" ></option>
</select>
</li>
<!-- <br/> <br/> <br/>-->
<!--
<li>
<label>回收资源交易:</label>
@ -85,6 +86,7 @@
var datas = [[${@dict.getType('sys_delegate_status')}]];
var tranferCountDatas = [[${@dict.getType('sys_transfer_number')}]];
var busiTypeDatas = [[${@dict.getType('sys_busi_type')}]];
var lockPeriodDatas = [[${@dict.getType('sys_lock_period')}]];
$(function() {
var options = {
url: prefix + "/list",
@ -109,10 +111,10 @@
field: 'toAddress',
title: '转入账户'
},
{
/* {
field: 'accountAddress',
title: '实际出账账户'
},
},*/
{
field: 'price',
title: '单价'
@ -149,7 +151,10 @@
},
{
field: 'lockPeriod',
title: '锁定周期(*3s)'
title: '锁定周期',
formatter: function(value, row, index) {
return $.table.selectDictLabel(lockPeriodDatas, value);
}
},
{
field: 'delegateStatus',

View File

@ -3,8 +3,6 @@ package com.ruoyi.common.core.domain.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
@ -57,10 +55,17 @@ public class TenantInfo extends BaseEntity
@Excel(name = "租期")
private Long period;
/** 最终到期日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "最终到期日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date finishTransferTime;
/** 用户id */
private String userId;
/** 状态 */
@Excel(name = "状态")
private String status;
/** 已经委托天数 */
@Excel(name = "已经委托天数")
private Long delegatedDays;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@ -80,6 +85,31 @@ public class TenantInfo extends BaseEntity
@Excel(name = "更新用户")
private String lcu;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Long getDelegatedDays() {
return delegatedDays;
}
public void setDelegatedDays(Long delegatedDays) {
this.delegatedDays = delegatedDays;
}
public void setIdTenantInfo(Long idTenantInfo)
{
this.idTenantInfo = idTenantInfo;
@ -170,15 +200,7 @@ public class TenantInfo extends BaseEntity
{
return period;
}
public void setFinishTransferTime(Date finishTransferTime)
{
this.finishTransferTime = finishTransferTime;
}
public Date getFinishTransferTime()
{
return finishTransferTime;
}
public void setFcd(Date fcd)
{
this.fcd = fcd;
@ -218,22 +240,24 @@ public class TenantInfo extends BaseEntity
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("idTenantInfo", getIdTenantInfo())
.append("receiverAddress", getReceiverAddress())
.append("monitorAddress", getMonitorAddress())
.append("price", getPrice())
.append("transferCount", getTransferCount())
.append("exchangeUnit", getExchangeUnit())
.append("txId", getTxId())
.append("exchangeAmount", getExchangeAmount())
.append("isPaid", getIsPaid())
.append("period", getPeriod())
.append("finishTransferTime", getFinishTransferTime())
.append("fcd", getFcd())
.append("fcu", getFcu())
.append("lcd", getLcd())
.append("lcu", getLcu())
.toString();
return "TenantInfo{" +
"idTenantInfo=" + idTenantInfo +
", receiverAddress='" + receiverAddress + '\'' +
", monitorAddress='" + monitorAddress + '\'' +
", price=" + price +
", transferCount=" + transferCount +
", exchangeUnit='" + exchangeUnit + '\'' +
", txId='" + txId + '\'' +
", exchangeAmount=" + exchangeAmount +
", isPaid='" + isPaid + '\'' +
", period=" + period +
", userId='" + userId + '\'' +
", status='" + status + '\'' +
", delegatedDays=" + delegatedDays +
", fcd=" + fcd +
", fcu='" + fcu + '\'' +
", lcd=" + lcd +
", lcu='" + lcu + '\'' +
'}';
}
}

View File

@ -1,10 +1,10 @@
package com.ruoyi.system.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.google.common.base.Preconditions;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.MonitorAddressInfo;
import com.ruoyi.common.core.domain.entity.TenantInfo;
@ -59,6 +59,7 @@ public class TenantInfoServiceImpl implements ITenantInfoService
* @return
*/
@Override
@DataScope(userAlias = "u")
public List<TenantInfo> selectTenantInfoList(TenantInfo tenantInfo)
{
return tenantInfoMapper.selectTenantInfoList(tenantInfo);
@ -86,15 +87,18 @@ public class TenantInfoServiceImpl implements ITenantInfoService
long exchangeAmount = price * transferCount;
tenantInfo.setExchangeAmount(exchangeAmount);
tenantInfo.setIsPaid(UserConstants.NO);
Long period = tenantInfo.getPeriod();
DateTime dateTime = DateUtil.offsetDay(DateUtil.date(), period.intValue() -1);
tenantInfo.setFinishTransferTime( DateUtil.endOfDay(dateTime));
tenantInfo.setDelegatedDays(0L);
Long userId = ShiroUtils.getUserId();
tenantInfo.setUserId(userId.toString());
String loginName = ShiroUtils.getLoginName();
tenantInfo.setFcd(new Date());
tenantInfo.setFcu(loginName);
String status = DictUtils.getDictValue("sys_tenant_status", "生效中");
tenantInfo.setStatus(status);
tenantInfo.setLcd(new Date());
tenantInfo.setLcu(loginName);
@ -117,10 +121,6 @@ public class TenantInfoServiceImpl implements ITenantInfoService
long exchangeAmount = price * transferCount;
tenantInfo.setExchangeAmount(exchangeAmount);
Long period = tenantInfo.getPeriod();
DateTime dateTime = DateUtil.offsetDay(tenantInfo.getFcd(), period.intValue());
tenantInfo.setFinishTransferTime( DateUtil.endOfDay(dateTime));
String loginName = ShiroUtils.getLoginName();
@ -160,6 +160,9 @@ public class TenantInfoServiceImpl implements ITenantInfoService
for (String id : idArray) {
TenantInfo tenantInfo = tenantInfoMapper.selectTenantInfoByIdTenantInfo(Long.valueOf(id));
String status = DictUtils.getDictValue("sys_tenant_status", "生效中");
Preconditions.checkState(status.equals(tenantInfo.getStatus()), "该租户不是生效中状态,不能发起委托任务");
String dictValue = DictUtils.getDictValue("sys_delegate_status", "已委托");
String busiType = DictUtils.getDictValue("sys_busi_type", "天数套餐");
TrxExchangeInfo trxExchangeInfo = TrxExchangeInfo.builder().fromAddress(tenantInfo.getReceiverAddress())
@ -173,11 +176,6 @@ public class TenantInfoServiceImpl implements ITenantInfoService
Preconditions.checkState(CollectionUtil.isEmpty(trxExchangeInfos), "该接收能量地址已在任务中,请勿重复发起");
Date finishTransferTime = tenantInfo.getFinishTransferTime();
int compare = DateUtil.compare(new Date(), finishTransferTime);
Preconditions.checkState(compare <= 0, "租户已过期,无法再次委托能量");
MonitorAddressInfo monitorAddressInfoExample = new MonitorAddressInfo();
monitorAddressInfoExample.setMonitorAddress(tenantInfo.getMonitorAddress());
monitorAddressInfoExample.setIsValid(UserConstants.YES);
@ -196,6 +194,9 @@ public class TenantInfoServiceImpl implements ITenantInfoService
trxExchange.setLockNum(between + 1);
trxExchangeInfoService.delegate(trxExchange, true);
tenantInfo.setDelegatedDays(tenantInfo.getDelegatedDays() + 1);
tenantInfoMapper.updateTenantInfo(tenantInfo);
}
return 1;

View File

@ -38,6 +38,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.util.UriComponentsBuilder;
import org.tron.trident.core.ApiWrapper;
import org.tron.trident.core.exceptions.IllegalException;
@ -382,6 +383,7 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
* @param monitorAddressAccount
* @throws IllegalException
*/
@Transactional
private void doDelegateResource(Contract contract, String txID, MonitorAddressAccount monitorAddressAccount) throws Exception {
@ -406,12 +408,12 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
TenantInfo tenantInfoExample = new TenantInfo();
tenantInfoExample.setReceiverAddress(ownerAddress);
// tenantInfoExample.setMonitorAddress(monitorAddressAccount.getMonitorAddress());
tenantInfoExample.setFinishTransferTime(new Date());
tenantInfoExample.setIsPaid(UserConstants.NO);
tenantInfoExample.setStatus(DictUtils.getDictValue("sys_tenant_status", "生效中"));
List<TenantInfo> tenantInfoList = tenantInfoMapper.selectTenantInfoList(tenantInfoExample);
TenantInfo tenantInfo = null;
if (tenantInfoList.size() > 0) {
TenantInfo tenantInfo = tenantInfoList.get(0);
tenantInfo = tenantInfoList.get(0);
Long exchangeAmount = tenantInfo.getExchangeAmount();
//判断入账金额是否与转入金额相等,如果相等则设置为已支付
if (amount != exchangeAmount) {
@ -429,7 +431,8 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
tenantInfo.setIsPaid("Y");
tenantInfo.setLcu("system");
tenantInfo.setTxId(txID);
tenantInfoMapper.updateTenantInfo(tenantInfo);
tenantInfo.setDelegatedDays(tenantInfo.getDelegatedDays() + 1);
//取包天的套餐锁定时间和交易笔数
lockPeriod = 1200L * 24;
busiType = DictUtils.getDictValue("sys_busi_type", "天数套餐");
@ -458,6 +461,10 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
calcBalanceAndDelegate(txID, apiWrapper, accountAddress, transferCount, ownerAddress, lockPeriod, toAddress, price, busiType, amount, "system");
//持久化之后放redis
redisTemplate.opsForValue().set("transfer_trx_" + txID, txID, 1, TimeUnit.DAYS);
if (tenantInfo !=null){
tenantInfoMapper.updateTenantInfo(tenantInfo);
}
}
/**
@ -577,23 +584,32 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
//查询是否是按天支付的租户,是的话需要回收完再次赠送
TenantInfo tenantInfoExample = new TenantInfo();
tenantInfoExample.setReceiverAddress(trxExchangeInfo.getFromAddress());
tenantInfoExample.setStatus(DictUtils.getDictValue("sys_tenant_status", "生效中"));
// tenantInfoExample.setMonitorAddress(trxExchangeInfo.getToAddress());
tenantInfoExample.setFinishTransferTime(new Date());
List<TenantInfo> tenantInfoList = tenantInfoMapper.selectTenantInfoList(tenantInfoExample);
TenantInfo tenantInfo = null;
if (tenantInfoList.size() > 0) {
Response.AccountResourceMessage accountResource = apiWrapper.getAccountResource(accountAddress);
TenantInfo tenantInfo = tenantInfoList.get(0);
tenantInfo = tenantInfoList.get(0);
if (UserConstants.NO.equals(tenantInfo.getIsPaid())) {
return;
}
/* String status = DictUtils.getDictValue("sys_tenant_status", "生效中");
if (!status.equals(tenantInfo.getStatus())){
return;//不是生效中状态不处理
}*/
Long period = tenantInfo.getPeriod();
Date tenantInfoFcd = tenantInfo.getFcd();
long between = DateUtil.between(tenantInfoFcd, new Date(), DateUnit.DAY);
if (between > period) {
//已到期不处理
// long between = DateUtil.between(tenantInfoFcd, new Date(), DateUnit.DAY);
Long delegatedDays = tenantInfo.getDelegatedDays();
if (delegatedDays == period) {
//委托天数已用完不再处理,更改状态为已满期
String expire = DictUtils.getDictValue("sys_tenant_status", "已满期");
tenantInfo.setStatus(expire);
tenantInfoMapper.updateTenantInfo(tenantInfo);
return;
}
@ -603,6 +619,8 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
return;
}
tenantInfo.setDelegatedDays(delegatedDays + 1);
String receiverAddress = tenantInfo.getReceiverAddress();
Long transferCount = tenantInfo.getTransferCount();
long newLockPeriod = 24 * 1200L;
@ -647,6 +665,11 @@ public class TrxExchangeInfoServiceImpl implements ITrxExchangeInfoService {
trxExchangeInfoMapper.insertTrxExchangeInfo(trxExchangeInfoNew);*/
}
if (tenantInfo != null){
tenantInfoMapper.updateTenantInfo(tenantInfo);
}
} catch (Exception e) {
log.error("回收能量业务处理异常{}", trxExchangeInfo.getIdTrxExchangeInfo(), e);
ErrorLog errorLog = ErrorLog.builder()

View File

@ -15,7 +15,9 @@
<result property="exchangeAmount" column="exchange_amount" />
<result property="isPaid" column="is_paid" />
<result property="period" column="period" />
<result property="finishTransferTime" column="finish_transfer_time" />
<result property="userId" column="user_id" />
<result property="status" column="status" />
<result property="delegatedDays" column="delegated_days" />
<result property="fcd" column="fcd" />
<result property="fcu" column="fcu" />
<result property="lcd" column="lcd" />
@ -23,12 +25,13 @@
</resultMap>
<sql id="selectTenantInfoVo">
select id_tenant_info, receiver_address, monitor_address, price, transfer_count, exchange_unit, tx_id, exchange_amount, is_paid, period, finish_transfer_time, fcd, fcu, lcd, lcu from tenant_info
select id_tenant_info, receiver_address, monitor_address, price, transfer_count, exchange_unit, tx_id, exchange_amount, is_paid, period, t.status, delegated_days, fcd, fcu, lcd, lcu from tenant_info t
</sql>
<select id="selectTenantInfoList" parameterType="TenantInfo" resultMap="TenantInfoResult">
<include refid="selectTenantInfoVo"/>
<where>
left join sys_user u on t.user_id = u.user_id
<where> 1 = 1
<if test="receiverAddress != null and receiverAddress != ''"> and receiver_address = #{receiverAddress}</if>
<if test="monitorAddress != null and monitorAddress != ''"> and monitor_address = #{monitorAddress}</if>
<if test="price != null "> and price = #{price}</if>
@ -38,12 +41,13 @@
<if test="exchangeAmount != null "> and exchange_amount = #{exchangeAmount}</if>
<if test="isPaid != null and isPaid != ''"> and is_paid = #{isPaid}</if>
<if test="period != null "> and period = #{period}</if>
<if test="finishTransferTime != null "> and finish_transfer_time &gt;= #{finishTransferTime}</if>
<if test="fcd != null "> and fcd &gt;= #{fcd}</if>
<if test="fcd != null "> and fcd = #{fcd}</if>
<if test="fcu != null and fcu != ''"> and fcu = #{fcu}</if>
<if test="lcd != null "> and lcd &lt;= #{lcd}</if>
<if test="lcd != null "> and lcd = #{lcd}</if>
<if test="lcu != null and lcu != ''"> and lcu = #{lcu}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectTenantInfoByIdTenantInfo" parameterType="Long" resultMap="TenantInfoResult">
@ -63,7 +67,9 @@
<if test="exchangeAmount != null">exchange_amount,</if>
<if test="isPaid != null">is_paid,</if>
<if test="period != null">period,</if>
<if test="finishTransferTime != null">finish_transfer_time,</if>
<if test="userId != null">user_id,</if>
<if test="status != null">status,</if>
<if test="delegatedDays != null">delegated_days,</if>
<if test="fcd != null">fcd,</if>
<if test="fcu != null">fcu,</if>
<if test="lcd != null">lcd,</if>
@ -79,7 +85,9 @@
<if test="exchangeAmount != null">#{exchangeAmount},</if>
<if test="isPaid != null">#{isPaid},</if>
<if test="period != null">#{period},</if>
<if test="finishTransferTime != null">#{finishTransferTime},</if>
<if test="userId != null">#{userId},</if>
<if test="status != null">#{status},</if>
<if test="delegatedDays != null">#{delegatedDays},</if>
<if test="fcd != null">#{fcd},</if>
<if test="fcu != null">#{fcu},</if>
<if test="lcd != null">#{lcd},</if>
@ -99,7 +107,9 @@
<if test="exchangeAmount != null">exchange_amount = #{exchangeAmount},</if>
<if test="isPaid != null">is_paid = #{isPaid},</if>
<if test="period != null">period = #{period},</if>
<if test="finishTransferTime != null">finish_transfer_time = #{finishTransferTime},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="status != null">status = #{status},</if>
<if test="delegatedDays != null">delegated_days = #{delegatedDays},</if>
<if test="fcd != null">fcd = #{fcd},</if>
<if test="fcu != null">fcu = #{fcu},</if>
<if test="lcd != null">lcd = #{lcd},</if>