123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- <?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.management.platform.mapper.UserMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.management.platform.entity.User">
- <id column="id" property="id" />
- <result column="name" property="name" />
- <result column="phone" property="phone" />
- <result column="password" property="password" />
- <result column="portrait_url" property="portraitUrl" />
- <result column="create_time" property="createTime" />
- <result column="role" property="role" />
- <result column="company_id" property="companyId" />
- <result column="department_id" property="departmentId" />
- <result column="department_cascade" property="departmentCascade" />
- <result column="cost" property="cost" />
- <result column="month_cost" property="monthCost" />
- <result column="salary_type" property="salaryType" />
- <result column="manage_dept_id" property="manageDeptId" />
- <result column="color" property="color" />
- <result column="is_active" property="isActive" />
- <result column="wx_openid" property="wxOpenid" />
- <result column="role_id" property="roleId" />
- <result column="role_name" property="roleName" />
- <result column="cost_apply_date" property="costApplyDate" />
- <result column="dingding_userid" property="dingdingUserid" />
- <result column="dingding_unionid" property="dingdingUnionid" />
- <result column="corpwx_userid" property="corpwxUserid" />
- <result column="induction_date" property="inductionDate" />
- <result column="inactive_date" property="inactiveDate" />
- <result column="position" property="position" />
- <result column="report_status" property="reportStatus" />
- <result column="superior_id" property="superiorId" />
- <result column="plate1" property="plate1" />
- <result column="plate2" property="plate2" />
- <result column="plate3" property="plate3" />
- <result column="plate4" property="plate4" />
- <result column="plate5" property="plate5" />
- <result column="is_ops" property="isOps" />
- <result column="job_number" property="jobNumber" />
- <result column="corpwx_deptid" property="corpwxDeptid" />
- <result column="corpwx_real_userid" property="corpwxRealUserid" />
- <result column="is_first_login" property="isFirstLogin" />
- <result column="is_mob_first_login" property="isMobFirstLogin" />
- <result column="feishu_userid" property="feishuUserid" />
- <result column="feishu_deptid" property="feishuDeptid" />
- <result column="only_audit_once" property="onlyAuditOnce" />
- </resultMap>
- <resultMap id="BaseResultMap2" type="com.management.platform.entity.User">
- <id column="id" property="id" />
- <result column="name" property="name" />
- <result column="department_id" property="departmentId" />
- <result column="department_name" property="departmentName" />
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- id, name, phone, password, portrait_url, create_time, role, company_id, department_id, department_cascade, cost, month_cost, salary_type, manage_dept_id, color, is_active, wx_openid, role_id, role_name, cost_apply_date, dingding_userid, dingding_unionid, corpwx_userid, induction_date, inactive_date, position, report_status, superior_id, plate1, plate2, plate3, plate4, plate5, is_ops, job_number, corpwx_deptid, corpwx_real_userid, is_first_login, is_mob_first_login, feishu_userid, feishu_deptid, only_audit_once
- </sql>
- <!--单独分页获取人员-->
- <select id="getUserByDepartment" resultType="java.util.Map">
- SELECT a.id, a.role_id as roleId, a.role_name as roleName, a.name, a.phone, a.portrait_url AS portraitUrl, a.role, a.company_id AS companyId, a.cost,
- a.department_id AS departmentId, b.department_name AS departmentName, a.department_cascade AS departmentCascade,a.corpwx_userid as corpwxUserid,
- a.month_cost as monthCost, a.salary_type as salaryType, a.is_active as isActive,date_format(a.`inactive_date`, '%Y-%m-%d') AS inactiveDate, a.cost_apply_date as costApplyDate,a.plate1,a.plate2,a.plate3,a.plate4,a.plate5,
- a.job_number as jobNumber, DATE_FORMAT(a.create_time, '%Y-%m-%d %H:%m') as createTime, c.name as superiorName, c.corpwx_userid as superiorCorpwxUserid
- FROM user AS a
- LEFT JOIN department AS b ON a.department_id = b.department_id
- left join user c on c.id = a.superior_id and c.company_id = #{companyId}
- WHERE a.company_id = #{companyId}
- <if test="corpwxUserIds != null">
- AND a.corpwx_userid in
- <foreach collection="corpwxUserIds" item="corpwxUserid" open="(" close=")" separator=",">
- #{corpwxUserid}</foreach>
- </if>
- <if test="departmentId != null and companyId != ''">
- AND a.department_id = #{departmentId}
- </if>
- <if test="keyword != null and keyword != ''">
- AND
- <choose>
- <when test="matchingType==0">
- a.name like '%${keyword}%'
- </when>
- <when test="matchingType==1">
- a.phone like '%${keyword}%'
- </when>
- <when test="matchingType==2">
- a.job_number like '%${keyword}%'
- </when>
- </choose>
- </if>
- <if test="status != null">
- AND a.is_active = #{status}
- </if>
- <if test="roleId != null">
- AND a.role_id = #{roleId}
- </if>
- </select>
- <!--范围分页获取人员-->
- <select id="getUserByDepartmentList" resultType="java.util.Map">
- SELECT a.id, a.role_id as roleId, a.role_name as roleName, a.name, a.phone, a.portrait_url AS portraitUrl, a.role, a.company_id AS companyId, a.cost,
- a.department_id AS departmentId, b.department_name AS departmentName, a.department_cascade AS departmentCascade,a.corpwx_userid as corpwxUserid,
- a.month_cost as monthCost, a.salary_type as salaryType, a.is_active as isActive,date_format(a.`inactive_date`, '%Y-%m-%d') AS inactiveDate, a.cost_apply_date as costApplyDate,a.plate1,a.plate2,a.plate3,a.plate4,a.plate5,
- a.job_number as jobNumber, DATE_FORMAT(a.create_time, '%Y-%m-%d %H:%m') as createTime, c.name as superiorName, c.corpwx_userid as superiorCorpwxUserid
- FROM user AS a
- LEFT JOIN department AS b ON a.department_id = b.department_id
- left join user c on c.id = a.superior_id and c.company_id = #{companyId}
- WHERE a.company_id = #{companyId} AND a.department_id IN
- <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
- #{departmentId}
- </foreach>
- <if test="keyword != null and keyword != ''">
- AND
- <choose>
- <when test="matchingType==0">
- a.name like '%${keyword}%'
- </when>
- <when test="matchingType==1">
- a.phone like '%${keyword}%'
- </when>
- <when test="matchingType==2">
- a.job_number like '%${keyword}%'
- </when>
- </choose>
- </if>
- <if test="status != null">
- AND a.is_active = #{status}
- </if>
- <if test="roleId != null">
- AND a.role_id = #{roleId}
- </if>
- </select>
- <select id="getPushUserList" resultType="java.util.Map">
- SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid, a.name, a.phone, b.department_name AS departmentName
- FROM user AS a LEFT JOIN department b ON a.department_id = b.department_id
- WHERE a.company_id = #{companyId}
- AND (a.wx_openid IS NOT NULL or corpwx_userid is not null)
- AND a.is_active = 1
- AND a.report_status =0
- <choose>
- <when test="alertType!=null and alertType==1">
- AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` = DATE_FORMAT(date_sub(NOW(),interval 1 day), '%Y-%m-%d'))
- </when>
- <otherwise>
- AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` = DATE_FORMAT(NOW(), '%Y-%m-%d'))
- </otherwise>
- </choose>
- <if test="date != null">
- and not exists (select 1 from leave_sheet where owner_id = a.id and start_date <= #{date} and end_date >= #{date} and leave_sheet.status = 0)
- </if>
- </select>
- <select id="getWeekPushUserList" resultType="java.util.Map">
- SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid, a.name, a.phone, b.department_name AS departmentName
- FROM user AS a LEFT JOIN department b ON a.department_id = b.department_id
- WHERE a.company_id = #{companyId}
- AND (a.wx_openid IS NOT NULL or corpwx_userid is not null)
- AND a.is_active = 1
- AND a.report_status =0
- AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` between #{startDate} and #{endDate})
- </select>
- <select id="getPushDingdingUserList" resultType="java.util.Map">
- SELECT a.company_id as companyId, a.dingding_userid as dingdingUserid
- FROM user AS a left join time_type on time_type.company_id = a.company_id
- left join company on a.company_id = company.id
- WHERE a.dingding_userid is not null and time_type.alert_time = #{alertTime}
- AND a.is_active = 1
- AND a.report_status=0
- AND company.expiration_date >= NOW()
- AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND ((report.`create_date` = DATE_FORMAT(date_sub(NOW(),interval 1 day), '%Y-%m-%d') and time_type.alert_type=1)or(report.`create_date` = DATE_FORMAT(NOW(), '%Y-%m-%d') and time_type.alert_type=0)))
- <if test="date != null">
- and not exists (select 1 from leave_sheet where owner_id = a.id and start_date <= #{date} and end_date >= #{date} and leave_sheet.status = 0)
- </if>
- order by a.company_id
- </select>
- <!--获取项目的参与人的推送id -->
- <select id="getProjectPushUserList" resultType="java.util.Map">
- SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid
- FROM user AS a
- WHERE a.wx_openid IS NOT NULL
- AND a.is_active = 1
- AND a.id in (select user_id from participation where project_id = #{projectId})
- </select>
- <select id="getSimpleNameList" resultType="java.util.HashMap">
- select id, name, job_number as jobNumber from user
- ${ew.customSqlSegment}
- </select>
- <select id="getUserWithDept" resultMap="BaseResultMap2">
- select user.id, name, department.department_name from user left join department on department.department_id = user.department_id
- ${ew.customSqlSegment}
- </select>
- <!--SELECT count(1) isActiveCount FROM user
- WHERE id IN (SELECT DISTINCT r.creator_id FROM report r
- LEFT JOIN project p
- ON r.project_id=p.id
- WHERE p.company_id=936 AND p.category IN(168,169,171,172)
- AND r.dept_id IN
- <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- AND r.create_date BETWEEN #{startDate} AND #{endDate})
- AND is_active=1 AND induction_date <= #{startDate}-->
- <select id="getIsActiveCount" resultType="java.lang.Integer">
- SELECT count(1) isActiveCount FROM user
- WHERE department_id IN
- <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- AND (is_active = 1 OR inactive_date > #{endDate} OR inactive_date IS NULL)
- AND (induction_date <= #{startDate} OR induction_date is NULL)
- AND id not IN (SELECT * from user_exclude)
- </select>
- <!-- SELECT user.* FROM user
- WHERE id in
- (SELECT DISTINCT r.creator_id FROM report r
- LEFT JOIN project p
- ON r.project_id=p.id
- WHERE p.company_id=936 AND p.category IN(168,169,171,172)
- AND r.dept_id IN
- <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- AND r.create_date BETWEEN #{startDate} AND #{endDate})
- AND inactive_date BETWEEN #{startDate} AND #{endDate} and induction_date <= #{startDate}-->
- <select id="getInActiveList" resultType="com.management.platform.entity.User">
- SELECT * FROM user
- WHERE department_id IN
- <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- AND inactive_date < #{endDate} AND inactive_date >= #{startDate}
- AND induction_date <= #{startDate}
- AND id not IN (SELECT * from user_exclude)
- </select>
- <!-- SELECT user.* FROM user
- WHERE id in
- (SELECT DISTINCT r.creator_id FROM report r
- LEFT JOIN project p
- ON r.project_id=p.id
- WHERE p.company_id=936 AND p.category IN(168,169,171,172)
- AND r.dept_id IN
- <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- AND r.create_date BETWEEN #{startDate} AND #{endDate})
- AND induction_date BETWEEN #{startDate} AND #{endDate} AND inactive_date BETWEEN #{startDate} AND #{endDate}-->
- <select id="getInActiveBewttenStartAndEndList" resultType="com.management.platform.entity.User">
- SELECT * FROM user
- WHERE department_id IN
- <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- AND inactive_date < #{endDate} AND inactive_date >= #{startDate}
- AND induction_date < #{endDate} AND induction_date >= #{startDate}
- AND induction_date < inactive_date
- AND id not IN (SELECT * from user_exclude)
- </select>
- <select id="getIsActiveList" resultType="com.management.platform.entity.User">
- SELECT id FROM user
- WHERE department_id IN
- <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- AND (is_active = 1 OR inactive_date > #{endDate} OR inactive_date IS NULL)
- AND (induction_date <= #{startDate} OR induction_date is NULL)
- AND id not IN (SELECT * from user_exclude)
- </select>
- <!-- <select id="getCustomerTotalCount" resultType="com.management.platform.entity.vo.UserVO">
- select count(*) as customertotal ,
- sum(case when c.close_deal=1 then 1 else 0 end) as customerDeal ,
- u.name,u.id
- from custom c
- left join user u on c.incharger_id=u.id
- <where>
- 1=1 and c.incharger_id is not null and c.company_id=#{companyId}
- <if test="startDate !=null and startDate !='' and endDate !=null and endDate !=''">
- AND c.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- <if test="userId !=null and userId!=''">
- AND c.incharger_id=#{userId}
- </if>
- </where>
- group by c.incharger_id
- </select>-->
- <select id="getCustomerTotalCount" resultType="com.management.platform.entity.vo.UserVO">
- SELECT count(*) customertotal ,
- sum(case when b.stage_id=15 then 1 else 0 end) as customerDeal,
- b.incharger_id id,u.name
- from business_opportunity b
- left join user u on b.incharger_id=u.id
- <where>
- 1=1 and b.incharger_id is not null and b.company_id=#{companyId}
- <if test="startDate !=null and startDate !='' and endDate !=null and endDate !=''">
- AND b.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- <if test="userId !=null and userId!=''">
- AND b.incharger_id=#{userId}
- </if>
- </where>
- GROUP BY b.incharger_id
- </select>
- <select id="getCustomerTransferRate" resultType="com.management.platform.entity.vo.UserVO">
- select count(distinct c.id) as num, count(distinct s.custom_id) as saleNum, c.incharger_id as id ,u.name
- from custom c
- left join sales_order s on c.id=s.custom_id
- INNER JOIN user u on u.id=c.incharger_id
- <where>
- 1=1 and c.incharger_id is not null and c.company_id=#{companyId}
- <if test="startDate !=null and startDate !='' and endDate !=null and endDate !=''">
- AND c.create_time BETWEEN #{startDate} AND #{endDate}
- </if>
- <if test="userId !=null and userId!=''">
- AND c.incharger_id=#{userId}
- </if>
- </where>
- group by c.incharger_id
- </select>
- <select id="getSimpleActiveUserList" resultType="java.util.Map">
- select id as value, name as label,job_number as jobNumber from user u
- <where>
- <if test="map.companyId !=null">
- and u.company_id=#{map.companyId}
- </if>
- <if test="map.isActive !=null">
- and u.is_active=#{map.isActive}
- </if>
- <if test="map.name !=null">
- and u.name like concat('%',#{map.name},'%')
- </if>
- <if test="map.deptIds !=null">
- and u.department_id in
- <foreach collection="map.deptIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- </where>
- </select>
- <update id="updateActiveByIds">
- update user set is_active=1 WHERE id IN
- <foreach collection="array" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- </update>
- </mapper>
|