UserMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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,
  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="departmentId != null and companyId != ''">
  70. AND a.department_id = #{departmentId}
  71. </if>
  72. <if test="keyword != null and keyword != ''">
  73. AND
  74. <choose>
  75. <when test="matchingType==0">
  76. a.name like '%${keyword}%'
  77. </when>
  78. <when test="matchingType==1">
  79. a.phone like '%${keyword}%'
  80. </when>
  81. <when test="matchingType==2">
  82. a.job_number like '%${keyword}%'
  83. </when>
  84. </choose>
  85. </if>
  86. <if test="status != null">
  87. AND a.is_active = #{status}
  88. </if>
  89. <if test="roleId != null">
  90. AND a.role_id = #{roleId}
  91. </if>
  92. </select>
  93. <!--范围分页获取人员-->
  94. <select id="getUserByDepartmentList" resultType="java.util.Map">
  95. 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,
  96. a.department_id AS departmentId, b.department_name AS departmentName, a.department_cascade AS departmentCascade,
  97. 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,
  98. 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
  99. FROM user AS a
  100. LEFT JOIN department AS b ON a.department_id = b.department_id
  101. left join user c on c.id = a.superior_id and c.company_id = #{companyId}
  102. WHERE a.company_id = #{companyId} AND a.department_id IN
  103. <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
  104. #{departmentId}
  105. </foreach>
  106. <if test="keyword != null and keyword != ''">
  107. AND a.name like '%${keyword}%'
  108. </if>
  109. <if test="status != null">
  110. AND a.is_active = #{status}
  111. </if>
  112. <if test="roleId != null">
  113. AND a.role_id = #{roleId}
  114. </if>
  115. </select>
  116. <select id="getPushUserList" resultType="java.util.Map">
  117. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid, a.name, a.phone, b.department_name AS departmentName
  118. FROM user AS a LEFT JOIN department b ON a.department_id = b.department_id
  119. WHERE a.company_id = #{companyId}
  120. AND (a.wx_openid IS NOT NULL or corpwx_userid is not null)
  121. AND a.is_active = 1
  122. AND a.report_status =0
  123. <choose>
  124. <when test="alertType!=null and alertType==1">
  125. 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'))
  126. </when>
  127. <otherwise>
  128. AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` = DATE_FORMAT(NOW(), '%Y-%m-%d'))
  129. </otherwise>
  130. </choose>
  131. <if test="date != null">
  132. 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)
  133. </if>
  134. </select>
  135. <select id="getWeekPushUserList" resultType="java.util.Map">
  136. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid, a.name, a.phone, b.department_name AS departmentName
  137. FROM user AS a LEFT JOIN department b ON a.department_id = b.department_id
  138. WHERE a.company_id = #{companyId}
  139. AND (a.wx_openid IS NOT NULL or corpwx_userid is not null)
  140. AND a.is_active = 1
  141. AND a.report_status =0
  142. AND NOT EXISTS(SELECT 1 FROM report WHERE report.`creator_id` = a.id AND report.`create_date` between #{startDate} and #{endDate})
  143. </select>
  144. <select id="getPushDingdingUserList" resultType="java.util.Map">
  145. SELECT a.company_id as companyId, a.dingding_userid as dingdingUserid
  146. FROM user AS a left join time_type on time_type.company_id = a.company_id
  147. left join company on a.company_id = company.id
  148. WHERE a.dingding_userid is not null and time_type.alert_time = #{alertTime}
  149. AND a.is_active = 1
  150. AND a.report_status=0
  151. AND company.expiration_date >= NOW()
  152. 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)))
  153. <if test="date != null">
  154. 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)
  155. </if>
  156. order by a.company_id
  157. </select>
  158. <!--获取项目的参与人的推送id -->
  159. <select id="getProjectPushUserList" resultType="java.util.Map">
  160. SELECT a.id, a.wx_openid as wxOpenid, a.corpwx_userid as corpwxUserid
  161. FROM user AS a
  162. WHERE a.wx_openid IS NOT NULL
  163. AND a.is_active = 1
  164. AND a.id in (select user_id from participation where project_id = #{projectId})
  165. </select>
  166. <select id="getSimpleNameList" resultType="java.util.HashMap">
  167. select id, name, job_number as jobNumber from user
  168. ${ew.customSqlSegment}
  169. </select>
  170. <select id="getUserWithDept" resultMap="BaseResultMap2">
  171. select user.id, name, department.department_name from user left join department on department.department_id = user.department_id
  172. ${ew.customSqlSegment}
  173. </select>
  174. <select id="getIsActiveCount" resultType="java.lang.Integer">
  175. SELECT count(1) isActiveCount FROM user
  176. WHERE id IN (SELECT DISTINCT r.creator_id FROM report r
  177. LEFT JOIN project p
  178. ON r.project_id=p.id
  179. WHERE p.company_id=936 AND p.category IN(168,169,171,172)
  180. AND r.dept_id IN
  181. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  182. #{id}
  183. </foreach>
  184. AND r.create_date BETWEEN #{startDate} AND #{endDate})
  185. AND is_active=1 AND (inactive_date >= #{endDate} OR inactive_date is null) AND induction_date &lt;= #{startDate}
  186. </select>
  187. <select id="getInActiveList" resultType="com.management.platform.entity.User">
  188. SELECT user.* FROM user
  189. WHERE id in
  190. (SELECT DISTINCT r.creator_id FROM report r
  191. LEFT JOIN project p
  192. ON r.project_id=p.id
  193. WHERE p.company_id=936 AND p.category IN(168,169,171,172)
  194. AND r.dept_id IN
  195. <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
  196. #{id}
  197. </foreach>
  198. AND r.create_date BETWEEN #{startDate} AND #{endDate})
  199. AND inactive_date BETWEEN #{startDate} AND #{endDate} and induction_date &lt;= #{startDate}
  200. </select>
  201. </mapper>