| | |
| | | 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; |
| | |
| | | /** |
| | | * 每天两点执行:还款提醒 |
| | | */ |
| | | // @Scheduled(cron = "0 0 2 * * ?") |
| | | @Scheduled(cron = "0 7 19 * * ?") |
| | | @Scheduled(cron = "0 0 2 * * ?") |
| | | public void timer() { |
| | | doExe(); |
| | | } |
| | |
| | | public void doExe() { |
| | | |
| | | List<PledgeContract> contractList = contractService.getContractByPledge(new Date()); |
| | | if(null == contractList || contractList.isEmpty()){ |
| | | if (null == contractList || contractList.isEmpty()) { |
| | | log.error("-----当前没有有效期的质押合同,不执行提醒核算-----"); |
| | | return; |
| | | } |
| | |
| | | double per = 0.0; |
| | | double backMoney = 0.0; |
| | | for (PledgeContract pledgeContract : contractList) { |
| | | log.info("-----开始处理质押合同:{}-----", pledgeContract.getContractName()); |
| | | log.info("-----开始处理质押合同:{}-----", pledgeContract.getName()); |
| | | |
| | | //计算待还款金额 |
| | | backMoney = pledgeContract.getContractAmount() - pledgeContract.getRepaidAmount(); |
| | | if(backMoney <= 0.0){ |
| | | if (backMoney <= 0.0) { |
| | | //若待还金额为0,则不统计此合同 |
| | | log.error("-----当前合同={}没有待还金额为{},不执行提醒核算-----", pledgeContract.getContractName(), backMoney); |
| | | log.error("-----当前合同={}没有待还金额为{},不执行提醒核算-----", pledgeContract.getName(), backMoney); |
| | | continue; |
| | | } |
| | | |
| | | if(StringUtils.isBlank(pledgeContract.getPledgeBank())){ |
| | | if (StringUtils.isBlank(pledgeContract.getPledgeBank())) { |
| | | //若质押银行未空,则跳过当前合同 |
| | | log.error("-----当前合同={}没有设置质押银行,不执行提醒核算-----", pledgeContract.getContractName()); |
| | | log.error("-----当前合同={}没有设置质押银行,不执行提醒核算-----", pledgeContract.getName()); |
| | | continue; |
| | | } |
| | | |
| | | if(StringUtils.isBlank(pledgeContract.getDepotIds())){ |
| | | if (StringUtils.isBlank(pledgeContract.getDepotIds())) { |
| | | //若质押仓库为空,则跳过当前合同 |
| | | log.error("-----当前合同={}没有设置质押仓库,不执行提醒核算-----", pledgeContract.getContractName()); |
| | | log.error("-----当前合同={}没有设置质押仓库,不执行提醒核算-----", pledgeContract.getName()); |
| | | continue; |
| | | } |
| | | |
| | | String[] depotIds = pledgeContract.getDepotIds().split(","); |
| | | if(depotIds.length < 1){ |
| | | if (depotIds.length < 1) { |
| | | //若质押仓库为空,则跳过当前合同 |
| | | log.error("-----当前合同={}没有设置质押仓库,不执行提醒核算-----", pledgeContract.getContractName()); |
| | | log.error("-----当前合同={}没有设置质押仓库,不执行提醒核算-----", pledgeContract.getName()); |
| | | continue; |
| | | } |
| | | sumMoney = 0.0; |
| | | for (String depotId : depotIds) { |
| | | //查询仓库信息 |
| | | depot = depotService.getCacheDepot(pledgeContract.getCompanyId(), depotId); |
| | | if(null == depot){ |
| | | log.error("-----当前合同={}下仓库={}不存在,不统计此仓库-----", pledgeContract.getContractName(), depotId); |
| | | if (null == depot) { |
| | | log.error("-----当前合同={}下仓库={}不存在,不统计此仓库-----", pledgeContract.getName(), depotId); |
| | | continue; |
| | | } |
| | | if(null == depot.getStorageReal()){ |
| | | if (null == depot.getStorageReal()) { |
| | | depot.setStorageReal(0.0); |
| | | } |
| | | |
| | | foodPrice = foodPriceService.getDataByBankAndFood(pledgeContract.getPledgeBank(), depot.getFoodVariety()); |
| | | if(null == foodPrice || null == foodPrice.getPrice()){ |
| | | log.error("-----当前合同={}下仓库={}对应的品种={}未配置价格,不统计此仓库-----", pledgeContract.getContractName(),depot.getName(), depot.getFoodVariety()); |
| | | if (null == foodPrice || null == foodPrice.getPrice()) { |
| | | log.error("-----当前合同={}下仓库={}对应的品种={}未配置价格,不统计此仓库-----", pledgeContract.getName(), depot.getName(), depot.getFoodVariety()); |
| | | continue; |
| | | } |
| | | |
| | | sumMoney += depot.getStorageReal() * foodPrice.getPrice(); |
| | | log.info("-----当前合同={}下仓库={}:对应的实际储量={},对应粮食单价={}-----", pledgeContract.getName(), depot.getName(), depot.getStorageReal(), foodPrice.getPrice()); |
| | | } |
| | | |
| | | per = sumMoney/backMoney; |
| | | per = sumMoney / backMoney; |
| | | |
| | | if(per <= 1.2){ |
| | | //执行流程 |
| | | conf = workService.getConfByDeptId(pledgeContract.getPledgeDept(), WorkBizType.TYPE_50); |
| | | //流程不启用 |
| | | if (null == conf || Constant.YN_N.equals(conf.getValTag())) { |
| | | log.error("-----当前合同={}质押库区={}未配置还款提醒审批流程,无法生成工单提醒-----", pledgeContract.getContractName(),pledgeContract.getPledgeDept()); |
| | | continue; |
| | | } |
| | | |
| | | BaseResp resp = workService.startByBackMoney(pledgeContract, conf); |
| | | log.info("---------当前合同={}启动还款提醒工单流程------{}",pledgeContract.getContractName(), resp); |
| | | if (per > 1.1) { |
| | | log.error("-----当前合同={}下质押仓库={}库存未到待还款的110%,sumMoney={},backMoney={},不生成还款提醒工单-----", pledgeContract.getName(), pledgeContract.getDepotNames(), sumMoney, backMoney); |
| | | 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); |
| | | } |
| | | } |
| | | |