Эх сурвалжийг харах

feat(app): 场地好评率计算逻辑优化

- 修改好评率计算方法,使用平均分 instead of 好评数比率
- 优化 addUser 方法,增加 endDate 参数
- 更新 AppCoureseServiceImpl、AppHomeServiceImpl、DetailServiceImpl 和 OrderServiceImpl 中的相关调用
- 修改 PlaceVO 和 SearchVO 中的好评率字段类型,从 long 改为 BigDecimal
SheepHy 3 долоо хоног өмнө
parent
commit
8672930ffd

+ 15 - 5
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/AppHomeServiceImpl.java

@@ -17,6 +17,8 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -194,10 +196,10 @@ public class AppHomeServiceImpl implements IAppHomeService {
                     placeVO.setKm(0.0);
                 }
                 long scoreNum = evaluateMapper.findByScoreNum(placeVO.getId());
-                long goodScoreNum = evaluateMapper.findByGoodScoreNum(placeVO.getId());
+                long scoreSum = evaluateMapper.findByAverageScore(placeVO.getId());//评论总评分
                 placeVO.setCategory(getCategoryName(placeVO.getCategoryId()));
                 placeVO.setTicketWhether(ticketWhether);
-                placeVO.setGoodRate(goodScoreNumRate(goodScoreNum, scoreNum));
+                placeVO.setGoodRate(calculateAverage(scoreSum, scoreNum));
                 placeVO.setComments(scoreNum);
             });
         }
@@ -366,9 +368,17 @@ public class AppHomeServiceImpl implements IAppHomeService {
         return page;
     }
 
-    public static long goodScoreNumRate(Long goodScoreNum, Long scoreNum) {
-        // 计算平均数
-        return scoreNum == 0 ? 0 : (long) (goodScoreNum * 100.00 / scoreNum);
+    public static BigDecimal calculateAverage(Long scoreSum, Long scoreNum) {
+        if (scoreNum == 0L) {
+            return  BigDecimal.valueOf(0).setScale(1 , RoundingMode.DOWN);
+        }
+
+        // 将分子和分母都转换为BigDecimal
+        BigDecimal sum = new BigDecimal(scoreSum);
+        BigDecimal num = new BigDecimal(scoreNum);
+
+        // 计算平均数,保留1位小数并四舍五入
+        return sum.divide(num, 1, RoundingMode.HALF_UP);
     }
 
     /** 

+ 19 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/DetailServiceImpl.java

@@ -37,6 +37,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -71,17 +72,34 @@ public class DetailServiceImpl implements IDetailService {
     @Resource
     private SysDictMapper sysDictMapper;
 
+    @Resource
+    private EvaluateMapper evaluateMapper;
+
     @Autowired
     private AppInsureMapper appInsureMapper;
     @Autowired
     InsurePriceMapper insurePriceMapper;
 
+    public static BigDecimal calculateAverage(Long scoreSum, Long scoreNum) {
+        if (scoreNum == 0L) {
+            return  BigDecimal.valueOf(0).setScale(1 , RoundingMode.DOWN);
+        }
+
+        // 将分子和分母都转换为BigDecimal
+        BigDecimal sum = new BigDecimal(scoreSum);
+        BigDecimal num = new BigDecimal(scoreNum);
+
+        // 计算平均数,保留1位小数并四舍五入
+        return sum.divide(num, 1, RoundingMode.HALF_UP);
+    }
 
     @Override
     public PlaceInfoVO getPlaceInfo(String id) {
         AppSite appSite = appSiteMapper.selectById(id);
         PlaceInfoVO placeInfo = appSiteMapper.getPlaceInfo(id);
-
+        long scoreNum = evaluateMapper.findByScoreNum(id);
+        long scoreSum = evaluateMapper.findByAverageScore(id);//评论总评分
+        placeInfo.setGoodRate(calculateAverage(scoreSum, scoreNum));
         List<DictModel> dictModels = sysDictMapper.queryDictItemsByCode(FACILITY_INFO);
         List<String> facilityInfo = new ArrayList<>();
         if(null != placeInfo.getFacility()){

+ 3 - 3
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/OrderServiceImpl.java

@@ -961,10 +961,10 @@ public class OrderServiceImpl implements IOrderService {
                 if(appSiteMapper.selectById(appCoursesMapper.selectById(appOrderProInfo.getProductId()).getAddressSiteId()).getType() == 0){
                     for (AppDevice appDevice : appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery().eq(AppDevice::getOrgCode, appOrder.getOrgCode()))){
                         if(null != appDevice){
-                            JsonObject addUserJson = JsonParser.parseString(addUser(new DateTime(appOrderProInfo.getExpireTime()),
+                            JsonObject addUserJson = JsonParser.parseString(addUser(new Date(),
                                     appDevice.getDeviceSerial(),
                                     appOrderProInfo.getUserName(),
-                                    appOrderProInfo.getId())).getAsJsonObject();
+                                    appOrderProInfo.getId(),new DateTime(appOrderProInfo.getExpireTime()))).getAsJsonObject();
                             JsonObject addFaceJson = JsonParser.parseString(addFace(appDevice.getDeviceSerial(), appOrderProInfo.getId(),
                                     familyMembersMapper.selectById(appOrderProInfo.getFamilyUserId()).getRealNameImg())).getAsJsonObject();
                             if (addUserJson.get("code").getAsInt() != 0 && addFaceJson.get("code").getAsInt() != 0){
@@ -999,7 +999,7 @@ public class OrderServiceImpl implements IOrderService {
                     String addUser = addUser(appSitePriceRulesMapper.selectById(appOrderProInfo.getProductId()).getDateOfSale(),
                             appDevice.getDeviceSerial(),
                             appOrderProInfo.getUserName(),
-                            appOrderProInfo.getId());
+                            appOrderProInfo.getId(),null);
                     String addFace = addFace(appDevice.getDeviceSerial(), appOrderProInfo.getId(),
                             familyMembersMapper.selectById(appOrderProInfo.getFamilyUserId()).getRealNameImg());
                     JsonObject addUserJson = JsonParser.parseString(addUser).getAsJsonObject();

+ 1 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/vo/PlaceVO.java

@@ -19,7 +19,7 @@ public class PlaceVO extends Page<PlaceVO> {
     @Schema(description = "场地名称")
     private String name;
     @Schema(description = "好评率")
-    private long goodRate;
+    private BigDecimal goodRate;
     @Schema(description = "评论数")
     private long comments;
     @Schema(description = "地址")

+ 1 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/vo/SearchVO.java

@@ -130,7 +130,7 @@ public class SearchVO{
         @Schema(description = "图片")
         private String cover;
         @Schema(description = "好评率")
-        private long goodRate;
+        private BigDecimal goodRate;
         @Schema(description = "评论数")
         private long comments;
         @Schema(description = "退款类型")

+ 7 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/hikiot/HikiotTool.java

@@ -197,12 +197,18 @@ public class HikiotTool {
      * @Description 新增/修改人员
      * @Date 9:35 2025/8/15
      **/
-    public static String addUser(Date inputDate,String deviceSerial,String name,String employeeNo){
+    public static String addUser(Date inputDate,String deviceSerial,String name,String employeeNo,Date endDate){
         LocalDateTime now = inputDate.toInstant()
                 .atZone(ZoneId.systemDefault())
                 .toLocalDateTime();
         LocalDateTime startOfDay = now.with(LocalTime.MIN); // 00:00
         LocalDateTime endOfDay = now.with(LocalTime.MAX);
+        if(null != endDate){
+            LocalDateTime outputDate = endDate.toInstant()
+                    .atZone(ZoneId.systemDefault())
+                    .toLocalDateTime();
+            endOfDay = outputDate.with(LocalTime.MAX);
+        }
         AddUserRequestDTO addUserRequestDTO = new AddUserRequestDTO();
         List<AddUserRequestDTO.DoorRightPlan> doorRightPlans = new ArrayList<>();
         AddUserRequestDTO.DoorRightPlan doorRightPlan = new AddUserRequestDTO.DoorRightPlan();

+ 2 - 2
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/service/impl/AppCoureseServiceImpl.java

@@ -462,10 +462,10 @@ public class AppCoureseServiceImpl extends ServiceImpl<AppCoursesMapper, AppCour
                 if(appSite.getType() == 0){
                     for (AppDevice appDevice : appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery().eq(AppDevice::getSiteId, appSite.getId()))){
                         if(null != appDevice){
-                            JsonObject addUserJson = JsonParser.parseString(addUser(new DateTime(verificationRecord.getCoursesEndTime()),
+                            JsonObject addUserJson = JsonParser.parseString(addUser(new DateTime(verificationRecord.getCoursesStartTime()),
                                     appDevice.getDeviceSerial(),
                                     verificationRecord.getUseUserName(),
-                                    "K" + verificationRecord.getId())).getAsJsonObject();
+                                    "K" + verificationRecord.getId(),new DateTime(verificationRecord.getCoursesEndTime()))).getAsJsonObject();
                             JsonObject addFaceJson = JsonParser.parseString(addFace(appDevice.getDeviceSerial(), "K" + verificationRecord.getId(),
                                     familyMembersMapper.selectById(verificationRecord.getUseUserId()).getRealNameImg())).getAsJsonObject();
                             if (addUserJson.get("code").getAsInt() != 0 && addFaceJson.get("code").getAsInt() != 0){