Нет описания

TLhzxFlowerWorkPlanMapper.xml 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.moduleMain.flower.mapper.TLhzxFlowerWorkPlanMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.yt.zhylplat.moduleMain.flower.entity.TLhzxFlowerWorkPlan">
  6. <id column="id" property="id" />
  7. <result column="plan_no" property="planNo" />
  8. <result column="section_id" property="sectionId" />
  9. <result column="section_name" property="sectionName" />
  10. <result column="maintenance_company_id" property="maintenanceCompanyId" />
  11. <result column="maintenance_company_name" property="maintenanceCompanyName" />
  12. <result column="phone" property="phone" />
  13. <result column="user_id" property="userId" />
  14. <result column="user_code" property="userCode" />
  15. <result column="user_name" property="userName" />
  16. <result column="start_time" property="startTime" />
  17. <result column="end_time" property="endTime" />
  18. <result column="plan_type" property="planType" />
  19. <result column="state" property="state" />
  20. <result column="effect_date" property="effectDate" />
  21. <result column="remark" property="remark" />
  22. <result column="create_user_id" property="createUserId" />
  23. <result column="create_date" property="createDate" />
  24. <result column="update_user_id" property="updateUserId" />
  25. <result column="update_date" property="updateDate" />
  26. <result column="del_flg" property="delFlg" />
  27. </resultMap>
  28. <!-- 通用查询结果列 -->
  29. <sql id="Base_Column_List">
  30. id, plan_no, section_id, section_name, maintenance_company_id, maintenance_company_name, phone, user_id, user_code, user_name, start_time, end_time, plan_type, state, effect_date, remark, create_user_id, create_date, update_user_id, update_date, del_flg
  31. </sql>
  32. <select id="selectFlowerWorkPlanBySection"
  33. resultType="com.yt.zhylplat.moduleMain.flower.entity.TLhzxFlowerWorkPlan">
  34. select
  35. temp.*
  36. from
  37. (<include refid="selectFlowerWorkPlanSql"/>) temp
  38. </select>
  39. <select id="selectFlowerWorkPlanBySectionType"
  40. resultType="com.yt.zhylplat.moduleMain.flower.entity.TLhzxFlowerWorkPlan">
  41. select
  42. temp.section_type,
  43. sum(if(temp.planCount is null, 0, temp.planCount)) as planCount,
  44. sum(if(temp.completeCount is null, 0, temp.completeCount)) as completeCount,
  45. if(
  46. sum(if(temp.planCount is null, 0, temp.planCount)) - sum(if(temp.completeCount is null, 0, temp.completeCount)) <![CDATA[ < ]]> 0,
  47. 0,
  48. sum(if(temp.planCount is null, 0, temp.planCount)) - sum(if(temp.completeCount is null, 0, temp.completeCount))
  49. ) as noCompleteCount
  50. from
  51. (<include refid="selectFlowerWorkPlanSql"/>) temp
  52. group by
  53. temp.section_type
  54. </select>
  55. <select id="selectFlowerWorkPlanSumCount"
  56. resultType="com.yt.zhylplat.moduleMain.flower.entity.TLhzxFlowerWorkPlan">
  57. select
  58. sum(if(temp.planCount is null, 0, temp.planCount)) as planCount,
  59. sum(if(temp.completeCount is null, 0, temp.completeCount)) as completeCount,
  60. if(
  61. sum(if(temp.planCount is null, 0, temp.planCount)) - sum(if(temp.completeCount is null, 0, temp.completeCount)) <![CDATA[ < ]]> 0,
  62. 0,
  63. sum(if(temp.planCount is null, 0, temp.planCount)) - sum(if(temp.completeCount is null, 0, temp.completeCount))
  64. ) as noCompleteCount
  65. from
  66. (<include refid="selectFlowerWorkPlanSql"/>) temp
  67. </select>
  68. <sql id="selectFlowerWorkPlanSql">
  69. select distinct
  70. rsmc.section_id as sectionId,
  71. s.section_name as sectionName,
  72. rsmc.maintenance_company_id as maintenanceCompanyId,
  73. mc.maintenance_company_name as maintenanceCompanyName,
  74. s.section_type,
  75. if(plan_count.planCount is null, 0, plan_count.planCount) as planCount,
  76. if(complete_count.completeCount is null, 0, complete_count.completeCount) as completeCount,
  77. if(
  78. if(plan_count.planCount is null, 0, plan_count.planCount) - if(complete_count.completeCount is null, 0, complete_count.completeCount) <![CDATA[ < ]]> 0,
  79. 0,
  80. if(plan_count.planCount is null, 0, plan_count.planCount) - if(complete_count.completeCount is null, 0, complete_count.completeCount)
  81. ) as noCompleteCount
  82. from
  83. T_Lhzx_Road_Section_Maintenance_Company rsmc
  84. left join
  85. T_Lhzx_Section s on s.id = rsmc.section_id
  86. left join
  87. T_Lhzx_Maintenance_Company mc on mc.id = rsmc.maintenance_company_id
  88. left join (
  89. select
  90. section_id,
  91. maintenance_company_id,
  92. count(id) as planCount
  93. from
  94. T_Lhzx_Flower_Work_Plan
  95. where
  96. plan_type = 1
  97. and
  98. del_flg = 0
  99. <if test="tLhzxFlowerWorkPlan.planMonth != null and tLhzxFlowerWorkPlan.planMonth != ''">
  100. and date_format(create_date, '%Y-%m') = #{tLhzxFlowerWorkPlan.planMonth}
  101. </if>
  102. group by
  103. section_id,
  104. maintenance_company_id
  105. ) plan_count on plan_count.section_id = rsmc.section_id and plan_count.maintenance_company_id = rsmc.maintenance_company_id
  106. left join (
  107. select
  108. section_id,
  109. maintenance_company_id,
  110. count(id) as completeCount
  111. from
  112. T_Lhzx_Flower_Work_Plan
  113. where
  114. plan_type = 2
  115. and
  116. del_flg = 0
  117. <if test="tLhzxFlowerWorkPlan.planMonth != null and tLhzxFlowerWorkPlan.planMonth != ''">
  118. and date_format(create_date, '%Y-%m') = #{tLhzxFlowerWorkPlan.planMonth}
  119. </if>
  120. group by
  121. section_id,
  122. maintenance_company_id
  123. ) complete_count on complete_count.section_id = rsmc.section_id and complete_count.maintenance_company_id = rsmc.maintenance_company_id
  124. where
  125. rsmc.del_flg = 0
  126. <if test="tLhzxFlowerWorkPlan.sectionId != null">
  127. and rsmc.section_id = #{tLhzxFlowerWorkPlan.sectionId}
  128. </if>
  129. <if test="tLhzxFlowerWorkPlan.maintenanceCompanyId != null">
  130. and rsmc.maintenance_company_id = #{tLhzxFlowerWorkPlan.maintenanceCompanyId}
  131. </if>
  132. <if test="tLhzxFlowerWorkPlan.sectionType != null">
  133. and s.section_type = #{tLhzxFlowerWorkPlan.sectionType}
  134. </if>
  135. order by
  136. rsmc.section_id,
  137. rsmc.maintenance_company_id
  138. </sql>
  139. </mapper>