DevicePurchasePlanDao.xml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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.dm.DevicePurchasePlanDao">
  4. <resultMap type="cn.ourwill.module.house.entity.dm.DevicePurchasePlan" id="baseMap">
  5. <result column="id" property="id"/>
  6. <result column="grain_id" property="grainId"/>
  7. <result column="uuid" property="uuid"/>
  8. <result column="sync_flag" property="syncFlag"/>
  9. <result column="remark" property="remark"/>
  10. <result column="c_id" property="cId"/>
  11. <result column="c_time" property="cTime"/>
  12. <result column="u_id" property="uId"/>
  13. <result column="u_time" property="uTime"/>
  14. <result column="check_date" property="checkDate"/>
  15. <result column="planner" property="planner"/>
  16. <result column="plan_month" property="planMonth"/>
  17. <result column="device_name" property="deviceName"/>
  18. <result column="application_number" property="applicationNumber"/>
  19. <result column="application_state" property="applicationState"/>
  20. <result column="store_number" property="storeNumber"/>
  21. <result column="plan_number" property="planNumber"/>
  22. <result column="purchased_number" property="purchasedNumber"/>
  23. </resultMap>
  24. <resultMap type="cn.ourwill.module.house.entity.dm.DevicePurchasePlan" id="mapOfFind" extends="baseMap">
  25. <result column="name" property="grainName"/>
  26. </resultMap>
  27. <sql id="columsOfFind">
  28. sg.name ,
  29. </sql>
  30. <sql id="columns">
  31. a.id ,
  32. a.grain_id ,
  33. a.uuid ,
  34. a.sync_flag ,
  35. a.remark ,
  36. a.c_id ,
  37. a.c_time ,
  38. a.u_id ,
  39. a.u_time ,
  40. a.check_date ,
  41. a.device_name ,
  42. a.application_number ,
  43. a.application_state,
  44. a.planner,
  45. a.plan_month,
  46. a.store_number,
  47. a.plan_number,
  48. a.purchased_number
  49. </sql>
  50. <sql id="joinCols">
  51. </sql>
  52. <select id="get" resultMap="baseMap">
  53. SELECT
  54. <include refid="columns"/>
  55. FROM device_purchase_plan a
  56. <include refid="joinCols"/>
  57. WHERE a.id = #{id}
  58. </select>
  59. <select id="findList" resultMap="mapOfFind">
  60. SELECT d.id,s.name,d.grain_id,
  61. DATE_FORMAT(d.check_date, '%Y-%m') AS check_date,d.device_name,
  62. d.application_number,
  63. d.store_number,
  64. d.plan_number
  65. FROM device_purchase_plan d, sys_grain s
  66. WHERE s.id = d.grain_id AND d.application_state='30'
  67. <if test="grainList !=null">
  68. and grain_id in
  69. <foreach item="item" index="index" collection="grainList" open="(" separator="," close=")">
  70. #{item}
  71. </foreach>
  72. </if>
  73. <if test="grainId !=null">
  74. and grain_id=#{grainId}
  75. </if>
  76. <if test="deviceName !=null">
  77. and device_name=#{deviceName}
  78. </if>
  79. <if test="checkDate !=null">
  80. and check_date=#{checkDate}
  81. </if>
  82. <if test="yearTime !=null">
  83. and date_format(check_date,'%Y')=#{yearTime}
  84. </if>
  85. <if test="monthTime !=null and yearTime !=null">
  86. and date_format(check_date,'%Y%m')=#{monthTime}
  87. </if>
  88. <if test="cityId !=null">
  89. and s.parentId = #{cityId}
  90. </if>
  91. GROUP BY d.device_name
  92. <choose>
  93. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  94. ORDER BY ${page.orderBy}
  95. </when>
  96. <otherwise>
  97. </otherwise>
  98. </choose>
  99. </select>
  100. <select id="getStoreNumber" resultType="java.lang.String">
  101. SELECT store_count FROM dm_device WHERE model_uuid=(
  102. SELECT uuid FROM dm_device_model WHERE grain_id=#{grainId} AND device_name=#{deviceName} LIMIT 1
  103. ) ORDER BY id DESC LIMIT 1
  104. </select>
  105. <insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  106. parameterType="cn.ourwill.module.house.entity.dm.DevicePurchasePlan" >
  107. INSERT INTO device_purchase_plan
  108. <trim prefix="(" suffix=")" suffixOverrides=",">
  109. <if test=" grainId != null">
  110. grain_id,
  111. </if>
  112. <if test="uuid !=null">
  113. uuid,
  114. </if>
  115. <if test=" syncFlag != null">
  116. sync_flag,
  117. </if>
  118. <if test=" remark != null">
  119. remark,
  120. </if>
  121. <if test=" cId != null">
  122. c_id,
  123. </if>
  124. <if test=" cTime != null">
  125. c_time,
  126. </if>
  127. <if test=" uId != null">
  128. u_id,
  129. </if>
  130. <if test=" uTime != null">
  131. u_time,
  132. </if>
  133. <if test=" checkDate != null">
  134. check_date,
  135. </if>
  136. <if test=" planner != null">
  137. planner,
  138. </if>
  139. <if test="planMonth !=null">
  140. plan_month,
  141. </if>
  142. <if test=" deviceName != null">
  143. device_name,
  144. </if>
  145. <if test=" applicationNumber != null">
  146. application_number,
  147. </if>
  148. <if test=" applicationState != null">
  149. application_state,
  150. </if>
  151. <if test="storeNumber !=null">
  152. store_number,
  153. </if>
  154. <if test="planNumber !=null">
  155. plan_number,
  156. </if>
  157. </trim>
  158. <trim prefix="values (" suffix=")" suffixOverrides=",">
  159. <if test=" grainId != null">
  160. #{grainId}, </if>
  161. <if test=" uuid != null">
  162. #{uuid}, </if>
  163. <if test="syncFlag !=null">
  164. #{syncFlag}, </if>
  165. <if test=" remark != null">
  166. #{remark}, </if>
  167. <if test=" cId != null">
  168. #{cId}, </if>
  169. <if test=" cTime != null">
  170. #{cTime}, </if>
  171. <if test=" uId != null">
  172. #{uId}, </if>
  173. <if test=" uTime != null">
  174. #{uTime}, </if>
  175. <if test=" checkDate != null">
  176. #{checkDate}, </if>
  177. <if test=" planner != null">
  178. #{planner},
  179. </if>
  180. <if test="planMonth !=null">
  181. #{planMonth},
  182. </if>
  183. <if test=" deviceName != null">
  184. #{deviceName},
  185. </if>
  186. <if test=" applicationNumber != null">
  187. #{applicationNumber},
  188. </if>
  189. <if test=" applicationState != null">
  190. #{applicationState},
  191. </if>
  192. <if test="storeNumber !=null">
  193. #{storeNumber},
  194. </if>
  195. <if test="planNumber !=null">
  196. #{planNumber},
  197. </if>
  198. </trim>
  199. </insert>
  200. <delete id="deleteByMonthTime">
  201. DELETE FROM device_purchase_plan
  202. <where>
  203. <if test="yearTime !=null">
  204. and date_format(check_date,'%Y')=#{yearTime}
  205. </if>
  206. <if test="monthTime !=null and yearTime !=null">
  207. and date_format(check_date,'%Y%m')=#{monthTime}
  208. </if>
  209. </where>
  210. </delete>
  211. <update id="update" parameterType="cn.ourwill.module.house.entity.dm.DevicePurchasePlan">
  212. UPDATE device_purchase_plan <set>
  213. <if test="grainId != null">
  214. grain_id= #{grainId},
  215. </if>
  216. <if test="uuid !=null">
  217. uuid= #{uuid},
  218. </if>
  219. <if test=" syncFlag != null">
  220. sync_flag= #{syncFlag},
  221. </if>
  222. <if test=" remark != null">
  223. remark = #{remark},
  224. </if>
  225. <if test=" cId != null">
  226. c_id = #{cId},
  227. </if>
  228. <if test=" cTime != null">
  229. c_time = #{cTime},
  230. </if>
  231. <if test=" uId != null">
  232. u_id = #{uId},
  233. </if>
  234. <if test=" uTime != null">
  235. u_time = #{uTime},
  236. </if>
  237. <if test=" checkDate != null">
  238. check_date = #{checkDate},
  239. </if>
  240. <if test=" planner != null">
  241. planner = #{planner},
  242. </if>
  243. <if test="planMonth !=null">
  244. plan_month = #{planMonth},
  245. </if>
  246. <if test=" deviceName != null">
  247. device_name = #{deviceName},
  248. </if>
  249. <if test=" applicationNumber != null">
  250. application_number = #{applicationNumber},
  251. </if>
  252. <if test=" applicationState != null">
  253. application_state = #{applicationState},
  254. </if>
  255. <if test="storeNumber !=null">
  256. store_number = #{storeNumber},
  257. </if>
  258. <if test="planNumber !=null">
  259. plan_number = #{planNumber}
  260. </if>
  261. </set>
  262. WHERE id = #{id}
  263. </update>
  264. </mapper>