DeviceUnitDao.xml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  2. <mapper namespace="cn.ourwill.module.house.dao.dm.DeviceUnitDao">
  3. <resultMap type="cn.ourwill.module.house.entity.dm.DeviceUnit" id="baseMap">
  4. <result column="uuid" property="uuid"/>
  5. <result column="device_uuid" property="deviceUuid"/>
  6. <result column="unit_uuid" property="unitUuid"/>
  7. </resultMap>
  8. <resultMap type="cn.ourwill.module.house.entity.dm.DeviceUnit" id="mapOfFind" extends="baseMap">
  9. <result column="device_name" property="deviceName"/>
  10. <result column="device_model" property="deviceModel"/>
  11. <result column="store_count" property="stockCount"/>
  12. </resultMap>
  13. <sql id="columns">
  14. a.uuid,
  15. a.device_uuid,
  16. a.unit_uuid
  17. </sql>
  18. <sql id="joinCols">
  19. </sql>
  20. <select id="get" resultMap="baseMap">
  21. SELECT
  22. <include refid="columns"/>
  23. FROM device_unit a
  24. <include refid="joinCols"/>
  25. WHERE a.id = #{id}
  26. </select>
  27. <select id="findList" resultMap="baseMap">
  28. SELECT
  29. <include refid="columns"/>
  30. FROM device_unit a
  31. <include refid="joinCols"/>
  32. <where>
  33. <if test="id !=null">
  34. and id = #{id}
  35. </if>
  36. <if test="uuid !=null">
  37. and uuid = #{uuid}
  38. </if>
  39. <if test="deviceUuid !=null">
  40. and device_uuid = #{deviceUuid}
  41. </if>
  42. <if test="unitUuid !=null">
  43. and unit_uuid = #{unitUuid}
  44. </if>
  45. </where>
  46. <choose>
  47. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  48. ORDER BY ${page.orderBy}
  49. </when>
  50. <otherwise>
  51. </otherwise>
  52. </choose>
  53. </select>
  54. <select id="findAllList" resultMap="baseMap">
  55. SELECT
  56. <include refid="columns"/>
  57. FROM device_unit a
  58. <include refid="joinCols"/>
  59. <where>
  60. <if test="id !=null">
  61. and id = #{id}
  62. </if>
  63. <if test="uuid !=null">
  64. and uuid = #{uuid}
  65. </if>
  66. <if test="deviceUuid !=null">
  67. and device_uuid = #{deviceUuid}
  68. </if>
  69. <if test="unitUuid !=null">
  70. and unit_uuid = #{unitUuid}
  71. </if>
  72. </where>
  73. <choose>
  74. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  75. ORDER BY ${page.orderBy}
  76. </when>
  77. <otherwise>
  78. </otherwise>
  79. </choose>
  80. </select>
  81. <select id="getByUuid" resultMap="baseMap">
  82. SELECT
  83. <include refid="columns"/>
  84. FROM device_unit a
  85. <include refid="joinCols"/>
  86. WHERE a.uuid = #{uuid}
  87. </select>
  88. <select id="getDeviceByUnitUuid" resultMap="mapOfFind">
  89. SELECT
  90. du.device_uuid,
  91. ddm.device_name,
  92. ddm.device_model,
  93. ifnull(sum(dd.store_count), '0') AS store_count
  94. FROM device_unit du LEFT JOIN dm_device_model ddm ON du.device_uuid = ddm.uuid
  95. LEFT JOIN dm_device dd ON du.device_uuid = dd.model_uuid
  96. WHERE unit_uuid = #{deviceUuid}
  97. GROUP BY du.device_uuid
  98. <choose>
  99. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  100. ORDER BY ${page.orderBy}
  101. </when>
  102. <otherwise>
  103. </otherwise>
  104. </choose>
  105. </select>
  106. <select id="getByUnitUuid" resultMap="mapOfFind">
  107. SELECT
  108. du.device_uuid,
  109. ddm.device_name,
  110. ddm.device_model,
  111. ifnull(sum(dd.store_count), '0') AS store_count
  112. FROM device_unit du LEFT JOIN dm_device_model ddm ON du.device_uuid = ddm.uuid
  113. LEFT JOIN dm_device dd ON du.device_uuid = dd.model_uuid
  114. WHERE unit_uuid = #{deviceUuid}
  115. GROUP BY du.device_uuid
  116. </select>
  117. <select id="getUnitByDeviceUuid" resultMap="mapOfFind">
  118. SELECT
  119. du.unit_uuid,
  120. ddm.device_name,
  121. ddm.device_model,
  122. ifnull(sum(dd.store_count), '0') AS store_count
  123. FROM device_unit du LEFT JOIN dm_device_model ddm ON du.unit_uuid = ddm.uuid
  124. LEFT JOIN dm_device dd ON du.unit_uuid = dd.model_uuid
  125. WHERE device_uuid = #{deviceUuid}
  126. GROUP BY du.unit_uuid
  127. <choose>
  128. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  129. ORDER BY ${page.orderBy}
  130. </when>
  131. <otherwise>
  132. </otherwise>
  133. </choose>
  134. </select>
  135. <select id="getDeviceByUnitUuidList" resultMap="mapOfFind">
  136. SELECT
  137. du.device_uuid,
  138. ddm.device_name,
  139. ddm.device_model,
  140. ifnull(sum(dd.store_count), '0') AS store_count
  141. FROM device_unit du LEFT JOIN dm_device_model ddm ON du.device_uuid = ddm.uuid
  142. LEFT JOIN dm_device dd ON du.device_uuid = dd.model_uuid
  143. WHERE unit_uuid = #{modelUuid}
  144. GROUP BY du.device_uuid
  145. </select>
  146. <select id="getUnitByDeviceUuidList" resultMap="mapOfFind">
  147. SELECT
  148. du.unit_uuid,
  149. ddm.device_name,
  150. ddm.device_model,
  151. ifnull(sum(dd.store_count), '0') AS store_count
  152. FROM device_unit du LEFT JOIN dm_device_model ddm ON du.unit_uuid = ddm.uuid
  153. LEFT JOIN dm_device dd ON du.unit_uuid = dd.model_uuid
  154. WHERE device_uuid = #{modelUuid}
  155. GROUP BY du.unit_uuid
  156. </select>
  157. <insert id="insert" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
  158. parameterType="cn.ourwill.module.house.entity.dm.DeviceUnit">
  159. INSERT INTO device_unit
  160. <trim prefix="(" suffix=")" suffixOverrides=",">
  161. <if test="uuid !=null">
  162. uuid,
  163. </if>
  164. <if test="deviceUuid !=null">
  165. device_uuid,
  166. </if>
  167. <if test="unitUuid !=null">
  168. unit_uuid
  169. </if>
  170. </trim>
  171. <trim prefix="values (" suffix=")" suffixOverrides=",">
  172. <if test="uuid !=null">
  173. #{uuid},
  174. </if>
  175. <if test="deviceUuid !=null">
  176. #{deviceUuid},
  177. </if>
  178. <if test="unitUuid !=null">
  179. #{unitUuid}
  180. </if>
  181. </trim>
  182. </insert>
  183. <update id="update" parameterType="cn.ourwill.module.house.entity.dm.DeviceCheck">
  184. UPDATE device_unit
  185. <set>
  186. <if test="uuid !=null">
  187. uuid = #{uuid},
  188. </if>
  189. <if test="deviceUuid !=null">
  190. device_uuid = #{deviceUuid},
  191. </if>
  192. <if test="unitUuid !=null">
  193. unit_uuid = #{unitUuid},
  194. </if>
  195. </set>
  196. WHERE id = #{id}
  197. </update>
  198. <update id="updateByUuid" parameterType="cn.ourwill.module.house.entity.dm.DeviceCheck">
  199. UPDATE device_unit
  200. <set>
  201. <if test="uuid !=null">
  202. uuid = #{uuid}
  203. </if>
  204. <if test="deviceUuid !=null">
  205. device_uuid = #{deviceUuid},
  206. </if>
  207. <if test="unitUuid !=null">
  208. unit_uuid = #{unitUuid},
  209. </if>
  210. </set>
  211. WHERE uuid = #{uuid}
  212. </update>
  213. <delete id="deleteById" parameterType="java.lang.Long">
  214. DELETE FROM device_unit
  215. WHERE id = #{id}
  216. </delete>
  217. <delete id="deleteByIds" parameterType="java.util.List">
  218. DELETE FROM device_unit WHERE id IN
  219. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  220. #{item}
  221. </foreach>
  222. </delete>
  223. <delete id="deleteByDeviceUuid" parameterType="java.lang.String">
  224. DELETE FROM device_unit
  225. WHERE device_uuid = #{deviceUuid}
  226. </delete>
  227. <delete id="deleteByUnitUuid" parameterType="java.lang.String">
  228. DELETE FROM device_unit
  229. WHERE unit_uuid = #{unitUuid}
  230. </delete>
  231. </mapper>