MaintenanceRecordMapper.xml 15 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="cn.com.ty.lift.business.maintenance.dao.mapper.MaintenanceRecordMapper">
  4. <resultMap id="BaseResultMap" type="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MtRecordResponse">
  5. <id column="id" property="id" jdbcType="BIGINT"/>
  6. <result column="mt_plan_id" property="mtPlanId" jdbcType="BIGINT"/>
  7. <result column="lift_id" property="liftId" jdbcType="BIGINT"/>
  8. <result column="project_id" property="projectId" jdbcType="BIGINT"/>
  9. <result column="mt_company_id" property="mtCompanyId" jdbcType="BIGINT"/>
  10. <result column="worker_id" property="workerId" jdbcType="BIGINT"/>
  11. <result column="code" property="code" jdbcType="CHAR"/>
  12. <result column="lift_type" property="liftType" jdbcType="TINYINT"/>
  13. <result column="type" property="type" jdbcType="TINYINT"/>
  14. <result column="plan_date" property="planDate" jdbcType="TIMESTAMP"/>
  15. <result column="work_date" property="workDate" jdbcType="TIMESTAMP"/>
  16. <result column="stop_date" property="stopDate" jdbcType="TIMESTAMP"/>
  17. <result column="recovery_date" property="recoveryDate" jdbcType="TIMESTAMP"/>
  18. <result column="maintenance_advice" property="maintenanceAdvice" jdbcType="VARCHAR"/>
  19. <result column="maintenance_option" property="maintenanceOption" jdbcType="LONGVARCHAR"/>
  20. <result column="position" property="position" jdbcType="VARCHAR"/>
  21. <result column="status" property="status" jdbcType="TINYINT"/>
  22. <result column="is_regular" property="isRegular" jdbcType="TINYINT"/>
  23. <result column="creator_id" property="creatorId" jdbcType="BIGINT"/>
  24. <result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
  25. <result column="worker_id1" property="workerId1" jdbcType="BIGINT"/>
  26. <result column="is_repair" property="isRepair" jdbcType="TINYINT"/>
  27. <result column="repair_reason" property="repairReason" jdbcType="VARCHAR"/>
  28. <result column="signature_img1" property="signatureImg1" jdbcType="VARCHAR"/>
  29. <result column="signature_img2" property="signatureImg2" jdbcType="VARCHAR"/>
  30. <result column="sparepart" property="sparepart" jdbcType="LONGVARCHAR"/>
  31. <result column="parts_cost" property="partsCost" jdbcType="DECIMAL"/>
  32. <result column="man_cost" property="manCost" jdbcType="DECIMAL"/>
  33. <result column="safety_confirm" property="safetyConfirm" jdbcType="VARCHAR"/>
  34. <result column="has_evaluate" property="hasEvaluate" jdbcType="INTEGER"/>
  35. <result column="project_name" property="projectName" jdbcType="VARCHAR"/>
  36. <result column="project_code" property="projectCode" jdbcType="VARCHAR"/>
  37. <result column="use_company_code" property="useCompanyCode" jdbcType="VARCHAR"/>
  38. <result column="mt_company_name" property="mtCompanyName" jdbcType="VARCHAR"/>
  39. <result column="category" property="category" jdbcType="INTEGER"/>
  40. <result column="registration_code" property="registrationCode" jdbcType="VARCHAR"/>
  41. <result column="worker_name" property="workerName" jdbcType="VARCHAR"/>
  42. <result column="repair_diff" property="repairDiff" jdbcType="BIGINT"/>
  43. <result column="star_level" property="starLevel" jdbcType="INTEGER"/>
  44. </resultMap>
  45. <sql id="Base_Column_List">
  46. id, mt_plan_id, lift_id, project_id, mt_company_id, worker_id, code, lift_type, type,
  47. plan_date, work_date, stop_date, recovery_date, maintenance_advice, maintenance_option, position, status,
  48. is_regular, creator_id, create_date, worker_id1, is_repair, repair_reason, signature_img1,
  49. signature_img2, sparepart, parts_cost, man_cost, safety_confirm
  50. </sql>
  51. <!--根据公司id和电梯id项目名称、项目id、电梯位置 -->
  52. <select id="findProjectByCompanyId"
  53. resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceRecordResponse"
  54. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest">
  55. SELECT l.id AS liftId,
  56. l.device_position AS devicePosition,
  57. p.project_name AS projectName,
  58. p.id AS projectId
  59. FROM project_lift_relevance plr
  60. LEFT JOIN project p ON plr.project_id = p.id
  61. LEFT JOIN lift l ON plr.lift_id = l.id
  62. WHERE 1 = 1
  63. <if test="request.mtCompanyId!=null and request.mtCompanyId!=''">
  64. AND plr.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  65. </if>
  66. <if test="request.liftId!=null and request.liftId!=''">
  67. AND plr.lift_id = #{request.liftId,jdbcType=BIGINT}
  68. </if>
  69. </select>
  70. <!--根据公司id和电梯id获取上次保养信息 -->
  71. <select id="findRecordByCompanyId"
  72. resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceRecordResponse"
  73. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest">
  74. SELECT work_date AS workDate,
  75. type AS type,
  76. lift_id AS liftId
  77. FROM maintenance_record
  78. WHERE 1=1
  79. <if test="request.mtCompanyId!=null and request.mtCompanyId!=''">
  80. AND mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  81. </if>
  82. <if test="request.liftId!=null and request.liftId!=''">
  83. AND lift_id = #{request.liftId,jdbcType=BIGINT}
  84. </if>
  85. AND work_date = (SELECT max(work_date)
  86. FROM maintenance_record
  87. WHERE status > 1
  88. <if test="request.mtCompanyId!=null and request.mtCompanyId!=''">
  89. AND mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  90. </if>
  91. <if test="request.liftId!=null and request.liftId!=''">
  92. AND lift_id = #{request.liftId,jdbcType=BIGINT}
  93. </if>)
  94. </select>
  95. <!--app端 保养任务列表 (1:保养中、2:已完成) -->
  96. <select id="findRecordByWorkerId" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceAppResponse"
  97. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest">
  98. SELECT p.project_name AS projectName,
  99. p.id AS projectId,
  100. mr.id AS mtPlanId,
  101. mr.id AS recordId,
  102. l.id AS liftId,
  103. l.coordinate AS coordinate,
  104. l.registration_code AS registrationCode,
  105. l.use_company_code AS useCompanyCode,
  106. l.lift_type AS liftType,
  107. l.category AS category,
  108. l.lift_code AS liftCode,
  109. l.device_position AS devicePosition,
  110. ui.name AS workerName,
  111. mr.worker_id AS workerId,
  112. mr.worker_id1 AS workerId1,
  113. mr.plan_date AS planDate,
  114. mr.type AS maintenanceType,
  115. mr.status AS status,
  116. mr.has_evaluate AS hasEvaluate
  117. FROM maintenance_record mr
  118. LEFT JOIN project p ON mr.project_id = p.id
  119. <if test="(request.currentRoleCode == 'REGION_DIRECTOR') or (request.currentRoleCode == 'ROLEMTWORK' and request.look == 1) ">
  120. LEFT JOIN project_user pu ON p.id = pu.project_id
  121. </if>
  122. LEFT JOIN lift l ON mr.lift_id = l.id
  123. LEFT JOIN user_info ui ON mr.worker_id = ui.user_id
  124. WHERE mr.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  125. <choose>
  126. <when test="(request.currentRoleCode == 'REGION_DIRECTOR') or (request.currentRoleCode == 'ROLEMTWORK' and request.look == 1) ">
  127. AND pu.user_id = #{request.userId,jdbcType=BIGINT}
  128. </when>
  129. <when test="request.userId !=null">
  130. AND mr.worker_id1 = #{request.userId,jdbcType=BIGINT}
  131. </when>
  132. <otherwise/>
  133. </choose>
  134. <if test="request.status!=null and request.status!=''">
  135. AND mr.status = #{request.status,jdbcType=VARCHAR}
  136. </if>
  137. <if test="request.currentTime!=null">
  138. AND <![CDATA[ mr.plan_date = #{request.currentTime}]]>
  139. </if>
  140. <if test="request.beginTime!=null">
  141. AND <![CDATA[ mr.plan_date >= #{request.beginTime}]]>
  142. </if>
  143. <if test="request.endTime!=null">
  144. AND <![CDATA[ mr.plan_date <= #{request.endTime}]]>
  145. </if>
  146. </select>
  147. <!--app端 保养任务统计 (1:保养中、2:已完成) -->
  148. <select id="countRecordByWorkerId" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.MaintenanceCount"
  149. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest">
  150. SELECT t.plan_date,
  151. MAX(CASE t.status WHEN '1' THEN t.total ELSE 0 END) inProgress,
  152. MAX(CASE t.status WHEN '2' THEN t.total ELSE 0 END) complete
  153. FROM (
  154. SELECT mr.status,
  155. mr.plan_date,
  156. count(1) total
  157. FROM maintenance_record mr
  158. LEFT JOIN project p ON mr.project_id = p.id
  159. <if test="(request.currentRoleCode == 'REGION_DIRECTOR') or (request.currentRoleCode == 'ROLEMTWORK' and request.look == 1) ">
  160. LEFT JOIN project_user pu ON p.id = pu.project_id
  161. </if>
  162. LEFT JOIN lift l ON mr.lift_id = l.id
  163. LEFT JOIN user_info ui ON mr.worker_id = ui.user_id
  164. WHERE mr.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  165. <choose>
  166. <when test="(request.currentRoleCode == 'REGION_DIRECTOR') or (request.currentRoleCode == 'ROLEMTWORK' and request.look == 1) ">
  167. AND pu.user_id = #{request.userId,jdbcType=BIGINT}
  168. </when>
  169. <when test="request.userId !=null">
  170. AND mr.worker_id1 = #{request.userId,jdbcType=BIGINT}
  171. </when>
  172. <otherwise/>
  173. </choose>
  174. <if test="request.beginTime!=null">
  175. AND <![CDATA[ mr.plan_date >= #{request.beginTime}]]>
  176. </if>
  177. <if test="request.endTime!=null">
  178. AND <![CDATA[ mr.plan_date <= #{request.endTime}]]>
  179. </if>
  180. GROUP BY plan_date,
  181. status
  182. ) t
  183. GROUP BY t.plan_date
  184. </select>
  185. <select id="findRecordByLiftId"
  186. resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.ScanRecordResponse"
  187. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  188. SELECT mr.id AS id,
  189. l.id AS liftId,
  190. l.registration_code AS registrationCode,
  191. p.project_name AS projectName,
  192. l.device_position AS devicePosition,
  193. l.lift_type AS liftType,
  194. ui.name AS workerName
  195. FROM maintenance_record mr
  196. LEFT JOIN lift l ON l.id = mr.lift_id
  197. LEFT JOIN project p ON mr.project_id = p.id
  198. LEFT JOIN user_info ui ON mr.worker_id = ui.user_id
  199. WHERE mr.lift_id = #{request.liftId,jdbcType=BIGINT} AND mr.status = '2'
  200. </select>
  201. <!--日常保养-保养单:根据条件分页查询-->
  202. <select id="pageRecordByCondition" resultMap="BaseResultMap"
  203. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  204. SELECT
  205. mr.*,
  206. li.use_company_code,
  207. li.registration_code,
  208. li.category,
  209. ui.`name` AS worker_name,
  210. pr.project_name,
  211. ifnull(ev.star_level, 0),
  212. TimeStampDiff(SECOND ,mr.stop_date,mr.recovery_date) AS repair_diff
  213. FROM
  214. maintenance_record mr
  215. LEFT JOIN lift li ON mr.lift_id = li.id
  216. LEFT JOIN user_info ui ON mr.worker_id1 = ui.user_id
  217. LEFT JOIN project pr ON mr.project_id = pr.id AND pr.mt_company_id = mr.mt_company_id
  218. LEFT JOIN evaluation ev ON mr.id = ev.record_id
  219. <where>
  220. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  221. AND mr.mt_company_id = #{cond.mtCompanyId}
  222. </if>
  223. <if test="cond.regionId != null and cond.regionId > 0">
  224. AND pr.region_id = #{cond.regionId}
  225. </if>
  226. <if test="cond.projectId != null and cond.projectId > 0">
  227. AND pr.id = #{cond.projectId}
  228. </if>
  229. <if test="cond.workerId != null and cond.workerId > 0">
  230. AND mr.worker_id1 = #{cond.workerId}
  231. </if>
  232. <if test="cond.planBegin != null">
  233. AND mr.plan_date &gt; #{cond.planBegin}
  234. </if>
  235. <if test="cond.planEnd != null">
  236. AND mr.plan_date &lt; #{cond.planEnd}
  237. </if>
  238. <if test="cond.workDate != null">
  239. AND mr.work_date = #{cond.workDate}
  240. </if>
  241. </where>
  242. </select>
  243. <!--日常保养-保养单:根据条件汇总条数-->
  244. <select id="countRecordByCondition" resultType="java.lang.Long"
  245. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  246. SELECT
  247. count(*)
  248. FROM
  249. maintenance_record mr
  250. <where>
  251. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  252. AND mr.mt_company_id = #{cond.mtCompanyId}
  253. </if>
  254. </where>
  255. </select>
  256. <!--日常保养-保养单:根据id查询,带关联信息-->
  257. <select id="infoById" resultMap="BaseResultMap"
  258. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  259. SELECT
  260. mr.*,
  261. li.use_company_code,
  262. li.registration_code,
  263. li.category,
  264. mc.name AS mt_company_name,
  265. ui.`name` AS worker_name,
  266. pr.project_name,
  267. pr.project_code,
  268. ev.star_level
  269. FROM
  270. maintenance_record mr
  271. LEFT JOIN lift li ON mr.lift_id = li.id
  272. LEFT JOIN user_info ui ON mr.worker_id1 = ui.user_id
  273. LEFT JOIN project pr ON mr.project_id = pr.id AND mr.mt_company_id = pr.mt_company_id
  274. LEFT JOIN evaluation ev ON mr.id = ev.record_id AND ev.source = 1
  275. LEFT JOIN maintenance_company mc ON mr.mt_company_id = mc.id
  276. <where>
  277. <if test="cond.id != null and cond.id > 0">
  278. mr.id = #{cond.id}
  279. </if>
  280. </where>
  281. </select>
  282. <select id="pageByLift" resultMap="BaseResultMap"
  283. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  284. SELECT
  285. mr.*,
  286. li.use_company_code,
  287. li.registration_code,
  288. li.category,
  289. mc.name AS mt_company_name,
  290. ui.`name` AS worker_name,
  291. pr.project_name,
  292. pr.project_code,
  293. ev.star_level
  294. FROM
  295. maintenance_record mr
  296. LEFT JOIN lift li ON mr.lift_id = li.id
  297. LEFT JOIN user_info ui ON mr.worker_id1 = ui.user_id
  298. LEFT JOIN project pr ON mr.project_id = pr.id
  299. LEFT JOIN evaluation ev ON mr.id = ev.record_id
  300. LEFT JOIN maintenance_company mc ON mr.mt_company_id = mc.id
  301. <where>
  302. <if test="cond.liftId != null and cond.liftId > 0">
  303. AND mr.lift_id = #{cond.liftId}
  304. </if>
  305. <if test="cond.projectId != null and cond.projectId > 0">
  306. AND mr.project_id = #{cond.projectId}
  307. </if>
  308. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  309. AND mr.mt_company_id = #{cond.mtCompanyId}
  310. </if>
  311. </where>
  312. </select>
  313. </mapper>