123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?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.dayou.mapper.DepartmentMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.dayou.entity.Department">
- <result column="id" property="id" />
- <result column="deleted" property="deleted" />
- <result column="created" property="created" />
- <result column="modified" property="modified" />
- <result column="parent_id" property="parentId" />
- <result column="name" property="name" />
- <result column="leader_id" property="leaderId" />
- <result column="phone" property="phone" />
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- id,
- deleted,
- created,
- modified,
- parent_id, name, leader_id, phone
- </sql>
- <select id="xPage" parameterType="com.dayou.entity.Department" resultType="com.dayou.vo.DepartmentVO">
- SELECT d.id,d.parent_id,d.name,d.leader_id,d.phone,d.deleted,d.created,d.modified,d.if_allot,
- ( SELECT NAME FROM department WHERE id = d.parent_id ) AS parentName ,
- (select name from user where id = d.leader_id) as leaderName,
- (select count(distinct user_id) from user_post where post_id in ((select id from post where department_id = d.id and user_post.deleted = 0))) as peopleNum
- FROM
- department d where d.deleted = 0
- <if test="department!=null and department.departmentIds!=null and department.departmentIds.size!=0">
- and d.id in
- <foreach collection="department.departmentIds" open="(" close=")" separator="," item="departmentId">
- #{departmentId}
- </foreach>
- </if>
- order by d.id DESC
- </select>
- <select id="getPage" parameterType="com.dayou.entity.Department" resultType="com.dayou.vo.DepartmentVO">
- select d.*,u.name as leaderName from department d left join user u on u.id = d.leader_id
- where d.deleted = 0
- </select>
- <!--根据业务code获取接单部门-->
- <select id="getAllotDepartmentByBusiness" resultType="com.dayou.entity.Department">
- SELECT department.id, department.name
- FROM department,sorted_department
- WHERE department.id = sorted_department.department_id
- AND department.deleted = 0
- AND sorted_department.business_type = #{businessCode}
- </select>
- <!--通过用户id获取部门信息-->
- <select id="getDepartmentByUserId" resultType="java.lang.Long">
- SELECT department_id
- FROM user,user_post,post
- WHERE user.id = user_post.user_id
- AND user_post.post_id = post.id
- AND user_post.deleted = 0
- AND post.deleted = 0
- AND user.id = #{userId}
- LIMIT 1
- </select>
- <!--根据部门id获取部门及其下属部门的id集合-->
- <select id="getDepIdList" resultType="java.lang.Long">
- SELECT DISTINCT
- department.id
- FROM
- ( SELECT department.id FROM department ) AS department
- INNER JOIN (
- SELECT
- id
- FROM
- ( SELECT id, parent_id FROM department WHERE deleted = 0 ORDER BY parent_id, id ) org_query,
- (
- SELECT
- @id := ( SELECT id FROM department WHERE id = #{depId} AND deleted = 0 )) initialisation
- WHERE
- ( FIND_IN_SET( parent_id, @id ) > 0 OR FIND_IN_SET( id, @id ) > 0 )
- AND @id := CONCAT( @id, ',', id )) AS depId ON depId.id = department.id
- </select>
- <!--通过客户经理id获取下单部门-->
- <select id="getManagerDepId" resultType="java.lang.Long">
- SELECT post.department_id
- FROM user,user_post,post
- WHERE user.id = user_post.user_id
- AND user_post.post_id = post.id
- AND user_post.deleted = 0
- AND post.deleted = 0
- AND user.id = #{managerId}
- LIMIT 1
- </select>
- <select id="allotMajor" resultType="com.dayou.vo.MajorDepartmentVO">
- SELECT
- d.id,
- d.NAME,
- o.orderOverStock
- FROM
- (
- SELECT
- id,
- NAME
- FROM
- department
- WHERE
- deleted = 0
- AND NAME IN ( '评估一部', '评估二部', '评估三部' )) d
- LEFT JOIN (
- SELECT
- department_id,
- count(*) AS orderOverStock
- FROM
- major
- WHERE
- id IN (
- SELECT
- business_id
- FROM
- work_flow_node_instance
- WHERE
- flow_id = 6
- AND business_type = 'MAJOR_BUSINESS'
- AND deleted = 0
- AND state = 'PENDING'
- AND node_id IN ( 55, 56, 57, 58, 59 ))
- AND deleted = 0
- AND allot_type = '轮单'
- and created < DATE_SUB(NOW(), INTERVAL 7 DAY)
- GROUP BY
- department_id
- ) o ON d.id = o.department_id
- ORDER BY
- d.id
- </select>
- </mapper>
|