MaintainPlanMapper.xml 5.2 KB
<?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.zteits.urbanops.module.garden.dal.mysql.maintainplan.MaintainPlanMapper">

    <!--
        一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
     -->
    <delete id="deleteByBatchNo">
        delete from garden_maintain_plan where batch_no =#{batchNo}
    </delete>


    <select id="appMaintainPlanRoadPage" resultType="com.zteits.urbanops.module.garden.controller.app.maintainplan.vo.AppMaintainPlanPageRoadRespVO">
        SELECT
        a.road_id,
        a.road_name,
        a.level_id
        FROM
        garden_maintain_plan_detail b
        INNER JOIN garden_maintain_plan a ON b.batch_no = a.batch_no and a.deleted = b.deleted
        INNER JOIN (
        SELECT DISTINCT batch_no
        FROM garden_maintain_plan_role
        WHERE deleted = 0
        AND dept_id = #{req.deptId}
        <if test="req.roleIds != null and req.roleIds.size() > 0">
            AND role_id IN
            <foreach collection="req.roleIds" item="roleId" open="(" separator="," close=")">
                #{roleId}
            </foreach>
        </if>
        ) c ON b.batch_no = c.batch_no
        WHERE
        a.deleted = 0
        <if test="req.roadName != null and req.roadName != ''">
            AND a.road_name LIKE CONCAT('%', #{req.roadName}, '%')
        </if>
        <if test="req.busiLineList != null and req.busiLineList.size() > 0">
            AND a.busi_line IN
            <foreach collection="req.busiLineList" item="busiLine" open="(" separator="," close=")">
                #{busiLine}
            </foreach>
        </if>
        <!-- 状态过滤 -->
        <choose>
            <when test="req.finishState == 1">
                AND a.finish_state = 1
                <![CDATA[AND b.begin_time  <=  #{req.localDateTime}
                AND b.end_time  >= #{req.localDateTime}]]>
            </when>
            <when test="req.finishState == 2">
                AND a.finish_state = 2

            </when>
            <when test="req.finishState == 3">
                AND a.finish_state = 3
                <![CDATA[AND b.begin_time  <=  #{req.localDateTime}
                AND b.end_time  >= #{req.localDateTime}]]>
            </when>
            <when test="req.finishState == 4">
                AND a.finish_state = 4
                <![CDATA[AND b.begin_time  <=  #{req.localDateTime}
                AND b.end_time  >= #{req.localDateTime}]]>
            </when>
        </choose>
        GROUP BY a.road_id, a.road_name, a.level_id
    </select>

    <select id="appMaintainPlanPlanTypePage" resultType="com.zteits.urbanops.module.garden.controller.app.maintainplan.vo.AppMaintainPlanPagePlanTypeRespVO">
        SELECT
        c.batch_no,
        c.plan_no,
        a.plan_name,
        a.plan_type_id,
        a.rate,
        a.cycle_id,
        c.plan_num,
        c.plan_finish_num,
        c.finish_state,
        c.begin_time,
        c.end_time
        FROM
        garden_maintain_plan a
        INNER JOIN  garden_maintain_plan_detail c ON a.batch_no = c.batch_no
        INNER JOIN (select distinct batch_no, dept_id
        from garden_maintain_plan_role
        where deleted = 0
        AND dept_id = #{req.deptId}
        <if test="req.roleIds != null and req.roleIds.size() > 0">
            AND role_id IN
            <foreach collection="req.roleIds" item="roleId" open="(" separator="," close=")">
                #{roleId}
            </foreach>
        </if>
        )   d ON c.batch_no = d.batch_no and c.dept_id = d.dept_id
        AND a.deleted=0
        AND a.plan_type_id = #{req.planTypeId}
        <if test="req.planName != null and req.planName !=''">
            AND a.plan_name LIKE CONCAT('%',#{req.planName},'%')
        </if>
        <if test="req.busiLineList != null and req.busiLineList.size() > 0">
            AND a.busi_line IN
            <foreach collection="req.busiLineList" item="busiLine" open="(" separator="," close=")">
                #{busiLine}
            </foreach>
        </if>
        <!--状态 1:未完成;2:已完成;3:已失效-->
        -- and c.finish_state =a.finish_state
        <if test="req.finishState == 1">
            and c.finish_state = 1
            <![CDATA[and c.begin_time <= #{req.localDateTime}
                     and c.end_time >= #{req.localDateTime}]]>
        </if>
        <if test="req.finishState == 2">
            and c.finish_state = 2
        </if>
        <if test="req.finishState == 3">
            and c.finish_state = 3
            <![CDATA[and c.begin_time <= #{req.localDateTime}
                     and c.end_time >= #{req.localDateTime}]]>
        </if>
        <if test="req.finishState == 4">
            and c.finish_state = 4
            <![CDATA[and c.begin_time <= #{req.localDateTime}
                     and c.end_time >= #{req.localDateTime}]]>
        </if>
        ORDER BY a.id desc
    </select>

</mapper>