DailyRecordInoutputDao.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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.daily.DailyRecordInoutputDao">
  4. <resultMap type="cn.ourwill.module.house.entity.daily.DailyRecordInoutput" id="baseMap">
  5. <result column="id" property="id"/>
  6. <result column="uuid" property="uuid"/>
  7. <result column="house_id" property="houseId"/>
  8. <result column="c_id" property="cId"/>
  9. <result column="c_time" property="cTime"/>
  10. <result column="u_id" property="uId"/>
  11. <result column="u_time" property="uTime"/>
  12. <result column="version" property="version"/>
  13. <result column="type" property="type"/>
  14. <result column="htype" property="htype"/>
  15. <result column="recorder" property="recorder"/>
  16. <result column="record_date" property="recordDate"/>
  17. <result column="classes" property="classes"/>
  18. <result column="record_num" property="recordNum"/>
  19. <result column="store_num" property="storeNum"/>
  20. <result column="plan_num" property="planNum"/>
  21. <result column="details" property="details"/>
  22. <result column="plan_scale" property="planScale"/>
  23. <result column="checker" property="checker"/>
  24. </resultMap>
  25. <sql id="dailyRecordInoutputColumns">
  26. id ,
  27. `type`,
  28. htype,
  29. recorder ,
  30. record_date ,
  31. `classes` ,
  32. record_num ,
  33. store_num ,
  34. plan_num ,
  35. details ,
  36. house_id,
  37. c_id ,
  38. c_time ,
  39. u_id ,
  40. u_time ,
  41. version,
  42. plan_scale,
  43. checker
  44. </sql>
  45. <sql id="dailyRecordInoutputJoins">
  46. </sql>
  47. <select id="get" resultMap="baseMap">
  48. SELECT
  49. <include refid="dailyRecordInoutputColumns"/>
  50. FROM daily_record_inoutput a
  51. <include refid="dailyRecordInoutputJoins"/>
  52. WHERE a.id = #{id}
  53. </select>
  54. <select id="getByUuid" resultMap="baseMap">
  55. SELECT
  56. <include refid="dailyRecordInoutputColumns"/>
  57. FROM daily_record_inoutput a
  58. <include refid="dailyRecordInoutputJoins"/>
  59. WHERE a.uuid = #{uuid}
  60. </select>
  61. <select id="findPlanNumList" resultMap="baseMap">
  62. SELECT distinct
  63. dri.plan_num
  64. FROM daily_record_inoutput dri
  65. left join house_info hou on dri.house_id = hou.id
  66. left join sys_grain gra on hou.grain_id = gra.id
  67. <where>
  68. <if test="grainId !=null and grainId !=''">
  69. and gra.id = #{grainId}
  70. </if>
  71. <if test="planNum !=null and planNum !=''">
  72. and dri.plan_num like '%${planNum}%'
  73. </if>
  74. </where>
  75. </select>
  76. <select id="findList" resultMap="baseMap">
  77. SELECT
  78. <include refid="dailyRecordInoutputColumns"/>
  79. FROM daily_record_inoutput a
  80. <include refid="dailyRecordInoutputJoins"/>
  81. <where>
  82. <if test="id !=null">
  83. and id = #{id}
  84. </if>
  85. <if test="type !=null">
  86. and `type` = #{type}
  87. </if>
  88. <if test="htype !=null">
  89. and `htype` = #{htype}
  90. </if>
  91. <if test="searchStartDate !=null">
  92. and record_date &gt;= #{searchStartDate}
  93. </if>
  94. <if test="searchEndDate !=null">
  95. and record_date &lt;= #{searchEndDate}
  96. </if>
  97. <if test="houseId !=null">
  98. and house_id = #{houseId}
  99. </if>
  100. <if test="checker !=null">
  101. and checker = #{checker}
  102. </if>
  103. <if test="cId !=null">
  104. and c_id = #{cId}
  105. </if>
  106. <if test="cTime !=null">
  107. and c_time = #{cTime}
  108. </if>
  109. <if test="uId !=null">
  110. and u_id = #{uId}
  111. </if>
  112. <if test="uTime !=null">
  113. and u_time = #{uTime}
  114. </if>
  115. <if test="version !=null">
  116. and version = #{version}
  117. </if>
  118. </where>
  119. <choose>
  120. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  121. ORDER BY ${page.orderBy}
  122. </when>
  123. <otherwise>
  124. order by id desc
  125. </otherwise>
  126. </choose>
  127. </select>
  128. <select id="findAllList" resultMap="baseMap">
  129. SELECT
  130. <include refid="dailyRecordInoutputColumns"/>
  131. FROM daily_record_inoutput a
  132. <include refid="dailyRecordInoutputJoins"/>
  133. <where>
  134. <if test="id !=null">
  135. and id = #{id}
  136. </if>
  137. <if test="type !=null">
  138. and `type` = #{type}
  139. </if>
  140. <if test="htype !=null">
  141. and `htype` = #{htype}
  142. </if>
  143. <if test="searchStartDate !=null">
  144. and record_date <![CDATA[ >= ]]> '#{searchStartDate}'
  145. </if>
  146. <if test="searchEndDate !=null">
  147. and record_date &lt;= '#{searchEndDate}'
  148. </if>
  149. <if test="houseId !=null">
  150. and house_id = #{houseId}
  151. </if>
  152. <if test="checker !=null">
  153. and checker = #{checker}
  154. </if>
  155. <if test="cId !=null">
  156. and c_id = #{cId}
  157. </if>
  158. <if test="cTime !=null">
  159. and c_time = #{cTime}
  160. </if>
  161. <if test="uId !=null">
  162. and u_id = #{uId}
  163. </if>
  164. <if test="uTime !=null">
  165. and u_time = #{uTime}
  166. </if>
  167. <if test="version !=null">
  168. and version = #{version}
  169. </if>
  170. </where>
  171. <choose>
  172. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  173. ORDER BY ${page.orderBy}
  174. </when>
  175. <otherwise>
  176. order by id desc
  177. </otherwise>
  178. </choose>
  179. </select>
  180. <!--轮换统计分析所用字段-->
  181. <resultMap id="statisticPlanUsed" type="cn.ourwill.module.house.entity.daily.DailyRecordInoutput" extends="baseMap">
  182. <result column="grainName" property="grainName"/>
  183. <result column="planName" property="planName"/>
  184. <result column="planScale" property="planScale"/>
  185. <result column="number" property="number"/>
  186. <result column="inputCount" property="inputCount"/>
  187. <result column="outputCount" property="outputCount"/>
  188. <result column="houseNames" property="houseNames"/>
  189. <result column="input_time" property="inputTime"/>
  190. <result column="first_check_time" property="firstCheckTime"/>
  191. <result column="apply_check_time" property="applyCheckTime"/>
  192. <result column="check_time" property="checkTime"/>
  193. <result column="check_result" property="checkResult"/>
  194. </resultMap>
  195. <select id="findStaticOfInoutputByHouse" resultMap="statisticPlanUsed">
  196. select gra.`name` as grainName,
  197. dri.plan_num as planName,
  198. dri.plan_scale as planScale,
  199. hou.house_name as houseNames,
  200. drq.number as number,
  201. sum(case when dri.type = 0 then dri.record_num else 0 END) as outputCount,
  202. sum(case when dri.type = 1 then dri.record_num else 0 end) as inputCount,
  203. drq.input_time as input_time,
  204. drq.check_time as first_check_time,
  205. drq.apply_check_time as apply_check_time,
  206. drqa.check_time as check_time,
  207. drqa.check_result as check_result
  208. from daily_record_inoutput dri
  209. left join house_info hou on dri.house_id = hou.id
  210. left join sys_grain gra on hou.grain_id = gra.id
  211. left join daily_record_qualitycheck drq
  212. on drq.id = (select id from daily_record_qualitycheck where house_id = dri.house_id and type = '0' order by check_time desc limit 1)
  213. left join daily_record_qualitycheck drqa
  214. on drqa.id = (select id from daily_record_qualitycheck where house_id = dri.house_id and type = '1' order by check_time desc limit 1)
  215. where gra.`name` is not null
  216. <if test="grainId!=null and grainId!=''">
  217. and gra.id = #{grainId}
  218. </if>
  219. <if test="cityId!=null and cityId!=''">
  220. and gra.parentId = #{cityId}
  221. </if>
  222. <if test="searchDateStart !=null and searchDateStart!=''">
  223. and dri.record_date &gt;= str_to_date(#{searchDateStart},'%Y-%m-%d')
  224. </if>
  225. <if test="searchDateEnd !=null and searchDateEnd!=''">
  226. and dri.record_date &lt;str_to_date(#{searchDateEnd},'%Y-%m-%d')
  227. </if>
  228. group by gra.`name`,hou.house_name,dri.plan_num
  229. order by gra.id,dri.plan_num,CONCAT(GetNum(hou.house_name),hou.house_name)+0 asc
  230. </select>
  231. <select id="findStaticOfInoutputByGrain" resultMap="statisticPlanUsed">
  232. select gra.`name` as grainName,
  233. dri.plan_num as planName,
  234. dri.plan_scale as planScale,
  235. sum(case when dri.type = 0 then dri.record_num else 0 END) as outputCount,
  236. sum(case when dri.type = 1 then dri.record_num else 0 end) as inputCount
  237. from daily_record_inoutput dri
  238. left join house_info hou on dri.house_id = hou.id
  239. left join sys_grain gra on hou.grain_id = gra.id
  240. where gra.`name` is not null
  241. <if test="grainId!=null and grainId!=''">
  242. and gra.id = #{grainId}
  243. </if>
  244. <if test="planNum !=null and planNum!=''">
  245. and dri.plan_num = #{planNum}
  246. </if>
  247. group by gra.`name`,dri.plan_num
  248. order by dri.plan_num,CONCAT(GetNum(hou.house_name),hou.house_name)+0 asc
  249. </select>
  250. <insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  251. parameterType="cn.ourwill.module.house.entity.daily.DailyRecordInoutput">
  252. INSERT INTO daily_record_inoutput
  253. <trim prefix="(" suffix=")" suffixOverrides=",">
  254. <if test=" id != null">
  255. id,
  256. </if>
  257. <if test=" uuid != null">
  258. uuid,
  259. </if>
  260. <if test="type != null">
  261. `type`,
  262. </if>
  263. <if test="htype != null">
  264. `htype`,
  265. </if>
  266. <if test=" recorder != null">
  267. recorder,
  268. </if>
  269. <if test=" recordDate != null">
  270. record_date,
  271. </if>
  272. <if test=" classes != null">
  273. classes,
  274. </if>
  275. <if test=" recordNum != null">
  276. record_num,
  277. </if>
  278. <if test=" storeNum != null">
  279. store_num,
  280. </if>
  281. <if test=" planNum != null">
  282. plan_num,
  283. </if>
  284. <if test=" details != null">
  285. details,
  286. </if>
  287. <if test="houseId != null">
  288. house_id,
  289. </if>
  290. <if test="checker !=null">
  291. checker,
  292. </if>
  293. <if test=" cId != null">
  294. c_id,
  295. </if>
  296. <if test=" cTime != null">
  297. c_time,
  298. </if>
  299. <if test=" uId != null">
  300. u_id,
  301. </if>
  302. <if test=" uTime != null">
  303. u_time,
  304. </if>
  305. <if test=" version != null">
  306. version,
  307. </if>
  308. <if test="planScale != null and planScale!=''">
  309. plan_scale
  310. </if>
  311. </trim>
  312. <trim prefix="values (" suffix=")" suffixOverrides=",">
  313. <if test=" id != null">
  314. #{id},
  315. </if>
  316. <if test=" uuid != null">
  317. #{uuid},
  318. </if>
  319. <if test="type != null">
  320. #{type},
  321. </if>
  322. <if test="htype != null">
  323. #{htype},
  324. </if>
  325. <if test=" recorder != null">
  326. #{recorder},
  327. </if>
  328. <if test=" recordDate != null">
  329. #{recordDate},
  330. </if>
  331. <if test=" classes != null">
  332. #{classes},
  333. </if>
  334. <if test=" recordNum != null">
  335. #{recordNum},
  336. </if>
  337. <if test=" storeNum != null">
  338. #{storeNum},
  339. </if>
  340. <if test=" planNum != null">
  341. #{planNum},
  342. </if>
  343. <if test=" details != null">
  344. #{details},
  345. </if>
  346. <if test=" houseId != null">
  347. #{houseId},
  348. </if>
  349. <if test="checker !=null">
  350. #{checker},
  351. </if>
  352. <if test=" cId != null">
  353. #{cId},
  354. </if>
  355. <if test=" cTime != null">
  356. #{cTime},
  357. </if>
  358. <if test=" uId != null">
  359. #{uId},
  360. </if>
  361. <if test=" uTime != null">
  362. #{uTime},
  363. </if>
  364. <if test=" version != null">
  365. #{version},
  366. </if>
  367. <if test="planScale !=null and planScale!=''">
  368. #{planScale}
  369. </if>
  370. </trim>
  371. </insert>
  372. <update id="updateByUuid" parameterType="cn.ourwill.module.house.entity.daily.DailyRecordInoutput">
  373. UPDATE daily_record_inoutput <set>
  374. <if test="uuid != null">
  375. uuid=#{uuid},
  376. </if>
  377. <if test="type != null">
  378. `type` = #{type},
  379. </if>
  380. <if test="htype != null">
  381. `htype` = #{htype},
  382. </if>
  383. <if test="recorder !=null">
  384. recorder = #{recorder},
  385. </if>
  386. <if test="recordDate !=null">
  387. record_date = #{recordDate},
  388. </if>
  389. <if test="classes !=null">
  390. classes = #{classes},
  391. </if>
  392. <if test="recordNum !=null">
  393. record_num = #{recordNum},
  394. </if>
  395. <if test="storeNum !=null">
  396. store_num = #{storeNum},
  397. </if>
  398. <if test="planNum !=null">
  399. plan_num = #{planNum},
  400. </if>
  401. <if test="details !=null">
  402. details = #{details},
  403. </if>
  404. <if test="houseId !=null">
  405. house_id = #{houseId},
  406. </if>
  407. <if test="checker !=null">
  408. checker = #{checker},
  409. </if>
  410. <if test="cId !=null">
  411. c_id = #{cId},
  412. </if>
  413. <if test="cTime !=null">
  414. c_time = #{cTime},
  415. </if>
  416. <if test="uId !=null">
  417. u_id = #{uId},
  418. </if>
  419. <if test="uTime !=null">
  420. u_time = #{uTime},
  421. </if>
  422. <if test="version !=null">
  423. version = #{version},
  424. </if>
  425. <if test="planScale !=null and planScale!=''">
  426. plan_scale = #{planScale},
  427. </if>
  428. <if test="syncFlag !=null">
  429. sync_flag=#{syncFlag}
  430. </if>
  431. </set>
  432. WHERE uuid = #{uuid}
  433. </update>
  434. <update id="update" parameterType="cn.ourwill.module.house.entity.daily.DailyRecordInoutput">
  435. UPDATE daily_record_inoutput
  436. <set>
  437. <if test="type != null">
  438. `type` = #{type},
  439. </if>
  440. <if test="htype != null">
  441. `htype` = #{htype},
  442. </if>
  443. <if test="recorder !=null">
  444. recorder = #{recorder},
  445. </if>
  446. <if test="recordDate !=null">
  447. record_date = #{recordDate},
  448. </if>
  449. <if test="classes !=null">
  450. classes = #{classes},
  451. </if>
  452. <if test="recordNum !=null">
  453. record_num = #{recordNum},
  454. </if>
  455. <if test="storeNum !=null">
  456. store_num = #{storeNum},
  457. </if>
  458. <if test="planNum !=null">
  459. plan_num = #{planNum},
  460. </if>
  461. <if test="details !=null">
  462. details = #{details},
  463. </if>
  464. <if test="houseId !=null">
  465. house_id = #{houseId},
  466. </if>
  467. <if test="checker !=null">
  468. checker = #{checker},
  469. </if>
  470. <if test="cId !=null">
  471. c_id = #{cId},
  472. </if>
  473. <if test="cTime !=null">
  474. c_time = #{cTime},
  475. </if>
  476. <if test="uId !=null">
  477. u_id = #{uId},
  478. </if>
  479. <if test="uTime !=null">
  480. u_time = #{uTime},
  481. </if>
  482. <if test="version !=null">
  483. version = #{version},
  484. </if>
  485. <if test="planScale !=null and planScale!=''">
  486. plan_scale = #{planScale}
  487. </if>
  488. </set>
  489. WHERE id = #{id}
  490. </update>
  491. <update id="updateHistoryRecord" parameterType="cn.ourwill.module.house.entity.daily.DailyRecordInoutput">
  492. UPDATE daily_record_inoutput
  493. <set>
  494. <if test="type != null">
  495. `type` = #{type},
  496. </if>
  497. <if test="htype != null">
  498. `htype` = #{htype},
  499. </if>
  500. <if test="houseId !=null">
  501. house_id = #{houseId},
  502. </if>
  503. <if test="checker !=null">
  504. checker = #{checker},
  505. </if>
  506. <if test="cId !=null">
  507. c_id = #{cId},
  508. </if>
  509. <if test="cTime !=null">
  510. c_time = #{cTime},
  511. </if>
  512. <if test="uId !=null">
  513. u_id = #{uId},
  514. </if>
  515. <if test="uTime !=null">
  516. u_time = #{uTime},
  517. </if>
  518. <if test="version !=null">
  519. version = #{version}
  520. </if>
  521. </set>
  522. WHERE id &lt;= #{id}
  523. </update>
  524. <delete id="deleteById" parameterType="java.lang.Long">
  525. DELETE FROM daily_record_inoutput
  526. WHERE id = #{id}
  527. </delete>
  528. <delete id="deleteByIds" parameterType="java.util.List">
  529. DELETE FROM daily_record_inoutput WHERE id IN
  530. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  531. #{item}
  532. </foreach>
  533. </delete>
  534. <select id="findByHouseIdNoPage" resultMap="baseMap">
  535. SELECT *
  536. FROM daily_record_inoutput a
  537. where house_id=#{houseId}
  538. <if test="cTime != null">
  539. AND record_date <![CDATA[ <= ]]> #{cTime}
  540. </if>
  541. </select>
  542. <delete id="deleteInoutputByHouseId">
  543. DELETE FROM daily_record_inoutput
  544. WHERE house_id = #{houseId}
  545. <if test="cTime != null">
  546. AND record_date <![CDATA[ <= ]]> #{cTime}
  547. </if>
  548. </delete>
  549. <select id="getLastOutYearByHouseId" resultMap="baseMap">
  550. SELECT *
  551. FROM daily_record_inoutput a
  552. where house_id=#{houseId} and type=0
  553. ORDER by a.record_date DESC,a.id DESC
  554. limit 1
  555. </select>
  556. </mapper>