KyxmMonthProgressMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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="KyxmMonthProgressMapper">
  4. <!--表名 -->
  5. <sql id="tableName">
  6. monthly_scientific_project_completion
  7. </sql>
  8. <!--表名 -->
  9. <sql id="listTableName">
  10. monthly_scientific_report_list
  11. </sql>
  12. <!--表名 -->
  13. <sql id="dettableTableName">
  14. highway_scientific_project_dettable
  15. </sql>
  16. <!-- 字段 -->
  17. <sql id="Field">
  18. COMPANY,
  19. COMPANY_ID,
  20. ROAD,
  21. ROAD_ID,
  22. YEAR,
  23. PROJECT_NAME,
  24. MONTH,
  25. ACTUAL_COST,
  26. PAY_COST,
  27. RATIO
  28. </sql>
  29. <sql id="FieldValue">
  30. #{item.company},
  31. #{item.companyId},
  32. #{item.road},
  33. #{item.roadId},
  34. #{item.year},
  35. #{item.projectName},
  36. #{item.month},
  37. #{item.actualCost},
  38. #{item.payCost},
  39. #{item.ratio}
  40. </sql>
  41. <!-- 查询道路项目 -->
  42. <select id="roadlistAll" parameterType="pd" resultType="pd">
  43. SELECT
  44. *
  45. FROM
  46. <include refid="dettableTableName"></include>
  47. WHERE
  48. YEAR = #{year}
  49. AND COMPANY_ID IN
  50. <foreach collection="companyIds" item="companyIds" index="index"
  51. open="(" close=")" separator=",">
  52. #{companyIds}
  53. </foreach>
  54. ORDER BY COMPANY_ID ASC ,ROAD_ID ASC
  55. </select>
  56. <!-- 列表(全部) -->
  57. <select id="listAll" parameterType="pd" resultType="pd">
  58. select
  59. <include refid="Field"></include>
  60. from
  61. <include refid="tableName"></include>
  62. WHERE
  63. YEAR = #{year}
  64. AND COMPANY_ID IN
  65. <foreach collection="companyIds" item="companyIds" index="index"
  66. open="(" close=")" separator=",">
  67. #{companyIds}
  68. </foreach>
  69. </select>
  70. <!--根据公司道路汇总 -->
  71. <select id="findSumByCompanyAndRoad" parameterType="pd" resultType="pd">
  72. SELECT
  73. COMPANY_ID,
  74. ROAD_ID,
  75. SUM(ACTUAL_COST) SUM_ACTUAL_COST,
  76. SUM(PAY_COST) SUM_PAY_COST,
  77. SUM(RATIO) SUM_RATIO
  78. FROM
  79. <include refid="tableName"></include>
  80. WHERE
  81. YEAR = #{year}
  82. AND COMPANY_ID IN
  83. <foreach collection="companyIds" item="companyIds" index="index"
  84. open="(" close=")" separator=",">
  85. #{companyIds}
  86. </foreach>
  87. GROUP BY COMPANY_ID,ROAD_ID
  88. </select>
  89. <!-- 批量插入 -->
  90. <insert id="insertBatch" parameterType="pd">
  91. insert into
  92. <include refid="tableName"></include>
  93. (
  94. <include refid="Field"></include>
  95. )
  96. values
  97. <foreach collection ="list" item="item" separator =",">
  98. (
  99. <include refid="FieldValue"></include>
  100. )
  101. </foreach >
  102. </insert>
  103. <!-- 根据年份和公司批量删除 -->
  104. <delete id="delByYearMonthAndCompanyId" parameterType="pd">
  105. delete from
  106. <include refid="tableName"></include>
  107. where
  108. YEAR = #{year}
  109. AND MONTH = #{month}
  110. AND COMPANY_ID IN
  111. <foreach collection="companyIds" item="companyIds" index="index"
  112. open="(" close=")" separator=",">
  113. #{companyIds}
  114. </foreach>
  115. </delete>
  116. <!-- 获取月度列表 -->
  117. <select id="getReportlist" parameterType="pd" resultType="pd">
  118. select
  119. *
  120. from
  121. <include refid="listTableName"></include>
  122. where
  123. 1=1
  124. <if test="keywords!= null and keywords != ''"><!-- 关键词检索 -->
  125. and
  126. (
  127. NAME LIKE CONCAT(CONCAT('%', #{pd.keywords}),'%')
  128. )
  129. </if>
  130. <if test="COMPANY != null">
  131. and COMPANY = #{COMPANY}
  132. </if>
  133. </select>
  134. <!-- 新增月度报告-->
  135. <insert id="addMonthlyReport" parameterType="pd">
  136. insert into
  137. <include refid="listTableName"></include>
  138. (
  139. COMPANY, COMPANY_ID,YEAR,NAME,STATUS,CTIME, MTIME
  140. ) values (
  141. #{COMPANY}, #{COMPANY_ID}, #{YEAR}, #{NAME}, #{STATUS}, #{CTIME}, #{MTIME}
  142. )
  143. </insert>
  144. <!-- 删除月度报告-->
  145. <delete id="delMonthlyReport" parameterType="pd">
  146. delete from
  147. <include refid="listTableName"></include>
  148. where
  149. COMPANY_ID = #{COMPANY_ID}
  150. AND YEAR = #{YEAR}
  151. </delete>
  152. <!-- 删除月度月度完成情况-->
  153. <delete id="delMonthlyCompletion" parameterType="pd">
  154. delete from
  155. <include refid="tableName"></include>
  156. where
  157. COMPANY_ID = #{COMPANY_ID}
  158. AND YEAR = #{YEAR}
  159. </delete>
  160. <!-- 通过月报表相关数据 -->
  161. <select id="getReportInfo" parameterType="pd" resultType="pd">
  162. select * from(
  163. select
  164. @f:= case when @ROAD_ID2=c.ROAD_ID then '0' else '1' end flag,
  165. @ROAD_ID2:=c.ROAD_ID1 ROAD_ID2,
  166. c.*,cast(num as char)numstr
  167. from(
  168. SELECT
  169. @r:= case when @ROAD_ID=a.ROAD_ID then @r+1 else 1 end num,
  170. @ROAD_ID:=a.ROAD_ID ROAD_ID1,
  171. a.*
  172. from(
  173. select h.COMPANY_ID,h.COMPANY,h.ROAD_ID,h.ROAD,h.YEAR,h.PROJECT_NAME,
  174. h.CATEGORY,h.CONTENT,h.YEAR_COST as PROJECT_COST,IFNULL(h.AUDIT_FEE,h.YEAR_COST) as AUDIT_FEE,
  175. h.MATTER_YEAR,h.MATTER_NEW_CARRY,h.MATTER_CONSULT,
  176. h.AUDIT_MAKER,h.XMWCQKSM as ACTUAL_QUANTITIES,
  177. m.ACTUAL_COST_1,m.PAY_COST_1,m.RATIO_1,m.ACTUAL_COST_2,m.PAY_COST_2,m.RATIO_2,m.ACTUAL_COST_3,m.PAY_COST_3,m.RATIO_3,
  178. m.ACTUAL_COST_4,m.PAY_COST_4,m.RATIO_4,m.ACTUAL_COST_5,m.PAY_COST_5,m.RATIO_5,m.ACTUAL_COST_6,m.PAY_COST_6,m.RATIO_6,
  179. m.ACTUAL_COST_7,m.PAY_COST_7,m.RATIO_7,m.ACTUAL_COST_8,m.PAY_COST_8,m.RATIO_8,m.ACTUAL_COST_9,m.PAY_COST_9,m.RATIO_9,
  180. m.ACTUAL_COST_10,m.PAY_COST_10,m.RATIO_10,m.ACTUAL_COST_11,m.PAY_COST_11,m.RATIO_11,m.ACTUAL_COST_12,m.PAY_COST_12,m.RATIO_12
  181. from ${subtable} h
  182. left join (
  183. select yb.COMPANY_ID,yb.ROAD_ID,yb.YEAR,yb.PROJECT_NAME
  184. ,max(ACTUAL_COST_1) as ACTUAL_COST_1,max(PAY_COST_1) as PAY_COST_1,max(RATIO_1) as RATIO_1
  185. ,max(ACTUAL_COST_2) as ACTUAL_COST_2,max(PAY_COST_2) as PAY_COST_2,max(RATIO_2) as RATIO_2
  186. ,max(ACTUAL_COST_3) as ACTUAL_COST_3,max(PAY_COST_3) as PAY_COST_3,max(RATIO_3) as RATIO_3
  187. ,max(ACTUAL_COST_4) as ACTUAL_COST_4,max(PAY_COST_4) as PAY_COST_4,max(RATIO_4) as RATIO_4
  188. ,max(ACTUAL_COST_5) as ACTUAL_COST_5,max(PAY_COST_5) as PAY_COST_5,max(RATIO_5) as RATIO_5
  189. ,max(ACTUAL_COST_6) as ACTUAL_COST_6,max(PAY_COST_6) as PAY_COST_6,max(RATIO_6) as RATIO_6
  190. ,max(ACTUAL_COST_7) as ACTUAL_COST_7,max(PAY_COST_7) as PAY_COST_7,max(RATIO_7) as RATIO_7
  191. ,max(ACTUAL_COST_8) as ACTUAL_COST_8,max(PAY_COST_8) as PAY_COST_8,max(RATIO_8) as RATIO_8
  192. ,max(ACTUAL_COST_9) as ACTUAL_COST_9,max(PAY_COST_9) as PAY_COST_9,max(RATIO_9) as RATIO_9
  193. ,max(ACTUAL_COST_10) as ACTUAL_COST_10,max(PAY_COST_10) as PAY_COST_10,max(RATIO_10) as RATIO_10
  194. ,max(ACTUAL_COST_11) as ACTUAL_COST_11,max(PAY_COST_11) as PAY_COST_11,max(RATIO_11) as RATIO_11
  195. ,max(ACTUAL_COST_12) as ACTUAL_COST_12,max(PAY_COST_12) as PAY_COST_12,max(RATIO_12) as RATIO_12
  196. from(
  197. select *
  198. ,case when month=1 then ACTUAL_COST else null end ACTUAL_COST_1
  199. ,case when month=1 then PAY_COST else null end PAY_COST_1
  200. ,case when month=1 then RATIO else null end RATIO_1
  201. ,case when month=2 then ACTUAL_COST else null end ACTUAL_COST_2
  202. ,case when month=2 then PAY_COST else null end PAY_COST_2
  203. ,case when month=2 then RATIO else null end RATIO_2
  204. ,case when month=3 then ACTUAL_COST else null end ACTUAL_COST_3
  205. ,case when month=3 then PAY_COST else null end PAY_COST_3
  206. ,case when month=3 then RATIO else null end RATIO_3
  207. ,case when month=4 then ACTUAL_COST else null end ACTUAL_COST_4
  208. ,case when month=4 then PAY_COST else null end PAY_COST_4
  209. ,case when month=4 then RATIO else null end RATIO_4
  210. ,case when month=5 then ACTUAL_COST else null end ACTUAL_COST_5
  211. ,case when month=5 then PAY_COST else null end PAY_COST_5
  212. ,case when month=5 then RATIO else null end RATIO_5
  213. ,case when month=6 then ACTUAL_COST else null end ACTUAL_COST_6
  214. ,case when month=6 then PAY_COST else null end PAY_COST_6
  215. ,case when month=6 then RATIO else null end RATIO_6
  216. ,case when month=7 then ACTUAL_COST else null end ACTUAL_COST_7
  217. ,case when month=7 then PAY_COST else null end PAY_COST_7
  218. ,case when month=7 then RATIO else null end RATIO_7
  219. ,case when month=8 then ACTUAL_COST else null end ACTUAL_COST_8
  220. ,case when month=8 then PAY_COST else null end PAY_COST_8
  221. ,case when month=8 then RATIO else null end RATIO_8
  222. ,case when month=9 then ACTUAL_COST else null end ACTUAL_COST_9
  223. ,case when month=9 then PAY_COST else null end PAY_COST_9
  224. ,case when month=9 then RATIO else null end RATIO_9
  225. ,case when month=10 then ACTUAL_COST else null end ACTUAL_COST_10
  226. ,case when month=10 then PAY_COST else null end PAY_COST_10
  227. ,case when month=10 then RATIO else null end RATIO_10
  228. ,case when month=11 then ACTUAL_COST else null end ACTUAL_COST_11
  229. ,case when month=11 then PAY_COST else null end PAY_COST_11
  230. ,case when month=11 then RATIO else null end RATIO_11
  231. ,case when month=12 then ACTUAL_COST else null end ACTUAL_COST_12
  232. ,case when month=12 then PAY_COST else null end PAY_COST_12
  233. ,case when month=12 then RATIO else null end RATIO_12
  234. from ${TABLETYPE}
  235. where YEAR = #{YEAR} and COMPANY_ID = #{COMPANY_ID}
  236. <if test="ROADS!= null and ROADS != ''">
  237. AND ROAD IN
  238. <foreach collection="ROADS" item="ROADS" index="index"
  239. open="(" close=")" separator=",">
  240. #{ROADS}
  241. </foreach>
  242. </if>
  243. )yb group by yb.YEAR,yb.COMPANY_ID,yb.ROAD_ID,yb.PROJECT_NAME
  244. ) m
  245. on h.YEAR = m.YEAR and h.COMPANY_ID = m.COMPANY_ID and h.PROJECT_NAME = m.PROJECT_NAME
  246. where h.YEAR = #{YEAR} and h.COMPANY_ID = #{COMPANY_ID}
  247. <if test="ROADS!= null and ROADS != ''">
  248. AND ROAD IN
  249. <foreach collection="ROADS" item="ROADS" index="index"
  250. open="(" close=")" separator=",">
  251. #{ROADS}
  252. </foreach>
  253. </if>
  254. )a
  255. ,(select @r:=0 ,@ROAD_ID:='',@c:=1) b
  256. order by COMPANY_ID,ROAD_ID,num desc
  257. )c
  258. ,(select @f:=0,@ROAD_ID2:='') d
  259. )e
  260. order by COMPANY_ID,ROAD_ID,num
  261. </select>
  262. <delete id="deleteMonthRecord" parameterType="pd">
  263. delete from ${TABLETYPE}
  264. where YEAR = #{YEAR} AND COMPANY_ID = #{COMPANY_ID} AND ROAD_ID = #{ROAD_ID} AND PROJECT_NAME = #{PROJECT_NAME}
  265. </delete>
  266. <insert id="insertMonthRecord" parameterType="pd">
  267. insert into ${TABLETYPE}(
  268. COMPANY,COMPANY_ID,ROAD,ROAD_ID,YEAR,PROJECT_NAME,MONTH,ACTUAL_COST,PAY_COST,RATIO,ACTUAL_QUANTITIES
  269. )values(
  270. #{COMPANY}, #{COMPANY_ID}, #{ROAD}, #{ROAD_ID}, #{YEAR}, #{PROJECT_NAME}, #{MONTH}, #{ACTUAL_COST}, #{PAY_COST}, #{RATIO},#{ACTUAL_QUANTITIES}
  271. )
  272. </insert>
  273. <update id="updateWCQKRecord" parameterType="pd">
  274. update ${TABLE_NAME}
  275. set XMWCQKSM=#{SJWCGCL}
  276. where YEAR = #{YEAR} AND COMPANY_ID = #{COMPANY_ID} AND ROAD_ID = #{ROAD_ID} AND PROJECT_NAME = #{PROJECT_NAME}
  277. </update>
  278. </mapper>