DutyRosterPlanSMapper.xml 7.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.zteits.park.mapper.smapper.DutyRosterPlanSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.park.domain.DutyRosterPlan">
        <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="plan_name" jdbcType="VARCHAR" property="planName" />
        <result column="effect_time" jdbcType="TIMESTAMP" property="effectTime" />
        <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
        <result column="employee_num" jdbcType="INTEGER" property="employeeNum" />
        <result column="pl_num" jdbcType="INTEGER" property="plNum" />
        <result column="duty_cycle" jdbcType="INTEGER" property="dutyCycle" />
        <result column="berth_range_num" jdbcType="INTEGER" property="berthRangeNum" />
        <result column="rest_type" jdbcType="VARCHAR" property="restType" />
        <result column="area_manage_type" jdbcType="INTEGER" property="areaManageType" />
        <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, plan_name, effect_time, expire_time, employee_num,
        pl_num, duty_cycle, berth_range_num, rest_type, area_manage_type, data_status, create_time,
        create_op, modify_time, modify_op
    </sql>




  <select id="queryDutyPlanMaxDutyDay"  resultType="com.zteits.park.domain.bean.DutyRosterPlanDO">
      SELECT
          a.plan_id AS planId,
          a.plan_name AS planName,
          a.duty_cycle AS dutyCycle,
          b.duty_day AS dutyDay
      FROM
      duty_roster_plan a
      LEFT JOIN (
              SELECT
              c.plan_id,
              max(c.duty_day) AS duty_day
              FROM
              duty_roster c
              WHERE
              c.data_status = 1
              GROUP BY
              c.plan_id
              ) b ON a.plan_id = b.plan_id
      WHERE
      1 = 1
      AND a.data_status = 1
       <![CDATA[and a.effect_time <= now()
        and a.expire_time >= now()]]>
      <if test="dutyType != null">
          and a.duty_type = #{dutyType}
      </if>
      GROUP BY
      a.plan_id,
      a.plan_name,
      a.duty_cycle,
      b.duty_day
  </select>

    <select id="queryPlanIdOfEffectDutyRosterPlan" resultType="java.lang.Long">
        SELECT DISTINCT t.plan_id
        FROM duty_roster_plan t
        WHERE  t.expire_time &gt; now() AND data_status = 1
        <if test="dutyType != null">
            and t.duty_type = #{dutyType}
        </if>

    </select>

    <update id="decreasePlNumFromRosterPlan">
        UPDATE duty_roster_plan
        <set>
            <if test="plNum != 0 ">
                pl_num = (
                CASE
                WHEN (pl_num - #{plNum})  > 0  THEN  (pl_num - #{plNum})
                ELSE 1
                END
                ),
            </if>
            <if test="chargerNum != 0 ">
                employee_num = #{chargerNum}
            </if>
        </set>
        WHERE
        1=1
        and plan_id = #{planId}
    </update>

    <update id="updatePlNumAndEmployeeNumForRosterPlan" parameterType="com.zteits.clouds.api.dto.park.param.dutyroster.DutyRosterForAddRosterInfoReq">
        update duty_roster_plan
        <set>
            <if test="employeeNum != null">
                employee_num = #{employeeNum,jdbcType=INTEGER},
            </if>

            <if test="plNum != null">
                pl_num = #{plNum,jdbcType=INTEGER}
            </if>
        </set>
        where data_status = 1
        and plan_id = #{planId}
    </update>

</mapper>