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

187 lines
8.8 KiB
XML
Raw Normal View History

2022-03-14 11:31:02 +08:00
<?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">
2022-03-14 11:31:02 +08:00
<id property="goodsId" column="goods_id" />
<result property="goodsCode" column="goods_code" />
<result property="deptId" column="dept_id" />
2022-03-14 11:31:02 +08:00
<result property="goodsName" column="goods_name" />
2022-07-22 22:28:58 +08:00
<result property="goodsDesc" column="goods_desc" />
2022-07-26 21:14:25 +08:00
<result property="goodsUnit" column="goods_unit" />
2022-03-14 11:31:02 +08:00
<result property="goodsSort" column="goods_sort"/>
2022-06-01 13:48:36 +08:00
<result property="workerId" column="worker_id"/>
2022-05-10 19:22:45 +08:00
<result property="deptGoodsCategoryId" column="dept_goods_category_id"/>
2022-03-14 11:31:02 +08:00
<result property="goodsImgUrl" column="goods_img_url"/>
2022-03-14 16:56:11 +08:00
<result property="goodsVideoUrl" column="goods_video_url"/>
2022-03-14 11:31:02 +08:00
<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">
2022-07-26 21:14:25 +08:00
SELECT goods_id, goods_code, dept_id, goods_name, goods_desc, goods_unit, goods_sort, worker_id,
dept_goods_category_id, goods_img_url, goods_video_url, status, create_by, create_time, remark
2022-05-10 19:22:45 +08:00
FROM goods
2022-03-14 11:31:02 +08:00
</sql>
2022-06-08 13:58:41 +08:00
<sql id="selectGoodsWithArea">
SELECT DISTINCT g.goods_id, goods_code, dept_id, goods_name, goods_desc, goods_sort, worker_id, goods_unit,
2022-12-17 00:15:20 +08:00
dept_goods_category_id, goods_img_url, goods_video_url, status, g.create_by, g.create_time, g.remark
2022-06-08 13:58:41 +08:00
FROM goods g
LEFT JOIN goods_area ga ON g.goods_id = ga.goods_id
</sql>
2022-03-14 11:31:02 +08:00
<update id="updateGoods" parameterType="com.ghy.goods.domain.Goods">
2022-05-10 19:22:45 +08:00
UPDATE goods
<set>
<if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
<if test="goodsSort != null and goodsSort != ''">goods_sort = #{goodsSort},</if>
2022-05-10 19:22:45 +08:00
<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>
2022-06-17 13:52:08 +08:00
<if test="status != null">`status` = #{status},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
2022-05-10 19:22:45 +08:00
WHERE goods_id = #{goodsId}
</update>
2022-05-10 20:54:51 +08:00
<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">
2022-03-17 14:54:11 +08:00
insert into goods(
<if test="goodsCode != null and goodsCode != ''">goods_code,</if>
2022-05-10 19:22:45 +08:00
<if test="deptId != null and deptId != ''">dept_id,</if>
<if test="goodsName != null and goodsName != ''">goods_name,</if>
2022-07-22 22:28:58 +08:00
<if test="goodsDesc != null and goodsDesc != ''">goods_desc,</if>
2022-07-26 21:14:25 +08:00
<if test="goodsUnit != null and goodsUnit != ''">goods_unit,</if>
<if test="goodsSort != null and goodsSort != ''">goods_sort,</if>
2022-06-01 13:48:36 +08:00
<if test="workerId != null and workerId != ''">worker_id,</if>
2022-05-10 19:22:45 +08:00
<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="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>
2022-05-10 19:22:45 +08:00
<if test="deptId != null and deptId != ''">#{deptId},</if>
<if test="goodsName != null and goodsName != ''">#{goodsName},</if>
2022-07-22 22:28:58 +08:00
<if test="goodsDesc != null and goodsDesc != ''">#{goodsDesc},</if>
2022-07-26 21:14:25 +08:00
<if test="goodsUnit != null and goodsUnit != ''">#{goodsUnit},</if>
<if test="goodsSort != null and goodsSort != ''">#{goodsSort},</if>
2022-06-01 13:48:36 +08:00
<if test="workerId != null and workerId != ''">#{workerId},</if>
2022-05-10 19:22:45 +08:00
<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="status != null and status != ''">#{status},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
2022-03-14 11:31:02 +08:00
2022-05-10 19:22:45 +08:00
<select id="selectGoodsList" parameterType="com.ghy.goods.domain.Goods" resultMap="GoodsResult">
2022-06-08 13:58:41 +08:00
<include refid="selectGoodsWithArea" />
2022-12-17 00:15:20 +08:00
LEFT JOIN sys_area sa ON sa.area_id = ga.country_area_id
2022-05-10 19:22:45 +08:00
<where>
<if test="goodsCode != null and goodsCode != ''">
AND goods_code like concat('%', #{goodsCode}, '%')
</if>
2022-06-07 10:33:11 +08:00
<if test="deptGoodsCategoryId != null and deptGoodsCategoryId != ''">
AND dept_goods_category_id = #{deptGoodsCategoryId}
</if>
<if test="deptGoodsCategoryIds != null">
AND dept_goods_category_id in
<foreach collection="deptGoodsCategoryIds" item="deptGoodsCategoryId" open="(" separator="," close=")">
#{deptGoodsCategoryId}
</foreach>
</if>
2022-06-08 13:58:41 +08:00
<if test="areaId != null and areaId != ''">
AND country_area_id = #{areaId}
</if>
2022-12-17 00:15:20 +08:00
<if test="exceptParentAreaId != null">
AND sa.parent_code != #{exceptParentAreaId}
</if>
2022-06-08 13:58:41 +08:00
<if test="goodsName != null and goodsName != ''">
AND goods_name like concat('%', #{goodsName}, '%')
</if>
<if test="status != null">
AND status = #{status}
</if>
2022-06-25 17:32:05 +08:00
<if test="workerId != null">
AND worker_id = #{workerId}
</if>
2022-05-10 19:22:45 +08:00
</where>
2022-06-08 13:58:41 +08:00
/* 默认生成时间排序 */
order by create_time
<trim suffixOverrides=",">
<choose>
<when test="params.createTimeSort != null and params.createTimeSort != ''">
${params.createTimeSort}
</when>
<otherwise>
desc
</otherwise>
</choose>
2022-06-08 13:58:41 +08:00
</trim>
2022-05-10 19:22:45 +08:00
</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"/>
2022-05-10 19:22:45 +08:00
WHERE dept_goods_category_id = #{deptGoodsCategoryId} LIMIT 1
</select>
2022-05-17 21:19:41 +08:00
<select id="selectByIds" resultMap="GoodsResult">
<include refid="selectGoods"/>
2022-05-26 15:08:52 +08:00
where goods_id IN
<foreach collection="collection" item="ids" open="(" separator="," close=")">
#{ids}
2022-05-17 21:19:41 +08:00
</foreach>
</select>
2022-06-07 10:33:11 +08:00
<select id="selectByCategoryIds" resultMap="GoodsResult">
<include refid="selectGoods"/>
where dept_goods_category_id IN
<foreach collection="collection" item="ids" open="(" separator="," close=")">
#{ids}
</foreach>
</select>
2022-06-08 13:58:41 +08:00
</mapper>