<?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.yunfeiyun.agmp.fms.mapper.TssSourceinfoMapper">

    <resultMap type="TssSourceinfo" id="TssSourceinfoResult">
        <result property="sourceinfoId" column="sourceinfoId"/>
        <result property="sourceinfoName" column="sourceinfoName"/>
        <result property="sourceinfoCode" column="sourceinfoCode"/>
        <result property="sourceinfoQualitystatus" column="sourceinfoQualitystatus"/>
        <result property="sourceinfoQualityremark" column="sourceinfoQualityremark"/>
        <result property="sourceinfoGrowstatus" column="sourceinfoGrowstatus"/>
        <result property="sourceinfoFiguretatus" column="sourceinfoFiguretatus"/>
        <result property="sourceinfoCreator" column="sourceinfoCreator"/>
        <result property="sourceinfoCreateddate" column="sourceinfoCreateddate"/>
        <result property="sourceinfoModifier" column="sourceinfoModifier"/>
        <result property="sourceinfoModifieddate" column="sourceinfoModifieddate"/>
    </resultMap>

    <sql id="selectTssSourceinfoVo">
        select sourceinfoId, sourceinfoName, sourceinfoCode, sourceinfoQualitystatus, sourceinfoQualityremark,
        sourceinfoGrowstatus, sourceinfoFiguretatus, sourceinfoCreator, sourceinfoCreateddate, sourceinfoModifier,
        sourceinfoModifieddate from TssSourceinfo
    </sql>

    <select id="selectTssSourceinfoList" parameterType="TssSourceinfo" resultType="TssSourceinfoListResVo">
        select s.sourceinfoId, s.sourceinfoName, s.sourceinfoCode, s.sourceinfoQualitystatus, s.sourceinfoQualityremark,
        s.sourceinfoGrowstatus,
        s.sourceinfoFiguretatus, s.sourceinfoCreator, s.sourceinfoCreateddate, s.sourceinfoModifier,
        s.sourceinfoModifieddate,
        (select GROUP_CONCAT(resUrl) from SysRes r where r.resBusId = s.sourceinfoId and r.resBiztype =
        'SOURCE_INFO_AVATAR') avatarPreview
        from TssSourceinfo s

        <where>
            <if test="sourceinfoName != null  and sourceinfoName != ''">and sourceinfoName like concat('%',
                #{sourceinfoName}, '%')
            </if>
            <if test="sourceinfoCode != null  and sourceinfoCode != ''">and sourceinfoCode = #{sourceinfoCode}</if>
            <if test="sourceinfoQualitystatus != null  and sourceinfoQualitystatus != ''">and sourceinfoQualitystatus =
                #{sourceinfoQualitystatus}
            </if>
            <if test="sourceinfoQualityremark != null  and sourceinfoQualityremark != ''">and sourceinfoQualityremark =
                #{sourceinfoQualityremark}
            </if>
            <if test="sourceinfoGrowstatus != null  and sourceinfoGrowstatus != ''">and sourceinfoGrowstatus =
                #{sourceinfoGrowstatus}
            </if>
            <if test="sourceinfoFiguretatus != null  and sourceinfoFiguretatus != ''">and sourceinfoFiguretatus =
                #{sourceinfoFiguretatus}
            </if>
            <if test="sourceinfoCreator != null  and sourceinfoCreator != ''">and sourceinfoCreator =
                #{sourceinfoCreator}
            </if>
            <if test="sourceinfoCreateddate != null  and sourceinfoCreateddate != ''">and sourceinfoCreateddate =
                #{sourceinfoCreateddate}
            </if>
            <if test="sourceinfoModifier != null  and sourceinfoModifier != ''">and sourceinfoModifier =
                #{sourceinfoModifier}
            </if>
            <if test="sourceinfoModifieddate != null  and sourceinfoModifieddate != ''">and sourceinfoModifieddate =
                #{sourceinfoModifieddate}
            </if>
        </where>

        order by s.sourceinfoCreateddate desc
    </select>

    <select id="selectTssSourceinfoBySourceinfoId" parameterType="String" resultMap="TssSourceinfoResult">
        <include refid="selectTssSourceinfoVo"/>
        where sourceinfoId = #{sourceinfoId}
    </select>

    <select id="selectTssSourceinfoByTarcecodeapplyno" parameterType="String" resultMap="TssSourceinfoResult">
        select
        ts.sourceinfoId,
        ts.sourceinfoName,
        ts.sourceinfoCode,
        ts.sourceinfoQualitystatus,
        ts.sourceinfoQualityremark,
        ts.sourceinfoGrowstatus,
        ts.sourceinfoFiguretatus,
        ts.sourceinfoCreator,
        ts.sourceinfoCreateddate,
        ts.sourceinfoModifier,
        ts.sourceinfoModifieddate
        from
        TssSourceinfo ts
        LEFT JOIN WmsFinishgoods wfg on wfg.sourceinfoId = ts.sourceinfoId
        LEFT JOIN WmsStock ws on ws.goodsId = wfg.goodsId
        LEFT JOIN TssTracecodeapply ttc on ttc.stockId = ws.stockId
        where ttc.tarcecodeapplyno = #{tarcecodeapplyno}
    </select>

    <insert id="insertTssSourceinfo" parameterType="TssSourceinfo">
        insert into TssSourceinfo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sourceinfoId != null">sourceinfoId,</if>
            <if test="sourceinfoName != null">sourceinfoName,</if>
            <if test="sourceinfoCode != null">sourceinfoCode,</if>
            <if test="sourceinfoQualitystatus != null">sourceinfoQualitystatus,</if>
            <if test="sourceinfoQualityremark != null">sourceinfoQualityremark,</if>
            <if test="sourceinfoGrowstatus != null">sourceinfoGrowstatus,</if>
            <if test="sourceinfoFiguretatus != null">sourceinfoFiguretatus,</if>
            <if test="sourceinfoCreator != null">sourceinfoCreator,</if>
            <if test="sourceinfoCreateddate != null">sourceinfoCreateddate,</if>
            <if test="sourceinfoModifier != null">sourceinfoModifier,</if>
            <if test="sourceinfoModifieddate != null">sourceinfoModifieddate,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sourceinfoId != null">#{sourceinfoId},</if>
            <if test="sourceinfoName != null">#{sourceinfoName},</if>
            <if test="sourceinfoCode != null">#{sourceinfoCode},</if>
            <if test="sourceinfoQualitystatus != null">#{sourceinfoQualitystatus},</if>
            <if test="sourceinfoQualityremark != null">#{sourceinfoQualityremark},</if>
            <if test="sourceinfoGrowstatus != null">#{sourceinfoGrowstatus},</if>
            <if test="sourceinfoFiguretatus != null">#{sourceinfoFiguretatus},</if>
            <if test="sourceinfoCreator != null">#{sourceinfoCreator},</if>
            <if test="sourceinfoCreateddate != null">#{sourceinfoCreateddate},</if>
            <if test="sourceinfoModifier != null">#{sourceinfoModifier},</if>
            <if test="sourceinfoModifieddate != null">#{sourceinfoModifieddate},</if>
        </trim>
    </insert>

    <update id="updateTssSourceinfo" parameterType="TssSourceinfo">
        update TssSourceinfo
        <trim prefix="SET" suffixOverrides=",">
            <if test="sourceinfoName != null">sourceinfoName = #{sourceinfoName},</if>
            <if test="sourceinfoCode != null">sourceinfoCode = #{sourceinfoCode},</if>
            <if test="sourceinfoQualitystatus != null">sourceinfoQualitystatus = #{sourceinfoQualitystatus},</if>
            <if test="sourceinfoQualityremark != null">sourceinfoQualityremark = #{sourceinfoQualityremark},</if>
            <if test="sourceinfoGrowstatus != null">sourceinfoGrowstatus = #{sourceinfoGrowstatus},</if>
            <if test="sourceinfoFiguretatus != null">sourceinfoFiguretatus = #{sourceinfoFiguretatus},</if>
            <if test="sourceinfoCreator != null">sourceinfoCreator = #{sourceinfoCreator},</if>
            <if test="sourceinfoCreateddate != null">sourceinfoCreateddate = #{sourceinfoCreateddate},</if>
            <if test="sourceinfoModifier != null">sourceinfoModifier = #{sourceinfoModifier},</if>
            <if test="sourceinfoModifieddate != null">sourceinfoModifieddate = #{sourceinfoModifieddate},</if>
        </trim>
        where sourceinfoId = #{sourceinfoId}
    </update>

    <delete id="deleteTssSourceinfoBySourceinfoId" parameterType="String">
        delete from TssSourceinfo where sourceinfoId = #{sourceinfoId}
    </delete>

    <delete id="deleteTssSourceinfoBySourceinfoIds" parameterType="String">
        delete from TssSourceinfo where sourceinfoId in
        <foreach item="sourceinfoId" collection="array" open="(" separator="," close=")">
            #{sourceinfoId}
        </foreach>
    </delete>
</mapper>