MaintenancePlanMapper.xml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.MaintenancePlanMapper" >
  4. <resultMap id="BaseResultMap" type="cn.com.ty.lift.business.maintenance.dao.entity.MaintenancePlan" >
  5. <id column="id" property="id" jdbcType="BIGINT" />
  6. <result column="lift_id" property="liftId" jdbcType="BIGINT" />
  7. <result column="mt_company_id" property="mtCompanyId" jdbcType="BIGINT" />
  8. <result column="project_id" property="projectId" jdbcType="BIGINT" />
  9. <result column="worker_id" property="workerId" jdbcType="BIGINT" />
  10. <result column="plan_date" property="planDate" jdbcType="TIMESTAMP" />
  11. <result column="work_date" property="workDate" jdbcType="TIMESTAMP" />
  12. <result column="count" property="count" jdbcType="INTEGER" />
  13. <result column="type" property="type" jdbcType="TINYINT" />
  14. <result column="status" property="status" jdbcType="TINYINT" />
  15. <result column="creator_id" property="creatorId" jdbcType="BIGINT" />
  16. <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
  17. <result column="update_id" property="updateId" jdbcType="BIGINT" />
  18. <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
  19. <result column="demand" property="demand" jdbcType="VARCHAR" />
  20. </resultMap>
  21. <resultMap id="maintenanceRecordResultMap" type="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MtPlanResponse"
  22. extends="BaseResultMap">
  23. <result column="lift_type" property="liftType" jdbcType="INTEGER" />
  24. <result column="project_name" property="projectName" jdbcType="VARCHAR" />
  25. <result column="use_company_code" property="useCompanyCode" jdbcType="VARCHAR" />
  26. <result column="registration_code" property="registrationCode" jdbcType="VARCHAR" />
  27. <result column="device_position" property="devicePosition" jdbcType="VARCHAR" />
  28. <result column="worker_name" property="workerName" jdbcType="VARCHAR" />
  29. <result column="mt_record_id" property="mtRecordId" jdbcType="BIGINT" />
  30. <result column="record_status" property="recordStatus" jdbcType="VARCHAR" />
  31. </resultMap>
  32. <sql id="Base_Column_List" >
  33. id, lift_id, mt_company_id, project_id, worker_id, plan_date, work_date, count, type,
  34. status
  35. </sql>
  36. <select id="findByCondition" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenancePlanResponse"
  37. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenancePlanRequest">
  38. SELECT
  39. mp.id AS id,
  40. if(isnull(mp.id), '0', '1') AS status,
  41. mp.plan_date AS planDate,
  42. l.id AS liftId,
  43. l.registration_code AS registrationCode,
  44. l.device_position AS devicePosition,
  45. plr.id AS relevanceId,
  46. plr.mt_company_id AS mtCompanyId,
  47. plr.worker_id AS workerId,
  48. plr.plan_interval AS planInterval,
  49. p.id AS projectId,
  50. p.project_name AS projectName,
  51. p.project_code AS projectCode,
  52. pclr.lift_company_status AS liftStatus,
  53. r.area_name AS regionName,
  54. ui.name AS workerName
  55. FROM
  56. project_lift_relevance plr
  57. LEFT JOIN platform_company_lift_relevance pclr ON plr.mt_company_id = pclr.mt_company_id AND plr.lift_id = pclr.lift_id
  58. LEFT JOIN lift l ON plr.lift_id = l.id
  59. LEFT JOIN project p ON plr.mt_company_id = p.mt_company_id AND plr.project_id = p.id
  60. LEFT JOIN maintenance_plan mp ON plr.mt_company_id = mp.mt_company_id AND plr.project_id = mp.project_id
  61. AND mp.status = 0 AND mp.plan_date = (SELECT MIN(plan_date) FROM maintenance_plan WHERE status = 0
  62. AND mt_company_id = #{request.mtCompanyId,jdbcType=VARCHAR} AND lift_id = plr.lift_id) AND plr.lift_id = mp.lift_id
  63. LEFT JOIN user_info ui ON plr.worker_id = ui.user_id
  64. LEFT JOIN region r ON p.region_id = r.id
  65. WHERE plr.mt_company_id = #{request.mtCompanyId,jdbcType=VARCHAR}
  66. AND pclr.lift_company_status != '1'
  67. <if test="request.projectId!=null and request.projectId!=''">
  68. AND p.id = #{request.projectId,jdbcType=BIGINT}
  69. </if>
  70. <if test="request.workerId!=null and request.workerId!=''">
  71. AND mp.worker_id = #{request.workerId,jdbcType=BIGINT}
  72. </if>
  73. <if test="request.regionId!=null and request.regionId!=''">
  74. AND p.region_id = #{request.regionId,jdbcType=BIGINT}
  75. </if>
  76. <if test="request.planInterval!=null and request.planInterval!=''">
  77. AND plr.plan_interval = #{request.planInterval,jdbcType=INTEGER}
  78. </if>
  79. <if test="request.beginTime!=null and request.beginTime!=''">
  80. AND mp.plan_date > #{request.beginTime,jdbcType=VARCHAR}
  81. </if>
  82. <if test="request.endTime!=null and request.endTime!=''">
  83. AND <![CDATA[mp.plan_date < #{request.endTime,jdbcType=VARCHAR}]]>
  84. </if>
  85. <if test="request.registrationCode!=null and request.registrationCode!=''">
  86. AND l.registration_code LIKE #{request.registrationCode,jdbcType=VARCHAR}
  87. </if>
  88. </select>
  89. <select id="queryPlanListByIds" parameterType="java.util.Map" resultMap="BaseResultMap">
  90. SELECT t.*
  91. FROM (SELECT *, concat(project_id,'-',lift_id) AS projectLift
  92. FROM maintenance_plan) t
  93. WHERE t.mt_company_id = #{paramMap.mtCompanyId,jdbcType=VARCHAR}
  94. AND t.projectLift IN
  95. <foreach collection="paramMap.projectLiftList" item="id" index="index" open="(" close=")" separator=",">
  96. #{id}
  97. </foreach>
  98. </select>
  99. <!--app端 保养任务列表 -->
  100. <select id="findListByWorkerId" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceAppResponse"
  101. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceAppRequest">
  102. SELECT p.project_name AS projectName,
  103. p.id AS projectId,
  104. mp.id AS mtPlanId,
  105. mr.id AS recordId,
  106. l.id AS liftId,
  107. l.coordinate AS coordinate,
  108. l.registration_code AS registrationCode,
  109. l.use_company_code AS useCompanyCode,
  110. l.lift_type AS liftType,
  111. l.category AS category,
  112. l.lift_code AS liftCode,
  113. l.device_position AS devicePosition,
  114. ui.name AS workerName,
  115. mp.worker_id AS workerId,
  116. mp.plan_date AS planDate,
  117. mp.type AS maintenanceType,
  118. mr.status AS status
  119. FROM maintenance_plan mp
  120. LEFT JOIN maintenance_record mr ON mp.id = mr.mt_plan_id
  121. LEFT JOIN project p ON mp.project_id = p.id
  122. LEFT JOIN lift l ON mp.lift_id = l.id
  123. LEFT JOIN user_info ui ON mp.worker_id = ui.user_id
  124. WHERE 1=1
  125. <if test="request.workerId!=null and request.workerId!=''">
  126. AND mp.worker_id = #{request.workerId,jdbcType=BIGINT}
  127. </if>
  128. <if test="request.status!=null and request.status!=''">
  129. AND mp.status = #{request.status,jdbcType=VARCHAR}
  130. </if>
  131. </select>
  132. <!--日常保养-计划超期:根据条件分页查询-->
  133. <select id="pagePlanByCondition" resultMap="maintenanceRecordResultMap" parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtPlanRequest">
  134. SELECT
  135. mp.*,
  136. li.use_company_code,
  137. li.device_position,
  138. li.registration_code,
  139. li.lift_type,
  140. pr.project_name,
  141. ui.`name` AS worker_name,
  142. mr.id AS mt_record_id,
  143. ifnull(mr.status, -3) AS record_status
  144. FROM
  145. maintenance_plan mp
  146. LEFT JOIN lift li ON li.id = mp.lift_id
  147. LEFT JOIN project pr ON pr.id = mp.project_id AND pr.mt_company_id = mp.mt_company_id
  148. LEFT JOIN user_info ui ON ui.user_id = mp.worker_id
  149. LEFT JOIN maintenance_record mr ON mr.mt_plan_id = mp.id
  150. WHERE mp.plan_date &lt; now() AND mp.work_date IS NULL
  151. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  152. AND mp.mt_company_id = #{cond.mtCompanyId}
  153. </if>
  154. <if test="cond.regionId != null and cond.regionId > 0">
  155. AND pr.region_id = #{cond.regionId}
  156. </if>
  157. <if test="cond.projectId != null and cond.projectId > 0">
  158. AND pr.id = #{cond.projectId}
  159. </if>
  160. <if test="cond.workerId != null and cond.workerId > 0">
  161. AND mp.worker_id = #{cond.workerId}
  162. </if>
  163. <if test="cond.planBegin != null">
  164. AND mp.plan_date &gt; #{cond.planBegin}
  165. </if>
  166. <if test="cond.planEnd != null">
  167. AND mp.plan_date &lt; #{cond.planEnd}
  168. </if>
  169. <if test="cond.workDate != null">
  170. AND mp.work_date = #{cond.workDate}
  171. </if>
  172. </select>
  173. <!--日常保养-计划超期:根据条件总计条数-->
  174. <select id="countPlanByCondition" resultType="java.lang.Long" parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtPlanRequest">
  175. SELECT
  176. count(*)
  177. FROM
  178. maintenance_plan mp
  179. WHERE mp.plan_date &lt; now() AND mp.work_date IS NULL
  180. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  181. AND mp.mt_company_id = #{cond.mtCompanyId}
  182. </if>
  183. </select>
  184. </mapper>