EventMapperAuto.xml 10.4 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.EventMapper">

    <resultMap id="eventPO" type="com.xiniunet.service.railway.po.EventPO">
        
        <id column="ID" jdbcType="NUMERIC" property="id"/>
        <result column="TENANT_ID" jdbcType="NUMERIC" property="tenantId"/>
        <result column="USER_ID" jdbcType="NUMERIC" property="userId"/>
        <result column="TYPE" jdbcType="VARCHAR" property="type"/>
        <result column="DESCRIPTION" jdbcType="VARCHAR" property="description"/>
        <result column="DATE_ID" jdbcType="VARCHAR" property="dateId"/>
        <result column="EVENT_TIME" jdbcType="TIMESTAMP" property="eventTime"/>
        <result column="EVENT_LOCATION" jdbcType="VARCHAR" property="eventLocation"/>
        <result column="STATION" jdbcType="VARCHAR" property="station"/>
        <result column="NEXT_STATION" jdbcType="VARCHAR" property="nextStation"/>
        <result column="IS_STATUS" jdbcType="TINYINT" property="isStatus"/>
        <result column="IS_HANDLED" jdbcType="TINYINT" property="isHandled"/>
        <result column="HANDLE_SUGGESTION" jdbcType="VARCHAR" property="handleSuggestion"/>
        <result column="APP_EVENT_ID" jdbcType="VARCHAR" property="appEventId"/>
        <result column="LINE_ID" jdbcType="VARCHAR" property="lineId"/>
        <result column="LINE_NAME" jdbcType="VARCHAR" property="lineName"/>
        <result column="CARRIAGE_NUMBER" jdbcType="VARCHAR" property="carriageNumber"/>
        <result column="STATION_ID" jdbcType="VARCHAR" property="stationId"/>
        <result column="TITLE" jdbcType="VARCHAR" property="title"/>
        <result column="TYPE1_ID" jdbcType="VARCHAR" property="type1Id"/>
        <result column="TYPE2_ID" jdbcType="VARCHAR" property="type2Id"/>
        <result column="TYPE3_ID" jdbcType="VARCHAR" property="type3Id"/>
        <result column="DETAILED" jdbcType="VARCHAR" property="detailed"/>
        <result column="TYPE1_NAME" jdbcType="VARCHAR" property="type1Name"/>
        <result column="TYPE2_NAME" jdbcType="VARCHAR" property="type2Name"/>
        <result column="TYPE3_NAME" jdbcType="VARCHAR" property="type3Name"/>
        <result column="GRADE_ID" jdbcType="VARCHAR" property="gradeId"/>
        <result column="GRADE_NAME" jdbcType="VARCHAR" property="gradeName"/>
        <result column="HAPPEN_TIME" jdbcType="VARCHAR" property="happenTime"/>
        <result column="COMMIT_TIME" jdbcType="VARCHAR" property="commitTime"/>
        <result column="NEXT_STATION_ID" jdbcType="VARCHAR" property="nextStationId"/>
        <result column="GA_FLAG" jdbcType="VARCHAR" property="gaFlag"/>
        <result column="APP_ATTACHEMENT_ADDRESS1" jdbcType="VARCHAR" property="appAttachementAddress1"/>
        <result column="APP_ATTACHEMENT_ADDRESS2" jdbcType="VARCHAR" property="appAttachementAddress2"/>
        <result column="APP_ATTACHEMENT_ADDRESS3" jdbcType="VARCHAR" property="appAttachementAddress3"/>
        <result column="ROW_VERSION" jdbcType="NUMERIC" property="rowVersion"/>
        <result column="IS_DELETED" jdbcType="TINYINT" property="isDeleted"/>
        <result column="CREATED_BY" jdbcType="NUMERIC" property="createdBy"/>
        <result column="CREATION_TIME" jdbcType="TIMESTAMP" property="creationTime"/>
        <result column="LAST_UPDATED_BY" jdbcType="NUMERIC" property="lastUpdatedBy"/>
        <result column="LAST_UPDATE_TIME" jdbcType="TIMESTAMP" property="lastUpdateTime"/>
    </resultMap>

    <resultMap id="eventCountPO" type="com.xiniunet.service.railway.po.EventCountPO">
        <result column="EVENT_COUNT" jdbcType="NUMERIC" property="eventCount"/>
        <result column="EFFECTIVE_NUMBER" jdbcType="NUMERIC" property="effectiveNumber"/>
    </resultMap>

    <sql id="entityColumnList">
         `ID`,`APP_EVENT_ID`,`LINE_ID`,`LINE_NAME`,`CARRIAGE_NUMBER`,`TENANT_ID`,`USER_ID`,`TYPE`,`TITLE`,`TYPE1_ID`,`TYPE2_ID`,`TYPE3_ID`,`TYPE1_NAME`,`TYPE2_NAME`,`TYPE3_NAME`,`GRADE_ID`,`GRADE_NAME`,`HAPPEN_TIME`,`COMMIT_TIME`,`DESCRIPTION`,`DATE_ID`,`EVENT_TIME`,`EVENT_LOCATION`,`STATION_ID`,`STATION`,`NEXT_STATION_ID`,`NEXT_STATION`,`GA_FLAG`, `IS_HANDLED`, `IS_STATUS`,`HANDLE_SUGGESTION`,`APP_ATTACHEMENT_ADDRESS1`,`APP_ATTACHEMENT_ADDRESS2`,`APP_ATTACHEMENT_ADDRESS3`,`ROW_VERSION`,`IS_DELETED`, `CREATED_BY`, `CREATION_TIME`,`LAST_UPDATED_BY`, `LAST_UPDATE_TIME`, `DETAILED`
    </sql>

    <insert id="insert">
        INSERT INTO
            `RW_EVENT`
            (
            <include refid="entityColumnList" />
            )
        VALUES
        (
        #{ event.id },
        #{ event.appEventId },
        #{ event.lineId },
        #{ event.lineName },
        #{ event.carriageNumber },
        #{ passport.tenantId },
        #{ event.userId },
        #{ event.type },
        #{ event.title },
        #{ event.type1Id },
        #{ event.type2Id },
        #{ event.type3Id },
        #{ event.type1Name },
        #{ event.type2Name },
        #{ event.type3Name },
        #{ event.gradeId },
        #{ event.gradeName },
        #{ event.happenTime },
        #{ event.commitTime },
        #{ event.description },
        #{ event.dateId },
        #{ event.eventTime },
        #{ event.eventLocation },
        #{ event.stationId },
        #{ event.station },
        #{ event.nextStationId },
        #{ event.nextStation },
        #{ event.gaFlag },
        #{ event.isHandled },
        #{ event.isStatus },
        #{ event.handleSuggestion },
        #{ event.appAttachementAddress1 },
        #{ event.appAttachementAddress2 },
        #{ event.appAttachementAddress3 },
        0,0,#{ passport.userId },sysdate(),null,null,#{event.detailed}
        )
    </insert>

    <insert id="insertBatch">
        INSERT INTO
            `RW_EVENT`
            (
            <include refid="entityColumnList" />
            )
        VALUES
        <foreach collection="list" item= "event" index ="index" separator=",">
            (
            #{ event.id },
            #{ event.appEventId },
            #{ event.lineId },
            #{ event.lineName },
            #{ event.carriageNumber },
            #{ passport.tenantId },
            #{ event.userId },
            #{ event.type },
            #{ event.title },
            #{ event.type1Id },
            #{ event.type2Id },
            #{ event.type3Id },
            #{ event.type1Name },
            #{ event.type2Name },
            #{ event.type3Name },
            #{ event.gradeId },
            #{ event.gradeName },
            #{ event.happenTime },
            #{ event.commitTime },
            #{ event.description },
            #{ event.dateId },
            #{ event.eventTime },
            #{ event.eventLocation },
            #{ event.stationId },
            #{ event.station },
            #{ event.nextStationId },
            #{ event.nextStation },
            #{ event.gaFlag },
            #{ event.isHandled },
            #{ event.handleSuggestion },
            #{ event.appAttachementAddress },
            #{ event.appAttachementAddress2 },
            #{ event.appAttachementAddress3 },

            0,0,#{ passport.userId },sysdate(),null,null,#{event.detailed}
            )
        </foreach >
    </insert>


    <update id="delete">
        UPDATE
            `RW_EVENT`
        SET
            `IS_DELETED` = 1
            ,`LAST_UPDATED_BY`=#{ passport.userId }
            ,`LAST_UPDATE_TIME`=SYSDATE()
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            AND `ID` = #{id}
    </update>

    <update id= "deleteBatch">
        UPDATE
            `RW_EVENT`
        SET
            `IS_DELETED` = 1
            ,`LAST_UPDATED_BY`=#{ passport.userId }
            ,`LAST_UPDATE_TIME`=SYSDATE()
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            AND `ID` in
        <foreach collection="list" item= "id" index ="index" open= "(" close =")" separator=",">
            #{id}
        </foreach >
    </update >


    <select id="getById" resultMap="eventPO">
        SELECT
            <include refid="entityColumnList" />
        FROM
            `RW_EVENT`
        WHERE
            `IS_DELETED` = 0
            AND `ID` = #{id}
            AND `TENANT_ID`=#{ passport.tenantId }
    </select>
    <select id="getByEventId" resultMap="eventPO">
        SELECT
        <include refid="entityColumnList" />
        FROM
        `RW_EVENT`
        WHERE
        `IS_DELETED` = 0
        AND `APP_EVENT_ID` = #{id}
        AND `TENANT_ID`=#{ passport.tenantId }
    </select>
    <select id="getListByIds" resultMap="eventPO">
        SELECT
            <include refid="entityColumnList" />
        FROM
            `RW_EVENT`
        WHERE
        `IS_DELETED` = 0
        AND `ID` in
        <foreach collection="list" item= "id" index ="index" open= "(" close =")" separator=",">
            #{id}
        </foreach >
        
            AND `TENANT_ID`=#{ passport.tenantId }
    </select>

    <select id="getAllList" resultMap="eventPO">
        SELECT
            <include refid="entityColumnList" />
        FROM
            `RW_EVENT`
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
    </select>

    <select id="existById"  resultType="java.lang.Long">
        SELECT
            COUNT(*)
        FROM
            `RW_EVENT`
        WHERE
            `IS_DELETED`=0
            AND `ID`=#{id}
            AND `TENANT_ID`=#{ passport.tenantId }
    </select>

    <select id="getCountByUserId" resultMap="eventCountPO">
        SELECT
            COUNT(1) AS EVENT_COUNT,
            IFNULL(A.EFFECTIVE_NUMBER,0) AS EFFECTIVE_NUMBER
        FROM
            `RW_EVENT` RE
        LEFT JOIN (
            SELECT
                COUNT(1) AS EFFECTIVE_NUMBER,USER_ID
            FROM
                `RW_EVENT`
            WHERE
                `IS_DELETED` = 0
        AND `IS_HANDLED` = 1
        AND `USER_ID` = #{request.userId}
        )A ON A.`USER_ID` = RE.`USER_ID`
        WHERE
            RE.`IS_DELETED` = 0
        AND RE.`USER_ID` = #{request.userId}
        AND RE.`TENANT_ID` = #{ passport.tenantId }
    </select>

    <select id="getListByUserId" resultMap="eventPO">
        SELECT
        <include refid="entityColumnList" />
        FROM
        `RW_EVENT`
        WHERE
        `IS_DELETED` = 0
        AND `USER_ID` = #{userId}
        AND `TENANT_ID`=#{ passport.tenantId }
        ORDER BY HAPPEN_TIME DESC
    </select>
</mapper>