SiteMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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.bizmatics.persistence.mapper.SiteMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.bizmatics.model.Site">
  6. <id column="id" property="id"/>
  7. <result column="site_name" property="siteName"/>
  8. <result column="site_address" property="siteAddress"/>
  9. <result column="company_code" property="companyCode"/>
  10. <result column="user_name" property="userName"/>
  11. <result column="phone" property="phone"/>
  12. <result column="station_area_id" property="stationAreaId"/>
  13. <result column="route_id" property="routeId"/>
  14. <result column="longitude" property="longitude"/>
  15. <result column="latitude" property="latitude"/>
  16. <result column="region" property="region"/>
  17. <result column="create_time" property="createTime"/>
  18. <result column="creator" property="creator"/>
  19. <result column="enable" property="enable"/>
  20. <result column="grouping_id" property="groupingId"/>
  21. <result column="tenant_id" property="tenantId"/>
  22. </resultMap>
  23. <select id="selectCount" resultType="java.lang.Integer">
  24. select count(*)
  25. from (
  26. select us.id
  27. from user_site as us
  28. inner join device_status as ds
  29. on us.site_Id = ds.site_id
  30. <where>
  31. <if test="userId != null and userId != 0">
  32. and us.user_id = #{userId}
  33. </if>
  34. <if test="siteId != null and siteId != 0">
  35. and us.site_id = #{siteId}
  36. </if>
  37. <if test="siteStatus != null">
  38. and ds.device_status = #{siteStatus}
  39. </if>
  40. </where>
  41. group by us.site_id
  42. ) as t
  43. </select>
  44. <select id="list" resultType="com.bizmatics.model.Site">
  45. select s.id,s.site_name,s.site_address,s.company_code,s.user_name,s.phone,s.station_area_id,s.route_id,
  46. s.installed_capacity,s.rheological_change,s.longitude,s.latitude,s.region,s.create_time,s.creator,s.enable
  47. from user_site as us
  48. inner join site as s
  49. on us.site_id = s.id
  50. <where>
  51. s.enable=1
  52. and s.tenant_id=#{tenantId}
  53. <if test="userId != null and userId != 0">
  54. and us.user_id = #{userId}
  55. </if>
  56. <if test="name != null and name != ''">
  57. and s.site_name LIKE CONCAT(CONCAT('%', #{name}), '%')
  58. </if>
  59. </where>
  60. </select>
  61. <select id="list2" resultType="com.bizmatics.model.SiteTwo">
  62. SELECT
  63. a.*, b.device_status
  64. FROM
  65. (
  66. SELECT
  67. s.id,
  68. s.site_name,
  69. s.site_address,
  70. s.company_code,
  71. s.user_name,
  72. s.phone,
  73. s.station_area_id,
  74. s.route_id,
  75. s.installed_capacity,
  76. s.rheological_change,
  77. s.longitude,
  78. s.latitude,
  79. s.region,
  80. s.create_time,
  81. s.creator,
  82. s. ENABLE
  83. FROM
  84. user_site AS us
  85. INNER JOIN site AS s ON us.site_id = s.id
  86. <where>
  87. s.enable=1
  88. <if test="userId != null and userId != 0">
  89. and us.user_id = #{userId}
  90. </if>
  91. <if test="name != null and name != ''">
  92. and s.site_name LIKE CONCAT(CONCAT('%', #{name}), '%')
  93. </if>
  94. </where>) AS a
  95. LEFT JOIN device_status AS b ON a.id = b.site_id
  96. GROUP BY
  97. a.id
  98. ORDER BY
  99. a.id
  100. </select>
  101. <select id="getDeviceListOne" resultType="com.bizmatics.model.Device">
  102. SELECT
  103. a.*, b.device_status
  104. FROM
  105. device AS a
  106. JOIN device_status AS b ON a.device_code = b.device_code
  107. <where>
  108. <if test="siteId != null and siteId != 0">
  109. a.site_id = #{siteId}
  110. </if>
  111. </where>
  112. </select>
  113. <select id="Sitelist" resultType="com.bizmatics.model.SiteList">
  114. select
  115. a.user_id,
  116. b.id,
  117. b.grouping_id,
  118. b.site_name,
  119. c.grouping_name
  120. from user_site as a
  121. join site as b on a.site_id = b.id
  122. left join site_grouping as c on b.grouping_id = c.id
  123. <where>
  124. b.enable=1
  125. <if test="userId != null and userId != 0">
  126. and a.user_id = #{userId}
  127. </if>
  128. <if test="name != null and name != ''">
  129. and b.site_name like CONCAT(CONCAT('%', #{name}), '%')
  130. </if>
  131. <if test="tenantId != null and tenantId != 0 and tenantId !=''">
  132. and b.tenant_id = #{tenantId}
  133. </if>
  134. group by b.id
  135. order by b.id desc
  136. </where>
  137. </select>
  138. <select id="SitelistOne" resultType="com.bizmatics.model.SiteList">
  139. select
  140. b.id,
  141. b.grouping_id,
  142. b.site_name,
  143. c.grouping_name
  144. from site as b
  145. left join site_grouping as c on b.grouping_id = c.id
  146. <where>
  147. b.enable=1
  148. <if test="name != null and name != ''">
  149. and b.site_name like CONCAT(CONCAT('%', #{name}), '%')
  150. </if>
  151. <if test="tenantId != null and tenantId != 0 and tenantId !=''">
  152. and b.tenant_id = #{tenantId}
  153. </if>
  154. group by b.id
  155. order by b.id desc
  156. </where>
  157. </select>
  158. <select id="GroupingList" resultType="com.bizmatics.model.GroupingList">
  159. select
  160. a.id,
  161. a.grouping_name
  162. from site_grouping as a
  163. left join site as b on a.id = b.grouping_id
  164. <where>
  165. <if test="name != null and name != ''">
  166. and b.site_name like CONCAT(CONCAT('%', #{name}), '%')
  167. </if>
  168. <if test="creator != null and creator != ''">
  169. and a.creator = #{creator}
  170. </if>
  171. <if test="tenantId != null and tenantId != 0 and tenantId !=''">
  172. and a.tenant_id = #{tenantId}
  173. </if>
  174. group by a.id
  175. order by a.id desc
  176. </where>
  177. </select>
  178. <select id="GroupingListOne" resultType="com.bizmatics.model.GroupingList">
  179. SELECT
  180. *
  181. FROM
  182. (
  183. SELECT
  184. g.*, COUNT(s.id) AS sl
  185. FROM
  186. site_grouping AS g
  187. LEFT JOIN site AS s ON g.id = s.grouping_id
  188. JOIN user_site AS us ON us.site_id = s.id
  189. WHERE
  190. s. ENABLE = 1
  191. <if test="tenantId != null and tenantId != 0 and tenantId !=''">
  192. and g.tenant_id = #{tenantId}
  193. </if>
  194. <if test="userId != null and userId != '' and userId != 0">
  195. and us.user_id = #{userId}
  196. </if>
  197. <if test="name != null and name != ''">
  198. and s.site_name like CONCAT(CONCAT('%', #{name}), '%')
  199. </if>
  200. GROUP BY
  201. g.id
  202. ) AS a
  203. WHERE
  204. a.sl > 0
  205. group by a.id
  206. order by a.id desc;
  207. </select>
  208. <select id="GroupingListTwo" resultType="com.bizmatics.model.GroupingList">
  209. select
  210. *
  211. from (
  212. SELECT
  213. a.*, COUNT(b.id) AS sl
  214. FROM
  215. site_grouping AS a
  216. LEFT JOIN site AS b ON a.id = b.grouping_id
  217. GROUP BY
  218. a.id
  219. ) AS c
  220. <where>
  221. c.sl = 0
  222. <if test="creator != null and creator != ''">
  223. and c.creator = #{creator}
  224. </if>
  225. order by c.id desc
  226. </where>
  227. </select>
  228. <select id="SiteGroupinglist" resultType="com.bizmatics.model.SiteList">
  229. select
  230. a.user_id,
  231. b.id,
  232. b.grouping_id,
  233. b.site_name,
  234. c.grouping_name
  235. from user_site as a
  236. join site as b on a.site_id = b.id
  237. left join site_grouping as c on b.grouping_id = c.id
  238. <where>
  239. b.enable=1
  240. and b.grouping_id=0
  241. <if test="userId != null and userId != 0">
  242. and a.user_id = #{userId}
  243. </if>
  244. <if test="name != null and name != ''">
  245. and b.site_name like CONCAT(CONCAT('%', #{name}), '%')
  246. </if>
  247. <if test="tenantId != null and tenantId != 0 and tenantId !=''">
  248. and b.tenant_id = #{tenantId}
  249. </if>
  250. group by b.id
  251. order by b.id desc
  252. </where>
  253. </select>
  254. <select id="idList" resultType="com.bizmatics.model.Site">
  255. select s.id
  256. from user_site as us
  257. inner join site as s
  258. on us.site_id = s.id
  259. <where>
  260. <if test="userId != null and userId != 0">
  261. and us.user_id = #{userId}
  262. </if>
  263. <if test="name != null and name != ''">
  264. and s.site_name LIKE CONCAT(CONCAT('%', #{name}), '%')
  265. </if>
  266. </where>
  267. </select>
  268. <select id="templateQuery" resultType="com.bizmatics.model.TemplateData">
  269. select
  270. a.id,
  271. a.site_name,
  272. a.site_address,
  273. a.company_code,
  274. a.user_name,
  275. a.phone,
  276. a.station_area_id,
  277. a.route_id,
  278. a.installed_capacity,
  279. a.rheological_change,
  280. a.longitude,
  281. a.latitude,
  282. a.region,
  283. a.grouping_id,
  284. b.id as site_dynamic_properties_id,
  285. b.fault_status,
  286. b.real_time_load,
  287. b.total_electricity,
  288. b.power_factor,
  289. b.site_id,
  290. b.site_type,
  291. b.user_company,
  292. b.operation_time,
  293. b.service_deadline,
  294. b.power_supply_type,
  295. b.voltage_level,
  296. b.demolition_standard_coal,
  297. b.demolition_standard_coal1,
  298. b.site_picture_one,
  299. b.site_picture_two,
  300. b.site_picture_three,
  301. a.spare_user_name,
  302. a.spare_phone
  303. from
  304. site AS a
  305. left join site_dynamic_properties as b on a.id = b.site_id
  306. <where>
  307. a.enable=1
  308. <if test="id != null and id != 0">
  309. and a.id = #{id}
  310. </if>
  311. </where>
  312. </select>
  313. <select id="list1" resultType="com.bizmatics.model.Site">
  314. select *
  315. from site
  316. <where>
  317. enable=1
  318. <if test="id != null and id != 0">
  319. and id = #{id}
  320. </if>
  321. </where>
  322. </select>
  323. <select id="SiteDynamicPropertieslist" resultType="com.bizmatics.model.SiteDynamicProperties">
  324. select *
  325. from site_dynamic_properties
  326. <where>
  327. <if test="siteId != null and siteId != 0">
  328. and site_id = #{siteId}
  329. </if>
  330. </where>
  331. </select>
  332. <select id="deviceAnalogVariableList" resultType="com.bizmatics.model.DeviceAnalogVariableList">
  333. SELECT
  334. a.*
  335. FROM
  336. device_analog_variable_list AS a
  337. left JOIN device AS b ON a.communication_equipment = b.id
  338. <where>
  339. a.status = 1
  340. <if test="dataArea != null and dataArea != 0">
  341. AND a.data_area = #{dataArea}
  342. </if>
  343. <if test="siteId != null and siteId != 0">
  344. AND b.site_id = #{siteId}
  345. </if>
  346. </where>
  347. </select>
  348. </mapper>