UserMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.management.platform.mapper.UserMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.management.platform.entity.User">
  6. <id column="id" property="id" />
  7. <result column="name" property="name" />
  8. <result column="phone" property="phone" />
  9. <result column="password" property="password" />
  10. <result column="portrait_url" property="portraitUrl" />
  11. <result column="create_time" property="createTime" />
  12. <result column="role" property="role" />
  13. <result column="company_id" property="companyId" />
  14. <result column="department_id" property="departmentId" />
  15. <result column="department_cascade" property="departmentCascade" />
  16. <result column="cost" property="cost" />
  17. <result column="month_cost" property="monthCost" />
  18. <result column="salary_type" property="salaryType" />
  19. <result column="manage_dept_id" property="manageDeptId" />
  20. <result column="color" property="color" />
  21. <result column="is_active" property="isActive" />
  22. <result column="wx_openid" property="wxOpenid" />
  23. <result column="role_id" property="roleId" />
  24. <result column="role_name" property="roleName" />
  25. <result column="cost_apply_date" property="costApplyDate" />
  26. <result column="dingding_userid" property="dingdingUserid" />
  27. <result column="dingding_unionid" property="dingdingUnionid" />
  28. <result column="corpwx_userid" property="corpwxUserid" />
  29. <result column="induction_date" property="inductionDate" />
  30. <result column="inactive_date" property="inactiveDate" />
  31. <result column="position" property="position" />
  32. <result column="report_status" property="reportStatus" />
  33. <result column="superior_id" property="superiorId" />
  34. <result column="plate1" property="plate1" />
  35. <result column="plate2" property="plate2" />
  36. <result column="plate3" property="plate3" />
  37. <result column="plate4" property="plate4" />
  38. <result column="plate5" property="plate5" />
  39. <result column="is_ops" property="isOps" />
  40. <result column="job_number" property="jobNumber" />
  41. <result column="corpwx_deptid" property="corpwxDeptid" />
  42. <result column="corpwx_real_userid" property="corpwxRealUserid" />
  43. <result column="is_first_login" property="isFirstLogin" />
  44. <result column="is_mob_first_login" property="isMobFirstLogin" />
  45. <result column="feishu_userid" property="feishuUserid" />
  46. <result column="feishu_deptid" property="feishuDeptid" />
  47. <result column="only_audit_once" property="onlyAuditOnce" />
  48. </resultMap>
  49. <resultMap id="BaseResultMap2" type="com.management.platform.entity.User">
  50. <id column="id" property="id" />
  51. <result column="name" property="name" />
  52. <result column="department_id" property="departmentId" />
  53. <result column="department_name" property="departmentName" />
  54. </resultMap>
  55. <!-- 通用查询结果列 -->
  56. <sql id="Base_Column_List">
  57. 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
  58. </sql>
  59. <!--单独分页获取人员-->
  60. <select id="getUserByDepartment" resultType="java.util.Map">
  61. 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,
  62. a.department_id AS departmentId, b.department_name AS departmentName, a.department_cascade AS departmentCascade,a.corpwx_userid as corpwxUserid,
  63. 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,
  64. 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
  65. FROM user AS a
  66. LEFT JOIN department AS b ON a.department_id = b.department_id
  67. left join user c on c.id = a.superior_id and c.company_id = #{companyId}
  68. WHERE a.company_id = #{companyId}
  69. <if test="corpwxUserIds != null">
  70. AND a.corpwx_userid in
  71. <foreach collection="corpwxUserIds" item="corpwxUserid" open="(" close=")" separator=",">
  72. #{corpwxUserid}</foreach>
  73. </if>
  74. <if test="departmentId != null and companyId != ''">
  75. AND a.department_id = #{departmentId}
  76. </if>
  77. <if test="keyword != null and keyword != ''">
  78. AND
  79. <choose>
  80. <when test="matchingType==0">
  81. a.name like '%${keyword}%'
  82. </when>
  83. <when test="matchingType==1">
  84. a.phone like '%${keyword}%'
  85. </when>
  86. <when test="matchingType==2">
  87. a.job_number like '%${keyword}%'
  88. </when>
  89. </choose>
  90. </if>
  91. <if test="status != null">
  92. AND a.is_active = #{status}
  93. </if>
  94. <if test="roleId != null">
  95. AND a.role_id = #{roleId}
  96. </if>
  97. </select>
  98. <!--范围分页获取人员-->
  99. <select id="getUserByDepartmentList" resultType="java.util.Map">
  100. 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,
  101. a.department_id AS departmentId, b.department_name AS departmentName, a.department_cascade AS departmentCascade,a.corpwx_userid as corpwxUserid,
  102. 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,
  103. 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
  104. FROM user AS a
  105. LEFT JOIN department AS b ON a.department_id = b.department_id
  106. left join user c on c.id = a.superior_id and c.company_id = #{companyId}
  107. WHERE a.company_id = #{companyId} AND a.department_id IN
  108. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  109. #{departmentId}
  110. </foreach>
  111. <if test="keyword != null and keyword != ''">
  112. AND
  113. <choose>
  114. <when test="matchingType==0">
  115. a.name like '%${keyword}%'
  116. </when>
  117. <when test="matchingType==1">
  118. a.phone like '%${keyword}%'
  119. </when>
  120. <when test="matchingType==2">
  121. a.job_number like '%${keyword}%'
  122. </when>
  123. </choose>
  124. </if>
  125. <if test="status != null">
  126. AND a.is_active = #{status}
  127. </if>
  128. <if test="roleId != null">
  129. AND a.role_id = #{roleId}
  130. </if>
  131. </select>
  132. <select id="getPushUserList" resultType="java.util.Map">
  133. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid, a.name, a.phone, b.department_name AS departmentName
  134. FROM user AS a LEFT JOIN department b ON a.department_id = b.department_id
  135. WHERE a.company_id = #{companyId}
  136. AND (a.wx_openid IS NOT NULL or corpwx_userid is not null)
  137. AND a.is_active = 1
  138. AND a.report_status =0
  139. <choose>
  140. <when test="alertType!=null and alertType==1">
  141. 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'))
  142. </when>
  143. <otherwise>
  144. AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` = DATE_FORMAT(NOW(), '%Y-%m-%d'))
  145. </otherwise>
  146. </choose>
  147. <if test="date != null">
  148. and not exists (select 1 from leave_sheet where owner_id = a.id and start_date &lt;= #{date} and end_date &gt;= #{date} and leave_sheet.status = 0)
  149. </if>
  150. </select>
  151. <select id="getWeekPushUserList" resultType="java.util.Map">
  152. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid, a.name, a.phone, b.department_name AS departmentName
  153. FROM user AS a LEFT JOIN department b ON a.department_id = b.department_id
  154. WHERE a.company_id = #{companyId}
  155. AND (a.wx_openid IS NOT NULL or corpwx_userid is not null)
  156. AND a.is_active = 1
  157. AND a.report_status =0
  158. AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` between #{startDate} and #{endDate})
  159. </select>
  160. <select id="getPushDingdingUserList" resultType="java.util.Map">
  161. SELECT a.company_id as companyId, a.dingding_userid as dingdingUserid
  162. FROM user AS a left join time_type on time_type.company_id = a.company_id
  163. left join company on a.company_id = company.id
  164. WHERE a.dingding_userid is not null and time_type.alert_time = #{alertTime}
  165. AND a.is_active = 1
  166. AND a.report_status=0
  167. AND company.expiration_date >= NOW()
  168. 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)))
  169. <if test="date != null">
  170. and not exists (select 1 from leave_sheet where owner_id = a.id and start_date &lt;= #{date} and end_date &gt;= #{date} and leave_sheet.status = 0)
  171. </if>
  172. order by a.company_id
  173. </select>
  174. <!--获取项目的参与人的推送id -->
  175. <select id="getProjectPushUserList" resultType="java.util.Map">
  176. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid
  177. FROM user AS a
  178. WHERE a.wx_openid IS NOT NULL
  179. AND a.is_active = 1
  180. AND a.id in (select user_id from participation where project_id = #{projectId})
  181. </select>
  182. <select id="getSimpleNameList" resultType="java.util.HashMap">
  183. select id, name, job_number as jobNumber from user
  184. ${ew.customSqlSegment}
  185. </select>
  186. <select id="getUserWithDept" resultMap="BaseResultMap2">
  187. select user.id, name, department.department_name from user left join department on department.department_id = user.department_id
  188. ${ew.customSqlSegment}
  189. </select>
  190. <!--SELECT count(1) isActiveCount FROM user
  191. WHERE id IN (SELECT DISTINCT r.creator_id FROM report r
  192. LEFT JOIN project p
  193. ON r.project_id=p.id
  194. WHERE p.company_id=936 AND p.category IN(168,169,171,172)
  195. AND r.dept_id IN
  196. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  197. #{id}
  198. </foreach>
  199. AND r.create_date BETWEEN #{startDate} AND #{endDate})
  200. AND is_active=1 AND induction_date &lt;= #{startDate}-->
  201. <select id="getIsActiveCount" resultType="java.lang.Integer">
  202. SELECT count(1) isActiveCount FROM user
  203. WHERE department_id IN
  204. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  205. #{id}
  206. </foreach>
  207. AND (is_active = 1 OR inactive_date > #{endDate} OR inactive_date IS NULL)
  208. AND (induction_date &lt;= #{startDate} OR induction_date is NULL)
  209. AND id not IN (SELECT * from user_exclude)
  210. </select>
  211. <!-- SELECT user.* FROM user
  212. WHERE id in
  213. (SELECT DISTINCT r.creator_id FROM report r
  214. LEFT JOIN project p
  215. ON r.project_id=p.id
  216. WHERE p.company_id=936 AND p.category IN(168,169,171,172)
  217. AND r.dept_id IN
  218. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  219. #{id}
  220. </foreach>
  221. AND r.create_date BETWEEN #{startDate} AND #{endDate})
  222. AND inactive_date BETWEEN #{startDate} AND #{endDate} and induction_date &lt;= #{startDate}-->
  223. <select id="getInActiveList" resultType="com.management.platform.entity.User">
  224. SELECT * FROM user
  225. WHERE department_id IN
  226. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  227. #{id}
  228. </foreach>
  229. AND inactive_date &lt; #{endDate} AND inactive_date >= #{startDate}
  230. AND induction_date &lt;= #{startDate}
  231. AND id not IN (SELECT * from user_exclude)
  232. </select>
  233. <!-- SELECT user.* FROM user
  234. WHERE id in
  235. (SELECT DISTINCT r.creator_id FROM report r
  236. LEFT JOIN project p
  237. ON r.project_id=p.id
  238. WHERE p.company_id=936 AND p.category IN(168,169,171,172)
  239. AND r.dept_id IN
  240. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  241. #{id}
  242. </foreach>
  243. AND r.create_date BETWEEN #{startDate} AND #{endDate})
  244. AND induction_date BETWEEN #{startDate} AND #{endDate} AND inactive_date BETWEEN #{startDate} AND #{endDate}-->
  245. <select id="getInActiveBewttenStartAndEndList" resultType="com.management.platform.entity.User">
  246. SELECT * FROM user
  247. WHERE department_id IN
  248. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  249. #{id}
  250. </foreach>
  251. AND inactive_date &lt; #{endDate} AND inactive_date &gt;= #{startDate}
  252. AND induction_date &lt; #{endDate} AND induction_date &gt;= #{startDate}
  253. AND induction_date &lt; inactive_date
  254. AND id not IN (SELECT * from user_exclude)
  255. </select>
  256. <select id="getIsActiveList" resultType="com.management.platform.entity.User">
  257. SELECT id FROM user
  258. WHERE department_id IN
  259. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  260. #{id}
  261. </foreach>
  262. AND (is_active = 1 OR inactive_date > #{endDate} OR inactive_date IS NULL)
  263. AND (induction_date &lt;= #{startDate} OR induction_date is NULL)
  264. AND id not IN (SELECT * from user_exclude)
  265. </select>
  266. <!-- <select id="getCustomerTotalCount" resultType="com.management.platform.entity.vo.UserVO">
  267. select count(*) as customertotal ,
  268. sum(case when c.close_deal=1 then 1 else 0 end) as customerDeal ,
  269. u.name,u.id
  270. from custom c
  271. left join user u on c.incharger_id=u.id
  272. <where>
  273. 1=1 and c.incharger_id is not null and c.company_id=#{companyId}
  274. <if test="startDate !=null and startDate !='' and endDate !=null and endDate !=''">
  275. AND c.create_time BETWEEN #{startDate} AND #{endDate}
  276. </if>
  277. <if test="userId !=null and userId!=''">
  278. AND c.incharger_id=#{userId}
  279. </if>
  280. </where>
  281. group by c.incharger_id
  282. </select>-->
  283. <select id="getCustomerTotalCount" resultType="com.management.platform.entity.vo.UserVO">
  284. SELECT count(*) customertotal ,
  285. sum(case when b.stage_id=15 then 1 else 0 end) as customerDeal,
  286. b.incharger_id id,u.name
  287. from business_opportunity b
  288. left join user u on b.incharger_id=u.id
  289. <where>
  290. 1=1 and b.incharger_id is not null and b.company_id=#{companyId}
  291. <if test="startDate !=null and startDate !='' and endDate !=null and endDate !=''">
  292. AND b.create_time BETWEEN #{startDate} AND #{endDate}
  293. </if>
  294. <if test="userId !=null and userId!=''">
  295. AND b.incharger_id=#{userId}
  296. </if>
  297. </where>
  298. GROUP BY b.incharger_id
  299. </select>
  300. <select id="getCustomerTransferRate" resultType="com.management.platform.entity.vo.UserVO">
  301. select count(distinct c.id) as num, count(distinct s.custom_id) as saleNum, c.incharger_id as id ,u.name
  302. from custom c
  303. left join sales_order s on c.id=s.custom_id
  304. INNER JOIN user u on u.id=c.incharger_id
  305. <where>
  306. 1=1 and c.incharger_id is not null and c.company_id=#{companyId}
  307. <if test="startDate !=null and startDate !='' and endDate !=null and endDate !=''">
  308. AND c.create_time BETWEEN #{startDate} AND #{endDate}
  309. </if>
  310. <if test="userId !=null and userId!=''">
  311. AND c.incharger_id=#{userId}
  312. </if>
  313. </where>
  314. group by c.incharger_id
  315. </select>
  316. <select id="getSimpleActiveUserList" resultType="java.util.Map">
  317. select id as value, name as label,job_number as jobNumber from user u
  318. <where>
  319. <if test="map.companyId !=null">
  320. and u.company_id=#{map.companyId}
  321. </if>
  322. <if test="map.isActive !=null">
  323. and u.is_active=#{map.isActive}
  324. </if>
  325. <if test="map.name !=null">
  326. and u.name like concat('%',#{map.name},'%')
  327. </if>
  328. <if test="map.deptIds !=null">
  329. and u.department_id in
  330. <foreach collection="map.deptIds" item="item" open="(" close=")" separator=",">
  331. #{item}
  332. </foreach>
  333. </if>
  334. </where>
  335. </select>
  336. <update id="updateActiveByIds">
  337. update user set is_active=1 WHERE id IN
  338. <foreach collection="array" item="id" open="(" close=")" separator=",">
  339. #{id}
  340. </foreach>
  341. </update>
  342. </mapper>