|
@@ -3,31 +3,32 @@ package org.dromara.fulfiller.dubbo;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
import org.apache.dubbo.config.annotation.DubboService;
|
|
|
import org.dromara.common.core.constant.CacheNames;
|
|
import org.dromara.common.core.constant.CacheNames;
|
|
|
import org.dromara.common.core.exception.user.UserException;
|
|
import org.dromara.common.core.exception.user.UserException;
|
|
|
|
|
+import org.dromara.common.core.utils.DateUtils;
|
|
|
import org.dromara.common.external.timor.TimorClient;
|
|
import org.dromara.common.external.timor.TimorClient;
|
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
import org.dromara.fulfiller.api.RemoteFulfillerService;
|
|
import org.dromara.fulfiller.api.RemoteFulfillerService;
|
|
|
import org.dromara.fulfiller.api.domain.vo.RemoteFulfillerVo;
|
|
import org.dromara.fulfiller.api.domain.vo.RemoteFulfillerVo;
|
|
|
import org.dromara.fulfiller.api.model.FulfillerLoginUser;
|
|
import org.dromara.fulfiller.api.model.FulfillerLoginUser;
|
|
|
import org.dromara.fulfiller.constants.FlfActionTypeConstant;
|
|
import org.dromara.fulfiller.constants.FlfActionTypeConstant;
|
|
|
-import org.dromara.fulfiller.domain.FlfBalanceLog;
|
|
|
|
|
-import org.dromara.fulfiller.domain.FlfFulfiller;
|
|
|
|
|
-import org.dromara.fulfiller.domain.FlfPointsLog;
|
|
|
|
|
|
|
+import org.dromara.fulfiller.domain.*;
|
|
|
|
|
+import org.dromara.fulfiller.domain.vo.FlfLevelConfigVo;
|
|
|
import org.dromara.fulfiller.enums.FlfBalanceBizTypeEnum;
|
|
import org.dromara.fulfiller.enums.FlfBalanceBizTypeEnum;
|
|
|
import org.dromara.fulfiller.enums.FlfFulfillerStatusEnum;
|
|
import org.dromara.fulfiller.enums.FlfFulfillerStatusEnum;
|
|
|
import org.dromara.fulfiller.enums.FlfPointsBizTypeEnum;
|
|
import org.dromara.fulfiller.enums.FlfPointsBizTypeEnum;
|
|
|
-import org.dromara.fulfiller.mapper.FlfBalanceLogMapper;
|
|
|
|
|
-import org.dromara.fulfiller.mapper.FlfFulfillerMapper;
|
|
|
|
|
-import org.dromara.fulfiller.mapper.FlfPointsLogMapper;
|
|
|
|
|
|
|
+import org.dromara.fulfiller.mapper.*;
|
|
|
|
|
+import org.dromara.fulfiller.service.IFlfLevelConfigService;
|
|
|
|
|
+import org.dromara.order.api.RemoteSubOrderLogService;
|
|
|
|
|
+import org.dromara.order.api.RemoteSubOrderService;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Collections;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 履约者服务实现
|
|
* 履约者服务实现
|
|
@@ -43,6 +44,15 @@ public class RemoteFulfillerServiceImpl implements RemoteFulfillerService {
|
|
|
private final FlfFulfillerMapper fulfillerMapper;
|
|
private final FlfFulfillerMapper fulfillerMapper;
|
|
|
private final FlfBalanceLogMapper balanceLogMapper;
|
|
private final FlfBalanceLogMapper balanceLogMapper;
|
|
|
private final FlfPointsLogMapper pointsLogMapper;
|
|
private final FlfPointsLogMapper pointsLogMapper;
|
|
|
|
|
+ private final FlfComplaintLogMapper complaintLogMapper;
|
|
|
|
|
+ private final FlfViolationLogMapper violationLogMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final IFlfLevelConfigService levelConfigService;
|
|
|
|
|
+
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private final RemoteSubOrderService remoteSubOrderService;
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private final RemoteSubOrderLogService remoteSubOrderLogService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public FulfillerLoginUser getFulfillerByPhone(String phone) throws UserException {
|
|
public FulfillerLoginUser getFulfillerByPhone(String phone) throws UserException {
|
|
@@ -161,6 +171,95 @@ public class RemoteFulfillerServiceImpl implements RemoteFulfillerService {
|
|
|
).getName();
|
|
).getName();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean taskLevelPoints() {
|
|
|
|
|
+
|
|
|
|
|
+ List<FlfFulfiller> fulfillers = fulfillerMapper.selectList();
|
|
|
|
|
+
|
|
|
|
|
+ Map<Integer, FlfLevelConfigVo> configMap = new HashMap<>();
|
|
|
|
|
+ levelConfigService.listAll().forEach(e -> configMap.put(e.getLvNo(), e));
|
|
|
|
|
+ for (FlfFulfiller fulfiller : fulfillers) {
|
|
|
|
|
+ FlfLevelConfigVo config = configMap.get(fulfiller.getLevel());
|
|
|
|
|
+
|
|
|
|
|
+ long count = remoteSubOrderLogService.countCompletedLastMonthByFulfiller(fulfiller.getId());
|
|
|
|
|
+ int onTimeCount = remoteSubOrderLogService.countOnTimeByFulfillerId(fulfiller.getId());
|
|
|
|
|
+ long complaintCount = complaintLogMapper.selectCount(
|
|
|
|
|
+ Wrappers.lambdaQuery(FlfComplaintLog.class)
|
|
|
|
|
+ .eq(FlfComplaintLog::getFulfiller, fulfiller.getId())
|
|
|
|
|
+ .ge(FlfComplaintLog::getCreateTime, DateUtils.getFirstDayOfLastMonth())
|
|
|
|
|
+ );
|
|
|
|
|
+ AtomicInteger violationCount = new AtomicInteger();
|
|
|
|
|
+ violationLogMapper.selectList(
|
|
|
|
|
+ Wrappers.lambdaQuery(FlfViolationLog.class)
|
|
|
|
|
+ .eq(FlfViolationLog::getFulfiller, fulfiller.getId())
|
|
|
|
|
+ .ge(FlfViolationLog::getViolationTime, DateUtils.getFirstDayOfLastMonth())
|
|
|
|
|
+ ).forEach(e -> violationCount.addAndGet(e.getCount()));
|
|
|
|
|
+
|
|
|
|
|
+ log.info("""
|
|
|
|
|
+ 骑手{}查询结果:
|
|
|
|
|
+ 总订单数: {}
|
|
|
|
|
+ 按时数: {}
|
|
|
|
|
+ 投诉数: {}
|
|
|
|
|
+ 违规数: {}
|
|
|
|
|
+ """, fulfiller.getName(), count, onTimeCount, complaintCount, violationCount.get());
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 先进行积分处理
|
|
|
|
|
+ */
|
|
|
|
|
+ // 上门准时率低于a%,自动扣罚积分x
|
|
|
|
|
+ if (onTimeCount * 10000 < config.getDegradeOntimeRate()) {
|
|
|
|
|
+ fulfiller.setPoints(fulfiller.getPoints() - config.getDegradeOntimeRateScore());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 完成订单为y,自动扣罚积分y2
|
|
|
|
|
+ if (count < config.getDegradeCompleteOrderQuality()) {
|
|
|
|
|
+ fulfiller.setPoints(fulfiller.getPoints() - config.getDegradeCompleteOrderQualityScore());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 投诉率达到a%,自动扣罚积分x
|
|
|
|
|
+ if (complaintCount * 10000 >= config.getDegradeComplaintCount()) {
|
|
|
|
|
+ fulfiller.setPoints(fulfiller.getPoints() - config.getDegradeComplaintCountScore());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 然后进行等级处理
|
|
|
|
|
+ */
|
|
|
|
|
+ if (fulfiller.getPoints() < config.getDegradePoints()) {
|
|
|
|
|
+ log.info("骑手{}积分不足,降级", fulfiller.getName());
|
|
|
|
|
+ fulfiller.setLevel(config.getLvNo() - 1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ config = configMap.get(config.getLvNo() + 1);
|
|
|
|
|
+ // 达到y5积分数量
|
|
|
|
|
+ if (fulfiller.getPoints() < config.getUpgradePoints()) {
|
|
|
|
|
+ log.info("骑手{}有{}积分,未达到{}积分,无法升级", fulfiller.getName(), fulfiller.getPoints(), config.getUpgradePoints());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 完成y1单量
|
|
|
|
|
+ if (config.getUpgradeCompleteOrderQuality() > count) {
|
|
|
|
|
+ log.info("骑手{}完成{}单,未达到{}单量,无法升级", fulfiller.getName(), count, config.getUpgradeCompleteOrderQuality());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 达到y2准时率
|
|
|
|
|
+ if (onTimeCount * 100L * 100 / count < config.getUpgradeOntimeRate()) {
|
|
|
|
|
+ log.info("骑手{}准时率为{},未达到{}准时率,无法升级", fulfiller.getName(), onTimeCount * 100L * 100 / count, config.getUpgradeOntimeRate());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 达到y3投诉率
|
|
|
|
|
+ if (complaintCount * 10000L / count > config.getUpgradeComplaintRate()) {
|
|
|
|
|
+ log.info("骑手{}投诉率为{},超过{},无法升级", fulfiller.getName(), complaintCount * 10000L / count, config.getUpgradeComplaintRate());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 低于y4违规次数
|
|
|
|
|
+ if (violationCount.get() >= config.getUpgradeViolationsCount()) {
|
|
|
|
|
+ log.info("骑手{}违规次数为{},超过{}次,无法升级", fulfiller.getName(), violationCount.get(), config.getUpgradeViolationsCount());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fulfiller.setLevel(config.getLvNo());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return fulfillerMapper.updateBatchById(fulfillers);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 手动转换 FlfFulfiller → FulfillerLoginUser(避免跨模块 MapStruct 转换器缺失)
|
|
* 手动转换 FlfFulfiller → FulfillerLoginUser(避免跨模块 MapStruct 转换器缺失)
|
|
|
*/
|
|
*/
|