RepairRecordMapper.xml 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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="userName" column="user_name"/>
  25. <result property="userPhone" column="user_phone"/>
  26. <result property="areaName" column="area_name"/>
  27. <result property="address" column="address"/>
  28. <result property="articleName" column="article_name"/>
  29. <result property="descript" column="description"/>
  30. <result property="image" column="image"/>
  31. <result property="stateId" column="state_id"/>
  32. <result property="price" column="price"/>
  33. <result property="maintenancerName" column="maintenancer_name"/>
  34. <result property="maintenancerPhone" column="maintenancer_phone"/>
  35. <result property="timeoutDispStr" column="timeout_disp_str"/>
  36. <result property="timeoutReceStr" column="timeout_rece_str"/>
  37. </resultMap>
  38. <select id="queryMyRepairRecordList" resultType="com.repair.model.vo.MyRepairRecordVo"
  39. resultMap="repairRecordOwnMap">
  40. select
  41. case ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW() and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time) and rr.maintenance_state &lt;= 7 and rr.is_duty = 0 when true then '超时未接'
  42. else null end as timeout_disp_str,
  43. case ((date_add(rdv.receiving_time, interval rdv.maintenance_assess_time minute) &lt;= NOW() and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time) and rr.maintenance_state &lt;= 7 and rr.is_duty = 0 when true then '维修超时'
  44. else null end as timeout_rece_str,
  45. rr.id,rr.price,rr.maintenancer_name,rr.maintenancer_phone,rr.record_no,rr.report_time,rr.user_name,rr.user_phone,rr.area_id
  46. as area_name,rr.address,rr.description,rat.name as article_name,rr.image,rr.maintenance_state as state_id from
  47. repair_record rr
  48. left join repair_article_type rat on rat.id = rr.article_id
  49. left join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr.id and rdr.is_lose_efficacy = 0
  50. left join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr.id and rdv.is_lose_efficacy = 0
  51. <where>
  52. and rr.deleted = 0
  53. <if test="stateStr != null and stateStr != ''">
  54. and rr.maintenance_state ${stateStr}
  55. </if>
  56. <if test="userId != null and userId != ''">
  57. and rr.user_id = #{userId}
  58. </if>
  59. </where>
  60. order by rr.report_time DESC
  61. </select>
  62. <resultMap type="com.repair.model.vo.MaintenanceTechnicianVo" id="repairRecordTechnicianMap">
  63. <result property="receivingCount" column="receiving_count"/>
  64. <result property="maintenanceCount" column="maintenance_count"/>
  65. <result property="timeoutCount" column="timeout_count"/>
  66. <result property="examineCount" column="examine_count"/>
  67. </resultMap>
  68. <select id="queryRepairTechnicianCount" resultType="com.repair.model.vo.MaintenanceTechnicianVo"
  69. resultMap="repairRecordTechnicianMap">
  70. select (select Count(*) from repair_record rr
  71. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.is_lose_efficacy = 0 and rdr.record_id = rr.id and rdr.users_id = #{userId}
  72. where rr.deleted = 0 and rr.maintenance_state = 1) as receiving_count ,(select Count(*) from repair_record rr2
  73. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.user_id = #{userId} and rdv.record_id = rr2.id and
  74. rdv.is_lose_efficacy = 0
  75. where rr2.maintenance_state = 2 and rr2.deleted = 0) as maintenance_count,(select Count(*) as cs from (select rr3.*
  76. from repair_record rr3
  77. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.users_id = #{userId} and rdr.record_id = rr3.id and
  78. rdr.is_lose_efficacy = 0
  79. and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  80. where rr3.is_duty = 0 and rr3.maintenance_state &lt;= 7 and rr3.deleted = 0
  81. UNION ALL
  82. select rr4.* from repair_record rr4
  83. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.user_id = #{userId} and rdv.record_id = rr4.id and
  84. rdv.is_lose_efficacy = 0
  85. and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  86. where rr4.is_duty = 0 and rr4.maintenance_state &lt;= 7 and rr4.deleted = 0) c) as timeout_count,(select Count(*) as sh from (
  87. select rr5.* from repair_record rr5
  88. inner join repair_collaborate_record rcr on rcr.deleted = 0 and rcr.user_id = #{userId} and rcr.record_id = rr5.id and
  89. rcr.approval_statu = 2
  90. where rr5.maintenance_state = 6 and rr5.deleted = 0
  91. UNION ALL
  92. select rr.* from repair_record rr
  93. inner join repair_transfer_record rtr on rtr.deleted = 0 and rtr.user_id = #{userId} and rtr.record_id = rr.id and
  94. rtr.approval_statu = 2
  95. where rr.maintenance_state = 5 and rr.deleted = 0) a) as examine_count
  96. </select>
  97. <resultMap type="com.repair.model.vo.RepairTechnicianVo" id="repairRecordTechnicianDataMap">
  98. <result property="id" column="id"/>
  99. <result property="recordNo" column="record_no"/>
  100. <result property="reportTime" column="report_time"/>
  101. <result property="userName" column="user_name"/>
  102. <result property="userPhone" column="user_phone"/>
  103. <result property="areaName" column="area_name"/>
  104. <result property="address" column="address"/>
  105. <result property="articleName" column="article_name"/>
  106. <result property="description" column="description"/>
  107. <result property="image" column="image"/>
  108. <result property="state" column="state"/>
  109. <result property="timeoutStr" column="timeout_str"/>
  110. <result property="maintenancerName" column="maintenancer_name"/>
  111. <result property="maintenancerPhone" column="maintenancer_phone"/>
  112. <result property="price" column="price"/>
  113. </resultMap>
  114. <!--待接单-->
  115. <select id="queryPendingOrderList" resultType="com.repair.model.vo.RepairTechnicianVo"
  116. resultMap="repairRecordTechnicianDataMap">
  117. select case ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time) and rr.is_duty = 0 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price
  118. from repair_record rr
  119. 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 and rdr.receiving_time is null
  120. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  121. where (rr.maintenance_state = 1 or rr.maintenance_state = 2) and rr.deleted = 0
  122. order by rr.report_time DESC
  123. </select>
  124. <!--维修中-->
  125. <select id="queryRepairOrderList" resultType="com.repair.model.vo.RepairTechnicianVo"
  126. resultMap="repairRecordTechnicianDataMap">
  127. select case ((date_add(rdv.receiving_time, interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time) and rr.is_duty = 0 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price
  128. from repair_record rr
  129. 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
  130. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  131. where rr.maintenance_state = 2 and rr.deleted = 0
  132. order by rr.report_time DESC
  133. </select>
  134. <!--已超时-->
  135. <select id="queryTimeoutOrderList" resultType="com.repair.model.vo.RepairTechnicianVo"
  136. resultMap="repairRecordTechnicianDataMap">
  137. SELECT * FROM (
  138. select case ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time) 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price from repair_record rr
  139. 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
  140. and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  141. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  142. where rr.is_duty = 0 and rr.maintenance_state &lt;= 7 and rr.deleted = 0
  143. UNION ALL
  144. select case ((date_add(rdv.receiving_time, interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time) 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price from repair_record rr
  145. 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
  146. and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  147. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  148. where rr.is_duty = 0 and rr.maintenance_state &lt;= 7 and rr.deleted = 0) t
  149. order by t.report_time desc
  150. </select>
  151. <!--待审核-->
  152. <select id="queryExamineOrderList" resultType="com.repair.model.vo.RepairTechnicianVo"
  153. resultMap="repairRecordTechnicianDataMap">
  154. 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price from repair_record rr
  155. 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
  156. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  157. where rr.maintenance_state = 6 and rr.deleted = 0
  158. UNION ALL
  159. 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price from repair_record rr
  160. 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
  161. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  162. where rr.maintenance_state = 5 and rr.deleted = 0
  163. </select>
  164. <resultMap type="com.repair.model.vo.RepairManageCountVo" id="repairManageCountMap">
  165. <result property="allCount" column="all_count"/>
  166. <result property="dispatchCount" column="dispatch_count"/>
  167. <result property="maintenanceCount" column="maintenance_count"/>
  168. <result property="logisticsCount" column="logistics_count"/>
  169. <result property="examineCount" column="examine_count"/>
  170. <result property="finishedCount" column="finished_count"/>
  171. <result property="canceledCount" column="canceled_count"/>
  172. <result property="closedCount" column="closed_count"/>
  173. <result property="timeoutCount" column="timeout_count"/>
  174. </resultMap>
  175. <select id="queryManageCount" resultType="com.repair.model.vo.RepairManageCountVo" resultMap="repairManageCountMap">
  176. select
  177. (select Count(*) from repair_record where deleted = 0
  178. <if test="schoolId != null and schoolId != ''">
  179. and school_id = #{schoolId}
  180. </if>
  181. ) as all_count,
  182. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 1
  183. <if test="schoolId != null and schoolId != ''">
  184. and school_id = #{schoolId}
  185. </if>
  186. ) as dispatch_count,
  187. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 2
  188. <if test="schoolId != null and schoolId != ''">
  189. and school_id = #{schoolId}
  190. </if>
  191. ) as maintenance_count,
  192. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 3
  193. <if test="schoolId != null and schoolId != ''">
  194. and school_id = #{schoolId}
  195. </if>
  196. ) as logistics_count,
  197. (select Count(*) from repair_record where deleted = 0 and (maintenance_state = 5 or maintenance_state = 6)
  198. <if test="schoolId != null and schoolId != ''">
  199. and school_id = #{schoolId}
  200. </if>
  201. ) as examine_count,
  202. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 7
  203. <if test="schoolId != null and schoolId != ''">
  204. and school_id = #{schoolId}
  205. </if>
  206. ) as finished_count,
  207. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 8
  208. <if test="schoolId != null and schoolId != ''">
  209. and school_id = #{schoolId}
  210. </if>
  211. ) as canceled_count,
  212. (select Count(*) from repair_record where deleted = 0 and maintenance_state = 9
  213. <if test="schoolId != null and schoolId != ''">
  214. and school_id = #{schoolId}
  215. </if>
  216. ) as closed_count,
  217. (select Count(*) as cs from (select rr3.* from repair_record rr3
  218. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr3.id and
  219. rdr.is_lose_efficacy = 0 and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW() and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  220. where rr3.is_duty = 0 and rr3.deleted = 0 and rr3.maintenance_state &lt;= 7
  221. <if test="schoolId != null and schoolId != ''">
  222. and rr3.school_id = #{schoolId}
  223. </if>
  224. UNION ALL
  225. select rr4.* from repair_record rr4
  226. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr4.id and
  227. rdv.is_lose_efficacy = 0 and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= NOW() and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  228. where rr4.is_duty = 0 and rr4.deleted = 0 and rr4.maintenance_state &lt;= 7
  229. <if test="schoolId != null and schoolId != ''">
  230. and rr4.school_id = #{schoolId}
  231. </if>
  232. ) c) as timeout_count
  233. </select>
  234. <resultMap type="com.repair.model.vo.RepairRecordPageVo" id="repairRecordPageMap">
  235. <result property="id" column="id"/>
  236. <result property="recordNo" column="record_no"/>
  237. <result property="schoolId" column="school_id"/>
  238. <result property="userName" column="user_name"/>
  239. <result property="userPhone" column="user_phone"/>
  240. <result property="articleName" column="article_name"/>
  241. <result property="description" column="description"/>
  242. <result property="reportTime" column="report_time"/>
  243. <result property="maintenancerName" column="maintenancer_name"/>
  244. <result property="details" column="details"/>
  245. <result property="maintenanceState" column="maintenance_state"/>
  246. <result property="userId" column="user_id"/>
  247. </resultMap>
  248. <!--除已超时外的其他数据获取方式-->
  249. <select id="queryNotTimeout" resultType="com.repair.model.vo.RepairRecordPageVo" resultMap="repairRecordPageMap">
  250. select rr.school_id,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
  251. article_name,
  252. rr.description,rr.report_time,rr.maintenancer_name,rr.maintenance_state
  253. from repair_record rr
  254. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  255. <where>
  256. and rr.deleted = 0
  257. <if test="schoolId != null and schoolId != ''">
  258. and rr.school_id = #{schoolId}
  259. </if>
  260. <if test="stateStr != null and stateStr != ''">
  261. and (rr.maintenance_state ${stateStr}
  262. </if>
  263. <if test="keyWord != null and keyWord != ''">
  264. and (rr.area_id like '%' #{keyWord} '%' or rr.user_name like '%' #{keyWord} '%' or rr.user_phone like
  265. '%' #{keyWord} '%')
  266. </if>
  267. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  268. and rr.report_time between #{startTime} and #{endTime}
  269. </if>
  270. </where>
  271. order by rr.report_time desc
  272. </select>
  273. <!--#已超时获取方式-->
  274. <select id="queryTimeout" resultType="com.repair.model.vo.RepairRecordPageVo" resultMap="repairRecordPageMap">
  275. SELECT * FROM (
  276. select rr3.school_id,rr3.user_id,1 as details,rr3.id,rr3.record_no,rr3.area_id as
  277. area_name,rr3.user_name,rr3.user_phone,rat.name as article_name,
  278. rr3.description,rr3.report_time,rr3.maintenancer_name,rr3.maintenance_state
  279. from repair_record rr3
  280. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr3.article_id
  281. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr3.id and
  282. rdr.is_lose_efficacy = 0
  283. and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW() and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  284. <where>
  285. and rr3.deleted = 0 and rr3.is_duty = 0 and rr3.maintenance_state &lt;= 7
  286. <if test="keyWord != null and keyWord != ''">
  287. and (rr3.area_id like '%' #{keyWord} '%' or rr3.user_name like '%' #{keyWord} '%' or rr3.user_phone like
  288. '%' #{keyWord} '%')
  289. </if>
  290. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  291. and rr3.report_time between #{startTime} and #{endTime}
  292. </if>
  293. <if test="schoolId != null and schoolId != ''">
  294. and rr3.school_id = #{schoolId}
  295. </if>
  296. </where>
  297. UNION ALL
  298. select rr4.user_id,1 as details,rr4.id,rr4.record_no,rr4.area_id as
  299. area_name,rr4.user_name,rr4.user_phone,rat.name as
  300. article_name,
  301. rr4.description,rr4.report_time,rr4.maintenancer_name,rr4.maintenance_state
  302. from repair_record rr4
  303. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr4.article_id
  304. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr4.id and
  305. rdv.is_lose_efficacy = 0
  306. and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= NOW() and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  307. <where>
  308. and rr4.deleted = 0 and rr4.is_duty = 0 and rr4.maintenance_state &lt;= 7
  309. <if test="keyWord != null and keyWord != ''">
  310. and (rr4.area_id like '%' #{keyWord} '%' or rr4.user_name like '%' #{keyWord} '%' or rr4.user_phone like
  311. '%' #{keyWord} '%')
  312. </if>
  313. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  314. and rr4.report_time between #{startTime} and #{endTime}
  315. </if>
  316. <if test="schoolId != null and schoolId != ''">
  317. and rr4.school_id = #{schoolId}
  318. </if>
  319. </where>
  320. ) t
  321. order by t.report_time desc
  322. </select>
  323. <!--#获取待处理池数据-->
  324. <resultMap type="com.repair.model.vo.pendingOrderVo" id="repairPendingOrderMap">
  325. <result property="id" column="id"/>
  326. <result property="recordNo" column="record_no"/>
  327. <result property="reportTime" column="report_time"/>
  328. <result property="userName" column="user_name"/>
  329. <result property="userPhone" column="user_phone"/>
  330. <result property="areaName" column="area_name"/>
  331. <result property="address" column="address"/>
  332. <result property="articleName" column="article_name"/>
  333. <result property="description" column="description"/>
  334. <result property="image" column="image"/>
  335. <result property="state" column="state"/>
  336. </resultMap>
  337. <select id="queryPendingOrder" resultType="com.repair.model.vo.pendingOrderVo" resultMap="repairPendingOrderMap">
  338. select * from (select (select Count(*) from repair_dispatch_record where is_lose_efficacy = 0 and record_id = rr.id and receiving_time is null) as disp_count,rr.id,rr.record_no,
  339. 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
  340. from repair_record rr
  341. left join repair_article_type rat on rat.id = rr.article_id
  342. where rr.maintenance_state = 1 and rr.deleted = 0) t where t.disp_count &lt;= 0
  343. order by t.report_time desc
  344. </select>
  345. <!--郭师傅维修 团队工单 头部数量-->
  346. <resultMap type="com.repair.model.vo.TeamWorkCountVo" id="teamWorkOrderMap">
  347. <result property="examineCount" column="examine_count"/>
  348. <result property="receivingCount" column="receiving_count"/>
  349. <result property="maintenanceCount" column="maintenance_count"/>
  350. <result property="finishedCount" column="finished_count"/>
  351. <result property="logisticsCount" column="logistics_count"/>
  352. <result property="timeoutCount" column="timeout_count"/>
  353. <result property="closedCount" column="closed_count"/>
  354. </resultMap>
  355. <select id="queryTeamWorkCount" resultType="com.repair.model.vo.TeamWorkCountVo" resultMap="teamWorkOrderMap">
  356. select
  357. (select Count(*) as sh from (
  358. select rr5.* from repair_record rr5
  359. inner join repair_collaborate_record rcr on rcr.deleted = 0 and rcr.record_id = rr5.id and
  360. rcr.approval_statu = 2
  361. where rr5.maintenance_state = 6 and rr5.school_id = #{schoolId} and rr5.deleted = 0
  362. UNION ALL
  363. select rr.* from repair_record rr
  364. inner join repair_transfer_record rtr on rtr.deleted = 0 and rtr.record_id = rr.id and
  365. rtr.approval_statu = 2
  366. where rr.maintenance_state = 5 and rr.school_id = #{schoolId} and rr.deleted = 0) a) as examine_count,
  367. (select Count(*) from repair_record rr1
  368. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr1.id and
  369. rdr.is_lose_efficacy = 0
  370. where rr1.maintenance_state = 1 and rr1.school_id = #{schoolId} and rr1.deleted = 0) as receiving_count,
  371. (select Count(*) from repair_record rr2
  372. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr2.id and
  373. rdv.is_lose_efficacy = 0
  374. where rr2.maintenance_state = 2 and rr2.school_id = #{schoolId} and rr2.deleted = 0) as maintenance_count,
  375. (select Count(*) from repair_record rr7
  376. where rr7.deleted = 0 and rr7.school_id = #{schoolId} and rr7.maintenance_state = 7) as finished_count,
  377. (select Count(*) from repair_record rr9
  378. where rr9.deleted = 0 and rr9.school_id = #{schoolId} and rr9.maintenance_state = 3) as logistics_count,
  379. (select Count(*) as cs from (select rr3.*
  380. from repair_record rr3
  381. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr3.id and
  382. rdr.is_lose_efficacy = 0
  383. and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  384. where rr3.deleted = 0 and rr3.maintenance_state &lt;= 7 and rr3.is_duty = 0 and rr3.school_id = #{schoolId}
  385. UNION ALL
  386. select rr4.* from repair_record rr4
  387. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr4.id and
  388. rdv.is_lose_efficacy = 0
  389. and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  390. where rr4.deleted = 0 and rr4.maintenance_state &lt;= 7 and rr4.is_duty = 0 and rr4.school_id = #{schoolId}) c) as timeout_count,
  391. (select Count(*) from repair_record rr8
  392. where rr8.deleted = 0 and rr8.school_id = #{schoolId} and rr8.maintenance_state = 9) as closed_count
  393. </select>
  394. <!--待审核-->
  395. <select id="queryTeamWorkExamine" resultType="com.repair.model.vo.RepairTechnicianVo"
  396. resultMap="repairRecordTechnicianDataMap">
  397. select rr5.id,rr5.record_no,rr5.report_time,rr5.user_name,rr5.user_phone,rr5.area_id as area_name,rr5.address,rat.name as article_name ,rr5.description,rr5.image,'协作审核' as state,rr5.maintenancer_name,rr5.maintenancer_phone,rr5.price from repair_record rr5
  398. inner join repair_collaborate_record rcr on rcr.deleted = 0 and rcr.record_id = rr5.id and rcr.approval_statu = 2
  399. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr5.article_id
  400. where rr5.maintenance_state = 6 and rr5.school_id = #{schoolId} and rr5.deleted = 0
  401. UNION ALL
  402. 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price from repair_record rr
  403. inner join repair_transfer_record rtr on rtr.deleted = 0 and rtr.record_id = rr.id and rtr.approval_statu = 2
  404. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  405. where rr.maintenance_state = 5 and rr.school_id = #{schoolId} and rr.deleted = 0
  406. </select>
  407. <!--待接单-->
  408. <select id="queryTeamWorkPending" resultType="com.repair.model.vo.RepairTechnicianVo"
  409. resultMap="repairRecordTechnicianDataMap">
  410. select case ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time) 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price
  411. from repair_record rr
  412. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr.id and rdr.is_lose_efficacy = 0
  413. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  414. where rr.maintenance_state = 1 and rr.school_id = #{schoolId} and rr.deleted = 0
  415. order by rr.report_time DESC
  416. </select>
  417. <!--维修中-->
  418. <select id="queryTeamWorkMaintenance" resultType="com.repair.model.vo.RepairTechnicianVo"
  419. resultMap="repairRecordTechnicianDataMap">
  420. select case ((date_add(rdv.receiving_time, interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time) 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price
  421. from repair_record rr
  422. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr.id and rdv.is_lose_efficacy = 0
  423. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  424. where rr.maintenance_state = 2 and rr.school_id = #{schoolId} and rr.deleted = 0
  425. order by rr.report_time DESC
  426. </select>
  427. <!--已完成-->
  428. <select id="queryTeamWorkFinished" resultType="com.repair.model.vo.RepairTechnicianVo"
  429. resultMap="repairRecordTechnicianDataMap">
  430. 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price from repair_record rr
  431. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  432. where rr.deleted = 0 and rr.school_id = #{schoolId} and rr.maintenance_state = 7
  433. order by rr.report_time DESC
  434. </select>
  435. <!--待处理-->
  436. <select id="queryTeamWorkLogistics" resultType="com.repair.model.vo.RepairTechnicianVo"
  437. resultMap="repairRecordTechnicianDataMap">
  438. 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price from repair_record rr
  439. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  440. where rr.deleted = 0 and rr.school_id = #{schoolId} and rr.maintenance_state = 3
  441. order by rr.report_time DESC
  442. </select>
  443. <!--已超时-->
  444. <select id="queryTeamWorkTimeout" resultType="com.repair.model.vo.RepairTechnicianVo"
  445. resultMap="repairRecordTechnicianDataMap">
  446. SELECT * FROM (
  447. select case ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time) when true then '超时未接' else null end as timeout_str,rr3.id,rr3.record_no,rr3.report_time,rr3.user_name,rr3.user_phone,rr3.area_id as area_name,rr3.address,rat.name as article_name ,rr3.description,rr3.image,'已超时' as state,rr3.maintenancer_name,rr3.maintenancer_phone,rr3.price from repair_record rr3
  448. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr3.id and rdr.is_lose_efficacy = 0
  449. and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= #{dateNow} and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  450. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr3.article_id
  451. where rr3.deleted = 0 and rr3.maintenance_state &lt;= 7 and rr3.is_duty = 0 and rr3.school_id = #{schoolId}
  452. UNION ALL
  453. select case ((date_add(rdv.receiving_time, interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time) when true then '维修超时' else null end as timeout_str,rr4.id,rr4.record_no,rr4.report_time,rr4.user_name,rr4.user_phone,rr4.area_id as area_name,rr4.address,rat.name as article_name ,rr4.description,rr4.image,'已超时' as state,rr4.maintenancer_name,rr4.maintenancer_phone,rr4.price from repair_record rr4
  454. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr4.id and
  455. rdv.is_lose_efficacy = 0
  456. and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= #{dateNow} and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  457. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr4.article_id
  458. where rr4.deleted = 0 and rr4.maintenance_state &lt;= 7 and rr4.is_duty = 0 and rr4.school_id = #{schoolId}) t
  459. order by t.report_time desc
  460. </select>
  461. <!--已关单-->
  462. <select id="queryTeamWorkClosed" resultType="com.repair.model.vo.RepairTechnicianVo"
  463. resultMap="repairRecordTechnicianDataMap">
  464. 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,rr.maintenancer_name,rr.maintenancer_phone,rr.price from repair_record rr
  465. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  466. where rr.deleted = 0 and rr.school_id = #{schoolId} and rr.maintenance_state = 9
  467. order by rr.report_time DESC
  468. </select>
  469. <!-- 报表导出获取除已超时外的其他数据获取方式-->
  470. <select id="queryNotTimeoutReportExport" resultType="com.repair.model.vo.ReportExportVo">
  471. 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
  472. article_name,
  473. rr.description,rr.report_time,rr.maintenancer_name,rr.maintenance_state
  474. from repair_record rr
  475. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr.article_id
  476. <where>
  477. and rr.deleted = 0
  478. <if test="schoolId != null and schoolId != ''">
  479. and rr.school_id = #{schoolId}
  480. </if>
  481. <if test="stateStr != null and stateStr != ''">
  482. and (rr.maintenance_state ${stateStr}
  483. </if>
  484. <if test="keyWord != null and keyWord != ''">
  485. and (rr.area_id like '%' #{keyWord} '%' or rr.user_name like '%' #{keyWord} '%' or rr.user_phone like
  486. '%' #{keyWord} '%')
  487. </if>
  488. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  489. and rr.report_time between #{startTime} and #{endTime}
  490. </if>
  491. </where>
  492. order by rr.report_time desc
  493. </select>
  494. <!-- 报表导出获取除已超时数据获取方式-->
  495. <select id="queryTimeoutReportExport" resultType="com.repair.model.vo.ReportExportVo">
  496. SELECT * FROM (
  497. select rr3.user_id,1 as details,rr3.id,rr3.record_no,rr3.area_id as
  498. area_name,rr3.user_name,rr3.user_phone,rat.name as article_name,
  499. rr3.description,rr3.report_time,rr3.maintenancer_name,rr3.maintenance_state
  500. from repair_record rr3
  501. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr3.article_id
  502. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr3.id and
  503. rdr.is_lose_efficacy = 0
  504. and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW() and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  505. <where>
  506. and rr3.deleted = 0 and rr3.is_duty = 0 and rr3.maintenance_state &lt;= 7
  507. <if test="keyWord != null and keyWord != ''">
  508. and (rr3.area_id like '%' #{keyWord} '%' or rr3.user_name like '%' #{keyWord} '%' or rr3.user_phone like
  509. '%' #{keyWord} '%')
  510. </if>
  511. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  512. and rr3.report_time between #{startTime} and #{endTime}
  513. </if>
  514. <if test="schoolId != null and schoolId != ''">
  515. and rr3.school_id = #{schoolId}
  516. </if>
  517. </where>
  518. UNION ALL
  519. select rr4.user_id,1 as details,rr4.id,rr4.record_no,rr4.area_id as
  520. area_name,rr4.user_name,rr4.user_phone,rat.name as
  521. article_name,
  522. rr4.description,rr4.report_time,rr4.maintenancer_name,rr4.maintenance_state
  523. from repair_record rr4
  524. left join repair_article_type rat on rat.deleted = 0 and rat.id = rr4.article_id
  525. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr4.id and
  526. rdv.is_lose_efficacy = 0
  527. and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= NOW() and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  528. <where>
  529. and rr4.deleted = 0 and rr4.is_duty = 0 and rr4.maintenance_state &lt;= 7
  530. <if test="keyWord != null and keyWord != ''">
  531. and (rr4.area_id like '%' #{keyWord} '%' or rr4.user_name like '%' #{keyWord} '%' or rr4.user_phone like
  532. '%' #{keyWord} '%')
  533. </if>
  534. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  535. and rr4.report_time between #{startTime} and #{endTime}
  536. </if>
  537. <if test="schoolId != null and schoolId != ''">
  538. and rr4.school_id = #{schoolId}
  539. </if>
  540. </where>
  541. ) t
  542. order by t.report_time desc
  543. </select>
  544. <!--维修师傅首页头部数量-->
  545. <resultMap type="com.repair.model.vo.MasterHomepageVo" id="masterHomepageMap">
  546. <result property="workCount" column="work_count"/>
  547. <result property="processCount" column="process_count"/>
  548. <result property="finishCount" column="finish_count"/>
  549. <result property="timeoutCount" column="timeout_count"/>
  550. </resultMap>
  551. <!--说明:-->
  552. <!--#work_count 工单数:维修师傅的工单总数,只计算维修师傅的接单数,待接单不用计算进去-->
  553. <!--#process_count 处理中:维修中没有完成的工单,包含维修中,待接单,待审核-->
  554. <!--#finish_count 已完成:已取消 已完成 已关单-->
  555. <!--#timeout_count 已超时:包含接单超时 维修超时-->
  556. <select id="queryMasterHomeCount" resultType="com.repair.model.vo.MasterHomepageVo" resultMap="masterHomepageMap">
  557. select
  558. (select count(*) from repair_receiving
  559. where deleted = 0 and user_id = #{userId}) as work_count,
  560. (select
  561. (select Count(*) as rc from repair_record rr
  562. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.is_lose_efficacy = 0 and rdr.record_id = rr.id and rdr.users_id = #{userId}
  563. where rr.deleted = 0 and rr.maintenance_state = 1) +
  564. (select Count(*) as wx from repair_record rr2
  565. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.user_id = #{userId} and rdv.record_id = rr2.id and
  566. rdv.is_lose_efficacy = 0
  567. where rr2.maintenance_state = 2 and rr2.deleted = 0) +
  568. (select Count(*) as sh from (
  569. select rr5.* from repair_record rr5
  570. inner join repair_collaborate_record rcr on rcr.deleted = 0 and rcr.user_id = #{userId} and rcr.record_id = rr5.id and
  571. rcr.approval_statu = 2
  572. where rr5.maintenance_state = 6 and rr5.deleted = 0
  573. UNION ALL
  574. select rr.* from repair_record rr
  575. inner join repair_transfer_record rtr on rtr.deleted = 0 and rtr.user_id = #{userId} and rtr.record_id = rr.id and
  576. rtr.approval_statu = 2
  577. where rr.maintenance_state = 5 and rr.deleted = 0) a) as process_count) as process_count,
  578. (select Count(*) from repair_record rr
  579. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.is_lose_efficacy = 0 and rdr.record_id = rr.id and rdr.users_id = #{userId}
  580. where rr.deleted = 0 and rr.maintenance_state >= 7) as finish_count,
  581. (select Count(*) as cs from (select rr3.*
  582. from repair_record rr3
  583. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.users_id = #{userId} and rdr.record_id = rr3.id and
  584. rdr.is_lose_efficacy = 0
  585. and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW() and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  586. where rr3.maintenance_state &lt;= 7 and rr3.is_duty = 0 and rr3.deleted = 0
  587. UNION ALL
  588. select rr4.* from repair_record rr4
  589. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.user_id = #{userId} and rdv.record_id = rr4.id and
  590. rdv.is_lose_efficacy = 0
  591. and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= NOW() and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  592. where rr4.maintenance_state &lt;= 7 and rr4.is_duty = 0 and rr4.deleted = 0) c) as timeout_count
  593. </select>
  594. <!--后勤人员和郭师傅首页头部数量-->
  595. <!--说明:-->
  596. <!--#work_count 工单数:对应校区的工单总数,只计算对应人员校区的接单数,待接单不用计算进去-->
  597. <!--#process_count 处理中:维修中没有完成的工单,包含维修中,待接单,待审核-->
  598. <!--#finish_count 已完成:已取消 已完成 已关单-->
  599. <!--#timeout_count 已超时:包含接单超时 维修超时-->
  600. <select id="queryLogisticHomeCount" resultType="com.repair.model.vo.MasterHomepageVo" resultMap="masterHomepageMap">
  601. select
  602. (select Count(*) from repair_receiving rc
  603. inner join repair_record rr on rr.deleted = 0 and rr.school_id = #{schoolId} and rr.id = rc.record_id
  604. where rc.deleted = 0) as work_count,
  605. (select
  606. (select Count(*) as rc from repair_record rr
  607. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.is_lose_efficacy = 0 and rdr.record_id = rr.id
  608. where rr.deleted = 0 and rr.maintenance_state = 1 and rr.school_id = #{schoolId}) +
  609. (select Count(*) as wx from repair_record rr2
  610. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr2.id and
  611. rdv.is_lose_efficacy = 0
  612. where rr2.maintenance_state = 2 and rr2.deleted = 0 and rr2.school_id = #{schoolId}) +
  613. (select Count(*) as sh from (
  614. select rr5.* from repair_record rr5
  615. inner join repair_collaborate_record rcr on rcr.deleted = 0 and rcr.record_id = rr5.id and
  616. rcr.approval_statu = 2
  617. where rr5.maintenance_state = 6 and rr5.deleted = 0 and rr5.school_id = #{schoolId}
  618. UNION ALL
  619. select rr.* from repair_record rr
  620. inner join repair_transfer_record rtr on rtr.deleted = 0 and rtr.record_id = rr.id and
  621. rtr.approval_statu = 2
  622. where rr.maintenance_state = 5 and rr.deleted = 0 and rr.school_id = #{schoolId}) a) as process_count) as process_count,
  623. (select Count(*) from repair_record rr
  624. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.is_lose_efficacy = 0 and rdr.record_id = rr.id
  625. where rr.deleted = 0 and rr.maintenance_state >= 7 and rr.school_id = #{schoolId}) as finish_count,
  626. (select Count(*) as cs from (select rr3.*
  627. from repair_record rr3
  628. inner join repair_dispatch_record rdr on rdr.deleted = 0 and rdr.record_id = rr3.id and
  629. rdr.is_lose_efficacy = 0
  630. and ((date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= NOW() and rdr.receiving_time is null) or date_add(rdr.assigned_time , interval rdr.acceptance_assess_time minute) &lt;= rdr.receiving_time)
  631. where rr3.is_duty = 0 and rr3.deleted = 0 and rr3.school_id = #{schoolId}
  632. UNION ALL
  633. select rr4.* from repair_record rr4
  634. inner join repair_receiving rdv on rdv.deleted = 0 and rdv.record_id = rr4.id and
  635. rdv.is_lose_efficacy = 0
  636. and ((date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= NOW() and rdv.maintenance_assess_time is null) or date_add(rdv.receiving_time , interval rdv.maintenance_assess_time minute) &lt;= rdv.finish_time)
  637. where rr4.is_duty = 0 and rr4.deleted = 0 and rr4.school_id = #{schoolId}) c) as timeout_count
  638. </select>
  639. <select id="repairCampusTotal" resultType="com.repair.model.vo.RepairCampusVo">
  640. SELECT rs.id,
  641. count(rr.school_id) as orders_total,
  642. rs.`name` as school_name,
  643. (SELECT COUNT(school_id)
  644. FROM `repair_record`
  645. WHERE price > 0
  646. AND rs.id = school_id
  647. AND deleted = 0) AS orders_compensation,
  648. (SELECT COUNT(school_id)
  649. FROM `repair_record`
  650. WHERE (price IS NULL OR price = 0)
  651. AND rs.id = school_id
  652. AND deleted = 0) AS orders_gratis,
  653. SUM(rr.price) AS total_price
  654. FROM `repair_record` rr
  655. LEFT JOIN repair_school rs ON rs.deleted = 0
  656. AND rr.school_id = rs.id
  657. AND rr.deleted = 0
  658. GROUP BY rr.school_id
  659. </select>
  660. <select id="repairCampus" resultType="com.repair.model.vo.RepairCampusVo">
  661. SELECT
  662. rs.id,
  663. count( rr.school_id ) as orders_total,
  664. rs.`name` as school_name,
  665. (
  666. SELECT
  667. COUNT( school_id )
  668. FROM
  669. `repair_record`
  670. <where>
  671. and price > 0
  672. AND rs.id = school_id
  673. AND deleted = 0
  674. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  675. and report_time between #{startTime} and #{endTime}
  676. </if>
  677. </where>
  678. ) AS orders_compensation,
  679. (
  680. SELECT
  681. COUNT( school_id )
  682. FROM
  683. `repair_record`
  684. <where>
  685. and ( price IS NULL OR price = 0 )
  686. AND rs.id = school_id
  687. AND deleted = 0
  688. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  689. and report_time between #{startTime} and #{endTime}
  690. </if>
  691. </where>
  692. ) AS orders_gratis,
  693. SUM( rr.price ) AS total_price
  694. FROM
  695. `repair_record` rr
  696. LEFT JOIN repair_school rs ON rs.deleted = 0
  697. AND rr.school_id = rs.id
  698. <where>
  699. AND rr.deleted = 0
  700. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  701. and report_time between #{startTime} and #{endTime}
  702. </if>
  703. </where>
  704. GROUP BY
  705. rr.school_id
  706. </select>
  707. <select id="repairAreaTotal" resultType="com.repair.model.vo.RepairAreaVo">
  708. SELECT row_number() over ( ORDER BY ra.area_name ) AS id, ra.*
  709. FROM (SELECT count(rr.area_id) AS orders_total,
  710. rs.`name` AS school_name,
  711. rr.area_id AS area_name,
  712. (SELECT COUNT(area_id)
  713. FROM `repair_record`
  714. WHERE price > 0
  715. AND rr.area_id = area_id
  716. AND deleted = 0) AS orders_compensation,
  717. (SELECT COUNT(area_id)
  718. FROM `repair_record`
  719. WHERE (price IS NULL OR price = 0)
  720. AND rr.area_id = area_id
  721. AND deleted = 0) AS orders_gratis,
  722. SUM(rr.price) AS total_price
  723. FROM `repair_record` rr
  724. LEFT JOIN repair_school rs ON rs.deleted = 0
  725. AND rr.school_id = rs.id
  726. where rr.deleted = 0
  727. GROUP BY rr.area_id) ra
  728. </select>
  729. <select id="repairArea" resultType="com.repair.model.vo.RepairAreaVo">
  730. SELECT row_number() over ( ORDER BY ra.area_name ) AS id, ra.*
  731. FROM (SELECT count(rr.area_id) AS orders_total,
  732. rs.`name` AS school_name,
  733. rr.area_id AS area_name,
  734. (SELECT COUNT(area_id)
  735. FROM `repair_record`
  736. <where>
  737. AND price > 0
  738. AND rr.area_id = area_id
  739. AND deleted = 0
  740. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  741. and report_time between #{startTime} and #{endTime}
  742. </if>
  743. </where>
  744. ) AS orders_compensation,
  745. (SELECT COUNT(area_id)
  746. FROM `repair_record`
  747. <where>
  748. AND (price IS NULL OR price = 0)
  749. AND rr.area_id = area_id
  750. AND deleted = 0
  751. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  752. and report_time between #{startTime} and #{endTime}
  753. </if>
  754. </where>
  755. ) AS orders_gratis,
  756. SUM(rr.price) AS total_price
  757. FROM `repair_record` rr
  758. LEFT JOIN repair_school rs ON rs.deleted = 0
  759. AND rr.school_id = rs.id
  760. <where>
  761. AND rr.deleted=0
  762. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  763. and report_time between #{startTime} and #{endTime}
  764. </if>
  765. </where>
  766. GROUP BY rr.area_id) ra
  767. </select>
  768. <select id="maintenanceGoodsTotal" resultType="com.repair.model.vo.MaintenanceGoodsVo">
  769. SELECT row_number() over ( ORDER BY wx.article_name ) AS id, wx.*
  770. FROM (SELECT rat.`name` AS article_name,
  771. count(rr.article_id) AS orders_total,
  772. (SELECT COUNT(article_id)
  773. FROM `repair_record`
  774. WHERE price > 0
  775. AND rr.article_id = article_id
  776. AND deleted = 0) AS orders_compensation,
  777. (SELECT COUNT(article_id)
  778. FROM `repair_record`
  779. WHERE (price IS NULL OR price = 0)
  780. AND rr.article_id = article_id
  781. AND deleted = 0) AS orders_gratis,
  782. SUM(rr.price) AS total_price
  783. FROM `repair_record` rr
  784. LEFT JOIN repair_article_type rat ON rat.deleted = 0
  785. AND rr.article_id = rat.id
  786. WHERE rr.deleted = 0
  787. GROUP BY rr.article_id) wx
  788. </select>
  789. <select id="maintenanceGoods" resultType="com.repair.model.vo.MaintenanceGoodsVo">
  790. SELECT row_number() over ( ORDER BY wx.article_name ) AS id, wx.*
  791. FROM (SELECT rat.`name` AS article_name,
  792. count(rr.article_id) AS orders_total,
  793. (SELECT COUNT(article_id)
  794. FROM `repair_record`
  795. <where>
  796. and price > 0 AND rr.article_id = article_id AND deleted = 0
  797. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  798. and report_time between #{startTime} and #{endTime}
  799. </if>
  800. </where>
  801. ) AS orders_compensation,
  802. (SELECT COUNT(article_id)
  803. FROM `repair_record`
  804. <where>
  805. and (price IS NULL OR price = 0)
  806. AND rr.article_id = article_id
  807. AND deleted = 0
  808. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  809. and report_time between #{startTime} and #{endTime}
  810. </if>
  811. </where>
  812. ) AS orders_gratis,
  813. SUM(rr.price) AS total_price
  814. FROM `repair_record` rr
  815. LEFT JOIN repair_article_type rat ON rat.deleted = 0
  816. AND rr.article_id = rat.id
  817. <where>
  818. and rr.deleted = 0
  819. <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
  820. and report_time between #{startTime} and #{endTime}
  821. </if>
  822. </where>
  823. GROUP BY rr.article_id) wx
  824. </select>
  825. </mapper>