RuoYi/box-test/src/main/resources/mapper/test/SysCustomerMapper.xml

111 lines
5.1 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.ruoyi.test.mapper.SysCustomerMapper">
<resultMap type="SysCustomer" id="SysCustomerResult">
<result property="customerId" column="customer_id" />
<result property="customerName" column="customer_name" />
<result property="phonenumber" column="phonenumber" />
<result property="sex" column="sex" />
<result property="birthday" column="birthday" />
<result property="remark" column="remark" />
</resultMap>
<resultMap id="SysCustomerSysGoodsResult" type="SysCustomer" extends="SysCustomerResult">
<collection property="sysGoodsList" notNullColumn="goods_id" javaType="java.util.List" resultMap="SysGoodsResult" />
</resultMap>
<resultMap type="SysGoods" id="SysGoodsResult">
<result property="goodsId" column="goods_id" />
<result property="customerId" column="customer_id" />
<result property="name" column="name" />
<result property="weight" column="weight" />
<result property="price" column="price" />
<result property="date" column="date" />
<result property="type" column="type" />
</resultMap>
<sql id="selectSysCustomerVo">
select customer_id, customer_name, phonenumber, sex, birthday, remark from sys_customer
</sql>
<select id="selectSysCustomerList" parameterType="SysCustomer" resultMap="SysCustomerResult">
<include refid="selectSysCustomerVo"/>
<where>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
<if test="phonenumber != null and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
<if test="sex != null and sex != ''"> and sex = #{sex}</if>
<if test="birthday != null "> and birthday = #{birthday}</if>
</where>
</select>
<select id="selectSysCustomerById" parameterType="Long" resultMap="SysCustomerSysGoodsResult">
select a.customer_id, a.customer_name, a.phonenumber, a.sex, a.birthday, a.remark,
b.goods_id, b.customer_id, b.name, b.weight, b.price, b.date, b.type
from sys_customer a
left join sys_goods b on b.customer_id = a.customer_id
where a.customer_id = #{customerId}
</select>
<insert id="insertSysCustomer" parameterType="SysCustomer" useGeneratedKeys="true" keyProperty="customerId">
insert into sys_customer
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="customerName != null">customer_name,</if>
<if test="phonenumber != null">phonenumber,</if>
<if test="sex != null">sex,</if>
<if test="birthday != null">birthday,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="customerName != null">#{customerName},</if>
<if test="phonenumber != null">#{phonenumber},</if>
<if test="sex != null">#{sex},</if>
<if test="birthday != null">#{birthday},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateSysCustomer" parameterType="SysCustomer">
update sys_customer
<trim prefix="SET" suffixOverrides=",">
<if test="customerName != null">customer_name = #{customerName},</if>
<if test="phonenumber != null">phonenumber = #{phonenumber},</if>
<if test="sex != null">sex = #{sex},</if>
<if test="birthday != null">birthday = #{birthday},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where customer_id = #{customerId}
</update>
<delete id="deleteSysCustomerById" parameterType="Long">
delete from sys_customer where customer_id = #{customerId}
</delete>
<delete id="deleteSysCustomerByIds" parameterType="String">
delete from sys_customer where customer_id in
<foreach item="customerId" collection="array" open="(" separator="," close=")">
#{customerId}
</foreach>
</delete>
<delete id="deleteSysGoodsByCustomerIds" parameterType="String">
delete from sys_goods where customer_id in
<foreach item="customerId" collection="array" open="(" separator="," close=")">
#{customerId}
</foreach>
</delete>
<delete id="deleteSysGoodsByCustomerId" parameterType="Long">
delete from sys_goods where customer_id = #{customerId}
</delete>
<insert id="batchSysGoods">
insert into sys_goods( goods_id, customer_id, name, weight, price, date, type) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.goodsId}, #{item.customerId}, #{item.name}, #{item.weight}, #{item.price}, #{item.date}, #{item.type})
</foreach>
</insert>
</mapper>