xinli/ry-xinli-system/src/main/resources/mapper/system/psychology/PsyWarningRuleMapper.xml

159 lines
8.4 KiB
XML
Raw Normal View History

<?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.ddnai.system.mapper.psychology.PsyWarningRuleMapper">
<resultMap type="com.ddnai.system.domain.psychology.PsyWarningRule" id="PsyWarningRuleResult">
<result property="ruleId" column="rule_id" />
<result property="scaleId" column="scale_id" />
<result property="factorId" column="factor_id" />
<result property="ruleName" column="rule_name" />
<result property="warningLevel" column="warning_level" />
<result property="scoreMin" column="score_min" />
<result property="scoreMax" column="score_max" />
<result property="percentileMin" column="percentile_min" />
<result property="percentileMax" column="percentile_max" />
<result property="autoRelief" column="auto_relief" />
<result property="reliefCondition" column="relief_condition" />
<result property="status" column="status" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="scaleName" column="scale_name" />
<result property="factorName" column="factor_name" />
</resultMap>
<sql id="selectWarningRuleVo">
select r.rule_id, r.scale_id, r.factor_id, r.rule_name, r.warning_level,
r.score_min, r.score_max, r.percentile_min, r.percentile_max,
r.auto_relief, r.relief_condition, r.status,
r.create_by, r.create_time, r.update_by, r.update_time, r.remark,
s.scale_name, f.factor_name
from psy_warning_rule r
left join psy_scale s on r.scale_id = s.scale_id
left join psy_factor f on r.factor_id = f.factor_id
</sql>
<select id="selectWarningRuleById" parameterType="Long" resultMap="PsyWarningRuleResult">
<include refid="selectWarningRuleVo"/>
where r.rule_id = #{ruleId}
</select>
<select id="selectWarningRuleList" parameterType="com.ddnai.system.domain.psychology.PsyWarningRule" resultMap="PsyWarningRuleResult">
2025-11-22 21:26:49 +08:00
select r.rule_id, r.scale_id, r.factor_id, r.rule_name, r.warning_level,
r.score_min, r.score_max, r.percentile_min, r.percentile_max,
r.auto_relief, r.relief_condition, r.status,
r.create_by, r.create_time, r.update_by, r.update_time, r.remark,
s.scale_name, f.factor_name
from psy_warning_rule r
left join psy_scale s on r.scale_id = s.scale_id
left join psy_factor f on r.factor_id = f.factor_id
<where>
<if test="scaleId != null">
AND r.scale_id = #{scaleId}
</if>
<if test="factorId != null">
AND r.factor_id = #{factorId}
</if>
<if test="warningLevel != null and warningLevel != ''">
2025-11-22 21:26:49 +08:00
AND (r.warning_level = #{warningLevel}
OR r.warning_level LIKE CONCAT('%', #{warningLevel}, '%')
OR (#{warningLevel} = '低' AND (r.warning_level = 'low' OR r.warning_level LIKE '%低%'))
OR (#{warningLevel} = '中' AND (r.warning_level = 'medium' OR r.warning_level LIKE '%中%'))
OR (#{warningLevel} = '高' AND (r.warning_level = 'high' OR r.warning_level LIKE '%高%'))
OR (#{warningLevel} = '严重' AND (r.warning_level = 'critical' OR r.warning_level LIKE '%严重%')))
</if>
<if test="status != null and status != ''">
AND r.status = #{status}
</if>
</where>
order by r.scale_id, r.factor_id, r.score_min
</select>
<select id="selectEnabledWarningRuleListByScaleId" parameterType="Long" resultMap="PsyWarningRuleResult">
<include refid="selectWarningRuleVo"/>
where r.scale_id = #{scaleId} and r.status = '1'
order by r.factor_id, r.score_min
</select>
<select id="selectEnabledWarningRuleList" resultMap="PsyWarningRuleResult">
<include refid="selectWarningRuleVo"/>
where r.scale_id = #{scaleId} and r.status = '1'
<if test="factorId != null">
AND r.factor_id = #{factorId}
</if>
<if test="factorId == null">
AND r.factor_id IS NULL
</if>
order by r.score_min
</select>
<insert id="insertWarningRule" parameterType="com.ddnai.system.domain.psychology.PsyWarningRule" useGeneratedKeys="true" keyProperty="ruleId">
insert into psy_warning_rule (
<if test="scaleId != null">scale_id, </if>
<if test="factorId != null">factor_id, </if>
<if test="ruleName != null and ruleName != ''">rule_name, </if>
<if test="warningLevel != null and warningLevel != ''">warning_level, </if>
<if test="scoreMin != null">score_min, </if>
<if test="scoreMax != null">score_max, </if>
<if test="percentileMin != null">percentile_min, </if>
<if test="percentileMax != null">percentile_max, </if>
<if test="autoRelief != null and autoRelief != ''">auto_relief, </if>
<if test="reliefCondition != null">relief_condition, </if>
<if test="status != null and status != ''">status, </if>
<if test="remark != null">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="scaleId != null">#{scaleId}, </if>
<if test="factorId != null">#{factorId}, </if>
<if test="ruleName != null and ruleName != ''">#{ruleName}, </if>
<if test="warningLevel != null and warningLevel != ''">#{warningLevel}, </if>
<if test="scoreMin != null">#{scoreMin}, </if>
<if test="scoreMax != null">#{scoreMax}, </if>
<if test="percentileMin != null">#{percentileMin}, </if>
<if test="percentileMax != null">#{percentileMax}, </if>
<if test="autoRelief != null and autoRelief != ''">#{autoRelief}, </if>
<if test="reliefCondition != null">#{reliefCondition}, </if>
<if test="status != null and status != ''">#{status}, </if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateWarningRule" parameterType="com.ddnai.system.domain.psychology.PsyWarningRule">
update psy_warning_rule
<set>
<if test="ruleName != null and ruleName != ''">rule_name = #{ruleName}, </if>
<if test="warningLevel != null and warningLevel != ''">warning_level = #{warningLevel}, </if>
<if test="scoreMin != null">score_min = #{scoreMin}, </if>
<if test="scoreMax != null">score_max = #{scoreMax}, </if>
<if test="percentileMin != null">percentile_min = #{percentileMin}, </if>
<if test="percentileMax != null">percentile_max = #{percentileMax}, </if>
<if test="autoRelief != null and autoRelief != ''">auto_relief = #{autoRelief}, </if>
<if test="reliefCondition != null">relief_condition = #{reliefCondition}, </if>
<if test="status != null and status != ''">status = #{status}, </if>
<if test="remark != null">remark = #{remark}, </if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where rule_id = #{ruleId}
</update>
<delete id="deleteWarningRuleById" parameterType="Long">
delete from psy_warning_rule where rule_id = #{ruleId}
</delete>
<delete id="deleteWarningRuleByIds" parameterType="String">
delete from psy_warning_rule where rule_id in
<foreach item="ruleId" collection="array" open="(" separator="," close=")">
#{ruleId}
</foreach>
</delete>
</mapper>