UserMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 (
  71. a.corpwx_userid in
  72. <foreach collection="corpwxUserIds" item="corpwxUserid" open="(" close=")" separator=",">
  73. #{corpwxUserid}</foreach>
  74. or a.dingding_userid in
  75. <foreach collection="corpwxUserIds" item="corpwxUserid" open="(" close=")" separator=",">
  76. #{corpwxUserid}</foreach>)
  77. </if>
  78. <if test="departmentId != null and companyId != ''">
  79. AND a.department_id = #{departmentId}
  80. </if>
  81. <if test="keyword != null and keyword != ''">
  82. AND
  83. <choose>
  84. <when test="matchingType==0">
  85. a.name like '%${keyword}%'
  86. </when>
  87. <when test="matchingType==1">
  88. a.phone like '%${keyword}%'
  89. </when>
  90. <when test="matchingType==2">
  91. a.job_number like '%${keyword}%'
  92. </when>
  93. </choose>
  94. </if>
  95. <if test="status != null">
  96. AND a.is_active = #{status}
  97. </if>
  98. <if test="roleId != null">
  99. AND a.role_id = #{roleId}
  100. </if>
  101. </select>
  102. <!--范围分页获取人员-->
  103. <select id="getUserByDepartmentList" resultType="java.util.Map">
  104. 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,
  105. a.department_id AS departmentId, b.department_name AS departmentName, a.department_cascade AS departmentCascade,a.corpwx_userid as corpwxUserid,
  106. 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,
  107. 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
  108. FROM user AS a
  109. LEFT JOIN department AS b ON a.department_id = b.department_id
  110. left join user c on c.id = a.superior_id and c.company_id = #{companyId}
  111. WHERE a.company_id = #{companyId} AND a.department_id IN
  112. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  113. #{departmentId}
  114. </foreach>
  115. <if test="keyword != null and keyword != ''">
  116. AND
  117. <choose>
  118. <when test="matchingType==0">
  119. a.name like '%${keyword}%'
  120. </when>
  121. <when test="matchingType==1">
  122. a.phone like '%${keyword}%'
  123. </when>
  124. <when test="matchingType==2">
  125. a.job_number like '%${keyword}%'
  126. </when>
  127. </choose>
  128. </if>
  129. <if test="status != null">
  130. AND a.is_active = #{status}
  131. </if>
  132. <if test="roleId != null">
  133. AND a.role_id = #{roleId}
  134. </if>
  135. </select>
  136. <select id="getPushUserList" resultType="java.util.Map">
  137. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid, a.name, a.phone, b.department_name AS departmentName
  138. FROM user AS a LEFT JOIN department b ON a.department_id = b.department_id
  139. WHERE a.company_id = #{companyId}
  140. AND (a.wx_openid IS NOT NULL or corpwx_userid is not null)
  141. AND a.is_active = 1
  142. AND a.report_status =0
  143. <choose>
  144. <when test="alertType!=null and alertType==1">
  145. 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'))
  146. </when>
  147. <otherwise>
  148. AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` = DATE_FORMAT(NOW(), '%Y-%m-%d'))
  149. </otherwise>
  150. </choose>
  151. <if test="date != null">
  152. 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)
  153. </if>
  154. </select>
  155. <select id="getWeekPushUserList" resultType="java.util.Map">
  156. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid, a.name, a.phone, b.department_name AS departmentName
  157. FROM user AS a LEFT JOIN department b ON a.department_id = b.department_id
  158. WHERE a.company_id = #{companyId}
  159. AND (a.wx_openid IS NOT NULL or corpwx_userid is not null)
  160. AND a.is_active = 1
  161. AND a.report_status =0
  162. AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` between #{startDate} and #{endDate})
  163. </select>
  164. <select id="getPushDingdingUserList" resultType="java.util.Map">
  165. SELECT a.company_id as companyId, a.dingding_userid as dingdingUserid
  166. FROM user AS a left join time_type on time_type.company_id = a.company_id
  167. left join company on a.company_id = company.id
  168. WHERE a.dingding_userid is not null and time_type.alert_time = #{alertTime}
  169. AND a.is_active = 1
  170. AND a.report_status=0
  171. AND company.expiration_date >= NOW()
  172. 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)))
  173. <if test="date != null">
  174. 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)
  175. </if>
  176. order by a.company_id
  177. </select>
  178. <!--获取项目的参与人的推送id -->
  179. <select id="getProjectPushUserList" resultType="java.util.Map">
  180. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid
  181. FROM user AS a
  182. WHERE a.wx_openid IS NOT NULL
  183. AND a.is_active = 1
  184. AND a.id in (select user_id from participation where project_id = #{projectId})
  185. </select>
  186. <select id="getSimpleNameList" resultType="java.util.HashMap">
  187. select id, name, job_number as jobNumber from user
  188. ${ew.customSqlSegment}
  189. </select>
  190. <select id="getUserWithDept" resultMap="BaseResultMap2">
  191. select user.id, name, department.department_name from user left join department on department.department_id = user.department_id
  192. ${ew.customSqlSegment}
  193. </select>
  194. <!--SELECT count(1) isActiveCount FROM user
  195. WHERE id IN (SELECT DISTINCT r.creator_id FROM report r
  196. LEFT JOIN project p
  197. ON r.project_id=p.id
  198. WHERE p.company_id=936 AND p.category IN(168,169,171,172)
  199. AND r.dept_id IN
  200. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  201. #{id}
  202. </foreach>
  203. AND r.create_date BETWEEN #{startDate} AND #{endDate})
  204. AND is_active=1 AND induction_date &lt;= #{startDate}-->
  205. <select id="getIsActiveCount" resultType="java.lang.Integer">
  206. SELECT count(1) isActiveCount FROM user
  207. WHERE department_id IN
  208. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  209. #{id}
  210. </foreach>
  211. AND (is_active = 1 OR inactive_date > #{endDate} OR inactive_date IS NULL)
  212. AND (induction_date &lt;= #{startDate} OR induction_date is NULL)
  213. AND id not IN (SELECT * from user_exclude)
  214. </select>
  215. <!-- SELECT user.* FROM user
  216. WHERE id in
  217. (SELECT DISTINCT r.creator_id FROM report r
  218. LEFT JOIN project p
  219. ON r.project_id=p.id
  220. WHERE p.company_id=936 AND p.category IN(168,169,171,172)
  221. AND r.dept_id IN
  222. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  223. #{id}
  224. </foreach>
  225. AND r.create_date BETWEEN #{startDate} AND #{endDate})
  226. AND inactive_date BETWEEN #{startDate} AND #{endDate} and induction_date &lt;= #{startDate}-->
  227. <select id="getInActiveList" resultType="com.management.platform.entity.User">
  228. SELECT * FROM user
  229. WHERE department_id IN
  230. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  231. #{id}
  232. </foreach>
  233. AND inactive_date &lt; #{endDate} AND inactive_date >= #{startDate}
  234. AND induction_date &lt;= #{startDate}
  235. AND id not IN (SELECT * from user_exclude)
  236. </select>
  237. <!-- SELECT user.* FROM user
  238. WHERE id in
  239. (SELECT DISTINCT r.creator_id FROM report r
  240. LEFT JOIN project p
  241. ON r.project_id=p.id
  242. WHERE p.company_id=936 AND p.category IN(168,169,171,172)
  243. AND r.dept_id IN
  244. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  245. #{id}
  246. </foreach>
  247. AND r.create_date BETWEEN #{startDate} AND #{endDate})
  248. AND induction_date BETWEEN #{startDate} AND #{endDate} AND inactive_date BETWEEN #{startDate} AND #{endDate}-->
  249. <select id="getInActiveBewttenStartAndEndList" resultType="com.management.platform.entity.User">
  250. SELECT * FROM user
  251. WHERE department_id IN
  252. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  253. #{id}
  254. </foreach>
  255. AND inactive_date &lt; #{endDate} AND inactive_date &gt;= #{startDate}
  256. AND induction_date &lt; #{endDate} AND induction_date &gt;= #{startDate}
  257. AND induction_date &lt; inactive_date
  258. AND id not IN (SELECT * from user_exclude)
  259. </select>
  260. <select id="getIsActiveList" resultType="com.management.platform.entity.User">
  261. SELECT id FROM user
  262. WHERE department_id IN
  263. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  264. #{id}
  265. </foreach>
  266. AND (is_active = 1 OR inactive_date > #{endDate} OR inactive_date IS NULL)
  267. AND (induction_date &lt;= #{startDate} OR induction_date is NULL)
  268. AND id not IN (SELECT * from user_exclude)
  269. </select>
  270. <update id="updateActiveByIds">
  271. update user set is_active=1 WHERE id IN
  272. <foreach collection="array" item="id" open="(" close=")" separator=",">
  273. #{id}
  274. </foreach>
  275. </update>
  276. </mapper>