Merge remote-tracking branch 'origin/main'

This commit is contained in:
2025-12-09 18:17:53 +08:00
10 changed files with 578 additions and 45 deletions

View File

@@ -26,6 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="statusId" column="status_id" />
<result property="weaningWeight" column="weaning_weight" />
<result property="currentWeight" column="current_weight" />
<result property="weaningDayAge" column="weaning_day_age" />
<result property="weaningDailyGain" column="weaning_daily_gain" />
<result property="breedStatusId" column="breed_status_id" />
<result property="breed" column="breed" />
<result property="bsFatherId" column="bs_father_id" />
@@ -72,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectSheepFileVo">
select id, bs_manage_tags, ranch_id, dr_ranch, sheepfold_id, sheepfold_name, electronic_tags, variety_id, variety, family, name, gender, birthday, day_age, month_age, parity, birth_weight, weaning_date, status_id, weaning_weight, current_weight, breed_status_id, breed, bs_father_id, father_manage_tags, bs_mother_id, mother_manage_tags, receptor_id, receptor_manage_tags, father_father_id, grandfather_manage_tags, father_mother_id, grandmother_manage_tags, father_id, maternal_grandfather_manage_tags, mother_id, maternal_grandmother_manage_tags, mating_date, mating_type_id, preg_date, lambing_date, lambing_day, mating_day, gestation_day, expected_date, post_lambing_day, lactation_day, anestrous_day, mating_counts, mating_total, miscarriage_counts, comment, controlled, body, breast, source, source_date, source_ranch_id, source_ranch, update_by, update_time, create_by, create_time, is_delete from sheep_file
select id, bs_manage_tags, ranch_id, dr_ranch, sheepfold_id, sheepfold_name, electronic_tags, variety_id, variety, family, name, gender, birthday, day_age, month_age, parity, birth_weight, weaning_date, status_id, weaning_weight, current_weight,weaning_day_age,weaning_daily_gain,breed_status_id, breed, bs_father_id, father_manage_tags, bs_mother_id, mother_manage_tags, receptor_id, receptor_manage_tags, father_father_id, grandfather_manage_tags, father_mother_id, grandmother_manage_tags, father_id, maternal_grandfather_manage_tags, mother_id, maternal_grandmother_manage_tags, mating_date, mating_type_id, preg_date, lambing_date, lambing_day, mating_day, gestation_day, expected_date, post_lambing_day, lactation_day, anestrous_day, mating_counts, mating_total, miscarriage_counts, comment, controlled, body, breast, source, source_date, source_ranch_id, source_ranch, update_by, update_time, create_by, create_time, is_delete from sheep_file
</sql>
<select id="selectSheepFileList" parameterType="SheepFile" resultMap="SheepFileResult">
@@ -139,5 +141,134 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY parity
</select>
<!--
获取字段唯一值的SQL映射
说明:这个查询使用 ${fieldName} 直接拼接字段名因为MyBatis的#{}不支持列名作为参数
安全性通过Service层的白名单验证来确保fieldName的安全性
-->
<select id="selectFieldValues" parameterType="String" resultType="String">
SELECT
DISTINCT ${fieldName} as field_value
FROM
sheep_file
WHERE
<!-- 过滤空值和NULL值确保返回的数据质量 -->
${fieldName} IS NOT NULL
AND ${fieldName} != ''
AND ${fieldName} != 'null'
ORDER BY
<!-- 按字母顺序排序,方便前端显示 -->
${fieldName} ASC
</select>
<select id="selectSheepFileListByCondition" parameterType="map" resultMap="SheepFileResult">
<include refid="selectSheepFileVo"/>
FROM sheep_file
<where>
<!-- 逻辑删除过滤 -->
AND is_delete = 0
<!-- 原有的 SheepFile 条件(保持兼容性) -->
<if test="sheepFile != null">
<if test="sheepFile.bsManageTags != null and sheepFile.bsManageTags != ''">
AND bs_manage_tags LIKE CONCAT('%', #{sheepFile.bsManageTags}, '%')
</if>
<if test="sheepFile.electronicTags != null and sheepFile.electronicTags != ''">
AND electronic_tags LIKE CONCAT('%', #{sheepFile.electronicTags}, '%')
</if>
<if test="sheepFile.drRanch != null and sheepFile.drRanch != ''">
AND dr_ranch LIKE CONCAT('%', #{sheepFile.drRanch}, '%')
</if>
<if test="sheepFile.variety != null and sheepFile.variety != ''">
AND variety LIKE CONCAT('%', #{sheepFile.variety}, '%')
</if>
<if test="sheepFile.name != null and sheepFile.name != ''">
AND name LIKE CONCAT('%', #{sheepFile.name}, '%')
</if>
<if test="sheepFile.gender != null">
AND gender = #{sheepFile.gender}
</if>
<if test="sheepFile.statusId != null">
AND status_id = #{sheepFile.statusId}
</if>
<if test="sheepFile.breed != null and sheepFile.breed != ''">
AND breed LIKE CONCAT('%', #{sheepFile.breed}, '%')
</if>
</if>
<!-- 动态条件处理 - 使用多个if标签代替复杂的choose -->
<if test="params != null and !params.isEmpty()">
<!-- 空值条件 -->
<foreach collection="params.entrySet()" item="value" index="key">
<if test="value == 'IS_NULL'">
AND ${key} IS NULL
</if>
<if test="value == 'NOT_NULL'">
AND ${key} IS NOT NULL
</if>
</foreach>
<!-- 范围条件 -->
<foreach collection="params.entrySet()" item="value" index="key">
<if test="value != null and value.toString().startsWith('GT:')">
AND ${key} &gt; #{value.toString().substring(3)}
</if>
<if test="value != null and value.toString().startsWith('LT:')">
AND ${key} &lt; #{value.toString().substring(3)}
</if>
<if test="value != null and value.toString().startsWith('GE:')">
AND ${key} &gt;= #{value.toString().substring(3)}
</if>
<if test="value != null and value.toString().startsWith('LE:')">
AND ${key} &lt;= #{value.toString().substring(3)}
</if>
</foreach>
<!-- 列表条件 -->
<foreach collection="params.entrySet()" item="value" index="key">
<if test="value != null and value.toString().contains(',')">
AND ${key} IN
<foreach collection="value.toString().split(',')" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</foreach>
<!-- 模糊查询条件(针对文本字段) -->
<foreach collection="params.entrySet()" item="value" index="key">
<if test="value != null and
(key == 'bs_manage_tags' or key == 'electronic_tags' or
key == 'dr_ranch' or key == 'sheepfold_name' or
key == 'variety' or key == 'family' or
key == 'name' or key == 'breed' or
key == 'father_manage_tags' or key == 'mother_manage_tags' or
key == 'receptor_manage_tags') and
value != 'IS_NULL' and value != 'NOT_NULL' and
!value.toString().startsWith('GT:') and !value.toString().startsWith('LT:') and
!value.toString().startsWith('GE:') and !value.toString().startsWith('LE:') and
!value.toString().contains(',')">
AND ${key} LIKE CONCAT('%', #{value}, '%')
</if>
</foreach>
<!-- 普通等于条件 -->
<foreach collection="params.entrySet()" item="value" index="key">
<if test="value != null and
value != 'IS_NULL' and value != 'NOT_NULL' and
!value.toString().startsWith('GT:') and !value.toString().startsWith('LT:') and
!value.toString().startsWith('GE:') and !value.toString().startsWith('LE:') and
!value.toString().contains(',') and
!(key == 'bs_manage_tags' or key == 'electronic_tags' or
key == 'dr_ranch' or key == 'sheepfold_name' or
key == 'variety' or key == 'family' or
key == 'name' or key == 'breed' or
key == 'father_manage_tags' or key == 'mother_manage_tags' or
key == 'receptor_manage_tags')">
AND ${key} = #{value}
</if>
</foreach>
</if>
</where>
ORDER BY id DESC
</select>
</mapper>

View File

@@ -59,8 +59,10 @@
<if test="code != null and code != ''">and code like concat('%', #{code}, '%')</if>
<if test="grade != null and grade != ''">and grade = #{grade}</if>
<if test="status != null and status != ''">and status = #{status}</if>
<if test="tech != null and tech != ''">and tech = #{tech}</if>
<if test="outDate != null "> and out_date = #{outDate}</if>
<if test="tech != null and tech != ''">
AND tech LIKE CONCAT('%', #{tech}, '%')
</if>
<if test="outDate != null ">and out_date = #{outDate}</if>
<if test="params.beginFreezeDate != null and params.endFreezeDate != null">
and freeze_date between #{params.beginFreezeDate} and #{params.endFreezeDate}
</if>
@@ -164,23 +166,26 @@
</delete>
<select id="selectFlushByEwe" resultType="map">
SELECT grade_a gradeA,
grade_b gradeB,
grade_c gradeC,
grade_d gradeD,
cell_2_4 cell24,
cell_8 cell8,
donor_male_no ramId
SELECT grade_a gradeA,
grade_b gradeB,
grade_c gradeC,
grade_d gradeD,
cell_2_4 cell24,
cell_8 cell8,
donor_male_no ramId
FROM sc_embryo_flush
WHERE donor_female_no = #{eweNo}
ORDER BY flush_time DESC
LIMIT 1
ORDER BY flush_time DESC LIMIT 1
</select>
<update id="updateDiscard" parameterType="DdFe">
UPDATE dd_fe
SET status = #{status},
SET status = #{status},
discard_txt = #{discardTxt}
WHERE id = #{id}
</update>
<select id="existsByCode" resultType="int">
SELECT COUNT(*) FROM dd_fe WHERE code = #{code}
</select>
</mapper>