LeaveApplyDao.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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.jeeplus.modules.leaveapply.dao.LeaveApplyDao">
  4. <sql id="leaveApplyColumns">
  5. a.id AS "id",
  6. a.create_by AS "createBy.id",
  7. a.create_date AS "createDate",
  8. a.update_by AS "updateBy.id",
  9. a.update_date AS "updateDate",
  10. a.remarks AS "remarks",
  11. a.del_flag AS "delFlag",
  12. a.office_id AS "officeId",
  13. a.company_id AS "companyId",
  14. a.branch_office AS "branchOffice",
  15. a.staff_id AS "staffId",
  16. a.start_time AS "startTime",
  17. a.end_time AS "endTime",
  18. a.start_type AS "startType",
  19. a.end_type AS "endType",
  20. a.long_time AS "longTime",
  21. a.status AS "status",
  22. a.process_instance_id AS "processInstanceId",
  23. a.sell_status AS "sellStatus",
  24. a.apply_time AS "applyTime",
  25. a.no AS "no",
  26. a.reason AS "reason",
  27. w.name AS "basicInfo.name",
  28. w.id AS "basicInfo.id",
  29. w.no AS "basicInfo.no",
  30. w.status as "basicInfo.status",
  31. m.top_company AS "basicInfo.office.name",
  32. m.id AS "basicInfo.office.id",
  33. j.name AS "basicInfo.jobGrade.name",
  34. a.applyer,
  35. a.back_time,
  36. a.contrast,
  37. a.back_start_type as "backStartType"
  38. </sql>
  39. <sql id="leaveApplyJoins">
  40. left join work_staff_achives w on w.id=a.staff_id
  41. left join sys_office m on m.id=w.office_id
  42. left join work_job_grade j on j.id=w.job_grade
  43. LEFT JOIN sys_office o ON o.id = a.office_id
  44. LEFT JOIN sys_office s ON s.id = a.company_id
  45. LEFT JOIN sys_user u ON u.id = a.create_by
  46. </sql>
  47. <select id="get" resultType="LeaveApply" >
  48. SELECT
  49. <include refid="leaveApplyColumns"/>
  50. FROM leave_apply a
  51. <include refid="leaveApplyJoins"/>
  52. WHERE a.id = #{id}
  53. </select>
  54. <select id="getByStaffIdAndTime" resultType="LeaveApply" >
  55. SELECT
  56. <include refid="leaveApplyColumns"/>
  57. FROM leave_apply a
  58. <include refid="leaveApplyJoins"/>
  59. LEFT JOIN leave_detail d ON d.leave_id = a.id
  60. WHERE a.staff_id = #{staffId}
  61. AND a.status IN ('5','8')
  62. AND #{time}
  63. BETWEEN d.start_time AND d.end_time
  64. AND #{time} &lt;= d.real_end_time;
  65. </select>
  66. <select id="findList" resultType="LeaveApply" >
  67. SELECT
  68. <include refid="leaveApplyColumns"/>
  69. FROM leave_apply a
  70. <include refid="leaveApplyJoins"/>
  71. <where>
  72. a.del_flag = #{DEL_FLAG_NORMAL}
  73. <if test="beginApplyTime != null and endApplyTime != null and beginApplyTime != '' and endApplyTime != ''">
  74. AND a.apply_time BETWEEN #{beginApplyTime} AND #{endApplyTime}
  75. </if>
  76. <if test="basicInfo != null and basicInfo.name != null and basicInfo.name != ''">
  77. AND w.name LIKE
  78. <if test="dbName == 'oracle'">'%'||#{basicInfo.name}||'%'</if>
  79. <if test="dbName == 'mssql'">'%'+#{basicInfo.name}+'%'</if>
  80. <if test="dbName == 'mysql'">concat('%',#{basicInfo.name},'%')</if>
  81. </if>
  82. ${sqlMap.dsf}
  83. <if test="staffId != null and staffId != ''">
  84. AND a.staff_id = #{staffId}
  85. </if>
  86. <if test="status != null and status != ''">
  87. AND a.status = #{status}
  88. </if>
  89. </where>
  90. <choose>
  91. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  92. ORDER BY ${page.orderBy}
  93. </when>
  94. <otherwise>
  95. ORDER BY a.update_date DESC
  96. </otherwise>
  97. </choose>
  98. </select>
  99. <select id="findAllList" resultType="LeaveApply" >
  100. SELECT
  101. <include refid="leaveApplyColumns"/>
  102. FROM leave_apply a
  103. <include refid="leaveApplyJoins"/>
  104. <where>
  105. a.del_flag = #{DEL_FLAG_NORMAL}
  106. </where>
  107. <choose>
  108. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  109. ORDER BY ${page.orderBy}
  110. </when>
  111. <otherwise>
  112. ORDER BY a.update_date DESC
  113. </otherwise>
  114. </choose>
  115. </select>
  116. <insert id="insert">
  117. INSERT INTO leave_apply(
  118. id,
  119. create_by,
  120. create_date,
  121. update_by,
  122. update_date,
  123. remarks,
  124. del_flag,
  125. office_id,
  126. company_id,
  127. branch_office,
  128. staff_id,
  129. start_time,
  130. end_time,
  131. start_type,
  132. end_type,
  133. long_time,
  134. status,
  135. process_instance_id,
  136. sell_status,
  137. apply_time,
  138. no,
  139. reason,
  140. applyer,
  141. back_time,
  142. contrast,
  143. back_start_type
  144. ) VALUES (
  145. #{id},
  146. #{createBy.id},
  147. #{createDate},
  148. #{updateBy.id},
  149. #{updateDate},
  150. #{remarks},
  151. #{delFlag},
  152. #{officeId},
  153. #{companyId},
  154. #{branchOffice},
  155. #{basicInfo.id},
  156. #{startTime},
  157. #{endTime},
  158. #{startType},
  159. #{endType},
  160. #{longTime},
  161. #{status},
  162. #{processInstanceId},
  163. #{sellStatus},
  164. #{applyTime},
  165. #{no},
  166. #{reason},
  167. #{applyer},
  168. #{backTime},
  169. #{contrast},
  170. #{backStartType}
  171. )
  172. </insert>
  173. <update id="update">
  174. UPDATE leave_apply SET
  175. update_by = #{updateBy.id},
  176. update_date = #{updateDate},
  177. remarks = #{remarks},
  178. office_id = #{officeId},
  179. company_id = #{companyId},
  180. branch_office = #{branchOffice},
  181. staff_id = #{basicInfo.id},
  182. start_time = #{startTime},
  183. end_time = #{endTime},
  184. start_type = #{startType},
  185. end_type = #{endType},
  186. long_time = #{longTime},
  187. status = #{status},
  188. process_instance_id = #{processInstanceId},
  189. sell_status = #{sellStatus},
  190. apply_time = #{applyTime},
  191. no = #{no},
  192. reason = #{reason},
  193. applyer=#{applyer},
  194. back_time = #{backTime},
  195. contrast=#{contrast},
  196. back_start_type = #{backStartType}
  197. WHERE id = #{id}
  198. </update>
  199. <!--物理删除-->
  200. <update id="delete">
  201. DELETE FROM leave_apply
  202. WHERE id = #{id}
  203. </update>
  204. <!--逻辑删除-->
  205. <update id="deleteByLogic">
  206. UPDATE leave_apply SET
  207. del_flag = #{DEL_FLAG_DELETE}
  208. WHERE id = #{id}
  209. </update>
  210. <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
  211. <select id="findUniqueByProperty" resultType="LeaveApply" statementType="STATEMENT">
  212. select * FROM leave_apply where ${propertyName} = '${value}'
  213. </select>
  214. <update id="updateProcessIdAndStatus" >
  215. UPDATE leave_apply SET
  216. process_instance_id = #{processInstanceId},
  217. status = #{status}
  218. WHERE id = #{id}
  219. </update>
  220. <select id="getCount" resultType="LeaveApply" >
  221. SELECT
  222. <include refid="leaveApplyColumns"/>
  223. FROM leave_apply a
  224. <include refid="leaveApplyJoins"/>
  225. WHERE a.staff_id = #{basicInfo.id} and a.status not in ('8')
  226. </select>
  227. <select id="getMaxTime" resultType="java.lang.String" parameterType="java.lang.String">
  228. SELECT
  229. max(DATE_FORMAT(end_time, '%Y-%m-%d')) AS endTime
  230. FROM `leave_apply` l
  231. WHERE
  232. del_flag='0'
  233. and staff_id = #{staffId}
  234. and id !=#{id}
  235. </select>
  236. <select id="findHisTime" resultType="java.lang.Integer">
  237. SELECT
  238. count(*) as "total"
  239. FROM leave_detail a
  240. <where>
  241. a.del_flag = '0'
  242. AND a.leave_id in
  243. (select y.id from leave_apply y where y.staff_id=#{staffId} and y.status='8' and y.del_flag='0'
  244. <if test="id != null and id != ''">
  245. and y.id!=#{id}
  246. </if>)
  247. and ((#{startTime}> a.start_time and #{startTime} &lt; a.end_time)
  248. or (#{endTime} &gt; a.start_time and #{endTime} &lt; a.end_time))
  249. </where>
  250. </select>
  251. <select id="findHisDate" resultType="java.lang.Integer">
  252. SELECT
  253. count(*) AS "total" FROM
  254. leave_detail a WHERE
  255. a.del_flag = '0' AND a.leave_id IN (
  256. SELECT y.id FROM leave_apply y WHERE y.staff_id =#{staffId}
  257. AND y. STATUS = '8'
  258. AND y.del_flag = '0'
  259. AND y.id !=#{id})
  260. AND ((a.start_time = #{startTime} and a.start_type=#{startType})
  261. OR (a.start_time = #{endTime} and a.start_type=#{endType})
  262. OR (a.end_time = #{startTime} and a.end_type=#{startType})
  263. OR (a.end_time = #{endTime} and a.end_type=#{endType}))
  264. </select>
  265. <select id="getMange" resultType="LeaveApply" >
  266. SELECT
  267. <include refid="leaveApplyColumns"/>
  268. FROM leave_apply a
  269. <include refid="leaveApplyJoins"/>
  270. WHERE a.company_id=#{companyId} and a.del_flag = '0' and a.status in('5','8','6','7','9')
  271. <if test="basicInfo != null and basicInfo.name != null and basicInfo.name != ''">
  272. AND w.name LIKE
  273. <if test="dbName == 'oracle'">'%'||#{basicInfo.name}||'%'</if>
  274. <if test="dbName == 'mssql'">'%'+#{basicInfo.name}+'%'</if>
  275. <if test="dbName == 'mysql'">concat('%',#{basicInfo.name},'%')</if>
  276. </if>
  277. <if test="basicInfo != null and basicInfo.office != null and basicInfo.office.id != null and basicInfo.office.id != ''">
  278. AND a.office_id = #{basicInfo.office.id}
  279. </if>
  280. <!-- 有异常-->
  281. <!-- group by a.staff_id order by w.no ASC-->
  282. </select>
  283. <select id="getSumDays" resultType="LeaveApply" parameterType="java.lang.String">
  284. SELECT
  285. ifnull(sum(a.sums),0) as "sumDays"
  286. FROM leave_count a
  287. where
  288. a.del_flag = '0'
  289. and a.staff_id =#{staffId}
  290. </select>
  291. <select id="getResetState" resultType="int" parameterType="java.lang.String">
  292. SELECT
  293. count(*)
  294. FROM leave_count a
  295. where
  296. a.del_flag = '0'
  297. and a.staff_id =#{staffId}
  298. and a.reset_state='0'
  299. </select>
  300. <update id="updateDetailFlat">
  301. UPDATE leave_detail a SET
  302. a.flat = '1',a.state='0'
  303. WHERE a.leave_id=#{id}
  304. </update>
  305. <update id="deleteDetail">
  306. DELETE FROM leave_detail
  307. WHERE leave_id = #{id} and state='1'
  308. </update>
  309. <update id="updateBack">
  310. UPDATE leave_apply a SET
  311. a.back_time=null,
  312. a.contrast=null
  313. WHERE a.id=#{id}
  314. </update>
  315. <update id="updateLongTime">
  316. UPDATE leave_apply a SET
  317. a.long_time=(select ifnull(sum(days),0) from leave_detail
  318. WHERE leave_id = #{id} and state!='1')
  319. WHERE a.id=#{id}
  320. </update>
  321. <select id="getBackTaskList" resultType="LeaveApply" >
  322. SELECT
  323. <include refid="leaveApplyColumns"/>
  324. FROM leave_apply a
  325. left join work_staff_achives w on w.id=a.staff_id
  326. left join sys_office m on m.id=w.office_id
  327. left join work_job_grade j on j.id=w.job_grade
  328. where a.id in (SELECT a.id FROM leave_apply a
  329. LEFT JOIN (SELECT d.leave_id, max(d.end_time) AS end_time FROM leave_detail d
  330. WHERE d.del_flag = '0' GROUP BY d.leave_id) i ON i.leave_id = a.id
  331. WHERE a.del_flag = '0'
  332. AND a.`status` = '5'
  333. AND date_add(DATE_FORMAT(i.end_time, '%Y-%m-%d'),INTERVAL 1 day)=DATE_FORMAT(now(), '%Y-%m-%d'))
  334. </select>
  335. </mapper>