SceneMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.huaxu.dao.SceneMapper">
  6. <resultMap type="SceneEntity" id="SceneResult">
  7. <result property="id" column="id"/>
  8. <result property="tenantId" column="tenant_id"/>
  9. <result property="parentSceneId" column="parent_scene_id"/>
  10. <result property="parentSceneIds" column="parent_scene_ids"/>
  11. <result property="sceneName" column="scene_name"/>
  12. <result property="companyOrgId" column="company_org_id"/>
  13. <result property="deptOrgId" column="dept_org_id"/>
  14. <result property="sceneTypeId" column="scene_type_id"/>
  15. <result property="enableState" column="enable_state"/>
  16. <result property="runTime" column="run_time"/>
  17. <result property="address" column="address"/>
  18. <result property="pointX" column="point_x"/>
  19. <result property="pointY" column="point_y"/>
  20. <result property="remark" column="remark"/>
  21. <result property="status" column="status"/>
  22. <result property="dateCreate" column="date_create"/>
  23. <result property="createBy" column="create_by"/>
  24. <result property="dateUpdate" column="date_update"/>
  25. <result property="updateBy" column="update_by"/>
  26. </resultMap>
  27. <!-- 实体栏位 -->
  28. <sql id="sceneColumns">
  29. a.id as "id" ,
  30. a.tenant_id as "tenantId" ,
  31. a.parent_scene_id as "parentSceneId" ,
  32. a.parent_scene_ids as "parentSceneIds" ,
  33. a.scene_name as "sceneName" ,
  34. a.company_org_id as "companyOrgId" ,
  35. a.dept_org_id as "deptOrgId" ,
  36. a.scene_type_id as "sceneTypeId" ,
  37. a.enable_state as "enableState" ,
  38. a.run_time as "runTime" ,
  39. a.address as "address" ,
  40. a.point_x as "pointX" ,
  41. a.point_y as "pointY" ,
  42. a.remark as "remark" ,
  43. a.status as "status" ,
  44. a.date_create as "dateCreate" ,
  45. a.create_by as "createBy" ,
  46. a.date_update as "dateUpdate" ,
  47. a.update_by as "updateBy",
  48. s.scene_type_name as "sceneTypeName"
  49. </sql>
  50. <sql id="deviceJoins">
  51. left join sms_scene_type s on s.id =a.scene_type_id and s.status=1
  52. </sql>
  53. <!-- 根据主键获取实体 -->
  54. <select id="findSceneById" resultType="com.huaxu.entity.SceneEntity">
  55. SELECT
  56. <include refid="sceneColumns"/>
  57. FROM sms_scene a
  58. <include refid="deviceJoins"/>
  59. WHERE a.id = #{id} and a.status=1
  60. </select>
  61. <!-- 根据获取实体List -->
  62. <select id="findList" resultType="com.huaxu.entity.SceneEntity">
  63. SELECT
  64. <include refid="sceneColumns"/>
  65. FROM sms_scene a
  66. <include refid="deviceJoins"/>
  67. <where>
  68. a.status=1
  69. <if test="scene.companyOrgId!=null and scene.deptOrgId!=null">
  70. and a.DEPT_ORG_ID = #{scene.deptOrgId} and a.COMPANY_ORG_ID = #{scene.companyOrgId}
  71. </if>
  72. <if test="scene.companyOrgId!=null and scene.deptOrgId == null">
  73. and a.DEPT_ORG_ID is null and a.COMPANY_ORG_ID = #{scene.companyOrgId}
  74. </if>
  75. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  76. <if test="scene.parentSceneId != null ">and a.parent_scene_id = #{scene.parentSceneId}</if>
  77. <if test="scene.sceneName != null and scene.sceneName != ''">
  78. and a.scene_name LIKE concat('%',#{scene.sceneName},'%')
  79. </if>
  80. <if test="scene.sceneTypeId != null ">and a.scene_type_id = #{scene.sceneTypeId}</if>
  81. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  82. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  83. and ( a.DEPT_ORG_ID in
  84. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  85. #{item.orgId}
  86. </foreach>
  87. or
  88. a.COMPANY_ORG_ID in
  89. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  90. #{item.orgId}
  91. </foreach>
  92. )
  93. </if>
  94. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  95. and a.DEPT_ORG_ID in
  96. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  97. #{item.orgId}
  98. </foreach>
  99. </if>
  100. <if test="scene.permissonType == 1">
  101. and a.COMPANY_ORG_ID in
  102. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  103. #{item.orgId}
  104. </foreach>
  105. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  106. </if>
  107. </if>
  108. </where>
  109. order by a.date_create
  110. </select>
  111. <!-- 根据主键获取租户菜单 -->
  112. <select id="findBySceneTypeIds" resultType="com.huaxu.entity.SceneEntity">
  113. select a.id
  114. FROM sms_scene a
  115. <include refid="deviceJoins"/>
  116. WHERE a.scene_type_id in
  117. <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
  118. #{dramaId}
  119. </foreach>
  120. </select>
  121. <!-- 根据主键获取租户菜单 -->
  122. <select id="findByParentSceneIds" resultType="com.huaxu.entity.SceneEntity">
  123. select a.id
  124. FROM sms_scene a
  125. <include refid="deviceJoins"/>
  126. WHERE a.status=1 and a.parent_scene_id in
  127. <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
  128. #{dramaId}
  129. </foreach>
  130. </select>
  131. <select id="findByParentIdsLike" resultType="com.huaxu.entity.SceneEntity">
  132. SELECT
  133. <include refid="sceneColumns"/>
  134. FROM sms_scene a
  135. <include refid="deviceJoins"/>
  136. <where>
  137. a.status=1
  138. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  139. <if test="scene.parentSceneIds != null ">and a.parent_scene_ids LIKE #{scene.parentSceneIds}</if>
  140. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  141. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  142. and ( a.DEPT_ORG_ID in
  143. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  144. #{item.orgId}
  145. </foreach>
  146. or
  147. a.COMPANY_ORG_ID in
  148. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  149. #{item.orgId}
  150. </foreach>
  151. )
  152. </if>
  153. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  154. and a.DEPT_ORG_ID in
  155. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  156. #{item.orgId}
  157. </foreach>
  158. </if>
  159. <if test="scene.permissonType == 1">
  160. and a.COMPANY_ORG_ID in
  161. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  162. #{item.orgId}
  163. </foreach>
  164. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  165. </if>
  166. </if>
  167. </where>
  168. </select>
  169. <!-- 根据获取实体 page -->
  170. <select id="findPage" resultType="com.huaxu.entity.SceneEntity">
  171. SELECT
  172. <include refid="sceneColumns"/>
  173. FROM sms_scene a
  174. <include refid="deviceJoins"/>
  175. <where>
  176. a.status=1 and a.parent_scene_id=0
  177. <if test="scene.companyOrgId!=null">
  178. and a.COMPANY_ORG_ID = #{scene.companyOrgId}
  179. </if>
  180. <if test="scene.deptOrgId != null">
  181. and a.DEPT_ORG_ID = #{scene.deptOrgId}
  182. </if>
  183. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  184. <if test="scene.parentSceneId != null ">and a.parent_scene_id = #{scene.parentSceneId}</if>
  185. <if test="scene.sceneName != null and scene.sceneName != ''">
  186. and a.scene_name LIKE concat('%',#{scene.sceneName},'%')
  187. </if>
  188. <if test="scene.sceneTypeId != null ">and a.scene_type_id = #{scene.sceneTypeId}</if>
  189. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  190. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  191. and ( a.DEPT_ORG_ID in
  192. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  193. #{item.orgId}
  194. </foreach>
  195. or
  196. a.COMPANY_ORG_ID in
  197. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  198. #{item.orgId}
  199. </foreach>
  200. )
  201. </if>
  202. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  203. and a.DEPT_ORG_ID in
  204. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  205. #{item.orgId}
  206. </foreach>
  207. </if>
  208. <if test="scene.permissonType == 1">
  209. and a.COMPANY_ORG_ID in
  210. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  211. #{item.orgId}
  212. </foreach>
  213. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  214. </if>
  215. </if>
  216. </where>
  217. order by a.date_create desc
  218. </select>
  219. <!--一级场景查询-->
  220. <select id="selectByTypeName" resultType="com.huaxu.entity.SceneEntity">
  221. SELECT
  222. <include refid="sceneColumns"/>
  223. FROM sms_scene a
  224. <include refid="deviceJoins"/>
  225. <where>
  226. a.parent_scene_id=0 and a.status=1 and a.enable_state=1 and s.scene_type_name=#{scene.sceneTypeName}
  227. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  228. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  229. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  230. and ( a.DEPT_ORG_ID in
  231. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  232. #{item.orgId}
  233. </foreach>
  234. or
  235. a.COMPANY_ORG_ID in
  236. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  237. #{item.orgId}
  238. </foreach>
  239. )
  240. </if>
  241. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  242. and a.DEPT_ORG_ID in
  243. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  244. #{item.orgId}
  245. </foreach>
  246. </if>
  247. <if test="scene.permissonType == 1">
  248. and a.COMPANY_ORG_ID in
  249. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  250. #{item.orgId}
  251. </foreach>
  252. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  253. </if>
  254. </if>
  255. </where>
  256. order by a.date_create
  257. </select>
  258. <!--根据一级场景查询所有场景信息-->
  259. <select id="findByParentId" resultType="com.huaxu.entity.SceneEntity">
  260. SELECT
  261. <include refid="sceneColumns"/>
  262. FROM sms_scene a
  263. <include refid="deviceJoins"/>
  264. <where>
  265. a.status=1
  266. <if test="scene.parentSceneIds != null ">and a.parent_scene_ids LIKE #{scene.parentSceneIds}</if>
  267. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  268. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  269. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  270. and ( a.DEPT_ORG_ID in
  271. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  272. #{item.orgId}
  273. </foreach>
  274. or
  275. a.COMPANY_ORG_ID in
  276. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  277. #{item.orgId}
  278. </foreach>
  279. )
  280. </if>
  281. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  282. and a.DEPT_ORG_ID in
  283. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  284. #{item.orgId}
  285. </foreach>
  286. </if>
  287. <if test="scene.permissonType == 1">
  288. and a.COMPANY_ORG_ID in
  289. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  290. #{item.orgId}
  291. </foreach>
  292. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  293. </if>
  294. </if>
  295. </where>
  296. order by a.date_create
  297. </select>
  298. </mapper>