LampMapper.xml 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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 as 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 as newFaultStatus,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.zegbee_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 as 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,lamp_ctrl_id
  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.zegbee_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 as 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="address != null">
  269. and L.address = #{address}
  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 and networkId !=0">
  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="address != null">
  291. and L.address = #{address}
  292. </if>
  293. <if test="id != null">
  294. and L.id != #{id}
  295. </if>
  296. <if test="macAddress != null">
  297. and L.macAddress = #{macAddress}
  298. </if>
  299. <if test="devAddr != null">
  300. and L.dev_addr = #{devAddr}
  301. </if>
  302. limit 1
  303. </select>
  304. <insert id="add" parameterType="com.welampiot.dto.LampInfoDTO" useGeneratedKeys="true" keyProperty="id"
  305. >
  306. insert into lampinfo(networkid,name,number,address,areaid,sectionid,longitude,latitude,createtime,ratedpower,control_type
  307. <if test="mode != null">,mode</if>
  308. <if test="lampPoleId != null">,lamp_pole_id</if>
  309. <if test="installDate != null">,install_date</if>
  310. <if test="expirationDate != null">,expiration_date</if>
  311. <if test="devAddr != null">,dev_addr</if>
  312. <if test="freqId != null">,freqId</if>
  313. <if test="loopNumber != null">,zegbee_section_id</if>
  314. )
  315. values
  316. (#{networkId},#{name},#{number},#{sn},#{areaId},#{sectionId},#{longitude},#{latitude},#{createTime},#{ratedPower},#{controlType}
  317. <if test="mode != null">,#{mode}</if>
  318. <if test="lampPoleId != null">,#{lampPoleId}</if>
  319. <if test="installDate != null">,#{installDate}</if>
  320. <if test="expirationDate != null">,#{expirationDate}</if>
  321. <if test="devAddr != null">,#{devAddr}</if>
  322. <if test="freqId != null">,#{freqId}</if>
  323. <if test="loopNumber != null">,#{zegbeeSectionId}</if>
  324. )
  325. </insert>
  326. <update id="update" parameterType="com.welampiot.dto.LampInfoDTO"
  327. >
  328. update lampinfo
  329. set
  330. networkid=#{networkId},
  331. name=#{name},
  332. number=#{number},
  333. address=#{sn},
  334. areaid=#{areaId},
  335. control_type=#{controlType},
  336. sectionid=#{sectionId},
  337. longitude=#{longitude},
  338. latitude=#{latitude},
  339. <if test="mode != null">mode=#{mode},</if>
  340. <if test="lampPoleId != null">lamp_pole_id=#{lampPoleId},</if>
  341. <if test="installDate != null">install_date=#{installDate},</if>
  342. <if test="expirationDate != null">expiration_date=#{expirationDate},</if>
  343. ratedpower=#{ratedPower}
  344. where id = #{id}
  345. </update>
  346. <select id="groupSelectLamp" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.LampListResponseVO">
  347. select
  348. L.number,
  349. L.id,
  350. L.address as sn,
  351. <choose>
  352. <when test="version == 1">
  353. G.english_name as area,
  354. </when>
  355. <when test="version == 2">
  356. G.ru_name as area,
  357. </when>
  358. <otherwise>
  359. G.chinese_name as area,
  360. </otherwise>
  361. </choose>
  362. S.name as section,
  363. S.timezone,
  364. L.lighteness,
  365. L.name,
  366. LI.gridvolt as voltage,
  367. LI.gridcurr as current,
  368. LI.grid_active_power as power,
  369. LI.work_time_total as lightTime,
  370. LI.used_energy_total as totalEnergy,
  371. LI.devicetime as cmdTime,
  372. LI.led_lux_value,LI.leakage_cur,
  373. N.status as networkStatus,
  374. L.status as lampStatus,
  375. L.online as lampOnline,
  376. N.rssi,
  377. N.snr,
  378. N.protocoltype,
  379. LI.updatetime as updateTime,
  380. L.faultstatus as faultStatus,
  381. L.mode,
  382. N.hw_version as hwVersion,
  383. N.sw_version as swVersion,
  384. L.control_type as controlType,
  385. L.macAddress,
  386. L.dev_addr as devAddr,
  387. L.bindStatus,
  388. L.policy_type as policyType,
  389. L.policyid as policyId,
  390. L.longitude,
  391. L.latitude,L.new_faultstatus as newFaultStatus
  392. from lampinfo L
  393. left join section as S on S.id = L.sectionid
  394. left join global_location as G on G.id = S.pid
  395. left join lamp_info_log_new as LI on LI.lampid = L.id
  396. left join network as N on N.id = L.networkid
  397. where 1=1
  398. <if test="sectionList != null and !sectionList.isEmpty()">
  399. and L.sectionid in
  400. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  401. #{vo}
  402. </foreach>
  403. </if>
  404. <if test="lampIds != null">
  405. and L.id in (#{lampIds})
  406. </if>
  407. </select>
  408. <delete id="deleteById">
  409. delete from lampinfo where id=#{id};
  410. </delete>
  411. <select id="getNavByVO" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.LampListResponseVO">
  412. select
  413. L.number,
  414. L.id,
  415. L.mode,
  416. N.protocoltype,
  417. L.areaid as areaId,
  418. L.control_type as controlType,
  419. L.height,
  420. L.dev_type as devType
  421. from lampinfo L
  422. left join network as N on N.id = L.networkid
  423. where 1=1
  424. <if test="sectionList != null and !sectionList.isEmpty()">
  425. and L.sectionid in
  426. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  427. #{vo}
  428. </foreach>
  429. </if>
  430. <if test="areaId != null and areaId != 0">
  431. and L.areaid = #{areaId}
  432. </if>
  433. <if test="sectionId != null and sectionId != 0">
  434. and L.sectionid = #{sectionId}
  435. </if>
  436. <if test="lampType != null and lampType == 1">
  437. and L.lamp_pole_id != 0
  438. </if>
  439. order by L.number asc,L.mode asc,L.createtime desc,L.id desc
  440. </select>
  441. <select id="getLampPoleDetailListByLampPoleId" resultType="com.welampiot.dto.LampInfoDTO" parameterType="int">
  442. select
  443. L.number,
  444. L.id,
  445. L.address as sn,
  446. L.address,
  447. L.areaid as areaId,
  448. L.sectionid as sectionId,
  449. L.name,
  450. N.protocoltype,
  451. L.control_type as controlType,
  452. L.macAddress,
  453. L.dev_addr as devAddr,
  454. L.longitude,
  455. L.latitude,L.install_date as installDate,L.expiration_date as expirationDate,L.ratedpower as ratedPower
  456. from lampinfo L
  457. left join section as S on S.id = L.sectionid
  458. left join network as N on N.id = L.networkid
  459. where lamp_pole_id=#{lampPoleId}
  460. </select>
  461. <select id="getLampInfoListByDTO" resultType="com.welampiot.dto.LampInfoDTO">
  462. select l.id,l.number,l.status,l.lighteness,n.status as netStatus,l1.grid_active_power as power,l.updatetime as updateTime,
  463. l1.gridvolt as voltage,l1.gridcurr as current,l1.gridPF,l1.used_energy_tonight as usedEnergyTonight,l1.work_time_total as lightTime,
  464. l.faultstatus as faultStatus,l.longitude,l.latitude,l.groupid as groupId,l.loopid as loopId,n.rssi,n.snr,l1.used_energy_total as usedEnergyTotal,
  465. l.control_type as controlType,l.colour_val as colourVal,a.id as alarmId,s.timezone
  466. from lampinfo l
  467. left join network n on l.networkid = n.id
  468. left join lamp_info_log_new l1 on l.id = l1.lampid
  469. left join all_alarm_info_log a on l.id = a.lampid
  470. left join section s on s.id = l.sectionid
  471. where 1=1
  472. <if test="keyword != null and keyword != ''">
  473. and (l.name like '%${keyword}%' or l.number like '%${keyword}%')
  474. </if>
  475. <if test="sectionList != null and !sectionList.isEmpty()">
  476. and l.sectionid in
  477. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  478. #{item}
  479. </foreach>
  480. </if>
  481. <choose>
  482. <when test="type == 5">
  483. and l.faultstatus != 0 and n.status = 1 and l.faultstatus != 128
  484. </when>
  485. <when test="type == 4">
  486. and n.status = 1
  487. </when>
  488. <when test="type == 3">
  489. and n.status = 0
  490. </when>
  491. <when test="type == 2">
  492. and n.status = 1 and l.status = 0
  493. </when>
  494. <when test="type == 1">
  495. and n.status = 1 and l.status = 1
  496. </when>
  497. </choose>
  498. <choose>
  499. <when test="alarmType == 16">
  500. and l.faultstatus = 16
  501. </when>
  502. <when test="alarmType == 8">
  503. and l.faultstatus = 8
  504. </when>
  505. <when test="alarmType == 4">
  506. and l.faultstatus = 4
  507. </when>
  508. <when test="alarmType == 2">
  509. and l.faultstatus = 2
  510. </when>
  511. <when test="alarmType == 1">
  512. and l.faultstatus = 1
  513. </when>
  514. <otherwise>
  515. and l.faultstatus = 0
  516. </otherwise>
  517. </choose>
  518. </select>
  519. <select id="getLampLocationByGroupId" resultType="com.welampiot.dto.LampInfoDTO">
  520. select l.latitude,l.longitude
  521. from lampinfo l
  522. left join `group` g on g.id = l.groupid
  523. where g.id = #{id}
  524. </select>
  525. <select id="getLampLocationByLoopId" resultType="com.welampiot.dto.LampInfoDTO">
  526. select l.latitude,l.longitude
  527. from lampinfo l
  528. left join `loop` l1 on l1.id = l.loopid
  529. where l1.id = #{id}
  530. </select>
  531. <!-- 灯控安装总数 -->
  532. <select id="getLampInstallTotalByDTO" resultType="Integer">
  533. select count(l.id)
  534. from lampinfo l
  535. where 1=1
  536. <if test="type != null and type == 2">
  537. and l.lamp_pole_id != 0
  538. </if>
  539. <if test="sectionList != null and !sectionList.isEmpty()">
  540. and l.sectionid in
  541. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  542. #{item}
  543. </foreach>
  544. </if>
  545. <if test="areaId != null and areaId != 0">
  546. and l.areaid = #{areaId}
  547. </if>
  548. <if test="sectionId != null and sectionId != 0">
  549. and l.sectionid = #{sectionId}
  550. </if>
  551. <if test="ratedPower != null">
  552. and l.ratedpower = #{ratedPower}
  553. </if>
  554. </select>
  555. <!-- 灯控亮灯数 -->
  556. <select id="getLampLightTotalByDTO" resultType="Integer">
  557. select count(l.id)
  558. from lampinfo l
  559. left join network n on l.networkid = n.id
  560. where n.status = 1 and l.status = 1
  561. <if test="type != null and type == 2">
  562. and l.lamp_pole_id != 0
  563. </if>
  564. <if test="sectionList != null and !sectionList.isEmpty()">
  565. and l.sectionid in
  566. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  567. #{item}
  568. </foreach>
  569. </if>
  570. <if test="areaId != null and areaId != 0">
  571. and l.areaid = #{areaId}
  572. </if>
  573. <if test="sectionId != null and sectionId != 0">
  574. and l.sectionid = #{sectionId}
  575. </if>
  576. </select>
  577. <!-- 灯控在线数 -->
  578. <select id="getLampOnlineTotalByDTO" resultType="Integer">
  579. select count(l.id)
  580. from lampinfo l
  581. left join network n on l.networkid = n.id
  582. where ((n.status = 1 and n.protocoltype != 11) or (n.protocoltype = 11 and l.online = 1 ))
  583. <if test="type != null and type == 2">
  584. and l.lamp_pole_id != 0
  585. </if>
  586. <if test="sectionList != null and !sectionList.isEmpty()">
  587. and l.sectionid in
  588. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  589. #{item}
  590. </foreach>
  591. </if>
  592. <if test="areaId != null and areaId != 0">
  593. and l.areaid = #{areaId}
  594. </if>
  595. <if test="sectionId != null and sectionId != 0">
  596. and l.sectionid = #{sectionId}
  597. </if>
  598. </select>
  599. <!-- 灯控故障数 -->
  600. <select id="getLampFaultTotalByDTO" resultType="Integer">
  601. select count(l.id)
  602. from lampinfo l
  603. left join network n on l.networkid = n.id
  604. where l.faultstatus != 0
  605. <if test="type != null and type == 2">
  606. and l.lamp_pole_id != 0
  607. </if>
  608. <if test="sectionList != null and !sectionList.isEmpty()">
  609. and l.sectionid in
  610. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  611. #{item}
  612. </foreach>
  613. </if>
  614. <if test="areaId != null and areaId != 0">
  615. and l.areaid = #{areaId}
  616. </if>
  617. <if test="sectionId != null and sectionId != 0">
  618. and l.sectionid = #{sectionId}
  619. </if>
  620. </select>
  621. <update id="changeLampLocationById" parameterType="LampInfoDTO">
  622. update
  623. lampinfo l
  624. set
  625. l.longitude = #{longitude},
  626. l.latitude = #{latitude}
  627. where l.id = #{id}
  628. </update>
  629. <select id="getSectionOfLampCountBySectionId" resultType="Integer">
  630. select count(l.id) as total
  631. from lampinfo l
  632. where l.sectionid = #{id}
  633. </select>
  634. <select id="getNameOrNumber" resultType="String">
  635. <choose>
  636. <when test="type == 0">
  637. select l.number
  638. from lampinfo l
  639. where l.id = #{value}
  640. </when>
  641. <when test="type == 1">
  642. select s.name
  643. from section s
  644. where s.id = #{value}
  645. </when>
  646. <when test="type == 2">
  647. select
  648. <choose>
  649. <when test="version == 0">
  650. g.chinese_name
  651. </when>
  652. <when test="version == 1">
  653. g.english_name
  654. </when>
  655. <otherwise>
  656. g.ru_name
  657. </otherwise>
  658. </choose>
  659. from global_location g
  660. where g.id = #{value}
  661. </when>
  662. </choose>
  663. </select>
  664. <select id="getLampInfoDTOById" resultType="com.welampiot.dto.LampInfoDTO">
  665. select l.id,l.number
  666. from lampinfo l
  667. where l.id = #{id}
  668. </select>
  669. <select id="getLampList" resultType="com.welampiot.dto.LampInfoDTO">
  670. select
  671. l.id,l.lamp_pole_id as lampPoleId,lp.name as lampPoleName,w.num as sn,s.name as section,l.number,l.name
  672. <choose>
  673. <when test="version == 0">
  674. ,gl.chinese_name as area
  675. </when>
  676. <when test="version == 1">
  677. ,gl.english_name as area
  678. </when>
  679. <otherwise>
  680. ,gl.ru_name as area
  681. </otherwise>
  682. </choose>
  683. ,n.status,l.lighteness,l1.gridcurr as current,l1.gridvolt as voltage,n.protocoltype as protocolType,
  684. l1.grid_active_power as power,l.address,l.updatetime as updateTime,l.install_date as installDate,l.online as lampOnline,
  685. l.expiration_date as expirationDate,p.name as policyName,l1.devicetime as serverTime,l1.work_time_total as lightTime
  686. from lampinfo l
  687. left join lamp_pole lp on l.lamp_pole_id = lp.id
  688. left join wifi w on lp.id = w.lamp_pole_id
  689. left join section s on l.sectionid = s.id
  690. left join global_location gl on gl.id = l.areaid
  691. left join network n on l.networkid = n.id
  692. left join lamp_info_log_new l1 on l1.lampid = l.id
  693. left join policy p on l.policyid = p.id
  694. where 1=1
  695. <if test="sectionList != null and !sectionList.isEmpty()">
  696. and l.sectionid in
  697. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  698. #{item}
  699. </foreach>
  700. </if>
  701. <if test="areaId != null and areaId != 0">
  702. and l.areaid = #{areaId}
  703. </if>
  704. <if test="sectionId != null and sectionId != 0">
  705. and l.sectionid = #{sectionId}
  706. </if>
  707. <if test="keyword != null and keyword != ''">
  708. and (l.number like '%${keyword}%' or l.address like '%${keyword}%')
  709. </if>
  710. <choose>
  711. <when test="online == 1">
  712. and n.status = 0
  713. </when>
  714. <when test="online == 2">
  715. and n.status = 1
  716. </when>
  717. </choose>
  718. <if test="page >= 0 and count > 0">
  719. limit #{page},#{count}
  720. </if>
  721. </select>
  722. <select id="getLampTotal" resultType="Integer">
  723. select count(*)
  724. from lampinfo l
  725. where 1=1
  726. <if test="sectionList != null and !sectionList.isEmpty()">
  727. and l.sectionid in
  728. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  729. #{item}
  730. </foreach>
  731. </if>
  732. <if test="areaId != null and areaId != 0">
  733. and l.areaid = #{areaId}
  734. </if>
  735. <if test="sectionId != null and sectionId != 0">
  736. and l.sectionid = #{sectionId}
  737. </if>
  738. </select>
  739. <select id="getCityLampCount" resultType="Integer">
  740. select count(*)
  741. from lampinfo l
  742. left join section s on l.sectionid = s.id
  743. left join global_location gl on s.pid = gl.id
  744. left join global_location gl1 on gl.pid = gl1.id
  745. where gl1.id = #{id}
  746. </select>
  747. <select id="getLampDataByLampIds" resultType="LampInfoDTO">
  748. select
  749. l.name,
  750. l.address,
  751. l.number,
  752. l.lighteness,
  753. l.status,
  754. l.control_type as controlType,
  755. n.status as `online`,
  756. l.power,
  757. l.mode,
  758. n.protocoltype as protocolType
  759. from lampinfo l
  760. left join network n on l.networkid = n.id
  761. where l.id in
  762. <foreach collection="lampIds" item="item" open="(" separator="," close=")">
  763. #{item}
  764. </foreach>
  765. </select>
  766. <update id="updateLight" parameterType="com.welampiot.dto.LampInfoDTO"
  767. >
  768. update lampinfo
  769. set
  770. lighteness=#{lighteness}
  771. <if test="policyId != null">,policyid=#{policyId}</if>
  772. <if test="policyType != null">,policy_type=#{policyType}</if>
  773. <if test="lighteness > 0">,status=1</if>
  774. <if test="lighteness == 0">,status=0</if>
  775. <if test="updateTime != null">,updatetime=#{updateTime}</if>
  776. where id = #{id}
  777. </update>
  778. <select id="getListByIdList" resultType="com.welampiot.dto.LampInfoDTO" parameterType="java.util.List">
  779. select
  780. L.id,
  781. L.address as sn,
  782. N.protocoltype,
  783. L.mode,
  784. L.control_type as controlType,
  785. from lampinfo L
  786. left join section as S on S.id = L.sectionid
  787. left join network as N on N.id = L.networkid
  788. where 1=1
  789. <if test="idList != null and !idList.isEmpty()">
  790. and L.id in
  791. <foreach item="vo" collection="idList" open="(" separator="," close=")">
  792. #{vo}
  793. </foreach>
  794. </if>
  795. </select>
  796. <select id="getLampPoleCountByVO" resultType="Integer" parameterType="com.welampiot.vo.LampCountVO">
  797. select count(*) from lampinfo L
  798. left join section as S on S.id = L.sectionid
  799. left join network as N on N.id = L.networkid
  800. where L.lamp_pole_id != 0
  801. <if test="sectionList != null and !sectionList.isEmpty()">
  802. and L.sectionid in
  803. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  804. #{vo}
  805. </foreach>
  806. </if>
  807. </select>
  808. <select id="areaInfoLampList" parameterType="com.welampiot.vo.LampListResponseVO" resultType="com.welampiot.dto.LampInfoDTO">
  809. select a.areaid as areaId,a.id,d.id as companyId from lampinfo a
  810. left join lamp_pole b on a.lamp_pole_id = b.id
  811. left join user c on b.create_id = c.id
  812. left join company d on d.id = c.company_id
  813. where a.lamp_pole_id != 0
  814. <if test="sectionList != null and !sectionList.isEmpty()">
  815. and a.sectionid in
  816. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  817. #{vo}
  818. </foreach>
  819. </if>
  820. </select>
  821. <select id="getLampListByLampPoleId" resultType="LampInfoDTO">
  822. select
  823. l.id,
  824. l.number
  825. from lampinfo l
  826. left join lamp_pole lp on l.lamp_pole_id = lp.id
  827. where l.lamp_pole_id = #{lampPoleId}
  828. </select>
  829. <select id="getLampPoleIdByLampId" resultType="Integer">
  830. select l.lamp_pole_id
  831. from lampinfo l
  832. where l.id = #{id}
  833. </select>
  834. <select id="getLampCountByLampPoleId" resultType="Integer">
  835. select count(*)
  836. from lampinfo l
  837. where l.lamp_pole_id = #{lampPoleId}
  838. </select>
  839. <update id="updateLampInfoForLoopId" parameterType="LampInfoDTO">
  840. update lampinfo l
  841. set
  842. l.loopid = #{loopId}
  843. where l.id = #{id}
  844. </update>
  845. <select id="getLampInfoListForGroup" resultType="LampInfoDTO">
  846. select
  847. l.id,
  848. l.number,
  849. n.status as networkStatus,
  850. l.status as lampStatus,
  851. l.lighteness,
  852. l1.gridcurr as `current`,
  853. l1.gridvolt as voltage,
  854. l1.grid_active_power as power,
  855. n.rssi,
  856. n.snr,
  857. n.protocoltype as protocolType,
  858. l.updatetime as updateTime,
  859. s.name as section,
  860. l1.work_time_total as lightTime
  861. <choose>
  862. <when test="version == 0">
  863. ,gl.chinese_name as area
  864. </when>
  865. <when test="version == 1">
  866. ,gl.english_name as area
  867. </when>
  868. <otherwise>
  869. ,gl.ru_name as area
  870. </otherwise>
  871. </choose>
  872. from lampinfo l
  873. left join lamp_info_log_new l1 on l1.lampid = l.id
  874. left join network n on l.networkid = n.id
  875. left join section s on s.id = l.sectionid
  876. left join global_location gl on gl.id = s.pid
  877. where 1=1
  878. <if test="sectionList != null and !sectionList.isEmpty()">
  879. and l.sectionid in
  880. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  881. #{item}
  882. </foreach>
  883. </if>
  884. <if test="sectionId != null and sectionId != 0">
  885. and l.sectionid = #{secitonId}
  886. </if>
  887. </select>
  888. <select id="getAlarmAreaCountTop" resultType="LampInfoDTO">
  889. SELECT COUNT(*) AS alarmCount
  890. <choose>
  891. <when test="version == 0">
  892. ,a.chinese_name AS area
  893. </when>
  894. <when test="version == 1">
  895. ,a.english_name AS area
  896. </when>
  897. <otherwise>
  898. ,a.ru_name AS area
  899. </otherwise>
  900. </choose>
  901. FROM `lampinfo` l
  902. LEFT JOIN global_location a ON a.id = l.areaid
  903. WHERE l.faultstatus != 0 AND l.faultstatus != 128
  904. <if test="sectionList != null and !sectionList.isEmpty()">
  905. and l.sectionid IN
  906. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  907. #{item}
  908. </foreach>
  909. </if>
  910. GROUP BY l.areaid
  911. ORDER BY alarmCount DESC
  912. LIMIT 5
  913. </select>
  914. <select id="getLampEleUseSectionTop" resultType="LampInfoDTO">
  915. SELECT
  916. COUNT(l.id) as lampCount,
  917. s.name as section,
  918. SUM(a.total_gener_energy_cache) as consumption
  919. FROM lampinfo l
  920. LEFT JOIN section s ON s.id = l.sectionid
  921. LEFT JOIN lamp_info_log_new a ON a.lampid = l.id
  922. <if test="sectionList != null and !sectionList.isEmpty()">
  923. WHERE l.sectionid IN
  924. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  925. #{item}
  926. </foreach>
  927. </if>
  928. GROUP BY l.sectionid
  929. ORDER BY consumption DESC
  930. LIMIT 5
  931. </select>
  932. <select id="getLampInfoAlarmList" resultType="LampInfoDTO">
  933. SELECT
  934. a.stralarmtype AS alarmStr,
  935. a.updatetime AS updateTime,
  936. l.number,
  937. s.name AS section
  938. <choose>
  939. <when test="version == 0">
  940. ,gl.chinese_name AS area
  941. </when>
  942. <when test="version == 1">
  943. ,gl.english_name AS area
  944. </when>
  945. <otherwise>
  946. ,gl.ru_name AS area
  947. </otherwise>
  948. </choose>
  949. FROM lampinfo l
  950. LEFT JOIN section s ON s.id = l.sectionid
  951. LEFT JOIN global_location gl ON gl.id = s.pid
  952. LEFT JOIN
  953. (SELECT t1.*
  954. FROM all_alarm_info_log t1,
  955. (SELECT lampid,
  956. max(updatetime) AS maxtime
  957. FROM all_alarm_info_log
  958. GROUP BY lampid) t2
  959. WHERE t1.lampid = t2.lampid
  960. AND t1.updatetime = t2.maxtime) AS a ON a.lampid = l.id
  961. WHERE a.devType = 0
  962. <if test="sectionList != null and !sectionList.isEmpty()">
  963. AND l.sectionid IN
  964. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  965. #{item}
  966. </foreach>
  967. </if>
  968. ORDER BY a.updatetime DESC
  969. <if test="page >= 0 and count > 0">
  970. LIMIT #{page},#{count}
  971. </if>
  972. </select>
  973. <select id="getLampAlarmTotal" resultType="LampInfoDTO">
  974. SELECT
  975. COUNT(l.id) AS lampCount,
  976. DATE(a.updatetime) AS updateTime
  977. FROM lampinfo l
  978. LEFT JOIN
  979. (SELECT t1.*
  980. FROM all_alarm_info_log t1,
  981. (SELECT lampid, MAX(updatetime) AS maxtime FROM all_alarm_info_log ORDER BY lampid) t2
  982. WHERE t1.lampid = t2.lampid AND t1.updatetime = t2.maxtime) AS a ON a.lampid = l.id
  983. WHERE a.devType = 0 AND a.updatetime <![CDATA[ <= ]]> #{endDate} AND a.updatetime >= #{startDate}
  984. <if test="sectionList != null and !sectionList.isEmpty()">
  985. AND l.sectionid IN
  986. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  987. #{item}
  988. </foreach>
  989. </if>
  990. GROUP BY DATE(a.updatetime)
  991. ORDER BY DATE(a.updatetime) DESC
  992. </select>
  993. <select id="getComBySectionList" resultType="com.welampiot.dto.LampInfoLogNewDTO" parameterType="com.welampiot.vo.LampVO">
  994. select sum(b.day_gener_energy) as dayGeneraEnergy,
  995. sum(b.month_gener_energy_cache) as monthGeneraEnergyCache,
  996. sum(b.year_gener_energy_cache) as yearGeneraEnergyCache,
  997. sum(b.total_gener_energy_cache) as totalGeneraEnergyCache,
  998. sum(b.month_ele_save_cache) as monthEleSaveCache,
  999. sum(b.year_ele_save_cache) as yearEleSaveCache,
  1000. sum(b.total_ele_save_cache) as totalEleSaveCache,
  1001. sum(b.day_ele_save) as dayEleSave
  1002. from lampinfo a
  1003. left join lamp_info_log_new b on b.lampid = a.id
  1004. where a.id is not null and b.day_gener_energy &lt; 50 and b.day_ele_save &lt; 50
  1005. <if test="sectionList != null and !sectionList.isEmpty()">
  1006. and a.sectionid in
  1007. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  1008. #{vo}
  1009. </foreach>
  1010. </if>
  1011. </select>
  1012. <select id="getAlarmCountByVO" resultType="int" parameterType="com.welampiot.vo.LampVO">
  1013. select count(*)
  1014. from lampinfo a
  1015. where ((a.faultstatus != 0 and a.faultstatus != 128) or a.new_faultstatus != 0)
  1016. <if test="sectionList != null and !sectionList.isEmpty()">
  1017. and a.sectionid in
  1018. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  1019. #{vo}
  1020. </foreach>
  1021. </if>
  1022. </select>
  1023. <select id="getOnlineCountByVO" resultType="int" parameterType="com.welampiot.vo.LampVO">
  1024. select count(*)
  1025. from lampinfo a
  1026. left join network b on a.networkid = b.id
  1027. where b.status = 1
  1028. <if test="sectionList != null and !sectionList.isEmpty()">
  1029. and a.sectionid in
  1030. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  1031. #{vo}
  1032. </foreach>
  1033. </if>
  1034. <if test="status == 1">
  1035. and a.status = #{status}
  1036. </if>
  1037. </select>
  1038. <select id="getMapDataByVO" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.MapDataVO">
  1039. select L.id,L.number,L.longitude,L.latitude,N.status as netStatus,
  1040. <choose>
  1041. <when test="version == 1">
  1042. A.english_name as area,
  1043. </when>
  1044. <when test="version == 2">
  1045. A.ru_name as area,
  1046. </when>
  1047. <otherwise>
  1048. A.chinese_name as area,
  1049. </otherwise>
  1050. </choose>
  1051. S.name as section,L.status,L.lighteness,LI.gridvolt as voltage,LI.gridcurr as current,LI.day_gener_energy as dayConsumption,LI.work_time_total as lightTime,LI.updatetime as updateTime,L.loopid,LI.grid_active_power as power,N.rssi,N.snr,L.faultstatus as faultStatus,L.new_faultstatus as newFaultStatus,AI.stralarmtype,LO.name as loopName,AI.id as alarmId,L.name,L.install_date as installDate,L.expiration_date as expirationDate
  1052. from lampinfo L
  1053. left join network N on L.networkid = N.id
  1054. left join section S on L.sectionid = S.id
  1055. left join global_location A on A.id = S.pid
  1056. left join `loop` LO on LO.id = L.loopid
  1057. left join policy P on P.id = L.policyid
  1058. left join lamp_info_log_new LI on L.id = LI.lampid
  1059. 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) AI on L.id = AI.lampid
  1060. where L.lamp_pole_id = 0
  1061. <if test="sectionList != null and !sectionList.isEmpty()">
  1062. and L.sectionid in
  1063. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  1064. #{vo}
  1065. </foreach>
  1066. </if>
  1067. <if test="keyword != null and !keyword.isEmpty()">
  1068. and L.number like '%${keyword}%'
  1069. </if>
  1070. <choose>
  1071. <when test="!lngLow.isEmpty() and !lngHigh.isEmpty() and Double.parseDouble(lngLow) > Double.parseDouble(lngHigh)">
  1072. and ((L.longitude >= #{lngLow} and L.longitude &lt;= 180) or (L.longitude &lt;= #{lngLow} and L.longitude >= -180))
  1073. </when>
  1074. <otherwise>
  1075. <if test="!lngLow.isEmpty()">
  1076. and L.longitude >= #{lngLow}
  1077. </if>
  1078. <if test="!lngHigh.isEmpty()">
  1079. and L.longitude &lt;= #{lngHigh}
  1080. </if>
  1081. </otherwise>
  1082. </choose>
  1083. <if test="!latLow.isEmpty()">
  1084. and L.latitude >= #{latLow}
  1085. </if>
  1086. <if test="!latHigh.isEmpty()">
  1087. and L.latitude &lt;= #{latHigh}
  1088. </if>
  1089. group by L.id
  1090. </select>
  1091. <select id="getNewMapDataByVO" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.MapDataVO">
  1092. select L.id,L.number,L.longitude,L.latitude,N.status as netStatus,L.status,L.lighteness as light,N.rssi,N.snr,L.faultstatus,L.name
  1093. from lampinfo L
  1094. left join network N on L.networkid = N.id
  1095. where L.lamp_pole_id = 0
  1096. <if test="sectionList != null and !sectionList.isEmpty()">
  1097. and L.sectionid in
  1098. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  1099. #{vo}
  1100. </foreach>
  1101. </if>
  1102. <if test="keyword != null and !keyword.isEmpty()">
  1103. and L.number like '%${keyword}%'
  1104. </if>
  1105. <choose>
  1106. <when test="!lngLow.isEmpty() and !lngHigh.isEmpty() and Double.parseDouble(lngLow) > Double.parseDouble(lngHigh)">
  1107. and ((L.longitude <![CDATA[ >= ]]> #{lngLow} and L.longitude <![CDATA[ <= ]]> 180) or (L.longitude <![CDATA[ <= ]]> #{lngLow} and L.longitude <![CDATA[ >= ]]> -180))
  1108. </when>
  1109. <otherwise>
  1110. <if test="!lngLow.isEmpty()">
  1111. and L.longitude <![CDATA[ >= ]]> #{lngLow}
  1112. </if>
  1113. <if test="!lngHigh.isEmpty()">
  1114. and L.longitude <![CDATA[ <= ]]> #{lngHigh}
  1115. </if>
  1116. </otherwise>
  1117. </choose>
  1118. <if test="!latLow.isEmpty()">
  1119. and L.latitude <![CDATA[ >= ]]> #{latLow}
  1120. </if>
  1121. <if test="!latHigh.isEmpty()">
  1122. and L.latitude <![CDATA[ <= ]]> #{latHigh}
  1123. </if>
  1124. group by L.id
  1125. </select>
  1126. <!-- 灯控路段故障数前十 -->
  1127. <select id="getLampSectionAlarmCountTop" resultType="LampInfoDTO">
  1128. SELECT
  1129. COUNT(b.id) as total,
  1130. s.name
  1131. FROM
  1132. lampinfo b
  1133. LEFT JOIN section s on b.sectionid = s.id,
  1134. (
  1135. SELECT
  1136. t1.lampid AS lampId
  1137. FROM
  1138. all_alarm_info_log t1,
  1139. (
  1140. SELECT
  1141. l.id,
  1142. a.id AS alarmId,
  1143. MAX( a.id ) AS maxId,
  1144. MAX( a.updatetime ) AS maxTime,
  1145. a.lampid,
  1146. a.`status`,
  1147. a.devType
  1148. FROM
  1149. lampinfo l
  1150. LEFT JOIN
  1151. all_alarm_info_log a ON a.lampid = l.id
  1152. WHERE
  1153. a.devType = 0
  1154. <if test="sectionList != null and !sectionList.isEmpty()">
  1155. AND l.sectionid IN
  1156. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  1157. #{item}
  1158. </foreach>
  1159. </if>
  1160. <if test="areaId != null and areaId != 0">
  1161. AND l.areaid = #{areaId}
  1162. </if>
  1163. <if test="sectionId != null and sectionId != 0">
  1164. AND l.sectionid = #{sectionId}
  1165. </if>
  1166. GROUP BY
  1167. a.lampid
  1168. ) t2
  1169. WHERE
  1170. t1.id = t2.maxId
  1171. AND t1.`status` != 2
  1172. ) t3
  1173. WHERE
  1174. b.id = t3.lampId
  1175. GROUP BY b.sectionid
  1176. ORDER BY total DESC
  1177. LIMIT 10
  1178. </select>
  1179. <!-- 智诺云·智慧灯杆-设备组件:灯控设备组件 -->
  1180. <select id="getLampOfLampPoleById" resultType="lampInfoDTO">
  1181. select l.id as lampId,l2.gridvolt as gridVolt,l2.gridcurr as gridCurr,l.id,lp.createtime as createTime,
  1182. l2.grid_active_power as gridActivePower,l2.gridPF,l2.work_time_total as workTimeTotal,
  1183. l2.total_gener_energy_cache as usedEnergyTotal,l2.total_ele_save_cache as powerSave,
  1184. p.name as policyName,l.lighteness,l.colour_val as colourVal,l.status,l.control_type as controlType
  1185. from lampinfo l
  1186. left join lamp_pole lp on l.lamp_pole_id = lp.id
  1187. left join lamp_info_log_new l2 on l2.lampid = l.id
  1188. left join policy p on p.id = l.policyid
  1189. where l.lamp_pole_id = #{lampPoleId}
  1190. <if test="lampId != null and lampId != 0">
  1191. and l.id = #{lampId}
  1192. </if>
  1193. </select>
  1194. <!-- 根据设备地址查找灯控设备信息 -->
  1195. <select id="findLampDeviceBySn" resultType="LampInfoDTO">
  1196. select l.id,n.protocoltype as protocolType,l.control_type as controlType,
  1197. s.name as section,n.status as `online`,l1.gridvolt as voltage,l1.gridcurr as `current`,
  1198. l1.grid_active_power as power,l1.gridPF,l.lighteness,l1.devicetime as cmdTime,l1.updatetime as updateTime,
  1199. l1.total_gener_energy_cache as totalEnergy,l1.work_time_total as lightTime
  1200. <choose>
  1201. <when test="version == 0">
  1202. ,g1.chinese_name as area,g2.chinese_name as city,g3.chinese_name as province
  1203. </when>
  1204. <when test="version == 1">
  1205. ,g1.english_name as area,g2.english_name as city,g3.english_name as province
  1206. </when>
  1207. <otherwise>
  1208. ,g1.ru_name as area,g2.ru_name as city,g3.ru_name as province
  1209. </otherwise>
  1210. </choose>
  1211. from lampinfo l
  1212. left join lamp_info_log_new l1 on l1.lampid = l.id
  1213. left join network n on n.id = l.networkid
  1214. left join section s on l.sectionid = s.id
  1215. left join global_location g1 on s.pid = g1.id
  1216. left join global_location g2 on g1.pid = g2.id
  1217. left join global_location g3 on g2.pid = g3.id
  1218. where l.address = #{address}
  1219. </select>
  1220. <select id="getDataByVO" resultType="LampInfoDTO">
  1221. select id,address,sectionid as sectionId,number,networkid as networkId from lampinfo
  1222. <trim prefix="where" suffixOverrides="and|or">
  1223. <if test="id != null">
  1224. id = #{id} or
  1225. </if>
  1226. <if test="address != null and address != ''">
  1227. address = #{address} or
  1228. </if>
  1229. <if test="networkId != null and networkId != 0">
  1230. networkid = #{networkId} or
  1231. </if>
  1232. <if test="macAddress != null and macAddress != ''">
  1233. macAddress = #{macAddress} or
  1234. </if>
  1235. </trim>
  1236. limit 0,1
  1237. </select>
  1238. <select id="getListByDto" resultType="LampInfoDTO">
  1239. select id,address,mode,control_type as controlType,dev_addr as devAddr from lampinfo
  1240. <trim prefix="where" suffixOverrides="and|or">
  1241. <if test="id != null">
  1242. id = #{id} or
  1243. </if>
  1244. <if test="address != null and macAddress != ''">
  1245. address = #{address} and macAddress = #{macAddress} or
  1246. </if>
  1247. </trim>
  1248. limit 0,2
  1249. </select>
  1250. <insert id="addByDto" parameterType="com.welampiot.dto.LampInfoDTO" useGeneratedKeys="true" keyProperty="id"
  1251. >
  1252. insert into lampinfo(networkid,name,number,address,areaid,sectionid,longitude,latitude,createtime,ratedpower,control_type
  1253. <if test="macAddress != null">,macAddress</if>
  1254. <if test="mode != null">,mode</if>
  1255. <if test="lampPoleId != null and lampPoleId != 0">,lamp_pole_id</if>
  1256. <if test="installDate != null">,install_date</if>
  1257. <if test="expirationDate != null">,expiration_date</if>
  1258. <if test="devAddr != null and devAddr != 0">,dev_addr</if>
  1259. <if test="freqId != null">,freqId</if>
  1260. <if test="loopNumber != null">,zegbee_section_id</if>
  1261. <if test="bindStatus != null">,bindStatus</if>
  1262. )
  1263. values
  1264. (#{networkId},#{name},#{number},#{address},#{areaId},#{sectionId},#{longitude},#{latitude},#{createTime},#{ratedPower},#{controlType}
  1265. <if test="macAddress != null">,#{macAddress}</if>
  1266. <if test="mode != null">,#{mode}</if>
  1267. <if test="lampPoleId != null and lampPoleId != 0">,#{lampPoleId}</if>
  1268. <if test="installDate != null">,#{installDate}</if>
  1269. <if test="expirationDate != null">,#{expirationDate}</if>
  1270. <if test="devAddr != null and devAddr != 0">,#{devAddr}</if>
  1271. <if test="freqId != null">,#{freqId}</if>
  1272. <if test="loopNumber != null">,#{zegbeeSectionId}</if>
  1273. <if test="bindStatus != null">,#{bindStatus}</if>
  1274. )
  1275. </insert>
  1276. <update id="updateById" parameterType="com.welampiot.dto.LampInfoDTO"
  1277. >
  1278. update lampinfo
  1279. set
  1280. networkid=#{networkId},
  1281. name=#{name},
  1282. number=#{number},
  1283. address=#{address},
  1284. areaid=#{areaId},
  1285. control_type=#{controlType},
  1286. sectionid=#{sectionId},
  1287. longitude=#{longitude},
  1288. latitude=#{latitude}
  1289. <if test="mode != null">,mode=#{mode}</if>
  1290. <if test="lampPoleId != null and lampPoleId != 0">,lamp_pole_id=#{lampPoleId}</if>
  1291. <if test="installDate != null">,install_date=#{installDate}</if>
  1292. <if test="expirationDate != null">,expiration_date=#{expirationDate}</if>
  1293. <if test="ratedpower != null and ratedpower != 0">,ratedpower=#{ratedPower}</if>
  1294. where id = #{id}
  1295. </update>
  1296. <select id="getOneData" parameterType="HashMap" resultType="LampInfoDTO">
  1297. select id,name,address,mode
  1298. from lampinfo
  1299. where areaid = #{areaId} and sectionid = #{sectionId}
  1300. <if test="name != null">
  1301. and name = #{name}
  1302. </if>
  1303. <if test="number != null">
  1304. and number = #{number}
  1305. </if>
  1306. <if test="mode != null">
  1307. and mode = #{mode}
  1308. </if>
  1309. </select>
  1310. <select id="getLampJoinLogList" parameterType="Integer" resultType="LampInfoDTO">
  1311. select a.lighteness,a.usedEnergyTotal,a.power_save as powerSave,b.work_time_total as workTimeTotal,a.policy_type as policyType,a.policyid as policyId,a.number,a.id from lampinfo a left join lamp_info_log_new b on a.id = b.lampid where a.lamp_pole_id = #{id} order by a.id desc
  1312. </select>
  1313. <select id="getLampLocaltion" resultType="LampInfoDTO" parameterType="LampInfoDTO">
  1314. select id,longitude,latitude,number from lampinfo
  1315. <trim prefix="where" suffixOverrides="and|or">
  1316. <if test="lampPoleId == 0">
  1317. lamp_pole_id = #{lampPoleId} and
  1318. </if>
  1319. <if test="sectionList != null and !sectionList.isEmpty()">
  1320. sectionid IN
  1321. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  1322. #{item}
  1323. </foreach>
  1324. </if>
  1325. </trim>
  1326. </select>
  1327. <select id="getLampById" resultType="LampInfoDTO">
  1328. select lighteness,colour_val as colourVal,power_save as powerSave,id,sectionid as sectionId
  1329. from lampinfo
  1330. where lamp_pole_id = #{id};
  1331. </select>
  1332. <select id="getLampListByIdList" resultType="com.welampiot.dto.LampInfoDTO">
  1333. select l.id,l.name,l.address,l.mode
  1334. from lampinfo l
  1335. where l.id in
  1336. <foreach collection="idList" item="item" open="(" separator="," close=")">
  1337. #{item}
  1338. </foreach>
  1339. </select>
  1340. </mapper>