sgj
2026-03-02 747a4a421dc8c1faf1c768aaac0fc7abc258e2c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.fzzy.igds.timer;
 
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.data.BaseResp;
import com.fzzy.igds.domain.Depot;
import com.fzzy.igds.domain.FoodPrice;
import com.fzzy.igds.domain.PledgeContract;
import com.fzzy.igds.service.DepotService;
import com.fzzy.igds.service.FoodPriceService;
import com.fzzy.igds.service.PledgeContractService;
import com.fzzy.work.data.WorkBizType;
import com.fzzy.work.domain.WorkOrderConf;
import com.fzzy.work.service.BizWorkService;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * @Description 警告信息定时统计:还款提醒
 * @Author CZT
 * @Date 2026/1/23 9:14
 */
@Slf4j
 
@Service
public class JobWarnService {
 
    @Resource
    private PledgeContractService contractService;
    @Resource
    private DepotService depotService;
    @Resource
    private FoodPriceService foodPriceService;
    @Resource
    private BizWorkService workService;
 
    /**
     * 每天两点执行:还款提醒
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void timer() {
        doExe();
    }
 
    /**
     * 开始质押合同核算
     */
    public void doExe() {
 
        List<PledgeContract> contractList = contractService.getContractByPledge(new Date());
        if (null == contractList || contractList.isEmpty()) {
            log.error("-----当前没有有效期的质押合同,不执行提醒核算-----");
            return;
        }
 
        Depot depot;
        FoodPrice foodPrice;
        WorkOrderConf conf;
        double sumMoney = 0.0;
        double per = 0.0;
        double backMoney = 0.0;
        for (PledgeContract pledgeContract : contractList) {
            log.info("-----开始处理质押合同:{}-----", pledgeContract.getName());
 
            //计算待还款金额
            backMoney = pledgeContract.getContractAmount() - pledgeContract.getRepaidAmount();
            if (backMoney <= 0.0) {
                //若待还金额为0,则不统计此合同
                log.error("-----当前合同={}没有待还金额为{},不执行提醒核算-----", pledgeContract.getName(), backMoney);
                continue;
            }
 
            if (StringUtils.isBlank(pledgeContract.getPledgeBank())) {
                //若质押银行未空,则跳过当前合同
                log.error("-----当前合同={}没有设置质押银行,不执行提醒核算-----", pledgeContract.getName());
                continue;
            }
 
            if (StringUtils.isBlank(pledgeContract.getDepotIds())) {
                //若质押仓库为空,则跳过当前合同
                log.error("-----当前合同={}没有设置质押仓库,不执行提醒核算-----", pledgeContract.getName());
                continue;
            }
 
            String[] depotIds = pledgeContract.getDepotIds().split(",");
            if (depotIds.length < 1) {
                //若质押仓库为空,则跳过当前合同
                log.error("-----当前合同={}没有设置质押仓库,不执行提醒核算-----", pledgeContract.getName());
                continue;
            }
            sumMoney = 0.0;
            for (String depotId : depotIds) {
                //查询仓库信息
                depot = depotService.getCacheDepot(pledgeContract.getCompanyId(), depotId);
                if (null == depot) {
                    log.error("-----当前合同={}下仓库={}不存在,不统计此仓库-----", pledgeContract.getName(), depotId);
                    continue;
                }
                if (null == depot.getStorageReal()) {
                    depot.setStorageReal(0.0);
                }
 
                foodPrice = foodPriceService.getDataByBankAndFood(pledgeContract.getPledgeBank(), depot.getFoodVariety());
                if (null == foodPrice || null == foodPrice.getPrice()) {
                    log.error("-----当前合同={}下仓库={}对应的品种={}未配置价格,不统计此仓库-----", pledgeContract.getName(), depot.getName(), depot.getFoodVariety());
                    continue;
                }
 
                sumMoney += depot.getStorageReal() * foodPrice.getPrice();
            }
 
            per = sumMoney / backMoney;
 
            if (per > 1.1) {
                log.error("-----当前合同={}下质押仓库={}库存未到待还款的110%,不生成还款提醒工单-----", pledgeContract.getName(), pledgeContract.getDepotNames());
                continue;
            }
 
            //执行流程
            conf = workService.getConfByDeptId(pledgeContract.getPledgeDept(), WorkBizType.TYPE_50);
            //流程不启用
            if (null == conf || Constant.YN_N.equals(conf.getValTag())) {
                log.error("-----当前合同={}质押库区={}未配置还款提醒审批流程,无法生成工单提醒-----", pledgeContract.getName(), pledgeContract.getPledgeDept());
                continue;
            }
 
            BaseResp resp = workService.startByBackMoney(pledgeContract, conf);
            log.info("---------当前合同={}启动还款提醒工单流程------{}", pledgeContract.getName(), resp);
        }
    }
 
}