Browse Source

保险列表

zhangxin 2 days ago
parent
commit
85d3608aab
14 changed files with 273 additions and 59 deletions
  1. 2 1
      national-motion-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java
  2. 2 0
      national-motion-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java
  3. 155 0
      national-motion-base-core/src/main/java/org/jeecg/common/util/DictAnnotationUtil.java
  4. 24 0
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/GameServiceImpl.java
  5. 5 0
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/vo/game/FindByGameIdPriceVo.java
  6. 12 30
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/controller/AppInsureController.java
  7. 31 21
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/entity/AppInsure.java
  8. 7 4
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/AppInsureMapper.java
  9. 2 1
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppGameMapper.xml
  10. 13 0
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/mapper/SysDictMapper.java
  11. 2 0
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/service/ISysDictService.java
  12. 5 1
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java
  13. 5 0
      national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDictServiceImpl.java
  14. 8 1
      national-motion-module-system/national-motion-system-start/src/main/java/org/jeecg/JeecgSystemApplication.java

+ 2 - 1
national-motion-base-core/src/main/java/org/jeecg/common/api/CommonAPI.java

@@ -142,6 +142,7 @@ public interface CommonAPI {
      * @return
      */
     List<DictModel> translateDictFromTableByKeys(String table, String text, String code, String keys, String dataSource);
-    //update-end---author:chenrui ---date:20231221  for:[issues/#5643]解决分布式下表字典跨库无法查询问题------------
+
+    String selectDictText(String dictCode, String itemValue);
 
 }

+ 2 - 0
national-motion-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java

@@ -210,6 +210,8 @@ public class DictAspect {
                 }
 
                 ((IPage) ((Result) result).getResult()).setRecords(items);
+            }else {
+
             }
 
         }

+ 155 - 0
national-motion-base-core/src/main/java/org/jeecg/common/util/DictAnnotationUtil.java

@@ -0,0 +1,155 @@
+package org.jeecg.common.util;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.jeecg.common.api.CommonAPI;
+import org.jeecg.common.aspect.annotation.Dict;
+import org.springframework.cache.Cache;
+import org.springframework.cache.CacheManager;
+import org.springframework.util.ConcurrentReferenceHashMap;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+@Log4j2
+public class DictAnnotationUtil {
+    // 缓存字典项(Key: dictCode, Value: Map<itemValue, itemText>)
+
+
+
+
+    private static final ConcurrentMap<String, Map<String, String>> DICT_CACHE =
+            new ConcurrentReferenceHashMap<>(512);
+
+    // Spring CacheManager(用于二级缓存,如Redis)
+    private static CacheManager cacheManager;
+
+
+    private static CommonAPI commonAPI;
+
+    /**
+     * 注入CacheManager(需在Spring容器初始化后调用)
+     */
+    public static void setCacheManager(CacheManager manager) {
+        cacheManager = manager;
+    }
+    public static void setCommonAPI(CommonAPI common) {
+        commonAPI = common;
+    }
+
+    /**
+     * 批量翻译集合中的字典字段
+     */
+    public static void translateDictList(Collection<?> list) {
+        if (list == null || list.isEmpty()) {
+            return;
+        }
+        System.out.println(JSONObject.toJSONString(list));
+        try {
+            list.forEach(DictAnnotationUtil::translateDict);
+        } catch (Exception e) {
+            // 生产环境打印警告日志,避免中断主流程
+            log.warn("字典翻译异常: {}", e.getMessage());
+        }
+    }
+
+    /**
+     * 翻译单个对象的字典字段
+     */
+    private static void translateDict(Object obj) {
+        if (obj == null) return;
+
+        System.out.println(JSONObject.toJSONString(obj));
+        Class<?> clazz = obj.getClass();
+        // 缓存类字段信息,避免重复反射
+        Field[] fields = getCachedFields(clazz);
+
+        for (Field field : fields) {
+            Dict dictAnnotation = field.getAnnotation(Dict.class);
+            if (dictAnnotation == null) continue;
+
+            try {
+                String dictCode = dictAnnotation.dicCode();
+                Object fieldValue = FieldUtils.readField(field, obj, true);
+                if (fieldValue == null) continue;
+
+                // 获取字典文本
+                String dictText = getDictText(dictCode, String.valueOf(fieldValue));
+                if (dictText == null) continue;
+
+                // 写入目标字段
+                String targetField = field.getName() + "_dictText";
+                FieldUtils.writeField(obj, targetField, dictText, true);
+            } catch (Exception e) {
+                log.warn("字段翻译失败: {}.{}", clazz.getSimpleName(), field.getName());
+            }
+        }
+    }
+
+    /**
+     * 获取字典文本(多级缓存策略)
+     */
+    private static String getDictText(String dictCode, String itemValue) {
+        // 1. 优先从本地缓存查询
+        Map<String, String> dictMap = DICT_CACHE.get(dictCode);
+        if (dictMap != null && dictMap.containsKey(itemValue)) {
+            return dictMap.get(itemValue);
+        }
+
+        // 2. 从Redis等分布式缓存查询
+        if (cacheManager != null) {
+            Cache cache = cacheManager.getCache("dictCache");
+            if (cache != null) {
+                String cacheKey = dictCode + ":" + itemValue;
+                String cachedText = cache.get(cacheKey, String.class);
+                if (cachedText != null) {
+                    return cachedText;
+                }
+            }
+        }
+
+        // 3. 从数据库查询并更新缓存
+        String dictText = queryFromDatabase(dictCode, itemValue);
+        if (dictText != null) {
+            updateCache(dictCode, itemValue, dictText);
+        }
+        return dictText;
+    }
+
+    /**
+     * 从数据库查询字典项
+     */
+    private static String queryFromDatabase(String dictCode, String itemValue) {
+        // 伪代码:实际需替换为MyBatis/JDBC查询
+
+        return commonAPI.selectDictText(dictCode, itemValue);
+    }
+
+    /**
+     * 更新多级缓存
+     */
+    private static void updateCache(String dictCode, String itemValue, String itemText) {
+        // 更新本地缓存
+        DICT_CACHE.computeIfAbsent(dictCode, k -> new HashMap<>())
+                .put(itemValue, itemText);
+
+        // 更新分布式缓存
+        if (cacheManager != null) {
+            Cache cache = cacheManager.getCache("dictCache");
+            if (cache != null) {
+                cache.put(dictCode + ":" + itemValue, itemText);
+            }
+        }
+    }
+
+    /**
+     * 缓存类字段信息(减少反射开销)
+     */
+    private static final Map<Class<?>, Field[]> FIELD_CACHE = new ConcurrentReferenceHashMap<>();
+    private static Field[] getCachedFields(Class<?> clazz) {
+        return FIELD_CACHE.computeIfAbsent(clazz, FieldUtils::getAllFields);
+    }
+}

+ 24 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/GameServiceImpl.java

@@ -1,14 +1,18 @@
 package org.jeecg.modules.app.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DictAnnotationUtil;
 import org.jeecg.modules.app.service.IGameService;
 import org.jeecg.modules.app.vo.game.*;
+import org.jeecg.modules.system.app.entity.AppInsure;
 import org.jeecg.modules.system.app.mapper.AppGameMapper;
 import org.jeecg.modules.system.app.mapper.AppGamePriceRulesMapper;
+import org.jeecg.modules.system.app.mapper.AppInsureMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -31,6 +35,9 @@ public class GameServiceImpl  implements IGameService {
     @Autowired
     private AppGamePriceRulesMapper appGamePriceRulesMapper;
 
+    @Autowired
+    private AppInsureMapper appInsureMapper;
+
 
     @Override
     public Result<IPage<FindPagResponse>> findConcerts(FindPageGameVO findPageGame) {
@@ -86,6 +93,23 @@ public class GameServiceImpl  implements IGameService {
         if (findByGameIdPriceVo==null){
             return Result.error("该赛事未查询到比赛");
         }
+        if (StringUtils.isNotEmpty(findByGameIdPriceVo.getInsureIds())){
+            List<String> aptitudesList = new ArrayList<>();
+            if (findByGameIdPriceVo.getInsureIds().indexOf(",")>0){
+                aptitudesList =  Arrays.asList(findByGameIdPriceVo.getInsureIds().split(","));
+            }else {
+                aptitudesList.add(findByGameIdPriceVo.getInsureIds());
+            }
+            LambdaQueryWrapper<AppInsure> wrapper = new LambdaQueryWrapper<>();
+            wrapper.in(AppInsure::getId, aptitudesList)
+                    .eq(AppInsure::getStatus,0)
+                    .eq(AppInsure::getDelFlag,0);  // 方法引用 + 集合
+            List<AppInsure> appInsureList = appInsureMapper.selectList(wrapper);
+            DictAnnotationUtil.translateDictList(appInsureList);
+            findByGameIdPriceVo.setInsureIdList(appInsureList);
+        }
+
+
         if (StringUtils.isNotEmpty(findByGameIdPriceVo.getAptitudes())){
             List<String> aptitudesList = new ArrayList<>();
             if (findByGameIdPriceVo.getAptitudes().indexOf(",")>0){

+ 5 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/vo/game/FindByGameIdPriceVo.java

@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+import org.jeecg.modules.system.app.entity.AppInsure;
 
 import java.util.List;
 
@@ -16,6 +17,10 @@ public class FindByGameIdPriceVo {
     private String id;
     @Schema(description = "资质")
     private String aptitudes;
+    @Schema(description = "保险")
+    private String  insureIds;
+    @Schema(description = "保险列表")
+    private List<AppInsure>  insureIdList;
     @Schema(description = "资质集合")
     private List<String> aptitudesList;
     @Schema(description = "比赛项目")

+ 12 - 30
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/controller/AppInsureController.java

@@ -1,43 +1,25 @@
 package org.jeecg.modules.system.app.controller;
 
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.system.query.QueryRuleEnum;
-import org.jeecg.common.util.oConvertUtils;
-import org.jeecg.modules.system.app.entity.AppInsure;
-import org.jeecg.modules.system.app.service.IAppInsureService;
-
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
-
-import org.jeecgframework.poi.excel.ExcelImportUtil;
-import org.jeecgframework.poi.excel.def.NormalExcelConstants;
-import org.jeecgframework.poi.excel.entity.ExportParams;
-import org.jeecgframework.poi.excel.entity.ImportParams;
-import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.modules.system.app.entity.AppInsure;
+import org.jeecg.modules.system.app.service.IAppInsureService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
-import com.alibaba.fastjson.JSON;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.Operation;
-import org.jeecg.common.aspect.annotation.AutoLog;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Arrays;
  /**
  * @Description: 保险表
  * @Author: jeecg-boot

+ 31 - 21
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/entity/AppInsure.java

@@ -1,23 +1,18 @@
 package org.jeecg.modules.system.app.entity;
 
-import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
-import java.util.Date;
-import java.math.BigDecimal;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import org.jeecg.common.constant.ProvinceCityArea;
-import org.jeecg.common.util.SpringContextUtils;
-import lombok.Data;
+import com.baomidou.mybatisplus.annotation.*;
 import com.fasterxml.jackson.annotation.JsonFormat;
-import org.springframework.format.annotation.DateTimeFormat;
-import org.jeecgframework.poi.excel.annotation.Excel;
-import org.jeecg.common.aspect.annotation.Dict;
 import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+import org.jeecg.common.aspect.annotation.Dict;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * @Description: 保险表
@@ -45,18 +40,33 @@ public class AppInsure implements Serializable {
 	@Excel(name = "租户id", width = 15)
     @Schema(description = "租户id")
     private String tenantId;
+
+    @Schema(description = "价格")
+    private BigDecimal price;
+    @Dict(dicCode = "insurance_name")
+    @Schema(description = "保险公司")
+    private Integer insuranceName;
+    @TableField(exist = false)
+    @Schema(description = "保险公司名称")
+    private String insuranceName_dictText;
+    @Dict(dicCode = "insurance_type")
+    @Schema(description = "保险类型,暂时为0 意外险")
+    private Integer insuranceType;
+    @TableField(exist = false)
+    @Schema(description = "保险类型名称,暂时为0 意外险")
+    private String insuranceType_dictText;
+    @Schema(description = "保障期限使用,进行分割")
+    private String guaranteeTerm;
+    @Schema(description = "保险责任与保额使用json存储key为保险责任,value为保额")
+    private String insuranceObvious;
 	/**险种*/
 	@Excel(name = "险种", width = 15)
     @Schema(description = "险种")
     private String name;
 	/**略图*/
-	@Excel(name = "略图", width = 15)
-    @Schema(description = "略图")
-    private String pic;
-	/**乐观锁*/
-	@Excel(name = "乐观锁", width = 15)
-    @Schema(description = "乐观锁")
-    private Integer revision;
+	@Excel(name = "封面", width = 15)
+    @Schema(description = "封面")
+    private String coverImg;
 	/**创建人;创建人*/
     @Schema(description = "创建人;创建人")
     private String createBy;

+ 7 - 4
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/AppInsureMapper.java

@@ -1,10 +1,10 @@
 package org.jeecg.modules.system.app.mapper;
 
-import java.util.List;
-
-import org.apache.ibatis.annotations.Param;
-import org.jeecg.modules.system.app.entity.AppInsure;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Select;
+import org.jeecg.modules.system.app.entity.AppInsure;
+
+import java.util.List;
 
 /**
  * @Description: 保险表
@@ -14,4 +14,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface AppInsureMapper extends BaseMapper<AppInsure> {
 
+    @Select("select * from nm_insure where del_flag = 0 and status  = 0")
+    List<AppInsure> findByList();
+
 }

+ 2 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppGameMapper.xml

@@ -86,6 +86,7 @@
     <resultMap id="findByGameIdPriceVoMap" type="org.jeecg.modules.app.vo.game.FindByGameIdPriceVo">
         <id property="id" column="id"/>
         <result property="aptitudes" column="aptitudes"/>
+        <result property="insureIds" column="insure_ids"/>
         <!-- 关联查询 - 比赛项目安排 -->
         <collection property="gamePriceRulesTypeVOList" ofType="org.jeecg.modules.app.vo.game.GamePriceRulesTypeVO" javaType="java.util.List">
             <id property="type" column="type"/>
@@ -255,7 +256,7 @@
     </select>
 
     <select id="findByGameId" resultMap="findByGameIdPriceVoMap">
-        select a.id,a.aptitudes,b.type,
+        select a.id,a.aptitudes,b.type,a.insure_ids,
         CASE
         WHEN b.type = 0 THEN '个人赛项目'
         WHEN b.type = 1 THEN '团队赛项目'

+ 13 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/mapper/SysDictMapper.java

@@ -214,4 +214,17 @@ public interface SysDictMapper extends BaseMapper<SysDict> {
 	 * @return
 	 */
     int removeLogicDeleted(@Param("ids")List<String> ids);
+
+	/**
+	 * 根据字典编码和值查询文本
+	 * @param dictCode 字典编码(如 sys_gender)
+	 * @param itemValue 字典值(如 1)
+	 * @return 字典文本(如 男)
+	 */
+
+	@Select("SELECT item_text FROM sys_dict_item WHERE " +
+			"dict_id = (SELECT id FROM sys_dict WHERE dict_code = #{dictCode}) " +
+			"AND item_value = #{itemValue}")
+	String selectDictText(@Param("dictCode") String dictCode,
+						  @Param("itemValue") String itemValue);
 }

+ 2 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/service/ISysDictService.java

@@ -300,4 +300,6 @@ public interface ISysDictService extends IService<SysDict> {
 	 * @param ids
 	 */
 	boolean removeLogicDeleted(List<String> ids);
+
+	String selectDictText(String dictCode, String itemValue);
 }

+ 5 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java

@@ -1566,7 +1566,11 @@ public class SysBaseApiImpl implements ISysBaseAPI {
 	public List<DictModel> translateDictFromTableByKeys(String table, String text, String code, String keys, String dataSource) {
 		return sysDictService.queryTableDictTextByKeys(table, text, code, Arrays.asList(keys.split(",")), dataSource);
 	}
-	//update-end---author:chenrui ---date:20231221  for:[issues/#5643]解决分布式下表字典跨库无法查询问题------------
+
+	@Override
+	public String selectDictText(String dictCode, String itemValue) {
+		return sysDictService.selectDictText(dictCode,itemValue);
+	}
 
 	//-------------------------------------流程节点发送模板消息-----------------------------------------------
 	@Autowired

+ 5 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDictServiceImpl.java

@@ -864,6 +864,11 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
 		return line > 0;
 	}
 
+	@Override
+	public String selectDictText(String dictCode, String itemValue) {
+		return sysDictMapper.selectDictText(dictCode,itemValue);
+	}
+
 	/**
 	 * 添加字典
 	 * @param dictName

+ 8 - 1
national-motion-module-system/national-motion-system-start/src/main/java/org/jeecg/JeecgSystemApplication.java

@@ -1,11 +1,14 @@
 package org.jeecg;
 
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.CommonAPI;
+import org.jeecg.common.util.DictAnnotationUtil;
 import org.jeecg.common.util.oConvertUtils;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.cache.CacheManager;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.core.env.Environment;
 
@@ -32,8 +35,12 @@ public class JeecgSystemApplication extends SpringBootServletInitializer {
         defaultProperties.put("management.health.elasticsearch.enabled", false);
         app.setDefaultProperties(defaultProperties);
         log.info("[JEECG] Elasticsearch Health Check Enabled: false" );
-        
+
         ConfigurableApplicationContext application = app.run(args);;
+        DictAnnotationUtil.setCommonAPI(
+                application.getBean(CommonAPI.class)
+        );
+        DictAnnotationUtil.setCacheManager(application.getBean(CacheManager.class));
         Environment env = application.getEnvironment();
         String ip = InetAddress.getLocalHost().getHostAddress();
         String port = env.getProperty("server.port");