MaintenanceRecordMapper.xml 14 KB

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