MaintenancePlanMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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="lift_category" property="liftCategory" jdbcType="INTEGER" />
  25. <result column="project_name" property="projectName" jdbcType="VARCHAR" />
  26. <result column="use_company_code" property="useCompanyCode" jdbcType="VARCHAR" />
  27. <result column="registration_code" property="registrationCode" jdbcType="VARCHAR" />
  28. <result column="device_position" property="devicePosition" jdbcType="VARCHAR" />
  29. <result column="worker_name" property="workerName" jdbcType="VARCHAR" />
  30. <result column="mt_record_id" property="mtRecordId" jdbcType="BIGINT" />
  31. <result column="record_status" property="recordStatus" jdbcType="VARCHAR" />
  32. </resultMap>
  33. <sql id="Base_Column_List" >
  34. id, lift_id, mt_company_id, project_id, worker_id, plan_date, work_date, count, type,
  35. status
  36. </sql>
  37. <select id="findByCondition" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenancePlanResponse"
  38. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenancePlanRequest">
  39. SELECT
  40. mp.id AS id,
  41. if(isnull(mp.id), '0', '1') AS status,
  42. mp.plan_date AS planDate,
  43. l.id AS liftId,
  44. l.registration_code AS registrationCode,
  45. l.device_position AS devicePosition,
  46. plr.id AS relevanceId,
  47. plr.mt_company_id AS mtCompanyId,
  48. plr.worker_id AS workerId,
  49. plr.plan_interval AS planInterval,
  50. p.id AS projectId,
  51. p.project_name AS projectName,
  52. p.project_code AS projectCode,
  53. pclr.lift_company_status AS liftStatus,
  54. r.area_name AS regionName,
  55. ui.name AS workerName
  56. FROM
  57. project_lift_relevance plr
  58. LEFT JOIN platform_company_lift_relevance pclr ON plr.mt_company_id = pclr.mt_company_id AND plr.lift_id = pclr.lift_id
  59. LEFT JOIN lift l ON plr.lift_id = l.id
  60. LEFT JOIN project p ON plr.mt_company_id = p.mt_company_id AND plr.project_id = p.id
  61. LEFT JOIN maintenance_plan mp ON plr.mt_company_id = mp.mt_company_id AND plr.project_id = mp.project_id
  62. AND mp.status = 0 AND mp.plan_date = (SELECT MIN(plan_date) FROM maintenance_plan WHERE status = 0
  63. AND mt_company_id = #{request.mtCompanyId,jdbcType=VARCHAR} AND lift_id = plr.lift_id) AND plr.lift_id = mp.lift_id
  64. LEFT JOIN user_info ui ON plr.worker_id = ui.user_id
  65. LEFT JOIN region r ON p.region_id = r.id
  66. WHERE plr.mt_company_id = #{request.mtCompanyId,jdbcType=VARCHAR}
  67. AND pclr.lift_company_status != '1'
  68. <if test="request.projectId!=null and request.projectId > 0">
  69. AND p.id = #{request.projectId,jdbcType=BIGINT}
  70. </if>
  71. <if test="request.workerId!=null and request.workerId > 0">
  72. AND mp.worker_id = #{request.workerId,jdbcType=BIGINT}
  73. </if>
  74. <if test="request.regionId!=null and request.regionId > 0">
  75. AND p.region_id = #{request.regionId,jdbcType=BIGINT}
  76. </if>
  77. <if test="request.planInterval!=null and request.planInterval > 0">
  78. AND plr.plan_interval = #{request.planInterval,jdbcType=INTEGER}
  79. </if>
  80. <if test="request.beginTime!=null">
  81. AND <![CDATA[mp.plan_date > #{request.beginTime}]]>
  82. </if>
  83. <if test="request.endTime!=null">
  84. AND <![CDATA[mp.plan_date < #{request.endTime,jdbcType=VARCHAR}]]>
  85. </if>
  86. <if test="request.registrationCode!=null and request.registrationCode!=''">
  87. AND l.registration_code LIKE #{request.registrationCode,jdbcType=VARCHAR}
  88. </if>
  89. </select>
  90. <select id="queryPlanListByIds" parameterType="java.util.Map" resultMap="BaseResultMap">
  91. SELECT <include refid="Base_Column_List"/>
  92. FROM maintenance_plan
  93. WHERE mt_company_id = #{paramMap.mtCompanyId,jdbcType=VARCHAR}
  94. AND plan_date BETWEEN #{paramMap.beginTime} AND #{paramMap.endTime}
  95. AND lift_id IN
  96. <foreach collection="paramMap.liftIdList" item="id" index="index" open="(" close=")" separator=",">
  97. #{id}
  98. </foreach>
  99. </select>
  100. <!--app端 保养任务列表 (0:待保养、-1:超期) -->
  101. <select id="findPlanByWorkerId" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceAppResponse"
  102. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest">
  103. SELECT p.project_name AS projectName,
  104. p.id AS projectId,
  105. mp.id AS mtPlanId,
  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. mp.status AS status
  119. FROM maintenance_plan mp
  120. LEFT JOIN project p ON mp.project_id = p.id
  121. LEFT JOIN project_user pu ON p.id = pu.project_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 mp.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  125. <if test="request.userId!=null">
  126. AND pu.user_id = #{request.userId,jdbcType=BIGINT}
  127. </if>
  128. <if test="request.status!=null and request.status!=''">
  129. AND mp.status = #{request.status,jdbcType=VARCHAR}
  130. </if>
  131. <if test="request.currentTime!=null">
  132. AND <![CDATA[ mp.plan_date = #{request.currentTime}]]>
  133. </if>
  134. <if test="request.beginTime!=null">
  135. AND <![CDATA[ mp.plan_date >= #{request.beginTime}]]>
  136. </if>
  137. <if test="request.endTime!=null">
  138. AND <![CDATA[ mp.plan_date <= #{request.endTime}]]>
  139. </if>
  140. </select>
  141. <!--app端 保养任务列表 (0:待保养、-1:超期) -->
  142. <select id="countPlanByWorkerId" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceAppResponse"
  143. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest">
  144. SELECT mp.status
  145. FROM maintenance_plan mp
  146. LEFT JOIN project p ON mp.project_id = p.id
  147. LEFT JOIN project_user pu ON p.id = pu.project_id
  148. LEFT JOIN lift l ON mp.lift_id = l.id
  149. LEFT JOIN user_info ui ON mp.worker_id = ui.user_id
  150. WHERE mp.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  151. <if test="request.userId!=null">
  152. AND pu.user_id = #{request.userId,jdbcType=BIGINT}
  153. </if>
  154. <if test="request.beginTime!=null">
  155. AND <![CDATA[ mp.plan_date >= #{request.beginTime}]]>
  156. </if>
  157. <if test="request.endTime!=null">
  158. AND <![CDATA[ mp.plan_date <= #{request.endTime}]]>
  159. </if>
  160. </select>
  161. <!--日常保养-计划超期:根据条件分页查询-->
  162. <select id="pagePlanByCondition" resultMap="maintenanceRecordResultMap" parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtPlanRequest">
  163. SELECT
  164. mp.*,
  165. li.use_company_code,
  166. li.device_position,
  167. li.registration_code,
  168. li.lift_type,
  169. li.category AS lift_category,
  170. pr.project_name,
  171. ui.`name` AS worker_name,
  172. mr.id AS mt_record_id,
  173. ifnull(mr.status, -3) AS record_status
  174. FROM
  175. maintenance_plan mp
  176. LEFT JOIN lift li ON li.id = mp.lift_id
  177. LEFT JOIN project pr ON pr.id = mp.project_id AND pr.mt_company_id = mp.mt_company_id
  178. LEFT JOIN user_info ui ON ui.user_id = mp.worker_id
  179. LEFT JOIN maintenance_record mr ON mr.mt_plan_id = mp.id
  180. WHERE mp.plan_date &lt; now() AND mp.work_date IS NULL
  181. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  182. AND mp.mt_company_id = #{cond.mtCompanyId}
  183. </if>
  184. <if test="cond.regionId != null and cond.regionId > 0">
  185. AND pr.region_id = #{cond.regionId}
  186. </if>
  187. <if test="cond.projectId != null and cond.projectId > 0">
  188. AND pr.id = #{cond.projectId}
  189. </if>
  190. <if test="cond.workerId != null and cond.workerId > 0">
  191. AND mp.worker_id = #{cond.workerId}
  192. </if>
  193. <if test="cond.planBegin != null">
  194. AND mp.plan_date &gt; #{cond.planBegin}
  195. </if>
  196. <if test="cond.planEnd != null">
  197. AND mp.plan_date &lt; #{cond.planEnd}
  198. </if>
  199. <if test="cond.workDate != null">
  200. AND mp.work_date = #{cond.workDate}
  201. </if>
  202. </select>
  203. <!--日常保养-计划超期:根据条件总计条数-->
  204. <select id="countPlanByCondition" resultType="java.lang.Long" parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtPlanRequest">
  205. SELECT
  206. count(*)
  207. FROM
  208. maintenance_plan mp
  209. WHERE mp.plan_date &lt; now() AND mp.work_date IS NULL
  210. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  211. AND mp.mt_company_id = #{cond.mtCompanyId}
  212. </if>
  213. </select>
  214. </mapper>