RepairRecordMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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.repair.mapper.RepairRecordMapper">
  4. <resultMap type="com.repair.model.vo.RepairRecordCountVo" id="repairRecordCountMap">
  5. <result property="Incomplete" column="Incomplete"/>
  6. <result property="Confirmed" column="Confirmed"/>
  7. <result property="Finished" column="Finished"/>
  8. </resultMap>
  9. <select id="queryRepairRecordCount" resultType="com.repair.model.vo.RepairRecordCountVo"
  10. resultMap="repairRecordCountMap">
  11. SELECT COUNT(IF(maintenance_state &lt; 7,1, NULL)) Incomplete,COUNT(IF(maintenance_state=4,1, NULL))
  12. Confirmed,COUNT(IF(maintenance_state &gt;=7 ,1, NULL)) Finished FROM `repair_record`
  13. <where>
  14. and maintenance_state &lt;= 7 and deleted = 0
  15. <if test="userId != null and userId != ''">
  16. and user_id = #{userId}
  17. </if>
  18. </where>
  19. </select>
  20. <resultMap type="com.repair.model.vo.MyRepairRecordVo" id="repairRecordOwnMap">
  21. <result property="id" column="id"/>
  22. <result property="recordNo" column="record_no"/>
  23. <result property="reportTime" column="report_time"/>
  24. <result property="dispatchTime" column="dispatch_time"/>
  25. <result property="userName" column="user_name"/>
  26. <result property="userPhone" column="user_phone"/>
  27. <result property="areaName" column="area_name"/>
  28. <result property="address" column="address"/>
  29. <result property="articleName" column="article_name"/>
  30. <result property="descript" column="description"/>
  31. <result property="image" column="image"/>
  32. <result property="stateId" column="state_id"/>
  33. <result property="price" column="price"/>
  34. <result property="maintenancerName" column="maintenancer_name"/>
  35. <result property="maintenancerPhone" column="maintenancer_phone"/>
  36. <result property="timeoutDispStr" column="timeout_disp_str"/>
  37. <result property="timeoutReceStr" column="timeout_rece_str"/>
  38. </resultMap>
  39. <select id="queryMyRepairRecordList" resultType="com.repair.model.vo.MyRepairRecordVo"
  40. resultMap="repairRecordOwnMap">
  41. select
  42. case date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW() when true then '超时未接'
  43. else null end as timeout_disp_str,
  44. case date_add(rdv.receiving_time, interval rdv.maintenance_assess_time minute) &lt;= NOW() when true then '维修超时'
  45. else null end as timeout_rece_str,
  46. rr.id,rr.price,rr.maintenancer_name,rr.maintenancer_phone,rr.record_no,rr.report_time,rr.dispatch_time,rr.user_name,rr.user_phone,rr.area_id
  47. as area_name,rr.address,rr.description,rat.name as article_name,rr.image,rr.maintenance_state as state_id from
  48. repair_record rr
  49. left join repair_article_type rat on rat.id = rr.article_id
  50. left join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr.id and rdr.is_lose_efficacy = 0
  51. left join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr.id and rdv.is_lose_efficacy = 0
  52. <where>
  53. and rr.deleted = 0
  54. <if test="stateStr != null and stateStr != ''">
  55. and rr.maintenance_state ${stateStr}
  56. </if>
  57. <if test="userId != null and userId != ''">
  58. and rr.user_id = #{userId}
  59. </if>
  60. </where>
  61. order by rr.report_time DESC
  62. </select>
  63. <resultMap type="com.repair.model.vo.MaintenanceTechnicianVo" id="repairRecordTechnicianMap">
  64. <result property="receivingCount" column="receiving_count"/>
  65. <result property="maintenanceCount" column="maintenance_count"/>
  66. <result property="timeoutCount" column="timeout_count"/>
  67. <result property="examineCount" column="examine_count"/>
  68. </resultMap>
  69. <select id="queryRepairTechnicianCount" resultType="com.repair.model.vo.MaintenanceTechnicianVo"
  70. resultMap="repairRecordTechnicianMap">
  71. select (select Count(*) from repair_record rr1
  72. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.users_id = #{userId} and rdr.record_id = rr1.id and
  73. rdr.is_lose_efficacy = 0
  74. where rr1.maintenance_state = 1 and rr1.deleted = 0) as receiving_count ,(select Count(*) from repair_record rr2
  75. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.user_id = #{userId} and rdv.record_id = rr2.id and
  76. rdv.is_lose_efficacy = 0
  77. where rr2.maintenance_state = 2 and rr2.deleted = 0) as maintenance_count,(select Count(*) as cs from (select rr3.*
  78. from repair_record rr3
  79. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.users_id = #{userId} and rdr.record_id = rr3.id and
  80. rdr.is_lose_efficacy = 0
  81. and date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow}
  82. where rr3.maintenance_state = 1 and rr3.deleted = 0
  83. UNION ALL
  84. select rr4.* from repair_record rr4
  85. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.user_id = #{userId} and rdv.record_id = rr4.id and
  86. rdv.is_lose_efficacy = 0
  87. and date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= #{dateNow}
  88. where rr4.maintenance_state = 2 and rr4.deleted = 0) c) as timeout_count,(select Count(*) as sh from (
  89. select rr5.* from repair_record rr5
  90. inner join repair_collaborate_record rcr on rcr.deleted = 0 and rcr.user_id = #{userId} and rcr.record_id = rr5.id and
  91. rcr.approval_statu = 2
  92. where rr5.maintenance_state = 6 and rr5.deleted = 0
  93. UNION ALL
  94. select rr.* from repair_record rr
  95. inner join repair_transfer_record rtr on rtr.deleted = 0 and rtr.user_id = #{userId} and rtr.record_id = rr.id and
  96. rtr.approval_statu = 2
  97. where rr.maintenance_state = 5 and rr.deleted = 0) a) as examine_count
  98. </select>
  99. <resultMap type="com.repair.model.vo.RepairTechnicianVo" id="repairRecordTechnicianDataMap">
  100. <result property="id" column="id"/>
  101. <result property="recordNo" column="record_no"/>
  102. <result property="reportTime" column="report_time"/>
  103. <result property="userName" column="user_name"/>
  104. <result property="userPhone" column="user_phone"/>
  105. <result property="areaName" column="area_name"/>
  106. <result property="address" column="address"/>
  107. <result property="articleName" column="article_name"/>
  108. <result property="description" column="description"/>
  109. <result property="image" column="image"/>
  110. <result property="state" column="state"/>
  111. <result property="timeoutStr" column="timeout_str"/>
  112. </resultMap>
  113. <!--待接单-->
  114. <select id="queryPendingOrderList" resultType="com.repair.model.vo.RepairTechnicianVo"
  115. resultMap="repairRecordTechnicianDataMap">
  116. select case date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} when true then '超时未接' else null end as timeout_str,rr.id,rr.record_no,rr.report_time,rr.user_name,rr.user_phone,rr.area_id as area_name,rr.address,rat.name as article_name,rr.description,rr.image,'待接单' as state
  117. from repair_record rr
  118. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.users_id = #{userId} and rdr.record_id = rr.id and rdr.is_lose_efficacy = 0
  119. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  120. where rr.maintenance_state = 1 and rr.deleted = 0
  121. order by rr.report_time DESC
  122. </select>
  123. <!--维修中-->
  124. <select id="queryRepairOrderList" resultType="com.repair.model.vo.RepairTechnicianVo"
  125. resultMap="repairRecordTechnicianDataMap">
  126. select case date_add(rdv.receiving_time, interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} when true then '维修超时' else null end as timeout_str,rr.id,rr.record_no,rr.report_time,rr.user_name,rr.user_phone,rr.area_id as area_name,rr.address,rat.name as article_name ,rr.description,rr.image,'维修中' as state
  127. from repair_record rr
  128. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.user_id = #{userId} and rdv.record_id = rr.id and rdv.is_lose_efficacy = 0
  129. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  130. where rr.maintenance_state = 2 and rr.deleted = 0
  131. order by rr.report_time DESC
  132. </select>
  133. <!--已超时-->
  134. <select id="queryTimeoutOrderList" resultType="com.repair.model.vo.RepairTechnicianVo"
  135. resultMap="repairRecordTechnicianDataMap">
  136. SELECT * FROM (
  137. select case date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} when true then '超时未接' else null end as timeout_str,rr.id,rr.record_no,rr.report_time,rr.user_name,rr.user_phone,rr.area_id as area_name,rr.address,rat.name as article_name ,rr.description,rr.image,'待接单' as state from repair_record rr
  138. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.users_id = #{userId} and rdr.record_id = rr.id and rdr.is_lose_efficacy = 0
  139. and date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow}
  140. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  141. where rr.maintenance_state = 1 and rr.deleted = 0
  142. UNION ALL
  143. select case date_add(rdv.receiving_time, interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} when true then '维修超时' else null end as timeout_str,rr.id,rr.record_no,rr.report_time,rr.user_name,rr.user_phone,rr.area_id as area_name,rr.address,rat.name as article_name ,rr.description,rr.image,'维修中' as state from repair_record rr
  144. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.user_id = #{userId} and rdv.record_id = rr.id and rdv.is_lose_efficacy = 0
  145. and date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= #{dateNow}
  146. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  147. where rr.maintenance_state = 2 and rr.deleted = 0) t
  148. order by t.report_time desc
  149. </select>
  150. <!--待审核-->
  151. <select id="queryExamineOrderList" resultType="com.repair.model.vo.RepairTechnicianVo"
  152. resultMap="repairRecordTechnicianDataMap">
  153. select rr.id,rr.record_no,rr.report_time,rr.user_name,rr.user_phone,rr.area_id as area_name,rr.address,rat.name as article_name ,rr.description,rr.image,'协作审核' as state from repair_record rr
  154. inner join repair_collaborate_record rcr on rcr.deleted = 0 and rcr.user_id = #{userId} and rcr.record_id = rr.id and rcr.approval_statu = 2
  155. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  156. where rr.maintenance_state = 6 and rr.deleted = 0
  157. UNION ALL
  158. select rr.id,rr.record_no,rr.report_time,rr.user_name,rr.user_phone,rr.area_id as area_name,rr.address,rat.name as article_name ,rr.description,rr.image,'转单审核' as state from repair_record rr
  159. inner join repair_transfer_record rtr on rtr.deleted = 0 and rtr.user_id = #{userId} and rtr.record_id = rr.id and rtr.approval_statu = 2
  160. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  161. where rr.maintenance_state = 5 and rr.deleted = 0
  162. </select>
  163. <resultMap type="com.repair.model.vo.RepairManageCountVo" id="repairManageCountMap">
  164. <result property="allCount" column="all_count"/>
  165. <result property="dispatchCount" column="dispatch_count"/>
  166. <result property="maintenanceCount" column="maintenance_count"/>
  167. <result property="logisticsCount" column="logistics_count"/>
  168. <result property="examineCount" column="examine_count"/>
  169. <result property="finishedCount" column="finished_count"/>
  170. <result property="canceledCount" column="canceled_count"/>
  171. <result property="closedCount" column="closed_count"/>
  172. <result property="timeoutCount" column="timeout_count"/>
  173. </resultMap>
  174. <select id="queryManageCount" resultType="com.repair.model.vo.RepairManageCountVo" resultMap="repairManageCountMap">
  175. select
  176. (select Count(*) from repair_record where deleted = 0) as all_count,
  177. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 1) as dispatch_count,
  178. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 2) as maintenance_count,
  179. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 3) as logistics_count,
  180. (select Count(*) from repair_record where deleted = 0 and (maintenance_state = 5 or maintenance_state = 6)) as examine_count,
  181. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 7) as finished_count,
  182. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 8) as canceled_count,
  183. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 9) as closed_count,
  184. (select Count(*) as cs from (select rr3.* from repair_record rr3
  185. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr3.id and
  186. rdr.is_lose_efficacy = 0 and date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW()
  187. where rr3.maintenance_state = 1 and rr3.deleted = 0
  188. UNION ALL
  189. select rr4.* from repair_record rr4
  190. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr4.id and
  191. rdv.is_lose_efficacy = 0 and date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= NOW()
  192. where rr4.maintenance_state = 2 and rr4.deleted = 0) c) as timeout_count
  193. </select>
  194. <resultMap type="com.repair.model.vo.RepairRecordPageVo" id="repairRecordPageMap">
  195. <result property="id" column="id"/>
  196. <result property="recordNo" column="record_no"/>
  197. <result property="userName" column="user_name"/>
  198. <result property="userPhone" column="user_phone"/>
  199. <result property="articleName" column="article_name"/>
  200. <result property="description" column="description"/>
  201. <result property="reportTime" column="report_time"/>
  202. <result property="maintenancerName" column="maintenancer_name"/>
  203. <result property="details" column="details"/>
  204. <result property="maintenanceState" column="maintenance_state"/>
  205. <result property="userId" column="user_id"/>
  206. </resultMap>
  207. <!--除已超时外的其他数据获取方式-->
  208. <select id="queryNotTimeout" resultType="com.repair.model.vo.RepairRecordPageVo" resultMap="repairRecordPageMap">
  209. select rr.user_id,1 as details,rr.id,rr.record_no,rr.area_id as area_name,rr.user_name,rr.user_phone,rat.name as
  210. article_name,
  211. rr.description,rr.report_time,rr.maintenancer_name,rr.maintenance_state
  212. from repair_record rr
  213. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  214. <where>
  215. and rr.deleted = 0
  216. <if test="stateStr != null and stateStr != ''">
  217. and (rr.maintenance_state ${stateStr}
  218. </if>
  219. <if test="keyWord != null and keyWord != ''">
  220. and (rr.area_id like '%' #{keyWord} '%' or rr.user_name like '%' #{keyWord} '%' or rr.user_phone like
  221. '%' #{keyWord} '%')
  222. </if>
  223. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  224. and rr.report_time between #{startTime} and #{endTime}
  225. </if>
  226. </where>
  227. order by rr.report_time desc
  228. </select>
  229. <!--#已超时获取方式-->
  230. <select id="queryTimeout" resultType="com.repair.model.vo.RepairRecordPageVo" resultMap="repairRecordPageMap">
  231. SELECT * FROM (
  232. select rr3.user_id,1 as details,rr3.id,rr3.record_no,rr3.area_id as
  233. area_name,rr3.user_name,rr3.user_phone,rat.name as article_name,
  234. rr3.description,rr3.report_time,rr3.maintenancer_name,rr3.maintenance_state
  235. from repair_record rr3
  236. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr3.article_id
  237. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr3.id and
  238. rdr.is_lose_efficacy = 0
  239. and date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW()
  240. <where>
  241. and rr3.maintenance_state = 1 and rr3.deleted = 0
  242. <if test="keyWord != null and keyWord != ''">
  243. and (rr3.area_id like '%' #{keyWord} '%' or rr3.user_name like '%' #{keyWord} '%' or rr3.user_phone like '%' #{keyWord} '%')
  244. </if>
  245. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  246. and rr3.report_time between #{startTime} and #{endTime}
  247. </if>
  248. </where>
  249. UNION ALL
  250. select rr4.user_id,1 as details,rr4.id,rr4.record_no,rr4.area_id as area_name,rr4.user_name,rr4.user_phone,rat.name as
  251. article_name,
  252. rr4.description,rr4.report_time,rr4.maintenancer_name,rr4.maintenance_state
  253. from repair_record rr4
  254. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr4.article_id
  255. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr4.id and
  256. rdv.is_lose_efficacy = 0
  257. and date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= NOW()
  258. <where>
  259. and rr4.maintenance_state = 2 and rr4.deleted = 0
  260. <if test="keyWord != null and keyWord != ''">
  261. and (rr4.area_id like '%' #{keyWord} '%' or rr4.user_name like '%' #{keyWord} '%' or rr4.user_phone like
  262. '%' #{keyWord} '%')
  263. </if>
  264. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  265. and rr4.report_time between #{startTime} and #{endTime}
  266. </if>
  267. </where>
  268. ) t
  269. order by t.report_time desc
  270. </select>
  271. <!--#获取待处理池数据-->
  272. <resultMap type="com.repair.model.vo.pendingOrderVo" id="repairPendingOrderMap">
  273. <result property="id" column="id"/>
  274. <result property="recordNo" column="record_no"/>
  275. <result property="reportTime" column="report_time"/>
  276. <result property="userName" column="user_name"/>
  277. <result property="userPhone" column="user_phone"/>
  278. <result property="areaName" column="area_name"/>
  279. <result property="address" column="address"/>
  280. <result property="articleName" column="article_name"/>
  281. <result property="description" column="description"/>
  282. <result property="image" column="image"/>
  283. <result property="state" column="state"/>
  284. </resultMap>
  285. <select id="queryPendingOrder" resultType="com.repair.model.vo.pendingOrderVo" resultMap="repairPendingOrderMap">
  286. select * from (select (select Count(*) from repair_dispatch_record where is_lose_efficacy = 0 and record_id = rr.id and users_id = #{userId}) as disp_count,rr.id,rr.record_no,
  287. rr.report_time,rr.user_name,rr.user_phone,rr.area_id as area_name,rr.address,rat.name as article_name,rr.description,rr.image,'待接单' as state
  288. from repair_record rr
  289. left join repair_article_type rat on rat.id = rr.article_id
  290. where rr.maintenance_state = 1 and rr.deleted = 0) t where t.disp_count &lt;= 0
  291. order by t.report_time desc
  292. </select>
  293. </mapper>