ghy-all/ghy-goods/src/main/resources/mapper/goods/GoodsMapper.xml

148 lines
7.6 KiB
XML

<?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.ghy.goods.mapper.GoodsMapper">
<resultMap id="GoodsResult" type="com.ghy.goods.domain.Goods">
<id property="goodsId" column="goods_id" />
<result property="goodsCode" column="goods_code" />
<result property="deptId" column="dept_id" />
<result property="goodsName" column="goods_name" />
<result property="goodsPrice" column="goods_price" />
<result property="discountsPrice" column="discounts_price" />
<result property="groupPrice" column="group_price" />
<result property="goodsSort" column="goods_sort"/>
<result property="deptGoodsCategoryId" column="dept_goods_category_id"/>
<result property="goodsImgUrl" column="goods_img_url"/>
<result property="goodsVideoUrl" column="goods_video_url"/>
<result property="goodsNumber" column="goods_number"/>
<result property="status" column="status"/>
<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="selectGoods">
SELECT goods_id, goods_code, dept_id, goods_name, goods_price, discounts_price, group_price, goods_sort,
dept_goods_category_id, goods_img_url, goods_video_url, goods_number, status, create_by, create_time, remark
FROM goods
</sql>
<select id="checkAGoodsStore" parameterType="com.ghy.goods.request.AppGoodsRequest" resultMap="GoodsResult">
<include refid="selectGoods" />
where goods_id = #{goodsId} and goods_number >= #{num}
</select>
<update id="updateGoods" parameterType="com.ghy.goods.domain.Goods">
UPDATE goods
<set>
<if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
<if test="goodsPrice != null and goodsPrice != ''">goods_price = #{goodsPrice},</if>
<if test="discountsPrice != null and discountsPrice != ''">discounts_price = #{discountsPrice},</if>
<if test="groupPrice != null and groupPrice != ''">group_price = #{groupPrice},</if>
<if test="goodsSort != null and goodsSort != ''">goods_sort = #{goodsSort},</if>
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != ''">dept_goods_category_id = #{deptGoodsCategoryId},</if>
<if test="goodsImgUrl != null and goodsImgUrl != ''">goods_img_url = #{goodsImgUrl},</if>
<if test="goodsVideoUrl != null and goodsVideoUrl != ''">goods_video_url = #{goodsVideoUrl},</if>
<if test="goodsNumber != null and goodsNumber != ''">goods_number = #{goodsNumber},</if>
<if test="status != null and status != ''">`status` = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
WHERE goods_id = #{goodsId}
</update>
<update id="setCode">
UPDATE goods
SET goods_code = #{goodsCode}, update_time = sysdate()
WHERE goods_id = #{goodsId}
</update>
<insert id="insertGoods" parameterType="com.ghy.goods.domain.Goods" useGeneratedKeys="true" keyProperty="goodsId">
insert into goods(
<if test="goodsCode != null and goodsCode != ''">goods_code,</if>
<if test="deptId != null and deptId != ''">dept_id,</if>
<if test="goodsName != null and goodsName != ''">goods_name,</if>
<if test="goodsPrice != null and goodsPrice != ''">goods_price,</if>
<if test="discountsPrice != null and discountsPrice != ''">discounts_price,</if>
<if test="groupPrice != null and groupPrice != ''">group_price,</if>
<if test="goodsSort != null and goodsSort != ''">goods_sort,</if>
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != 0">dept_goods_category_id,</if>
<if test="goodsImgUrl != null and goodsImgUrl != ''">goods_img_url,</if>
<if test="goodsVideoUrl != null and goodsVideoUrl != ''">goods_video_url,</if>
<if test="goodsNumber != null and goodsNumber != ''">goods_number,</if>
<if test="status != null and status != ''">status,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="goodsCode != null and goodsCode != ''">#{goodsCode},</if>
<if test="deptId != null and deptId != ''">#{deptId},</if>
<if test="goodsName != null and goodsName != ''">#{goodsName},</if>
<if test="goodsPrice != null and goodsPrice != ''">#{goodsPrice},</if>
<if test="discountsPrice != null and discountsPrice != ''">#{discountsPrice},</if>
<if test="groupPrice != null and groupPrice != ''">#{groupPrice},</if>
<if test="goodsSort != null and goodsSort != ''">#{goodsSort},</if>
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != 0">#{deptGoodsCategoryId},</if>
<if test="goodsImgUrl != null and goodsImgUrl != ''">#{goodsImgUrl},</if>
<if test="goodsVideoUrl != null and goodsVideoUrl != ''">#{goodsVideoUrl},</if>
<if test="goodsNumber != null and goodsNumber != ''">#{goodsNumber},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<select id="selectGoodsList" parameterType="com.ghy.goods.domain.Goods" resultMap="GoodsResult">
<include refid="selectGoods" />
<where>
<if test="goodsCode != null and goodsCode != ''">
AND goods_code like concat('%', #{goodsCode}, '%')
</if>
</where>
</select>
<select id="selectById" parameterType="long" resultMap="GoodsResult">
<include refid="selectGoods"/>
<where>
<if test="goodsId != null and goodsId != 0">
AND goods_id = #{goodsId}
</if>
</where>
</select>
<delete id="deleteGoodsByIds" parameterType="Long">
delete from goods where goods_id in
<foreach collection="array" item="goodsId" open="(" separator="," close=")">
#{goodsId}
</foreach>
</delete>
<select id="checkGoodsNameUnique" parameterType="String" resultMap="GoodsResult">
<include refid="selectGoods"/>
where goods_name=#{goodsName} limit 1
</select>
<select id="checkGoodsCodeUnique" parameterType="String" resultMap="GoodsResult">
<include refid="selectGoods"/>
where goods_code=#{goodsCode} limit 1
</select>
<select id="selectOneByGoodsCategoryId" parameterType="String" resultMap="GoodsResult">
<include refid="selectGoods"/>
WHERE dept_goods_category_id = #{deptGoodsCategoryId} LIMIT 1
</select>
<select id="selectByIds" resultMap="GoodsResult">
<include refid="selectGoods"/>
where goods_id IN
<foreach collection="collection" item="ids" open="(" separator="," close=")">
#{ids}
</foreach>
</select>
</mapper>