LampMapper.xml 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  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.welampiot.dao.LampDao">
  4. <select id="getCountByVO" resultType="Integer" parameterType="com.welampiot.vo.LampCountVO">
  5. select count(*) from lampinfo L
  6. left join section as S on S.id = L.sectionid
  7. left join global_location as G on G.id = S.pid
  8. left join lamp_info_log_new as LI on LI.lampid = L.id
  9. left join network as N on N.id = L.networkid
  10. left join net_card_info as CD on N.id = CD.net_id
  11. left join policy as P on P.id = L.policyid
  12. left join (select t1.* from all_alarm_info_log t1, (select lampid, max(updatetime) as maxtime from all_alarm_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as AI on L.id = AI.lampid
  13. where 1=1
  14. <if test="sectionList != null and !sectionList.isEmpty()">
  15. and L.sectionid in
  16. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  17. #{vo}
  18. </foreach>
  19. </if>
  20. <if test="onlineStatus != null">
  21. and N.status = #{onlineStatus}
  22. </if>
  23. <if test="lampStatus != null">
  24. <if test="lampStatus == 0">
  25. and L.lighteness = 0
  26. </if>
  27. <if test="lampStatus == 1">
  28. and L.lighteness > 0
  29. </if>
  30. </if>
  31. <if test="alarmStatus != null">
  32. <if test="alarmStatus == 0">
  33. and (L.faultstatus = 0 or L.faultstatus = 128)
  34. </if>
  35. <if test="alarmStatus == 1">
  36. and L.faultstatus != 0 and L.faultstatus != 128
  37. </if>
  38. </if>
  39. <if test="keyword != null">
  40. AND (L.number like '%#{keyword}%' OR L.address like '%#{keyword}%' OR L.macAddress like '%#{keyword}%')
  41. </if>
  42. </select>
  43. <select id="getConsumptionByVO" resultType="Float" parameterType="com.welampiot.vo.LampCountVO">
  44. select sum((select sum(consum) from lamp_info_cache_by_day t
  45. where t.lampid = a.id
  46. <if test="startDate != null and startDate != ''">
  47. and t.updatetime >= #{startDate}
  48. </if>
  49. )) as consum
  50. from lampinfo a
  51. left join lamp_info_log_new b on a.id = b.lampid
  52. where 1=1
  53. <if test="sectionList != null and !sectionList.isEmpty()">
  54. and a.sectionid in
  55. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  56. #{vo}
  57. </foreach>
  58. </if>
  59. </select>
  60. <select id="getDayConsumptionByVO" resultType="Float" parameterType="com.welampiot.vo.LampCountVO">
  61. select sum(b.day_gener_energy) as consum
  62. from lampinfo a left join lamp_info_log_new b on a.id = b.lampid
  63. where 1=1
  64. <if test="sectionList != null and !sectionList.isEmpty()">
  65. and a.sectionid in
  66. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  67. #{vo}
  68. </foreach>
  69. </if>
  70. <if test="startDate != null and startDate != ''">
  71. and b.updatetime >= #{startDate}
  72. </if>
  73. </select>
  74. <select id="getConsumptionListByVO" resultType="com.welampiot.vo.LampLogVO" parameterType="com.welampiot.vo.LampCountVO">
  75. select * from (
  76. select sum(a.consum) as consumption,sum(a.powerSave) as powerSave,a.updatetime as updateTime
  77. from lamp_info_cache_by_day a left join lampinfo b on b.id = a.lampid
  78. where b.id is not null
  79. <if test="sectionList != null and !sectionList.isEmpty()">
  80. and a.sectionid in
  81. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  82. #{vo}
  83. </foreach>
  84. </if>
  85. <if test="startDate != null and startDate != ''">
  86. and a.updatetime >= #{startDate}
  87. </if>
  88. <if test="endDate != null and endDate != ''">
  89. and a.updatetime &lt;= #{endDate}
  90. </if>
  91. group by a.updatetime
  92. ) as t order by t.updatetime asc
  93. </select>
  94. <select id="getListByVO" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.LampListResponseVO">
  95. select
  96. L.number,
  97. L.id,
  98. L.address as sn,
  99. <choose>
  100. <when test="version == 1">
  101. G.english_name as area,
  102. </when>
  103. <when test="version == 2">
  104. G.ru_name as area,
  105. </when>
  106. <otherwise>
  107. G.chinese_name as area,
  108. </otherwise>
  109. </choose>
  110. S.name as section,
  111. S.timezone,
  112. L.lighteness,
  113. L.name,
  114. LI.gridvolt as voltage,
  115. LI.gridcurr as current,
  116. LI.grid_active_power as power,
  117. LI.work_time_total as lightTime,
  118. LI.used_energy_total as totalEnergy,
  119. LI.devicetime as cmdTime,
  120. LI.led_lux_value,LI.leakage_cur,
  121. N.status as networkStatus,
  122. L.status as lampStatus,
  123. L.online as lampOnline,
  124. N.rssi,
  125. N.snr,
  126. N.protocoltype,
  127. LI.updatetime as updateTime,
  128. L.faultstatus,
  129. L.mode,
  130. N.hw_version as hwVersion,
  131. N.sw_version as swVersion,
  132. L.control_type as controlType,
  133. L.macAddress,
  134. L.dev_addr as devAddr,
  135. L.bindStatus,
  136. L.policy_type as policyType,
  137. L.policyid as policyId,
  138. L.longitude,
  139. L.latitude,L.new_faultstatus,L.install_date,L.expiration_date,
  140. P.name as policyName,AI.status as alarmStatus,AI.id as alarmid,AI.stralarmtype,
  141. CD.dueDate,CD.workingCondition,CD.remainGprs,CD.useGprs,CD.totalGprs,CD.comboName,CD.comboType,CD.id as card_id
  142. from lampinfo L
  143. left join section as S on S.id = L.sectionid
  144. left join global_location as G on G.id = S.pid
  145. left join lamp_info_log_new as LI on LI.lampid = L.id
  146. left join network as N on N.id = L.networkid
  147. left join net_card_info as CD on N.id = CD.net_id
  148. left join policy as P on P.id = L.policyid
  149. left join (select t1.* from all_alarm_info_log t1, (select lampid, max(updatetime) as maxtime from all_alarm_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as AI on L.id = AI.lampid
  150. where 1=1
  151. <if test="sectionList != null and !sectionList.isEmpty()">
  152. and L.sectionid in
  153. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  154. #{vo}
  155. </foreach>
  156. </if>
  157. <if test="online != null">
  158. AND ((N.status = #{online} and N.protocoltype != 5 and N.protocoltype != 11) or (L.online = #{online} and N.protocoltype = 5) or (L.online = #{online} and N.protocoltype = 11 and L.control_type != 26 and L.control_type != 27) or (N.status = #{online} and N.protocoltype = 11 and (L.control_type = 26 or L.control_type = 27)))
  159. </if>
  160. <if test="lightStatus != null">
  161. <if test="lightStatus == 0">
  162. AND ((N.status = 0 and N.protocoltype != 5) or (L.online = 0 and N.protocoltype = 5) or L.lighteness = 0)
  163. </if>
  164. <if test="lightStatus == 1">
  165. AND ((N.status = 1 and N.protocoltype != 5) or (L.online = 1 and N.protocoltype = 5)) and L.lighteness != 0
  166. </if>
  167. </if>
  168. <if test="keyword != null">
  169. AND (L.number like '%#{keyword}%' OR L.address like '%#{keyword}%' OR L.macAddress like '%#{keyword}%')
  170. </if>
  171. <if test="alarmType != null">
  172. AND L.faultstatus = #{alarmType}
  173. </if>
  174. <if test="lampPoleId != null">
  175. AND L.lamp_pole_id = #{lampPoleId}
  176. </if>
  177. order by L.number asc,L.mode asc,L.createtime desc,L.id desc
  178. <if test="offset != null and limit != null">
  179. limit #{offset},#{limit}
  180. </if>
  181. </select>
  182. <select id="getDetailsById" resultType="com.welampiot.dto.LampInfoDTO" parameterType="Integer">
  183. select
  184. L.number,
  185. L.id,
  186. L.address as sn,
  187. <choose>
  188. <when test="version == 1">
  189. GL.english_name as area,
  190. </when>
  191. <when test="version == 2">
  192. GL.ru_name as area,
  193. </when>
  194. <otherwise>
  195. GL.chinese_name as area,
  196. </otherwise>
  197. </choose>
  198. L.networkid as networkId,N.protocoltype as protocolType,L.areaid as areaId,
  199. L.sectionid as sectionId,L.groupid as groupId,L.longitude,L.latitude,S.name as section,L.dev_addr as devAddr,
  200. L.macAddress,L.section_id as loopNumber,G.name as `group`,N.network_name as network,N.rssi,
  201. L.lamp_pole_id as lampPoleId,LP.name as lampPoleName,L.control_type as controlType,
  202. L.lighteness,N.status as netStatus,LI.colour_value as colourValue,LI.used_energy_total as usedEnergyTotal,LI.updatetime,LI.work_time_total as workTimeTotal,
  203. LI.gridPF,LI.used_energy_tonight as usedEnergyTonight,L.faultstatus,N.snr,N.rssi,AI.id as alarmId,
  204. AI.stralarmtype as alarmInfo,S.timezone,L.status as lampStatas,L.freqId,
  205. L.ratedpower as power,L.address as imei,N.simid,L.name,N.sw_version as solfVersion,
  206. N.hw_version as hardVersion,L.install_date,L.expiration_date,L.mode
  207. from lampinfo L
  208. left join section as S on S.id = L.sectionid
  209. left join global_location as GL on GL.id = S.pid
  210. left join lamp_info_log_new as LI on LI.lampid = L.id
  211. left join network as N on N.id = L.networkid
  212. left join net_card_info as CD on N.id = CD.net_id
  213. left join policy as P on P.id = L.policyid
  214. left join lamp_pole as LP on LP.id = L.lamp_pole_id
  215. left join `group` as G on G.id = L.groupid
  216. left join (select t1.* from all_alarm_info_log t1, (select lampid, max(updatetime) as maxtime from all_alarm_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as AI on L.id = AI.lampid
  217. where L.id=#{id}
  218. </select>
  219. <select id="getDetailsByAddress" resultType="com.welampiot.dto.LampInfoDTO" parameterType="String">
  220. select
  221. L.number,
  222. L.id,
  223. L.address as sn,
  224. <choose>
  225. <when test="version == 1">
  226. GL.english_name as area,
  227. </when>
  228. <when test="version == 2">
  229. GL.ru_name as area,
  230. </when>
  231. <otherwise>
  232. GL.chinese_name as area,
  233. </otherwise>
  234. </choose>
  235. L.networkid as networkId,N.protocoltype as protocolType,L.areaid as areaId,
  236. L.sectionid as sectionId,L.groupid as groupId,L.longitude,L.latitude,S.name as section,L.dev_addr as devAddr,
  237. L.macAddress,L.section_id as loopNumber,G.name as `group`,N.network_name as network,N.rssi,
  238. L.lamp_pole_id as lampPoleId,LP.name as lampPoleName,L.control_type as controlType,
  239. L.lighteness,N.status as netStatus,LI.colour_value as colourValue,LI.used_energy_total as usedEnergyTotal,LI.updatetime,LI.work_time_total as workTimeTotal,
  240. LI.gridPF,LI.used_energy_tonight as usedEnergyTonight,L.faultstatus,N.snr,N.rssi,AI.id as alarmId,
  241. AI.stralarmtype as alarmInfo,S.timezone,L.status as lampStatas,L.freqId,
  242. L.ratedpower as power,L.address as imei,N.simid,L.name,N.sw_version as solfVersion,
  243. N.hw_version as hardVersion,L.install_date,L.expiration_date
  244. from lampinfo L
  245. left join section as S on S.id = L.sectionid
  246. left join global_location as GL on GL.id = S.pid
  247. left join lamp_info_log_new as LI on LI.lampid = L.id
  248. left join network as N on N.id = L.networkid
  249. left join net_card_info as CD on N.id = CD.net_id
  250. left join policy as P on P.id = L.policyid
  251. left join lamp_pole as LP on LP.id = L.lamp_pole_id
  252. left join `group` as G on G.id = L.groupid
  253. left join (select t1.* from all_alarm_info_log t1, (select lampid, max(updatetime) as maxtime from all_alarm_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as AI on L.id = AI.lampid
  254. where L.address=#{address}
  255. </select>
  256. <select id="findByVO" resultType="Integer" parameterType="com.welampiot.dto.LampInfoDTO">
  257. select count(*) from lampinfo L
  258. where 1=1
  259. <if test="sectionId != null">
  260. and L.sectionid = #{sectionId}
  261. </if>
  262. <if test="name != null">
  263. and L.name = #{name}
  264. </if>
  265. <if test="number != null">
  266. and L.number = #{number}
  267. </if>
  268. <if test="sn != null">
  269. and L.address = #{sn}
  270. </if>
  271. <if test="id != null">
  272. and L.id != #{id}
  273. </if>
  274. </select>
  275. <select id="checkData" resultType="Integer" parameterType="com.welampiot.dto.LampInfoDTO">
  276. select IFNULL(L.id,0) from lampinfo L
  277. where 1=1
  278. <if test="sectionId != null">
  279. and L.sectionid = #{sectionId}
  280. </if>
  281. <if test="networkId != null">
  282. and L.networkid != #{networkId}
  283. </if>
  284. <if test="name != null">
  285. and L.name = #{name}
  286. </if>
  287. <if test="number != null">
  288. and L.number = #{number}
  289. </if>
  290. <if test="sn != null">
  291. and L.address = #{sn}
  292. </if>
  293. <if test="id != null">
  294. and L.id != #{id}
  295. </if>
  296. limit 1
  297. </select>
  298. <insert id="add" parameterType="com.welampiot.dto.LampInfoDTO" useGeneratedKeys="true" keyProperty="id"
  299. >
  300. insert into lampinfo(networkid,name,number,address,areaid,sectionid,longitude,latitude,createtime,ratedpower,control_type
  301. <if test="mode != null">,mode</if>
  302. <if test="lampPoleId != null">,lamp_pole_id</if>
  303. <if test="installDate != null">,install_date</if>
  304. <if test="expirationDate != null">,expiration_date</if>
  305. )
  306. values
  307. (#{networkId},#{name},#{number},#{sn},#{areaId},#{sectionId},#{longitude},#{latitude},#{createTime},#{ratedPower},#{controlType}
  308. <if test="mode != null">,#{mode}</if>
  309. <if test="lampPoleId != null">,#{lampPoleId}</if>
  310. <if test="installDate != null">,#{installDate}</if>
  311. <if test="expirationDate != null">,#{expirationDate}</if>
  312. )
  313. </insert>
  314. <update id="update" parameterType="com.welampiot.dto.LampInfoDTO"
  315. >
  316. update lampinfo
  317. set
  318. networkid=#{networkId},
  319. name=#{name},
  320. number=#{number},
  321. address=#{sn},
  322. areaid=#{areaId},
  323. control_type=#{controlType},
  324. sectionid=#{sectionId},
  325. longitude=#{longitude},
  326. latitude=#{latitude},
  327. <if test="mode != null">mode=#{mode},</if>
  328. <if test="lampPoleId != null">lamp_pole_id=#{lampPoleId},</if>
  329. <if test="installDate != null">install_date=#{installDate},</if>
  330. <if test="expirationDate != null">expiration_date=#{expirationDate},</if>
  331. ratedpower=#{ratedPower}
  332. where id = #{id}
  333. </update>
  334. <select id="groupSelectLamp" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.LampListResponseVO">
  335. select
  336. L.number,
  337. L.id,
  338. L.address as sn,
  339. <choose>
  340. <when test="version == 1">
  341. G.english_name as area,
  342. </when>
  343. <when test="version == 2">
  344. G.ru_name as area,
  345. </when>
  346. <otherwise>
  347. G.chinese_name as area,
  348. </otherwise>
  349. </choose>
  350. S.name as section,
  351. S.timezone,
  352. L.lighteness,
  353. L.name,
  354. LI.gridvolt as voltage,
  355. LI.gridcurr as current,
  356. LI.grid_active_power as power,
  357. LI.work_time_total as lightTime,
  358. LI.used_energy_total as totalEnergy,
  359. LI.devicetime as cmdTime,
  360. LI.led_lux_value,LI.leakage_cur,
  361. N.status as networkStatus,
  362. L.status as lampStatus,
  363. L.online as lampOnline,
  364. N.rssi,
  365. N.snr,
  366. N.protocoltype,
  367. LI.updatetime as updateTime,
  368. L.faultstatus,
  369. L.mode,
  370. N.hw_version as hwVersion,
  371. N.sw_version as swVersion,
  372. L.control_type as controlType,
  373. L.macAddress,
  374. L.dev_addr as devAddr,
  375. L.bindStatus,
  376. L.policy_type as policyType,
  377. L.policyid as policyId,
  378. L.longitude,
  379. L.latitude,L.new_faultstatus
  380. from lampinfo L
  381. left join section as S on S.id = L.sectionid
  382. left join global_location as G on G.id = S.pid
  383. left join lamp_info_log_new as LI on LI.lampid = L.id
  384. left join network as N on N.id = L.networkid
  385. where 1=1
  386. <if test="sectionList != null and !sectionList.isEmpty()">
  387. and L.sectionid in
  388. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  389. #{vo}
  390. </foreach>
  391. </if>
  392. <if test="lampIds != null">
  393. and L.id in (#{lampIds})
  394. </if>
  395. </select>
  396. <delete id="deleteById">
  397. delete from lampinfo where id=#{id};
  398. </delete>
  399. <select id="getNavByVO" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.LampListResponseVO">
  400. select
  401. L.number,
  402. L.id,
  403. L.mode,
  404. N.protocoltype,
  405. L.areaid as areaId,
  406. L.control_type as controlType
  407. from lampinfo L
  408. left join network as N on N.id = L.networkid
  409. where 1=1
  410. <if test="sectionList != null and !sectionList.isEmpty()">
  411. and L.sectionid in
  412. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  413. #{vo}
  414. </foreach>
  415. </if>
  416. <if test="lampType != null and lampType == 1">
  417. and L.lamp_pole_id != 0
  418. </if>
  419. order by L.number asc,L.mode asc,L.createtime desc,L.id desc
  420. </select>
  421. <select id="getLampPoleDetailListByLampPoleId" resultType="com.welampiot.dto.LampInfoDTO" parameterType="int">
  422. select
  423. L.number,
  424. L.id,
  425. L.address as sn,
  426. L.address,
  427. L.areaid as areaId,
  428. L.sectionid as sectionId,
  429. L.name,
  430. N.protocoltype,
  431. L.control_type as controlType,
  432. L.macAddress,
  433. L.dev_addr as devAddr,
  434. L.longitude,
  435. L.latitude,L.install_date as installDate,L.expiration_date as expirationDate,L.ratedpower as ratedPower
  436. from lampinfo L
  437. left join section as S on S.id = L.sectionid
  438. left join network as N on N.id = L.networkid
  439. where lamp_pole_id=#{lampPoleId}
  440. </select>
  441. <select id="getLampInfoListByDTO" resultType="com.welampiot.dto.LampInfoDTO">
  442. select l.id,l.number,l.status,l.lighteness,n.status as netStatus,l1.grid_active_power as power,l.updatetime as updateTime,
  443. l1.gridvolt as voltage,l1.gridcurr as current,l1.gridPF,l1.used_energy_tonight as usedEnergyTonight,l1.work_time_total as lightTime,
  444. l.faultstatus,l.longitude,l.latitude,l.groupid as groupId,l.loopid as loopId,n.rssi,n.snr,l1.used_energy_total as usedEnergyTotal,
  445. l.control_type as controlType,l.colour_val as colourVal,a.id as alarmId,s.timezone
  446. from lampinfo l
  447. left join network n on l.networkid = n.id
  448. left join lamp_info_log_new l1 on l.id = l1.lampid
  449. left join all_alarm_info_log a on l.id = a.lampid
  450. left join section s on s.id = l.sectionid
  451. where 1=1
  452. <if test="keyword != null and keyword != ''">
  453. and (l.name like '%${keyword}%' or l.number like '%${keyword}%')
  454. </if>
  455. <if test="sectionList != null and !sectionList.isEmpty()">
  456. and l.sectionid in
  457. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  458. #{item}
  459. </foreach>
  460. </if>
  461. <choose>
  462. <when test="type == 5">
  463. and l.faultstatus != 0 and n.status = 1 and l.faultstatus != 128
  464. </when>
  465. <when test="type == 4">
  466. and n.status = 1
  467. </when>
  468. <when test="type == 3">
  469. and n.status = 0
  470. </when>
  471. <when test="type == 2">
  472. and n.status = 1 and l.status = 0
  473. </when>
  474. <when test="type == 1">
  475. and n.status = 1 and l.status = 1
  476. </when>
  477. </choose>
  478. <choose>
  479. <when test="alarmType == 16">
  480. and l.faultstatus = 16
  481. </when>
  482. <when test="alarmType == 8">
  483. and l.faultstatus = 8
  484. </when>
  485. <when test="alarmType == 4">
  486. and l.faultstatus = 4
  487. </when>
  488. <when test="alarmType == 2">
  489. and l.faultstatus = 2
  490. </when>
  491. <when test="alarmType == 1">
  492. and l.faultstatus = 1
  493. </when>
  494. <otherwise>
  495. and l.faultstatus = 0
  496. </otherwise>
  497. </choose>
  498. </select>
  499. <select id="getLampLocationByGroupId" resultType="com.welampiot.dto.LampInfoDTO">
  500. select l.latitude,l.longitude
  501. from lampinfo l
  502. left join `group` g on g.id = l.groupid
  503. where g.id = #{id}
  504. </select>
  505. <select id="getLampLocationByLoopId" resultType="com.welampiot.dto.LampInfoDTO">
  506. select l.latitude,l.longitude
  507. from lampinfo l
  508. left join `loop` l1 on l1.id = l.loopid
  509. where l1.id = #{id}
  510. </select>
  511. <!-- 灯控安装总数 -->
  512. <select id="getLampInstallTotalByDTO" resultType="Integer">
  513. select count(l.id)
  514. from lampinfo l
  515. where 1=1
  516. <if test="type != null and type == 2">
  517. and l.lamp_pole_id != 0
  518. </if>
  519. <if test="sectionList != null and !sectionList.isEmpty()">
  520. and l.sectionid in
  521. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  522. #{item}
  523. </foreach>
  524. </if>
  525. <if test="areaId != null and areaId != 0">
  526. and l.areaid = #{areaId}
  527. </if>
  528. <if test="sectionId != null and sectionId != 0">
  529. and l.sectionid = #{sectionId}
  530. </if>
  531. </select>
  532. <!-- 灯控亮灯数 -->
  533. <select id="getLampLightTotalByDTO" resultType="Integer">
  534. select count(l.id)
  535. from lampinfo l
  536. left join network n on l.networkid = n.id
  537. where n.status = 1 and l.status = 1
  538. <if test="type != null and type == 2">
  539. and l.lamp_pole_id != 0
  540. </if>
  541. <if test="sectionList != null and !sectionList.isEmpty()">
  542. and l.sectionid in
  543. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  544. #{item}
  545. </foreach>
  546. </if>
  547. <if test="areaId != null and areaId != 0">
  548. and l.areaid = #{areaId}
  549. </if>
  550. <if test="sectionId != null and sectionId != 0">
  551. and l.sectionid = #{sectionId}
  552. </if>
  553. </select>
  554. <!-- 灯控在线数 -->
  555. <select id="getLampOnlineTotalByDTO" resultType="Integer">
  556. select count(l.id)
  557. from lampinfo l
  558. left join network n on l.networkid = n.id
  559. where n.status = 1
  560. <if test="type != null and type == 2">
  561. and l.lamp_pole_id != 0
  562. </if>
  563. <if test="sectionList != null and !sectionList.isEmpty()">
  564. and l.sectionid in
  565. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  566. #{item}
  567. </foreach>
  568. </if>
  569. <if test="areaId != null and areaId != 0">
  570. and l.areaid = #{areaId}
  571. </if>
  572. <if test="sectionId != null and sectionId != 0">
  573. and l.sectionid = #{sectionId}
  574. </if>
  575. </select>
  576. <!-- 灯控故障数 -->
  577. <select id="getLampFaultTotalByDTO" resultType="Integer">
  578. select count(l.id)
  579. from lampinfo l
  580. left join network n on l.networkid = n.id
  581. where n.status = 1 and l.faultstatus != 0 and l.faultstatus != 128
  582. <if test="type != null and type == 2">
  583. and l.lamp_pole_id != 0
  584. </if>
  585. <if test="sectionList != null and !sectionList.isEmpty()">
  586. and l.sectionid in
  587. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  588. #{item}
  589. </foreach>
  590. </if>
  591. <if test="areaId != null and areaId != 0">
  592. and l.areaid = #{areaId}
  593. </if>
  594. <if test="sectionId != null and sectionId != 0">
  595. and l.sectionid = #{sectionId}
  596. </if>
  597. </select>
  598. <update id="changeLampLocationById" parameterType="LampInfoDTO">
  599. update
  600. lampinfo l
  601. set
  602. l.longitude = #{longitude},
  603. l.latitude = #{latitude}
  604. where l.id = #{id}
  605. </update>
  606. <select id="getSectionOfLampCountBySectionId" resultType="Integer">
  607. select count(l.id) as total
  608. from lampinfo l
  609. where l.sectionid = #{id}
  610. </select>
  611. <select id="getNameOrNumber" resultType="String">
  612. <choose>
  613. <when test="type == 0">
  614. select l.number
  615. from lampinfo l
  616. where l.id = #{value}
  617. </when>
  618. <when test="type == 1">
  619. select s.name
  620. from section s
  621. where s.id = #{value}
  622. </when>
  623. <when test="type == 2">
  624. select
  625. <choose>
  626. <when test="version == 0">
  627. g.chinese_name
  628. </when>
  629. <when test="version == 1">
  630. g.english_name
  631. </when>
  632. <otherwise>
  633. g.ru_name
  634. </otherwise>
  635. </choose>
  636. from global_location g
  637. where g.id = #{value}
  638. </when>
  639. </choose>
  640. </select>
  641. <select id="getLampInfoDTOById" resultType="com.welampiot.dto.LampInfoDTO">
  642. select l.id,l.number
  643. from lampinfo l
  644. where l.id = #{id}
  645. </select>
  646. <select id="getLampList" resultType="com.welampiot.dto.LampInfoDTO">
  647. select
  648. l.id,l.lamp_pole_id as lampPoleId,lp.name as lampPoleName,w.num as sn,s.name as section,l.number,l.name
  649. <choose>
  650. <when test="version == 0">
  651. ,gl.chinese_name as area
  652. </when>
  653. <when test="version == 1">
  654. ,gl.english_name as area
  655. </when>
  656. <otherwise>
  657. ,gl.ru_name as area
  658. </otherwise>
  659. </choose>
  660. ,n.status,l.lighteness,l1.gridcurr as current,l1.gridvolt as voltage,n.protocoltype as protocolType,
  661. l1.grid_active_power as power,l.address,l.updatetime as updateTime,l.install_date as installDate,l.online as lampOnline,
  662. l.expiration_date as expirationDate,p.name as policyName,l1.devicetime as serverTime,l1.work_time_total as lightTime
  663. from lampinfo l
  664. left join lamp_pole lp on l.lamp_pole_id = lp.id
  665. left join wifi w on lp.id = w.lamp_pole_id
  666. left join section s on l.section_id = s.id
  667. left join global_location gl on gl.id = l.areaid
  668. left join network n on l.networkid = n.id
  669. left join lamp_info_log_new l1 on l1.lampid = l.id
  670. left join policy p on l.policyid = p.id
  671. where 1=1
  672. <if test="sectionList != null and !sectionList.isEmpty()">
  673. and l.sectionid in
  674. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  675. #{item}
  676. </foreach>
  677. </if>
  678. <if test="areaId != null and areaId != 0">
  679. and l.areaid = #{areaId}
  680. </if>
  681. <if test="sectionId != null and sectionId != 0">
  682. and l.sectionid = #{sectionId}
  683. </if>
  684. <if test="keyword != null and keyword != ''">
  685. and (l.number like '%${keyword}%' or l.address like '%${keyword}%')
  686. </if>
  687. <choose>
  688. <when test="online == 1">
  689. and n.status = 0
  690. </when>
  691. <when test="online == 2">
  692. and n.status = 1
  693. </when>
  694. </choose>
  695. <if test="page >= 0 and count > 0">
  696. limit #{page},#{count}
  697. </if>
  698. </select>
  699. <select id="getLampTotal" resultType="Integer">
  700. select count(*)
  701. from lampinfo l
  702. where 1=1
  703. <if test="sectionList != null and !sectionList.isEmpty()">
  704. and l.sectionid in
  705. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  706. #{item}
  707. </foreach>
  708. </if>
  709. <if test="areaId != null and areaId != 0">
  710. and l.areaid = #{areaId}
  711. </if>
  712. <if test="sectionId != null and sectionId != 0">
  713. and l.sectionid = #{sectionId}
  714. </if>
  715. </select>
  716. <select id="getCityLampCount" resultType="Integer">
  717. select count(*)
  718. from lampinfo l
  719. left join section s on l.sectionid = s.id
  720. left join global_location gl on s.pid = gl.id
  721. left join global_location gl1 on gl.pid = gl1.id
  722. where gl1.id = #{id}
  723. </select>
  724. <select id="getLampDataByLampIds" resultType="LampInfoDTO">
  725. select
  726. l.name,
  727. l.address,
  728. l.number,
  729. l.lighteness,
  730. l.status,
  731. l.control_type as controlType,
  732. n.status as `online`,
  733. l.power,
  734. l.mode,
  735. n.protocoltype as protocolType
  736. from lampinfo l
  737. left join network n on l.networkid = n.id
  738. where l.id in
  739. <foreach collection="lampIds" item="item" open="(" separator="," close=")">
  740. #{item}
  741. </foreach>
  742. </select>
  743. <update id="updateLight" parameterType="com.welampiot.dto.LampInfoDTO"
  744. >
  745. update lampinfo
  746. set
  747. lighteness=#{light}
  748. <if test="policyId != null">,policyid=#{policyId}</if>
  749. <if test="policyType != null">,policy_type=#{policyType}</if>
  750. <if test="light > 0">,status=1</if>
  751. <if test="light == 0">,status=0</if>
  752. where id = #{id}
  753. </update>
  754. <select id="getListByIdList" resultType="com.welampiot.dto.LampInfoDTO" parameterType="java.util.List">
  755. select
  756. L.id,
  757. L.address as sn,
  758. N.protocoltype,
  759. L.mode,
  760. L.control_type as controlType,
  761. from lampinfo L
  762. left join section as S on S.id = L.sectionid
  763. left join network as N on N.id = L.networkid
  764. where 1=1
  765. <if test="idList != null and !idList.isEmpty()">
  766. and L.id in
  767. <foreach item="vo" collection="idList" open="(" separator="," close=")">
  768. #{vo}
  769. </foreach>
  770. </if>
  771. </select>
  772. <select id="getLampPoleCountByVO" resultType="Integer" parameterType="com.welampiot.vo.LampCountVO">
  773. select count(*) from lampinfo L
  774. left join section as S on S.id = L.sectionid
  775. left join network as N on N.id = L.networkid
  776. where L.lamp_pole_id != 0
  777. <if test="sectionList != null and !sectionList.isEmpty()">
  778. and L.sectionid in
  779. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  780. #{vo}
  781. </foreach>
  782. </if>
  783. </select>
  784. <select id="areaInfoLampList" parameterType="com.welampiot.vo.LampListResponseVO" resultType="com.welampiot.dto.LampInfoDTO">
  785. select a.areaid as areaId,a.id,d.id as companyId from lampinfo a
  786. left join lamp_pole b on a.lamp_pole_id = b.id
  787. left join user c on b.create_id = c.id
  788. left join company d on d.id = c.company_id
  789. where a.lamp_pole_id != 0
  790. <if test="sectionList != null and !sectionList.isEmpty()">
  791. and a.sectionid in
  792. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  793. #{vo}
  794. </foreach>
  795. </if>
  796. </select>
  797. <select id="getLampListByLampPoleId" resultType="LampInfoDTO">
  798. select
  799. l.id,
  800. l.number
  801. from lampinfo l
  802. left join lamp_pole lp on l.lamp_pole_id = lp.id
  803. where l.lamp_pole_id = #{lampPoleId}
  804. </select>
  805. <select id="getLampPoleIdByLampId" resultType="Integer">
  806. select l.lamp_pole_id
  807. from lampinfo l
  808. where l.id = #{id}
  809. </select>
  810. <select id="getLampCountByLampPoleId" resultType="Integer">
  811. select count(*)
  812. from lampinfo l
  813. where l.lamp_pole_id = #{lampPoleId}
  814. </select>
  815. <update id="updateLampInfoForLoopId" parameterType="LampInfoDTO">
  816. update lampinfo l
  817. set
  818. l.loopid = #{loopId}
  819. where l.id = #{id}
  820. </update>
  821. <select id="getLampInfoListForGroup" resultType="LampInfoDTO">
  822. select
  823. l.id,
  824. l.number,
  825. n.status as networkStatus,
  826. l.status as lampStatus,
  827. l.lighteness,
  828. l1.gridcurr as `current`,
  829. l1.gridvolt as voltage,
  830. l1.grid_active_power as power,
  831. n.rssi,
  832. n.snr,
  833. n.protocoltype as protocolType,
  834. l.updatetime as updateTime,
  835. s.name as section,
  836. l1.work_time_total as lightTime
  837. <choose>
  838. <when test="version == 0">
  839. ,gl.chinese_name as area
  840. </when>
  841. <when test="version == 1">
  842. ,gl.english_name as area
  843. </when>
  844. <otherwise>
  845. ,gl.ru_name as area
  846. </otherwise>
  847. </choose>
  848. from lampinfo l
  849. left join lamp_info_log_new l1 on l1.lampid = l.id
  850. left join network n on l.networkid = n.id
  851. left join section s on s.id = l.sectionid
  852. left join global_location gl on gl.id = s.pid
  853. where 1=1
  854. <if test="sectionList != null and !sectionList.isEmpty()">
  855. and l.sectionid in
  856. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  857. #{item}
  858. </foreach>
  859. </if>
  860. <if test="sectionId != null and sectionId != 0">
  861. and l.sectionid = #{secitonId}
  862. </if>
  863. </select>
  864. <select id="getAlarmAreaCountTop" resultType="LampInfoDTO">
  865. SELECT COUNT(*) AS alarmCount
  866. <choose>
  867. <when test="version == 0">
  868. ,a.chinese_name AS area
  869. </when>
  870. <when test="version == 1">
  871. ,a.english_name AS area
  872. </when>
  873. <otherwise>
  874. ,a.ru_name AS area
  875. </otherwise>
  876. </choose>
  877. FROM `lampinfo` l
  878. LEFT JOIN global_location a ON a.id = l.areaid
  879. WHERE l.faultstatus != 0 AND l.faultstatus != 128
  880. <if test="sectionList != null and !sectionList.isEmpty()">
  881. and l.sectionid IN
  882. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  883. #{item}
  884. </foreach>
  885. </if>
  886. GROUP BY l.areaid
  887. ORDER BY alarmCount DESC
  888. LIMIT 5
  889. </select>
  890. <select id="getLampEleUseSectionTop" resultType="LampInfoDTO">
  891. SELECT
  892. COUNT(l.id) as lampCount,
  893. s.name as section,
  894. SUM(a.total_gener_energy_cache) as consumption
  895. FROM lampinfo l
  896. LEFT JOIN section s ON s.id = l.sectionid
  897. LEFT JOIN lamp_info_log_new a ON a.lampid = l.id
  898. <if test="sectionList != null and !sectionList.isEmpty()">
  899. WHERE l.sectionid IN
  900. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  901. #{item}
  902. </foreach>
  903. </if>
  904. GROUP BY l.sectionid
  905. ORDER BY consumption DESC
  906. LIMIT 5
  907. </select>
  908. <select id="getLampInfoAlarmList" resultType="LampInfoDTO">
  909. SELECT
  910. a.stralarmtype AS alarmStr,
  911. a.updatetime AS updateTime,
  912. l.number,
  913. s.name AS section
  914. <choose>
  915. <when test="version == 0">
  916. ,gl.chinese_name AS area
  917. </when>
  918. <when test="version == 1">
  919. ,gl.english_name AS area
  920. </when>
  921. <otherwise>
  922. ,gl.ru_name AS area
  923. </otherwise>
  924. </choose>
  925. FROM lampinfo l
  926. LEFT JOIN section s ON s.id = l.sectionid
  927. LEFT JOIN global_location gl ON gl.id = s.pid
  928. LEFT JOIN
  929. (SELECT t1.*
  930. FROM all_alarm_info_log t1,
  931. (SELECT lampid,
  932. max(updatetime) AS maxtime
  933. FROM all_alarm_info_log
  934. GROUP BY lampid) t2
  935. WHERE t1.lampid = t2.lampid
  936. AND t1.updatetime = t2.maxtime) AS a ON a.lampid = l.id
  937. WHERE a.devType = 0
  938. <if test="sectionList != null and !sectionList.isEmpty()">
  939. AND l.sectionid IN
  940. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  941. #{item}
  942. </foreach>
  943. </if>
  944. ORDER BY a.updatetime DESC
  945. <if test="page >= 0 and count > 0">
  946. LIMIT #{page},#{count}
  947. </if>
  948. </select>
  949. <select id="getLampAlarmTotal" resultType="LampInfoDTO">
  950. SELECT
  951. COUNT(l.id) AS lampCount,
  952. DATE(a.updatetime) AS updateTime
  953. FROM lampinfo l
  954. LEFT JOIN
  955. (SELECT t1.*
  956. FROM all_alarm_info_log t1,
  957. (SELECT lampid, MAX(updatetime) AS maxtime FROM all_alarm_info_log ORDER BY lampid) t2
  958. WHERE t1.lampid = t2.lampid AND t1.updatetime = t2.maxtime) AS a ON a.lampid = l.id
  959. WHERE a.devType = 0 AND a.updatetime <![CDATA[ <= ]]> #{endDate} AND a.updatetime >= #{startDate}
  960. <if test="sectionList != null and !sectionList.isEmpty()">
  961. AND l.sectionid IN
  962. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  963. #{item}
  964. </foreach>
  965. </if>
  966. GROUP BY DATE(a.updatetime)
  967. ORDER BY DATE(a.updatetime) DESC
  968. </select>
  969. <select id="getComBySectionList" resultType="com.welampiot.dto.LampInfoLogNewDTO" parameterType="com.welampiot.vo.LampVO">
  970. select sum(b.day_gener_energy) as dayGeneraEnergy,
  971. sum(b.month_gener_energy_cache) as monthGeneraEnergyCache,
  972. sum(b.year_gener_energy_cache) as yearGeneraEnergyCache,
  973. sum(b.total_gener_energy_cache) as totalGeneraEnergyCache,
  974. sum(b.month_ele_save_cache) as monthEleSaveCache,
  975. sum(b.year_ele_save_cache) as yearEleSaveCache,
  976. sum(b.total_ele_save_cache) as totalEleSaveCache,
  977. sum(b.day_ele_save) as dayEleSave
  978. from lampinfo a
  979. left join lamp_info_log_new b on b.lampid = a.id
  980. where a.id is not null and b.day_gener_energy &lt; 50 and b.day_ele_save &lt; 50
  981. <if test="sectionList != null and !sectionList.isEmpty()">
  982. and a.sectionid in
  983. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  984. #{vo}
  985. </foreach>
  986. </if>
  987. </select>
  988. <select id="getAlarmCountByVO" resultType="int" parameterType="com.welampiot.vo.LampVO">
  989. select count(*)
  990. from lampinfo a
  991. where ((a.faultstatus != 0 and a.faultstatus != 128) or a.new_faultstatus != 0)
  992. <if test="sectionList != null and !sectionList.isEmpty()">
  993. and a.sectionid in
  994. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  995. #{vo}
  996. </foreach>
  997. </if>
  998. </select>
  999. <select id="getOnlineCountByVO" resultType="int" parameterType="com.welampiot.vo.LampVO">
  1000. select count(*)
  1001. from lampinfo a
  1002. left join network b on a.networkid = b.id
  1003. where b.status = 1
  1004. <if test="sectionList != null and !sectionList.isEmpty()">
  1005. and a.sectionid in
  1006. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  1007. #{vo}
  1008. </foreach>
  1009. </if>
  1010. </select>
  1011. </mapper>