| | |
| | | //package com.ruoyi.web.controller.task; |
| | | // |
| | | // |
| | | //import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | //import com.ruoyi.common.utils.SmsUtil; |
| | | //import com.ruoyi.system.mapper.TBillMapper; |
| | | //import com.ruoyi.system.model.TBill; |
| | | //import com.ruoyi.system.model.TContract; |
| | | //import com.ruoyi.system.model.TContractRentType; |
| | | //import com.ruoyi.system.service.TBillService; |
| | | //import com.ruoyi.system.service.TContractRentTypeService; |
| | | //import com.ruoyi.system.service.TContractService; |
| | | //import org.springframework.beans.factory.annotation.Autowired; |
| | | //import org.springframework.scheduling.annotation.Scheduled; |
| | | //import org.springframework.stereotype.Component; |
| | | // |
| | | //import javax.annotation.Resource; |
| | | //import java.math.BigDecimal; |
| | | //import java.time.LocalDate; |
| | | //import java.time.LocalDateTime; |
| | | //import java.time.LocalTime; |
| | | //import java.time.ZoneId; |
| | | //import java.time.temporal.ChronoUnit; |
| | | //import java.time.temporal.TemporalAdjusters; |
| | | //import java.util.ArrayList; |
| | | //import java.util.Date; |
| | | //import java.util.List; |
| | | //import java.util.Random; |
| | | //import java.util.stream.Collectors; |
| | | // |
| | | ///** |
| | | // * @author zhibing.pu |
| | | // * @date 2023/7/11 8:39 |
| | | // */ |
| | | //@Component |
| | | //public class TaskUtil { |
| | | // @Autowired |
| | | // private TContractService contractService; |
| | | // @Autowired |
| | | // private TBillMapper billMapper; |
| | | // // 用于更新违约金账单 |
| | | // // 每分钟执行一次的定时任务 |
| | | // |
| | | // @Scheduled(cron = "0 * * * * ?") |
| | | // public void dayOfProportionBill() { |
| | | // try { |
| | | // // 查询所有未缴费账单 |
| | | // List<TBill> list = billMapper.selectList(new LambdaQueryWrapper<TBill>().eq(TBill::getPayFeesStatus, 1) |
| | | // .le(TBill::getPayableFeesTime,LocalDate.now())); |
| | | // for (TBill tBill : list) { |
| | | // tBill.setPayFeesStatus("4"); |
| | | // TContract contract = contractService.getById(tBill.getContractId()); |
| | | // LocalDate payableFeesTime = tBill.getPayableFeesTime(); |
| | | // // 将LocalDate转化为LocalDateTime |
| | | // LocalDateTime payableFeesTime1 = LocalDateTime.of(payableFeesTime, LocalTime.of(0, 0, 0)); |
| | | // LocalDateTime now = LocalDateTime.now(); |
| | | // // 计算两个时间相差多少个小时 |
| | | // long hours = ChronoUnit.HOURS.between(payableFeesTime1, now); |
| | | // long l = hours / 24; |
| | | // if (l>=3){ |
| | | // // 违约金比例 |
| | | // BigDecimal proportion = contract.getProportion(); |
| | | // // 按每天 待缴费金额 * XX% 增加违约金费用 |
| | | // if (tBill.getOutstandingMoney().compareTo(new BigDecimal("0"))==0){ |
| | | // tBill.setPayFeesStatus("3"); |
| | | // billMapper.updateById(tBill); |
| | | // continue; |
| | | // } |
| | | // BigDecimal money = tBill.getOutstandingMoney().multiply(new BigDecimal(100).add(proportion)).divide(new BigDecimal(100),2, BigDecimal.ROUND_DOWN); |
| | | // tBill.setOverDays((int) l); |
| | | // tBill.setPayableFeesPenalty((tBill.getPayableFeesPenalty()!=null?tBill.getPayableFeesPenalty():BigDecimal.ZERO).add(money)); |
| | | // tBill.setOutstandingMoney(money); |
| | | // billMapper.updateById(tBill); |
| | | // |
| | | // } |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // |
| | | // |
| | | //} |
| | | package com.ruoyi.web.controller.task; |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.constant.Constants; |
| | | 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.*; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.utils.util.AIUtil; |
| | | import com.ruoyi.system.vo.TCrmClinicVO; |
| | | import com.ruoyi.web.controller.yuncang.api.trade.LogisticsSyncAck; |
| | | import com.ruoyi.web.controller.yuncang.api.trade.LogisticsSyncQuery; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author xiaochen |
| | | * @date 2023/7/11 8:39 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class TaskUtil { |
| | | |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | @Autowired |
| | | private AIUtil aiUtil; |
| | | @Autowired |
| | | private TCrmClinicService crmClinicService; |
| | | @Autowired |
| | | private TErpProcurementService erpProcurementService; |
| | | @Autowired |
| | | private TCrmSupplierService crmSupplierService; |
| | | @Autowired |
| | | private TCrmSupplierVerifyService crmSupplierVerifyService; |
| | | @Autowired |
| | | private TSysOtherConfigService sysOtherConfigService; |
| | | @Autowired |
| | | private TSysCloudConfigService sysCloudConfigService; |
| | | |
| | | // @Scheduled(fixedRate = 86460000) |
| | | // @Scheduled(cron = "10 0 0 * * ?") |
| | | public void dayOfProportionBill() { |
| | | try { |
| | | |
| | | // 查询跳转检测的用户 |
| | | Set<String> cacheSet = redisCache.getCacheSet(Constants.AI_USER_INSPECTION); |
| | | // 获取前一天时间 |
| | | LocalDate lastDay = LocalDate.now().minusDays(1); |
| | | for (String phone : cacheSet) { |
| | | R<JSONObject> result = aiUtil.reportQuery(phone, lastDay.toString(), lastDay.toString()); |
| | | JSONObject data = result.getData(); |
| | | System.err.println(data); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0 0 L * ?") |
| | | public void monthUpdateClinicPerformance() { |
| | | try { |
| | | // 判断哪些诊所本月没有业绩达标 |
| | | List<TCrmClinic> clinics = crmClinicService.list(); |
| | | String monthDate = new SimpleDateFormat("yyyy-MM").format(new Date()); |
| | | List<TErpProcurement> procurements = erpProcurementService.list(Wrappers.lambdaQuery(TErpProcurement.class) |
| | | .in(TErpProcurement::getStatus, Arrays.asList(3,4,5)) |
| | | .likeRight(TErpProcurement::getCreateTime, monthDate)); |
| | | for (TCrmClinic clinic : clinics) { |
| | | List<TErpProcurement> procurementList = procurements.stream().filter(procurement -> procurement.getClinicId().equals(clinic.getId())).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(procurementList)){ |
| | | BigDecimal monthPurchaseAmount = procurementList.stream().map(TErpProcurement::getPayMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // 未达标 |
| | | if(monthPurchaseAmount.compareTo(clinic.getLowProcurementMoney())<0){ |
| | | clinic.setPerformanceCount(clinic.getPerformanceCount()+1); |
| | | } |
| | | } |
| | | } |
| | | crmClinicService.updateBatchById(clinics); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0 0 * * ?") |
| | | public void dayUpdateClinicMessageCount() { |
| | | try { |
| | | // 判断哪些诊所本月没有业绩达标 |
| | | List<TCrmClinic> clinics = crmClinicService.list(); |
| | | for (TCrmClinic clinic : clinics) { |
| | | clinic.setSendMessageCount(0); |
| | | } |
| | | crmClinicService.updateBatchById(clinics); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // @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; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 每小时更新订单云物流状态 |
| | | */ |
| | | // @Scheduled(fixedRate = 86460000) |
| | | @Scheduled(cron = "0 0 * * * ?") |
| | | public void hourUpdateOrderCloudLogisticsStatus() { |
| | | try { |
| | | TSysCloudConfig sysCloudConfig = sysCloudConfigService.getOne(Wrappers.lambdaQuery(TSysCloudConfig.class) |
| | | .eq(TSysCloudConfig::getCloudWarehouse, 1) |
| | | .last("LIMIT 1")); |
| | | |
| | | JSONObject jsonObject = LogisticsSyncQuery.logisticsSyncQuery(sysCloudConfig.getSid(), sysCloudConfig.getAppKey(), |
| | | sysCloudConfig.getAppSecret(), sysCloudConfig.getUrl(), ""); |
| | | if(Objects.nonNull(jsonObject)){ |
| | | JSONArray trades = jsonObject.getJSONArray("trades"); |
| | | Map<String, String> map = new HashMap<>(); |
| | | List<String> tidList = new ArrayList<>(); |
| | | List<Map<String, Object>> logistics_list = new ArrayList<>(); |
| | | for (int i = 0; i < trades.size(); i++) { |
| | | JSONObject trade_order = JSONObject.parseObject(JSONObject.toJSONString(trades.get(i))); |
| | | String rec_id = trade_order.getString("rec_id"); // 主键,用于logistics_sync_ack回写状态 |
| | | String tid = trade_order.getString("tid"); // 原始单号 |
| | | String logistics_no = trade_order.getString("logistics_no"); // 物流单号 |
| | | String logistics_name = trade_order.getString("logistics_name"); // 物流名称 |
| | | map.put(tid, logistics_no); |
| | | tidList.add(tid); |
| | | Map<String, Object> logistics_1 = new HashMap<>(); |
| | | logistics_1.put("rec_id", rec_id); |
| | | logistics_1.put("status", 0); |
| | | logistics_1.put("message", "同步成功"); |
| | | logistics_list.add(logistics_1); |
| | | } |
| | | |
| | | List<TErpProcurement> procurements = erpProcurementService.list(Wrappers.lambdaQuery(TErpProcurement.class) |
| | | .in(TErpProcurement::getProcurementCode, tidList)); |
| | | if(!CollectionUtils.isEmpty(procurements)){ |
| | | for (TErpProcurement procurement : procurements) { |
| | | procurement.setLogisticsNo(map.get(procurement.getProcurementCode())); |
| | | procurement.setStatus(4); |
| | | } |
| | | erpProcurementService.updateBatchById(procurements); |
| | | } |
| | | // 物流同步回写 |
| | | JSONObject logisticsSyncAck = LogisticsSyncAck.logisticsSyncAck(sysCloudConfig.getSid(), sysCloudConfig.getAppKey(), |
| | | sysCloudConfig.getAppSecret(), sysCloudConfig.getUrl(), logistics_list); |
| | | log.info("物流同步成功"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 供应商周期核查 |
| | | * @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); |
| | | } |
| | | |
| | | } |