RepairApplicationFormMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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.platform.dao.mapper.repair.RepairApplicationFormMapper">
  4. <sql id="Base_Column_List">
  5. application.*,
  6. user.real_name as userName,
  7. user2.real_name as repairUserName,
  8. user3.real_name as checkUserName,
  9. sb.name as sbName,part.name as partName,
  10. sb.no as sbNo, sb.cph as sbCph, sb.model_id as modelId,
  11. error.name as repairErrorTypeName,
  12. dept.name as deptName
  13. </sql>
  14. <select id="selectPageList" parameterType="com.platform.dao.dto.repair.RepairApplicationFormDTO"
  15. resultType="com.platform.dao.vo.repair.RepairApplicationFormVO">
  16. select
  17. <include refid="Base_Column_List"/>,
  18. user4.real_name as repairUser,sbPos.name as positionName,
  19. part.name as partName,userSecond.real_name as secondRepairUserName,
  20. userThree.real_name as threeRepairUserName,userFour.real_name as fourRepairUserName
  21. from t_repair_application_form application
  22. left join t_sys_user user on application.user_id = user.user_id
  23. left join t_sys_user user2 on application.repair_user_id = user2.user_id
  24. left join t_sys_user user3 on application.check_user_id = user3.user_id
  25. left join t_sys_user userSecond on application.second_repair_user = userSecond.user_id
  26. left join t_sys_user userThree on application.three_repair_user = userThree.user_id
  27. left join t_sys_user userFour on application.four_repair_user = userFour.user_id
  28. left join t_sb_info sb on application.sb_id = sb.id
  29. left join t_sb_position sbPos on sbPos.id = sb.position_id
  30. left join t_sys_user user4 on sb.repair_user = user4.user_id
  31. left join t_error_type error on application.repair_error_type_id = error.id
  32. left join t_part_info part on application.part_id = part.id
  33. left join t_sys_dept dept on application.dept_id = dept.dept_id
  34. <where>
  35. <if test="keyword != null and keyword != ''">
  36. and (
  37. application.no like concat('%',#{keyword},'%') or
  38. application.content like concat('%',#{keyword},'%') or
  39. application.remark like concat('%',#{keyword},'%') or
  40. application.repair_content like concat('%',#{keyword},'%') or
  41. application.check_content like concat('%',#{keyword},'%') or
  42. application.examine_content like concat('%',#{keyword},'%') or
  43. application.refuse_remark like concat('%',#{keyword},'%') or
  44. application.repair_dispatch_remark like concat('%',#{keyword},'%') or
  45. application.actual_user like concat('%',#{keyword},'%') or
  46. application.out_no like concat('%',#{keyword},'%') or
  47. sb.name like concat('%',#{keyword},'%') or
  48. sb.no like concat('%',#{keyword},'%') or
  49. sb.cph like concat('%',#{keyword},'%') or
  50. sbPos.name like concat('%',#{keyword},'%') or
  51. error.name like concat('%',#{keyword},'%') or
  52. part.name like concat('%',#{keyword},'%') or
  53. user.real_name like concat('%',#{keyword},'%') or
  54. user2.real_name like concat('%',#{keyword},'%') or
  55. user3.real_name like concat('%',#{keyword},'%') or
  56. user4.real_name like concat('%',#{keyword},'%') or
  57. userSecond.real_name like concat('%',#{keyword},'%') or
  58. userThree.real_name like concat('%',#{keyword},'%') or
  59. userFour.real_name like concat('%',#{keyword},'%')
  60. )
  61. </if>
  62. <if test="content != null and content != ''">
  63. and application.content like concat('%',#{content},'%')
  64. </if>
  65. <if test="sbId != null and sbId != ''">
  66. and application.sb_id = #{sbId}
  67. </if>
  68. <if test="category != null and category != ''">
  69. and application.category = #{category}
  70. </if>
  71. <if test="categoryList != null and categoryList.size > 0">
  72. AND application.category in
  73. <foreach item="item" index="index" collection="categoryList" open="(" close=")" separator=",">
  74. #{item}
  75. </foreach>
  76. </if>
  77. <if test="zbh != null and zbh != ''">
  78. and sb.zbh = #{zbh}
  79. </if>
  80. <if test="no != null and no != ''">
  81. and application.no = #{no}
  82. </if>
  83. <if test="planFlag != null and planFlag != ''">
  84. and application.plan_flag = #{planFlag}
  85. </if>
  86. <if test="status != null and status != ''">
  87. and application.status = #{status}
  88. </if>
  89. <if test="statusList != null and statusList.size > 0">
  90. and application.status in
  91. <foreach item="item" index="index" collection="statusList" open="(" close=")" separator=",">
  92. #{item}
  93. </foreach>
  94. </if>
  95. <if test="actualUser != null and actualUser != ''">
  96. and application.actual_user = #{actualUser}
  97. </if>
  98. <if test="mainRepairId != null and mainRepairId != ''">
  99. and application.main_repair_id = #{mainRepairId}
  100. </if>
  101. <if test="outType != null and outType != ''">
  102. and application.out_type = #{outType}
  103. </if>
  104. <if test="type != null and type != ''">
  105. and application.type = #{type}
  106. </if>
  107. <if test="userId != null and userId != ''">
  108. and application.user_id = #{userId}
  109. </if>
  110. <if test="repairUserId != null and repairUserId != ''">
  111. <if test="repairUserIdOrNoAssignFlag != null and repairUserIdOrNoAssignFlag == true">
  112. and (application.repair_user_id = #{repairUserId} or application.repair_user_id is null)
  113. </if>
  114. <if test="repairUserIdOrNoAssignFlag == null || repairUserIdOrNoAssignFlag == false">
  115. and (application.repair_user_id = #{repairUserId} or application.second_repair_user = #{repairUserId} or application.three_repair_user = #{repairUserId} or application.four_repair_user = #{repairUserId})
  116. </if>
  117. </if>
  118. <if test="checkUserId != null and checkUserId != ''">
  119. and application.check_user_id = #{checkUserId}
  120. </if>
  121. <if test="repairUserName != null and repairUserName != ''">
  122. and user2.real_name like concat('%',#{repairUserName},'%')
  123. </if>
  124. <if test="searchStartTime != null">
  125. and application.apply_time <![CDATA[ >= ]]> #{searchStartTime}
  126. </if>
  127. <if test="searchEndTime != null">
  128. and application.apply_time <![CDATA[ <= ]]> #{searchEndTime}
  129. </if>
  130. <if test="deptId != null and deptId != ''">
  131. and application.dept_id = #{deptId}
  132. </if>
  133. <if test="deptIdList != null and deptIdList.size > 0">
  134. AND application.dept_id in
  135. <foreach item="item" index="index" collection="deptIdList" open="(" close=")" separator=",">
  136. #{item}
  137. </foreach>
  138. </if>
  139. </where>
  140. </select>
  141. <select id="selectById" parameterType="java.lang.Object"
  142. resultType="com.platform.dao.entity.repair.RepairApplicationForm">
  143. select
  144. <include refid="Base_Column_List"/>
  145. from t_repair_application_form application
  146. left join t_sys_user user on application.user_id = user.user_id
  147. left join t_sys_user user2 on application.repair_user_id = user2.user_id
  148. left join t_sys_user user3 on application.check_user_id = user3.user_id
  149. left join t_sb_info sb on application.sb_id = sb.id
  150. left join t_part_info part on application.part_id = part.id
  151. left join t_error_type error on application.repair_error_type_id = error.id
  152. left join t_sys_dept dept on application.dept_id = dept.dept_id
  153. where application.id = #{id,jdbcType=VARCHAR}
  154. </select>
  155. <select id="selectNoById" parameterType="java.lang.Object" resultType="java.lang.String">
  156. select no
  157. from t_repair_application_form
  158. where id = #{id,jdbcType=VARCHAR}
  159. </select>
  160. <!-- 查询存在指定状态报修单的设备ID(用于排除审核中工单的设备) -->
  161. <select id="selectSbIdsWithStatus" resultType="java.lang.String">
  162. SELECT DISTINCT application.sb_id
  163. FROM t_repair_application_form application
  164. <where>
  165. <if test="sbIds != null and sbIds.size > 0">
  166. AND application.sb_id IN
  167. <foreach item="item" index="index" collection="sbIds" open="(" close=")" separator=",">
  168. #{item}
  169. </foreach>
  170. </if>
  171. <if test="status != null and status.size > 0">
  172. AND application.status IN
  173. <foreach item="item" index="index" collection="status" open="(" close=")" separator=",">
  174. #{item}
  175. </foreach>
  176. </if>
  177. </where>
  178. </select>
  179. <!-- 维修工时统计:按维修人分组,统计维修结束时间不为空的报修单 -->
  180. <select id="statisticsWorkHourByUser" parameterType="com.platform.dao.dto.repair.RepairApplicationFormDTO"
  181. resultType="com.platform.dao.vo.report.RepairWorkHourReportVO">
  182. select application.repair_user_id as repairUserId,
  183. user2.real_name as repairUserName,
  184. count(1) as num,
  185. IFNULL(sum(application.repair_minutes), 0) as totalRepairHours,
  186. IFNULL(avg(application.repair_minutes), 0) as avgRepairHours,
  187. IFNULL(sum(application.deal_minutes), 0) as totalDealHours
  188. from t_repair_application_form application
  189. left join t_sys_user user2 on application.repair_user_id = user2.user_id
  190. <where>
  191. application.repair_end_time is not null
  192. and application.repair_user_id is not null and application.repair_user_id != ''
  193. <if test="repairUserId != null and repairUserId != ''">
  194. and application.repair_user_id = #{repairUserId}
  195. </if>
  196. <if test="repairUserName != null and repairUserName != ''">
  197. and user2.real_name like concat('%',#{repairUserName},'%')
  198. </if>
  199. <if test="searchRepairStartTime != null">
  200. and application.repair_start_time <![CDATA[ >= ]]> #{searchRepairStartTime}
  201. </if>
  202. <if test="searchRepairEndTime != null">
  203. and application.repair_start_time <![CDATA[ <= ]]> #{searchRepairEndTime}
  204. </if>
  205. </where>
  206. group by application.repair_user_id
  207. order by totalRepairHours desc
  208. </select>
  209. <!-- 维修工时统计:按设备分组,统计维修结束时间不为空的报修单 -->
  210. <select id="statisticsWorkHourBySb" parameterType="com.platform.dao.dto.repair.RepairApplicationFormDTO"
  211. resultType="com.platform.dao.vo.report.RepairWorkHourReportVO">
  212. select application.sb_id as sbId,
  213. sb.no as sbNo,
  214. sb.name as sbName,
  215. sbType.name as sbTypeName,
  216. count(1) as num,
  217. IFNULL(sum(application.repair_minutes), 0) as totalRepairHours,
  218. IFNULL(avg(application.repair_minutes), 0) as avgRepairHours,
  219. IFNULL(sum(application.deal_minutes), 0) as totalDealHours
  220. from t_repair_application_form application
  221. left join t_sb_info sb on application.sb_id = sb.id
  222. left join t_sb_type sbType on sb.type_id = sbType.id
  223. <where>
  224. application.repair_end_time is not null
  225. and application.sb_id is not null and application.sb_id != ''
  226. <if test="sbId != null and sbId != ''">
  227. and application.sb_id = #{sbId}
  228. </if>
  229. <if test="keyword != null and keyword != ''">
  230. and (sb.name like concat('%',#{keyword},'%') or sb.no like concat('%',#{keyword},'%'))
  231. </if>
  232. <if test="searchRepairStartTime != null">
  233. and application.repair_start_time <![CDATA[ >= ]]> #{searchRepairStartTime}
  234. </if>
  235. <if test="searchRepairEndTime != null">
  236. and application.repair_start_time <![CDATA[ <= ]]> #{searchRepairEndTime}
  237. </if>
  238. </where>
  239. group by application.sb_id
  240. order by totalRepairHours desc
  241. </select>
  242. <!-- 维修工时统计明细:某维修人或某设备已完成维修的报修单列表 -->
  243. <select id="selectWorkHourDetail" parameterType="com.platform.dao.dto.repair.RepairApplicationFormDTO"
  244. resultType="com.platform.dao.vo.repair.RepairApplicationFormVO">
  245. select
  246. <include refid="Base_Column_List"/>
  247. from t_repair_application_form application
  248. left join t_sys_user user on application.user_id = user.user_id
  249. left join t_sys_user user2 on application.repair_user_id = user2.user_id
  250. left join t_sys_user user3 on application.check_user_id = user3.user_id
  251. left join t_sb_info sb on application.sb_id = sb.id
  252. left join t_part_info part on application.part_id = part.id
  253. left join t_error_type error on application.repair_error_type_id = error.id
  254. left join t_sys_dept dept on application.dept_id = dept.dept_id
  255. <where>
  256. application.repair_end_time is not null
  257. <if test="repairUserId != null and repairUserId != ''">
  258. and application.repair_user_id = #{repairUserId}
  259. </if>
  260. <if test="sbId != null and sbId != ''">
  261. and application.sb_id = #{sbId}
  262. </if>
  263. <if test="searchRepairStartTime != null">
  264. and application.repair_start_time <![CDATA[ >= ]]> #{searchRepairStartTime}
  265. </if>
  266. <if test="searchRepairEndTime != null">
  267. and application.repair_start_time <![CDATA[ <= ]]> #{searchRepairEndTime}
  268. </if>
  269. </where>
  270. order by application.repair_start_time desc
  271. </select>
  272. <select id="selectMaxNo" parameterType="com.platform.dao.dto.repair.RepairApplicationFormDTO" resultType="String">
  273. SELECT max(SUBSTRING(no from 18 for 20 )) from t_repair_application_form
  274. <where>
  275. <if test="applyTimeStart != null">
  276. and apply_time <![CDATA[ > ]]> #{applyTimeStart}
  277. </if>
  278. <if test="applyTimeEnd != null">
  279. and apply_time <![CDATA[ < ]]> #{applyTimeEnd}
  280. </if>
  281. </where>
  282. </select>
  283. <!-- 维修工时统计:按月度统计所有设备的单次平均维修工时 -->
  284. <select id="statisticsWorkHourByMonth" parameterType="com.platform.dao.dto.repair.RepairApplicationFormDTO"
  285. resultType="com.platform.dao.vo.report.RepairWorkHourReportVO">
  286. select application.sb_id as sbId,
  287. sb.no as sbNo,
  288. sb.name as sbName,
  289. sbType.name as sbTypeName,
  290. count(1) as num,
  291. IFNULL(sum(application.repair_minutes), 0) as totalRepairHours,
  292. IFNULL(avg(application.repair_minutes), 0) as avgRepairHours,
  293. IFNULL(sum(application.deal_minutes), 0) as totalDealHours
  294. from t_repair_application_form application
  295. left join t_sb_info sb on application.sb_id = sb.id
  296. left join t_sb_type sbType on sb.type_id = sbType.id
  297. <where>
  298. application.repair_end_time is not null
  299. and application.sb_id is not null and application.sb_id != ''
  300. <if test="sbId != null and sbId != ''">
  301. and application.sb_id = #{sbId}
  302. </if>
  303. <if test="keyword != null and keyword != ''">
  304. and (sb.name like concat('%',#{keyword},'%') or sb.no like concat('%',#{keyword},'%'))
  305. </if>
  306. <if test="searchRepairStartTime != null">
  307. and application.repair_start_time <![CDATA[ >= ]]> #{searchRepairStartTime}
  308. </if>
  309. <if test="searchRepairEndTime != null">
  310. and application.repair_start_time <![CDATA[ <= ]]> #{searchRepairEndTime}
  311. </if>
  312. </where>
  313. group by application.sb_id
  314. having totalRepairHours > 0
  315. order by totalRepairHours desc
  316. </select>
  317. </mapper>