Jelajahi Sumber

司机评分变动修改企业评分

tangyishan 4 minggu lalu
induk
melakukan
14cb9cb535

+ 11 - 3
sckw-modules-api/sckw-fleet-api/src/main/java/com/sckw/fleet/api/feign/DriverScoreFeignService.java

@@ -6,12 +6,20 @@ import org.springframework.cloud.openfeign.FeignClient;
 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.RequestParam;
 
-@FeignClient(name = "sckw-ng-fleet",path = "/driverScore")
+@FeignClient(name = "sckw-ng-fleet")
 public interface DriverScoreFeignService {
     /**
      * 更新司机评分
      */
-    @PostMapping("/update")
+    @PostMapping("/driverScore/update")
     public HttpResult update(@Validated @RequestBody UpdateDriverScoreDto updateDriverScoreDto);
-}
+
+    /**
+     * 统计司机数量
+     */
+    @PostMapping("/kwfDriver/countDriver")
+    public HttpResult countDriver(@RequestParam Long entId);
+ }
+

+ 28 - 18
sckw-modules/sckw-contract/src/main/java/com/sckw/contract/service/impl/KwcContractLogisticsScoreServiceImpl.java

@@ -1,6 +1,7 @@
 package com.sckw.contract.service.impl;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -397,24 +398,33 @@ public class KwcContractLogisticsScoreServiceImpl implements IKwcContractLogisti
         KwcContractLogisticsScore logisticsScore = kwcContractLogisticsScoreMapper.selectLogisticsScoreByEntId(detailDto.getProviderEntId(),detailDto.getLogisticsEntId());
         //1、更新企业评分
         BigDecimal score = logisticsScore.getScore();
-        BigDecimal resultScore = score.add(detailDto.getScoreChange());
-        logisticsScore.setScore(resultScore);
-        logisticsScore.setUpdateBy(LoginUserHolder.getUserId());
-        logisticsScore.setUpdateTime(new Date());
-        kwcContractLogisticsScoreMapper.updateKwcContractLogisticsScore(logisticsScore);
-        //2.插入评分明细记录
-        LogisticsScoreDetailAddDto detailAddDto = new LogisticsScoreDetailAddDto();
-        detailAddDto.setScoreId(logisticsScore.getId());
-        detailAddDto.setInfluenceBy(detailDto.getInfluenceBy());
-        detailAddDto.setAction(detailDto.getAction());
-        detailAddDto.setScoreChange(detailDto.getScoreChange());
-        detailAddDto.setScore(resultScore);
-        //2.设置评分状态为通过
-        detailAddDto.setStatus(NumberConstant.ONE);
-        //3.构建评分明细记录
-        KwcContractLogisticsScoreDetail logisticsScoreDetail = buildLogisticsScoreDetail(detailAddDto);
-        //4.插入数据
-        return SqlHelper.retBool(kwcContractLogisticsScoreDetailMapper.insertKwcContractLogisticsScoreDetail(logisticsScoreDetail));
+        //查询物流企业下所有的司机
+        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);
+            logisticsScore.setScore(resultScore);
+            logisticsScore.setUpdateBy(LoginUserHolder.getUserId());
+            logisticsScore.setUpdateTime(new Date());
+            kwcContractLogisticsScoreMapper.updateKwcContractLogisticsScore(logisticsScore);
+            //2.插入评分明细记录
+            LogisticsScoreDetailAddDto detailAddDto = new LogisticsScoreDetailAddDto();
+            detailAddDto.setScoreId(logisticsScore.getId());
+            detailAddDto.setInfluenceBy(detailDto.getInfluenceBy());
+            detailAddDto.setAction(detailDto.getAction());
+            detailAddDto.setScoreChange(entScoreChange);
+            detailAddDto.setScore(resultScore);
+            //2.设置评分状态为通过
+            detailAddDto.setStatus(NumberConstant.ONE);
+            //3.构建评分明细记录
+            KwcContractLogisticsScoreDetail logisticsScoreDetail = buildLogisticsScoreDetail(detailAddDto);
+            //4.插入数据
+            return SqlHelper.retBool(kwcContractLogisticsScoreDetailMapper.insertKwcContractLogisticsScoreDetail(logisticsScoreDetail));
+        }else{
+            throw new BusinessException("查询物流企业司机数量失败");
+        }
     }
 
 

+ 5 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/controller/KwfDriverController.java

@@ -361,5 +361,10 @@ public class KwfDriverController {
         return BaseResult.success();
     }
 
+    @PostMapping("/countDriver")
+    public HttpResult countDriver(@RequestParam Long entId) {
+        Integer driverCount = driverService.countDriversByEntId(entId);
+        return HttpResult.ok(driverCount);
+    }
 
 }

+ 7 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/dao/KwfDriverMapper.java

@@ -59,6 +59,13 @@ public interface KwfDriverMapper extends BaseMapper<KwfDriver> {
 
     List<KwfDriver> findListByEntId(Long entId);
 
+    /**
+     * 统计   当前企业的司机数量
+     * @param entId
+     * @return
+     */
+    Integer countDriversByEntId(Long entId);
+
     /**
      * 查询
      * @param params

+ 13 - 0
sckw-modules/sckw-fleet/src/main/java/com/sckw/fleet/service/KwfDriverService.java

@@ -103,6 +103,9 @@ public class KwfDriverService {
     @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 8000)
     private TransportRemoteService transportRemoteService;
 
+    @Autowired
+    private KwfDriverMapper driverMapper;
+
     /**
      * @param key 逐渐id
      * @desc 根据主键查询
@@ -1477,4 +1480,14 @@ public class KwfDriverService {
     }
 
 
+    /**
+     * @param
+     * @desc 查询
+     * @author zk
+     * @date 2023/7/6
+     **/
+    public Integer countDriversByEntId(Long entId) {
+        return driverMapper.countDriversByEntId(entId);
+    }
+
 }

+ 9 - 1
sckw-modules/sckw-fleet/src/main/resources/mapper/KwfDriverMapper.xml

@@ -279,7 +279,7 @@
         ORDER BY dr.create_time desc
     </select>
 
-    <select id="findListByEntId" resultType="com.sckw.fleet.model.KwfDriver" parameterType="java.util.Map" >
+    <select id="findListByEntId" resultType="com.sckw.fleet.model.KwfDriver" parameterType="java.lang.Long" >
         SELECT
         dr.id, name, phone, idcard, total_complete totalComplete,
         total_take totalTake, total_weight totalWeight, dre.ent_id entId
@@ -289,6 +289,14 @@
         and dre.ent_id = #{entId, jdbcType=VARCHAR}
     </select>
 
+    <select id="countDriversByEntId" resultType="java.lang.Integer" parameterType="java.lang.Long" >
+        SELECT count(1)
+        from kwf_driver dr
+                 inner join kwf_driver_ent dre on dr.id = dre.driver_id
+        where dr.del_flag = 0 and dre.del_flag = 0
+          and dre.ent_id = #{entId}
+    </select>
+
     <select id="findDriver" resultType="com.sckw.fleet.model.KwfDriver" parameterType="java.util.Map" >
         SELECT
             id, ent_id entId, name, phone, salt, password, idcard, total_complete totalComplete,