<?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.ruoyi.basicData.mapper.TGoodsMapper">

    <resultMap type="TGoods" id="TGoodsResult">
        <result property="fId"    column="f_id"    />
        <result property="fTypeid"    column="f_typeid"    />
        <result property="fNo"    column="f_no"    />
        <result property="fName"    column="f_name"    />
        <result property="fEnam"    column="f_enam"    />
        <result property="fSpecs"    column="f_specs"    />
        <result property="fPackagespecs"    column="f_packagespecs"    />
        <result property="fColor"    column="f_color"    />
        <result property="fHscode"    column="f_hscode"    />
        <result property="fPackageid"    column="f_packageid"    />
        <result property="fEmsNo"    column="f_ems_no"    />
        <result property="fEmsSeqNo"    column="f_ems_seq_no"    />
        <result property="fGoodsTs"    column="f_goods_ts"    />
        <result property="fWmsDclUnit"    column="f_wms_dcl_unit"    />
        <result property="fWmsLawUnit"    column="f_wms_law_unit"    />
        <result property="ifCntrno"    column="if_cntrno"    />
        <result property="fStatus"    column="f_status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTGoodsVo">
        select f_id, f_typeid, f_no, f_name, f_enam, f_specs, f_packagespecs, f_color, f_hscode, f_packageid, f_ems_no, f_ems_seq_no, f_goods_ts, f_wms_dcl_unit, f_wms_law_unit, if_cntrno, f_status, del_flag, create_by, create_time, update_by, update_time, remark from t_goods
    </sql>

    <select id="selectTGoodsList" parameterType="TGoods" resultMap="TGoodsResult">
        <include refid="selectTGoodsVo"/>
        <where>
            <if test="fTypeid != null  and fTypeid != ''">and f_typeid = #{fTypeid}</if>
            <if test="ifCntrno != null  and ifCntrno != ''">and if_cntrno = #{ifCntrno}</if>
            <if test="fNo != null  and fNo != ''">and f_no like concat('%', #{fNo}, '%')</if>
            <if test="fName != null  and fName != ''">and f_name like concat('%', #{fName}, '%')</if>
            <if test="fEnam != null  and fEnam != ''">and f_enam like concat('%', #{fEnam}, '%')</if>
            <if test="fSpecs != null  and fSpecs != ''">and f_specs like concat('%', #{fSpecs}, '%')</if>
            <if test="fPackagespecs != null ">and f_packagespecs like concat('%', #{fPackagespecs}, '%')</if>
            <if test="fColor != null  and fColor != ''">and f_color like concat('%', #{fColor}, '%')</if>
            <if test="fHscode != null  and fHscode != ''">and f_hscode like concat('%', #{fHscode}, '%')</if>
            <if test="fPackageid != null ">and f_packageid = #{fPackageid}</if>
            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
        </where>
    </select>

    <select id="selectTGoodsById" parameterType="Long" resultMap="TGoodsResult">
        <include refid="selectTGoodsVo"/>
        where f_id = #{fId}
    </select>

    <insert id="insertTGoods" parameterType="TGoods" useGeneratedKeys="true" keyProperty="fId">
        insert into t_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fTypeid != null">f_typeid,</if>
            <if test="fNo != null and fNo != ''">f_no,</if>
            <if test="fName != null and fName != ''">f_name,</if>
            <if test="fEnam != null and fEnam != ''">f_enam,</if>
            <if test="fSpecs != null and fSpecs != ''">f_specs,</if>
            <if test="fPackagespecs != null">f_packagespecs,</if>
            <if test="fColor != null">f_color,</if>
            <if test="fHscode != null">f_hscode,</if>
            <if test="fPackageid != null">f_packageid,</if>
            <if test="fEmsNo != null">f_ems_no,</if>
            <if test="fEmsSeqNo != null">f_ems_seq_no,</if>
            <if test="fGoodsTs != null">f_goods_ts,</if>
            <if test="fWmsDclUnit != null">f_wms_dcl_unit,</if>
            <if test="fWmsLawUnit != null">f_wms_law_unit,</if>
            <if test="ifCntrno != null">if_cntrno,</if>
            <if test="fStatus != null">f_status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fTypeid != null">#{fTypeid},</if>
            <if test="fNo != null and fNo != ''">#{fNo},</if>
            <if test="fName != null and fName != ''">#{fName},</if>
            <if test="fEnam != null and fEnam != ''">#{fEnam},</if>
            <if test="fSpecs != null and fSpecs != ''">#{fSpecs},</if>
            <if test="fPackagespecs != null">#{fPackagespecs},</if>
            <if test="fColor != null">#{fColor},</if>
            <if test="fHscode != null">#{fHscode},</if>
            <if test="fPackageid != null">#{fPackageid},</if>
            <if test="fEmsNo != null">#{fEmsNo},</if>
            <if test="fEmsSeqNo != null">#{fEmsSeqNo},</if>
            <if test="fGoodsTs != null">#{fGoodsTs},</if>
            <if test="fWmsDclUnit != null">#{fWmsDclUnit},</if>
            <if test="fWmsLawUnit != null">#{fWmsLawUnit},</if>
            <if test="ifCntrno != null">#{ifCntrno},</if>
            <if test="fStatus != null">#{fStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTGoods" parameterType="TGoods">
        update t_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="fTypeid != null">f_typeid = #{fTypeid},</if>
            <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
            <if test="fName != null and fName != ''">f_name = #{fName},</if>
            <if test="fEnam != null and fEnam != ''">f_enam = #{fEnam},</if>
            <if test="fSpecs != null and fSpecs != ''">f_specs = #{fSpecs},</if>
            <if test="fPackagespecs != null">f_packagespecs = #{fPackagespecs},</if>
            <if test="fColor != null">f_color = #{fColor},</if>
            <if test="fHscode != null">f_hscode = #{fHscode},</if>
            <if test="fPackageid != null">f_packageid = #{fPackageid},</if>
            <if test="fEmsNo != null">f_ems_no = #{fEmsNo},</if>
            <if test="fEmsSeqNo != null">f_ems_seq_no = #{fEmsSeqNo},</if>
            <if test="fGoodsTs != null">f_goods_ts = #{fGoodsTs},</if>
            <if test="fWmsDclUnit != null">f_wms_dcl_unit = #{fWmsDclUnit},</if>
            <if test="fWmsLawUnit != null">f_wms_law_unit = #{fWmsLawUnit},</if>
            <if test="ifCntrno != null">if_cntrno = #{ifCntrno},</if>
            <if test="fStatus != null">f_status = #{fStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteTGoodsById" parameterType="Long">
        delete from t_goods where f_id = #{fId}
    </delete>

    <delete id="deleteTGoodsByIds" parameterType="String">
        delete from t_goods where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>

    <select id="checkFNoUnique" parameterType="String" resultMap="TGoodsResult">
	    select f_id,f_no from t_goods where f_no = #{fNo} limit 1
    </select>

    <select id="checkUFNnameUnique" parameterType="String" resultMap="TGoodsResult">
        select f_id,f_name from t_goods where f_name = #{fAame} limit 1
    </select>
    <select id="getGoodName" parameterType="string" resultType="map">
        SELECT
	        t.f_id fId,
	        t.f_name fName,
	        pro.dict_label typeName
        FROM
	    t_goods t
	    LEFT JOIN sys_dict_data pro ON pro.dict_value = t.f_typeid and pro.dict_type = 'data_goods_category'
	    WHERE t.f_status = '0'
    </select>

    <select id="selectByIds" resultMap="TGoodsResult">
        SELECT f_id, f_typeid, f_no, f_name
        FROM
            t_goods
        where
            f_id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="getGoodsByNo" parameterType="String" resultMap="TGoodsResult">
        <include refid="selectTGoodsVo"/>
        where f_no = #{fNo} limit 1
    </select>

</mapper>