UserMapperAuto.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.UserMapper">

    <resultMap id="userPO" type="com.xiniunet.service.railway.po.UserPO">
        
        <id column="ID" jdbcType="NUMERIC" property="id"/>
        <result column="TENANT_ID" jdbcType="NUMERIC" property="tenantId"/>
        <result column="IS_PARTY_MEMBER" jdbcType="TINYINT" property="isPartyMember"/>
        <result column="POLITICAL_STATUS" jdbcType="NUMERIC" property="politicalStatus"/>
        <result column="PERMISSION_ID" jdbcType="NUMERIC" property="permissionId"/>
        <result column="ACCOUNT" jdbcType="VARCHAR" property="account"/>
        <result column="PARTY_ID" jdbcType="NUMERIC" property="partyId"/>
        <result column="PARTY_CODE" jdbcType="VARCHAR" property="partyCode"/>
        <result column="PARTY_NAME" jdbcType="VARCHAR" property="partyName"/>
        <result column="COMPANY_ID" jdbcType="NUMERIC" property="companyId"/>
        <result column="COMPANY_CODE" jdbcType="VARCHAR" property="companyCode"/>
        <result column="COMPANY_NAME" jdbcType="VARCHAR" property="companyName"/>
        <result column="VOLUNTEER_ID" jdbcType="NUMERIC" property="volunteerId"/>
        <result column="VOLUNTEER_CODE" jdbcType="VARCHAR" property="volunteerCode"/>
        <result column="VOLUNTEER_NAME" jdbcType="VARCHAR" property="volunteerName"/>
        <result column="GENDER" jdbcType="VARCHAR" property="gender"/>
        <result column="AGE" jdbcType="INTEGER" property="age"/>
        <result column="EDUCATION" jdbcType="VARCHAR" property="education"/>
        <result column="OCCUPATION" jdbcType="VARCHAR" property="occupation"/>
        <result column="ESCORT_COUNT" jdbcType="NUMERIC" property="escortCount"/>
        <result column="ESCORT_TIME" jdbcType="NUMERIC" property="escortTime"/>
        <result column="IS_EMPLOYEE" jdbcType="TINYINT" property="isEmployee"/>
        <result column="EMPLOYEE_NUMBER" jdbcType="VARCHAR" property="employeeNumber"/>
        <result column="AGE" jdbcType="INTEGER" property="age"/>
        <result column="IS_WEEK_STATUS" jdbcType="NUMERIC" property="isWeekStatus"/>
        <result column="WEEK_ESCORT_COUNT" jdbcType="NUMERIC" property="weekEscortCount"/>
        <result column="WEEK_ESCORT_TIME" jdbcType="NUMERIC" property="weekEscortTime"/>
        <result column="IS_MONTH_STATUS" jdbcType="NUMERIC" property="isMonthStatus"/>
        <result column="MONTH_ESCORT_COUNT" jdbcType="NUMERIC" property="monthEscortCount"/>
        <result column="MONTH_ESCORT_TIME" jdbcType="NUMERIC" property="monthEscortTime"/>
        <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="userListPO" type="com.xiniunet.service.railway.po.UserListPO">

        <id column="ID" jdbcType="NUMERIC" property="id"/>
        <result column="ACCOUNT" jdbcType="VARCHAR" property="account"/>
        <result column="NAME" jdbcType="VARCHAR" property="name"/>
        <result column="IS_PARTY_MEMBER" jdbcType="TINYINT" property="isPartyMember"/>
        <result column="COMPANY_NAME" jdbcType="VARCHAR" property="companyName"/>

        <result column="ESCORT_Time" jdbcType="VARCHAR" property="escortTime"/>
        <result column="ESCORT_COUNT" jdbcType="VARCHAR" property="escortCount"/>
        <result column="EMPLOYEE_NUMBER" jdbcType="VARCHAR" property="employeeNumber"/>
        <result column="GENDER" jdbcType="VARCHAR" property="gender"/>
        <result column="POINTS" jdbcType="VARCHAR" property="points"/>
        <result column="eventCount" jdbcType="VARCHAR" property="eventCount"/>

        <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="userRolePO" type="com.xiniunet.service.railway.po.UserRolePO">

        <id column="ID" jdbcType="NUMERIC" property="id"/>
        <result column="ACCOUNT" jdbcType="VARCHAR" property="account"/>
        <result column="PERMISSION_ID" jdbcType="VARCHAR" property="permissionId"/>
        <result column="NAME" jdbcType="VARCHAR" property="name"/>
        <result column="ROLE_NAME" jdbcType="VARCHAR" property="roleName"/>
        <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="railwayPartyBranchRankNumberPO" type="com.xiniunet.service.railway.po.RailwayPartyBranchRankNumberPO">
        <result column="NUMBER" jdbcType="VARCHAR" property="number"/>
        <result column="NAME" jdbcType="VARCHAR" property="name"/>
        <result column="ATTRIBUTE" jdbcType="VARCHAR" property="attribute"/>
    </resultMap>
    <resultMap id="companyPO" type="com.xiniunet.service.railway.po.CompanyPO">

        <id column="ID" jdbcType="NUMERIC" property="id"/>
        <result column="NAME" jdbcType="VARCHAR" property="name"/>
    </resultMap>

    <resultMap id="stationPO" type="com.xiniunet.service.railway.po.StationPO">

        <id column="STATION_ID" jdbcType="NUMERIC" property="stationId"/>
        <result column="STATION_NAME" jdbcType="VARCHAR" property="stationName"/>
    </resultMap>

    <sql id="entityColumnList">
         `ID`, `TENANT_ID`, `IS_PARTY_MEMBER`, `PARTY_ID`,COMPANY_ID,GENDER,AGE,EDUCATION,OCCUPATION,ESCORT_COUNT,ESCORT_TIME,IS_EMPLOYEE,EMPLOYEE_NUMBER, `ROW_VERSION`,`IS_DELETED`,`CREATED_BY`,`CREATION_TIME`,`LAST_UPDATED_BY`,`LAST_UPDATE_TIME`
    </sql>

    <insert id="insert">
        INSERT INTO
            `RW_USER`
            (
            <include refid="entityColumnList" />
            )
        VALUES
        (
        #{ user.id },
        #{ passport.tenantId },
        #{ user.isPartyMember },
        #{ user.partyId },
        #{ user.companyId },
        #{ user.gender },
        #{ user.age },
        #{ user.education },
        #{ user.occupation },
        #{ user.escortCount },
        #{ user.escortTime },
        #{ user.isEmployee },
        #{ user.employeeNumber },
        0,0,#{ passport.userId },sysdate(),null,null
        )
    </insert>

    <insert id="insertBatch">
        INSERT INTO
            `RW_USER`
            (
            <include refid="entityColumnList" />
            )
        VALUES
        <foreach collection="list" item= "user" index ="index" separator=",">
            (
            #{ user.id },
            #{ passport.tenantId },
            #{ user.isPartyMember },
            #{ user.partyId },
            #{ user.companyId },
            #{ user.gender },
            #{ user.age },
            #{ user.education },
            #{ user.occupation },
            #{ user.escortCount },
            #{ user.escortTime },
            #{ user.isEmployee },
            #{ user.employeeNumber },
            0,0,#{ passport.userId },sysdate(),null,null
            )
        </foreach >
    </insert>


    <update id="delete">
        UPDATE
            `RW_USER`
        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_USER`
        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="userPO">
        SELECT
          ru.ID ,ru.ROW_VERSION ,ru.IS_PARTY_MEMBER ,ru.POLITICAL_STATUS,ru.PARTY_ID ,ru.GENDER,ru.AGE,ru.EDUCATION,ru.OCCUPATION,rc.`CODE` COMPANY_CODE,
          ru.ESCORT_COUNT, ru.ESCORT_TIME,ru.IS_EMPLOYEE,ru.EMPLOYEE_NUMBER,
          rc.`NAME` COMPANY_NAME,ro.`CODE` PARTY_CODE,ro.`NAME` PARTY_NAME,rv.ID AS VOLUNTEER_ID,rv.CODE AS VOLUNTEER_CODE,rv.NAME AS VOLUNTEER_NAME,ru.IS_WEEK_STATUS,
          ru.WEEK_ESCORT_COUNT,ru.WEEK_ESCORT_TIME,ru.IS_MONTH_STATUS,ru.MONTH_ESCORT_COUNT,ru.MONTH_ESCORT_TIME
        FROM
            `RW_USER` ru
        LEFT JOIN railway.rw_company rc ON ru.COMPANY_ID = rc.ID
        LEFT JOIN railway.rw_organization ro ON ru.PARTY_ID = ro.CODE
        LEFT JOIN railway.rw_volunteer rv ON rv.CODE = ru.VOLUNTEER_ID
        WHERE
            ru.`IS_DELETED` = 0
            AND ru.`ID` = #{id}
            AND ru.`TENANT_ID`=#{ passport.tenantId }
    </select>

    <select id="getListByIds" resultMap="userPO">
        SELECT
            <include refid="entityColumnList" />
        FROM
            `RW_USER`
        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="userPO">
        SELECT
            <include refid="entityColumnList" />
        FROM
            `RW_USER`
        WHERE
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
    </select>

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

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

    <update id="updateBatch">
        UPDATE
        `RW_USER`
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="PERMISSION_ID =case"  suffix="end,">
                <foreach collection="list" item="user"  index="index">
                    when ( `ROW_VERSION`=#{user.rowVersion}
                    AND `IS_DELETED`=0
                    AND `ID` = #{user.id}
                    AND `TENANT_ID`=#{passport.tenantId}
                    )
                    then #{user.permissionId}
                </foreach>
            </trim>
            <trim prefix="LAST_UPDATED_BY =case"  suffix="end,">
                <foreach collection="list" item="user"  index="index">
                    WHEN ( `ROW_VERSION`=#{user.rowVersion}
                    AND `IS_DELETED`=0
                    AND `ID` = #{user.id}
                    AND `TENANT_ID`=#{passport.tenantId}
                    )
                    then #{passport.userId}
                </foreach>
            </trim>
            <trim prefix="LAST_UPDATE_TIME =case"  suffix="end,">
                <foreach collection="list" item="user"  index="index">
                    when ( `ROW_VERSION`=#{user.rowVersion}
                    AND `IS_DELETED`=0
                    AND `ID` = #{user.id}
                    AND `TENANT_ID`=#{passport.tenantId}
                    )
                    then SYSDATE()
                </foreach>
            </trim>
            <trim prefix="ROW_VERSION =case"  suffix="end,">
                <foreach collection="list" item="user"  index="index">
                    when ( `ROW_VERSION`=#{user.rowVersion}
                    AND `IS_DELETED`=0
                    AND `ID` = #{user.id}
                    AND `TENANT_ID`=#{passport.tenantId}
                    )
                    then #{user.rowVersion}+1
                </foreach>
            </trim>
        </trim>
        WHERE
        <foreach collection="list" separator="or" item="user" index="index" >
            `IS_DELETED`=0
            AND `TENANT_ID`=#{ passport.tenantId }
            AND `ID` = #{user.id}
            AND `ROW_VERSION`=#{user.rowVersion}
        </foreach>
    </update>

</mapper>