ProductMapper.xml 4.97 KB
Newer Older
licc's avatar
licc committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
<?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="cn.wisenergy.mapper.ProductMapper">
    <resultMap id="productMap" type="cn.wisenergy.model.app.ProductInfo">
        <id column="id" property="id"/>
        <result column="batch_number" property="batchNumber"/>
        <result column="brand" property="brand"/>
        <result column="specification" property="specification"/>
        <result column="brand_name" property="brandName"/>
        <result column="product_country" property="productCountry"/>
        <result column="valid_time" property="validTime"/>
        <result column="company_name" property="companyName"/>
        <result column="company_address" property="companyAddress"/>
        <result column="company_url" property="companyUrl"/>
        <result column="tracking_number" property="trackingNumber"/>
        <result column="logistics_url" property="logisticsUrl"/>
        <result column="record_number" property="recordNumber"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="table">
        product_info
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
        batch_number,brand,specification,brand_name,product_country, valid_time, company_name,company_address,
        company_url,tracking_number, logistics_url,record_number, create_time,update_time
    </sql>

    <sql id="vals">
        #{batchNumber},#{brand}, #{specification},#{brandName},#{productCountry}, #{validTime},#{companyName},
        #{companyAddress},#{companyUrl},#{trackingNumber},#{logisticsUrl}, #{recordNumber},now(),now()
    </sql>

    <sql id="createsVal">
        #{i.batchNumber},#{i.brand},#{i.specification},#{i.brandName},#{i.productCountry},
        #{i.validTime},#{i.companyName},
        #{i.companyAddress}, #{i.companyUrl},#{i.trackingNumber},#{i.logisticsUrl}, #{i.recordNumber},now(),now()
    </sql>

    <sql id="updateCondition">
        <if test="batchNumber != null">batch_number = #{batchNumber},</if>
        <if test="brand != null">brand = #{brand},</if>
        <if test="specification != null">specification = #{specification},</if>
        <if test="brandName != null">brand_name = #{brandName},</if>
        <if test="productCountry != null">product_country = #{productCountry},</if>
        <if test="validTime != null">valid_time = #{validTime},</if>
        <if test="companyName != null">company_name = #{companyName},</if>
        <if test="companyAddress != null">company_address = #{companyAddress},</if>
        <if test="companyUrl != null">company_url = #{companyUrl},</if>
        <if test="trackingNumber != null">tracking_number = #{trackingNumber},</if>
        <if test="logisticsUrl != null">logistics_url = #{logisticsUrl},</if>
        <if test="recordNumber != null">record_number = #{recordNumber},</if>
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="batchNumber != null">and batch_number = #{batchNumber}</if>
        <if test="brand != null">and brand = #{brand}</if>
        <if test="specification != null">and specification = #{specification}</if>
        <if test="brandName != null">and brand_name = #{brandName}</if>
        <if test="productCountry != null">and product_country = #{productCountry}</if>
        <if test="validTime != null">and valid_time = #{validTime}</if>
        <if test="companyName != null">and company_name = #{companyName}</if>
        <if test="companyAddress != null">and company_address = #{companyAddress}</if>
        <if test="companyUrl != null">and company_url = #{companyUrl}</if>
        <if test="trackingNumber != null">and tracking_number = #{trackingNumber}</if>
        <if test="logisticsUrl != null">and logistics_url = #{logisticsUrl}</if>
        <if test="recordNumber != null">and record_number = #{recordNumber}</if>
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
    </sql>

    <insert id="add" parameterType="cn.wisenergy.model.app.ProductInfo" keyProperty="id" useGeneratedKeys="true">
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>

    <update id="edit" parameterType="cn.wisenergy.model.app.ProductInfo">
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
        <where>
            id = #{id}
        </where>
    </update>

    <select id="getByBatchNumber" resultMap="productMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            batch_number=#{batchNumber}
        </where>
    </select>


</mapper>