Newer
Older
huludao / src / main / resources / mapper / EventsManage / DivisionOrgDao.xml
<?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.newfiber.api.pc.dao.EventsManage.DivisionOrgDao" >
  <resultMap id="BaseResultMap" type="com.newfiber.api.pc.model.EventsManage.DivisionOrg" >
    <id column="Serial" property="serial" jdbcType="BIGINT" />
    <result column="Division_No" property="divisionNo" jdbcType="VARCHAR" />
    <result column="Org_No" property="orgNo" jdbcType="VARCHAR" />
    <result column="Create_User_No" property="createUserNo" jdbcType="VARCHAR" />
    <result column="Create_Time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <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 collection="criterion.value" item="listItem" open="(" close=")" 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="(" suffix=")" prefixOverrides="and" >
            <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 collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    <if test="fields == null" >
      Serial, Division_No, Org_No, Create_User_No, Create_Time
    </if>
    <if test="fields != null" >
      ${fields}
    </if>
  </sql>


  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.newfiber.api.pc.model.EventsManage.DivisionOrgQuery" >
    select DISTINCT
    m.Serial,
    m.Division_No,
    m.Org_No,
    m.Create_User_No,
    DATE_FORMAT(m.Create_Time,'%Y-%m-%d %T') formatTime,
    o.Org_Name orgName
    from division_org_manage m INNER JOIN huludao_main.sys_organization o
    ON m.Org_No=o.Org_No
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="startRow != null" >
      ORDER BY Serial limit #{startRow},#{pageSize}
    </if>
  </select>



  <delete id="deleteByExample" parameterType="com.newfiber.api.pc.model.EventsManage.DivisionOrgQuery" >
    delete from division_org_manage
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>


  <insert id="insertSelective" parameterType="com.newfiber.api.pc.model.EventsManage.DivisionOrg" >
    insert into division_org_manage
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="serial != null" >
        Serial,
      </if>
      <if test="divisionNo != null" >
        Division_No,
      </if>
      <if test="orgNo != null" >
        Org_No,
      </if>
      <if test="createUserNo != null" >
        Create_User_No,
      </if>
      <if test="createTime != null" >
        Create_Time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="serial != null" >
        #{serial,jdbcType=BIGINT},
      </if>
      <if test="divisionNo != null" >
        #{divisionNo,jdbcType=VARCHAR},
      </if>
      <if test="orgNo != null" >
        #{orgNo,jdbcType=VARCHAR},
      </if>
      <if test="createUserNo != null" >
        #{createUserNo,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>


  <select id="countByExample" parameterType="com.newfiber.api.pc.model.EventsManage.DivisionOrgQuery" resultType="java.lang.Integer" >
    select count(*) from division_org_manage
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update division_org_manage
    <set >
      <if test="record.serial != null" >
        Serial = #{record.serial,jdbcType=BIGINT},
      </if>
      <if test="record.divisionNo != null" >
        Division_No = #{record.divisionNo,jdbcType=VARCHAR},
      </if>
      <if test="record.orgNo != null" >
        Org_No = #{record.orgNo,jdbcType=VARCHAR},
      </if>
      <if test="record.createUserNo != null" >
        Create_User_No = #{record.createUserNo,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null" >
        Create_Time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>


  <!--根据用户编号查询出直属区域-->
  <select id="getDivisionNoByUserNo" parameterType="String" resultType="com.newfiber.api.pc.model.EventsManage.AdministrativeDivision">
      SELECT
      DISTINCT
        do.Division_No divisionNo,
        a.Division_Name divisionName
        FROM division_org_manage do
        <if test="userNo != null">
          INNER JOIN huludao_main.sys_user_org uo ON uo.Org_No=do.Org_No
        </if>

      INNER JOIN administrative_division a ON do.Division_No=a.Division_No
    <choose>
      <when test="userNo != null">
        WHERE uo.User_No=#{userNo}
      </when>
      <otherwise>
        WHERE a.Parent_Division_No ='0'
      </otherwise>
    </choose>


  </select>
  
  <select id="getUserNoByDivisionNo" parameterType="String" resultType="String">
    SELECT
      DISTINCT
        uo.User_No
        FROM division_org_manage do INNER JOIN huludao_main.sys_user_org uo ON uo.Org_No=do.Org_No
        WHERE do.Division_No IN
        <foreach collection="divisions" item="divisionNo" open="(" close=")" separator=",">
          #{divisionNo}
        </foreach>
  </select>

  <!--根据角色编号以及区划编号获取机构信息-->
  <select id="getOrgByDivisionNoAndRoleNo" parameterType="String" resultMap="BaseResultMap">
      SELECT
      DISTINCT
        dm.Org_No orgNo,
        o.Org_Name orgName
      FROM huludao_main.sys_role_org RO
      INNER JOIN division_org_manage dm ON RO.Org_No=dm.Org_No
      INNER JOIN huludao_main.sys_organization o ON o.Org_No=dm.Org_No
      WHERE ro.Role_No=#{roleNo} AND dm.Division_No=#{divisionNo}
  </select>

  <select id="selectChiefOrgByDivisionNo" parameterType="String" resultMap="BaseResultMap">
    SELECT
    o.Org_Name orgName,
    o.Org_No orgNo
    FROM division_org_manage do INNER JOIN huludao_main.sys_organization o
    ON o.Org_No=do.Org_No
    WHERE do.Division_No=#{divisionNo}
    <choose>
      <when test="type==1">
        AND o.Org_Name LIKE '%治水办%'
      </when>
      <otherwise>
        AND o.Org_Name LIKE '%管理处%'
      </otherwise>
    </choose>
  </select>

  <select id="getUsersByDivisionNo" parameterType="string" resultType="com.newfiber.api.pc.model.UserManager.UserInfo">
    SELECT d.user_name,d.User_No userNo FROM division_org_manage a
  INNER JOIN huludao_main.sys_organization b ON a.Org_No  = b.Org_No
INNER JOIN huludao_main.sys_user_org c ON b.Org_No = c.Org_No
INNER JOIN  huludao_main.sys_user_info d ON c.User_No = d.User_No
WHERE a.Division_No = #{divisionNo}
AND d.User_No NOT IN (SELECT Chief_User_No FROM river_chief )


  </select>
  
  <select id="getChildDivisionNos" parameterType="String" resultType="String">
    select distinct Division_No from administrative_division
    where FIND_IN_SET(Division_No,getChildrenDivision(#{divisionNo}))
  </select>
  
  <select id="getChildDivisionNoByUser" parameterType="String" resultType="String">
    <choose>
      <when test="userNo != null">
        select DISTINCT Division_No from administrative_division where Parent_Division_No in(
        select c.Division_No from huludao_main.sys_user_org a,division_org_manage b,administrative_division c where a.Org_No = b.Org_No and b.Division_No = c.Division_No and a.User_No = #{userNo}
        )
        union all
        select DISTINCT c.Division_No from huludao_main.sys_user_org a,division_org_manage b,administrative_division c where a.Org_No = b.Org_No and b.Division_No = c.Division_No and a.User_No = #{userNo}
      </when>
      <otherwise>
        select DISTINCT Division_No from administrative_division where Parent_Division_No in (
        select  Division_No from administrative_division where Parent_Division_No = '0')
        union all
        select DISTINCT Division_No from administrative_division where Parent_Division_No = '0'
      </otherwise>
    </choose>
  </select>

</mapper>