wx-cashier-service/src/main/resources/mapper/TbMerchantCouponMapper.xml

482 lines
22 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.chaozhanggui.system.cashierservice.dao.TbMerchantCouponMapper">
<resultMap type="com.chaozhanggui.system.cashierservice.entity.TbMerchantCoupon" id="TbMerchantCouponMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="status" column="status" jdbcType="INTEGER"/>
<result property="title" column="title" jdbcType="VARCHAR"/>
<result property="templateId" column="template_id" jdbcType="VARCHAR"/>
<result property="shopId" column="shop_id" jdbcType="VARCHAR"/>
<result property="shopSnap" column="shop_snap" jdbcType="VARCHAR"/>
<result property="fromTime" column="from_time" jdbcType="TIMESTAMP"/>
<result property="toTime" column="to_time" jdbcType="TIMESTAMP"/>
<result property="limitNumber" column="limit_number" jdbcType="VARCHAR"/>
<result property="number" column="number" jdbcType="INTEGER"/>
<result property="leftNumber" column="left_number" jdbcType="VARCHAR"/>
<result property="amount" column="amount" jdbcType="NUMERIC"/>
<result property="limitAmount" column="limit_amount" jdbcType="NUMERIC"/>
<result property="isShow" column="is_show" jdbcType="INTEGER"/>
<result property="pic" column="pic" jdbcType="VARCHAR"/>
<result property="type" column="type" jdbcType="INTEGER"/>
<result property="ratio" column="ratio" jdbcType="NUMERIC"/>
<result property="maxRatioAmount" column="max_ratio_amount" jdbcType="NUMERIC"/>
<result property="track" column="track" jdbcType="VARCHAR"/>
<result property="classType" column="class_type" jdbcType="VARCHAR"/>
<result property="effectType" column="effect_type" jdbcType="INTEGER"/>
<result property="effectDays" column="effect_days" jdbcType="INTEGER"/>
<result property="relationIds" column="relation_ids" jdbcType="VARCHAR"/>
<result property="relationList" column="relation_list" jdbcType="VARCHAR"/>
<result property="editor" column="editor" jdbcType="VARCHAR"/>
<result property="note" column="note" jdbcType="VARCHAR"/>
<result property="createdAt" column="created_at" jdbcType="INTEGER"/>
<result property="updatedAt" column="updated_at" jdbcType="INTEGER"/>
<result property="furnishMeal" column="furnish_meal" jdbcType="INTEGER"/>
<result property="furnishExpress" column="furnish_express" jdbcType="INTEGER"/>
<result property="furnishDraw" column="furnish_draw" jdbcType="INTEGER"/>
<result property="furnishVir" column="furnish_vir" jdbcType="INTEGER"/>
<result property="disableDistribute" column="disable_distribute" jdbcType="INTEGER"/>
<result property="merchantId" column="merchant_id" jdbcType="VARCHAR"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="TbMerchantCouponMap">
select
id, status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id
from tb_merchant_coupon
where id = #{id}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="TbMerchantCouponMap">
select
id, status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id
from tb_merchant_coupon
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="status != null">
and status = #{status}
</if>
<if test="title != null and title != ''">
and title = #{title}
</if>
<if test="templateId != null and templateId != ''">
and template_id = #{templateId}
</if>
<if test="shopId != null and shopId != ''">
and shop_id = #{shopId}
</if>
<if test="shopSnap != null and shopSnap != ''">
and shop_snap = #{shopSnap}
</if>
<if test="fromTime != null">
and from_time = #{fromTime}
</if>
<if test="toTime != null">
and to_time = #{toTime}
</if>
<if test="limitNumber != null and limitNumber != ''">
and limit_number = #{limitNumber}
</if>
<if test="number != null">
and number = #{number}
</if>
<if test="leftNumber != null and leftNumber != ''">
and left_number = #{leftNumber}
</if>
<if test="amount != null">
and amount = #{amount}
</if>
<if test="limitAmount != null">
and limit_amount = #{limitAmount}
</if>
<if test="isShow != null">
and is_show = #{isShow}
</if>
<if test="pic != null and pic != ''">
and pic = #{pic}
</if>
<if test="type != null">
and type = #{type}
</if>
<if test="ratio != null">
and ratio = #{ratio}
</if>
<if test="maxRatioAmount != null">
and max_ratio_amount = #{maxRatioAmount}
</if>
<if test="track != null and track != ''">
and track = #{track}
</if>
<if test="classType != null and classType != ''">
and class_type = #{classType}
</if>
<if test="effectType != null">
and effect_type = #{effectType}
</if>
<if test="effectDays != null">
and effect_days = #{effectDays}
</if>
<if test="relationIds != null and relationIds != ''">
and relation_ids = #{relationIds}
</if>
<if test="relationList != null and relationList != ''">
and relation_list = #{relationList}
</if>
<if test="editor != null and editor != ''">
and editor = #{editor}
</if>
<if test="note != null and note != ''">
and note = #{note}
</if>
<if test="createdAt != null">
and created_at = #{createdAt}
</if>
<if test="updatedAt != null">
and updated_at = #{updatedAt}
</if>
<if test="furnishMeal != null">
and furnish_meal = #{furnishMeal}
</if>
<if test="furnishExpress != null">
and furnish_express = #{furnishExpress}
</if>
<if test="furnishDraw != null">
and furnish_draw = #{furnishDraw}
</if>
<if test="furnishVir != null">
and furnish_vir = #{furnishVir}
</if>
<if test="disableDistribute != null">
and disable_distribute = #{disableDistribute}
</if>
<if test="merchantId != null and merchantId != ''">
and merchant_id = #{merchantId}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from tb_merchant_coupon
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="status != null">
and status = #{status}
</if>
<if test="title != null and title != ''">
and title = #{title}
</if>
<if test="templateId != null and templateId != ''">
and template_id = #{templateId}
</if>
<if test="shopId != null and shopId != ''">
and shop_id = #{shopId}
</if>
<if test="shopSnap != null and shopSnap != ''">
and shop_snap = #{shopSnap}
</if>
<if test="fromTime != null">
and from_time = #{fromTime}
</if>
<if test="toTime != null">
and to_time = #{toTime}
</if>
<if test="limitNumber != null and limitNumber != ''">
and limit_number = #{limitNumber}
</if>
<if test="number != null">
and number = #{number}
</if>
<if test="leftNumber != null and leftNumber != ''">
and left_number = #{leftNumber}
</if>
<if test="amount != null">
and amount = #{amount}
</if>
<if test="limitAmount != null">
and limit_amount = #{limitAmount}
</if>
<if test="isShow != null">
and is_show = #{isShow}
</if>
<if test="pic != null and pic != ''">
and pic = #{pic}
</if>
<if test="type != null">
and type = #{type}
</if>
<if test="ratio != null">
and ratio = #{ratio}
</if>
<if test="maxRatioAmount != null">
and max_ratio_amount = #{maxRatioAmount}
</if>
<if test="track != null and track != ''">
and track = #{track}
</if>
<if test="classType != null and classType != ''">
and class_type = #{classType}
</if>
<if test="effectType != null">
and effect_type = #{effectType}
</if>
<if test="effectDays != null">
and effect_days = #{effectDays}
</if>
<if test="relationIds != null and relationIds != ''">
and relation_ids = #{relationIds}
</if>
<if test="relationList != null and relationList != ''">
and relation_list = #{relationList}
</if>
<if test="editor != null and editor != ''">
and editor = #{editor}
</if>
<if test="note != null and note != ''">
and note = #{note}
</if>
<if test="createdAt != null">
and created_at = #{createdAt}
</if>
<if test="updatedAt != null">
and updated_at = #{updatedAt}
</if>
<if test="furnishMeal != null">
and furnish_meal = #{furnishMeal}
</if>
<if test="furnishExpress != null">
and furnish_express = #{furnishExpress}
</if>
<if test="furnishDraw != null">
and furnish_draw = #{furnishDraw}
</if>
<if test="furnishVir != null">
and furnish_vir = #{furnishVir}
</if>
<if test="disableDistribute != null">
and disable_distribute = #{disableDistribute}
</if>
<if test="merchantId != null and merchantId != ''">
and merchant_id = #{merchantId}
</if>
</where>
</select>
<select id="queryAllByPage" resultType="com.chaozhanggui.system.cashierservice.entity.vo.CouAndShopVo">
SELECT
cou.id as id,
cou.title as title,
cou.shop_id as shopId,
cou.amount as amount,
cou.number as number,
cou.ratio as ratio,
cou.relation_ids as relationIds,
info.shop_name as shopName,
info.logo
FROM
tb_merchant_coupon as cou
LEFT JOIN tb_shop_info as info ON cou.shop_id = info.id
<where>
cou.class_type = 'product'
AND cou.`status` = 1
AND info.cities =#{cities}
<if test="rightTopLng != null and rightTopLng != '' and leftBottomLng != null and leftBottomLng != ''">
AND info.lng BETWEEN #{leftBottomLng} AND #{rightTopLng}
AND info.lat BETWEEN #{leftBottomLat} AND #{rightTopLat}
</if>
</where>
<choose>
<when test="order == '1'">
ORDER BY (ABS(info.lat - #{lat}) + ABS(info.lng - #{lng})) ASC
</when>
<when test="order == '2'">
ORDER BY cou.number ASC
</when>
<when test="order == '3'">
ORDER BY cou.amount ASC
</when>
<otherwise>
ORDER BY cou.id ASC
</otherwise>
</choose>
limit #{pageable}, #{sizeable}
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into tb_merchant_coupon(status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id)
values (#{status}, #{title}, #{templateId}, #{shopId}, #{shopSnap}, #{fromTime}, #{toTime}, #{limitNumber}, #{number}, #{leftNumber}, #{amount}, #{limitAmount}, #{isShow}, #{pic}, #{type}, #{ratio}, #{maxRatioAmount}, #{track}, #{classType}, #{effectType}, #{effectDays}, #{relationIds}, #{relationList}, #{editor}, #{note}, #{createdAt}, #{updatedAt}, #{furnishMeal}, #{furnishExpress}, #{furnishDraw}, #{furnishVir}, #{disableDistribute}, #{merchantId})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into tb_merchant_coupon(status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.status}, #{entity.title}, #{entity.templateId}, #{entity.shopId}, #{entity.shopSnap}, #{entity.fromTime}, #{entity.toTime}, #{entity.limitNumber}, #{entity.number}, #{entity.leftNumber}, #{entity.amount}, #{entity.limitAmount}, #{entity.isShow}, #{entity.pic}, #{entity.type}, #{entity.ratio}, #{entity.maxRatioAmount}, #{entity.track}, #{entity.classType}, #{entity.effectType}, #{entity.effectDays}, #{entity.relationIds}, #{entity.relationList}, #{entity.editor}, #{entity.note}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.furnishMeal}, #{entity.furnishExpress}, #{entity.furnishDraw}, #{entity.furnishVir}, #{entity.disableDistribute}, #{entity.merchantId})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into tb_merchant_coupon(status, title, template_id, shop_id, shop_snap, from_time, to_time, limit_number, number, left_number, amount, limit_amount, is_show, pic, type, ratio, max_ratio_amount, track, class_type, effect_type, effect_days, relation_ids, relation_list, editor, note, created_at, updated_at, furnish_meal, furnish_express, furnish_draw, furnish_vir, disable_distribute, merchant_id)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.status}, #{entity.title}, #{entity.templateId}, #{entity.shopId}, #{entity.shopSnap}, #{entity.fromTime}, #{entity.toTime}, #{entity.limitNumber}, #{entity.number}, #{entity.leftNumber}, #{entity.amount}, #{entity.limitAmount}, #{entity.isShow}, #{entity.pic}, #{entity.type}, #{entity.ratio}, #{entity.maxRatioAmount}, #{entity.track}, #{entity.classType}, #{entity.effectType}, #{entity.effectDays}, #{entity.relationIds}, #{entity.relationList}, #{entity.editor}, #{entity.note}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.furnishMeal}, #{entity.furnishExpress}, #{entity.furnishDraw}, #{entity.furnishVir}, #{entity.disableDistribute}, #{entity.merchantId})
</foreach>
on duplicate key update
status = values(status),
title = values(title),
template_id = values(template_id),
shop_id = values(shop_id),
shop_snap = values(shop_snap),
from_time = values(from_time),
to_time = values(to_time),
limit_number = values(limit_number),
number = values(number),
left_number = values(left_number),
amount = values(amount),
limit_amount = values(limit_amount),
is_show = values(is_show),
pic = values(pic),
type = values(type),
ratio = values(ratio),
max_ratio_amount = values(max_ratio_amount),
track = values(track),
class_type = values(class_type),
effect_type = values(effect_type),
effect_days = values(effect_days),
relation_ids = values(relation_ids),
relation_list = values(relation_list),
editor = values(editor),
note = values(note),
created_at = values(created_at),
updated_at = values(updated_at),
furnish_meal = values(furnish_meal),
furnish_express = values(furnish_express),
furnish_draw = values(furnish_draw),
furnish_vir = values(furnish_vir),
disable_distribute = values(disable_distribute),
merchant_id = values(merchant_id)
</insert>
<!--通过主键修改数据-->
<update id="update">
update tb_merchant_coupon
<set>
<if test="status != null">
status = #{status},
</if>
<if test="title != null and title != ''">
title = #{title},
</if>
<if test="templateId != null and templateId != ''">
template_id = #{templateId},
</if>
<if test="shopId != null and shopId != ''">
shop_id = #{shopId},
</if>
<if test="shopSnap != null and shopSnap != ''">
shop_snap = #{shopSnap},
</if>
<if test="fromTime != null">
from_time = #{fromTime},
</if>
<if test="toTime != null">
to_time = #{toTime},
</if>
<if test="limitNumber != null and limitNumber != ''">
limit_number = #{limitNumber},
</if>
<if test="number != null">
number = #{number},
</if>
<if test="leftNumber != null and leftNumber != ''">
left_number = #{leftNumber},
</if>
<if test="amount != null">
amount = #{amount},
</if>
<if test="limitAmount != null">
limit_amount = #{limitAmount},
</if>
<if test="isShow != null">
is_show = #{isShow},
</if>
<if test="pic != null and pic != ''">
pic = #{pic},
</if>
<if test="type != null">
type = #{type},
</if>
<if test="ratio != null">
ratio = #{ratio},
</if>
<if test="maxRatioAmount != null">
max_ratio_amount = #{maxRatioAmount},
</if>
<if test="track != null and track != ''">
track = #{track},
</if>
<if test="classType != null and classType != ''">
class_type = #{classType},
</if>
<if test="effectType != null">
effect_type = #{effectType},
</if>
<if test="effectDays != null">
effect_days = #{effectDays},
</if>
<if test="relationIds != null and relationIds != ''">
relation_ids = #{relationIds},
</if>
<if test="relationList != null and relationList != ''">
relation_list = #{relationList},
</if>
<if test="editor != null and editor != ''">
editor = #{editor},
</if>
<if test="note != null and note != ''">
note = #{note},
</if>
<if test="createdAt != null">
created_at = #{createdAt},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt},
</if>
<if test="furnishMeal != null">
furnish_meal = #{furnishMeal},
</if>
<if test="furnishExpress != null">
furnish_express = #{furnishExpress},
</if>
<if test="furnishDraw != null">
furnish_draw = #{furnishDraw},
</if>
<if test="furnishVir != null">
furnish_vir = #{furnishVir},
</if>
<if test="disableDistribute != null">
disable_distribute = #{disableDistribute},
</if>
<if test="merchantId != null and merchantId != ''">
merchant_id = #{merchantId},
</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from tb_merchant_coupon where id = #{id}
</delete>
</mapper>