Merge remote-tracking branch 'origin/main'

This commit is contained in:
达富斌
2025-09-15 11:16:49 +08:00
2 changed files with 151 additions and 41 deletions

View File

@@ -9,4 +9,101 @@
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
-->
<!-- 根据CodeOutBatch分组查询,获取每个批次的最新记录 -->
<select id="selectLatestByCodeOutBatch" resultType="cn.iocoder.yudao.module.farm.dal.dataobject.traceabilitycode.TraceabilityCodeDO">
SELECT t1.* FROM farm_traceability_code t1
INNER JOIN (
SELECT code_out_batch, MAX(create_time) as max_create_time
FROM farm_traceability_code
WHERE 1=1
<if test="tenantId != null">
AND tenant_id = #{tenantId}
</if>
<if test="speciesCode != null">
AND species_code = #{speciesCode}
</if>
<if test="speciesName != null and speciesName != ''">
AND species_name LIKE CONCAT('%', #{speciesName}, '%')
</if>
<if test="baseId != null">
AND base_id = #{baseId}
</if>
<if test="baseName != null and baseName != ''">
AND base_name LIKE CONCAT('%', #{baseName}, '%')
</if>
<if test="plotId != null">
AND plot_id = #{plotId}
</if>
<if test="plotName != null and plotName != ''">
AND plot_name LIKE CONCAT('%', #{plotName}, '%')
</if>
<if test="harvestDateStart != null">
AND harvest_date &gt;= #{harvestDateStart}
</if>
<if test="harvestDateEnd != null">
AND harvest_date &lt;= #{harvestDateEnd}
</if>
<if test="farmingInputCount != null">
AND farming_input_count = #{farmingInputCount}
</if>
<if test="productId != null">
AND product_id = #{productId}
</if>
<if test="productName != null and productName != ''">
AND product_name LIKE CONCAT('%', #{productName}, '%')
</if>
<if test="codeOutBatch != null and codeOutBatch != ''">
AND code_out_batch = #{codeOutBatch}
</if>
<if test="status != null">
AND status = #{status}
</if>
GROUP BY code_out_batch
) t2 ON t1.code_out_batch = t2.code_out_batch AND t1.create_time = t2.max_create_time
WHERE 1=1
<if test="tenantId != null">
AND t1.tenant_id = #{tenantId}
</if>
<if test="speciesCode != null">
AND t1.species_code = #{speciesCode}
</if>
<if test="speciesName != null and speciesName != ''">
AND t1.species_name LIKE CONCAT('%', #{speciesName}, '%')
</if>
<if test="baseId != null">
AND t1.base_id = #{baseId}
</if>
<if test="baseName != null and baseName != ''">
AND t1.base_name LIKE CONCAT('%', #{baseName}, '%')
</if>
<if test="plotId != null">
AND t1.plot_id = #{plotId}
</if>
<if test="plotName != null and plotName != ''">
AND t1.plot_name LIKE CONCAT('%', #{plotName}, '%')
</if>
<if test="harvestDateStart != null">
AND t1.harvest_date &gt;= #{harvestDateStart}
</if>
<if test="harvestDateEnd != null">
AND t1.harvest_date &lt;= #{harvestDateEnd}
</if>
<if test="farmingInputCount != null">
AND t1.farming_input_count = #{farmingInputCount}
</if>
<if test="productId != null">
AND t1.product_id = #{productId}
</if>
<if test="productName != null and productName != ''">
AND t1.product_name LIKE CONCAT('%', #{productName}, '%')
</if>
<if test="codeOutBatch != null and codeOutBatch != ''">
AND t1.code_out_batch = #{codeOutBatch}
</if>
<if test="status != null">
AND t1.status = #{status}
</if>
ORDER BY t1.create_time DESC
</select>
</mapper>