120 lines
5.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.zhyc.module.produce.manage_sheep.mapper.ScChangeEarMapper">
<resultMap type="com.zhyc.module.produce.manage_sheep.domain.ScChangeEar" id="ScChangeEarResult">
<result property="id" column="sce_id"/>
<result property="sheepId" column="sheep_id"/>
<result property="manageTags" column="manage_tags"/>
<result property="sheepfoldName" column="sheepfold_name"/>
<result property="eventType" column="event_type"/>
<result property="earType" column="ear_type"/>
<result property="newTag" column="newTag"/>
<result property="oldTag" column="oldTag"/>
<result property="comment" column="comment"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
</resultMap>
<sql id="selectScChangeEarVo">
select sce.id as sce_id,
sce.sheep_id,
bs.manage_tags as manage_tags,
sf.sheepfold_name as sheepfold_name,
case
when sce.ear_type = 0 then '改电子耳号'
when sce.ear_type = 1 then '改管理耳号'
else ''
end as event_type,
sce.ear_type,
sce.newTag,
sce.oldTag as oldTag,
sce.comment,
sce.create_by,
sce.create_time
from sc_change_ear sce
LEFT JOIN bas_sheep bs ON sce.sheep_id = bs.id
LEFT JOIN da_sheepfold sf ON bs.sheepfold_id = sf.id
</sql>
<select id="selectScChangeEarList" parameterType="ScChangeEar" resultMap="ScChangeEarResult">
<include refid="selectScChangeEarVo"/>
<where>
<if test="sheepId != null">and sce.sheep_id = #{sheepId}</if>
<if test="manageTags != null and manageTags != ''">
and bs.manage_tags LIKE CONCAT('%', #{manageTags}, '%')
</if>
<if test="sheepfoldId != null">and bs.sheepfold_id = #{sheepfoldId}</if>
<if test="sheepfoldName != null and sheepfoldName != ''">
and sf.sheepfold_name LIKE CONCAT('%', #{sheepfoldName}, '%')
</if>
<if test="earType != null ">and sce.ear_type = #{earType}</if>
<if test="newTag != null and newTag != ''">
and sce.newTag LIKE CONCAT('%', #{newTag}, '%')
</if>
<if test="oldTag != null and oldTag != ''">
and sce.oldTag LIKE CONCAT('%', #{oldTag}, '%')
</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''">
and sce.create_time between #{params.beginCreateTime} and #{params.endCreateTime}
</if>
</where>
ORDER BY sce.create_time DESC
</select>
<select id="selectScChangeEarById" parameterType="Integer" resultMap="ScChangeEarResult">
<include refid="selectScChangeEarVo"/>
where sce.id = #{id}
</select>
<insert id="insertScChangeEar" parameterType="ScChangeEar" useGeneratedKeys="true" keyProperty="id">
insert into sc_change_ear
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="sheepId != null">sheep_id,</if>
<if test="earType != null">ear_type,</if>
<if test="newTag != null and newTag != ''">newTag,</if>
<if test="oldTag != null and oldTag != ''">oldTag,</if>
<if test="comment != null">comment,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="sheepId != null">#{sheepId},</if>
<if test="earType != null">#{earType},</if>
<if test="newTag != null and newTag != ''">#{newTag},</if>
<if test="oldTag != null and oldTag != ''">#{oldTag},</if>
<if test="comment != null">#{comment},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateScChangeEar" parameterType="ScChangeEar">
update sc_change_ear
<trim prefix="SET" suffixOverrides=",">
<if test="sheepId != null">sheep_id = #{sheepId},</if>
<if test="earType != null">ear_type = #{earType},</if>
<if test="newTag != null and newTag != ''">newTag = #{newTag},</if>
<if test="oldTag != null and oldTag != ''">oldTag = #{oldTag},</if>
<if test="comment != null">comment = #{comment},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteScChangeEarById" parameterType="Integer">
delete
from sc_change_ear
where id = #{id}
</delete>
<delete id="deleteScChangeEarByIds" parameterType="String">
delete from sc_change_ear where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>