lanan-system/dl-module-inspection/src/main/resources/mapper/partner/PartnerCustomerInfoMapper.xml
2024-10-17 17:18:17 +08:00

136 lines
6.9 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="cn.iocoder.yudao.module.partner.mapper.PartnerCustomerInfoMapper">
<resultMap type="cn.iocoder.yudao.module.partner.entity.PartnerCustomerInfo" id="PartnerCustomerInfoResult">
<result property="id" column="id" />
<result property="partnerId" column="partner_id" />
<result property="customerName" column="customer_name" />
<result property="customerPhone" column="customer_phone" />
<result property="userId" column="user_id" />
<result property="sex" column="sex" />
<result property="userAge" column="user_age" />
<result property="deptId" column="dept_id" />
<result property="createTime" column="create_time" />
<result property="creator" column="creator" />
<result property="updateTime" column="update_time" />
<result property="updater" column="updater" />
</resultMap>
<sql id="selectPartnerCustomerInfoVo">
select id, partner_id, customer_name, customer_phone, user_id, sex, user_age, dept_id, create_time, creator, update_time, updater from partner_customer_info
</sql>
<select id="selectPartnerCustomerInfoList" resultType="cn.iocoder.yudao.module.partner.entity.PartnerCustomerInfo">
select pci.*,
sr.name as roleName,
sr.code as roleCode
from partner_customer_info pci
left join shop_user_car suc on suc.user_id = pci.user_id
left join system_users su on su.id = pci.user_id
left join system_user_role sur on sur.user_id = su.id
left join system_role sr on sr.id = sur.role_id
<where>
<if test="vo.carNum != null and vo.carNum != ''"> and suc.car_no like concat('%', #{vo.carNum}, '%')</if>
<if test="vo.customerName != null and vo.customerName != ''"> and pci.customer_name like concat('%', #{vo.customerName}, '%')</if>
<if test="vo.customerPhone != null and vo.customerPhone != ''"> and pci.customer_phone like concat('%', #{vo.customerPhone}, '%')</if>
<if test="vo.roleCode != null and vo.roleCode != ''"> and sr.code = #{vo.roleCode}</if>
</where>
group by pci.id
order by suc.next_inspection_date
</select>
<select id="selectPartnerCustomerInfoById" parameterType="Long" resultMap="PartnerCustomerInfoResult">
<include refid="selectPartnerCustomerInfoVo"/>
where id = #{id}
</select>
<select id="pagePartnerCustomerInfoList"
resultType="cn.iocoder.yudao.module.partner.entity.PartnerCustomerInfo">
select pci.*,
sr.name as roleName,
sr.code as roleCode,
COUNT(ins.id) AS orderCount
from partner_customer_info pci
left join shop_user_car suc on suc.user_id = pci.user_id
left join system_users su on su.id = pci.user_id
left join system_user_role sur on sur.user_id = su.id
left join system_role sr on sr.id = sur.role_id
LEFT JOIN inspection_info ins ON ins.user_id = pci.user_id AND YEAR(ins.create_time) =YEAR(NOW())
<where>
<if test="vo.carNum != null and vo.carNum != ''"> and suc.car_no like concat('%', #{vo.carNum}, '%')</if>
<if test="vo.customerName != null and vo.customerName != ''"> and pci.customer_name like concat('%', #{vo.customerName}, '%')</if>
<if test="vo.customerPhone != null and vo.customerPhone != ''"> and pci.customer_phone like concat('%', #{vo.customerPhone}, '%')</if>
<if test="vo.roleCode != null and vo.roleCode != ''"> and sr.code = #{vo.roleCode}</if>
</where>
group by pci.id
order by suc.next_inspection_date
</select>
<insert id="insertPartnerCustomerInfo" parameterType="cn.iocoder.yudao.module.partner.entity.PartnerCustomerInfo">
insert into partner_customer_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="partnerId != null">partner_id,</if>
<if test="customerName != null">customer_name,</if>
<if test="customerPhone != null">customer_phone,</if>
<if test="userId != null">user_id,</if>
<if test="sex != null">sex,</if>
<if test="userAge != null">user_age,</if>
<if test="deptId != null">dept_id,</if>
<if test="createTime != null">create_time,</if>
<if test="creator != null">creator,</if>
<if test="updateTime != null">update_time,</if>
<if test="updater != null">updater,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="partnerId != null">#{partnerId},</if>
<if test="customerName != null">#{customerName},</if>
<if test="customerPhone != null">#{customerPhone},</if>
<if test="userId != null">#{userId},</if>
<if test="sex != null">#{sex},</if>
<if test="userAge != null">#{userAge},</if>
<if test="deptId != null">#{deptId},</if>
<if test="createTime != null">#{createTime},</if>
<if test="creator != null">#{creator},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="updater != null">#{updater},</if>
</trim>
</insert>
<update id="updatePartnerCustomerInfo" parameterType="cn.iocoder.yudao.module.partner.entity.PartnerCustomerInfo">
update partner_customer_info
<trim prefix="SET" suffixOverrides=",">
<if test="partnerId != null">partner_id = #{partnerId},</if>
<if test="customerName != null">customer_name = #{customerName},</if>
<if test="customerPhone != null">customer_phone = #{customerPhone},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="sex != null">sex = #{sex},</if>
<if test="userAge != null">user_age = #{userAge},</if>
<if test="deptId != null">dept_id = #{deptId},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="creator != null">creator = #{creator},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="updater != null">updater = #{updater},</if>
</trim>
where id = #{id}
</update>
<delete id="deletePartnerCustomerInfoById" parameterType="Long">
delete from partner_customer_info where id = #{id}
</delete>
<delete id="deletePartnerCustomerInfoByIds" parameterType="String">
delete from partner_customer_info where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>