<?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.MppProductMapper">
    
    <resultMap type="MppProduct" id="MppProductResult">
        <result property="productId"    column="productId"    />
        <result property="productName"    column="productName"    />
        <result property="productCode"    column="productCode"    />
        <result property="productRemark"    column="productRemark"    />
    </resultMap>

    <sql id="selectMppProductVo">
        select productId, productName, productCode, productRemark from MppProduct
    </sql>
    <sql id="selectMppProductNewVo">
        select dictId productId, dictName productName, dictValue productCode, dicttypeCode, dictRemark productRemark
        from SysDict
    </sql>


    <select id="selectMppProductList" parameterType="MppProduct" resultMap="MppProductResult">
        <include refid="selectMppProductNewVo"/>
        where dicttypeCode = 'agm_mpp_product'
        <if test="productName != null  and productName != ''"> and dictName like concat('%', #{productName}, '%')</if>
        <if test="productNameEq != null  and productNameEq != ''"> and dictName = #{productNameEq}</if>
        <if test="productCode != null  and productCode != ''"> and dictValue = #{productCode}</if>
        order by dictSeq desc
    </select>


    <select id="selectMppProductByProductId" parameterType="String" resultMap="MppProductResult">
        <include refid="selectMppProductNewVo"/>
        where dictId = #{productId}
    </select>


    <insert id="insertMppProduct" parameterType="MppProduct">
        insert into SysDict(
        <if test="productId != null and productId != ''">dictId,</if>
        <if test="dictSeq != null">dictSeq,</if>
        <if test="productName != null and productName != ''">dictName,</if>
        <if test="productCode != null and productCode != ''">dictValue,</if>
        dicttypeCode,
        dictAvlstatus,
        <if test="productRemark != null and productRemark != ''">dictRemark,</if>
        <if test="dictCreator != null and dictCreator != ''">dictCreator,</if>
        dictCreateddate
        )values(
        <if test="productId != null and productId != ''">#{productId},</if>
        <if test="dictSeq != null">#{dictSeq},</if>
        <if test="productName != null and productName != ''">#{productName},</if>
        <if test="productCode != null and productCode != ''">#{productCode},</if>
        'agm_mpp_product',
        '0',
        <if test="productRemark != null and productRemark != ''">#{productRemark},</if>
        <if test="dictCreator != null and dictCreator != ''">#{dictCreator},</if>
        date_format(sysdate(),'%Y-%m-%d %H:%i:%s')
        )
    </insert>


    <update id="updateMppProduct" parameterType="MppProduct">
        update SysDict
        <trim prefix="SET" suffixOverrides=",">
            <if test="productName != null">dictName = #{productName},</if>
        </trim>
        where dictId = #{productId}
    </update>


    <delete id="deleteMppProductByProductIds" parameterType="String">
        delete from SysDict where dictId in
        <foreach item="productId" collection="array" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </delete>
</mapper>