Procházet zdrojové kódy

新增驾意险信息功能增强

1. 完善info日志记录
2. 删除类中没用的import
3. 完善驾意险查询功能,当查询报错的时候,给前端返回一个提示信息。 原先的代码逻辑,如果报错,返回一个空的集合,业务不知道是没查到数据还是应用报错
lipf před 5 měsíci
rodič
revize
50a8e33a28

+ 53 - 0
commons/src/main/java/com/jzg/commons/core/page/ResultInfo.java

@@ -0,0 +1,53 @@
+package com.jzg.commons.core.page;
+
+
+import java.io.Serializable;
+
+
+/**
+ * 服务之间交互的实体
+ *
+ * @author lipf
+ * @date 2026/4/2 9:57
+ */
+public class ResultInfo<T> extends HttpResult<T> implements Serializable {
+
+    private boolean success;
+
+    public boolean isSuccess() {
+        return success;
+    }
+
+    public void setSuccess(boolean success) {
+        this.success = success;
+    }
+
+    public ResultInfo<T> ResultInfo(){
+        ResultInfo<T> res =  new ResultInfo<>();
+        res.setSuccess(true);
+        return res;
+    }
+
+    public static <T> ResultInfo<T> resOk(String msg) {
+        ResultInfo<T> r = new ResultInfo<>();
+        r.setMsg(msg);
+        r.setSuccess(true);
+        return r;
+    }
+
+    public static <T> ResultInfo<T> resError(String msg) {
+        ResultInfo<T> r = new ResultInfo<>();
+        r.setMsg(msg);
+        r.setSuccess(false);
+        return r;
+    }
+
+    public static <T> ResultInfo<T> resOk(String msg, T data) {
+        ResultInfo<T> r = new ResultInfo<>();
+        r.setMsg(msg);
+        r.setData(data);
+        r.setSuccess(true);
+        return r;
+    }
+
+}

+ 13 - 3
platform/src/main/java/com/jzg/controller/JyxConfigController.java

@@ -6,6 +6,7 @@ import com.jzg.commons.core.page.HttpResult;
 import com.jzg.commons.entity.dto.JyxConfigAdd;
 import com.jzg.commons.entity.dto.JyxConfigEnd;
 import com.jzg.commons.entity.dto.JyxConfigParam;
+import com.jzg.commons.entity.vo.JyxConfigVo;
 import com.jzg.service.JyxConfigService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -15,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 
 @Validated
 @Tag(name="驾意险配置")
@@ -26,9 +29,10 @@ public class JyxConfigController extends BaseController {
     @Autowired
     private JyxConfigService jyxConfigService;
 
+
     @PostMapping("saveAll")
     @Operation(summary = "保存驾意险配置")
-    public HttpResult saveAll(@Valid @RequestBody JyxConfigAdd configAdd){
+    public HttpResult<String> saveAll(@Valid @RequestBody JyxConfigAdd configAdd){
         return jyxConfigService.saveAll(configAdd);
     }
 
@@ -40,10 +44,16 @@ public class JyxConfigController extends BaseController {
     }
 
 
+    /**
+     * 查询驾意险信息,如果查询异常,会给前端返回提示信息
+     *
+     * @author lipf
+     * @date 2026/4/2 10:07
+     */
     @PostMapping("jyxList")
     @Operation(summary = "查询驾意险配置列表")
-    public HttpResult jyxList(@RequestBody JyxConfigParam configParam){
-        return HttpResult.ok(jyxConfigService.jyxList(configParam));
+    public HttpResult<List<JyxConfigVo>> jyxList(@RequestBody JyxConfigParam configParam){
+        return jyxConfigService.jyxList(configParam);
     }
 
 

+ 17 - 3
platform/src/main/java/com/jzg/service/JyxConfigService.java

@@ -2,6 +2,7 @@ package com.jzg.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jzg.commons.core.page.HttpResult;
+import com.jzg.commons.core.page.ResultInfo;
 import com.jzg.commons.entity.dto.JyxConfigAdd;
 import com.jzg.commons.entity.dto.JyxConfigEnd;
 import com.jzg.commons.entity.dto.JyxConfigParam;
@@ -13,14 +14,27 @@ import java.util.List;
 
 public interface JyxConfigService extends IService<JyxConfig> {
 
-
-    HttpResult saveAll(JyxConfigAdd configAdd);
+    /**
+     * 添加驾意险配置
+     *
+     * @param configAdd 要添加的驾意险信息
+     * @author lifp  modify by lipf
+     * @date 2026/4/2 9:49
+     */
+    HttpResult<String> saveAll(JyxConfigAdd configAdd);
 
     HttpResult selectById(String id);
 
     HttpResult updateById(JyxConfigEnd configEnd);
 
-    List<JyxConfigVo> jyxList(JyxConfigParam configParam);
+    /**
+     * 查询驾意险信息
+     *
+     * @param configParam 驾意险查询参数
+     * @author lipf
+     * @date 2026/4/2 9:54
+     */
+    ResultInfo<List<JyxConfigVo>> jyxList(JyxConfigParam configParam);
 
     HttpResult deleteById(String id);
 

+ 28 - 7
platform/src/main/java/com/jzg/service/impl/JyxConfigServiceImpl.java

@@ -1,10 +1,12 @@
 package com.jzg.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jzg.commons.constants.Constants;
 import com.jzg.commons.core.page.HttpResult;
+import com.jzg.commons.core.page.ResultInfo;
 import com.jzg.commons.entity.dto.JyxConfigAdd;
 import com.jzg.commons.entity.dto.JyxConfigEnd;
 import com.jzg.commons.entity.dto.JyxConfigParam;
@@ -53,9 +55,17 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
 
 
 
+    /**
+     * 添加驾意险配置
+     *
+     * @param configAdd 要添加的驾意险信息
+     * @author lipf
+     * @date 2026/4/2 9:49
+     */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public HttpResult saveAll(JyxConfigAdd configAdd) {
+    public HttpResult<String> saveAll(JyxConfigAdd configAdd) {
+        log.info("添加驾意险信息:[{}]", JSONUtil.toJsonStr(configAdd));
         try {
             AssertionUtils.isFail(Optional.ofNullable(baseMapper.selectOne(new LambdaQueryWrapper<JyxConfig>().eq(JyxConfig::getProductCode, configAdd.getProductCode())
                     .eq(JyxConfig::getIsDelete, Constants.NOT_DELETED))).isPresent(), "产品编码重复");
@@ -83,6 +93,7 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
             }
             return HttpResult.ok("添加成功");
         }catch (Exception e){
+            log.error("添加驾意险异常。configAdd=[{}]", JSONUtil.toJsonStr(configAdd), e);
             return HttpResult.error("添加失败" + e.getMessage());
         }
     }
@@ -154,12 +165,21 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
         }
     }
 
+    /**
+     * 查询驾意险信息
+     *
+     * @param configParam 驾意险查询参数
+     * @author lipf
+     * @date 2026/4/2 9:54
+     */
     @Override
-    public List<JyxConfigVo> jyxList(JyxConfigParam configParam) {
+    public ResultInfo<List<JyxConfigVo>> jyxList(JyxConfigParam configParam) {
         try {
             List<JyxConfigVo> jyxConfigVos = Optional.ofNullable(jyxConfigMapper.jyxList(configParam)).orElse(Collections.emptyList());
             if (StringUtils.isNotEmpty(configParam.getSeats()) || StringUtils.isNotEmpty(configParam.getParams())) {
-                Set<String> ids = jyxConfigVos.stream().filter(v -> !ConstantsParent.PARENT_ID_ROOT.equals(v.getParentId())).map(JyxConfigVo::getParentId).collect(Collectors.toSet());
+                // modify by lipf  2026年4月2日10:10:00, 调换map和filter 来简化filter的写法
+                Set<String> ids = jyxConfigVos.stream().map(JyxConfigVo::getParentId)
+                        .filter(parentId -> !ConstantsParent.PARENT_ID_ROOT.equals(parentId)).collect(Collectors.toSet());
                 if (!CollectionUtils.isEmpty(ids)){
                     List<JyxConfigVo> parentConfigs = jyxConfigMapper.selectParentIds(new ArrayList<>(ids));
                     jyxConfigVos.addAll(parentConfigs);
@@ -169,18 +189,19 @@ public class JyxConfigServiceImpl extends ServiceImpl<JyxConfigMapper, JyxConfig
                 ));
             }
             if (jyxConfigVos.isEmpty()) {
-                return Collections.emptyList();
+                log.info("根据查询条件[{}]查询出的驾意险信息为空", JSONUtil.toJsonStr(configParam));
+                return ResultInfo.resOk("查询出的驾意险数据为空", Collections.emptyList());
             }
             Map<String, List<JyxConfigVo>> childrenMap = jyxConfigVos.stream()
                     .filter(vo -> !ConstantsParent.PARENT_ID_ROOT.equals(vo.getParentId()))
                     .collect(Collectors.groupingBy(vo -> String.valueOf(vo.getParentId()), Collectors.mapping(Function.identity(), Collectors.toList())));
             List<JyxConfigVo> configVos = jyxConfigVos.stream().filter(parentConfig -> ConstantsParent.PARENT_ID_ROOT.equals(parentConfig.getParentId())).collect(Collectors.toList());
             configVos.forEach(parentConfig -> parentConfig.setChildren(childrenMap.getOrDefault(String.valueOf(parentConfig.getId()), Collections.emptyList())));
-            return configVos;
+            return ResultInfo.resOk(null, configVos);
         } catch (Exception e) {
             // 记录日志或进行其他异常处理
-            log.error("执行jyxList方法异常",e);
-            return Collections.emptyList();
+            log.error("查询驾意险信息异常。 configParam=[{}]",JSONUtil.toJsonStr(configParam), e);
+            return ResultInfo.resError("查询驾意险异常,请联系管理员");
         }
     }