UserMapperAuto.xml 4.84 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="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="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>

    <sql id="entityColumnList">
         `ID`, `TENANT_ID`, `IS_PARTY_MEMBER`, `PARTY_ID`,COMPANY_ID, `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 },
        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 },
            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 ID,ru.ROW_VERSION ROW_VERSION,ru.IS_PARTY_MEMBER IS_PARTY_MEMBER,ru.PARTY_ID PARTY_ID,rc.`CODE` COMPANY_CODE,
          rc.`NAME` COMPANY_NAME,ro.`CODE` PARTY_CODE,ro.`NAME` PARTY_NAME
        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.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>
</mapper>