多耳号查询与模糊查询

This commit is contained in:
ll
2026-01-19 20:42:27 +08:00
parent aa9496c27e
commit b911a29167
12 changed files with 188 additions and 63 deletions

View File

@@ -19,14 +19,13 @@
SELECT
mpc.id,
mpc.datetime,
v.bs_manage_tags, <!-- 取消别名,使用原列名 -->
v.bs_manage_tags,
v.electronic_tags,
v.parity,
v.dr_ranch,
mpc.classes,
mpc.milk,
mpc.corrected_milk AS corrected_milk
<!-- 修改为与 resultMap 对应的列名 -->
FROM np_milk_prod_classes mpc
JOIN sheep_file v ON mpc.sheep_id = v.id
LEFT JOIN xz_wegih_correction wc ON DATE(mpc.datetime) = DATE(wc.datetime) AND v.dr_ranch = wc.factory
@@ -39,19 +38,34 @@
<if test="datetimeEnd != null">
AND mpc.datetime &lt;= #{datetimeEnd}
</if>
<if test="manageEarNo != null and manageEarNo != ''">
AND v.bs_manage_tags LIKE CONCAT('%', #{manageEarNo}, '%')
<if test="npMilkProdClasses.allEarNumbers != null and npMilkProdClasses.allEarNumbers.size() > 0">
AND (
v.bs_manage_tags IN
<foreach collection="npMilkProdClasses.allEarNumbers" item="earNumber" open="(" separator="," close=")">
#{earNumber}
</foreach>
)
</if>
<if test="factory != null and factory != ''">
AND v.dr_ranch = #{factory}
<if test="npMilkProdClasses.factory != null and npMilkProdClasses.factory != ''">
AND v.dr_ranch = #{npMilkProdClasses.factory}
</if>
<if test="classes != null">
AND mpc.classes = #{classes}
<if test="npMilkProdClasses.classes != null">
AND mpc.classes = #{npMilkProdClasses.classes}
</if>
</where>
</select>
<!-- 称重矫正系数 -->
<select id="searchEarNumbers" resultType="java.lang.String">
SELECT DISTINCT sf.bs_manage_tags
FROM sheep_file sf
WHERE sf.bs_manage_tags LIKE CONCAT(#{query}, '%')
AND sf.is_delete = 0
ORDER BY sf.bs_manage_tags
LIMIT 50
</select>
<select id="getWeightCorrection" resultType="java.lang.Double">
SELECT actual / system_milk
FROM xz_wegih_correction
@@ -60,7 +74,6 @@
AND system_milk > 0
</select>
<!-- 胎次矫正系数 -->
<select id="getParityCorrection" resultType="java.lang.Double">
SELECT
CASE
@@ -72,7 +85,6 @@
WHERE parity = #{parity}
</select>
<!-- 干物质矫正系数 -->
<select id="getDryMatterCorrection" resultType="java.lang.Double">
SELECT coefficient
FROM xz_dry_matter_correction
@@ -90,4 +102,4 @@
FROM sheep_file
WHERE bs_manage_tags = #{manageEarNo}
</select>
</mapper>
</mapper>

View File

@@ -4,8 +4,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhyc.module.dairyProducts.mapper.NpSheepMilkAnalysisMapper">
<!-- 1) 获取distinct sheep_id支持按sheep_file.bs_manage_tags模糊搜索 -->
<select id="selectDistinctSheepIds" resultType="string" parameterType="map">
<select id="selectDistinctSheepIds" resultType="string" parameterType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis">
SELECT DISTINCT a.sheep_id
FROM np_milk_prod_classes a
LEFT JOIN sheep_file sf ON a.sheep_id = sf.id
@@ -13,12 +12,27 @@
<if test="manageEarTag != null and manageEarTag != ''">
AND sf.bs_manage_tags LIKE CONCAT('%', #{manageEarTag}, '%')
</if>
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
AND (
sf.bs_manage_tags IN
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
#{earNumber}
</foreach>
)
</if>
</where>
ORDER BY a.sheep_id
</select>
<!-- 2) 获取某只羊的所有班次记录(按班次日期升序) -->
<!-- 假设表中字段class_date, system_milk, corrected_milk, parity -->
<select id="searchEarNumbers" resultType="java.lang.String">
SELECT DISTINCT sf.bs_manage_tags
FROM sheep_file sf
WHERE sf.bs_manage_tags LIKE CONCAT(#{query}, '%')
AND sf.is_delete = 0
ORDER BY sf.bs_manage_tags
LIMIT 50
</select>
<select id="selectMilkRecordsBySheepId" resultType="map" parameterType="string">
SELECT
datetime AS classDate,
@@ -30,8 +44,6 @@
ORDER BY datetime ASC
</select>
<!-- 3) 获取该羊在sheep_file视图中的基础信息 -->
<!-- 假设字段名称bs_manage_tags、variety、lactation_day、name、birthday、parity、month_age、current_weight、breed、father_manage_tags、mother_manage_tags、dr_ranch、family -->
<select id="selectSheepFileBySheepId" resultType="map" parameterType="string">
SELECT
id AS sheep_id,
@@ -52,27 +64,30 @@
WHERE id = #{sheepId}
</select>
<!-- 4) 兼容旧list查询返回domain对象列表但在我们的实现中service会构造最终的NpSheepMilkAnalysis列表 -->
<select id="selectNpSheepMilkAnalysisList" resultType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis" parameterType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis">
<!-- 如果你仍需基于某张表的简单映射可在此实现当前我们在ServiceImpl中组装对象所以该查询不做复杂实现 -->
SELECT 1 FROM dual WHERE 1=0
</select>
<!-- 5) 导出奶产量分析记录 -->
<select id="selectNpSheepMilkAnalysisForExport" resultType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis" parameterType="com.zhyc.module.dairyProducts.domain.NpSheepMilkAnalysis">
<!-- 这里需要根据实际表结构编写SQL查询 -->
<!-- 示例SQL需要根据实际表结构调整 -->
SELECT
sf.id as sheepId,
sf.bs_manage_tags as manageEarTag,
sf.variety,
<!-- 其他字段 -->
m.datetime as milkingStartTime
FROM sheep_file sf
LEFT JOIN np_milk_prod_classes m ON sf.id = m.sheep_id
<where>
<if test="manageEarTag != null and manageEarTag != ''">
AND sf.bs_manage_tags LIKE CONCAT('%', #{manageEarTag}, '%')
</if>
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
AND (
sf.bs_manage_tags IN
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
#{earNumber}
</foreach>
)
</if>
</where>
GROUP BY sf.id
</select>