| | |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.EsModel; |
| | | import com.ruoyi.service.EsService; |
| | | import com.ruoyi.service.ZfEconomyService; |
| | | import com.ruoyi.service.impl.InterfaceBasedSearchRouter; |
| | | import com.ruoyi.service.impl.ZfEconomyServiceImpl; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.websocket.server.PathParam; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Resource |
| | | EsService esService; |
| | | |
| | | @Resource |
| | | InterfaceBasedSearchRouter interfaceBasedSearchRouter; |
| | | |
| | | @Resource |
| | | ZfEconomyServiceImpl zfEconomyService; |
| | | |
| | | @GetMapping() |
| | | public AjaxResult search(@PathParam("keyword") String keyword){ |
| | |
| | | List<EsModel> modelList = esService.getAll(); |
| | | return AjaxResult.success(modelList); |
| | | } |
| | | |
| | | @GetMapping("/companion/{moduleCode}") |
| | | public AjaxResult getAllbyCAY( @PathVariable("moduleCode") String moduleCode,@RequestParam(value = "companion", required = false) String companion, |
| | | @RequestParam(value = "happenStartTime", required = false) |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") Date happenStartTime, |
| | | @RequestParam(value = "happenEndTime", required = false) |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") Date happenEndTime){ |
| | | System.out.println("[[[[[["+moduleCode); |
| | | System.out.println("[[[[[["+companion); |
| | | |
| | | |
| | | System.out.println("[[[[[["+happenStartTime); |
| | | System.out.println("[[[[[["+happenEndTime); |
| | | |
| | | return interfaceBasedSearchRouter.routeSearch(moduleCode,companion,happenStartTime,happenEndTime); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | messages: |
| | | # 国际化资源文件路径 |
| | | basename: i18n/messages |
| | | profiles: |
| | | profiles: |
| | | active: druid |
| | | # 文件上传 |
| | | servlet: |
| | |
| | | mail.smtp.ssl.trust: smtp.qq.com |
| | | mail.smtp.ssl.protocols: TLSv1.2 |
| | | default-encoding: UTF-8 |
| | | # 特定模块的缓存过期时间 |
| | | cache: |
| | | cache-names: |
| | | economy_search: 1800 # economy_search缓存1小时 |
| | | |
| | | # token配置 |
| | | token: |
| | |
| | | secret: abcdefghijklmnopqrstuvwxyz |
| | | # 令牌有效期(默认30分钟) |
| | | expireTime: 100 |
| | | |
| | | |
| | | # MyBatis配置 |
| | | mybatis-plus: |
| | | # 搜索指定包别名 |
| | |
| | | # configLocation: classpath:mybatis/mybatis-config.xml |
| | | |
| | | # PageHelper分页插件 |
| | | pagehelper: |
| | | pagehelper: |
| | | helperDialect: mysql |
| | | supportMethodsArguments: true |
| | | params: count=countSql |
| | |
| | | @Field(index = true,type = FieldType.Text,analyzer = "ik_max_word") |
| | | private int by13; |
| | | |
| | | /** 备用14 */ |
| | | @Field(index = true,type = FieldType.Date,analyzer = "ik_max_wor") |
| | | private Date by14; |
| | | // /** 备用14 */ |
| | | // @Field(index = true,type = FieldType.Date,analyzer = "ik_max_wor") |
| | | // private Date by14; |
| | | // |
| | | // /** 备用15 */ |
| | | // @Field(index = true,type = FieldType.Date,analyzer = "ik_max_wor") |
| | | // private Date by15; |
| | | |
| | | /** 备用15 */ |
| | | @Field(index = true,type = FieldType.Date,analyzer = "ik_max_wor") |
| | | private Date by15; |
| | | |
| | | /** 备用16 */ |
| | | @Field(index = true,type = FieldType.Date,analyzer = "ik_max_wor ") |
| | | private Timestamp by16; |
| | | // /** 备用16 */ |
| | | // @Field(index = true,type = FieldType.Date,analyzer = "ik_max_wor") |
| | | // private Timestamp by16; |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | <select id="selectMenuTreeAll" resultMap="SysMenuResult"> |
| | | select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time |
| | | from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0 and m.menu_id in (1, 100, 118,2016,2048,2049,2050,2051,2068) |
| | | from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0 and m.menu_id in (1, 100, 118,2016,2048,2049,2050,2051,2068, 2085) |
| | | order by m.parent_id, m.order_num |
| | | |
| | | </select> |
| | |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import lombok.Data; |
| | | import lombok.ToString; |
| | | import org.springframework.data.annotation.Transient; |
| | | |
| | | import java.io.Serializable; |
| | | import java.time.LocalDate; |
| | |
| | | |
| | | private String cosKey; |
| | | |
| | | /** |
| | | * 参与者 |
| | | */ |
| | | private String companion; |
| | | |
| | | // @TableField(exist = false) |
| | | // private Integer year; |
| | | } |
| New file |
| | |
| | | package com.ruoyi.service; |
| | | |
| | | import com.ruoyi.domain.ZfEconomy; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | public interface ModuleSearchable { |
| | | /** |
| | | * 获取支持的模块编码 |
| | | */ |
| | | String getModuleCode(); |
| | | |
| | | /** |
| | | * 搜索方法 |
| | | */ |
| | | List<?> search(String companion, Date happenStartTime,Date happenEndTime); |
| | | |
| | | /** |
| | | * 模块名称 |
| | | */ |
| | | default String getModuleName() { |
| | | return getModuleCode(); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.ruoyi.service.impl; |
| | | |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.service.ModuleSearchable; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.logging.Log; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class InterfaceBasedSearchRouter { |
| | | |
| | | private final Map<String, ModuleSearchable> moduleSearchMap; |
| | | |
| | | /** |
| | | * 自动收集所有实现ModuleSearchable接口的Bean |
| | | */ |
| | | @Autowired |
| | | public InterfaceBasedSearchRouter(List<ModuleSearchable> searchServices) { |
| | | this.moduleSearchMap = searchServices.stream() |
| | | .collect(Collectors.toMap( |
| | | ModuleSearchable::getModuleCode, |
| | | Function.identity(), |
| | | (existing, replacement) -> { |
| | | log.warn("发现重复的模块编码: {}, 使用先注册的服务", existing.getModuleCode()); |
| | | return existing; |
| | | } |
| | | )); |
| | | |
| | | log.info("已注册搜索模块: {}", moduleSearchMap.keySet()); |
| | | } |
| | | |
| | | /** |
| | | * 通用的路由搜索请求(支持不同参数类型) |
| | | */ |
| | | /** |
| | | * 通用的路由搜索请求 |
| | | */ |
| | | public AjaxResult routeSearch(String moduleCode, Object... args) { |
| | | log.info("路由搜索: moduleCode={}, args={}", moduleCode, Arrays.toString(args)); |
| | | |
| | | ModuleSearchable searchService = moduleSearchMap.get(moduleCode); |
| | | if (searchService == null) { |
| | | String availableModules = String.join(", ", moduleSearchMap.keySet()); |
| | | return AjaxResult.error("不支持的搜索模块: " + moduleCode + "。可用模块: [" + availableModules + "]"); |
| | | } |
| | | |
| | | try { |
| | | // 根据参数数量进行路由 |
| | | if (args.length == 3) { |
| | | return handleFourArgs(searchService, args); |
| | | } else { |
| | | return AjaxResult.error("不支持的参数数量,需要3个参数,实际收到: " + args.length); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("搜索执行失败: moduleCode={}", moduleCode, e); |
| | | return AjaxResult.error("搜索执行失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理3个参数的情况(companion + happenStartTime + happenEndTime) |
| | | */ |
| | | private AjaxResult handleFourArgs(ModuleSearchable searchService, Object[] args) { |
| | | String companion = null; |
| | | Date happenStartTime = null; |
| | | Date happenEndTime = null; |
| | | |
| | | // 处理companion参数 |
| | | if (args[0] instanceof String) { |
| | | companion = (String) args[0]; |
| | | } else if (args[0] != null) { |
| | | companion = args[0].toString(); |
| | | } |
| | | |
| | | // 处理时间参数 |
| | | if (args[1] instanceof Date) { |
| | | happenStartTime = (Date) args[1]; |
| | | } |
| | | |
| | | if (args[2] instanceof Date) { |
| | | happenEndTime = (Date) args[2]; |
| | | } |
| | | |
| | | // 判断搜索类型 |
| | | boolean hasTimeRange = happenStartTime != null && happenEndTime != null; |
| | | |
| | | List<?> result; |
| | | if (hasTimeRange) { |
| | | // 有时间范围:执行时间范围搜索 |
| | | log.info("执行时间范围搜索: companion={}, startTime={}, endTime={}", |
| | | companion, happenStartTime, happenEndTime); |
| | | result = searchService.search(companion, happenStartTime, happenEndTime); |
| | | } else { |
| | | // 无时间范围:只按companion搜索 |
| | | log.info("执行companion搜索: companion={}, 时间范围为空", companion); |
| | | result = searchService.search(companion, null, null); |
| | | } |
| | | |
| | | return AjaxResult.success("搜索成功", result); |
| | | } |
| | | // |
| | | // /** |
| | | // * 获取所有可搜索的模块信息 |
| | | // */ |
| | | // public List<SysMenu> getAvailableModules() { |
| | | // return moduleSearchMap.values().stream() |
| | | // .map(service -> SysMenu.builder() |
| | | // .moduleCode(service.getModuleCode()) |
| | | // .moduleName(service.getModuleName()) |
| | | // .build()) |
| | | // .collect(Collectors.toList()); |
| | | // } |
| | | |
| | | /** |
| | | * 检查模块是否支持搜索 |
| | | */ |
| | | public boolean supports(String moduleCode) { |
| | | return moduleSearchMap.containsKey(moduleCode); |
| | | } |
| | | |
| | | /** |
| | | * 获取模块服务实例 |
| | | */ |
| | | public ModuleSearchable getModuleService(String moduleCode) { |
| | | return moduleSearchMap.get(moduleCode); |
| | | } |
| | | } |
| | |
| | | import org.elasticsearch.action.update.UpdateRequest; |
| | | import org.elasticsearch.client.RequestOptions; |
| | | import org.elasticsearch.client.RestHighLevelClient; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class ZfEconomyServiceImpl extends ServiceImpl<ZfEconomyMapper, ZfEconomy> implements ZfEconomyService { |
| | | public class ZfEconomyServiceImpl extends ServiceImpl<ZfEconomyMapper, ZfEconomy> implements ZfEconomyService,ModuleSearchable{ |
| | | @Resource |
| | | ZfEconomyService zfEconomyService; |
| | | |
| | |
| | | lqw.like(StringUtils.isNotEmpty(zfEconomy.getUsePeople()),ZfEconomy::getUsePeople,zfEconomy.getUsePeople()); |
| | | lqw.like(StringUtils.isNotEmpty(zfEconomy.getBalance()),ZfEconomy::getBalance,zfEconomy.getBalance()); |
| | | lqw.like(StringUtils.isNotEmpty(zfEconomy.getRemark()),ZfEconomy::getRemark,zfEconomy.getRemark()); |
| | | lqw.like(StringUtils.isNotEmpty(zfEconomy.getCompanion()),ZfEconomy::getCompanion,zfEconomy.getCompanion()); |
| | | // if (zfEconomy.getYear() != 0) { |
| | | // System.out.println("pppppppppppppppppppppppppppppppppppppppppppppppppppp"+zfEconomy.getYear()); |
| | | // lqw.apply("YEAR(happen_time) = {0}", zfEconomy.getYear()); |
| | | // } |
| | | lqw.eq(zfEconomy.getHappenTime() != null, ZfEconomy::getHappenTime, zfEconomy.getHappenTime()); |
| | | lqw.between(zfEconomy.getHappenStartTime() != null && zfEconomy.getHappenEndTime() != null, ZfEconomy::getHappenTime, zfEconomy.getHappenStartTime(), zfEconomy.getHappenEndTime()); |
| | | System.out.println("查询条件: " + lqw.getCustomSqlSegment()); |
| | | |
| | | return lqw; |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public AjaxResult addData(ZfEconomy zfEconomy) { |
| | | //清除redis中zfEconomy的缓存 |
| | | clearAllCache(); |
| | | |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | Long familyId = myself.getFamilyId(); |
| | | |
| | |
| | | |
| | | @Override |
| | | public AjaxResult updateData(ZfEconomy zfEconomy) { |
| | | //清除redis中zfEconomy的缓存 |
| | | clearAllCache(); |
| | | |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | Long familyId = myself.getFamilyId(); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String getModuleCode() { |
| | | return "2045"; |
| | | } |
| | | |
| | | @Override |
| | | @Cacheable(value = "economy_search", key = "T(String).format('2045_%s_%s_%s',#companion != null ? #companion : 'null',#happenStartTime != null ? #happenStartTime.getTime() : 0,#happenEndTime != null ? #happenEndTime.getTime() : 0)") |
| | | public List<?> search(String companion, Date happenStartTime,Date happenEndTime) { |
| | | ZfEconomy zfEconomy = new ZfEconomy(); |
| | | zfEconomy.setCompanion(companion); |
| | | zfEconomy.setHappenStartTime(happenStartTime); |
| | | zfEconomy.setHappenEndTime(happenEndTime); |
| | | System.out.println("ssssss"+zfEconomy); |
| | | return selectByCondition(zfEconomy); |
| | | } |
| | | |
| | | @CacheEvict(value = "economy_search", allEntries = true) |
| | | public void clearAllCache() { |
| | | System.out.println("清除所有经济搜索缓存"); |
| | | } |
| | | } |