GoodsMapper.xml 6.87 KB
Newer Older
张新旗 committed
1 2 3 4
<?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">
5
<mapper namespace="com.soss.system.mapper.GoodsMapper">
张新旗 committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    
    <resultMap type="Goods" id="GoodsResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="category"    column="category"    />
        <result property="price"    column="price"    />
        <result property="discount"    column="discount"    />
        <result property="takeTime"    column="take_time"    />
        <result property="spec"    column="spec"    />
        <result property="pics"    column="pics"    />
        <result property="desc"    column="desc"    />
        <result property="remarks"    column="remarks"    />
        <result property="state"    column="state"    />
        <result property="isDeleted"    column="is_deleted"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
        <result property="code"    column="code"    />
张新旗 committed
23
        <result property="shelfAt" column="shelf_at"/>
张新旗 committed
24
        <result property="categoryName" column="categoryName"/>
张新旗 committed
25 26 27
    </resultMap>

    <sql id="selectGoodsVo">
张新旗 committed
28
        select id, name, category, price, discount, take_time, spec, pics, `desc`, remarks, state, is_deleted, created_at, updated_at, code,shelf_at from goods
张新旗 committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    </sql>

    <select id="selectGoodsList" parameterType="Goods" resultMap="GoodsResult">
        <include refid="selectGoodsVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="category != null  and category != ''"> and category = #{category}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="discount != null "> and discount = #{discount}</if>
            <if test="takeTime != null "> and take_time = #{takeTime}</if>
            <if test="spec != null  and spec != ''"> and spec = #{spec}</if>
            <if test="pics != null  and pics != ''"> and pics = #{pics}</if>
            <if test="desc != null  and desc != ''"> and `desc` = #{desc}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
            <if test="isDeleted != null "> and is_deleted = #{isDeleted}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
张新旗 committed
48

张新旗 committed
49
        </where>
张新旗 committed
50
        order by created_at desc
张新旗 committed
51 52 53
    </select>
    
    <select id="selectGoodsById" parameterType="String" resultMap="GoodsResult">
张新旗 committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
        select
        g.id,
        g.name,
        g.category,
        gc.name as categoryName,
        g.price,
        g.discount,
        g.take_time,
        g.spec,
        g.pics,
        g.`desc`,
        g.remarks,
        g.state,
        g.is_deleted,
        g.created_at,
        g.updated_at,
        g.code,
        g.shelf_at
        from
        goods g,goods_category gc
        where g.id = #{id}
        and g.category =gc.id
张新旗 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    </select>
        
    <insert id="insertGoods" parameterType="Goods" useGeneratedKeys="true" keyProperty="id">
        insert into goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="category != null and category != ''">category,</if>
            <if test="price != null">price,</if>
            <if test="discount != null">discount,</if>
            <if test="takeTime != null">take_time,</if>
            <if test="spec != null and spec != ''">spec,</if>
            <if test="pics != null and pics != ''">pics,</if>
            <if test="desc != null">`desc`,</if>
            <if test="remarks != null">remarks,</if>
            <if test="state != null and state != ''">state,</if>
            <if test="isDeleted != null">is_deleted,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="code != null">code,</if>
张新旗 committed
95
            <if test="shelfAt != null">shelf_at,</if>
张新旗 committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="category != null and category != ''">#{category},</if>
            <if test="price != null">#{price},</if>
            <if test="discount != null">#{discount},</if>
            <if test="takeTime != null">#{takeTime},</if>
            <if test="spec != null and spec != ''">#{spec},</if>
            <if test="pics != null and pics != ''">#{pics},</if>
            <if test="desc != null">#{desc},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="state != null and state != ''">#{state},</if>
            <if test="isDeleted != null">#{isDeleted},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="code != null">#{code},</if>
张新旗 committed
112
            <if test="shelfAt != null">#{shelfAt},</if>
张新旗 committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
         </trim>
    </insert>

    <update id="updateGoods" parameterType="Goods">
        update goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="category != null and category != ''">category = #{category},</if>
            <if test="price != null">price = #{price},</if>
            <if test="discount != null">discount = #{discount},</if>
            <if test="takeTime != null">take_time = #{takeTime},</if>
            <if test="spec != null and spec != ''">spec = #{spec},</if>
            <if test="pics != null and pics != ''">pics = #{pics},</if>
            <if test="desc != null">`desc` = #{desc},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="state != null and state != ''">state = #{state},</if>
            <if test="isDeleted != null">is_deleted = #{isDeleted},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="code != null">code = #{code},</if>
张新旗 committed
132
            <if test="shelfAt != null">shelf_at = #{shelfAt},</if>
张新旗 committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGoodsById" parameterType="String">
        delete from goods where id = #{id}
    </delete>

    <delete id="deleteGoodsByIds" parameterType="String">
        delete from goods where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
张新旗 committed
147 148 149
    <select id="selectCount" resultType="integer">
        select count(*) from goods where category=#{id}
    </select>
张新旗 committed
150
</mapper>