DutyRosterBaseSMapper.xml 8.78 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.park.mapper.smapper.DutyRosterBaseSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.park.domain.DutyRosterBase">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="org_id" jdbcType="BIGINT" property="orgId" />
        <result column="plan_id" jdbcType="BIGINT" property="planId" />
        <result column="duty_type" jdbcType="INTEGER" property="dutyType" />
        <result column="charger_code" jdbcType="VARCHAR" property="chargerCode" />
        <result column="charger_name" jdbcType="VARCHAR" property="chargerName" />
        <result column="day_num" jdbcType="INTEGER" property="dayNum" />
        <result column="duty_cycle" jdbcType="INTEGER" property="dutyCycle" />
        <result column="is_rest" jdbcType="INTEGER" property="isRest" />
        <result column="pl_no" jdbcType="VARCHAR" property="plNo" />
        <result column="pl_name" jdbcType="VARCHAR" property="plName" />
        <result column="berth_range_no" jdbcType="VARCHAR" property="berthRangeNo" />
        <result column="berth_range_name" jdbcType="VARCHAR" property="berthRangeName" />
        <result column="group_id" jdbcType="BIGINT" property="groupId" />
        <result column="group_name" jdbcType="VARCHAR" property="groupName" />
        <result column="group_start_time" jdbcType="TIME" property="groupStartTime" />
        <result column="group_end_time" jdbcType="TIME" property="groupEndTime" />
        <result column="data_status" jdbcType="INTEGER" property="dataStatus" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="create_op" jdbcType="BIGINT" property="createOp" />
        <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
        <result column="modify_op" jdbcType="BIGINT" property="modifyOp" />
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        id, org_id, plan_id, duty_type, charger_code, charger_name, day_num, duty_cycle,
        is_rest, pl_no, pl_name, berth_range_no, berth_range_name, group_id, group_name,
        group_start_time, group_end_time, data_status, create_time, create_op, modify_time,
        modify_op
    </sql>
    <insert id="moveTempToBase">

        INSERT INTO duty_roster_base (org_id, plan_id,duty_type, charger_code, charger_name, day_num, duty_cycle, is_rest, pl_no,
                                      pl_name, berth_range_no, berth_range_name, group_id, group_name, group_start_time,
                                      group_end_time, data_status, create_time, create_op, modify_time, modify_op)
            SELECT
                org_id,
                plan_id,
                duty_type,
                charger_code,
                charger_name,
                day_num,
                duty_cycle,
                is_rest,
                pl_no,
                pl_name,
                berth_range_no,
                berth_range_name,
                group_id,
                group_name,
                group_start_time,
                group_end_time,
                data_status,
                create_time,
                create_op,
                modify_time,
                modify_op
            FROM duty_roster_base_temp temp
            WHERE data_status = 1 AND temp.org_id = #{orgId} AND temp.plan_id = #{planId}
              <if test="null != dutyType">
                  AND temp.duty_type = #{dutyType}
              </if>


    </insert>

    <select id="queryHasDutyRosterParkLot" resultType="java.lang.String">
        SELECT DISTINCT pl_no
        FROM duty_roster_base
        WHERE data_status = 1 AND org_id = #{orgId}
        <if test="null != plNos and plNos.size > 0 ">
            AND pl_no IN
            <foreach collection="plNos" close=")" open="(" separator="," item="plNo">
                #{plNo}
            </foreach>

        </if>

        <if test="null != dutyType">
            AND duty_type = #{dutyType}
        </if>


    </select>


    <select id="queryChargersByPlNos" resultType="java.lang.String">
        SELECT DISTINCT charger_code
        FROM duty_roster_base
        WHERE data_status = 1 AND org_id = #{orgId}
        <if test="null != plNos and plNos.size > 0 ">
            AND pl_no IN
            <foreach collection="plNos" close=")" open="(" separator="," item="plNo">
                #{plNo}
            </foreach>

        </if>

        <if test="null != dutyType">
            AND duty_type = #{dutyType}
        </if>


    </select>
    <select id="queryBerthRangeNoByOrgId" resultType="java.lang.String">
        SELECT
            DISTINCT berth_range_no
        FROM duty_roster_base
        WHERE org_id = #{orgId}
          AND data_status = 1
        <if test="null != dutyType">
            and duty_type = #{dutyType}
        </if>

    </select>

    <update id="exchangeDutyRoster" parameterType="com.zteits.clouds.api.dto.park.param.dutyroster.DutyRosteExchangeReq">

        UPDATE duty_roster_base a, duty_roster_base b
        SET
            a.charger_code = b.charger_code,
            a.charger_name = b.charger_name,
            b.charger_code = a.charger_code,
            b.charger_name = a.charger_name
        WHERE
            a.charger_code = #{souceChargerCode}
          AND b.charger_code = #{targetChargerCode}
        <if test="null != dutyType">
            and a.duty_type = #{dutyType}
            and b.duty_type = #{dutyType}
        </if>

    </update>

    <select id="queryHaveChargerNumForUpdatePlan" resultType="java.lang.Integer">
        select count(charger_code)
        from
            (
                SELECT charger_code FROM duty_roster_base WHERE data_status = 1 AND plan_id = #{planId}
                GROUP BY charger_code
            ) y
    </select>
</mapper>