LampMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. where 1=1
  52. <if test="sectionList != null and !sectionList.isEmpty()">
  53. and a.sectionid in
  54. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  55. #{vo}
  56. </foreach>
  57. </if>
  58. </select>
  59. <select id="getDayConsumptionByVO" resultType="Float" parameterType="com.welampiot.vo.LampCountVO">
  60. select sum(b.day_gener_energy) as consum
  61. from lampinfo a left join lamp_info_log_new b on a.id = b.lampid
  62. where 1=1
  63. <if test="sectionList != null and !sectionList.isEmpty()">
  64. and a.sectionid in
  65. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  66. #{vo}
  67. </foreach>
  68. </if>
  69. <if test="startDate != null and startDate != ''">
  70. and b.updatetime >= #{startDate}
  71. </if>
  72. </select>
  73. <select id="getConsumptionListByVO" resultType="com.welampiot.vo.LampLogVO" parameterType="com.welampiot.vo.LampCountVO">
  74. select * from (
  75. select sum(a.consum) as consumption,sum(a.powerSave) as powerSave,a.updatetime as updateTime
  76. from lamp_info_cache_by_day a left join lampinfo b on b.id = a.lampid
  77. where b.id is not null
  78. <if test="sectionList != null and !sectionList.isEmpty()">
  79. and a.sectionid in
  80. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  81. #{vo}
  82. </foreach>
  83. </if>
  84. <if test="startDate != null and startDate != ''">
  85. and a.updatetime >= #{startDate}
  86. </if>
  87. <if test="endDate != null and endDate != ''">
  88. and a.updatetime &lt;= #{endDate}
  89. </if>
  90. group by a.updatetime
  91. ) as t order by t.updatetime asc
  92. </select>
  93. <select id="getListByVO" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.LampListResponseVO">
  94. select
  95. L.number,
  96. L.id,
  97. L.address as sn,
  98. <choose>
  99. <when test="version == 1">
  100. G.english_name as area,
  101. </when>
  102. <when test="version == 2">
  103. G.ru_name as area,
  104. </when>
  105. <otherwise>
  106. G.chinese_name as area,
  107. </otherwise>
  108. </choose>
  109. S.name as section,
  110. S.timezone,
  111. L.lighteness,
  112. L.name,
  113. LI.gridvolt as voltage,
  114. LI.gridcurr as current,
  115. LI.grid_active_power as power,
  116. LI.work_time_total as lightTime,
  117. LI.used_energy_total as totalEnergy,
  118. LI.devicetime as cmdTime,
  119. LI.led_lux_value,LI.leakage_cur,
  120. N.status as networkStatus,
  121. L.status as lampStatus,
  122. L.online as lampOnline,
  123. N.rssi,
  124. N.snr,
  125. N.protocoltype,
  126. LI.updatetime as updateTime,
  127. L.faultstatus,
  128. L.mode,
  129. N.hw_version as hwVersion,
  130. N.sw_version as swVersion,
  131. L.control_type as controlType,
  132. L.macAddress,
  133. L.dev_addr as devAddr,
  134. L.bindStatus,
  135. L.policy_type as policyType,
  136. L.policyid,
  137. L.longitude,
  138. L.latitude,L.new_faultstatus,L.install_date,L.expiration_date,
  139. P.name as policyName,AI.status as alarmStatus,AI.id as alarmid,AI.stralarmtype,
  140. CD.dueDate,CD.workingCondition,CD.remainGprs,CD.useGprs,CD.totalGprs,CD.comboName,CD.comboType,CD.id as card_id
  141. from lampinfo L
  142. left join section as S on S.id = L.sectionid
  143. left join global_location as G on G.id = S.pid
  144. left join lamp_info_log_new as LI on LI.lampid = L.id
  145. left join network as N on N.id = L.networkid
  146. left join net_card_info as CD on N.id = CD.net_id
  147. left join policy as P on P.id = L.policyid
  148. 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
  149. where 1=1
  150. <if test="sectionList != null and !sectionList.isEmpty()">
  151. and L.sectionid in
  152. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  153. #{vo}
  154. </foreach>
  155. </if>
  156. <if test="online != null">
  157. 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)))
  158. </if>
  159. <if test="lightStatus != null">
  160. <if test="lightStatus == 0">
  161. AND ((N.status = 0 and N.protocoltype != 5) or (L.online = 0 and N.protocoltype = 5) or L.lighteness = 0)
  162. </if>
  163. <if test="lightStatus == 1">
  164. AND ((N.status = 1 and N.protocoltype != 5) or (L.online = 1 and N.protocoltype = 5)) and L.lighteness != 0
  165. </if>
  166. </if>
  167. <if test="keyword != null">
  168. AND (L.number like '%#{keyword}%' OR L.address like '%#{keyword}%' OR L.macAddress like '%#{keyword}%')
  169. </if>
  170. <if test="alarmType != null">
  171. AND L.faultstatus = #{alarmType}
  172. </if>
  173. <if test="lampPoleId != null">
  174. AND L.lamp_pole_id = #{lampPoleId}
  175. </if>
  176. order by L.number asc,L.mode asc,L.createtime desc,L.id desc
  177. <if test="offset != null and limit != null">
  178. limit #{offset},#{limit}
  179. </if>
  180. </select>
  181. <select id="getDetailsById" resultType="com.welampiot.dto.LampInfoDTO" parameterType="Integer">
  182. select
  183. L.number,
  184. L.id,
  185. L.address as sn,
  186. <choose>
  187. <when test="version == 1">
  188. GL.english_name as area,
  189. </when>
  190. <when test="version == 2">
  191. GL.ru_name as area,
  192. </when>
  193. <otherwise>
  194. GL.chinese_name as area,
  195. </otherwise>
  196. </choose>
  197. L.networkid as networkId,N.protocoltype as protocolType,L.areaid as areaId,
  198. L.sectionid as sectionId,L.groupid as groupId,L.longitude,L.latitude,S.name as section,L.dev_addr as devAddr,
  199. L.macAddress,L.section_id as loopNumber,G.name as `group`,N.network_name as network,N.rssi,
  200. L.lamp_pole_id as lampPoleId,LP.name as lampPoleName,L.control_type as controlType,
  201. 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,
  202. LI.gridPF,LI.used_energy_tonight as usedEnergyTonight,L.faultstatus,N.snr,N.rssi,AI.id as alarmId,
  203. AI.stralarmtype as alarmInfo,S.timezone,L.status as lampStatas,L.freqId,
  204. L.ratedpower as power,L.address as imei,N.simid,L.name,N.sw_version as solfVersion,
  205. N.hw_version as hardVersion,L.install_date,L.expiration_date,L.mode
  206. from lampinfo L
  207. left join section as S on S.id = L.sectionid
  208. left join global_location as GL on GL.id = S.pid
  209. left join lamp_info_log_new as LI on LI.lampid = L.id
  210. left join network as N on N.id = L.networkid
  211. left join net_card_info as CD on N.id = CD.net_id
  212. left join policy as P on P.id = L.policyid
  213. left join lamp_pole as LP on LP.id = L.lamp_pole_id
  214. left join `group` as G on G.id = L.groupid
  215. 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
  216. where L.id=#{id}
  217. </select>
  218. <select id="getDetailsByAddress" resultType="com.welampiot.dto.LampInfoDTO" parameterType="String">
  219. select
  220. L.number,
  221. L.id,
  222. L.address as sn,
  223. <choose>
  224. <when test="version == 1">
  225. GL.english_name as area,
  226. </when>
  227. <when test="version == 2">
  228. GL.ru_name as area,
  229. </when>
  230. <otherwise>
  231. GL.chinese_name as area,
  232. </otherwise>
  233. </choose>
  234. L.networkid as networkId,N.protocoltype as protocolType,L.areaid as areaId,
  235. L.sectionid as sectionId,L.groupid as groupId,L.longitude,L.latitude,S.name as section,L.dev_addr as devAddr,
  236. L.macAddress,L.section_id as loopNumber,G.name as `group`,N.network_name as network,N.rssi,
  237. L.lamp_pole_id as lampPoleId,LP.name as lampPoleName,L.control_type as controlType,
  238. 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,
  239. LI.gridPF,LI.used_energy_tonight as usedEnergyTonight,L.faultstatus,N.snr,N.rssi,AI.id as alarmId,
  240. AI.stralarmtype as alarmInfo,S.timezone,L.status as lampStatas,L.freqId,
  241. L.ratedpower as power,L.address as imei,N.simid,L.name,N.sw_version as solfVersion,
  242. N.hw_version as hardVersion,L.install_date,L.expiration_date
  243. from lampinfo L
  244. left join section as S on S.id = L.sectionid
  245. left join global_location as GL on GL.id = S.pid
  246. left join lamp_info_log_new as LI on LI.lampid = L.id
  247. left join network as N on N.id = L.networkid
  248. left join net_card_info as CD on N.id = CD.net_id
  249. left join policy as P on P.id = L.policyid
  250. left join lamp_pole as LP on LP.id = L.lamp_pole_id
  251. left join `group` as G on G.id = L.groupid
  252. 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
  253. where L.address=#{address}
  254. </select>
  255. <select id="findByVO" resultType="Integer" parameterType="com.welampiot.dto.LampInfoDTO">
  256. select count(*) from lampinfo L
  257. where 1=1
  258. <if test="sectionId != null">
  259. and L.sectionid = #{sectionId}
  260. </if>
  261. <if test="name != null">
  262. and L.name = #{name}
  263. </if>
  264. <if test="number != null">
  265. and L.number = #{number}
  266. </if>
  267. <if test="sn != null">
  268. and L.address = #{sn}
  269. </if>
  270. <if test="id != null">
  271. and L.id != #{id}
  272. </if>
  273. </select>
  274. <select id="checkData" resultType="Integer" parameterType="com.welampiot.dto.LampInfoDTO">
  275. select IFNULL(L.id,0) from lampinfo L
  276. where 1=1
  277. <if test="sectionId != null">
  278. and L.sectionid = #{sectionId}
  279. </if>
  280. <if test="networkId != null">
  281. and L.networkid != #{networkId}
  282. </if>
  283. <if test="name != null">
  284. and L.name = #{name}
  285. </if>
  286. <if test="number != null">
  287. and L.number = #{number}
  288. </if>
  289. <if test="sn != null">
  290. and L.address = #{sn}
  291. </if>
  292. <if test="id != null">
  293. and L.id != #{id}
  294. </if>
  295. limit 1
  296. </select>
  297. <insert id="add" parameterType="com.welampiot.dto.LampInfoDTO" useGeneratedKeys="true" keyProperty="id"
  298. >
  299. insert into lampinfo(networkid,name,number,address,areaid,sectionid,longitude,latitude,createtime,ratedpower,control_type
  300. <if test="mode != null">,mode</if>
  301. <if test="lampPoleId != null">,lamp_pole_id</if>
  302. <if test="installDate != null">,install_date</if>
  303. <if test="expirationDate != null">,expiration_date</if>
  304. )
  305. values
  306. (#{networkId},#{name},#{number},#{sn},#{areaId},#{sectionId},#{longitude},#{latitude},#{createTime},#{ratedPower},#{controlType}
  307. <if test="mode != null">,#{mode}</if>
  308. <if test="lampPoleId != null">,#{lampPoleId}</if>
  309. <if test="installDate != null">,#{installDate}</if>
  310. <if test="expirationDate != null">,#{expirationDate}</if>
  311. )
  312. </insert>
  313. <update id="update" parameterType="com.welampiot.dto.LampInfoDTO"
  314. >
  315. update lampinfo
  316. set
  317. networkid=#{networkId},
  318. name=#{name},
  319. number=#{number},
  320. address=#{sn},
  321. areaid=#{areaId},
  322. control_type=#{controlType},
  323. sectionid=#{sectionId},
  324. longitude=#{longitude},
  325. latitude=#{latitude},
  326. <if test="mode != null">mode=#{mode},</if>
  327. <if test="lampPoleId != null">lamp_pole_id=#{lampPoleId},</if>
  328. <if test="installDate != null">install_date=#{installDate},</if>
  329. <if test="expirationDate != null">expiration_date=#{expirationDate},</if>
  330. ratedpower=#{ratedPower}
  331. where id = #{id}
  332. </update>
  333. <select id="groupSelectLamp" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.LampListResponseVO">
  334. select
  335. L.number,
  336. L.id,
  337. L.address as sn,
  338. <choose>
  339. <when test="version == 1">
  340. G.english_name as area,
  341. </when>
  342. <when test="version == 2">
  343. G.ru_name as area,
  344. </when>
  345. <otherwise>
  346. G.chinese_name as area,
  347. </otherwise>
  348. </choose>
  349. S.name as section,
  350. S.timezone,
  351. L.lighteness,
  352. L.name,
  353. LI.gridvolt as voltage,
  354. LI.gridcurr as current,
  355. LI.grid_active_power as power,
  356. LI.work_time_total as lightTime,
  357. LI.used_energy_total as totalEnergy,
  358. LI.devicetime as cmdTime,
  359. LI.led_lux_value,LI.leakage_cur,
  360. N.status as networkStatus,
  361. L.status as lampStatus,
  362. L.online as lampOnline,
  363. N.rssi,
  364. N.snr,
  365. N.protocoltype,
  366. LI.updatetime as updateTime,
  367. L.faultstatus,
  368. L.mode,
  369. N.hw_version as hwVersion,
  370. N.sw_version as swVersion,
  371. L.control_type as controlType,
  372. L.macAddress,
  373. L.dev_addr as devAddr,
  374. L.bindStatus,
  375. L.policy_type as policyType,
  376. L.policyid,
  377. L.longitude,
  378. L.latitude,L.new_faultstatus
  379. from lampinfo L
  380. left join section as S on S.id = L.sectionid
  381. left join global_location as G on G.id = S.pid
  382. left join lamp_info_log_new as LI on LI.lampid = L.id
  383. left join network as N on N.id = L.networkid
  384. where 1=1
  385. <if test="sectionList != null and !sectionList.isEmpty()">
  386. and L.sectionid in
  387. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  388. #{vo}
  389. </foreach>
  390. </if>
  391. <if test="lampIds != null">
  392. and L.id in (#{lampIds})
  393. </if>
  394. </select>
  395. <delete id="deleteById">
  396. delete from lampinfo where id=#{id};
  397. </delete>
  398. <select id="getNavByVO" resultType="com.welampiot.dto.LampInfoDTO" parameterType="com.welampiot.vo.LampListResponseVO">
  399. select
  400. L.number,
  401. L.id,
  402. L.mode,
  403. N.protocoltype,
  404. L.control_type as controlType
  405. from lampinfo L
  406. left join network as N on N.id = L.networkid
  407. where 1=1
  408. <if test="sectionList != null and !sectionList.isEmpty()">
  409. and L.sectionid in
  410. <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
  411. #{vo}
  412. </foreach>
  413. </if>
  414. <if test="lampType != null and lampType == 1">
  415. and L.lamp_pole_id != 0
  416. </if>
  417. order by L.number asc,L.mode asc,L.createtime desc,L.id desc
  418. </select>
  419. <select id="getLampPoleDetailListByLampPoleId" resultType="com.welampiot.dto.LampInfoDTO" parameterType="int">
  420. select
  421. L.number,
  422. L.id,
  423. L.address as sn,
  424. L.address,
  425. L.areaid as areaId,
  426. L.sectionid as sectionId,
  427. L.name,
  428. N.protocoltype,
  429. L.control_type as controlType,
  430. L.macAddress,
  431. L.dev_addr as devAddr,
  432. L.longitude,
  433. L.latitude,L.install_date as installDate,L.expiration_date as expirationDate,L.ratedpower as ratedPower
  434. from lampinfo L
  435. left join section as S on S.id = L.sectionid
  436. left join network as N on N.id = L.networkid
  437. where lamp_pole_id=#{lampPoleId}
  438. </select>
  439. <select id="getLampInfoListByDTO" resultType="com.welampiot.dto.LampInfoDTO">
  440. select l.id,l.number,l.status,l.lighteness,n.status as netStatus,l1.grid_active_power as power,l.updatetime as updateTime,
  441. l1.gridvolt as voltage,l1.gridcurr as current,l1.gridPF,l1.used_energy_tonight as usedEnergyTonight,l1.work_time_total as lightTime,
  442. l.faultstatus,l.longitude,l.latitude,l.groupid as groupId,l.loopid as loopId,n.rssi,n.snr,l1.used_energy_total as usedEnergyTotal,
  443. l.control_type as controlType,l.colour_val as colourVal,a.id as alarmId,s.timezone
  444. from lampinfo l
  445. left join network n on l.networkid = n.id
  446. left join lamp_info_log_new l1 on l.id = l1.lampid
  447. left join all_alarm_info_log a on l.id = a.lampid
  448. left join section s on s.id = l.sectionid
  449. where 1=1
  450. <if test="keyword != null and keyword != ''">
  451. and (l.name like '%${keyword}%' or l.number like '%${keyword}%')
  452. </if>
  453. <if test="sectionList != null and !sectionList.isEmpty()">
  454. and l.sectionid in
  455. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  456. #{item}
  457. </foreach>
  458. </if>
  459. <choose>
  460. <when test="type == 5">
  461. and l.faultstatus != 0 and n.status = 1 and l.faultstatus != 128
  462. </when>
  463. <when test="type == 4">
  464. and n.status = 1
  465. </when>
  466. <when test="type == 3">
  467. and n.status = 0
  468. </when>
  469. <when test="type == 2">
  470. and n.status = 1 and l.status = 0
  471. </when>
  472. <when test="type == 1">
  473. and n.status = 1 and l.status = 1
  474. </when>
  475. </choose>
  476. <choose>
  477. <when test="alarmType == 16">
  478. and l.faultstatus = 16
  479. </when>
  480. <when test="alarmType == 8">
  481. and l.faultstatus = 8
  482. </when>
  483. <when test="alarmType == 4">
  484. and l.faultstatus = 4
  485. </when>
  486. <when test="alarmType == 2">
  487. and l.faultstatus = 2
  488. </when>
  489. <when test="alarmType == 1">
  490. and l.faultstatus = 1
  491. </when>
  492. <otherwise>
  493. and l.faultstatus = 0
  494. </otherwise>
  495. </choose>
  496. </select>
  497. <select id="getLampLocationByGroupId" resultType="com.welampiot.dto.LampInfoDTO">
  498. select l.latitude,l.longitude
  499. from lampinfo l
  500. left join `group` g on g.id = l.groupid
  501. where g.id = #{id}
  502. </select>
  503. <select id="getLampLocationByLoopId" resultType="com.welampiot.dto.LampInfoDTO">
  504. select l.latitude,l.longitude
  505. from lampinfo l
  506. left join `loop` l1 on l1.id = l.loopid
  507. where l1.id = #{id}
  508. </select>
  509. <!-- 灯控安装总数 -->
  510. <select id="getLampInstallTotalByDTO" resultType="Integer">
  511. select count(l.id)
  512. from lampinfo l
  513. where 1=1
  514. <if test="type != null and type == 2">
  515. and l.lamp_pole_id != 0
  516. </if>
  517. <if test="sectionList != null and !sectionList.isEmpty()">
  518. and l.sectionid in
  519. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  520. #{item}
  521. </foreach>
  522. </if>
  523. <if test="areaId != null and areaId != 0">
  524. and l.areaid = #{areaId}
  525. </if>
  526. <if test="sectionId != null and sectionId != 0">
  527. and l.sectionid = #{sectionId}
  528. </if>
  529. </select>
  530. <!-- 灯控亮灯数 -->
  531. <select id="getLampLightTotalByDTO" resultType="Integer">
  532. select count(l.id)
  533. from lampinfo l
  534. left join network n on l.networkid = n.id
  535. where n.status = 1 and l.status = 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. </select>
  552. <!-- 灯控在线数 -->
  553. <select id="getLampOnlineTotalByDTO" resultType="Integer">
  554. select count(l.id)
  555. from lampinfo l
  556. left join network n on l.networkid = n.id
  557. where n.status = 1
  558. <if test="type != null and type == 2">
  559. and l.lamp_pole_id != 0
  560. </if>
  561. <if test="sectionList != null and !sectionList.isEmpty()">
  562. and l.sectionid in
  563. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  564. #{item}
  565. </foreach>
  566. </if>
  567. <if test="areaId != null and areaId != 0">
  568. and l.areaid = #{areaId}
  569. </if>
  570. <if test="sectionId != null and sectionId != 0">
  571. and l.sectionid = #{sectionId}
  572. </if>
  573. </select>
  574. <!-- 灯控故障数 -->
  575. <select id="getLampFaultTotalByDTO" resultType="Integer">
  576. select count(l.id)
  577. from lampinfo l
  578. left join network n on l.networkid = n.id
  579. where n.status = 1 and l.faultstatus != 0 and l.faultstatus != 128
  580. <if test="type != null and type == 2">
  581. and l.lamp_pole_id != 0
  582. </if>
  583. <if test="sectionList != null and !sectionList.isEmpty()">
  584. and l.sectionid in
  585. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  586. #{item}
  587. </foreach>
  588. </if>
  589. <if test="areaId != null and areaId != 0">
  590. and l.areaid = #{areaId}
  591. </if>
  592. <if test="sectionId != null and sectionId != 0">
  593. and l.sectionid = #{sectionId}
  594. </if>
  595. </select>
  596. <update id="changeLampLocationById" parameterType="LampInfoDTO">
  597. update
  598. lampinfo l
  599. set
  600. l.longitude = #{longitude},
  601. l.latitude = #{latitude}
  602. where l.id = #{id}
  603. </update>
  604. <select id="getSectionOfLampCountBySectionId" resultType="Integer">
  605. select count(l.id) as total
  606. from lampinfo l
  607. where l.sectionid = #{id}
  608. </select>
  609. <select id="getNameOrNumber" resultType="String">
  610. <choose>
  611. <when test="type == 0">
  612. select l.number
  613. from lampinfo l
  614. where l.id = #{value}
  615. </when>
  616. <when test="type == 1">
  617. select s.name
  618. from section s
  619. where s.id = #{value}
  620. </when>
  621. <when test="type == 2">
  622. select
  623. <choose>
  624. <when test="version == 0">
  625. g.chinese_name
  626. </when>
  627. <when test="version == 1">
  628. g.english_name
  629. </when>
  630. <otherwise>
  631. g.ru_name
  632. </otherwise>
  633. </choose>
  634. from global_location g
  635. where g.id = #{value}
  636. </when>
  637. </choose>
  638. </select>
  639. <select id="getLampInfoDTOById" resultType="com.welampiot.dto.LampInfoDTO">
  640. select l.id,l.number
  641. from lampinfo l
  642. where l.id = #{id}
  643. </select>
  644. <select id="getLampList" resultType="com.welampiot.dto.LampInfoDTO">
  645. select
  646. l.id,l.lamp_pole_id as lampPoleId,lp.name as lampPoleName,w.num as sn,s.name as section,l.number,l.name
  647. <choose>
  648. <when test="version == 0">
  649. ,gl.chinese_name as area
  650. </when>
  651. <when test="version == 1">
  652. ,gl.english_name as area
  653. </when>
  654. <otherwise>
  655. ,gl.ru_name as area
  656. </otherwise>
  657. </choose>
  658. ,n.status,l.lighteness,l1.gridcurr as current,l1.gridvolt as voltage,n.protocoltype as protocolType,
  659. l1.grid_active_power as power,l.address,l.updatetime as updateTime,l.install_date as installDate,l.online as lampOnline,
  660. l.expiration_date as expirationDate,p.name as policyName,l1.devicetime as serverTime,l1.work_time_total as lightTime
  661. from lampinfo l
  662. left join lamp_pole lp on l.lamp_pole_id = lp.id
  663. left join wifi w on lp.id = w.lamp_pole_id
  664. left join section s on l.section_id = s.id
  665. left join global_location gl on gl.id = l.areaid
  666. left join network n on l.networkid = n.id
  667. left join lamp_info_log_new l1 on l1.lampid = l.id
  668. left join policy p on l.policyid = p.id
  669. where 1=1
  670. <if test="sectionList != null and !sectionList.isEmpty()">
  671. and l.sectionid in
  672. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  673. #{item}
  674. </foreach>
  675. </if>
  676. <if test="areaId != null and areaId != 0">
  677. and l.areaid = #{areaId}
  678. </if>
  679. <if test="sectionId != null and sectionId != 0">
  680. and l.sectionid = #{sectionId}
  681. </if>
  682. <if test="keyword != null and keyword != ''">
  683. and (l.number like '%${keyword}%' or l.address like '%${keyword}%')
  684. </if>
  685. <choose>
  686. <when test="online == 1">
  687. and n.status = 0
  688. </when>
  689. <when test="online == 2">
  690. and n.status = 1
  691. </when>
  692. </choose>
  693. <if test="page >= 0 and count > 0">
  694. limit #{page},#{count}
  695. </if>
  696. </select>
  697. <select id="getLampTotal" resultType="Integer">
  698. select count(*)
  699. from lampinfo l
  700. where 1=1
  701. <if test="sectionList != null and !sectionList.isEmpty()">
  702. and l.sectionid in
  703. <foreach collection="sectionList" item="item" open="(" separator="," close=")">
  704. #{item}
  705. </foreach>
  706. </if>
  707. <if test="areaId != null and areaId != 0">
  708. and l.areaid = #{areaId}
  709. </if>
  710. <if test="sectionId != null and sectionId != 0">
  711. and l.sectionid = #{sectionId}
  712. </if>
  713. </select>
  714. <select id="getCityLampCount" resultType="Integer">
  715. select count(*)
  716. from lampinfo l
  717. left join section s on l.sectionid = s.id
  718. left join global_location gl on s.pid = gl.id
  719. left join global_location gl1 on gl.pid = gl1.id
  720. where gl1.id = #{id}
  721. </select>
  722. <select id="getLampDataByLampIds" resultType="LampInfoDTO">
  723. select
  724. l.name,
  725. l.address,
  726. l.number,
  727. l.lighteness,
  728. l.status,
  729. l.control_type as controlType,
  730. n.status as `online`,
  731. l.power,
  732. l.mode,
  733. n.protocoltype as protocolType
  734. from lampinfo l
  735. left join network n on l.networkid = n.id
  736. where l.id in
  737. <foreach collection="lampIds" item="item" open="(" separator="," close=")">
  738. #{item}
  739. </foreach>
  740. </select>
  741. <select id="getLampListByLampPoleId" resultType="LampInfoDTO">
  742. select
  743. l.id,
  744. l.number
  745. from lampinfo l
  746. left join lamp_pole lp on l.lamp_pole_id = lp.id
  747. where l.lamp_pole_id = #{lampPoleId}
  748. </select>
  749. <select id="getLampPoleIdByLampId" resultType="Integer">
  750. select l.lamp_pole_id
  751. from lampinfo l
  752. where l.id = #{id}
  753. </select>
  754. <select id="getLampCountByLampPoleId" resultType="Integer">
  755. select count(*)
  756. from lampinfo l
  757. where l.lamp_pole_id = #{lampPoleId}
  758. </select>
  759. </mapper>