DeviceMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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="com.huaxu.dao.DeviceMapper">
  4. <sql id="Base_Column_List">
  5. d.id
  6. ,d.TENANT_ID as "tenantId"
  7. ,d.DEVICE_CODE as "deviceCode"
  8. ,d.DEVICE_NAME as "deviceName"
  9. ,d.DEVICE_TYPE_ID as "deviceTypeId"
  10. ,d.COMPANY_ORG_ID as "companyOrgId"
  11. ,d.DEPT_ORG_ID as "deptOrgId"
  12. ,d.SCENE_ID as "sceneId"
  13. ,d.POINT_X as "pointX"
  14. ,d.POINT_Y as "pointY"
  15. ,d.ENABLE_STATE as "enableState"
  16. ,d.LAST_UPDATE_TIME as "lastUpdateTime"
  17. ,d.ADDRESS as "address"
  18. ,d.REMARK as "remark"
  19. ,d.`STATUS` as "status"
  20. ,d.DATE_CREATE as "dateCreate"
  21. ,d.CREATE_BY as "createBy"
  22. ,d.DATE_UPDATE as "dateUpdate"
  23. ,d.UPDATE_BY as "updateBy"
  24. ,s.SCENE_NAME as "sceneName"
  25. ,t.MANUFACTURER_NAME as "manufacturerName"
  26. ,t.MANUFACTURER_ID as "manufacturerId"
  27. ,t.DEVICE_TYPE as "deviceType"
  28. ,t.DEVICE_MODE as "deviceMode"
  29. </sql>
  30. <sql id="deviceJoins">
  31. left join sms_scene s on d.SCENE_ID =s.id
  32. left join sms_device_type t on d.DEVICE_TYPE_ID = t.id
  33. </sql>
  34. <select id="selectById" resultType="com.huaxu.dto.DeviceDto">
  35. select
  36. <include refid="Base_Column_List"/>
  37. from sms_device d
  38. <include refid="deviceJoins"/>
  39. where d.ID = #{id} and d.status = 1
  40. </select>
  41. <select id="selectByIds" resultType="com.huaxu.dto.DeviceDto">
  42. select
  43. <include refid="Base_Column_List"/>
  44. from sms_device d
  45. <include refid="deviceJoins"/>
  46. where d.status = 1
  47. and d.id in
  48. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  49. #{item}
  50. </foreach>
  51. </select>
  52. <!--通过实体作为筛选条件查询-->
  53. <select id="selectList" resultType="com.huaxu.dto.DeviceDto">
  54. select
  55. <include refid="Base_Column_List"/>
  56. from sms_device d
  57. <include refid="deviceJoins"/>
  58. where d.status = 1
  59. <if test="deviceDto.tenantId != null and deviceDto.tenantId != '' ">
  60. and d.tenant_id = #{deviceDto.tenantId}
  61. </if>
  62. <if test="deviceDto.condition != null and deviceDto.condition != ''">
  63. and (device_code like concat('%', #{deviceDto.condition},'%') or device_name like concat('%', #{deviceDto.condition},'%'))
  64. </if>
  65. <if test="deviceDto.companyOrgId != null and deviceDto.companyOrgId != 0 ">
  66. and d.COMPANY_ORG_ID=#{deviceDto.companyOrgId}
  67. </if>
  68. <if test="deviceDto.deptOrgId != null and deviceDto.deptOrgId != 0 ">
  69. and d.DEPT_ORG_ID =#{deviceDto.deptOrgId}
  70. </if>
  71. <if test="deviceDto.sceneIds != null and deviceDto.sceneIds.size() > 0">
  72. and d.SCENE_ID in
  73. <foreach collection="deviceDto.sceneIds" item="item" open="(" close=")" separator=",">
  74. #{item}
  75. </foreach>
  76. </if>
  77. <if test="deviceDto.enableState != null ">
  78. and d.ENABLE_STATE =#{deviceDto.enableState}
  79. </if>
  80. <if test="deviceDto.userType!=null and deviceDto.userType!=-999 and deviceDto.userType!=-9999 and deviceDto.programItems != null and deviceDto.programItems.size() > 0">
  81. <if test="deviceDto.permissonType == 5 or deviceDto.permissonType == 2">
  82. and ( d.DEPT_ORG_ID in
  83. <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
  84. #{item.orgId}
  85. </foreach>
  86. or
  87. d.COMPANY_ORG_ID in
  88. <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
  89. #{item.orgId}
  90. </foreach>
  91. )
  92. </if>
  93. <if test="deviceDto.permissonType == 4 or deviceDto.permissonType == 3">
  94. and d.DEPT_ORG_ID in
  95. <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
  96. #{item.orgId}
  97. </foreach>
  98. </if>
  99. <if test="deviceDto.permissonType == 1">
  100. and d.COMPANY_ORG_ID in
  101. <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
  102. #{item.orgId}
  103. </foreach>
  104. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  105. </if>
  106. </if>
  107. </select>
  108. <!-- 新增所有列 -->
  109. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  110. INSERT INTO sms_device ( TENANT_ID , DEVICE_CODE , DEVICE_NAME , DEVICE_TYPE_ID ,
  111. <if test="companyOrgId != null and companyOrgId != 0">COMPANY_ORG_ID , </if>
  112. <if test="deptOrgId != null and deptOrgId != 0">DEPT_ORG_ID ,</if>
  113. <if test="sceneId != null and sceneId != 0">SCENE_ID ,</if>
  114. POINT_X , POINT_Y , ENABLE_STATE , LAST_UPDATE_TIME , ADDRESS , REMARK , STATUS , DATE_CREATE , CREATE_BY , DATE_UPDATE , UPDATE_BY )
  115. VALUES ( #{tenantId} ,#{deviceCode} ,#{deviceName} ,#{deviceTypeId} ,
  116. <if test="companyOrgId != null and companyOrgId != 0">#{companyOrgId} , </if>
  117. <if test="deptOrgId != null and deptOrgId != 0"> #{deptOrgId} , </if>
  118. <if test="sceneId != null and sceneId != 0">#{sceneId} , </if>
  119. #{pointX} ,#{pointY} ,#{enableState} ,#{lastUpdateTime} ,#{address} ,#{remark} ,#{status} ,#{dateCreate} ,#{createBy} ,#{dateUpdate} ,#{updateBy})
  120. </insert>
  121. <!-- 批量新增 -->
  122. <insert id="batchInsert">
  123. INSERT INTO sms_device ( TENANT_ID , DEVICE_CODE , DEVICE_NAME , DEVICE_TYPE_ID , COMPANY_ORG_ID , DEPT_ORG_ID , SCENE_ID , POINT_X , POINT_Y , ENABLE_STATE , LAST_UPDATE_TIME , ADDRESS , REMARK , STATUS , DATE_CREATE , CREATE_BY , DATE_UPDATE , UPDATE_BY )
  124. values
  125. <foreach collection="devices" item="item" index="index" separator=",">
  126. ( #{item.tenantId} ,#{item.deviceCode} ,#{item.deviceName} ,#{item.deviceTypeId} ,#{item.companyOrgId} ,#{item.deptOrgId} ,#{item.sceneId} ,#{item.pointX} ,#{item.pointY} ,#{item.enableState} ,#{item.lastUpdateTime} ,#{item.address} ,#{item.remark} ,#{item.status} ,#{item.dateCreate} ,#{item.createBy} ,#{item.dateUpdate} ,#{item.updateBy})
  127. </foreach>
  128. </insert>
  129. <!-- 通过主键修改数据 -->
  130. <update id="update">
  131. UPDATE sms_device
  132. <set>
  133. <if test="tenantId != null and tenantId != '' ">
  134. TENANT_ID = #{tenantId},
  135. </if>
  136. <if test="deviceCode != null ">
  137. DEVICE_CODE = #{deviceCode},
  138. </if>
  139. <if test="deviceName != null and deviceName != '' ">
  140. DEVICE_NAME = #{deviceName},
  141. </if>
  142. <if test="deviceTypeId != null and deviceTypeId != 0">
  143. DEVICE_TYPE_ID = #{deviceTypeId},
  144. </if>
  145. <if test="companyOrgId != null and companyOrgId != 0">
  146. COMPANY_ORG_ID = #{companyOrgId},
  147. </if>
  148. DEPT_ORG_ID = #{deptOrgId},
  149. <if test="sceneId != null and sceneId != 0">
  150. SCENE_ID = #{sceneId},
  151. </if>
  152. <if test="pointX != null ">
  153. POINT_X = #{pointX},
  154. </if>
  155. <if test="pointY != null ">
  156. POINT_Y = #{pointY},
  157. </if>
  158. <if test="enableState != null ">
  159. ENABLE_STATE = #{enableState},
  160. </if>
  161. <if test="lastUpdateTime != null ">
  162. LAST_UPDATE_TIME = #{lastUpdateTime},
  163. </if>
  164. ADDRESS = #{address},
  165. REMARK = #{remark},
  166. <if test="status != null ">
  167. STATUS = #{status},
  168. </if>
  169. <if test="dateUpdate != null ">
  170. DATE_UPDATE = #{dateUpdate},
  171. </if>
  172. <if test="updateBy != null and updateBy != ''">
  173. UPDATE_BY = #{updateBy}
  174. </if>
  175. </set>
  176. WHERE
  177. ID = #{id};
  178. </update>
  179. <!--通过主键删除-->
  180. <delete id="deleteById">
  181. UPDATE sms_device set STATUS = 0 where id = #{id}
  182. </delete>
  183. <!--通过主键删除-->
  184. <delete id="batchDelete">
  185. UPDATE sms_device set STATUS = 0
  186. where id in
  187. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  188. #{item}
  189. </foreach>
  190. </delete>
  191. <!-- 分页查询 -->
  192. <select id="selectPage" resultType="com.huaxu.dto.DeviceDto">
  193. select
  194. <include refid="Base_Column_List"/>
  195. from sms_device d
  196. <include refid="deviceJoins"/>
  197. where d.status = 1
  198. <if test="deviceDto.tenantId != null and deviceDto.tenantId != '' ">
  199. and d.tenant_id = #{deviceDto.tenantId}
  200. </if>
  201. <if test="deviceDto.condition != null and deviceDto.condition != ''">
  202. and (device_code like concat('%', #{deviceDto.condition},'%') or device_name like concat('%', #{deviceDto.condition},'%'))
  203. </if>
  204. <if test="deviceDto.companyOrgId != null and deviceDto.companyOrgId != 0">
  205. and d.COMPANY_ORG_ID=#{deviceDto.companyOrgId}
  206. </if>
  207. <if test="deviceDto.deptOrgId != null and deviceDto.deptOrgId != 0">
  208. and d.DEPT_ORG_ID =#{deviceDto.deptOrgId}
  209. </if>
  210. <if test="deviceDto.sceneIds != null and deviceDto.sceneIds.size() > 0">
  211. and d.SCENE_ID in
  212. <foreach collection="deviceDto.sceneIds" item="item" open="(" close=")" separator=",">
  213. #{item}
  214. </foreach>
  215. </if>
  216. <if test="deviceDto.enableState != null ">
  217. and d.ENABLE_STATE =#{deviceDto.enableState}
  218. </if>
  219. <if test="deviceDto.userType!=null and deviceDto.userType!=-999 and deviceDto.userType!=-9999 and deviceDto.programItems != null and deviceDto.programItems.size() > 0">
  220. <if test="deviceDto.permissonType == 5 or deviceDto.permissonType == 2">
  221. and ( d.DEPT_ORG_ID in
  222. <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
  223. #{item.orgId}
  224. </foreach>
  225. or
  226. d.COMPANY_ORG_ID in
  227. <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
  228. #{item.orgId}
  229. </foreach>
  230. )
  231. </if>
  232. <if test="deviceDto.permissonType == 4 or deviceDto.permissonType == 3">
  233. and d.DEPT_ORG_ID in
  234. <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
  235. #{item.orgId}
  236. </foreach>
  237. </if>
  238. <if test="deviceDto.permissonType == 1">
  239. and d.COMPANY_ORG_ID in
  240. <foreach collection="deviceDto.programItems" item="item" open="(" close=")" separator=",">
  241. #{item.orgId}
  242. </foreach>
  243. and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
  244. </if>
  245. </if>
  246. </select>
  247. </mapper>