Bez popisu

TLhgyWorkPlanMapper.xml 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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="com.yt.zhylplat.moduleLhgy.mapper.TLhgyWorkPlanMapper">
  4. <select id="selectWorkPlanBySection" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
  5. select
  6. temp_rsmc.old_section_id as sectionId,
  7. temp_rsmc.section_name as section_code,
  8. temp_rsmc.old_maintenance_company_id as objectId,
  9. temp_rsmc.maintenance_company_name as object_name,
  10. temp_rsmc.section_type,
  11. temp_rsmc.section_id as newSectionId,
  12. temp_rsmc.maintenance_company_id as maintenance_company_id,
  13. if(temp.planCount is null, 0, temp.planCount) as planCount,
  14. if(temp.noCompleteCount is null, 0, temp.noCompleteCount) as noCompleteCount,
  15. if(temp.completeCount is null, 0, temp.completeCount) as completeCount
  16. from
  17. (
  18. SELECT DISTINCT
  19. rsmc.section_id,
  20. s.section_name,
  21. s.section_type,
  22. rsmc.maintenance_company_id,
  23. mc.maintenance_company_name,
  24. s.old_section_id,
  25. mc.old_maintenance_company_id
  26. FROM
  27. T_Lhzx_Road_Section_Maintenance_Company rsmc
  28. LEFT JOIN
  29. T_Lhzx_Section s ON rsmc.section_id = s.id
  30. LEFT JOIN
  31. T_Lhzx_Maintenance_Company mc on rsmc.maintenance_company_id = mc.id
  32. ) temp_rsmc
  33. left join
  34. (<include refid="selectWorkPlanSql"/>) temp
  35. on temp_rsmc.section_id = temp.newSectionId and temp_rsmc.maintenance_company_id = temp.maintenance_company_id
  36. </select>
  37. <select id="selectWorkPlanBySectionType" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
  38. select distinct
  39. s.section_type,
  40. sum(if(temp.planCount is null, 0, temp.planCount)) as planCount,
  41. sum(if(temp.noCompleteCount is null, 0, temp.noCompleteCount)) as noCompleteCount,
  42. sum(if(temp.completeCount is null, 0, temp.completeCount)) as completeCount
  43. from
  44. T_Lhzx_Section s
  45. left join
  46. (<include refid="selectWorkPlanSql"/>) temp
  47. on
  48. s.section_type = temp.section_type
  49. group by
  50. s.section_type
  51. </select>
  52. <select id="selectWorkPlanSumCount" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
  53. select
  54. if(sum(if(temp.planCount is null, 0, temp.planCount)) is null, 0, sum(if(temp.planCount is null, 0, temp.planCount))) as planCount,
  55. if(sum(if(temp.noCompleteCount is null, 0, temp.noCompleteCount)) is null, 0, sum(if(temp.noCompleteCount is null, 0, temp.noCompleteCount))) as noCompleteCount,
  56. if(sum(if(temp.completeCount is null, 0, temp.completeCount)) is null, 0, sum(if(temp.completeCount is null, 0, temp.completeCount))) as completeCount
  57. from
  58. (<include refid="selectWorkPlanSql"/>) temp
  59. </select>
  60. <select id="selectWorkPlanComRateBySection" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
  61. select
  62. temp.*
  63. from
  64. (<include refid="workPlanComRateSql"/>) temp
  65. </select>
  66. <select id="selectWorkPlanComRateByTrimType" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
  67. select
  68. temp.trim_type,
  69. SUM(IF(temp.planCount is null, 0, temp.planCount)) as planCount,
  70. SUM(IF(temp.completeCount is null,0,temp.completeCount)) as completeCount,
  71. SUM(IF(temp.completeCount is null,0,temp.completeCount)) / SUM(IF(temp.planCount is null, 0, temp.planCount)) as complete_rate
  72. from
  73. (<include refid="workPlanComRateSql"/>) temp
  74. group by
  75. temp.trim_type
  76. </select>
  77. <select id="selectLhgyPlanByPageList" resultType="com.yt.zhylplat.moduleLhgy.entity.TLhgyWorkPlan">
  78. select * from T_Lhgy_Work_Plan p left join (
  79. select
  80. plan_id,
  81. trim_type
  82. FROM
  83. T_Lhgy_Work_Plan_Detail
  84. where
  85. state=2
  86. and
  87. delete_flag=0
  88. <if test="tLhgyWorkPlan.trimType != null">
  89. and trim_type=#{tLhgyWorkPlan.trimType}
  90. </if>
  91. GROUP BY plan_id,trim_type ORDER BY plan_id) pd
  92. on p.id=pd.plan_id
  93. where p.state=2
  94. and p.delete_flag=0
  95. <if test="tLhgyWorkPlan.planType != null">
  96. and p.plan_type = #{tLhgyWorkPlan.planType}
  97. </if>
  98. <if test="tLhgyWorkPlan.sectionId != null">
  99. and p.section_id = #{tLhgyWorkPlan.sectionId}
  100. </if>
  101. <if test="tLhgyWorkPlan.objectId != null">
  102. and p.object_id = #{tLhgyWorkPlan.objectId}
  103. </if>
  104. order by
  105. p.id
  106. </select>
  107. <sql id="workPlanComRateSql">
  108. SELECT
  109. wp.section_id,
  110. s.section_name as section_code,
  111. wp.object_id,
  112. mc.maintenance_company_name as object_name,
  113. wpd.trim_type,
  114. SUM(IF(wpd.amount is null, 0, wpd.amount)) as planCount,
  115. SUM(IF(wpdi.complete_amount is null,0,wpdi.complete_amount)) as completeCount,
  116. SUM(IF(wpdi.complete_amount is null,0,wpdi.complete_amount)) / SUM(IF(wpd.amount is null, 0, wpd.amount)) as complete_rate
  117. FROM
  118. T_Lhgy_Work_Plan_Detail wpd
  119. LEFT JOIN
  120. T_Lhgy_Work_Plan wp ON wp.id = wpd.plan_id
  121. left join
  122. T_Lhzx_Section s on wp.section_id = s.old_section_id
  123. left join
  124. T_Lhzx_Maintenance_Company mc on mc.old_maintenance_company_id = wp.object_id
  125. LEFT JOIN (
  126. SELECT
  127. SUM(IF(complete_amount is null,0,complete_amount)) as complete_amount,
  128. plan_detail_id
  129. FROM
  130. T_Lhgy_Work_Plan_Detail_Item
  131. WHERE
  132. delete_flag = 0
  133. GROUP BY
  134. plan_detail_id
  135. ) wpdi on wpd.id = wpdi.plan_detail_id
  136. LEFT JOIN (
  137. SELECT
  138. sum(
  139. if(extra_large_num is null, 0, extra_large_num) +
  140. if(large_num is null, 0, large_num) +
  141. if(medium_num is null, 0, medium_num) +
  142. if(small_num is null, 0, small_num)
  143. ) as total_amount,
  144. mc.old_maintenance_company_id,
  145. s.old_section_id,
  146. road_id
  147. FROM
  148. T_Lhzx_Street_Tree st
  149. LEFT JOIN T_Lhzx_Maintenance_Company mc on mc.id = st.maintenance_company_id
  150. LEFT JOIN T_Lhzx_Section s on s.id = st.section_id
  151. WHERE
  152. st.del_flg = 0
  153. GROUP BY
  154. maintenance_company_id,
  155. section_id,
  156. road_id
  157. ) st on st.road_id = wpd.number5 and st.old_section_id = wp.section_id and st.old_maintenance_company_id = wp.object_id
  158. WHERE
  159. wpd.delete_flag = 0
  160. <if test="tLhgyWorkPlan.trimType != null and tLhgyWorkPlan.trimType == 4">
  161. and (wpd.trim_type = 4 or wp.plan_type = 2)
  162. </if>
  163. <if test="tLhgyWorkPlan.trimType != null and tLhgyWorkPlan.trimType != 4">
  164. and wpd.trim_type = #{tLhgyWorkPlan.trimType}
  165. </if>
  166. <if test="tLhgyWorkPlan.sectionId != null">
  167. and wp.section_id = #{tLhgyWorkPlan.sectionId}
  168. </if>
  169. <if test="tLhgyWorkPlan.objectId != null">
  170. and wp.object_id = #{tLhgyWorkPlan.objectId}
  171. </if>
  172. <if test="tLhgyWorkPlan.planYear != null and tLhgyWorkPlan.planYear != ''">
  173. and DATE_FORMAT(wpd.create_date, '%Y') = #{tLhgyWorkPlan.planYear}
  174. </if>
  175. and
  176. wpd.trim_type is not null
  177. and
  178. wp.section_id is not null
  179. GROUP BY
  180. wp.section_id,
  181. wp.section_code,
  182. wp.object_id,
  183. wp.object_name,
  184. wpd.trim_type,
  185. s.id,
  186. mc.id
  187. order by
  188. s.id,
  189. mc.id
  190. </sql>
  191. <sql id="selectWorkPlanSql">
  192. select
  193. wp.section_id as sectionId,
  194. s.section_name as section_code,
  195. wp.object_id as objectId,
  196. mc.maintenance_company_name as object_name,
  197. s.section_type,
  198. s.id as newSectionId,
  199. mc.id as maintenance_company_id,
  200. count(wp.id) as planCount,
  201. sum(if(wp.comp_state = 1, 1, 0)) as noCompleteCount,
  202. sum(if(wp.comp_state = 2, 1, 0)) as completeCount
  203. from
  204. T_Lhgy_Work_Plan wp
  205. left join
  206. T_Lhzx_Section s on s.old_section_id = wp.section_id
  207. left join
  208. T_Lhzx_Maintenance_Company mc on mc.old_maintenance_company_id = wp.object_id
  209. where
  210. wp.delete_flag = 0
  211. <if test="tLhgyWorkPlan.sectionId != null">
  212. and wp.section_id = #{tLhgyWorkPlan.sectionId}
  213. </if>
  214. <if test="tLhgyWorkPlan.objectId != null">
  215. and wp.object_id = #{tLhgyWorkPlan.objectId}
  216. </if>
  217. <if test="tLhgyWorkPlan.planMonth != null and tLhgyWorkPlan.planMonth != ''">
  218. and DATE_FORMAT(wp.create_date, '%Y-%m') = #{tLhgyWorkPlan.planMonth}
  219. </if>
  220. <if test="tLhgyWorkPlan.sectionType != null">
  221. and s.section_type = #{tLhgyWorkPlan.sectionType}
  222. </if>
  223. <if test="tLhgyWorkPlan.trimType != null">
  224. and wp.id in (
  225. select
  226. plan_id
  227. from
  228. T_Lhgy_Work_Plan_Detail
  229. where
  230. delete_flag = 0
  231. and
  232. trim_type = #{trimType}
  233. )
  234. </if>
  235. group by
  236. wp.section_id,
  237. s.section_name,
  238. wp.object_id,
  239. mc.maintenance_company_name,
  240. s.section_type,
  241. s.id,
  242. mc.id
  243. order by
  244. s.id,
  245. mc.id
  246. </sql>
  247. </mapper>