EscortAttendanceMapper.xml 13 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.xiniunet.service.railway.dal.EscortAttendanceMapper">

    <sql id="whereForFindList">
        <if test="request.userId  != null">AND `USER_ID`=#{ request.userId }</if>
        <if test="request.dateId  != null">AND `DATE_ID`=#{ request.dateId }</if>
        <if test="request.type  != null">AND `TYPE`=#{ request.type }</if>

    </sql>

    <sql id="whereForSearchList">
        AND
        (
            1=0
        )
    </sql>

    <sql id="whereForFindCount">
        <if test="request.type  != null">
        AND ID IN(
        SELECT
        ID
        FROM
        rw_escort_attendance
        WHERE
        id IN (
        SELECT
        max(id)
        FROM
        rw_escort_attendance
        GROUP BY
        USER_ID
        )
        AND TYPE = #{ request.type })</if>

    </sql>

    <sql id="whereForDistinctFindList">
        <if test="request.userId  != null">AND `USER_ID`=#{ request.userId }</if>
        <if test="request.dateId  != null">AND `DATE_ID`=#{ request.dateId }</if>
        <if test="request.userIdList!=null and request.userIdList.size() != 0">
            AND `USER_ID` IN
            <foreach collection="request.userIdList" item="userId" index="index" open="(" close=")" separator=",">
                #{userId}
            </foreach>
        </if>
        <if test="request.trainIdList!=null and request.trainIdList.size() != 0">
            AND `TRAIN_ID` IN
            <foreach collection="request.trainIdList" item="trainId" index="index" open="(" close=")" separator=",">
                #{trainId}
            </foreach>
        </if>
        <if test="request.trainCarriageIdList!=null and request.trainCarriageIdList.size() != 0">
            AND `TRAIN_CARRIAGE_ID` IN
            <foreach collection="request.trainCarriageIdList" item="carriageId" index="index" open="(" close=")" separator=",">
                #{carriageId}
            </foreach>
        </if>
        <if test="request.type  != null">AND `TYPE`=#{ request.type }</if>
        <if test="request.type  == null">AND `TYPE`= 'LAID_ON'</if>
    </sql>
    <select id="findLineTrainCount" resultType="java.lang.Long">
        select COUNT(1) from (
          select TRAIN_LINE_ID,TRAIN_ID,TRAIN_CARRIAGE_ID  from rw_escort_attendance where id in (select max(id) from rw_escort_attendance  GROUP BY USER_ID  )
          AND `DATE_ID`=#{ request.dateId } AND TYPE='LAID_ON'
          GROUP BY TRAIN_ID,TRAIN_CARRIAGE_ID
        ) t
    </select>

    <select id="findLineTrain" resultMap="escortAttendancePO">
       select TRAIN_LINE_ID,TRAIN_ID,TRAIN_CARRIAGE_ID  from rw_escort_attendance where id in (select max(id) from rw_escort_attendance  GROUP BY USER_ID  )
       AND `DATE_ID`=#{ request.dateId } AND TYPE='LAID_ON'
       GROUP BY TRAIN_ID,TRAIN_CARRIAGE_ID
    </select>
    <select id="findDistinctTrainCount" resultType="java.lang.Long">
        select COUNT(1) from rw_escort_attendance where id in (select max(id) from rw_escort_attendance  GROUP BY TRAIN_ID  )
        <if test="request.dateId  != null">AND `DATE_ID`=#{ request.dateId }</if>
    </select>

    <select id="findDistinctTrain" resultMap="escortAttendancePO">
        select * from rw_escort_attendance where id in (select max(id) from rw_escort_attendance  GROUP BY TRAIN_ID  )
        <if test="request.dateId  != null">AND `DATE_ID`=#{ request.dateId }</if>
    </select>

    <select id="findDistinct" resultMap="escortAttendancePO">
        select * from rw_escort_attendance where id in (select max(id) from rw_escort_attendance  GROUP BY USER_ID  )
        <include refid="whereForDistinctFindList" />
    </select>
    <select id="findDistinctCount" resultType="java.lang.Long">
        select count(1) from rw_escort_attendance where id in (select max(id) from rw_escort_attendance  GROUP BY USER_ID  )
        <include refid="whereForDistinctFindList" />
    </select>

    <select id="findEscortTime" resultType="java.lang.Long">
        select SUM(ESCORT_TIME) from rw_escort_attendance
        where USER_ID= #{ request.userId }
        <if test="request.dateId  != null">AND `DATE_ID`=#{ request.dateId }</if>
        and TYPE ='LAID_OFF'
    </select>

    <select id="find" resultMap="escortAttendancePO">
        SELECT
            <include refid="entityColumnList"/>
        FROM
            `RW_ESCORT_ATTENDANCE`
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            <include refid="whereForFindList" />
        ORDER BY LAID_TIME DESC
        <if test="request.pageSize !=0">
            LIMIT #{ request.beginItemIndex }, #{ request.pageSize }
        </if>
    </select>

    <select id="findCount" resultType="java.lang.Long">
        SELECT
           COUNT(1)
        FROM
            `RW_ESCORT_ATTENDANCE`
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            <include refid="whereForFindList" />
    </select>

    <select id="findCountTrain" resultType="java.lang.Long">
        SELECT
        COUNT(*)
        FROM
        (SELECT
        TRAIN_ID
        FROM
        rw_escort_attendance
        WHERE
        `IS_DELETED` = 0
        AND `TENANT_ID`=#{ passport.tenantId }
        <include refid="whereForFindList"/>
        GROUP BY TRAIN_ID
        )t
    </select>

    <select id="findCountTrains" resultType="java.lang.Long">
        SELECT COUNT(1) FROM(
            SELECT COUNT(1) FROM
                (SELECT t.TRAIN_LINE_ID,t.TRAIN_ID FROM (
                SELECT USER_ID,TRAIN_LINE_ID,TRAIN_ID FROM rw_escort_attendance_log
                WHERE ID IN (
                                SELECT
                        max(id)
                        FROM
                        rw_escort_attendance_log
                                GROUP BY USER_ID
                )
                )T
                INNER JOIN (SELECT * FROM rw_escort_attendance WHERE ID IN (SELECT
                        max(id)
                        FROM
                        rw_escort_attendance
                                GROUP BY USER_ID)
                                AND `IS_DELETED` = 0
                                AND `TENANT_ID`=#{ passport.tenantId }
                                AND `TYPE`=#{ request.type })A ON A.USER_ID = T.USER_ID
                )s
            GROUP BY s.TRAIN_LINE_ID,s.TRAIN_ID
        )r

    </select>

    <select id="findCountTrainCarriage" resultType="java.lang.Long">
        SELECT
        COUNT(*)
        FROM
        rw_escort_attendance
        WHERE
        id IN (
        SELECT
        max(id)
        FROM
        rw_escort_attendance
        GROUP BY
        TRAIN_ID,TRAIN_CARRIAGE_ID
        )
        AND `IS_DELETED`=0
        AND `TENANT_ID`=#{ passport.tenantId }
        <include refid="whereForFindList"/>
    </select>

    <select id="search" resultMap="escortAttendancePO">
        SELECT
            <include refid="entityColumnList"/>
        FROM
            `RW_ESCORT_ATTENDANCE`
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            <if test="request.keyword !=null">
                <include refid="whereForSearchList" />
            </if>
        <if test="request.pageSize !=0">
            LIMIT #{ request.beginItemIndex }, #{ request.pageSize }
        </if>
    </select>

    <select id="searchCount" resultType="java.lang.Long">
        SELECT
           COUNT(1)
        FROM
            `RW_ESCORT_ATTENDANCE`
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            <if test="request.keyword !=null">
                <include refid="whereForSearchList" />
            </if>
    </select>

    <select id="existByCode" resultType="java.lang.Long">
        SELECT
           COUNT(1)
        FROM
            `RW_ESCORT_ATTENDANCE`
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            AND `ID` != #{id}
            AND `CODE` = #{code}
    </select>

    <update id="update">
        UPDATE
            `RW_ESCORT_ATTENDANCE`
        SET
        <if test="request.userId!=null">
            `USER_ID`=#{ request.userId },
        </if>
        <if test="request.userName!=null">
            `USER_NAME`=#{ request.userName },
        </if>
        <if test="request.type!=null">
            `TYPE`=#{ request.type },
        </if>
        <if test="request.dateId!=null">
            `DATE_ID`=#{ request.dateId },
        </if>
        <if test="request.laidTime!=null">
            `LAID_TIME`=#{ request.laidTime },
        </if>
        <if test="request.escortTime!=null">
            `ESCORT_TIME`=#{ request.escortTime },
        </if>
        <if test="request.laidLocation!=null">
            `LAID_LOCATION`=#{ request.laidLocation },
        </if>
        <if test="request.trainId!=null">
            `TRAIN_ID`=#{ request.trainId },
        </if>
        <if test="request.trainGroupId!=null">
            `TRAIN_GROUP_ID`=#{ request.trainGroupId },
        </if>
        <if test="request.trainLineId!=null">
            `TRAIN_LINE_ID`=#{ request.trainLineId },
        </if>
        <if test="request.trainCarriageId!=null">
            `TRAIN_CARRIAGE_ID`=#{ request.trainCarriageId },
        </if>
        <if test="request.trainDoorId!=null">
            `TRAIN_DOOR_ID`=#{ request.trainDoorId },
        </if>
        <if test="request.currentStation!=null">
            `CURRENT_STATION`=#{ request.currentStation },
        </if>
        <if test="request.nextStation!=null">
            `NEXT_STATION`=#{ request.nextStation },
        </if>
        <if test="request.positionFlag!=null">
            `POSITION_FLAG`=#{ request.positionFlag },
        </if>
            `LAST_UPDATED_BY`=#{ passport.userId },
            `LAST_UPDATE_TIME`=SYSDATE(),
            `ROW_VERSION`=#{ request.rowVersion }+1
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            AND `ID` = #{ request.id }
            AND `ROW_VERSION` = #{ request.rowVersion }
    </update>

    <select id="getRailwayPartyBranchRankNumber" resultMap="railwayPartyBranchRankNumberPO">
        SELECT SUM(ESCORT_TIME) time,USER_ID ATTRIBUTE,USER_NAME NAME
        FROM
        `RW_ESCORT_ATTENDANCE`
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
        GROUP BY USER_ID
        ORDER BY time desc
    </select>

    <select id="getRailwayUserLaidDetail" resultMap="escortAttendancePO">
        SELECT
        <include refid="entityColumnList"/>
        FROM
        `RW_ESCORT_ATTENDANCE`
        WHERE
        `IS_DELETED`=0
        AND `TENANT_ID`=#{ passport.tenantId }
        AND ID in (
                SELECT MAX(ID)
                FROM RW_ESCORT_ATTENDANCE
                GROUP BY USER_ID
        )
        ORDER BY LAID_TIME DESC
        <if test="request.pageSize !=0">
            LIMIT #{ request.beginItemIndex }, #{ request.pageSize }
        </if>
    </select>

    <select id="getDiffLinesTrainsEscortsNumberPercent" resultMap="diffLinesTrainsEscortCountPO">
        SELECT COUNT(1) COUNT,r.TRAIN_LINE_ID FROM(
        SELECT s.TRAIN_LINE_ID,s.TRAIN_ID FROM
        (SELECT t.TRAIN_LINE_ID,t.TRAIN_ID FROM (
        SELECT USER_ID,TRAIN_LINE_ID,TRAIN_ID FROM rw_escort_attendance_log
        WHERE ID IN (
        SELECT
        TRAIN_LINE_ID,TRAIN_ID
        FROM
        rw_escort_attendance
        WHERE
        id IN (
        SELECT
        max(id)
        FROM
        rw_escort_attendance
        GROUP BY
        TRAIN_LINE_ID,TRAIN_ID
        )
        AND `IS_DELETED` = 0
        AND `TENANT_ID` = #{ passport.tenantId }
        <if test="request.type  != null">AND `TYPE`=#{ request.type }</if>
        )T
        GROUP BY TRAIN_LINE_ID
    </select>
    <select id="getDiffLinesTrainsCarriageEscortsNumberPercent" resultMap="diffLinesTrainsEscortCountPO">
        SELECT COUNT(1) COUNT,TRAIN_LINE_ID
        FROM
        (SELECT TRAIN_LINE_ID,TRAIN_ID,TRAIN_CARRIAGE_ID
                FROM
        (
		SELECT LTC.USER_ID,LTC.TRAIN_ID,LTC.TRAIN_LINE_ID,LTC.TRAIN_CARRIAGE_ID from
        (
            SELECT
            USER_ID,TRAIN_LINE_ID,TRAIN_ID,TRAIN_CARRIAGE_ID,IS_DELETED,TENANT_ID
            FROM
            RW_ESCORT_ATTENDANCE_LOG
            WHERE
            id IN (
            SELECT
            max(id)
            FROM
            RW_ESCORT_ATTENDANCE_LOG
            GROUP BY
            USER_ID
						)
        ) LTC
        LEFT  JOIN (
          SELECT
            USER_ID,TRAIN_LINE_ID,TRAIN_ID,TRAIN_CARRIAGE_ID,`TYPE`
            FROM
            RW_ESCORT_ATTENDANCE
            WHERE
            id IN (
            SELECT
            max(id)
            FROM
            RW_ESCORT_ATTENDANCE
            GROUP BY
            USER_ID
						)
        ) EA
        ON EA.USER_ID = LTC.USER_ID
				WHERE
        LTC.`IS_DELETED` = 0
        AND LTC.`TENANT_ID` = #{ passport.tenantId }
        AND EA.`TYPE`='LAID_ON'
      ) T
       GROUP BY T.TRAIN_LINE_ID,T.TRAIN_ID,T.TRAIN_CARRIAGE_ID )
      TT GROUP BY TT.TRAIN_LINE_ID;
    </select>

</mapper>