Merge remote-tracking branch 'origin/dev-agent' into dev

This commit is contained in:
墨大叔 2024-10-06 08:47:44 +08:00
commit 1b3c9d90a6
13 changed files with 117 additions and 39 deletions

View File

@ -6,6 +6,10 @@ import com.ruoyi.dashboard.vo.TodoListVO;
import com.ruoyi.ss.abnormal.domain.AbnormalQuery;
import com.ruoyi.ss.abnormal.domain.enums.AbnormalStatus;
import com.ruoyi.ss.abnormal.service.AbnormalService;
import com.ruoyi.ss.bonus.domain.BonusQuery;
import com.ruoyi.ss.bonus.domain.enums.BonusArrivalType;
import com.ruoyi.ss.bonus.domain.vo.BonusDailyAmountVO;
import com.ruoyi.ss.bonus.service.BonusService;
import com.ruoyi.ss.complaint.domain.SmComplaintQuery;
import com.ruoyi.ss.complaint.service.ISmComplaintService;
import com.ruoyi.ss.dashboard.ServiceIncomeQuery;
@ -65,6 +69,9 @@ public class DashboardService {
@Autowired
private ReceiveBillService receiveBillService;
@Autowired
private BonusService bonusService;
public TodoListVO getTodoList() {
TodoListVO vo = new TodoListVO();
@ -102,6 +109,13 @@ public class DashboardService {
public List<ServiceIncomeVO> getServiceIncome(ServiceIncomeQuery query) {
// 查询服务费
BonusQuery bonusQuery = new BonusQuery();
bonusQuery.setPayDateStart(query.getStartDate());
bonusQuery.setPayDateEnd(query.getEndDate());
bonusQuery.setArrivalType(BonusArrivalType.PLATFORM.getType());
List<BonusDailyAmountVO> bonusList = bonusService.selectDailyAmount(bonusQuery);
// 查询订单
TransactionBillQuery billQuery = new TransactionBillQuery();
billQuery.setStartDate(query.getStartDate());
@ -128,15 +142,23 @@ public class DashboardService {
ServiceIncomeVO vo = new ServiceIncomeVO();
vo.setDate(date);
// 订单服务费收入及成本
// 订单服务费
BonusDailyAmountVO bonus = bonusList.stream()
.filter(item -> item.getKey().isEqual(date))
.findFirst().orElse(null);
if (bonus != null) {
vo.setServiceAmount(bonus.getSum());
} else {
vo.setServiceAmount(BigDecimal.ZERO);
}
// 渠道成本
TransactionAmountVO<Date> transaction = amountList.stream()
.filter(item -> item.getKey().compareTo(DateUtils.toDate(date)) == 0)
.findFirst().orElse(null);
if (transaction != null) {
vo.setServiceAmount(transaction.getServiceAmount());
vo.setChannelCost(transaction.getChannelCost());
} else {
vo.setServiceAmount(BigDecimal.ZERO);
vo.setChannelCost(BigDecimal.ZERO);
}

View File

@ -12,6 +12,9 @@ import java.math.BigDecimal;
@Data
public class BonusMonthAmountVO {
@ApiModelProperty("年份")
private Integer year;
@ApiModelProperty("月份")
private Integer month;

View File

@ -147,7 +147,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectMonthAmount" resultMap="BonusMonthAmountVO">
select
month(sb.pay_time) as month,
year(sb.pay_time) as `year`,
month(sb.pay_time) as `month`,
sum(amount) as amount
<include refid="searchTables"/>
<where>

View File

@ -11,6 +11,7 @@ import com.ruoyi.ss.bonus.domain.vo.BonusMonthAmountVO;
import com.ruoyi.ss.bonus.domain.vo.ProvideBonusVO;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -141,4 +142,9 @@ public interface BonusService
* @return
*/
int selectCount(BonusQuery query);
/**
* 支付预计分成在指定时间的分成
*/
int payBonusBeforeTime(LocalDateTime time);
}

View File

@ -27,6 +27,7 @@ import com.ruoyi.ss.user.service.UserAssembler;
import com.ruoyi.system.domain.enums.config.ConfigKey;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
@ -36,6 +37,8 @@ import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@ -45,6 +48,7 @@ import java.util.stream.Collectors;
* @date 2024-08-20
*/
@Service
@Slf4j
public class BonusServiceImpl implements BonusService
{
@Autowired
@ -68,6 +72,9 @@ public class BonusServiceImpl implements BonusService
@Autowired
private UserAssembler userAssembler;
@Autowired
private ScheduledExecutorService scheduledExecutorService;
/**
* 查询分成明细
*
@ -290,6 +297,11 @@ public class BonusServiceImpl implements BonusService
return updateAmount;
});
// 立即执行一次分成
scheduledExecutorService.schedule(() -> {
this.payBonusBeforeTime(LocalDateTime.now());
}, 3, TimeUnit.SECONDS);
return result == null ? 0 : result;
}
@ -373,6 +385,31 @@ public class BonusServiceImpl implements BonusService
return bonusMapper.selectCount(query);
}
@Override
public int payBonusBeforeTime(LocalDateTime time) {
// 查询预计分成时间当前时间之前且为待分成的分成单
BonusQuery query = new BonusQuery();
query.setStatus(BonusStatus.WAIT_DIVIDE.getStatus());
query.setPrePayTimeEnd(time);
List<BonusVO> list = this.selectBonusList(query);
if (CollectionUtils.isEmptyElement(list)) {
log.info("暂无待分成的分成单");
return 0;
}
int sum = 0;
for (BonusVO bonus : list) {
try {
sum += this.payBonus(bonus);
} catch (Exception e) {
log.warn("分成打款失败id={}, e={}", bonus.getId(), e.getMessage());
}
}
return sum;
}
private int batchUpdateAmount(List<BonusVO> list) {
if (CollectionUtils.isEmptyElement(list)) {
return 0;

View File

@ -204,7 +204,7 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
rechargeDto.setStatus(TransactionBillStatus.SUCCESS.getStatus());
List<BillCountVo> billCount = transactionBillService.selectCount(rechargeDto);
if (!CollectionUtils.isEmpty(billCount) && billCount.get(0).getRecharge() != null) {
brief.setRechargeAmount(billCount.get(0).getRecharge());
brief.setRechargeAmount(billCount.get(0).getRechargeAmount());
} else {
brief.setRechargeAmount(BigDecimal.ZERO);
}
@ -215,7 +215,7 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
todayRechargeQuery.setCreateDate(now);
List<BillCountVo> todayBillCount = transactionBillService.selectCount(todayRechargeQuery);
if (!CollectionUtils.isEmpty(todayBillCount) && todayBillCount.get(0).getRecharge() != null) {
brief.setTodayRechargeAmount(todayBillCount.get(0).getRecharge());
brief.setTodayRechargeAmount(todayBillCount.get(0).getRechargeAmount());
} else {
brief.setTodayRechargeAmount(BigDecimal.ZERO);
}

View File

@ -81,4 +81,8 @@ public class BillCountVo {
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModelProperty("数量")
private Integer count;
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModelProperty("订单金额")
private BigDecimal rechargeAmount;
}

View File

@ -3,17 +3,18 @@ package com.ruoyi.ss.device.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.constants.DictTypeConstants;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.system.valid.DictValid;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
@ -151,8 +152,8 @@ public class Device extends BaseEntity
private BigDecimal serviceRate;
@ApiModelProperty("服务费类型")
@NotBlank(message = "服务费类型不允许为空", groups = {ValidGroup.Create.class})
@DictValid(type = DictTypeConstants.SERVICE_TYPE, message = "非法的服务费类型")
// @NotBlank(message = "服务费类型不允许为空", groups = {ValidGroup.Create.class})
// @DictValid(type = DictTypeConstants.SERVICE_TYPE, message = "非法的服务费类型")
private String serviceType;
@ApiModelProperty("剩余时长(秒)")

View File

@ -304,6 +304,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="serviceCharge" column="service_charge" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="channelCost" column="channel_cost" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="profit" column="profit" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="rechargeAmount" column="recharge_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
</resultMap>
<select id="selectCount" resultMap="BillCountVo">
@ -333,6 +334,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
stb.device_id as device_id,
</if>
SUM(IF( stb.type = '1' and stb.status = '2', stb.arrival_amount, 0 )) AS recharge,
SUM(IF( stb.type = '1' and stb.status = '2', stb.money, 0 )) AS recharge_amount,
SUM(IF( stb.type = '2' and stb.status = '14', stb.arrival_amount, 0 )) AS withdraw,
SUM(stb.service_charge) AS service_charge,
SUM(stb.channel_cost) AS channel_cost,

View File

@ -935,7 +935,15 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
ServiceUtil.assertion(bill == null || !TransactionBillType.RECHARGE.getType().equals(bill.getType()), "充值订单不存在");
ServiceUtil.assertion(!TransactionBillStatus.UNPAID.getStatus().equals(bill.getStatus()), "当前订单状态非未支付");
List<BonusVO> bonusList = bill.getBonusList();
Integer result = transactionTemplate.execute(status -> {
// 处理分成将金额分好
bonusService.partBonus(bonusList, bill.getMoney());
BonusVO platform = bonusList.stream().filter(bonus -> bonus.getArrivalType().equals(BonusArrivalType.PLATFORM.getType())).findFirst().orElse(null);
BonusVO mch = bonusList.stream().filter(bonus -> bonus.getArrivalType().equals(BonusArrivalType.MCH.getType())).findFirst().orElse(null);
// 修改订单信息
TransactionBill data = new TransactionBill();
data.setStatus(TransactionBillStatus.SUCCESS.getStatus());
@ -943,6 +951,12 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
data.setChannelId(pay.getChannelId());
data.setChannelCost(pay.getChannelCost());
data.setPayId(pay.getPayId());
if (platform != null) {
data.setServiceCharge(platform.getAmount());
}
if (mch != null) {
data.setArrivalAmount(mch.getAmount());
}
TransactionBillQuery query = new TransactionBillQuery();
query.setBillId(bill.getBillId());
query.setStatus(TransactionBillStatus.UNPAID.getStatus());
@ -950,9 +964,6 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
int updateCount = this.updateByQuery(data, query);
ServiceUtil.assertion(updateCount != 1, "订单状态已发生变化,请刷新后重试");
// 处理分成将金额分好
bonusService.partBonus(bill.getBonusList(), bill.getMoney());
return updateCount;
});

View File

@ -59,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
if(su.is_real, su.real_name, su.user_name) as real_or_user_name,
(select sum(stb.money) from sm_transaction_bill stb where stb.user_id = su.user_id and stb.type = '1' and stb.status = '2') as recharge_amount,
(select sum(stb.arrival_amount) from sm_transaction_bill stb where stb.user_id = su.user_id and stb.type = '2' and stb.status = '14') as with_drawl_amount,
(select sum(stb.arrival_amount) from sm_transaction_bill stb where stb.mch_id = su.user_id and stb.type = '1' and stb.status = '2') as total_income
(select sum(sb.payed_amount) from ss_bonus sb where sb.arrival_id = su.user_id and sb.arrival_type in ('2', '3')) as total_income
from sm_user su
</sql>

View File

@ -1,16 +1,11 @@
package com.ruoyi.task.bonus;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.bonus.domain.BonusQuery;
import com.ruoyi.ss.bonus.domain.BonusVO;
import com.ruoyi.ss.bonus.domain.enums.BonusStatus;
import com.ruoyi.ss.bonus.service.BonusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author wjh
@ -27,25 +22,7 @@ public class BonusTask {
* 分成打款
*/
public void payBonus() {
// 查询预计分成时间当前时间之前且为待分成的分成单
BonusQuery query = new BonusQuery();
query.setStatus(BonusStatus.WAIT_DIVIDE.getStatus());
query.setPrePayTimeEnd(LocalDateTime.now());
List<BonusVO> list = bonusService.selectBonusList(query);
if (CollectionUtils.isEmptyElement(list)) {
log.info("暂无待分成的分成单");
return;
}
for (BonusVO bonus : list) {
try {
bonusService.payBonus(bonus);
} catch (Exception e) {
log.warn("分成打款失败id={}, e={}", bonus.getId(), e.getMessage());
}
}
bonusService.payBonusBeforeTime(LocalDateTime.now());
}
}

View File

@ -7,6 +7,8 @@ import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.dashboard.DashboardService;
import com.ruoyi.ss.balancePeriod.domain.SmBalancePeriodQuery;
import com.ruoyi.ss.balancePeriod.service.ISmBalancePeriodService;
import com.ruoyi.ss.bonus.domain.BonusQuery;
import com.ruoyi.ss.bonus.service.BonusService;
import com.ruoyi.ss.businessRecord.service.ISmBusinessRecordService;
import com.ruoyi.ss.dashboard.ServiceIncomeQuery;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
@ -42,9 +44,13 @@ public class SmDashboardController extends BaseController {
@Autowired
private ISmBusinessRecordService businessRecordService;
@Autowired
private DashboardService dashboardService;
@Autowired
private BonusService bonusService;
/**
* 舆情分析数据
*/
@ -99,4 +105,12 @@ public class SmDashboardController extends BaseController {
return success(dashboardService.getServiceIncome(query));
}
/**
* 按月统计分成
*/
@GetMapping("/bonusMonthAmount")
public AjaxResult getBonusMonthAmount(BonusQuery query) {
return success(bonusService.selectMonthAmount(query));
}
}