LampMapper.xml 54 KB

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