SceneMapper.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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
  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.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  70. <if test="scene.parentSceneId != null ">and a.parent_scene_id = #{scene.parentSceneId}</if>
  71. <if test="scene.sceneName != null and scene.sceneName != ''">
  72. and a.scene_name LIKE concat('%',#{scene.sceneName},'%')
  73. </if>
  74. <if test="scene.sceneTypeId != null ">and a.scene_type_id = #{scene.sceneTypeId}</if>
  75. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  76. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  77. and ( a.DEPT_ORG_ID in
  78. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  79. #{item.orgId}
  80. </foreach>
  81. or
  82. a.COMPANY_ORG_ID in
  83. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  84. #{item.orgId}
  85. </foreach>
  86. )
  87. </if>
  88. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  89. and a.DEPT_ORG_ID in
  90. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  91. #{item.orgId}
  92. </foreach>
  93. </if>
  94. <if test="scene.permissonType == 1">
  95. and a.COMPANY_ORG_ID in
  96. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  97. #{item.orgId}
  98. </foreach>
  99. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  100. </if>
  101. </if>
  102. </where>
  103. order by a.date_create
  104. </select>
  105. <!-- 根据主键获取租户菜单 -->
  106. <select id="findBySceneTypeIds" resultType="com.huaxu.entity.SceneEntity">
  107. select a.id
  108. FROM sms_scene a
  109. <include refid="deviceJoins"/>
  110. WHERE a.scene_type_id in
  111. <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
  112. #{dramaId}
  113. </foreach>
  114. </select>
  115. <!-- 根据主键获取租户菜单 -->
  116. <select id="findByParentSceneIds" resultType="com.huaxu.entity.SceneEntity">
  117. select a.id
  118. FROM sms_scene a
  119. <include refid="deviceJoins"/>
  120. WHERE a.parent_scene_id in
  121. <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
  122. #{dramaId}
  123. </foreach>
  124. </select>
  125. <select id="findByParentIdsLike" resultType="com.huaxu.entity.SceneEntity">
  126. SELECT
  127. <include refid="sceneColumns"/>
  128. FROM sms_scene a
  129. <include refid="deviceJoins"/>
  130. <where>
  131. a.status=1
  132. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  133. <if test="scene.parentSceneIds != null ">and a.parent_scene_ids LIKE #{scene.parentSceneIds}</if>
  134. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  135. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  136. and ( a.DEPT_ORG_ID in
  137. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  138. #{item.orgId}
  139. </foreach>
  140. or
  141. a.COMPANY_ORG_ID in
  142. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  143. #{item.orgId}
  144. </foreach>
  145. )
  146. </if>
  147. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  148. and a.DEPT_ORG_ID in
  149. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  150. #{item.orgId}
  151. </foreach>
  152. </if>
  153. <if test="scene.permissonType == 1">
  154. and a.COMPANY_ORG_ID in
  155. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  156. #{item.orgId}
  157. </foreach>
  158. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  159. </if>
  160. </if>
  161. </where>
  162. </select>
  163. <!-- 根据获取实体 page -->
  164. <select id="findPage" resultType="com.huaxu.entity.SceneEntity">
  165. SELECT
  166. <include refid="sceneColumns"/>
  167. FROM sms_scene a
  168. <include refid="deviceJoins"/>
  169. <where>
  170. a.status=1 and a.parent_scene_id=0
  171. <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
  172. <if test="scene.parentSceneId != null ">and a.parent_scene_id = #{scene.parentSceneId}</if>
  173. <if test="scene.sceneName != null and scene.sceneName != ''">
  174. and a.scene_name LIKE concat('%',#{scene.sceneName},'%')
  175. </if>
  176. <if test="scene.sceneTypeId != null ">and a.scene_type_id = #{scene.sceneTypeId}</if>
  177. <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
  178. <if test="scene.permissonType == 5 or scene.permissonType == 2">
  179. and ( a.DEPT_ORG_ID in
  180. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  181. #{item.orgId}
  182. </foreach>
  183. or
  184. a.COMPANY_ORG_ID in
  185. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  186. #{item.orgId}
  187. </foreach>
  188. )
  189. </if>
  190. <if test="scene.permissonType == 4 or scene.permissonType == 3">
  191. and a.DEPT_ORG_ID in
  192. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  193. #{item.orgId}
  194. </foreach>
  195. </if>
  196. <if test="scene.permissonType == 1">
  197. and a.COMPANY_ORG_ID in
  198. <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
  199. #{item.orgId}
  200. </foreach>
  201. and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
  202. </if>
  203. </if>
  204. </where>
  205. order by a.date_create
  206. </select>
  207. </mapper>