153 lines
5.7 KiB
XML
153 lines
5.7 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.bycrm.mapper.ReportMapper">
|
|
|
|
<resultMap id="BaseResultMap" type="com.bycrm.entity.Report">
|
|
<id column="id" property="id"/>
|
|
<result column="dealer_id" property="dealerId"/>
|
|
<result column="school_id" property="schoolId"/>
|
|
<result column="school_name" property="schoolName"/>
|
|
<result column="product" property="product"/>
|
|
<result column="project_type" property="projectType"/>
|
|
<result column="description" property="description"/>
|
|
<result column="status" property="status"/>
|
|
<result column="reject_reason" property="rejectReason"/>
|
|
<result column="cancel_reason" property="cancelReason"/>
|
|
<result column="protect_start_date" property="protectStartDate"/>
|
|
<result column="protect_end_date" property="protectEndDate"/>
|
|
<result column="created_at" property="createdAt"/>
|
|
<result column="updated_at" property="updatedAt"/>
|
|
<result column="dealer_name" property="dealerName"/>
|
|
</resultMap>
|
|
|
|
<select id="selectById" resultMap="BaseResultMap">
|
|
SELECT r.*,
|
|
d.name AS dealer_name
|
|
FROM crm_report r
|
|
LEFT JOIN crm_dealer d ON r.dealer_id = d.id
|
|
WHERE r.id = #{id}
|
|
</select>
|
|
|
|
<select id="selectValidBySchoolAndProduct" resultMap="BaseResultMap">
|
|
SELECT * FROM crm_report
|
|
WHERE school_id = #{schoolId}
|
|
AND product = #{product}
|
|
AND project_type = #{projectType}
|
|
AND status IN (0, 1)
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<select id="selectValidBySchoolNameAndProduct" resultMap="BaseResultMap">
|
|
SELECT * FROM crm_report
|
|
WHERE school_name = #{schoolName}
|
|
AND product = #{product}
|
|
AND project_type = #{projectType}
|
|
AND status IN (0, 1)
|
|
LIMIT 1
|
|
</select>
|
|
|
|
<select id="selectPage" resultMap="BaseResultMap">
|
|
SELECT r.*,
|
|
d.name AS dealer_name
|
|
FROM crm_report r
|
|
LEFT JOIN crm_dealer d ON r.dealer_id = d.id
|
|
<where>
|
|
<if test="dealerId != null">
|
|
AND r.dealer_id = #{dealerId}
|
|
</if>
|
|
<if test="dealerName != null and dealerName != ''">
|
|
AND d.name LIKE CONCAT('%', #{dealerName}, '%')
|
|
</if>
|
|
<if test="customerName != null and customerName != ''">
|
|
AND r.school_name LIKE CONCAT('%', #{customerName}, '%')
|
|
</if>
|
|
<if test="status != null">
|
|
AND r.status = #{status}
|
|
</if>
|
|
</where>
|
|
ORDER BY r.created_at DESC
|
|
LIMIT #{query.size} OFFSET #{query.offset}
|
|
</select>
|
|
|
|
<select id="countPage" resultType="java.lang.Long">
|
|
SELECT COUNT(*)
|
|
FROM crm_report r
|
|
LEFT JOIN crm_dealer d ON r.dealer_id = d.id
|
|
<where>
|
|
<if test="dealerId != null">
|
|
AND r.dealer_id = #{dealerId}
|
|
</if>
|
|
<if test="dealerName != null and dealerName != ''">
|
|
AND d.name LIKE CONCAT('%', #{dealerName}, '%')
|
|
</if>
|
|
<if test="customerName != null and customerName != ''">
|
|
AND r.school_name LIKE CONCAT('%', #{customerName}, '%')
|
|
</if>
|
|
<if test="status != null">
|
|
AND r.status = #{status}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
<insert id="insert" parameterType="com.bycrm.entity.Report" useGeneratedKeys="true" keyProperty="id">
|
|
INSERT INTO crm_report (dealer_id, school_id, school_name, product, project_type, description, status, protect_start_date, protect_end_date)
|
|
VALUES (#{dealerId}, #{schoolId}, #{schoolName}, #{product}, #{projectType}, #{description}, #{status}, #{protectStartDate}, #{protectEndDate})
|
|
</insert>
|
|
|
|
<update id="update" parameterType="com.bycrm.entity.Report">
|
|
UPDATE crm_report
|
|
<set>
|
|
<if test="product != null">product = #{product},</if>
|
|
<if test="projectType != null">project_type = #{projectType},</if>
|
|
<if test="description != null">description = #{description},</if>
|
|
<if test="status != null">status = #{status},</if>
|
|
<if test="rejectReason != null">reject_reason = #{rejectReason},</if>
|
|
<if test="cancelReason != null">cancel_reason = #{cancelReason},</if>
|
|
<if test="protectStartDate != null">protect_start_date = #{protectStartDate},</if>
|
|
<if test="protectEndDate != null">protect_end_date = #{protectEndDate},</if>
|
|
updated_at = NOW()
|
|
</set>
|
|
WHERE id = #{id}
|
|
</update>
|
|
|
|
<delete id="deleteById">
|
|
DELETE FROM crm_report WHERE id = #{id}
|
|
</delete>
|
|
|
|
<select id="selectExpiringReports" resultMap="BaseResultMap">
|
|
SELECT * FROM crm_report
|
|
WHERE status = 1
|
|
AND protect_end_date <= #{endDate}
|
|
</select>
|
|
|
|
<update id="batchUpdateExpired">
|
|
UPDATE crm_report
|
|
SET status = 3
|
|
WHERE id IN
|
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
</update>
|
|
|
|
<select id="countByDealerId" resultType="java.lang.Long">
|
|
SELECT COUNT(*)
|
|
FROM crm_report
|
|
<where>
|
|
<if test="dealerId != null">
|
|
AND dealer_id = #{dealerId}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
<select id="countPendingByDealerId" resultType="java.lang.Long">
|
|
SELECT COUNT(*)
|
|
FROM crm_report
|
|
WHERE status = 0
|
|
<if test="dealerId != null">
|
|
AND dealer_id = #{dealerId}
|
|
</if>
|
|
</select>
|
|
|
|
</mapper>
|