| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.system.model.TCrmClinic; |
| | | import com.ruoyi.system.model.TErpProcurement; |
| | | import com.ruoyi.system.service.TCrmClinicService; |
| | | import com.ruoyi.system.service.TErpProcurementService; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.utils.util.AIUtil; |
| | | import com.ruoyi.system.vo.TCrmClinicVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private TCrmClinicService crmClinicService; |
| | | @Autowired |
| | | private TErpProcurementService erpProcurementService; |
| | | @Autowired |
| | | private TCrmSupplierService crmSupplierService; |
| | | @Autowired |
| | | private TCrmSupplierVerifyService crmSupplierVerifyService; |
| | | @Autowired |
| | | private TSysOtherConfigService sysOtherConfigService; |
| | | |
| | | @Scheduled(fixedRate = 86460000) |
| | | // @Scheduled(cron = "10 0 0 * * ?") |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0 1 * * ?") |
| | | public void dayUpdateSupplierVerify() { |
| | | try { |
| | | // 每天1点生成供应商周期性的核查 |
| | | List<TCrmSupplier> crmSuppliers = crmSupplierService.list(); |
| | | if(!CollectionUtils.isEmpty(crmSuppliers)){ |
| | | // 查询核查周期配置 |
| | | TSysOtherConfig sysOtherConfig = sysOtherConfigService.getById(1); |
| | | List<String> supplierIds = crmSuppliers.stream().map(TCrmSupplier::getId).collect(Collectors.toList()); |
| | | // 查询审核列表 |
| | | List<TCrmSupplierVerify> crmSupplierVerifies = crmSupplierVerifyService.list(Wrappers.lambdaQuery(TCrmSupplierVerify.class) |
| | | .in(TCrmSupplierVerify::getSupplierId, supplierIds) |
| | | .orderByDesc(TCrmSupplierVerify::getGenerateTime)); |
| | | for (TCrmSupplier crmSupplier : crmSuppliers) { |
| | | List<TCrmSupplierVerify> supplierVerifies = crmSupplierVerifies.stream().filter(crmSupplierVerify -> crmSupplier.getId().equals(crmSupplierVerify.getSupplierId())).collect(Collectors.toList()); |
| | | Integer verifyUnit = sysOtherConfig.getVerifyUnit(); |
| | | Integer verifyValue = sysOtherConfig.getVerifyValue(); |
| | | if (!CollectionUtils.isEmpty(supplierVerifies)) { |
| | | // 根据最新的核查进行比较核查周期 |
| | | TCrmSupplierVerify tCrmSupplierVerify = supplierVerifies.get(0); |
| | | LocalDate generateTime = tCrmSupplierVerify.getGenerateTime(); |
| | | LocalDate nextVerifyDate = calculateNextVerifyDate(generateTime, verifyUnit, verifyValue); |
| | | if (nextVerifyDate != null && nextVerifyDate.isEqual(LocalDate.now())) { |
| | | createSupplierVerify(crmSupplier); |
| | | } |
| | | } else { |
| | | // 根据供应商添加时间进行比较核查周期 |
| | | LocalDate createTime = crmSupplier.getCreateTime().toLocalDate(); |
| | | LocalDate nextVerifyDate = calculateNextVerifyDate(createTime, verifyUnit, verifyValue); |
| | | if (nextVerifyDate != null && nextVerifyDate.isEqual(LocalDate.now())) { |
| | | createSupplierVerify(crmSupplier); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计算下一次供应商核查时间 |
| | | * @param baseDate |
| | | * @param verifyUnit |
| | | * @param verifyValue |
| | | * @return |
| | | */ |
| | | private LocalDate calculateNextVerifyDate(LocalDate baseDate, Integer verifyUnit, Integer verifyValue) { |
| | | switch (verifyUnit) { |
| | | case 1: |
| | | return baseDate.plusDays(verifyValue); |
| | | case 2: |
| | | return baseDate.plusMonths(verifyValue); |
| | | case 3: |
| | | return baseDate.plusYears(verifyValue); |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 供应商周期核查 |
| | | * @param crmSupplier |
| | | */ |
| | | private void createSupplierVerify(TCrmSupplier crmSupplier) { |
| | | TCrmSupplierVerify crmSupplierVerify = new TCrmSupplierVerify(); |
| | | crmSupplierVerify.setSupplierId(crmSupplier.getId()); |
| | | crmSupplierVerify.setGenerateTime(LocalDate.now()); |
| | | crmSupplierVerify.setStatus(1); |
| | | crmSupplierVerifyService.save(crmSupplierVerify); |
| | | } |
| | | |
| | | } |