305 lines
14 KiB
XML
305 lines
14 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
||
<!DOCTYPE mapper
|
||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||
<mapper namespace="com.bonus.template.mapper.IMDAnalysisRuleSetMapper">
|
||
|
||
<!-- 结果集映射(与AnalysisRuleSetVo完全对应,包含前端展示所需字段) -->
|
||
<resultMap type="com.bonus.common.domain.template.vo.AnalysisRuleSetVo" id="analysisRuleSetResult">
|
||
<id property="ruleSetId" column="rule_set_id" />
|
||
<result property="templateId" column="template_id" />
|
||
<result property="templateName" column="template_name" /> <!-- 关联查询的模板名称 -->
|
||
<result property="analysisLabelItemId" column="analysis_label_item_id" />
|
||
<result property="analysisLabelItemName" column="analysis_label_item_name" /> <!-- 关联查询的配置项名称 -->
|
||
<result property="analysisName" column="analysis_name" />
|
||
<result property="analysisCode" column="analysis_code" />
|
||
<result property="parentId" column="parent_id" />
|
||
<result property="parentName" column="parent_name" /> <!-- 关联查询的父节点名称 -->
|
||
<result property="analysisLevel" column="analysis_level" />
|
||
<result property="analysisSort" column="analysis_sort" />
|
||
<result property="promptWord" column="prompt_word" />
|
||
<result property="delFlag" column="del_flag" />
|
||
<result property="createTime" column="create_time" />
|
||
<result property="updateTime" column="update_time" />
|
||
|
||
|
||
<!-- 关联查询定位规则列表 -->
|
||
<collection property="positions" ofType="com.bonus.common.domain.template.po.PositionQueryRule"
|
||
select="com.bonus.template.mapper.IMDPositionQueryRuleMapper.selectByRuleSetId"
|
||
column="rule_set_id"/>
|
||
|
||
<collection property="subRules" ofType="com.bonus.common.domain.template.po.SubRule"
|
||
select="com.bonus.template.mapper.IMDSubRuleMapper.selectByRuleSetId"
|
||
column="rule_set_id"/>
|
||
</resultMap>
|
||
|
||
<!-- 基础查询SQL片段(包含关联表字段) -->
|
||
<sql id="selectAnalysisRuleSet">
|
||
select
|
||
ars.rule_set_id,
|
||
ars.template_id,
|
||
ars.analysis_label_item_id,
|
||
ars.analysis_name,
|
||
ars.analysis_code,
|
||
ars.parent_id,
|
||
ars.analysis_level,
|
||
ars.analysis_sort,
|
||
ars.create_time,
|
||
ars.update_time,
|
||
ars.del_flag,
|
||
ars.prompt_word
|
||
from tb_analysis_rule_set ars
|
||
where ars.del_flag = '0'
|
||
</sql>
|
||
|
||
<!-- 1. 列表查询 -->
|
||
<select id="selectAnalysisRuleSetList" parameterType="com.bonus.common.domain.template.dto.AnalysisRuleSetDto" resultMap="analysisRuleSetResult">
|
||
<include refid="selectAnalysisRuleSet"/>
|
||
|
||
<!-- 模板ID筛选 -->
|
||
<if test="templateId != null and templateId != 0">
|
||
AND ars.template_id = #{templateId}
|
||
</if>
|
||
|
||
<!-- 配置项ID筛选 -->
|
||
<if test="analysisLabelItemId != null and analysisLabelItemId != ''">
|
||
AND ars.analysis_label_item_id = #{analysisLabelItemId}
|
||
</if>
|
||
|
||
<!-- 解析名称模糊查询 -->
|
||
<if test="analysisName != null and analysisName != ''">
|
||
AND ars.analysis_name like concat('%', #{analysisName}, '%')
|
||
</if>
|
||
|
||
<!-- 解析编码筛选 -->
|
||
<if test="analysisCode != null and analysisCode != ''">
|
||
AND ars.analysis_code = #{analysisCode}
|
||
</if>
|
||
|
||
<!-- 父节点筛选 -->
|
||
<if test="parentId != null and parentId != ''">
|
||
AND ars.parent_id = #{parentId}
|
||
</if>
|
||
|
||
<!-- 排序:按排序号升序 -->
|
||
order by ars.analysis_sort asc, ars.create_time desc
|
||
</select>
|
||
|
||
<!-- 2. 详情查询(根据解析规则ID) -->
|
||
<select id="selectAnalysisRuleSetById" parameterType="Long" resultMap="analysisRuleSetResult">
|
||
<include refid="selectAnalysisRuleSet"/>
|
||
AND ars.rule_set_id = #{ruleSetId}
|
||
</select>
|
||
|
||
<!-- 3. 校验解析规则名称唯一性 -->
|
||
<select id="checkAnalysisNameUnique" parameterType="com.bonus.common.domain.template.dto.AnalysisRuleSetDto" resultType="Integer">
|
||
select count(1)
|
||
from tb_analysis_rule_set
|
||
where del_flag = '0'
|
||
and analysis_name = #{analysisName}
|
||
<!-- 编辑时排除自身 -->
|
||
<if test="ruleSetId != null and ruleSetId != 0">
|
||
AND rule_set_id != #{ruleSetId}
|
||
</if>
|
||
</select>
|
||
|
||
<!-- 4. 新增解析规则配置 -->
|
||
<insert id="insertAnalysisRule" parameterType="com.bonus.common.domain.template.dto.AnalysisRuleSetDto" useGeneratedKeys="true" keyProperty="ruleSetId">
|
||
insert into tb_analysis_rule_set(
|
||
rule_set_id,
|
||
template_id,
|
||
analysis_label_item_id,
|
||
analysis_name,
|
||
analysis_code,
|
||
parent_id,
|
||
analysis_level,
|
||
analysis_sort,
|
||
create_time,
|
||
prompt_word
|
||
)values(
|
||
#{ruleSetId},
|
||
#{templateId},
|
||
#{analysisLabelItemId},
|
||
#{analysisName},
|
||
#{analysisCode},
|
||
#{parentId},
|
||
#{analysisLevel},
|
||
#{analysisSort},
|
||
sysdate(),
|
||
#{promptWord}
|
||
)
|
||
</insert>
|
||
|
||
<!-- 5. 编辑解析规则配置 -->
|
||
<update id="updateAnalysisRule" parameterType="com.bonus.common.domain.template.dto.AnalysisRuleSetDto">
|
||
update tb_analysis_rule_set
|
||
<set>
|
||
<!-- 模板ID -->
|
||
<if test="templateId != null and templateId != 0">template_id = #{templateId},</if>
|
||
<!-- 配置项ID -->
|
||
<if test="analysisLabelItemId != null and analysisLabelItemId != ''">analysis_label_item_id = #{analysisLabelItemId},</if>
|
||
<!-- 解析名称 -->
|
||
<if test="analysisName != null and analysisName != ''">analysis_name = #{analysisName},</if>
|
||
<!-- 解析编码 -->
|
||
<if test="analysisCode != null and analysisCode != ''">analysis_code = #{analysisCode},</if>
|
||
<!-- 父节点 -->
|
||
<if test="parentId != null and parentId != ''">parent_id = #{parentId},</if>
|
||
<!-- 层级 -->
|
||
<if test="analysisLevel != null">analysis_level = #{analysisLevel},</if>
|
||
<!-- 排序 -->
|
||
<if test="analysisSort != null">analysis_sort = #{analysisSort},</if>
|
||
<!-- 提示词 -->
|
||
<if test="promptWord != null and promptWord != ''">prompt_word = #{promptWord},</if>
|
||
<!-- 修改时间 -->
|
||
update_time = sysdate()
|
||
</set>
|
||
where rule_set_id = #{ruleSetId}
|
||
</update>
|
||
|
||
<!-- 6. 逻辑删除解析规则配置 -->
|
||
<delete id="deleteAnalysisRule" parameterType="com.bonus.common.domain.template.dto.AnalysisRuleSetDto">
|
||
update tb_analysis_rule_set
|
||
set
|
||
del_flag = '1',
|
||
update_time = sysdate()
|
||
where rule_set_id = #{ruleSetId}
|
||
</delete>
|
||
|
||
<select id="selectByTemplateId" parameterType="Long" resultType="com.bonus.common.domain.template.po.AnalysisRuleSet">
|
||
select
|
||
rule_set_id, template_id, analysis_label_item_id,
|
||
analysis_name, analysis_code, parent_id, analysis_level,
|
||
analysis_sort, prompt_word, del_flag, create_time,
|
||
update_time
|
||
from tb_analysis_rule_set
|
||
where del_flag = '0'
|
||
and template_id = #{templateId}
|
||
order by analysis_sort asc
|
||
</select>
|
||
|
||
<!-- 新增:2. 根据解析规则ID查询子规则 -->
|
||
<select id="selectSubRulesByRuleSetId" parameterType="Long" resultType="com.bonus.common.domain.template.po.SubRule">
|
||
select
|
||
sub_rule_id, rule_set_id, sort_order, del_flag
|
||
from tb_sub_rule
|
||
where del_flag = '0'
|
||
and rule_set_id = #{ruleSetId}
|
||
order by sort_order asc
|
||
</select>
|
||
|
||
<!-- 新增:3. 根据解析规则ID查询定位查询规则 -->
|
||
<select id="selectPositionQueryRulesByRuleSetId" parameterType="Long" resultType="com.bonus.common.domain.template.po.PositionQueryRule">
|
||
select
|
||
query_rule_id, rule_set_id, rule_set_type, 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
|
||
from tb_position_query_rule
|
||
where rule_set_id = #{ruleSetId}
|
||
</select>
|
||
|
||
<!-- 新增:4. 根据子规则ID查询关联的内容来源 -->
|
||
<select id="selectResourcesBySubRuleId" parameterType="Long" resultType="com.bonus.common.domain.template.po.RuleResource">
|
||
select
|
||
rule_resource_id, sub_rule_id, composition_id
|
||
from tb_rule_resource
|
||
where sub_rule_id = #{subRuleId}
|
||
</select>
|
||
|
||
<!-- 新增:5. 根据定位查询规则ID查询关联的内容来源 -->
|
||
<select id="selectResourcesByQueryRuleId" parameterType="Long" resultType="com.bonus.common.domain.template.po.RuleResource">
|
||
select
|
||
rule_resource_id, sub_rule_id, composition_id
|
||
from tb_rule_resource
|
||
where query_rule_id = #{queryRuleId}
|
||
</select>
|
||
|
||
<resultMap type="com.bonus.common.domain.template.vo.AnalysisRuleSetVo" id="analysisRuleSetHistoryResult">
|
||
<id property="ruleSetId" column="rule_set_id" />
|
||
<result property="templateId" column="template_id" />
|
||
<result property="templateName" column="template_name" />
|
||
<result property="analysisLabelItemId" column="analysis_label_item_id" />
|
||
<result property="analysisLabelItemName" column="analysis_label_item_name" />
|
||
<result property="analysisName" column="analysis_name" />
|
||
<result property="analysisCode" column="analysis_code" />
|
||
<result property="parentId" column="parent_id" />
|
||
<result property="parentName" column="parent_name" />
|
||
<result property="analysisLevel" column="analysis_level" />
|
||
<result property="analysisSort" column="analysis_sort" />
|
||
<result property="promptWord" column="prompt_word" />
|
||
<result property="delFlag" column="del_flag" />
|
||
<result property="createTime" column="create_time" />
|
||
<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"/>
|
||
|
||
<!-- 仅通过currentVersion关联子规则历史表 -->
|
||
<collection property="subRules" ofType="com.bonus.common.domain.template.po.SubRuleHistory"
|
||
select="com.bonus.template.mapper.IMDSubRuleHistoryMapper.selectByVersion"
|
||
column="current_version"/>
|
||
</resultMap>
|
||
|
||
<!-- 基础查询SQL片段 -->
|
||
<sql id="selectAnalysisRuleSetHistory">
|
||
select
|
||
arsh.rule_set_id,
|
||
arsh.template_id,
|
||
arsh.analysis_label_item_id,
|
||
arsh.analysis_name,
|
||
arsh.analysis_code,
|
||
arsh.parent_id,
|
||
arsh.analysis_level,
|
||
arsh.analysis_sort,
|
||
arsh.create_time,
|
||
arsh.update_time,
|
||
arsh.del_flag,
|
||
arsh.prompt_word,
|
||
arsh.current_version
|
||
from tb_analysis_rule_set_history arsh
|
||
where arsh.del_flag = '0'
|
||
</sql>
|
||
|
||
<!-- 列表查询方法(以currentVersion为核心关联条件) -->
|
||
<select id="selectAnalysisRuleSetHistory" parameterType="com.bonus.common.domain.template.dto.AnalysisRuleSetHistoryDto" resultMap="analysisRuleSetHistoryResult">
|
||
<include refid="selectAnalysisRuleSetHistory"/>
|
||
|
||
<!-- 模板ID筛选 -->
|
||
<if test="templateId != null and templateId != 0">
|
||
and arsh.template_id = #{templateId}
|
||
</if>
|
||
|
||
<!-- 配置项ID筛选 -->
|
||
<if test="analysisLabelItemId != null and analysisLabelItemId != ''">
|
||
and arsh.analysis_label_item_id = #{analysisLabelItemId}
|
||
</if>
|
||
|
||
<!-- 版本号筛选(核心关联条件) -->
|
||
<if test="currentVersion != null and currentVersion != ''">
|
||
and arsh.current_version = #{currentVersion}
|
||
</if>
|
||
|
||
<!-- 解析名称模糊查询 -->
|
||
<if test="analysisName != null and analysisName != ''">
|
||
and arsh.analysis_name like concat('%', #{analysisName}, '%')
|
||
</if>
|
||
|
||
<!-- 解析编码筛选 -->
|
||
<if test="analysisCode != null and analysisCode != ''">
|
||
and arsh.analysis_code = #{analysisCode}
|
||
</if>
|
||
|
||
<!-- 父节点筛选 -->
|
||
<if test="parentId != null and parentId != ''">
|
||
and arsh.parent_id = #{parentId}
|
||
</if>
|
||
|
||
<!-- 排序:按版本号降序,再按排序号升序 -->
|
||
order by arsh.current_version desc, arsh.analysis_sort asc, arsh.update_time desc
|
||
</select>
|
||
|
||
</mapper>
|