gxtOrderPersonMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ygtx.gxt.mapper.GxtOrderPersonMapper">
  6. <resultMap type="com.ygtx.gxt.domain.GxtOrderPerson" id="GxtOrderPersonResult">
  7. <result property="userId" column="user_id"/>
  8. <result property="nickName" column="nick_name"/>
  9. <result property="orderCode" column="order_code"/>
  10. <result property="center" column="center"/>
  11. <result property="parent" column="parent"/>
  12. <result property="pcs" column="pcs"/>
  13. <result property="orderType" column="order_type"/>
  14. <result property="scoreType" column="score_type"/>
  15. <result property="finishDate" column="finish_date"/>
  16. <result property="score" column="score"/>
  17. </resultMap>
  18. <select id="selectGxtOrderPersonList" parameterType="GxtOrderPerson" resultMap="GxtOrderPersonResult">
  19. SELECT po.*,DATE( po.real_end_time ) AS finish_date FROM (
  20. SELECT
  21. o.work_order_project_no AS order_code,
  22. o.gxt_center AS center,
  23. d.dept_name AS parent,
  24. o.pcs_station_name AS pcs,
  25. '维修工单' AS order_type,
  26. o.real_end_time,
  27. p.score,p.user_id
  28. FROM
  29. gxt_repair_order_person p
  30. LEFT JOIN gxt_repair_order o ON p.order_id = o.id
  31. LEFT JOIN sys_dept d ON o.pcs_station_pid = d.dept_id
  32. WHERE
  33. o.occur_time >= DATE_FORMAT( CURDATE(), '%Y-%m-01 00:00:00' )
  34. AND o.real_end_time <![CDATA[<]]> DATE_FORMAT( DATE_ADD( CURDATE(), INTERVAL 1 MONTH ), '%Y-%m-01 00:00:00' )
  35. AND p.score IS NOT NULL AND o.scoring_status IN ('to_archive','archived')
  36. UNION ALL
  37. SELECT
  38. o.work_order_project_no AS order_code,
  39. o.gxt_center AS center,
  40. d.dept_name AS parent,
  41. o.pcs_station_name AS pcs,
  42. '维保工单' AS order_type,
  43. o.real_end_time,
  44. p.score,p.user_id
  45. FROM
  46. gxt_work_order_person p
  47. LEFT JOIN gxt_work_order o ON p.order_id = o.id
  48. LEFT JOIN sys_dept d ON o.pcs_station_pid = d.dept_id
  49. WHERE
  50. o.create_time >= DATE_FORMAT( CURDATE(), '%Y-%m-01 00:00:00' )
  51. AND o.real_end_time <![CDATA[<]]> DATE_FORMAT( DATE_ADD( CURDATE(), INTERVAL 1 MONTH ), '%Y-%m-01 00:00:00' )
  52. AND p.score IS NOT NULL AND o.scoring_status IN ('to_archive','archived')
  53. ) po
  54. WHERE 1=1
  55. <if test="userId != null">
  56. AND po.user_id = #{userId}
  57. </if>
  58. <if test="orderCode != null and orderCode != ''">
  59. AND po.order_code LIKE CONCAT( '%', #{orderCode}, '%' )
  60. </if>
  61. ORDER BY po.real_end_time DESC
  62. </select>
  63. <select id="selectGxtScoreDetailList" parameterType="GxtOrderPerson" resultMap="GxtOrderPersonResult">
  64. SELECT
  65. u.nick_name,
  66. CASE WHEN t.order_type=1 THEN ro.work_order_project_no ELSE wo.work_order_project_no END AS order_code,
  67. CASE WHEN t.order_type=1 THEN ro.gxt_center ELSE wo.gxt_center END AS center,
  68. d.dept_name AS parent,DATE( t.create_time ) AS finish_date,t.user_id,
  69. CASE WHEN t.order_type=1 THEN ro.pcs_station_name ELSE wo.pcs_station_name END AS pcs,
  70. CASE WHEN t.order_type=1 THEN '维修工单' ELSE '维保工单' END AS order_type,
  71. CASE WHEN t.score_type=1 THEN '工单得分' WHEN t.score_type=2 THEN '运行得分' ELSE '停机扣分' END AS score_type,t.score
  72. FROM gxt_order_score_detail t
  73. LEFT JOIN sys_user u ON t.user_id=u.user_id
  74. LEFT JOIN gxt_repair_order ro ON t.order_id=ro.id
  75. LEFT JOIN gxt_work_order wo ON wo.id=t.order_id
  76. LEFT JOIN sys_dept d ON
  77. d.dept_id=CASE WHEN t.order_type=1 THEN ro.pcs_station_pid ELSE wo.pcs_station_pid END
  78. WHERE DATE_FORMAT(t.create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
  79. <if test="userId != null">
  80. AND t.user_id = #{userId}
  81. </if>
  82. <if test="orderCode != null and orderCode != ''">
  83. AND t.order_code LIKE CONCAT( '%', #{orderCode}, '%' )
  84. </if>
  85. ORDER BY t.create_time DESC
  86. </select>
  87. <delete id="delRepairOrderFlowRecords">
  88. DELETE FROM gxt_repair_order_flow_records
  89. </delete>
  90. <delete id="delRepairOrderFlowRecordsNext">
  91. DELETE FROM gxt_repair_order_flow_records_next
  92. </delete>
  93. <delete id="delWorkOrderFlowRecords">
  94. DELETE FROM gxt_work_order_flow_records
  95. </delete>
  96. <delete id="delWorkOrderFlowRecordsNext">
  97. DELETE FROM gxt_work_order_flow_records_next
  98. </delete>
  99. <select id="selectRepairOrderFlowRecordsSize" resultType="Integer">
  100. SELECT count(*) FROM gxt_repair_order_flow_records
  101. </select>
  102. <select id="repairOrderFlowRecordsSize" resultType="Integer">
  103. SELECT COUNT(*) FROM (
  104. SELECT
  105. f.order_id,
  106. f.action_type,
  107. f.action_time,
  108. ro.real_start_time,
  109. (SELECT COUNT(*)
  110. FROM gxt_repair_order_flow f2
  111. WHERE f2.order_id = f.order_id
  112. AND f2.action_type IN ('approved', 'resume', 'auto_suspend', 'auto_resume')
  113. AND f.action_time >= f2.action_time) AS order_seq
  114. FROM gxt_repair_order_flow f
  115. LEFT JOIN gxt_repair_order ro
  116. ON ro.id = f.order_id
  117. WHERE f.action_type IN ('approved', 'resume', 'auto_suspend', 'auto_resume')
  118. ) t
  119. </select>
  120. <insert id="addRepairOrderFlowRecords">
  121. INSERT INTO gxt_repair_order_flow_records (
  122. order_id,
  123. action_type,
  124. action_time,
  125. real_start_time,
  126. order_seq
  127. )
  128. SELECT
  129. f.order_id,
  130. f.action_type,
  131. f.action_time,
  132. ro.real_start_time,
  133. (SELECT COUNT(*)
  134. FROM gxt_repair_order_flow f2
  135. WHERE f2.order_id = f.order_id
  136. AND f2.action_type IN ('approved', 'resume', 'auto_suspend', 'auto_resume')
  137. AND f.action_time >= f2.action_time) AS order_seq
  138. FROM gxt_repair_order_flow f
  139. LEFT JOIN gxt_repair_order ro
  140. ON ro.id = f.order_id
  141. WHERE f.action_type IN ('approved', 'resume', 'auto_suspend', 'auto_resume')
  142. ORDER BY f.order_id, f.action_time
  143. </insert>
  144. <insert id="addRepairOrderFlowRecordsNext">
  145. INSERT INTO gxt_repair_order_flow_records_next (
  146. order_id,
  147. total_before_start_suspend_seconds,
  148. total_in_work_suspend_seconds,
  149. total_night_auto_suspend_seconds,
  150. before_start_suspend_format,
  151. in_work_suspend_format,
  152. night_auto_suspend_format
  153. )
  154. SELECT
  155. t0.order_id,
  156. COALESCE(SUM(CASE
  157. WHEN t1.action_time <![CDATA[<]]> t1.real_start_time
  158. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  159. ELSE 0
  160. END), 0) AS total_before_start_suspend_seconds,
  161. COALESCE(SUM(CASE
  162. WHEN t1.action_time >= t1.real_start_time
  163. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  164. ELSE 0
  165. END), 0) AS total_in_work_suspend_seconds,
  166. COALESCE(SUM(CASE
  167. WHEN t4.action_time IS NOT NULL
  168. THEN TIMESTAMPDIFF(SECOND, t3.action_time, t4.action_time)
  169. ELSE 0
  170. END), 0) AS total_night_auto_suspend_seconds,
  171. CONCAT(
  172. FLOOR(COALESCE(SUM(CASE
  173. WHEN t1.action_time <![CDATA[<]]> t1.real_start_time
  174. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  175. ELSE 0
  176. END), 0) / 3600), '小时',
  177. FLOOR(MOD(COALESCE(SUM(CASE
  178. WHEN t1.action_time <![CDATA[<]]> t1.real_start_time
  179. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  180. ELSE 0
  181. END), 0), 3600) / 60), '分钟',
  182. MOD(COALESCE(SUM(CASE
  183. WHEN t1.action_time <![CDATA[<]]> t1.real_start_time
  184. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  185. ELSE 0
  186. END), 0), 60), '秒'
  187. ) AS before_start_suspend_format,
  188. CONCAT(
  189. FLOOR(COALESCE(SUM(CASE
  190. WHEN t1.action_time >= t1.real_start_time
  191. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  192. ELSE 0
  193. END), 0) / 3600), '小时',
  194. FLOOR(MOD(COALESCE(SUM(CASE
  195. WHEN t1.action_time >= t1.real_start_time
  196. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  197. ELSE 0
  198. END), 0), 3600) / 60), '分钟',
  199. MOD(COALESCE(SUM(CASE
  200. WHEN t1.action_time >= t1.real_start_time
  201. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  202. ELSE 0
  203. END), 0), 60), '秒'
  204. ) AS in_work_suspend_format,
  205. CONCAT(
  206. FLOOR(COALESCE(SUM(CASE
  207. WHEN t4.action_time IS NOT NULL
  208. THEN TIMESTAMPDIFF(SECOND, t3.action_time, t4.action_time)
  209. ELSE 0
  210. END), 0) / 3600), '小时',
  211. FLOOR(MOD(COALESCE(SUM(CASE
  212. WHEN t4.action_time IS NOT NULL
  213. THEN TIMESTAMPDIFF(SECOND, t3.action_time, t4.action_time)
  214. ELSE 0
  215. END), 0), 3600) / 60), '分钟',
  216. MOD(COALESCE(SUM(CASE
  217. WHEN t4.action_time IS NOT NULL
  218. THEN TIMESTAMPDIFF(SECOND, t3.action_time, t4.action_time)
  219. ELSE 0
  220. END), 0), 60), '秒'
  221. ) AS night_auto_suspend_format
  222. FROM (SELECT order_id FROM gxt_repair_order_flow_records GROUP BY order_id) t0
  223. LEFT JOIN gxt_repair_order_flow_records t1
  224. ON t0.order_id = t1.order_id
  225. AND t1.action_type = 'approved'
  226. LEFT JOIN gxt_repair_order_flow_records t2
  227. ON t1.order_id = t2.order_id
  228. AND t2.order_seq = t1.order_seq + 1
  229. AND t1.action_type = 'approved'
  230. AND t2.action_type IN ('resume','auto_resume')
  231. LEFT JOIN gxt_repair_order_flow_records t3
  232. ON t0.order_id = t3.order_id
  233. AND t3.action_type = 'auto_suspend'
  234. LEFT JOIN gxt_repair_order_flow_records t4
  235. ON t3.order_id = t4.order_id
  236. AND t4.order_seq = t3.order_seq + 1
  237. AND t3.action_type = 'auto_suspend'
  238. AND t4.action_type IN ('resume','auto_resume')
  239. GROUP BY t0.order_id
  240. ORDER BY t0.order_id
  241. </insert>
  242. <select id="selectWorkOrderFlowRecordsSize" resultType="Integer">
  243. SELECT count(*) FROM gxt_work_order_flow_records
  244. </select>
  245. <select id="workOrderFlowRecordsSize" resultType="Integer">
  246. SELECT COUNT(*) FROM (
  247. SELECT
  248. f.order_id,
  249. f.action_type,
  250. f.action_time,
  251. ro.real_start_time,
  252. (SELECT COUNT(*)
  253. FROM gxt_work_order_flow f2
  254. WHERE f2.order_id = f.order_id
  255. AND f2.action_type IN ('approved', 'resume', 'auto_suspend', 'auto_resume')
  256. AND f.action_time >= f2.action_time) AS order_seq
  257. FROM gxt_work_order_flow f
  258. LEFT JOIN gxt_work_order ro
  259. ON ro.id = f.order_id
  260. WHERE f.action_type IN ('approved', 'resume', 'auto_suspend', 'auto_resume')) t
  261. </select>
  262. <insert id="addWorkOrderFlowRecords">
  263. INSERT INTO gxt_work_order_flow_records (
  264. order_id,
  265. action_type,
  266. action_time,
  267. real_start_time,
  268. order_seq
  269. )
  270. SELECT
  271. f.order_id,
  272. f.action_type,
  273. f.action_time,
  274. ro.real_start_time,
  275. (SELECT COUNT(*)
  276. FROM gxt_work_order_flow f2
  277. WHERE f2.order_id = f.order_id
  278. AND f2.action_type IN ('approved', 'resume', 'auto_suspend', 'auto_resume')
  279. AND f.action_time >= f2.action_time) AS order_seq
  280. FROM gxt_work_order_flow f
  281. LEFT JOIN gxt_work_order ro
  282. ON ro.id = f.order_id
  283. WHERE f.action_type IN ('approved', 'resume', 'auto_suspend', 'auto_resume')
  284. ORDER BY f.order_id, f.action_time
  285. </insert>
  286. <insert id="addWorkOrderFlowRecordsNext">
  287. INSERT INTO gxt_work_order_flow_records_next (
  288. order_id,
  289. total_before_start_suspend_seconds,
  290. total_in_work_suspend_seconds,
  291. total_night_auto_suspend_seconds,
  292. before_start_suspend_format,
  293. in_work_suspend_format,
  294. night_auto_suspend_format
  295. )
  296. SELECT
  297. t0.order_id,
  298. COALESCE(SUM(CASE
  299. WHEN t1.action_time <![CDATA[<]]> t1.real_start_time
  300. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  301. ELSE 0
  302. END), 0) AS total_before_start_suspend_seconds,
  303. COALESCE(SUM(CASE
  304. WHEN t1.action_time >= t1.real_start_time
  305. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  306. ELSE 0
  307. END), 0) AS total_in_work_suspend_seconds,
  308. COALESCE(SUM(CASE
  309. WHEN t4.action_time IS NOT NULL
  310. THEN TIMESTAMPDIFF(SECOND, t3.action_time, t4.action_time)
  311. ELSE 0
  312. END), 0) AS total_night_auto_suspend_seconds,
  313. CONCAT(
  314. FLOOR(COALESCE(SUM(CASE
  315. WHEN t1.action_time <![CDATA[<]]> t1.real_start_time
  316. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  317. ELSE 0
  318. END), 0) / 3600), '小时',
  319. FLOOR(MOD(COALESCE(SUM(CASE
  320. WHEN t1.action_time <![CDATA[<]]> t1.real_start_time
  321. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  322. ELSE 0
  323. END), 0), 3600) / 60), '分钟',
  324. MOD(COALESCE(SUM(CASE
  325. WHEN t1.action_time <![CDATA[<]]> t1.real_start_time
  326. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  327. ELSE 0
  328. END), 0), 60), '秒'
  329. ) AS before_start_suspend_format,
  330. CONCAT(
  331. FLOOR(COALESCE(SUM(CASE
  332. WHEN t1.action_time >= t1.real_start_time
  333. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  334. ELSE 0
  335. END), 0) / 3600), '小时',
  336. FLOOR(MOD(COALESCE(SUM(CASE
  337. WHEN t1.action_time >= t1.real_start_time
  338. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  339. ELSE 0
  340. END), 0), 3600) / 60), '分钟',
  341. MOD(COALESCE(SUM(CASE
  342. WHEN t1.action_time >= t1.real_start_time
  343. THEN TIMESTAMPDIFF(SECOND, t1.action_time, t2.action_time)
  344. ELSE 0
  345. END), 0), 60), '秒'
  346. ) AS in_work_suspend_format,
  347. CONCAT(
  348. FLOOR(COALESCE(SUM(CASE
  349. WHEN t4.action_time IS NOT NULL
  350. THEN TIMESTAMPDIFF(SECOND, t3.action_time, t4.action_time)
  351. ELSE 0
  352. END), 0) / 3600), '小时',
  353. FLOOR(MOD(COALESCE(SUM(CASE
  354. WHEN t4.action_time IS NOT NULL
  355. THEN TIMESTAMPDIFF(SECOND, t3.action_time, t4.action_time)
  356. ELSE 0
  357. END), 0), 3600) / 60), '分钟',
  358. MOD(COALESCE(SUM(CASE
  359. WHEN t4.action_time IS NOT NULL
  360. THEN TIMESTAMPDIFF(SECOND, t3.action_time, t4.action_time)
  361. ELSE 0
  362. END), 0), 60), '秒'
  363. ) AS night_auto_suspend_format
  364. FROM (SELECT order_id FROM gxt_work_order_flow_records GROUP BY order_id) t0
  365. LEFT JOIN gxt_work_order_flow_records t1
  366. ON t0.order_id = t1.order_id
  367. AND t1.action_type = 'approved'
  368. LEFT JOIN gxt_work_order_flow_records t2
  369. ON t1.order_id = t2.order_id
  370. AND t2.order_seq = t1.order_seq + 1
  371. AND t1.action_type = 'approved'
  372. AND t2.action_type IN ('resume','auto_resume')
  373. LEFT JOIN gxt_work_order_flow_records t3
  374. ON t0.order_id = t3.order_id
  375. AND t3.action_type = 'auto_suspend'
  376. LEFT JOIN gxt_work_order_flow_records t4
  377. ON t3.order_id = t4.order_id
  378. AND t4.order_seq = t3.order_seq + 1
  379. AND t3.action_type = 'auto_suspend'
  380. AND t4.action_type IN ('resume','auto_resume')
  381. GROUP BY t0.order_id
  382. ORDER BY t0.order_id
  383. </insert>
  384. </mapper>