MaintenanceRecordMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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"
  97. resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceAppResponse"
  98. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceAppRequest">
  99. SELECT p.project_name AS projectName,
  100. p.id AS projectId,
  101. mr.id AS mtPlanId,
  102. mr.id AS recordId,
  103. l.id AS liftId,
  104. l.coordinate AS coordinate,
  105. l.registration_code AS registrationCode,
  106. l.use_company_code AS useCompanyCode,
  107. l.lift_type AS liftType,
  108. l.category AS category,
  109. l.lift_code AS liftCode,
  110. l.device_position AS devicePosition,
  111. ui.name AS workerName,
  112. mr.worker_id AS workerId,
  113. mr.worker_id1 AS workerId1,
  114. mr.plan_date AS planDate,
  115. mr.type AS maintenanceType,
  116. mr.status AS status
  117. FROM maintenance_record mr
  118. LEFT JOIN project p ON mr.project_id = p.id
  119. LEFT JOIN lift l ON mr.lift_id = l.id
  120. LEFT JOIN user_info ui ON mr.worker_id = ui.user_id
  121. WHERE mr.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  122. <if test="request.workerId!=null and request.workerId!=''">
  123. AND mr.worker_id1 = #{request.workerId,jdbcType=BIGINT}
  124. </if>
  125. <if test="request.status!=null and request.status!=''">
  126. AND mr.status = #{request.status,jdbcType=VARCHAR}
  127. </if>
  128. </select>
  129. <select id="findRecordByLiftId"
  130. resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.ScanRecordResponse"
  131. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  132. SELECT mr.id AS id,
  133. l.id AS liftId,
  134. l.registration_code AS registrationCode,
  135. p.project_name AS projectName,
  136. l.device_position AS devicePosition,
  137. l.lift_type AS liftType,
  138. ui.name AS workerName
  139. FROM maintenance_record mr
  140. LEFT JOIN lift l ON l.id = mr.lift_id
  141. LEFT JOIN project p ON mr.project_id = p.id
  142. LEFT JOIN user_info ui ON mr.worker_id = ui.user_id
  143. WHERE mr.lift_id = #{request.liftId,jdbcType=BIGINT} AND mr.status = '2'
  144. </select>
  145. <select id="countDoingByUser" resultType="java.lang.Long"
  146. parameterType="cn.com.ty.lift.business.common.CommonRequest">
  147. SELECT
  148. count(1)
  149. FROM maintenance_record mr
  150. WHERE mr.status = '1'
  151. <if test="request.userId != null and request.userId > 0">
  152. AND mr.worker_id1 = #{request.userId}
  153. </if>
  154. <if test="request.mtCompanyId != null and request.mtCompanyId > 0">
  155. AND mr.mt_company_id = #{request.mtCompanyId}
  156. </if>
  157. </select>
  158. <!--日常保养-保养单:根据条件分页查询-->
  159. <select id="pageRecordByCondition" resultMap="BaseResultMap"
  160. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  161. SELECT
  162. mr.*,
  163. li.use_company_code,
  164. li.registration_code,
  165. li.category,
  166. ui.`name` AS worker_name,
  167. pr.project_name,
  168. ifnull(ev.star_level, 0),
  169. TimeStampDiff(SECOND ,mr.stop_date,mr.recovery_date) AS repair_diff
  170. FROM
  171. maintenance_record mr
  172. LEFT JOIN lift li ON mr.lift_id = li.id
  173. LEFT JOIN user_info ui ON mr.worker_id1 = ui.user_id
  174. LEFT JOIN project pr ON mr.project_id = pr.id AND pr.mt_company_id = mr.mt_company_id
  175. LEFT JOIN evaluation ev ON mr.id = ev.record_id
  176. <where>
  177. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  178. AND mr.mt_company_id = #{cond.mtCompanyId}
  179. </if>
  180. <if test="cond.regionId != null and cond.regionId > 0">
  181. AND pr.region_id = #{cond.regionId}
  182. </if>
  183. <if test="cond.projectId != null and cond.projectId > 0">
  184. AND pr.id = #{cond.projectId}
  185. </if>
  186. <if test="cond.workerId != null and cond.workerId > 0">
  187. AND mr.worker_id1 = #{cond.workerId}
  188. </if>
  189. <if test="cond.planBegin != null">
  190. AND mr.plan_date &gt; #{cond.planBegin}
  191. </if>
  192. <if test="cond.planEnd != null">
  193. AND mr.plan_date &lt; #{cond.planEnd}
  194. </if>
  195. <if test="cond.workDate != null">
  196. AND mr.work_date = #{cond.workDate}
  197. </if>
  198. </where>
  199. </select>
  200. <!--日常保养-保养单:根据条件汇总条数-->
  201. <select id="countRecordByCondition" resultType="java.lang.Long"
  202. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  203. SELECT
  204. count(*)
  205. FROM
  206. maintenance_record mr
  207. <where>
  208. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  209. AND mr.mt_company_id = #{cond.mtCompanyId}
  210. </if>
  211. </where>
  212. </select>
  213. <!--日常保养-保养单:根据id查询,带关联信息-->
  214. <select id="infoById" resultMap="BaseResultMap"
  215. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  216. SELECT
  217. mr.*,
  218. li.use_company_code,
  219. li.registration_code,
  220. li.category,
  221. mc.name AS mt_company_name,
  222. ui.`name` AS worker_name,
  223. pr.project_name,
  224. pr.project_code,
  225. ev.star_level
  226. FROM
  227. maintenance_record mr
  228. LEFT JOIN lift li ON mr.lift_id = li.id
  229. LEFT JOIN user_info ui ON mr.worker_id1 = ui.user_id
  230. LEFT JOIN project pr ON mr.project_id = pr.id AND mr.mt_company_id = pr.mt_company_id
  231. LEFT JOIN evaluation ev ON mr.id = ev.record_id AND ev.source = 1
  232. LEFT JOIN maintenance_company mc ON mr.mt_company_id = mc.id
  233. <where>
  234. <if test="cond.id != null and cond.id > 0">
  235. mr.id = #{cond.id}
  236. </if>
  237. </where>
  238. </select>
  239. <select id="pageByLift" resultMap="BaseResultMap"
  240. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtRecordRequest">
  241. SELECT
  242. mr.*,
  243. li.use_company_code,
  244. li.registration_code,
  245. li.category,
  246. mc.name AS mt_company_name,
  247. ui.`name` AS worker_name,
  248. pr.project_name,
  249. pr.project_code,
  250. ev.star_level
  251. FROM
  252. maintenance_record mr
  253. LEFT JOIN lift li ON mr.lift_id = li.id
  254. LEFT JOIN user_info ui ON mr.worker_id1 = ui.user_id
  255. LEFT JOIN project pr ON mr.project_id = pr.id
  256. LEFT JOIN evaluation ev ON mr.id = ev.record_id
  257. LEFT JOIN maintenance_company mc ON mr.mt_company_id = mc.id
  258. <where>
  259. <if test="cond.liftId != null and cond.liftId > 0">
  260. AND mr.lift_id = #{cond.liftId}
  261. </if>
  262. <if test="cond.projectId != null and cond.projectId > 0">
  263. AND mr.project_id = #{cond.projectId}
  264. </if>
  265. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  266. AND mr.mt_company_id = #{cond.mtCompanyId}
  267. </if>
  268. </where>
  269. </select>
  270. </mapper>