Преглед на файлове

调整司机行为对企业评分的修改方式

tangyishan преди 4 месеца
родител
ревизия
8c374ee3db

+ 7 - 0
sckw-modules-api/sckw-fleet-api/src/main/java/com/sckw/fleet/api/feign/DriverScoreFeignService.java

@@ -1,6 +1,7 @@
 package com.sckw.fleet.api.feign;
 
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.fleet.api.model.dto.DriverScoreQuery;
 import com.sckw.fleet.api.model.dto.UpdateDriverScoreDto;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.validation.annotation.Validated;
@@ -21,5 +22,11 @@ public interface DriverScoreFeignService {
      */
     @PostMapping("/kwfDriver/countDriver")
     public HttpResult countDriver(@RequestParam("entId") Long entId);
+
+    /**
+     * 统计指定物流企业所有司机总分
+     */
+    @PostMapping("/driverScore/countDriverScore")
+    public HttpResult countDriverScore(@Validated @RequestBody DriverScoreQuery query);
  }
 

+ 23 - 0
sckw-modules-api/sckw-fleet-api/src/main/java/com/sckw/fleet/api/model/dto/DriverScoreQuery.java

@@ -0,0 +1,23 @@
+package com.sckw.fleet.api.model.dto;
+
+import jakarta.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+/**
+ * 司机评分查询参数
+ *
+ * @author tangyishan
+ * @since 2026-01-27  09:12
+ */
+@Data
+@AllArgsConstructor
+public class DriverScoreQuery {
+    /** 供应商企业id */
+    @NotNull(message = "供应商企业id不能为空")
+    private Long providerEntId;
+
+    /** 物流企业id */
+    @NotNull(message = "物流企业id不能为空")
+    private Long logisticsEntId;
+}

+ 16 - 6
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/service/impl/KwcContractLogisticsScoreServiceImpl.java

@@ -5,6 +5,7 @@ import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageInfo;
@@ -34,6 +35,7 @@ import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.fleet.api.feign.DriverScoreFeignService;
+import com.sckw.fleet.api.model.dto.DriverScoreQuery;
 import com.sckw.fleet.api.model.dto.UpdateDriverScoreDto;
 import com.sckw.redis.constant.RedisConstant;
 import com.sckw.redis.utils.RedissonUtils;
@@ -394,12 +396,20 @@ public class KwcContractLogisticsScoreServiceImpl implements IKwcContractLogisti
         //1、更新企业评分
         BigDecimal score = logisticsScore.getScore();
         //查询物流企业下所有的司机
-        HttpResult result = driverScoreFeignService.countDriver(detailDto.getLogisticsEntId());
-        if(result.getCode() == HttpStatus.SUCCESS_CODE  && (Integer)result.getData()>0){
-           Integer driverCount =(Integer)result.getData();
-                //企业变动评分
-            BigDecimal entScoreChange = detailDto.getScoreChange().divide(new BigDecimal(driverCount),2, RoundingMode.HALF_UP);
-            BigDecimal resultScore = score.add(entScoreChange);
+        HttpResult driverCountRes = driverScoreFeignService.countDriver(detailDto.getLogisticsEntId());
+        if(driverCountRes.getCode() == HttpStatus.SUCCESS_CODE  && (Integer)driverCountRes.getData()>0){
+            //查询物流企业下的所有司机的总分
+            HttpResult scoreCountRes = driverScoreFeignService.countDriverScore(new DriverScoreQuery(detailDto.getProviderEntId(),detailDto.getLogisticsEntId()));
+            if(scoreCountRes.getCode() != HttpStatus.SUCCESS_CODE){
+                log.error("查询物流企业下的所有司机的总分失败,响应信息如下:{}", JSON.toJSONString(scoreCountRes));
+                throw new BusinessException("系统修改评分失败,请稍后再试");
+            }
+            BigDecimal driverScoreCount = (BigDecimal)scoreCountRes.getData();
+            Integer driverCount =(Integer)driverCountRes.getData();
+            //计算物流企业最新评分
+            BigDecimal resultScore = driverScoreCount.divide(new BigDecimal(driverCount),2, RoundingMode.HALF_UP);
+            //企业变动评分
+            BigDecimal entScoreChange = resultScore.subtract(score);
             logisticsScore.setScore(resultScore);
             logisticsScore.setUpdateBy(LoginUserHolder.getUserId());
             logisticsScore.setUpdateTime(new Date());

+ 10 - 4
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/controller/KwfDriverScoreController.java

@@ -3,6 +3,7 @@ package com.sckw.fleet.controller;
 import com.sckw.core.web.response.BaseResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.result.PageDataResult;
+import com.sckw.fleet.api.model.dto.DriverScoreQuery;
 import com.sckw.fleet.api.model.dto.UpdateDriverScoreDto;
 import com.sckw.fleet.model.request.DriverScorerDetailRequest;
 import com.sckw.fleet.model.vo.DriverScorerDetailVO;
@@ -11,10 +12,9 @@ import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import java.math.BigDecimal;
 
 /**
  * @Author: tangyishan
@@ -51,4 +51,10 @@ public class KwfDriverScoreController {
         return BaseResult.success(ScorerDetailPageList);
     }
 
+    @PostMapping("/countDriverScore")
+    public HttpResult countDriverScore(@Validated @RequestBody DriverScoreQuery query) {
+        BigDecimal driverScoreCount = kwfDriverScoreService.countDriverScore(query);
+        return HttpResult.ok(driverScoreCount);
+    }
+
 }

+ 4 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/dao/KwfDriverScoreMapper.java

@@ -1,10 +1,12 @@
 package com.sckw.fleet.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sckw.fleet.api.model.dto.DriverScoreQuery;
 import com.sckw.fleet.model.KwfDriverScore;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -32,6 +34,8 @@ public interface KwfDriverScoreMapper extends BaseMapper<KwfDriverScore>
      */
     public List<KwfDriverScore> selectKwfDriverScoreList(KwfDriverScore kwfDriverScore);
 
+    public BigDecimal selectKwfDriverScoreCount(DriverScoreQuery query);
+
     /**
      * 新增司机评分
      * 

+ 5 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/service/KwfDriverScoreService.java

@@ -15,6 +15,7 @@ import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.response.result.PageDataResult;
 import com.sckw.fleet.api.RemoteFleetService;
+import com.sckw.fleet.api.model.dto.DriverScoreQuery;
 import com.sckw.fleet.api.model.dto.RUpdateDriverScoreDto;
 import com.sckw.fleet.api.model.dto.UpdateDriverScoreDto;
 import com.sckw.fleet.api.model.vo.RDriverVo;
@@ -287,6 +288,10 @@ public class KwfDriverScoreService {
         return scoreDetail;
     }
 
+    public BigDecimal countDriverScore(DriverScoreQuery query) {
+        return kwfDriverScoreMapper.selectKwfDriverScoreCount(query);
+    }
+
 
     @Data
     @AllArgsConstructor

+ 8 - 0
sckw-modules/sckw-fleet/src/main/resources/mapper/KwfDriverScoreMapper.xml

@@ -28,6 +28,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="driverId != null "> and driver_id = #{driverId}</if>
         </where>
     </select>
+
+    <select id="selectKwfDriverScoreCount" resultType="java.math.BigDecimal">
+        select sum(score) from kwf_driver_score
+        <where>
+            <if test="providerEntId != null "> and provider_ent_id = #{providerEntId}</if>
+            <if test="logisticsEntId != null "> and logistics_ent_id = #{logisticsEntId}</if>
+        </where>
+    </select>
     
     <select id="selectKwfDriverScoreById" parameterType="Long" resultMap="KwfDriverScoreResult">
         <include refid="selectKwfDriverScoreVo"/>