MaintenancePlanMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. <!-- 查询当天所有维保工的维保任务 -->
  38. <select id="queryMaintenanceTask" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.MaintenanceTask">
  39. SELECT count(1) AS num,
  40. mp.worker_id,
  41. ua.device_model,
  42. ua.device_flag
  43. FROM maintenance_plan mp
  44. LEFT JOIN user_account ua ON mp.worker_id = ua.user_id
  45. WHERE plan_date = current_date() AND mp.status = 0
  46. GROUP BY mp.worker_id, ua.device_model, ua.device_flag
  47. </select>
  48. <select id="findByCondition" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenancePlanResponse"
  49. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenancePlanRequest">
  50. SELECT
  51. mp.id AS id,
  52. if(isnull(mp.id), '0', '1') AS status,
  53. mp.plan_date AS planDate,
  54. l.id AS liftId,
  55. l.registration_code AS registrationCode,
  56. l.device_position AS devicePosition,
  57. plr.id AS relevanceId,
  58. plr.mt_company_id AS mtCompanyId,
  59. plr.worker_id AS workerId,
  60. plr.plan_interval AS planInterval,
  61. p.id AS projectId,
  62. p.project_name AS projectName,
  63. p.project_code AS projectCode,
  64. pclr.lift_company_status AS liftStatus,
  65. r.area_name AS regionName,
  66. ui.name AS workerName
  67. FROM
  68. project_lift_relevance plr
  69. LEFT JOIN platform_company_lift_relevance pclr ON plr.mt_company_id = pclr.mt_company_id AND plr.lift_id = pclr.lift_id
  70. LEFT JOIN lift l ON plr.lift_id = l.id
  71. LEFT JOIN project p ON plr.mt_company_id = p.mt_company_id AND plr.project_id = p.id
  72. LEFT JOIN maintenance_plan mp ON plr.mt_company_id = mp.mt_company_id AND plr.project_id = mp.project_id
  73. AND mp.status = 0 AND mp.plan_date = (SELECT MIN(plan_date) FROM maintenance_plan WHERE status = 0
  74. AND mt_company_id = #{request.mtCompanyId,jdbcType=VARCHAR} AND lift_id = plr.lift_id) AND plr.lift_id = mp.lift_id
  75. LEFT JOIN user_info ui ON plr.worker_id = ui.user_id
  76. LEFT JOIN region r ON p.region_id = r.id
  77. WHERE plr.mt_company_id = #{request.mtCompanyId,jdbcType=VARCHAR}
  78. AND pclr.lift_company_status != '1'
  79. <if test="request.projectId!=null and request.projectId > 0">
  80. AND p.id = #{request.projectId,jdbcType=BIGINT}
  81. </if>
  82. <if test="request.workerId!=null and request.workerId > 0">
  83. AND mp.worker_id = #{request.workerId,jdbcType=BIGINT}
  84. </if>
  85. <if test="request.regionId!=null and request.regionId > 0">
  86. AND p.region_id = #{request.regionId,jdbcType=BIGINT}
  87. </if>
  88. <if test="request.planInterval!=null and request.planInterval > 0">
  89. AND plr.plan_interval = #{request.planInterval,jdbcType=INTEGER}
  90. </if>
  91. <if test="request.beginTime!=null">
  92. AND <![CDATA[mp.plan_date > #{request.beginTime}]]>
  93. </if>
  94. <if test="request.endTime!=null">
  95. AND <![CDATA[mp.plan_date < #{request.endTime,jdbcType=VARCHAR}]]>
  96. </if>
  97. <if test="request.registrationCode!=null and request.registrationCode!=''">
  98. AND l.registration_code LIKE #{request.registrationCode,jdbcType=VARCHAR}
  99. </if>
  100. ORDER BY plan_date
  101. </select>
  102. <select id="queryPlanListByIds" parameterType="java.util.Map" resultMap="BaseResultMap">
  103. SELECT <include refid="Base_Column_List"/>
  104. FROM maintenance_plan
  105. WHERE mt_company_id = #{paramMap.mtCompanyId,jdbcType=VARCHAR}
  106. AND plan_date BETWEEN #{paramMap.beginTime} AND #{paramMap.endTime}
  107. AND lift_id IN
  108. <foreach collection="paramMap.liftIdList" item="id" index="index" open="(" close=")" separator=",">
  109. #{id}
  110. </foreach>
  111. </select>
  112. <!--app端 保养任务列表 (0:待保养、-1:超期) -->
  113. <select id="findPlanByWorkerId" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.response.MaintenanceAppResponse"
  114. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest">
  115. SELECT p.project_name AS projectName,
  116. p.id AS projectId,
  117. mp.id AS mtPlanId,
  118. l.id AS liftId,
  119. l.coordinate AS coordinate,
  120. l.registration_code AS registrationCode,
  121. l.use_company_code AS useCompanyCode,
  122. l.lift_type AS liftType,
  123. l.category AS category,
  124. l.lift_code AS liftCode,
  125. l.device_position AS devicePosition,
  126. ui.name AS workerName,
  127. mp.worker_id AS workerId,
  128. mp.plan_date AS planDate,
  129. mp.type AS maintenanceType,
  130. mp.status AS status
  131. FROM maintenance_plan mp
  132. LEFT JOIN project p ON mp.project_id = p.id
  133. <if test="request.currentRoleCode == 'REGION_DIRECTOR' ">
  134. LEFT JOIN project_user pu ON p.id = pu.project_id
  135. </if>
  136. LEFT JOIN lift l ON mp.lift_id = l.id
  137. LEFT JOIN user_info ui ON mp.worker_id = ui.user_id
  138. WHERE mp.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  139. <choose>
  140. <when test="request.userId > 0 and request.currentRoleCode == 'REGION_DIRECTOR' ">
  141. AND pu.user_id = #{request.userId,jdbcType=BIGINT}
  142. </when>
  143. <otherwise>
  144. AND mp.worker_id = #{request.userId,jdbcType=BIGINT}
  145. </otherwise>
  146. </choose>
  147. <if test="request.status!=null and request.status!=''">
  148. AND mp.status = #{request.status,jdbcType=VARCHAR}
  149. </if>
  150. <if test="request.currentTime!=null">
  151. AND <![CDATA[ mp.plan_date = #{request.currentTime}]]>
  152. </if>
  153. <if test="request.beginTime!=null">
  154. AND <![CDATA[ mp.plan_date >= #{request.beginTime}]]>
  155. </if>
  156. <if test="request.endTime!=null">
  157. AND <![CDATA[ mp.plan_date <= #{request.endTime}]]>
  158. </if>
  159. </select>
  160. <!--app端 保养任务统计 (0:待保养、-1:超期) -->
  161. <select id="countPlanByWorkerId" resultType="cn.com.ty.lift.business.maintenance.dao.entity.model.MaintenanceCount"
  162. parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MaintenanceRecordRequest">
  163. SELECT t.plan_date,
  164. MAX(CASE t.status WHEN '0' THEN t.total ELSE 0 END) waitingMaintenance,
  165. MAX(CASE t.status WHEN '-1' THEN t.total ELSE 0 END) overdue
  166. FROM (
  167. SELECT mp.status,
  168. mp.plan_date,
  169. count(1) total
  170. FROM maintenance_plan mp
  171. LEFT JOIN project p ON mp.project_id = p.id
  172. <if test="request.currentRoleCode == 'REGION_DIRECTOR' ">
  173. LEFT JOIN project_user pu ON p.id = pu.project_id
  174. </if>
  175. LEFT JOIN lift l ON mp.lift_id = l.id
  176. LEFT JOIN user_info ui ON mp.worker_id = ui.user_id
  177. WHERE mp.mt_company_id = #{request.mtCompanyId,jdbcType=BIGINT}
  178. <choose>
  179. <when test="request.userId > 0 and request.currentRoleCode == 'REGION_DIRECTOR' ">
  180. AND pu.user_id = #{request.userId,jdbcType=BIGINT}
  181. </when>
  182. <otherwise>
  183. AND mp.worker_id = #{request.userId,jdbcType=BIGINT}
  184. </otherwise>
  185. </choose>
  186. <if test="request.beginTime!=null">
  187. AND <![CDATA[ mp.plan_date >= #{request.beginTime}]]>
  188. </if>
  189. <if test="request.endTime!=null">
  190. AND <![CDATA[ mp.plan_date <= #{request.endTime}]]>
  191. </if>
  192. GROUP BY plan_date,
  193. status
  194. ) t
  195. GROUP BY t.plan_date
  196. </select>
  197. <!--日常保养-计划超期:根据条件分页查询-->
  198. <select id="pagePlanByCondition" resultMap="maintenanceRecordResultMap" parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtPlanRequest">
  199. SELECT
  200. mp.*,
  201. li.use_company_code,
  202. li.device_position,
  203. li.registration_code,
  204. li.lift_type,
  205. li.category AS lift_category,
  206. pr.project_name,
  207. ui.`name` AS worker_name,
  208. mr.id AS mt_record_id,
  209. ifnull(mr.status, -3) AS record_status
  210. FROM
  211. maintenance_plan mp
  212. LEFT JOIN lift li ON li.id = mp.lift_id
  213. LEFT JOIN project pr ON pr.id = mp.project_id AND pr.mt_company_id = mp.mt_company_id
  214. LEFT JOIN user_info ui ON ui.user_id = mp.worker_id
  215. LEFT JOIN maintenance_record mr ON mr.mt_plan_id = mp.id
  216. WHERE mp.plan_date &lt; now() AND mp.work_date IS NULL
  217. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  218. AND mp.mt_company_id = #{cond.mtCompanyId}
  219. </if>
  220. <if test="cond.regionId != null and cond.regionId > 0">
  221. AND pr.region_id = #{cond.regionId}
  222. </if>
  223. <if test="cond.projectId != null and cond.projectId > 0">
  224. AND pr.id = #{cond.projectId}
  225. </if>
  226. <if test="cond.workerId != null and cond.workerId > 0">
  227. AND mp.worker_id = #{cond.workerId}
  228. </if>
  229. <if test="cond.planBegin != null">
  230. AND mp.plan_date &gt; #{cond.planBegin}
  231. </if>
  232. <if test="cond.planEnd != null">
  233. AND mp.plan_date &lt; #{cond.planEnd}
  234. </if>
  235. <if test="cond.workDate != null">
  236. AND mp.work_date = #{cond.workDate}
  237. </if>
  238. </select>
  239. <!--日常保养-计划超期:根据条件总计条数-->
  240. <select id="countPlanByCondition" resultType="java.lang.Long" parameterType="cn.com.ty.lift.business.maintenance.dao.entity.model.request.MtPlanRequest">
  241. SELECT
  242. count(*)
  243. FROM
  244. maintenance_plan mp
  245. WHERE mp.plan_date &lt; now() AND mp.work_date IS NULL
  246. <if test="cond.mtCompanyId != null and cond.mtCompanyId > 0">
  247. AND mp.mt_company_id = #{cond.mtCompanyId}
  248. </if>
  249. </select>
  250. <select id="exportList" parameterType="java.util.List" resultType="java.util.Map">
  251. SELECT DATE_FORMAT(mp.plan_date,'%Y-%m-%d') AS planDate,
  252. l.registration_code AS registrationCode,
  253. l.device_position AS devicePosition,
  254. plr.plan_interval AS planInterval,
  255. p.project_name AS projectName,
  256. p.project_code AS projectCode,
  257. CASE pclr.lift_company_status
  258. WHEN '1' THEN '停保'
  259. WHEN '2' THEN '正常'
  260. WHEN '3' THEN '保养中'
  261. WHEN '4' THEN '维修中'
  262. WHEN '5' THEN '年检中'
  263. WHEN '6' THEN '大修中'
  264. END AS liftStatus,
  265. r.area_name AS regionName,
  266. ui.name AS workerName
  267. FROM project_lift_relevance plr
  268. LEFT JOIN platform_company_lift_relevance pclr
  269. ON plr.mt_company_id = pclr.mt_company_id AND plr.lift_id = pclr.lift_id
  270. LEFT JOIN lift l ON plr.lift_id = l.id
  271. LEFT JOIN project p ON plr.mt_company_id = p.mt_company_id AND plr.project_id = p.id
  272. LEFT JOIN maintenance_plan mp ON plr.mt_company_id = mp.mt_company_id AND plr.project_id = mp.project_id
  273. AND plr.lift_id = mp.lift_id
  274. LEFT JOIN user_info ui ON plr.worker_id = ui.user_id
  275. LEFT JOIN region r ON p.region_id = r.id
  276. <where>
  277. <if test="exportList != null and exportList.size > 0">
  278. AND mp.id IN
  279. <foreach collection="exportList" item="id" open="(" separator="," close=")">
  280. #{id}
  281. </foreach>
  282. </if>
  283. </where>
  284. </select>
  285. </mapper>