Compare commits

...

2 Commits

Author SHA1 Message Date
LHD_HY 783490fa2e Merge remote-tracking branch 'origin/master' 2025-12-05 09:10:14 +08:00
LHD_HY 729bf16ba2 功能优化 2025-12-05 09:00:04 +08:00
22 changed files with 129 additions and 41 deletions

View File

@ -7,6 +7,7 @@ import com.bonus.common.core.domain.AjaxResult;
import com.bonus.common.core.domain.model.LoginUser;
import com.bonus.common.core.page.TableDataInfo;
import com.bonus.common.domain.template.dto.AnalysisRuleSetDto;
import com.bonus.common.domain.template.dto.AnalysisRuleSetHistoryDto;
import com.bonus.common.domain.template.vo.AnalysisRuleSetVo;
import com.bonus.common.enums.OperaType;
import com.bonus.common.utils.SecurityUtils;
@ -53,9 +54,9 @@ public class AnalysisRuleSetController extends BaseController {
@GetMapping("/list/history")
@SysLog(title = "解析规则配置", module = "解析规则->查询列表", businessType = OperaType.QUERY, details = "查询解析规则配置列表", logType = 1)
@RequiresPermissions("analysis:rule:list")
public TableDataInfo getHistoryList(AnalysisRuleSetDto queryDto) {
public TableDataInfo getHistoryList(AnalysisRuleSetHistoryDto queryDto) {
startPage();
List<AnalysisRuleSetVo> ruleSetList = analysisRuleSetService.selectAnalysisRuleSetList(queryDto);
List<AnalysisRuleSetVo> ruleSetList = analysisRuleSetService.selectAnalysisRuleSetHistoryList(queryDto);
return getDataTable(ruleSetList);
}

View File

@ -2,11 +2,9 @@ package com.bonus.web.service.template;
import com.bonus.common.core.domain.AjaxResult;
import com.bonus.common.domain.template.dto.AnalysisRuleSetDto;
import com.bonus.common.domain.template.po.AnalysisRuleSet;
import com.bonus.common.domain.template.dto.AnalysisRuleSetHistoryDto;
import com.bonus.common.domain.template.po.*;
import com.bonus.common.domain.template.vo.AnalysisRuleSetVo;
import com.bonus.common.domain.template.po.PositionQueryRule;
import com.bonus.common.domain.template.po.SubRule;
import com.bonus.common.domain.template.po.RuleResource;
import com.bonus.common.utils.ValidatorsUtils;
import com.bonus.template.service.IMDAnalysisRuleSetService;
import com.bonus.template.service.IMDPositionQueryRuleService;
@ -52,7 +50,7 @@ public class AnalysisRuleSetService {
return imdAnalysisRuleSetService.selectAnalysisRuleSetList(queryDto);
}
public List<AnalysisRuleSetVo> selectAnalysisRuleSetHistoryList(AnalysisRuleSetDto queryDto) {
public List<AnalysisRuleSetVo> selectAnalysisRuleSetHistoryList(AnalysisRuleSetHistoryDto queryDto) {
return imdAnalysisRuleSetService.selectAnalysisRuleSetHistoryList(queryDto);
}
@ -196,9 +194,9 @@ public class AnalysisRuleSetService {
}
// 2. 校验规则名称唯一性
if (!imdAnalysisRuleSetService.checkAnalysisNameUnique(editDto)) {
return AjaxResult.error("解析规则名称已存在,请更换");
}
// if (!imdAnalysisRuleSetService.checkAnalysisNameUnique(editDto)) {
// return AjaxResult.error("解析规则名称已存在,请更换");
// }
// 3. 修改解析规则主表信息
int rows = imdAnalysisRuleSetService.operAnalysisRuleData(editDto, 2);

View File

@ -197,16 +197,32 @@ public class TemplateInfoService {
}
// 3. 校验模板名称唯一性
if (!imdTemplateInfoService.checkTemplateNameUnique(editDto)) {
return AjaxResult.error("模板名称已存在,请更换");
if(StringUtils.isNotBlank(editDto.getTemplateName())){
if (!imdTemplateInfoService.checkTemplateNameUnique(editDto)) {
return AjaxResult.error("模板名称已存在,请更换");
}
}
// 4. 调用内层Service修改模板信息操作类型2=修改
int rows = imdTemplateInfoService.operTemplateData(editDto, 2);
if (rows <= 0) {
throw new RuntimeException("模板数据修改失败");
}
if (CollectionUtils.isNotEmpty(editDto.getDelComposition())) {
log.info("开始删除模板组成compositionId列表{}", editDto.getDelComposition());
// 遍历需要删除的compositionId列表
for (Long compositionId : editDto.getDelComposition()) {
// 删除模板组成记录本身
int delCompRows = imdTemplateCompositionService.deleteByCompositionId(compositionId);
if (delCompRows <= 0) {
log.warn("模板组成记录删除失败compositionId{}", compositionId);
}
}
}
// 5. 新增文件
if (CollectionUtils.isNotEmpty(editDto.getFiles())) {
for (ResourceFilePo file : editDto.getFiles()) {
@ -297,6 +313,7 @@ public class TemplateInfoService {
for (ResourceFileVo file : composition.getFileList()) {
file.setCompositionFileType(composition.getFileType());
file.setCompositionName(composition.getFileName());
file.setCompositionId(composition.getCompositionId());
// 区分来源project/section
if ("1".equals(composition.getCompositionType())) {
projectFiles.add(file);

View File

@ -212,6 +212,7 @@ public class TemplatePublishService {
history.setShouldIncludeCharactersNum(source.getShouldIncludeCharactersNum());
history.setEndText(source.getEndText());
history.setCurrentVersion(version);
history.setSubRuleId(source.getSubRuleId());
// 移除 createTime, updateTime
return history;
}

View File

@ -36,4 +36,6 @@ public class ResourceFileVo {
private String compositionFileType;
private String compositionName;
private Long compositionId;
}

View File

@ -40,7 +40,6 @@ public class TemplateInfoDto {
* 模板名称
* 新增修改时必填
*/
@NotBlank(message = "模板名称不能为空", groups = {ADD.class, UPDATE.class})
@Length(max = 64, message = "模板名称长度不能超过64", groups = {ADD.class, UPDATE.class})
private String templateName;
@ -48,7 +47,6 @@ public class TemplateInfoDto {
/**
* 行业类型
*/
@NotBlank(message = "行业类型不能为空", groups = {ADD.class, UPDATE.class})
@Length(max = 32, message = "行业类型长度不能超过32", groups = {ADD.class, UPDATE.class})
private String industryType;
@ -61,7 +59,6 @@ public class TemplateInfoDto {
/**
* 启用状态0.启用 1.未启用
*/
@NotBlank(message = "启用状态不能为空", groups = {ADD.class, UPDATE.class})
@Length(max = 2, message = "启用状态长度不能超过2", groups = {ADD.class, UPDATE.class})
private String useState;
@ -137,6 +134,8 @@ public class TemplateInfoDto {
*/
private List<String> delFiles = new ArrayList<>();
private List<Long> delComposition = new ArrayList<>();
/**
* 查询条件限制

View File

@ -56,4 +56,6 @@ public class PositionQueryRuleHistory extends BaseEntity {
private String endText;
private String currentVersion;
private Long subRuleId;
}

View File

@ -19,6 +19,12 @@ public class SubRuleHistory extends BaseEntity {
/** 子规则表主键 */
private Long subRuleId;
/** 内容来源ID模板组成ID */
private Long compositionId;
/** 内容来源名称 */
private String compositionName;
/** 关联解析规则配置id */
private Long ruleSetId;

View File

@ -1,6 +1,8 @@
package com.bonus.template.mapper;
import com.bonus.common.domain.template.dto.AnalysisRuleSetDto;
import com.bonus.common.domain.template.dto.AnalysisRuleSetHistoryDto;
import com.bonus.common.domain.template.dto.TemplateInfoDto;
import com.bonus.common.domain.template.vo.AnalysisRuleSetVo;
import com.bonus.common.domain.template.po.AnalysisRuleSet;
import com.bonus.common.domain.template.po.PositionQueryRule;
@ -23,7 +25,9 @@ public interface IMDAnalysisRuleSetMapper {
*/
List<AnalysisRuleSetVo> selectAnalysisRuleSetList(AnalysisRuleSetDto queryDto);
List<AnalysisRuleSetVo> selectAnalysisRuleSetHistory(AnalysisRuleSetDto queryDto);
List<AnalysisRuleSetVo> selectAnalysisRuleSetHistory(AnalysisRuleSetHistoryDto queryDto);
void updateStatus(Long templateId);
/**
* 2. 根据解析规则ID查询详情
* @param ruleSetId 解析规则主键ID

View File

@ -30,5 +30,6 @@ public interface IMDPositionQueryRuleHistoryMapper {
* @param currentVersion 版本号
* @return 定位查询规则历史记录列表
*/
List<PositionQueryRuleHistory> selectByVersion(@Param("currentVersion") String currentVersion);
List<PositionQueryRuleHistory> selectByVersion(@Param("currentVersion") String currentVersion,
@Param("ruleSetId") Long ruleSetId);
}

View File

@ -30,7 +30,8 @@ public interface IMDSubRuleHistoryMapper {
* @param currentVersion 版本号
* @return 子规则历史记录列表
*/
List<SubRuleHistory> selectByVersion(@Param("currentVersion") String currentVersion);
List<SubRuleHistory> selectByVersion(@Param("currentVersion") String currentVersion,
@Param("ruleSetId") Long ruleSetId);
}

View File

@ -46,4 +46,11 @@ public interface IMDTemplateCompositionMapper {
* @return 组成ID列表
*/
List<Long> selectBusinessIdsByFilePaths(List<String> filePaths, String sourceTable);
/**
* 6. 根据单个组成ID删除模板组成记录
* @param compositionId 组成主键ID
* @return 影响行数
*/
int deleteByCompositionId(Long compositionId);
}

View File

@ -1,11 +1,9 @@
package com.bonus.template.service;
import com.bonus.common.domain.template.dto.AnalysisRuleSetDto;
import com.bonus.common.domain.template.dto.AnalysisRuleSetHistoryDto;
import com.bonus.common.domain.template.po.*;
import com.bonus.common.domain.template.vo.AnalysisRuleSetVo;
import com.bonus.common.domain.template.po.AnalysisRuleSet; // 新增导入
import com.bonus.common.domain.template.po.PositionQueryRule; // 新增导入
import com.bonus.common.domain.template.po.RuleResource; // 新增导入
import com.bonus.common.domain.template.po.SubRule; // 新增导入
import java.util.List;
@ -22,7 +20,7 @@ public interface IMDAnalysisRuleSetService {
*/
List<AnalysisRuleSetVo> selectAnalysisRuleSetList(AnalysisRuleSetDto queryDto);
List<AnalysisRuleSetVo> selectAnalysisRuleSetHistoryList(AnalysisRuleSetDto queryDto);
List<AnalysisRuleSetVo> selectAnalysisRuleSetHistoryList(AnalysisRuleSetHistoryDto queryDto);
/**
* 查询解析规则配置详情纯数据查询

View File

@ -45,4 +45,6 @@ public interface IMDTemplateCompositionService {
* @return 组成ID列表
*/
List<Long> getBusinessIdsByFilePaths(List<String> filePaths, String sourceTable);
int deleteByCompositionId(Long compositionId);
}

View File

@ -1,11 +1,13 @@
package com.bonus.template.service.impl;
import com.bonus.common.domain.template.dto.AnalysisRuleSetDto;
import com.bonus.common.domain.template.dto.AnalysisRuleSetHistoryDto;
import com.bonus.common.domain.template.po.AnalysisRuleSet;
import com.bonus.common.domain.template.po.PositionQueryRule;
import com.bonus.common.domain.template.po.RuleResource;
import com.bonus.common.domain.template.po.SubRule;
import com.bonus.common.domain.template.vo.AnalysisRuleSetVo;
import com.bonus.common.utils.StringUtils;
import com.bonus.template.mapper.IMDAnalysisRuleSetMapper;
import com.bonus.template.service.IMDAnalysisRuleSetService;
import lombok.extern.slf4j.Slf4j;
@ -41,7 +43,7 @@ public class IMDAnalysisRuleSetServiceImpl implements IMDAnalysisRuleSetService
}
@Override
public List<AnalysisRuleSetVo> selectAnalysisRuleSetHistoryList(AnalysisRuleSetDto queryDto) {
public List<AnalysisRuleSetVo> selectAnalysisRuleSetHistoryList(AnalysisRuleSetHistoryDto queryDto) {
try {
// 调用Mapper查询null处理为空白列表避免空指针
return Optional.ofNullable(imdAnalysisRuleSetMapper.selectAnalysisRuleSetHistory(queryDto))
@ -74,8 +76,14 @@ public class IMDAnalysisRuleSetServiceImpl implements IMDAnalysisRuleSetService
try {
// 按操作类型调用Mapper统一处理新增/修改/删除
if (type == 1) { // 1=新增
if(dto.getTemplateId() > 0){
imdAnalysisRuleSetMapper.updateStatus(dto.getTemplateId());
}
return Optional.ofNullable(imdAnalysisRuleSetMapper.insertAnalysisRule(dto)).orElse(0);
} else if (type == 2) { // 2=修改
if(dto.getTemplateId() > 0){
imdAnalysisRuleSetMapper.updateStatus(dto.getTemplateId());
}
// 校验解析规则ID有效性
if (dto.getRuleSetId() == null || dto.getRuleSetId() <= 0) {
log.warn("修改解析规则配置失败解析规则ID为空或无效");

View File

@ -106,4 +106,20 @@ public class IMDTemplateCompositionServiceImpl implements IMDTemplateComposition
return new ArrayList<>();
}
}
@Override
public int deleteByCompositionId(Long compositionId) {
try {
// 校验组成ID有效性
if (compositionId == null || compositionId <= 0) {
log.warn("按组成ID删除模板组成记录失败组成ID为空或无效");
return 0;
}
// 调用Mapper删除单个组成记录null处理为0
return Optional.ofNullable(imdTemplateCompositionMapper.deleteByCompositionId(compositionId)).orElse(0);
} catch (Exception e) {
log.error("按组成ID删除模板组成记录失败compositionId={}", compositionId, e);
return 0;
}
}
}

View File

@ -156,6 +156,14 @@
where rule_set_id = #{ruleSetId}
</update>
<update id="updateStatus" parameterType="com.bonus.common.domain.template.dto.TemplateInfoDto">
update tb_template
<set>
published_status = '0'
</set>
where template_id = #{templateId}
</update>
<!-- 6. 逻辑删除解析规则配置 -->
<delete id="deleteAnalysisRule" parameterType="com.bonus.common.domain.template.dto.AnalysisRuleSetDto">
update tb_analysis_rule_set
@ -232,15 +240,14 @@
<result property="updateTime" column="update_time" />
<result property="currentVersion" column="current_version" />
<!-- 仅通过currentVersion关联定位规则历史表 -->
<collection property="positions" ofType="com.bonus.common.domain.template.po.PositionQueryRuleHistory"
select="com.bonus.template.mapper.IMDPositionQueryRuleHistoryMapper.selectByVersion"
column="current_version"/>
column="{currentVersion=current_version, ruleSetId=rule_set_id}"/>
<!-- 仅通过currentVersion关联子规则历史表 -->
<collection property="subRules" ofType="com.bonus.common.domain.template.po.SubRuleHistory"
select="com.bonus.template.mapper.IMDSubRuleHistoryMapper.selectByVersion"
column="current_version"/>
column="{currentVersion=current_version, ruleSetId=rule_set_id}"/>
</resultMap>
<!-- 基础查询SQL片段 -->

View File

@ -52,15 +52,16 @@
<!-- 新增的查询方法 -->
<select id="selectDistinctVersionsByTemplateId" resultMap="VersionVOMap">
SELECT
DISTINCT
current_version,
update_time
MAX(update_time) AS update_time
FROM
tb_analysis_rule_set_history
WHERE
template_id = #{templateId}
GROUP BY
current_version
ORDER BY
update_time DESC
update_time DESC;
</select>

View File

@ -9,7 +9,7 @@
specified_word_count, specified_text, before_characters_num,
specified_keywords, after_characters_num, specified_word_count_length,
before_specified_characters_num, first_text, should_include_characters_num,
end_text,current_version
end_text,current_version,sub_rule_id
</sql>
<!-- 1. 插入单条记录 -->
@ -21,7 +21,7 @@
#{specifiedWordCount}, #{specifiedText}, #{beforeCharactersNum},
#{specifiedKeywords}, #{afterCharactersNum}, #{specifiedWordCountLength},
#{beforeSpecifiedCharactersNum}, #{firstText}, #{shouldIncludeCharactersNum},
#{endText}, #{currentVersion}
#{endText}, #{currentVersion}, #{subRuleId}
)
</insert>
@ -36,18 +36,18 @@
#{item.specifiedWordCount}, #{item.specifiedText}, #{item.beforeCharactersNum},
#{item.specifiedKeywords}, #{item.afterCharactersNum}, #{item.specifiedWordCountLength},
#{item.beforeSpecifiedCharactersNum}, #{item.firstText}, #{item.shouldIncludeCharactersNum},
#{item.endText},#{item.currentVersion}
#{item.endText},#{item.currentVersion}, #{item.subRuleId}
)
</foreach>
</insert>
<!-- 根据版本号查询 -->
<select id="selectByVersion" parameterType="java.lang.String" resultType="com.bonus.common.domain.template.po.PositionQueryRuleHistory">
<select id="selectByVersion" parameterType="com.bonus.common.domain.template.po.PositionQueryRuleHistory" resultType="com.bonus.common.domain.template.po.PositionQueryRuleHistory">
select
<include refid="Base_Column_List"/>
from tb_position_query_rule_history
where current_version = #{currentVersion}
and del_flag = '0'
and rule_set_id = #{ruleSetId}
</select>
</mapper>

View File

@ -30,12 +30,20 @@
</insert>
<!-- 根据版本号查询 -->
<select id="selectByVersion" parameterType="java.lang.String" resultType="com.bonus.common.domain.template.po.SubRuleHistory">
<select id="selectByVersion" parameterType="com.bonus.common.domain.template.po.SubRuleHistory" resultType="com.bonus.common.domain.template.po.SubRuleHistory">
select
<include refid="Base_Column_List"/>
from tb_sub_rule_history
where current_version = #{currentVersion}
and del_flag = '0'
sr.sub_rule_id,
sr.rule_set_id,
sr.sort_order,
sr.del_flag,
tr.composition_id,
tr.sub_rule_id,
tr.rule_resource_id
from tb_sub_rule_history sr
left join tb_position_query_rule_resource_history tr on tr.sub_rule_id = sr.sub_rule_id
where tr.current_version = #{currentVersion}
and sr.current_version = #{currentVersion}
and rule_set_id = #{ruleSetId}
order by sort_order asc
</select>

View File

@ -25,6 +25,7 @@
<select id="selectByTemplateId" parameterType="Long" resultMap="templateCompositionResult">
<include refid="selectTemplateComposition"/>
where template_id = #{templateId}
and del_flag = '0'
</select>
<!-- 2. 新增模板组成记录 -->
@ -80,4 +81,11 @@
where composition_id = #{compositionId}
</update>
<delete id="deleteByCompositionId" parameterType="Long">
update tb_template_composition
set del_flag = '1'
where composition_id = #{compositionId}
</delete>
</mapper>

View File

@ -47,6 +47,7 @@
left join tb_template_composition comp
on tb.template_id = comp.template_id
where tb.del_flag = '0'
and comp.del_flag = '0'
</sql>