Commit 3d68dd86 authored by chenjiuping's avatar chenjiuping

自动核销功能

parent b94caa15
......@@ -139,5 +139,21 @@ public interface ReceiptService extends IService<ReceiptDO> {
ReceiptExportDto getReceiptExportByOrderId(Long orderId);
/**
* 判断当前收款单有没有达到比例
*
* @param receiptDO
* @param proportion
* @return
*/
Boolean judgingProportion(ReceiptDO receiptDO, String proportion);
/**
* 自动更新收款单的核销状态
*
* @param receiptDO
*/
void autoWriteOffReceipt(ReceiptDO receiptDO, String userId, String userName);
}
package cn.iocoder.yudao.module.wealth.controller.admin.job;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.wealth.dal.dataobject.receipt.ReceiptDO;
import cn.iocoder.yudao.module.wealth.enums.ReceiptStatusEnum;
import cn.iocoder.yudao.module.wealth.service.receipt.ReceiptService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
/**
* 收款单自动核销任务
*/
@Component
@TenantJob
@Slf4j
public class ReceiptAutoWriteOff implements JobHandler {
@Resource
ReceiptService receiptService;
@Resource
AdminUserApi adminUserApi;
@Override
public String execute(String param) throws Exception {
if (StrUtil.isBlank(param)) {
log.error("自动核销比例未配置,自动退出");
return "";
}
String[] paramArray = param.split(",");
if (paramArray.length != 2 || StrUtil.isBlank(paramArray[0]) || StrUtil.isBlank(paramArray[1])) {
log.error("自动核销比例JOB参数错误,自动退出");
return "";
}
AdminUserRespDTO adminUserRespDTO = adminUserApi.getUser(Long.parseLong(paramArray[1]));
if (null == adminUserRespDTO) {
log.error("自动核销比例JOB参数错误,核销人配置错误,自动退出");
return "";
}
//查询所有收款单状态为待核销的
LambdaQueryWrapper<ReceiptDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.and(i -> i.eq(ReceiptDO::getState, ReceiptStatusEnum.WRITE_OFF_WAITING.getValue()).or().eq(ReceiptDO::getState, ReceiptStatusEnum.WRITE_OFF_PART_ING.getValue()));
List<ReceiptDO> receiptDOList = receiptService.selectList(lambdaQueryWrapper);
for (ReceiptDO receiptDO : receiptDOList) {
try {
//判断当前收款单下的收款明细是不是全部是已核销并且核销比例要大于配置(params)
Boolean result = receiptService.judgingProportion(receiptDO, paramArray[0]);
if (result) {
receiptService.autoWriteOffReceipt(receiptDO, paramArray[1], adminUserRespDTO.getNickname());
}
} catch (Exception e) {
log.error("收款单{}自动核销出错原因:{}", receiptDO.getReceiptNo(), e.getMessage());
}
}
return "";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment