1.每天凌晨0点5分执行,计算分账结果

2.增加分账项目
This commit is contained in:
邱贞招 2024-05-27 14:36:47 +08:00
parent da26d6b2b1
commit 3ce298b53d
13 changed files with 584 additions and 7 deletions

View File

@ -168,7 +168,7 @@ public class Constants
/**
* 定时任务白名单配置仅允许访问的包名如其他需要可以自行添加
*/
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi.quartz.task" };
public static final String[] JOB_WHITELIST_STR = { "com.ruoyi.quartz.task", "com.ruoyi.system.task" };
/**
* 定时任务违规的字符

View File

@ -110,6 +110,30 @@ public class SysUser extends BaseEntity
/** 角色ID */
private Long roleId;
/** 分账项目 */
@Excel(name = "分账项目")
private String dividendItem;
/** 分账项目ids */
@Excel(name = "分账项目ids")
private List<String> dividendItemIds;
public List<String> getDividendItemIds() {
return dividendItemIds;
}
public void setDividendItemIds(List<String> dividendItemIds) {
this.dividendItemIds = dividendItemIds;
}
public String getDividendItem() {
return dividendItem;
}
public void setDividendItem(String dividendItem) {
this.dividendItem = dividendItem;
}
public SysUser()
{

View File

@ -5,7 +5,7 @@ import com.ruoyi.common.utils.StringUtils;
/**
* 定时任务调度测试
*
*
* @author ruoyi
*/
@Component("ryTask")

View File

@ -0,0 +1,53 @@
package com.ruoyi.system.domain;
import java.math.BigDecimal;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 分账明细对象 et_dividend_detail
*
* @author 邱贞招
* @date 2024-05-27
*/
@Data
public class EtDividendDetail extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 区域id */
@Excel(name = "区域id")
private Long areaId;
/** 合伙人id */
@Excel(name = "合伙人id")
private Long partnerId;
/** 订单号 */
@Excel(name = "订单号")
private String orderNo;
/** 订单总金额 */
@Excel(name = "订单总金额")
private BigDecimal totalAmount;
/** 分账金额 */
@Excel(name = "分账金额")
private BigDecimal dividendAmount;
/** 分红比例 */
@Excel(name = "分红比例")
private Integer dividendProportion;
/** 分账项目 */
@Excel(name = "分账项目")
private String dividendItem;
}

View File

@ -0,0 +1,70 @@
package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.EtDividendDetail;
/**
* 分账明细Mapper接口
*
* @author 邱贞招
* @date 2024-05-27
*/
public interface EtDividendDetailMapper
{
/**
* 查询分账明细
*
* @param id 分账明细主键
* @return 分账明细
*/
public EtDividendDetail selectEtDividendDetailById(Long id);
/**
* 查询分账明细列表
*
* @param etDividendDetail 分账明细
* @return 分账明细集合
*/
public List<EtDividendDetail> selectEtDividendDetailList(EtDividendDetail etDividendDetail);
/**
* 新增分账明细
*
* @param etDividendDetail 分账明细
* @return 结果
*/
public int insertEtDividendDetail(EtDividendDetail etDividendDetail);
/**
* 修改分账明细
*
* @param etDividendDetail 分账明细
* @return 结果
*/
public int updateEtDividendDetail(EtDividendDetail etDividendDetail);
/**
* 删除分账明细
*
* @param id 分账明细主键
* @return 结果
*/
public int deleteEtDividendDetailById(Long id);
/**
* 批量删除分账明细
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteEtDividendDetailByIds(Long[] ids);
/**
* 判断是否已经计算过
* @param date
* @return
*/
public int isDividendComputed(String date);
}

View File

@ -0,0 +1,69 @@
package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.EtDividendDetail;
/**
* 分账明细Service接口
*
* @author 邱贞招
* @date 2024-05-27
*/
public interface IEtDividendDetailService
{
/**
* 查询分账明细
*
* @param id 分账明细主键
* @return 分账明细
*/
public EtDividendDetail selectEtDividendDetailById(Long id);
/**
* 查询分账明细列表
*
* @param etDividendDetail 分账明细
* @return 分账明细集合
*/
public List<EtDividendDetail> selectEtDividendDetailList(EtDividendDetail etDividendDetail);
/**
* 新增分账明细
*
* @param etDividendDetail 分账明细
* @return 结果
*/
public int insertEtDividendDetail(EtDividendDetail etDividendDetail);
/**
* 修改分账明细
*
* @param etDividendDetail 分账明细
* @return 结果
*/
public int updateEtDividendDetail(EtDividendDetail etDividendDetail);
/**
* 批量删除分账明细
*
* @param ids 需要删除的分账明细主键集合
* @return 结果
*/
public int deleteEtDividendDetailByIds(Long[] ids);
/**
* 删除分账明细信息
*
* @param id 分账明细主键
* @return 结果
*/
public int deleteEtDividendDetailById(Long id);
/**
* 判断该日期是否已经计算过分账结果
*
* @param date 日期格式 yyyy-MM-dd
* @return 结果
*/
boolean isDividendComputed(String date);
}

View File

@ -161,5 +161,6 @@ public interface IEtOrderService
List<RechargeVo> rechargeList(EtOrder etOrder);
// public partnerBill();
}

View File

@ -0,0 +1,110 @@
package com.ruoyi.system.service.impl;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.EtDividendDetailMapper;
import com.ruoyi.system.domain.EtDividendDetail;
import com.ruoyi.system.service.IEtDividendDetailService;
/**
* 分账明细Service业务层处理
*
* @author 邱贞招
* @date 2024-05-27
*/
@Service
public class EtDividendDetailServiceImpl implements IEtDividendDetailService
{
@Autowired
private EtDividendDetailMapper etDividendDetailMapper;
/**
* 查询分账明细
*
* @param id 分账明细主键
* @return 分账明细
*/
@Override
public EtDividendDetail selectEtDividendDetailById(Long id)
{
return etDividendDetailMapper.selectEtDividendDetailById(id);
}
/**
* 查询分账明细列表
*
* @param etDividendDetail 分账明细
* @return 分账明细
*/
@Override
public List<EtDividendDetail> selectEtDividendDetailList(EtDividendDetail etDividendDetail)
{
return etDividendDetailMapper.selectEtDividendDetailList(etDividendDetail);
}
/**
* 新增分账明细
*
* @param etDividendDetail 分账明细
* @return 结果
*/
@Override
public int insertEtDividendDetail(EtDividendDetail etDividendDetail)
{
etDividendDetail.setCreateTime(DateUtils.getNowDate());
return etDividendDetailMapper.insertEtDividendDetail(etDividendDetail);
}
/**
* 修改分账明细
*
* @param etDividendDetail 分账明细
* @return 结果
*/
@Override
public int updateEtDividendDetail(EtDividendDetail etDividendDetail)
{
return etDividendDetailMapper.updateEtDividendDetail(etDividendDetail);
}
/**
* 批量删除分账明细
*
* @param ids 需要删除的分账明细主键
* @return 结果
*/
@Override
public int deleteEtDividendDetailByIds(Long[] ids)
{
return etDividendDetailMapper.deleteEtDividendDetailByIds(ids);
}
/**
* 删除分账明细信息
*
* @param id 分账明细主键
* @return 结果
*/
@Override
public int deleteEtDividendDetailById(Long id)
{
return etDividendDetailMapper.deleteEtDividendDetailById(id);
}
/**
* 判断是否已经计算过
* @param date
* @return
*/
@Override
public boolean isDividendComputed(String date) {
if(etDividendDetailMapper.isDividendComputed(date) > 0){
return true;
}
return false;
}
}

View File

@ -215,7 +215,7 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
* 新增保存部门信息
*
* 分账 partner_dividend 对账 reconciliation dividend amount 金额 分成 Divide amount 总金额
* @param dept 部门信息
* @return 结果
*/

View File

@ -19,6 +19,7 @@ import com.ruoyi.system.service.IAsDeviceService;
import com.ruoyi.system.service.IEtOperatingAreaService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -139,7 +140,30 @@ public class SysUserServiceImpl implements ISysUserService
@Override
public SysUser selectUserById(Long userId)
{
return userMapper.selectUserById(userId);
SysUser sysUser = userMapper.selectUserById(userId);
if(ObjectUtils.isNotEmpty(sysUser)){
// 显示分润项目
showDividendItem(sysUser);
}
return sysUser;
}
/**
* 回显分账项目
* @param sysUser
*/
private void showDividendItem(SysUser sysUser) {
String space = sysUser.getDividendItem();
if(StringUtils.isNotEmpty(space)){
String[] split = space.split(",");
List<String> ids = new ArrayList<>();
for (String id:split) {
ids.add(id);
}
sysUser.setDividendItemIds(ids);
}else{
sysUser.setDividendItemIds(new ArrayList<>());
}
}
/**
@ -274,6 +298,8 @@ public class SysUserServiceImpl implements ISysUserService
@Transactional
public int insertUser(SysUser user)
{
// 分账项目
setDividendItem(user);
// 新增用户信息
int rows = userMapper.insertUser(user);
// 新增用户岗位关联
@ -283,6 +309,23 @@ public class SysUserServiceImpl implements ISysUserService
return rows;
}
private void setDividendItem(SysUser user) {
List<String> ids = user.getDividendItemIds();
if(ObjectUtils.isNotEmpty(ids)){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ids.size(); i++) {
sb.append(ids.get(i));
// 判断是否是最后一个元素如果不是则添加逗号
if (i < ids.size() - 1) {
sb.append(",");
}
}
user.setDividendItem(sb.toString());
}else{
user.setDividendItem("");
}
}
/**
* 注册用户信息
*
@ -314,6 +357,8 @@ public class SysUserServiceImpl implements ISysUserService
userPostMapper.deleteUserPostByUserId(userId);
// 新增用户与岗位管理
insertUserPost(user);
// 分账项目
setDividendItem(user);
return userMapper.updateUser(user);
}

View File

@ -0,0 +1,104 @@
package com.ruoyi.system.task;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.EtDividendDetail;
import com.ruoyi.system.domain.EtOperatingArea;
import com.ruoyi.system.domain.EtOrder;
import com.ruoyi.system.mapper.EtOrderMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.IEtDividendDetailService;
import com.ruoyi.system.service.IEtOperatingAreaService;
import com.ruoyi.system.service.IEtOrderService;
import com.ruoyi.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
* 定时任务调度测试
*
* @author ruoyi
*/
@Slf4j
@Component("etTask")
public class EtTask {
@Resource
private EtOrderMapper etOrderMapper;
@Autowired
private IEtOperatingAreaService etOperatingAreaService;
@Resource
private SysUserMapper userMapper;
@Autowired
private IEtDividendDetailService dividendDetailService;
/**
* 每天凌晨0点5分执行计算分账结果
* cron: 0 5 0 * * ?
*/
public void computeDividend()
{
log.info("每天凌晨0点5分执行计算分账结果");
// 获取昨天的订单,2024-05-26 00:00:00 -- 2024-05-26 23:59:59
// 获取昨天日期格式 yyyy-MM-dd
LocalDate yesterday = LocalDate.now().minusDays(1);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String formattedYesterday = yesterday.format(formatter);
log.info("获取昨天日期 = " + formattedYesterday);
//判断该日期是否已经计算过分账结果
if(dividendDetailService.isDividendComputed(LocalDate.now().format(formatter))){
log.info("该日期已经计算过分账结果");
return;
}
String startDateStr = formattedYesterday + " "+ Constants.DATE_FORMAT_START_PEREND;
String endDateStr = formattedYesterday + " " +Constants.DATE_FORMAT_END_PEREND;
EtOrder order = new EtOrder();
order.setStartTime(startDateStr);
order.setEndTime(endDateStr);
order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
List<EtOrder> orderListByDate = etOrderMapper.selectEtOrderList(order);
for(EtOrder order1:orderListByDate){
EtDividendDetail etDividendDetail = new EtDividendDetail();
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order1.getAreaId());
SysUser sysUser = new SysUser();
sysUser.setUserType("03");
sysUser.setAreaId(area.getAreaId());
List<SysUser> sysUsers = userMapper.selectUserList(sysUser);
for(SysUser user : sysUsers){
etDividendDetail.setAreaId(area.getAreaId());
etDividendDetail.setPartnerId(user.getUserId());
etDividendDetail.setOrderNo(order1.getOrderNo());
etDividendDetail.setTotalAmount(order1.getTotalFee());
etDividendDetail.setDividendAmount(order1.getTotalFee().multiply(new BigDecimal(user.getDividendProportion()).divide(new BigDecimal(100),2, BigDecimal.ROUND_HALF_UP)));
etDividendDetail.setDividendProportion(user.getDividendProportion());
etDividendDetail.setCreateTime(DateUtils.getNowDate());
etDividendDetail.setDividendItem(user.getDividendItem());
int i = dividendDetailService.insertEtDividendDetail(etDividendDetail);
if(i==0){
throw new ServiceException("保存分账明细失败");
}
}
}
}
}

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.EtDividendDetailMapper">
<resultMap type="EtDividendDetail" id="EtDividendDetailResult">
<result property="id" column="id" />
<result property="areaId" column="area_id" />
<result property="partnerId" column="partner_id" />
<result property="orderNo" column="order_no" />
<result property="totalAmount" column="total_amount" />
<result property="dividendAmount" column="dividend_amount" />
<result property="dividendProportion" column="dividend_proportion" />
<result property="createTime" column="create_time" />
<result property="dividendItem" column="dividend_item" />
</resultMap>
<sql id="selectEtDividendDetailVo">
select id, area_id, partner_id, order_no, total_amount, dividend_amount, dividend_proportion, create_time, dividend_item from et_dividend_detail
</sql>
<select id="selectEtDividendDetailList" parameterType="EtDividendDetail" resultMap="EtDividendDetailResult">
<include refid="selectEtDividendDetailVo"/>
<where>
<if test="areaId != null "> and area_id = #{areaId}</if>
<if test="partnerId != null "> and partner_id = #{partnerId}</if>
<if test="orderNo != null and orderNo != ''"> and order_no = #{orderNo}</if>
<if test="totalAmount != null "> and total_amount = #{totalAmount}</if>
<if test="dividendAmount != null "> and dividend_amount = #{dividendAmount}</if>
<if test="dividendProportion != null "> and dividend_proportion = #{dividendProportion}</if>
<if test="dividendItem != null and dividendItem != ''"> and dividend_item = #{dividendItem}</if>
</where>
</select>
<select id="selectEtDividendDetailById" parameterType="Long" resultMap="EtDividendDetailResult">
<include refid="selectEtDividendDetailVo"/>
where id = #{id}
</select>
<select id="isDividendComputed" resultType="Integer">
SELECT COUNT(1)
FROM et_dividend_detail
WHERE DATE(create_time) = #{date}
</select>
<insert id="insertEtDividendDetail" parameterType="EtDividendDetail">
insert into et_dividend_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="areaId != null">area_id,</if>
<if test="partnerId != null">partner_id,</if>
<if test="orderNo != null and orderNo != ''">order_no,</if>
<if test="totalAmount != null">total_amount,</if>
<if test="dividendAmount != null">dividend_amount,</if>
<if test="dividendProportion != null">dividend_proportion,</if>
<if test="createTime != null">create_time,</if>
<if test="dividendItem != null">dividend_item,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="areaId != null">#{areaId},</if>
<if test="partnerId != null">#{partnerId},</if>
<if test="orderNo != null and orderNo != ''">#{orderNo},</if>
<if test="totalAmount != null">#{totalAmount},</if>
<if test="dividendAmount != null">#{dividendAmount},</if>
<if test="dividendProportion != null">#{dividendProportion},</if>
<if test="createTime != null">#{createTime},</if>
<if test="dividendItem != null">#{dividendItem},</if>
</trim>
</insert>
<update id="updateEtDividendDetail" parameterType="EtDividendDetail">
update et_dividend_detail
<trim prefix="SET" suffixOverrides=",">
<if test="areaId != null">area_id = #{areaId},</if>
<if test="partnerId != null">partner_id = #{partnerId},</if>
<if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
<if test="totalAmount != null">total_amount = #{totalAmount},</if>
<if test="dividendAmount != null">dividend_amount = #{dividendAmount},</if>
<if test="dividendProportion != null">dividend_proportion = #{dividendProportion},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="dividendItem != null">dividend_item = #{dividendItem},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteEtDividendDetailById" parameterType="Long">
delete from et_dividend_detail where id = #{id}
</delete>
<delete id="deleteEtDividendDetailByIds" parameterType="String">
delete from et_dividend_detail where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -25,6 +25,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
<result property="areaId" column="area_id" />
<result property="dividendProportion" column="dividend_proportion" />
<result property="dividendItem" column="dividend_item" />
<result property="cooperationTime" column="cooperation_time" />
<result property="dividendStatus" column="dividend_status" />
<association property="dept" javaType="SysDept" resultMap="deptResult" />
@ -51,7 +52,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectUserVo">
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.area_id,u.dividend_proportion,u.cooperation_time,u.dividend_status,
select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.area_id,u.dividend_proportion,u.dividend_item, u.cooperation_time,u.dividend_status,
d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,a.area_name areaName
from sys_user u
@ -62,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, u.area_id,u.dividend_proportion,u.cooperation_time,u.dividend_status,d.dept_name, d.leader,a.area_name areaName from sys_user u
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, u.area_id,u.dividend_proportion,u.dividend_item,u.cooperation_time,u.dividend_status,d.dept_name, d.leader,a.area_name areaName from sys_user u
left join sys_dept d on u.dept_id = d.dept_id
left join et_operating_area a on u.area_id = a.area_id
where u.del_flag = '0'
@ -168,6 +169,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null and remark != ''">remark,</if>
<if test="areaId != null and areaId != ''">area_id,</if>
<if test="dividendProportion != null and dividendProportion != ''">dividend_proportion,</if>
<if test="dividendItem != null and dividendItem != ''">dividend_item,</if>
<if test="cooperationTime != null">cooperation_time,</if>
<if test="dividendStatus != null and dividendStatus != ''">dividend_status,</if>
create_time
@ -187,6 +189,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null and remark != ''">#{remark},</if>
<if test="areaId != null">#{areaId},</if>
<if test="dividendProportion != null and dividendProportion != ''">#{dividendProportion},</if>
<if test="dividendItem != null and dividendItem != ''">#{dividendItem},</if>
<if test="cooperationTime != null">#{cooperationTime},</if>
<if test="dividendStatus != null and dividendStatus != ''">#{dividendStatus},</if>
sysdate()
@ -212,7 +215,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">remark = #{remark},</if>
<if test="areaId != null">area_id = #{areaId},</if>
<if test="dividendProportion != null">dividend_proportion = #{dividendProportion},</if>
<if test="cooperationTime != null">cooperation_time = #{recooperationTimemark},</if>
<if test="dividendItem != null">dividend_item = #{dividendItem},</if>
<if test="cooperationTime != null">cooperation_time = #{cooperationTime},</if>
<if test="dividendStatus != null">dividend_status = #{dividendStatus},</if>
update_time = sysdate()
</set>