DeviceApplicationDao.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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.DeviceApplicationDao">
  4. <resultMap type="cn.ourwill.module.house.entity.daily.DeviceApplication" 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="uuid" property="uuid"/>
  9. <result column="sync_flag" property="syncFlag"/>
  10. <result column="remark" property="remark"/>
  11. <result column="c_id" property="cId"/>
  12. <result column="c_time" property="cTime"/>
  13. <result column="u_id" property="uId"/>
  14. <result column="u_time" property="uTime"/>
  15. <result column="check_date" property="checkDate"/>
  16. <result column="device_applicationer" property="deviceApplicationer"/>
  17. <result column="application_month" property="applicationMonth"/>
  18. <result column="device_name" property="deviceName"/>
  19. <result column="application_number" property="applicationNumber"/>
  20. <result column="application_state" property="applicationState"/>
  21. <result column="agreed_date" property="agreedDate"/>
  22. <result column="deny_date" property="denyDate"/>
  23. <result column="deny_reason" property="denyReason"/>
  24. <result column="total" property="total"/>
  25. <result column="monthTime" property="monthTime"/>
  26. <result column="april" property="april"/>
  27. <result column="may" property="may"/>
  28. <result column="store_number" property="storeNumber"/>
  29. </resultMap>
  30. <resultMap type="cn.ourwill.module.house.entity.daily.DeviceApplication" id="mapOfFind" extends="baseMap">
  31. <result column="name" property="grainName"/>
  32. <result column="house_name" property="houseName"/>
  33. </resultMap>
  34. <sql id="columsOfFind">
  35. sg.name ,
  36. hf.house_name,
  37. </sql>
  38. <sql id="columns">
  39. a.id ,
  40. a.grain_id ,
  41. a.house_id ,
  42. a.uuid ,
  43. a.sync_flag ,
  44. a.remark ,
  45. a.c_id ,
  46. a.c_time ,
  47. a.u_id ,
  48. a.u_time ,
  49. a.check_date ,
  50. a.device_applicationer ,
  51. a.application_month ,
  52. a.device_name ,
  53. a.application_number ,
  54. a.application_state,
  55. agreed_date,
  56. deny_date,
  57. deny_reason
  58. </sql>
  59. <sql id="joinCols">
  60. </sql>
  61. <select id="get" resultMap="baseMap">
  62. SELECT
  63. hf.house_name,
  64. <include refid="columns"/>
  65. FROM device_application a
  66. LEFT JOIN house_info hf on hf.id=a.house_id
  67. <include refid="joinCols"/>
  68. WHERE a.id = #{id}
  69. </select>
  70. <select id="getByUuid" resultMap="baseMap">
  71. SELECT
  72. hf.house_name,
  73. <include refid="columns"/>
  74. FROM device_application a
  75. LEFT JOIN house_info hf on hf.id=a.house_id
  76. <include refid="joinCols"/>
  77. WHERE a.uuid = #{uuid}
  78. </select>
  79. <select id="findList" resultMap="mapOfFind">
  80. SELECT
  81. <include refid="columsOfFind"/>
  82. <include refid="columns"/>
  83. FROM device_application a
  84. LEFT JOIN sys_grain sg on sg.id=a.grain_id
  85. LEFT JOIN house_info hf on hf.id=a.house_id
  86. <include refid="joinCols"/>
  87. <where>
  88. <if test="id !=null">
  89. and a.id = #{id}
  90. </if>
  91. <if test="grainId !=null">
  92. and a.grain_id = #{grainId}
  93. </if>
  94. <if test="houseId !=null">
  95. and a.house_id = #{houseId}
  96. </if>
  97. <if test="uuid !=null">
  98. and a.uuid = #{uuid}
  99. </if>
  100. <if test="syncFlag !=null">
  101. and a.sync_flag = #{syncFlag}
  102. </if>
  103. <if test="remark !=null">
  104. and a.remark = #{remark}
  105. </if>
  106. <if test="cId !=null">
  107. and a.c_id = #{cId}
  108. </if>
  109. <if test="cTime !=null">
  110. and a.c_time = #{cTime}
  111. </if>
  112. <if test="uId !=null">
  113. and a.u_id = #{uId}
  114. </if>
  115. <if test="uTime !=null">
  116. and a.u_time = #{uTime}
  117. </if>
  118. <if test="checkDate !=null">
  119. and a.check_date = #{checkDate}
  120. </if>
  121. <if test="deviceApplicationer !=null">
  122. and a.device_applicationer = #{deviceApplicationer}
  123. </if>
  124. <if test="applicationMonth !=null">
  125. and a.application_month = #{applicationMonth}
  126. </if>
  127. <if test="deviceName !=null">
  128. and a.device_name = #{deviceName}
  129. </if>
  130. <if test="searchStartDate !=null">
  131. and a.check_date &gt;= #{searchStartDate}
  132. </if>
  133. <if test="searchEndDate !=null">
  134. and a.check_date &lt;= #{searchEndDate}
  135. </if>
  136. <if test="applicationNumber !=null">
  137. and a.application_number = #{applicationNumber}
  138. </if>
  139. <if test="agreedDate !=null">
  140. and a.agreed_date = #{agreedDate}
  141. </if>
  142. <if test="denyDate !=null">
  143. and a.deny_date = #{denyDate}
  144. </if>
  145. <if test="denyReason !=null">
  146. and a.deny_reason = #{denyReason}
  147. </if>
  148. <if test="applicationState !=null">
  149. and a.application_state <![CDATA[ <> ]]>'10'
  150. </if>
  151. <if test="yearTime !=null">
  152. and date_format(check_date,'%Y')=#{yearTime}
  153. </if>
  154. <if test="monthTime !=null and yearTime !=null">
  155. and date_format(check_date,'%Y%m')=#{monthTime}
  156. </if>
  157. <if test="cityId !=null">
  158. and sg.parentId = #{cityId}
  159. </if>
  160. </where>
  161. <choose>
  162. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  163. ORDER BY ${page.orderBy}
  164. </when>
  165. <otherwise>
  166. </otherwise>
  167. </choose>
  168. </select>
  169. <select id="findAllList" resultMap="baseMap">
  170. SELECT
  171. <include refid="columns"/>
  172. FROM device_application a
  173. <include refid="joinCols"/>
  174. <where>
  175. <if test="id !=null">
  176. and id = #{id}
  177. </if>
  178. <if test="grainId !=null">
  179. and grain_id = #{grainId}
  180. </if>
  181. <if test="houseId !=null">
  182. and house_id = #{houseId}
  183. </if>
  184. <if test="uuid !=null">
  185. and uuid = #{uuid}
  186. </if>
  187. <if test="syncFlag !=null">
  188. and sync_flag = #{syncFlag}
  189. </if>
  190. <if test="remark !=null">
  191. and remark = #{remark}
  192. </if>
  193. <if test="cId !=null">
  194. and c_id = #{cId}
  195. </if>
  196. <if test="cTime !=null">
  197. and c_time = #{cTime}
  198. </if>
  199. <if test="uId !=null">
  200. and u_id = #{uId}
  201. </if>
  202. <if test="uTime !=null">
  203. and u_time = #{uTime}
  204. </if>
  205. <if test="checkDate !=null">
  206. and check_date = #{checkDate}
  207. </if>
  208. <if test="deviceApplicationer !=null">
  209. and device_applicationer = #{deviceApplicationer}
  210. </if>
  211. <if test="applicationMonth !=null">
  212. and application_month = #{applicationMonth}
  213. </if>
  214. <if test="deviceName !=null">
  215. and device_name = #{deviceName}
  216. </if>
  217. <if test="applicationNumber !=null">
  218. and application_number = #{applicationNumber}
  219. </if>
  220. <if test="applicationState !=null">
  221. and application_state = #{applicationState}
  222. </if>
  223. <if test="agreedDate !=null">
  224. and agreed_date = #{agreedDate}
  225. </if>
  226. <if test="denyDate !=null">
  227. and deny_date = #{denyDate}
  228. </if>
  229. <if test="denyReason !=null">
  230. and deny_reason = #{denyReason}
  231. </if>
  232. </where>
  233. <choose>
  234. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  235. ORDER BY ${page.orderBy}
  236. </when>
  237. <otherwise>
  238. </otherwise>
  239. </choose>
  240. </select>
  241. <insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  242. parameterType="cn.ourwill.module.house.entity.daily.DeviceApplication">
  243. INSERT INTO device_application
  244. <trim prefix="(" suffix=")" suffixOverrides=",">
  245. <if test=" id != null">
  246. id,
  247. </if>
  248. <if test=" grainId != null">
  249. grain_id,
  250. </if>
  251. <if test=" houseId != null">
  252. house_id,
  253. </if>
  254. <if test="uuid !=null">
  255. uuid,
  256. </if>
  257. <if test=" syncFlag != null">
  258. sync_flag,
  259. </if>
  260. <if test=" remark != null">
  261. remark,
  262. </if>
  263. <if test=" cId != null">
  264. c_id,
  265. </if>
  266. <if test=" cTime != null">
  267. c_time,
  268. </if>
  269. <if test=" uId != null">
  270. u_id,
  271. </if>
  272. <if test=" uTime != null">
  273. u_time,
  274. </if>
  275. <if test=" checkDate != null">
  276. check_date,
  277. </if>
  278. <if test=" deviceApplicationer != null">
  279. device_applicationer,
  280. </if>
  281. <if test="applicationMonth !=null">
  282. application_month,
  283. </if>
  284. <if test=" deviceName != null">
  285. device_name,
  286. </if>
  287. <if test=" applicationNumber != null">
  288. application_number,
  289. </if>
  290. <if test=" applicationState != null">
  291. application_state,
  292. </if>
  293. <if test="agreedDate !=null">
  294. agreed_date,
  295. </if>
  296. <if test="denyDate !=null">
  297. deny_date,
  298. </if>
  299. <if test="denyReason !=null">
  300. deny_reason
  301. </if>
  302. </trim>
  303. <trim prefix="values (" suffix=")" suffixOverrides=",">
  304. <if test=" id != null">
  305. #{id}, </if>
  306. <if test=" grainId != null">
  307. #{grainId}, </if>
  308. <if test=" houseId != null">
  309. #{houseId}, </if>
  310. <if test=" uuid != null">
  311. #{uuid}, </if>
  312. <if test="syncFlag !=null">
  313. #{syncFlag}, </if>
  314. <if test=" remark != null">
  315. #{remark}, </if>
  316. <if test=" cId != null">
  317. #{cId}, </if>
  318. <if test=" cTime != null">
  319. #{cTime}, </if>
  320. <if test=" uId != null">
  321. #{uId}, </if>
  322. <if test=" uTime != null">
  323. #{uTime}, </if>
  324. <if test=" checkDate != null">
  325. #{checkDate}, </if>
  326. <if test=" deviceApplicationer != null">
  327. #{deviceApplicationer}, </if>
  328. <if test="applicationMonth !=null">
  329. #{applicationMonth}, </if>
  330. <if test=" deviceName != null">
  331. #{deviceName}, </if>
  332. <if test=" applicationNumber != null">
  333. #{applicationNumber}, </if>
  334. <if test=" applicationState != null">
  335. #{applicationState}, </if>
  336. <if test="agreedDate !=null">
  337. #{agreedDate},
  338. </if>
  339. <if test="denyDate !=null">
  340. #{denyDate},
  341. </if>
  342. <if test="denyReason !=null">
  343. #{denyReason}
  344. </if>
  345. </trim>
  346. </insert>
  347. <update id="update" parameterType="cn.ourwill.module.house.entity.daily.DeviceApplication">
  348. UPDATE device_application <set>
  349. <if test=" id != null">
  350. id = #{id}, </if>
  351. <if test=" grainId != null">
  352. grain_id = #{grainId}, </if>
  353. <if test=" houseId != null">
  354. house_id = #{houseId}, </if>
  355. <if test=" uuid != null">
  356. uuid = #{uuid}, </if>
  357. <if test="syncFlag !=null">
  358. sync_flag = #{syncFlag}, </if>
  359. <if test=" remark != null">
  360. remark = #{remark}, </if>
  361. <if test=" cId != null">
  362. c_id = #{cId}, </if>
  363. <if test=" cTime != null">
  364. c_time = #{cTime}, </if>
  365. <if test=" uId != null">
  366. u_id = #{uId}, </if>
  367. <if test=" uTime != null">
  368. u_time = #{uTime}, </if>
  369. <if test=" checkDate != null">
  370. check_date = #{checkDate}, </if>
  371. <if test=" deviceApplicationer != null">
  372. device_applicationer = #{deviceApplicationer}, </if>
  373. <if test="applicationMonth !=null">
  374. application_month = #{applicationMonth}, </if>
  375. <if test=" deviceName != null">
  376. device_name = #{deviceName} , </if>
  377. <if test=" applicationNumber != null">
  378. application_number = #{applicationNumber}, </if>
  379. <if test=" applicationState != null">
  380. application_state = #{applicationState}, </if>
  381. <if test="agreedDate !=null">
  382. agreed_date = #{agreedDate},
  383. </if>
  384. <if test="denyDate !=null">
  385. deny_date = #{denyDate},
  386. </if>
  387. <if test="denyReason !=null">
  388. deny_reason = #{denyReason}
  389. </if>
  390. </set>
  391. WHERE id = #{id}
  392. </update>
  393. <update id="updateByUUID" parameterType="cn.ourwill.module.house.entity.daily.DeviceApplication">
  394. UPDATE device_application <set>
  395. <if test=" id != null">
  396. id = #{id}, </if>
  397. <if test=" grainId != null">
  398. grain_id = #{grainId}, </if>
  399. <if test=" houseId != null">
  400. house_id = #{houseId}, </if>
  401. <if test=" uuid != null">
  402. uuid = #{uuid}, </if>
  403. <if test="syncFlag !=null">
  404. sync_flag = #{syncFlag}, </if>
  405. <if test=" remark != null">
  406. remark = #{remark}, </if>
  407. <if test=" cId != null">
  408. c_id = #{cId}, </if>
  409. <if test=" cTime != null">
  410. c_time = #{cTime}, </if>
  411. <if test=" uId != null">
  412. u_id = #{uId}, </if>
  413. <if test=" uTime != null">
  414. u_time = #{uTime}, </if>
  415. <if test=" checkDate != null">
  416. check_date = #{checkDate}, </if>
  417. <if test=" deviceApplicationer != null">
  418. device_applicationer = #{deviceApplicationer}, </if>
  419. <if test="applicationMonth !=null">
  420. application_month = #{applicationMonth}, </if>
  421. <if test=" deviceName != null">
  422. device_name = #{deviceName} , </if>
  423. <if test=" applicationNumber != null">
  424. application_number = #{applicationNumber}, </if>
  425. <if test=" applicationState != null">
  426. application_state = #{applicationState}, </if>
  427. <if test="agreedDate !=null">
  428. agreed_date = #{agreedDate},
  429. </if>
  430. <if test="denyDate !=null">
  431. deny_date = #{denyDate},
  432. </if>
  433. <if test="denyReason !=null">
  434. deny_reason = #{denyReason}
  435. </if>
  436. </set>
  437. WHERE uuid = #{uuid}
  438. </update>
  439. <delete id="deleteById" parameterType="java.lang.Long">
  440. DELETE FROM device_application WHERE id = #{id}
  441. </delete>
  442. <delete id="deleteByIds" parameterType="java.util.List">
  443. DELETE FROM device_application WHERE id IN
  444. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  445. #{item}
  446. </foreach>
  447. </delete>
  448. <select id="batchApplicationByIds" parameterType="java.util.List" resultMap="baseMap">
  449. SELECT
  450. <include refid="columns"/>
  451. FROM device_application a
  452. <include refid="joinCols"/>
  453. WHERE id IN
  454. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  455. #{item}
  456. </foreach>
  457. </select>
  458. <select id="findCollectionList" resultMap="baseMap">
  459. select DATE_FORMAT(check_date,'%m') monthTime,da.device_name,sum(da.application_number) total
  460. from device_application da
  461. where DATE_FORMAT(check_date,'%Y')=#{yearTime} and da.application_state='30'
  462. <if test=" grainId != null">
  463. and grain_id = #{grainId}
  464. </if>
  465. group BY device_name,monthTime
  466. <choose>
  467. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  468. ORDER BY ${page.orderBy}
  469. </when>
  470. <otherwise>
  471. </otherwise>
  472. </choose>
  473. </select>
  474. <select id="findApplicationList" resultMap="mapOfFind">
  475. SELECT s.name,d.grain_id,
  476. d.check_date,d.device_name,
  477. sum(d.application_number) application_number,
  478. a.store_count store_number
  479. FROM device_application d, (SELECT sum(dd.store_count) store_count,ddm.device_name FROM dm_device dd LEFT JOIN dm_device_model ddm ON dd.model_uuid = ddm.uuid GROUP BY ddm.device_name) AS a,sys_grain s
  480. WHERE s.id = d.grain_id AND d.device_name = a.device_name AND d.application_state='30'
  481. <if test="yearTime !=null">
  482. and date_format(check_date,'%Y')=#{yearTime}
  483. </if>
  484. <if test="monthTime !=null and yearTime !=null">
  485. and date_format(check_date,'%Y%m')=#{monthTime}
  486. </if>
  487. GROUP BY d.device_name
  488. <choose>
  489. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  490. ORDER BY ${page.orderBy}
  491. </when>
  492. <otherwise>
  493. </otherwise>
  494. </choose>
  495. </select>
  496. </mapper>