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.AbnormalQuery;
import com.ruoyi.ss.abnormal.domain.enums.AbnormalStatus; import com.ruoyi.ss.abnormal.domain.enums.AbnormalStatus;
import com.ruoyi.ss.abnormal.service.AbnormalService; 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.domain.SmComplaintQuery;
import com.ruoyi.ss.complaint.service.ISmComplaintService; import com.ruoyi.ss.complaint.service.ISmComplaintService;
import com.ruoyi.ss.dashboard.ServiceIncomeQuery; import com.ruoyi.ss.dashboard.ServiceIncomeQuery;
@ -65,6 +69,9 @@ public class DashboardService {
@Autowired @Autowired
private ReceiveBillService receiveBillService; private ReceiveBillService receiveBillService;
@Autowired
private BonusService bonusService;
public TodoListVO getTodoList() { public TodoListVO getTodoList() {
TodoListVO vo = new TodoListVO(); TodoListVO vo = new TodoListVO();
@ -102,6 +109,13 @@ public class DashboardService {
public List<ServiceIncomeVO> getServiceIncome(ServiceIncomeQuery query) { 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(); TransactionBillQuery billQuery = new TransactionBillQuery();
billQuery.setStartDate(query.getStartDate()); billQuery.setStartDate(query.getStartDate());
@ -128,15 +142,23 @@ public class DashboardService {
ServiceIncomeVO vo = new ServiceIncomeVO(); ServiceIncomeVO vo = new ServiceIncomeVO();
vo.setDate(date); 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() TransactionAmountVO<Date> transaction = amountList.stream()
.filter(item -> item.getKey().compareTo(DateUtils.toDate(date)) == 0) .filter(item -> item.getKey().compareTo(DateUtils.toDate(date)) == 0)
.findFirst().orElse(null); .findFirst().orElse(null);
if (transaction != null) { if (transaction != null) {
vo.setServiceAmount(transaction.getServiceAmount());
vo.setChannelCost(transaction.getChannelCost()); vo.setChannelCost(transaction.getChannelCost());
} else { } else {
vo.setServiceAmount(BigDecimal.ZERO);
vo.setChannelCost(BigDecimal.ZERO); vo.setChannelCost(BigDecimal.ZERO);
} }

View File

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

View File

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

View File

@ -11,6 +11,7 @@ import com.ruoyi.ss.bonus.domain.vo.BonusMonthAmountVO;
import com.ruoyi.ss.bonus.domain.vo.ProvideBonusVO; import com.ruoyi.ss.bonus.domain.vo.ProvideBonusVO;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -141,4 +142,9 @@ public interface BonusService
* @return * @return
*/ */
int selectCount(BonusQuery query); 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.domain.enums.config.ConfigKey;
import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysDeptService; import com.ruoyi.system.service.ISysDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
@ -36,6 +37,8 @@ import java.math.RoundingMode;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -45,6 +48,7 @@ import java.util.stream.Collectors;
* @date 2024-08-20 * @date 2024-08-20
*/ */
@Service @Service
@Slf4j
public class BonusServiceImpl implements BonusService public class BonusServiceImpl implements BonusService
{ {
@Autowired @Autowired
@ -68,6 +72,9 @@ public class BonusServiceImpl implements BonusService
@Autowired @Autowired
private UserAssembler userAssembler; private UserAssembler userAssembler;
@Autowired
private ScheduledExecutorService scheduledExecutorService;
/** /**
* 查询分成明细 * 查询分成明细
* *
@ -290,6 +297,11 @@ public class BonusServiceImpl implements BonusService
return updateAmount; return updateAmount;
}); });
// 立即执行一次分成
scheduledExecutorService.schedule(() -> {
this.payBonusBeforeTime(LocalDateTime.now());
}, 3, TimeUnit.SECONDS);
return result == null ? 0 : result; return result == null ? 0 : result;
} }
@ -373,6 +385,31 @@ public class BonusServiceImpl implements BonusService
return bonusMapper.selectCount(query); 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) { private int batchUpdateAmount(List<BonusVO> list) {
if (CollectionUtils.isEmptyElement(list)) { if (CollectionUtils.isEmptyElement(list)) {
return 0; return 0;

View File

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

View File

@ -81,4 +81,8 @@ public class BillCountVo {
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModelProperty("数量") @ApiModelProperty("数量")
private Integer count; 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.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
import com.ruoyi.common.annotation.Excel; 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.BaseEntity;
import com.ruoyi.common.core.domain.JsonViewProfile; import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.domain.ValidGroup; import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.system.valid.DictValid;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Range; import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat; 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.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Date; import java.util.Date;
@ -151,8 +152,8 @@ public class Device extends BaseEntity
private BigDecimal serviceRate; private BigDecimal serviceRate;
@ApiModelProperty("服务费类型") @ApiModelProperty("服务费类型")
@NotBlank(message = "服务费类型不允许为空", groups = {ValidGroup.Create.class}) // @NotBlank(message = "服务费类型不允许为空", groups = {ValidGroup.Create.class})
@DictValid(type = DictTypeConstants.SERVICE_TYPE, message = "非法的服务费类型") // @DictValid(type = DictTypeConstants.SERVICE_TYPE, message = "非法的服务费类型")
private String serviceType; private String serviceType;
@ApiModelProperty("剩余时长(秒)") @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="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="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="profit" column="profit" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="rechargeAmount" column="recharge_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
</resultMap> </resultMap>
<select id="selectCount" resultMap="BillCountVo"> <select id="selectCount" resultMap="BillCountVo">
@ -333,6 +334,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
stb.device_id as device_id, stb.device_id as device_id,
</if> </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.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(IF( stb.type = '2' and stb.status = '14', stb.arrival_amount, 0 )) AS withdraw,
SUM(stb.service_charge) AS service_charge, SUM(stb.service_charge) AS service_charge,
SUM(stb.channel_cost) AS channel_cost, 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(bill == null || !TransactionBillType.RECHARGE.getType().equals(bill.getType()), "充值订单不存在");
ServiceUtil.assertion(!TransactionBillStatus.UNPAID.getStatus().equals(bill.getStatus()), "当前订单状态非未支付"); ServiceUtil.assertion(!TransactionBillStatus.UNPAID.getStatus().equals(bill.getStatus()), "当前订单状态非未支付");
List<BonusVO> bonusList = bill.getBonusList();
Integer result = transactionTemplate.execute(status -> { 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(); TransactionBill data = new TransactionBill();
data.setStatus(TransactionBillStatus.SUCCESS.getStatus()); data.setStatus(TransactionBillStatus.SUCCESS.getStatus());
@ -943,6 +951,12 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
data.setChannelId(pay.getChannelId()); data.setChannelId(pay.getChannelId());
data.setChannelCost(pay.getChannelCost()); data.setChannelCost(pay.getChannelCost());
data.setPayId(pay.getPayId()); data.setPayId(pay.getPayId());
if (platform != null) {
data.setServiceCharge(platform.getAmount());
}
if (mch != null) {
data.setArrivalAmount(mch.getAmount());
}
TransactionBillQuery query = new TransactionBillQuery(); TransactionBillQuery query = new TransactionBillQuery();
query.setBillId(bill.getBillId()); query.setBillId(bill.getBillId());
query.setStatus(TransactionBillStatus.UNPAID.getStatus()); query.setStatus(TransactionBillStatus.UNPAID.getStatus());
@ -950,9 +964,6 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
int updateCount = this.updateByQuery(data, query); int updateCount = this.updateByQuery(data, query);
ServiceUtil.assertion(updateCount != 1, "订单状态已发生变化,请刷新后重试"); ServiceUtil.assertion(updateCount != 1, "订单状态已发生变化,请刷新后重试");
// 处理分成将金额分好
bonusService.partBonus(bill.getBonusList(), bill.getMoney());
return updateCount; 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, 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.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.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 from sm_user su
</sql> </sql>

View File

@ -1,16 +1,11 @@
package com.ruoyi.task.bonus; 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 com.ruoyi.ss.bonus.service.BonusService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* @author wjh * @author wjh
@ -27,25 +22,7 @@ public class BonusTask {
* 分成打款 * 分成打款
*/ */
public void payBonus() { public void payBonus() {
// 查询预计分成时间当前时间之前且为待分成的分成单 bonusService.payBonusBeforeTime(LocalDateTime.now());
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());
}
}
} }
} }

View File

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