UserMapper.xml 16 KB

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