ghy-all/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml

158 lines
7.0 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.customer.mapper.CustomerMapper">
<resultMap id="CustomerResult" type="com.ghy.customer.domain.Customer">
<result property="customerId" column="customer_id" />
<result property="name" column="name" />
<result property="account" column="account" />
<result property="phone" column="phone" />
<result property="openId" column="open_id" />
<result property="password" column="password" />
<result property="status" column="status" />
<result property="placeStatus" column="place_status" />
<result property="customerLogoUrl" column="customer_logo_url" />
<result property="customerPlace" column="customer_place" />
<result property="parentCustomerPlace" column="parent_customer_place" />
<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="selectCustomer">
SELECT customer_id, name, account, phone, open_id, password, status, place_status,
customer_logo_url, customer_place, parent_customer_place, create_by, create_time, remark
FROM customer
</sql>
<sql id="selectCount">
SELECT COUNT(*)
FROM customer
</sql>
<select id="getCustomerList" resultMap="CustomerResult">
<include refid="selectCustomer" />
<where>
<if test="customerId != null">
AND customer_id = #{customerId}
</if>
<if test="openId != null and openId != ''">
AND open_id = #{openId}
</if>
<if test="customerPlace != null and customerPlace != ''">
AND customer_place = #{customerPlace}
</if>
<if test="placeStatus != null">
AND place_status = #{placeStatus}
</if>
<if test="phone != null and phone != ''">
AND phone like concat('%', #{phone}, '%')
</if>
</where>
order by update_time desc
</select>
<select id="countCustomer" resultType="long">
<include refid="selectCount" />
<where>
<if test="openId != null and openId != ''">
AND open_id = #{openId}
</if>
<if test="customerPlace != null and customerPlace != ''">
AND customer_place = #{customerPlace}
</if>
<if test="customerPlaces != null and customerPlaces.size > 0">
AND customer_place in
<foreach item="customerPlace" collection="customerPlaces" open="(" separator="," close=")">
#{customerPlace}
</foreach>
</if>
<if test="updateTimeStart != null">
AND update_time &gt;= #{updateTimeStart}
</if>
</where>
</select>
<delete id="deleteByIds">
DELETE FROM customer WHERE customer_id IN
<foreach collection="array" item="customerIds" open="(" separator="," close=")">
#{customerIds}
</foreach>
</delete>
<delete id="deleteByCustomerId" parameterType="Long">
DELETE FROM customer WHERE customer_id = #{customerId}
</delete>
<select id="selectByCustomerId" resultMap="CustomerResult">
<include refid="selectCustomer"/>
<where>
<if test="customerId != null and customerId != 0">
AND customer_id = #{customerId}
</if>
</where>
</select>
<insert id="insertCustomer" parameterType="com.ghy.customer.domain.Customer" useGeneratedKeys="true" keyProperty="customerId">
insert into customer(
<if test="customerId != null and customerId != 0">customer_id,</if>
<if test="name != null and name != ''">name,</if>
<if test="account != null and account != ''">account,</if>
<if test="phone != null and phone != ''">phone,</if>
<if test="customerLogoUrl != null and customerLogoUrl != ''">customer_logo_url,</if>
<if test="openId != null and openId != ''">open_id,</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="customerId != null and customerId != 0">#{customerId},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="account != null and account != ''">#{account},</if>
<if test="phone != null and phone != ''">#{phone},</if>
<if test="customerLogoUrl != null and customerLogoUrl != ''">#{customerLogoUrl},</if>
<if test="openId != null and openId != ''">#{openId},</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>
<update id="updateCustomer" parameterType="com.ghy.customer.domain.Customer">
update customer
<set>
<if test="name != null and name != ''">name = #{name},</if>
<if test="account != null and account != ''">account = #{account},</if>
<if test="phone != null and phone != ''">phone = #{phone},</if>
<if test="customerLogoUrl != null and customerLogoUrl != ''">customer_logo_url = #{customerLogoUrl},</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>
<if test="customerPlace != null">customer_place = #{customerPlace},</if>
<if test="parentCustomerPlace != null">parent_customer_place = #{parentCustomerPlace},</if>
<if test="placeStatus != null">place_status = #{placeStatus},</if>
update_time = sysdate()
</set>
where customer_id = #{customerId}
</update>
<select id="selectByIds" resultMap="CustomerResult">
<include refid="selectCustomer" />
<where>
AND customer_id IN
<foreach item="item" index="customerIds" collection="customerIds" open="(" separator="," close=")">
#{item}
</foreach>
</where>
</select>
<select id="selectByAccount" resultMap="CustomerResult">
<include refid="selectCustomer" />
WHERE account = #{account}
</select>
</mapper>