ElectRecordDao.xml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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.ourwill.module.house.dao.elect.ElectRecordDao">
  4. <resultMap type="cn.ourwill.module.house.entity.elect.ElectRecord" id="baseMap">
  5. <result column="id" property="id"/>
  6. <result column="grain_id" property="grainId"/>
  7. <result column="house_id" property="houseId"/>
  8. <result column="type" property="type"/>
  9. <result column="elect_name" property="electName"/>
  10. <result column="elect_period" property="electPeriod"/>
  11. <result column="elect_num" property="electNum"/>
  12. <result column="money_num" property="moneyNum"/>
  13. <result column="c_id" property="cId" />
  14. <result column="c_time" property="cTime" />
  15. <result column="u_time" property="uTime" />
  16. <result column="u_id" property="uId" />
  17. <result column="version" property="version"/>
  18. <result column="uuid" property="uuid"/>
  19. <result column="sync_flag" property="syncFlag"/>
  20. </resultMap>
  21. <resultMap id="messageMap" type="cn.ourwill.module.house.entity.elect.ElectMessage">
  22. <result column="id" property="id"/>
  23. <result column="grain_id" property="grainId"/>
  24. <result column="house_id" property="houseId"/>
  25. <result column="elect_name" property="electName"/>
  26. <result column="type" property="type"/>
  27. <result column="c_id" property="cId" />
  28. <result column="c_time" property="cTime" />
  29. <result column="u_time" property="uTime" />
  30. <result column="u_id" property="uId" />
  31. <result column="err_count" property="errCount"/>
  32. <result column="err_state" property="errState"/>
  33. </resultMap>
  34. <sql id="columns">
  35. id,
  36. grain_id,
  37. house_id,
  38. `type`,
  39. elect_name,
  40. elect_period,
  41. elect_num,
  42. money_num,
  43. sync_flag,
  44. c_id,
  45. c_time,
  46. u_time,
  47. u_id,
  48. version,
  49. uuid,
  50. sync_flag
  51. </sql>
  52. <sql id="joinCols">
  53. </sql>
  54. <insert id="saveRecordTemp" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  55. parameterType="cn.ourwill.module.house.entity.elect.ElectRecord">
  56. INSERT INTO elect_record_day
  57. <trim prefix="(" suffix=")" suffixOverrides=",">
  58. <if test=" id != null">
  59. id,
  60. </if>
  61. <if test=" grainId != null">
  62. grain_id,
  63. </if>
  64. <if test=" houseId != null and houseId != ''">
  65. house_id,
  66. </if>
  67. <if test=" type != null">
  68. `type`,
  69. </if>
  70. <if test="electName !=null">
  71. elect_name,
  72. </if>
  73. <if test="electPeriod !=null">
  74. elect_period,
  75. </if>
  76. <if test="electNum !=null">
  77. elect_num,
  78. </if>
  79. <if test="moneyNum !=null">
  80. money_num,
  81. </if>
  82. <if test="uuid !=null">
  83. uuid,
  84. </if>
  85. <if test="syncFlag !=null">
  86. sync_flag,
  87. </if>
  88. <if test=" cTime != null">
  89. c_time,
  90. </if>
  91. <if test=" cId != null">
  92. c_id,
  93. </if>
  94. <if test=" uTime != null">
  95. u_time,
  96. </if>
  97. <if test=" uId != null">
  98. u_id,
  99. </if>
  100. <if test=" version != null">
  101. version
  102. </if>
  103. </trim>
  104. <trim prefix="values (" suffix=")" suffixOverrides=",">
  105. <if test=" id != null">
  106. #{id},
  107. </if>
  108. <if test=" grainId != null">
  109. #{grainId},
  110. </if>
  111. <if test=" houseId != null and houseId != ''">
  112. #{houseId},
  113. </if>
  114. <if test=" type != null">
  115. #{type},
  116. </if>
  117. <if test="electName !=null">
  118. #{electName},
  119. </if>
  120. <if test="electPeriod !=null">
  121. #{electPeriod},
  122. </if>
  123. <if test="electNum !=null">
  124. #{electNum},
  125. </if>
  126. <if test="moneyNum !=null">
  127. #{moneyNum},
  128. </if>
  129. <if test="uuid !=null">
  130. #{uuid},
  131. </if>
  132. <if test="syncFlag !=null">
  133. #{syncFlag},
  134. </if>
  135. <if test=" cTime != null">
  136. #{cTime},
  137. </if>
  138. <if test=" cId != null">
  139. #{cId},
  140. </if>
  141. <if test=" uTime != null">
  142. #{uTime},
  143. </if>
  144. <if test=" uId != null">
  145. #{uId},
  146. </if>
  147. <if test=" version != null">
  148. #{version}
  149. </if>
  150. </trim>
  151. </insert>
  152. <insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  153. parameterType="cn.ourwill.module.house.entity.elect.ElectRecord">
  154. INSERT INTO elect_record
  155. <trim prefix="(" suffix=")" suffixOverrides=",">
  156. <if test=" grainId != null">
  157. grain_id,
  158. </if>
  159. <if test=" houseId != null and houseId != ''">
  160. house_id,
  161. </if>
  162. <if test=" type != null">
  163. `type`,
  164. </if>
  165. <if test="electName !=null">
  166. elect_name,
  167. </if>
  168. <if test="electPeriod !=null">
  169. elect_period,
  170. </if>
  171. <if test="electNum !=null">
  172. elect_num,
  173. </if>
  174. <if test="moneyNum !=null">
  175. money_num,
  176. </if>
  177. <if test="uuid !=null">
  178. uuid,
  179. </if>
  180. <if test="syncFlag !=null">
  181. sync_flag,
  182. </if>
  183. <if test=" cTime != null">
  184. c_time,
  185. </if>
  186. <if test=" cId != null">
  187. c_id,
  188. </if>
  189. <if test=" uTime != null">
  190. u_time,
  191. </if>
  192. <if test=" uId != null">
  193. u_id,
  194. </if>
  195. <if test=" version != null">
  196. version
  197. </if>
  198. </trim>
  199. <trim prefix="values (" suffix=")" suffixOverrides=",">
  200. <if test=" grainId != null">
  201. #{grainId},
  202. </if>
  203. <if test=" houseId != null and houseId != ''">
  204. #{houseId},
  205. </if>
  206. <if test=" type != null">
  207. #{type},
  208. </if>
  209. <if test="electName !=null">
  210. #{electName},
  211. </if>
  212. <if test="electPeriod !=null">
  213. #{electPeriod},
  214. </if>
  215. <if test="electNum !=null">
  216. #{electNum},
  217. </if>
  218. <if test="moneyNum !=null">
  219. #{moneyNum},
  220. </if>
  221. <if test="uuid !=null">
  222. #{uuid},
  223. </if>
  224. <if test="syncFlag !=null">
  225. #{syncFlag},
  226. </if>
  227. <if test=" cTime != null">
  228. #{cTime},
  229. </if>
  230. <if test=" cId != null">
  231. #{cId},
  232. </if>
  233. <if test=" uTime != null">
  234. #{uTime},
  235. </if>
  236. <if test=" uId != null">
  237. #{uId},
  238. </if>
  239. <if test=" version != null">
  240. #{version}
  241. </if>
  242. </trim>
  243. </insert>
  244. <select id="getByDistinctElectNameTemp" resultMap="baseMap" >
  245. SELECT
  246. DISTINCT a.elect_name,a.house_id,a.grain_id,a.`type`,a.elect_num
  247. FROM
  248. elect_record_day a
  249. <where>
  250. <if test="grainList !=null">
  251. and a.grain_id in
  252. <foreach item="item" index="index" collection="grainList" open="(" separator="," close=")">
  253. #{item}
  254. </foreach>
  255. </if>
  256. <if test="type !=null">
  257. and a.`type` = #{type}
  258. </if>
  259. <if test="electName !=null">
  260. and a.elect_name like CONCAT('%',#{electName},'%')
  261. </if>
  262. </where>
  263. GROUP BY a.elect_name
  264. <choose>
  265. <when test="page !=null and page.count != null and page.orderBy != null and page.orderBy != ''">
  266. ORDER BY ${page.orderBy}
  267. </when>
  268. <otherwise>
  269. </otherwise>
  270. </choose>
  271. </select>
  272. <select id="getByDistinctElectName" resultMap="baseMap" >
  273. SELECT
  274. DISTINCT a.elect_name,a.house_id,a.grain_id,a.`type`,a.elect_num
  275. FROM
  276. elect_record a
  277. <where>
  278. <if test="grainList !=null">
  279. and a.grain_id in
  280. <foreach item="item" index="index" collection="grainList" open="(" separator="," close=")">
  281. #{item}
  282. </foreach>
  283. </if>
  284. <if test="houseList !=null">
  285. and a.house_id <!--in
  286. <foreach item="items" index="index" collection="houseList" open="(" separator="," close=")">
  287. #{items}
  288. </foreach>-->
  289. </if>
  290. <if test="type !=null">
  291. and a.`type` = #{type}
  292. </if>
  293. <if test="electName !=null">
  294. and a.elect_name like CONCAT('%',#{electName},'%')
  295. </if>
  296. <if test="grainId !=null">
  297. and a.grain_id =#{grainId}
  298. </if>
  299. </where>
  300. GROUP BY a.elect_name
  301. <choose>
  302. <when test="page !=null and page.count != null and page.orderBy != null and page.orderBy != ''">
  303. ORDER BY ${page.orderBy}
  304. </when>
  305. <otherwise>
  306. </otherwise>
  307. </choose>
  308. </select>
  309. <select id="getByDistinctElects" resultMap="baseMap" >
  310. SELECT
  311. DISTINCT a.elect_name,a.house_id,a.grain_id,a.`type`,a.elect_num
  312. FROM
  313. elect_record_day a
  314. <where>
  315. <if test="grainList !=null">
  316. and a.grain_id in
  317. <foreach item="item" index="index" collection="grainList" open="(" separator="," close=")">
  318. #{item}
  319. </foreach>
  320. </if>
  321. <if test="houseList !=null">
  322. and a.house_id in
  323. <foreach item="items" index="index" collection="houseList" open="(" separator="," close=")">
  324. #{items}
  325. </foreach>
  326. </if>
  327. <if test="type !=null">
  328. and a.`type` = #{type}
  329. </if>
  330. <if test="electName !=null">
  331. and a.elect_name like CONCAT('%',#{electName},'%')
  332. </if>
  333. <!-- <if test="electPeriod !=null">
  334. and a.elect_period like CONCAT('%',#{electPeriod},'%')
  335. </if>-->
  336. </where>
  337. GROUP BY a.elect_name
  338. <choose>
  339. <when test="page !=null and page.count != null and page.orderBy != null and page.orderBy != ''">
  340. ORDER BY ${page.orderBy}
  341. </when>
  342. <otherwise>
  343. </otherwise>
  344. </choose>
  345. </select>
  346. <select id="getListBySearchDate" resultMap="baseMap" >
  347. SELECT
  348. DISTINCT a.elect_name,a.house_id,a.grain_id,a.`type`
  349. FROM
  350. elect_record_day a
  351. <where>
  352. <if test="grainList !=null">
  353. and a.grain_id in
  354. <foreach item="item" index="index" collection="grainList" open="(" separator="," close=")">
  355. #{item}
  356. </foreach>
  357. </if>
  358. <if test="type !=null">
  359. and a.`type` = #{type}
  360. </if>
  361. <if test="searchStartDate !=null">
  362. and a.elect_period <![CDATA[ >= ]]> #{searchStartDate}
  363. </if>
  364. <if test="searchEndDate !=null">
  365. and a.elect_period &lt;= #{searchEndDate}
  366. </if>
  367. </where>
  368. GROUP BY a.elect_name
  369. <choose>
  370. <when test="page !=null and page.count != null and page.orderBy != null and page.orderBy != ''">
  371. ORDER BY ${page.orderBy}
  372. </when>
  373. <otherwise>
  374. </otherwise>
  375. </choose>
  376. </select>
  377. <select id="getMonthElectPay" resultType="java.lang.Double" parameterType="java.lang.String" >
  378. SELECT
  379. sum(money_num) money_nums
  380. FROM
  381. elect_record_day
  382. <where>
  383. <if test="grainId !=null">
  384. and grain_id = #{grainId}
  385. </if>
  386. <if test="electName !=null">
  387. and elect_name like CONCAT('%',#{electName},'%')
  388. </if>
  389. <if test="electPeriod !=null">
  390. and elect_period like CONCAT('%',#{electPeriod},'%')
  391. </if>
  392. </where>
  393. GROUP BY elect_name
  394. </select>
  395. <select id="getSearchDateElectPay" resultType="java.lang.Double" parameterType="java.lang.String" >
  396. SELECT
  397. sum(money_num) money_nums
  398. FROM
  399. elect_record_day
  400. <where>
  401. <if test="grainId !=null">
  402. and grain_id = #{grainId}
  403. </if>
  404. <if test="electName !=null">
  405. and elect_name like CONCAT('%',#{electName},'%')
  406. </if>
  407. <if test="searchStartDate !=null and searchStartDate != ''">
  408. and elect_period <![CDATA[ >= ]]> #{searchStartDate}
  409. </if>
  410. <if test="searchEndDate !=null and searchEndDate != ''">
  411. and elect_period &lt;= #{searchEndDate}
  412. </if>
  413. </where>
  414. GROUP BY elect_name
  415. </select>
  416. <select id="getMonthElect" resultType="java.lang.Double" parameterType="java.lang.String" >
  417. SELECT
  418. elect_num
  419. FROM
  420. elect_record_day
  421. <where>
  422. <if test="grainId !=null">
  423. and grain_id = #{grainId}
  424. </if>
  425. <if test="electName !=null">
  426. and elect_name like CONCAT('%',#{electName},'%')
  427. </if>
  428. <if test="electPeriod !=null">
  429. and elect_period like CONCAT('%',#{electPeriod},'%')
  430. </if>
  431. </where>
  432. order by elect_period
  433. </select>
  434. <select id="getMonthList" resultMap="baseMap">
  435. SELECT
  436. *
  437. FROM
  438. elect_record_day
  439. <where>
  440. <if test="grainId !=null">
  441. and grain_id = #{grainId}
  442. </if>
  443. <if test="electName !=null">
  444. and elect_name like CONCAT('%',#{electName},'%')
  445. </if>
  446. <if test="electPeriod !=null">
  447. and elect_period like CONCAT('%',#{electPeriod},'%')
  448. </if>
  449. </where>
  450. order by elect_period
  451. </select>
  452. <select id="getElectPeriodList" resultMap="baseMap" >
  453. SELECT
  454. elect_period,elect_num
  455. FROM
  456. elect_record
  457. <where>
  458. <if test="grainId !=null">
  459. and grain_id = #{grainId}
  460. </if>
  461. <if test="type !=null">
  462. and `type` = #{type}
  463. </if>
  464. <if test="electName !=null">
  465. and elect_name like CONCAT('%',#{electName},'%')
  466. </if>
  467. <if test="electPeriod !=null">
  468. and elect_period like CONCAT('%',#{electPeriod},'%')
  469. </if>
  470. </where>
  471. ORDER BY elect_period asc
  472. </select>
  473. <select id="getElectPeriods" resultMap="baseMap" >
  474. SELECT
  475. elect_period,elect_num
  476. FROM
  477. elect_record_day
  478. <where>
  479. <if test="grainId !=null">
  480. and grain_id = #{grainId}
  481. </if>
  482. <if test="type !=null">
  483. and `type` = #{type}
  484. </if>
  485. <if test="electName !=null">
  486. and elect_name like CONCAT('%',#{electName},'%')
  487. </if>
  488. <if test="electPeriod !=null">
  489. and elect_period like CONCAT('%',#{electPeriod},'%')
  490. </if>
  491. </where>
  492. ORDER BY elect_period asc
  493. </select>
  494. <select id="getElectSearchDateList" resultMap="baseMap" >
  495. SELECT
  496. elect_period,elect_num
  497. FROM
  498. elect_record
  499. <where>
  500. <if test="grainId !=null">
  501. and grain_id = #{grainId}
  502. </if>
  503. <if test="type !=null">
  504. and `type` = #{type}
  505. </if>
  506. <if test="electName !=null">
  507. and elect_name like CONCAT('%',#{electName},'%')
  508. </if>
  509. <if test="searchStartDate !=null and searchStartDate != ''">
  510. and elect_period <![CDATA[ >= ]]> #{searchStartDate}
  511. </if>
  512. <if test="searchEndDate !=null and searchEndDate != ''">
  513. and elect_period &lt;= #{searchEndDate}
  514. </if>
  515. </where>
  516. ORDER BY elect_period asc
  517. </select>
  518. <select id="getElectSearchDateLists" resultMap="baseMap" >
  519. SELECT
  520. elect_period,elect_num
  521. FROM
  522. elect_record_day
  523. <where>
  524. <if test="grainId !=null">
  525. and grain_id = #{grainId}
  526. </if>
  527. <if test="type !=null">
  528. and `type` = #{type}
  529. </if>
  530. <if test="electName !=null">
  531. and elect_name like CONCAT('%',#{electName},'%')
  532. </if>
  533. <if test="searchStartDate !=null and searchStartDate != ''">
  534. and elect_period <![CDATA[ >= ]]> #{searchStartDate}
  535. </if>
  536. <if test="searchEndDate !=null and searchEndDate != ''">
  537. and elect_period &lt;= #{searchEndDate}
  538. </if>
  539. </where>
  540. ORDER BY elect_period asc
  541. </select>
  542. <select id="getEveryoneMonthChartBudget" resultMap="baseMap" >
  543. SELECT
  544. elect_period,elect_num
  545. FROM
  546. elect_record_day
  547. <where>
  548. <if test="grainId !=null">
  549. and grain_id = #{grainId}
  550. </if>
  551. <if test="electName !=null">
  552. and elect_name = #{electName}
  553. </if>
  554. <if test="electPeriod !=null and electPeriod != ''">
  555. and elect_period like CONCAT('%',#{electPeriod},'%')
  556. </if>
  557. </where>
  558. ORDER BY elect_period asc
  559. </select>
  560. <delete id="deleteAll">
  561. DELETE FROM elect_record where id not in (select a.id from (select MAX(id) id from elect_record GROUP BY elect_name) a)
  562. </delete>
  563. <update id="updateVersion">
  564. UPDATE elect_record SET sync_flag='1'
  565. </update>
  566. <!-- 智能电表消息提醒表操作-start-->
  567. <select id="getMessageList" resultMap="messageMap">
  568. SELECT * FROM elect_message WHERE err_count>3
  569. <if test="grainId !=null and grainId != ''">
  570. and grain_id = #{grainId}
  571. </if>
  572. <if test="houseList !=null">
  573. and house_id in
  574. <foreach item="item" index="index" collection="houseList" open="(" separator="," close=")">
  575. #{item}
  576. </foreach>
  577. </if>
  578. </select>
  579. <select id="getAllMessageList" resultMap="messageMap">
  580. SELECT elect_name,id,err_count FROM elect_message
  581. </select>
  582. <select id="getElectMessageByName" resultMap="messageMap">
  583. SELECT * FROM elect_message where elect_name=#{electName}
  584. </select>
  585. <select id="getElectName" resultType="cn.ourwill.module.house.entity.elect.ElectRecord">
  586. SELECT DISTINCT elect_name FROM elect_record_day
  587. </select>
  588. <insert id="saveElectMessage" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  589. parameterType="cn.ourwill.module.house.entity.elect.ElectMessage">
  590. INSERT INTO elect_message
  591. <trim prefix="(" suffix=")" suffixOverrides=",">
  592. <if test=" grainId != null">
  593. grain_id,
  594. </if>
  595. <if test=" houseId != null and houseId != ''">
  596. house_id,
  597. </if>
  598. <if test=" type != null">
  599. `type`,
  600. </if>
  601. <if test="electName !=null">
  602. elect_name,
  603. </if>
  604. <if test="errCount !=null">
  605. err_count,
  606. </if>
  607. <if test="errState !=null">
  608. err_state,
  609. </if>
  610. <if test="uuid !=null">
  611. uuid,
  612. </if>
  613. <if test=" cTime != null">
  614. c_time,
  615. </if>
  616. <if test=" cId != null">
  617. c_id,
  618. </if>
  619. <if test=" uTime != null">
  620. u_time,
  621. </if>
  622. <if test=" uId != null">
  623. u_id
  624. </if>
  625. </trim>
  626. <trim prefix="values (" suffix=")" suffixOverrides=",">
  627. <if test=" grainId != null">
  628. #{grainId},
  629. </if>
  630. <if test=" houseId != null and houseId != ''">
  631. #{houseId},
  632. </if>
  633. <if test=" type != null">
  634. #{type},
  635. </if>
  636. <if test="electName !=null">
  637. #{electName},
  638. </if>
  639. <if test="errCount !=null">
  640. #{errCount},
  641. </if>
  642. <if test="errState !=null">
  643. #{errState},
  644. </if>
  645. <if test="uuid !=null">
  646. #{uuid},
  647. </if>
  648. <if test=" cTime != null">
  649. #{cTime},
  650. </if>
  651. <if test=" cId != null">
  652. #{cId},
  653. </if>
  654. <if test=" uTime != null">
  655. #{uTime},
  656. </if>
  657. <if test=" uId != null">
  658. #{uId}
  659. </if>
  660. </trim>
  661. </insert>
  662. <update id="updateElectMessage">
  663. UPDATE elect_message SET err_count =#{errCount} where elect_name=#{electName}
  664. </update>
  665. <update id="updateByElectName">
  666. UPDATE elect_record SET house_id =#{houseId} where elect_name=#{electName}
  667. </update>
  668. <update id="updateByElectNameDay">
  669. UPDATE elect_record_day SET house_id =#{houseId} where elect_name=#{electName}
  670. </update>
  671. <delete id="deleteByName">
  672. DELETE FROM elect_message where elect_name=#{electName}
  673. </delete>
  674. <!-- 智能电表消息提醒表操作-end-->
  675. </mapper>