DeviceMapper.xml 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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.bz.smart_city.dao.DeviceMapper">
  4. <!--auto generated Code-->
  5. <resultMap id="BaseResultMap" type="com.bz.smart_city.entity.Device">
  6. <result column="id" property="id" jdbcType="BIGINT"/>
  7. <result column="device_no" property="deviceNo" jdbcType="VARCHAR"/>
  8. <result column="device_type" property="deviceType" jdbcType="BIGINT"/>
  9. <result column="sys_id" property="sysId" jdbcType="BIGINT"/>
  10. <result column="site_id" property="siteId" jdbcType="BIGINT"/>
  11. <result column="building_id" property="buildingId" jdbcType="BIGINT"/>
  12. <result column="floor" property="floor" jdbcType="INTEGER"/>
  13. <result column="loc_desc" property="locDesc" jdbcType="VARCHAR"/>
  14. <result column="related_device_no" property="relatedDeviceNo" jdbcType="BIGINT"/>
  15. <result column="manufacturer_id" property="manufacturerId" jdbcType="BIGINT"/>
  16. <result column="device_status" property="deviceStatus" jdbcType="INTEGER"/>
  17. <result column="status" property="status" jdbcType="INTEGER"/>
  18. <result column="is_tag" property="isTag" jdbcType="INTEGER"/>
  19. <result column="x_coordinates" property="xCoordinates" jdbcType="DECIMAL"/>
  20. <result column="y_coordinates" property="yCoordinates" jdbcType="DECIMAL"/>
  21. <result column="create_by" property="createBy" jdbcType="VARCHAR"/>
  22. <result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
  23. <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP"/>
  24. <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP"/>
  25. <result column="plan_id" property="planId" jdbcType="INTEGER"/>
  26. <result column="water_meter_no" property="waterMeterNo" jdbcType="VARCHAR"/>
  27. <result column="water_meter_file_no" property="waterMeterFileNo" jdbcType="VARCHAR"/>
  28. <result column="customer_id" property="customerId" jdbcType="INTEGER"/>
  29. <result column="udip_id" property="udipId" jdbcType="VARCHAR"/>
  30. </resultMap>
  31. <!--auto generated Code-->
  32. <sql id="Base_Column_List">
  33. id,
  34. device_no,
  35. device_type,
  36. sys_id,
  37. site_id,
  38. building_id,
  39. floor,
  40. loc_desc,
  41. related_device_no,
  42. manufacturer_id,
  43. device_status,
  44. status,
  45. is_tag,
  46. x_coordinates,
  47. y_coordinates,
  48. create_by,
  49. update_by,
  50. date_create,
  51. date_update,
  52. plan_id,
  53. water_meter_no,
  54. water_meter_file_no,
  55. customer_id,
  56. udip_id
  57. </sql>
  58. <resultMap id="JobCardMap" type="com.bz.smart_city.entity.JobCard">
  59. <result column="id" property="id" jdbcType="BIGINT"/>
  60. <result column="device_no" property="deviceNo" jdbcType="VARCHAR"/>
  61. <result column="device_type_id" property="deviceTypeId" jdbcType="INTEGER"/>
  62. <result column="site_id" property="siteId" jdbcType="INTEGER"/>
  63. <result column="is_used" property="isUsed" jdbcType="INTEGER"/>
  64. <result column="manufacturer_name" property="manufactureName" jdbcType="VARCHAR"/>
  65. <result column="manufacturer_id" property="manufacturerId" jdbcType="INTEGER"/>
  66. <result column="device_type_name" property="deviceTypeName" jdbcType="VARCHAR"/>
  67. <result column="plan_id" property="planId" jdbcType="INTEGER"/>
  68. <result column="water_meter_no" property="waterMeterNo" jdbcType="VARCHAR"/>
  69. <result column="water_meter_file_no" property="waterMeterFileNo" jdbcType="VARCHAR"/>
  70. <result column="customer_id" property="customerId" jdbcType="INTEGER"/>
  71. </resultMap>
  72. <select id="queryJobCard" resultType="com.bz.smart_city.entity.JobCard">
  73. SELECT
  74. d.id as id,
  75. d.site_id as site_id,
  76. d.manufacturer_id as manufacturer_id,
  77. d.device_type as device_type_id,
  78. d.device_no as device_no,
  79. j.is_used as is_used,
  80. m.`name` as manufacturer_name,
  81. CONCAT( m.`name`, '/', t.equipment_type, '/', t.model ) AS device_type_name
  82. FROM
  83. (
  84. SELECT
  85. cat.device_id AS device_id,
  86. cat.device_no AS device_no,
  87. cat.extend_value AS category,
  88. u.extend_value AS is_used
  89. FROM
  90. sc_device_extend_info cat
  91. LEFT JOIN sc_device_extend_info u ON ( cat.device_id = u.device_id and u.extend_type_name = 'isUsed' and u.`status` = 1 )
  92. WHERE
  93. cat.extend_type_name = 'category'
  94. AND cat.extend_value = 'jobCard'
  95. AND cat.`status` = 1
  96. ) j
  97. LEFT JOIN sc_device d ON ( d.id = j.device_id )
  98. LEFT JOIN sc_device_type t ON ( d.device_type = t.id )
  99. LEFT JOIN sc_device_manufacturer m ON ( d.manufacturer_id = m.id )
  100. WHERE
  101. d.`status` = 1
  102. <if test="siteId != null">and d.site_id = #{siteId,jdbcType=INTEGER}</if>
  103. <if test="isUsed != null">and j.is_used = #{isUsed,jdbcType=INTEGER}</if>
  104. <if test="deviceNo != null and deviceNo != '' ">and d.device_no like #{deviceNo,jdbcType=VARCHAR}</if>
  105. order by d.date_create desc
  106. </select>
  107. <select id="singleQueryJobCard" resultType="com.bz.smart_city.entity.JobCard">
  108. SELECT
  109. d.id as id,
  110. d.site_id as site_id,
  111. d.manufacturer_id as manufacturer_id,
  112. d.device_type as device_type_id,
  113. d.device_no as device_no,
  114. j.is_used as is_used,
  115. m.`name` as manufacturer_name,
  116. CONCAT( m.`name`, '/', t.equipment_type, '/', t.model ) AS device_type_name
  117. FROM
  118. (
  119. SELECT
  120. cat.device_id AS device_id,
  121. cat.device_no AS device_no,
  122. cat.extend_value AS category,
  123. u.extend_value AS is_used
  124. FROM
  125. sc_device_extend_info cat
  126. LEFT JOIN sc_device_extend_info u ON ( cat.device_id = u.device_id and u.extend_type_name = 'isUsed' and u.`status` = 1 )
  127. WHERE
  128. cat.extend_type_name = 'category'
  129. AND cat.extend_value = 'jobCard'
  130. AND cat.`status` = 1
  131. ) j
  132. LEFT JOIN sc_device d ON ( d.id = j.device_id )
  133. LEFT JOIN sc_device_type t ON ( d.device_type = t.id )
  134. LEFT JOIN sc_device_manufacturer m ON ( d.manufacturer_id = m.id )
  135. WHERE
  136. d.`status` = 1
  137. <if test="card.deviceNo != null">and d.device_no = #{card.deviceNo,jdbcType=VARCHAR}</if>
  138. <if test="card.id != null">and d.id = #{card.id,jdbcType=BIGINT}</if>
  139. limit 1
  140. </select>
  141. <!--auto generated Code-->
  142. <insert id="insert" useGeneratedKeys="true" keyProperty="device.id">
  143. INSERT INTO sc_device (
  144. id,
  145. device_no,
  146. device_type,
  147. sys_id,
  148. site_id,
  149. building_id,
  150. `floor`,
  151. loc_desc,
  152. related_device_no,
  153. manufacturer_id,
  154. device_status,
  155. `status`,
  156. is_tag,
  157. x_coordinates,
  158. y_coordinates,
  159. create_by,
  160. update_by,
  161. date_create,
  162. date_update,
  163. plan_id,
  164. water_meter_no,
  165. water_meter_file_no,
  166. customer_id,
  167. metercode,
  168. account_id,
  169. udip_id,
  170. register_status,
  171. sync_status
  172. ) VALUES (
  173. #{device.id,jdbcType=BIGINT},
  174. #{device.deviceNo,jdbcType=VARCHAR},
  175. #{device.deviceType,jdbcType=BIGINT},
  176. #{device.sysId,jdbcType=BIGINT},
  177. #{device.siteId,jdbcType=BIGINT},
  178. #{device.buildingId,jdbcType=BIGINT},
  179. #{device.floor,jdbcType=INTEGER},
  180. #{device.locDesc,jdbcType=VARCHAR},
  181. #{device.relatedDeviceNo,jdbcType=BIGINT},
  182. #{device.manufacturerId,jdbcType=BIGINT},
  183. #{device.deviceStatus,jdbcType=INTEGER},
  184. #{device.status,jdbcType=INTEGER},
  185. #{device.isTag,jdbcType=INTEGER},
  186. #{device.xCoordinates,jdbcType=DECIMAL},
  187. #{device.yCoordinates,jdbcType=DECIMAL},
  188. #{device.createBy,jdbcType=VARCHAR},
  189. #{device.updateBy,jdbcType=VARCHAR},
  190. #{device.dateCreate,jdbcType=TIMESTAMP},
  191. #{device.dateUpdate,jdbcType=TIMESTAMP},
  192. #{device.planId,jdbcType=INTEGER},
  193. #{device.waterMeterNo,jdbcType=VARCHAR},
  194. #{device.waterMeterFileNo,jdbcType=VARCHAR},
  195. #{device.customerId,jdbcType=INTEGER},
  196. #{device.metercode,jdbcType=VARCHAR},
  197. #{device.accountId,jdbcType=BIGINT},
  198. #{device.udipId,jdbcType=VARCHAR},
  199. #{device.registerStatus,jdbcType=INTEGER},
  200. #{device.syncStatus,jdbcType=INTEGER}
  201. )
  202. </insert>
  203. <!--auto generated Code-->
  204. <insert id="insertSelective" useGeneratedKeys="true" keyProperty="device.id">
  205. INSERT INTO sc_device
  206. <trim prefix="(" suffix=")" suffixOverrides=",">
  207. <if test="device.id!=null"> id,</if>
  208. <if test="device.deviceNo!=null"> device_no,</if>
  209. <if test="device.deviceType!=null"> device_type,</if>
  210. <if test="device.sysId!=null"> sys_id,</if>
  211. <if test="device.siteId!=null"> site_id,</if>
  212. <if test="device.buildingId!=null"> building_id,</if>
  213. <if test="device.floor!=null"> `floor`,</if>
  214. <if test="device.locDesc!=null"> loc_desc,</if>
  215. <if test="device.relatedDeviceNo!=null"> related_device_no,</if>
  216. <if test="device.manufacturerId!=null"> manufacturer_id,</if>
  217. <if test="device.deviceStatus!=null"> device_status,</if>
  218. <if test="device.status!=null"> `status`,</if>
  219. <if test="device.isTag!=null"> is_tag,</if>
  220. <if test="device.xCoordinates!=null"> x_coordinates,</if>
  221. <if test="device.yCoordinates!=null"> y_coordinates,</if>
  222. <if test="device.createBy!=null"> create_by,</if>
  223. <if test="device.updateBy!=null"> update_by,</if>
  224. <if test="device.dateCreate!=null"> date_create,</if>
  225. <if test="device.dateUpdate!=null"> date_update,</if>
  226. <if test="device.planId!=null"> plan_id,</if>
  227. <if test="device.waterMeterNo!=null"> water_meter_no,</if>
  228. <if test="device.waterMeterFileNo!=null"> water_meter_file_no,</if>
  229. <if test="device.customerId!=null"> customer_id,</if>
  230. <if test="device.udipId!=null"> udip_id,</if>
  231. <if test="device.registerStatus!=null"> register_status</if>
  232. </trim>
  233. VALUES
  234. <trim prefix="(" suffix=")" suffixOverrides=",">
  235. <if test="device.id!=null"> #{device.id,jdbcType=BIGINT},</if>
  236. <if test="device.deviceNo!=null"> #{device.deviceNo,jdbcType=VARCHAR},</if>
  237. <if test="device.deviceType!=null"> #{device.deviceType,jdbcType=BIGINT},</if>
  238. <if test="device.sysId!=null"> #{device.sysId,jdbcType=BIGINT},</if>
  239. <if test="device.siteId!=null"> #{device.siteId,jdbcType=BIGINT},</if>
  240. <if test="device.buildingId!=null"> #{device.buildingId,jdbcType=BIGINT},</if>
  241. <if test="device.floor!=null"> #{device.floor,jdbcType=INTEGER},</if>
  242. <if test="device.locDesc!=null"> #{device.locDesc,jdbcType=VARCHAR},</if>
  243. <if test="device.relatedDeviceNo!=null"> #{device.relatedDeviceNo,jdbcType=BIGINT},</if>
  244. <if test="device.manufacturerId!=null"> #{device.manufacturerId,jdbcType=BIGINT},</if>
  245. <if test="device.deviceStatus!=null"> #{device.deviceStatus,jdbcType=INTEGER},</if>
  246. <if test="device.status!=null"> #{device.status,jdbcType=INTEGER},</if>
  247. <if test="device.isTag!=null"> #{device.isTag,jdbcType=INTEGER},</if>
  248. <if test="device.xCoordinates!=null"> #{device.xCoordinates,jdbcType=DECIMAL},</if>
  249. <if test="device.yCoordinates!=null"> #{device.yCoordinates,jdbcType=DECIMAL},</if>
  250. <if test="device.createBy!=null"> #{device.createBy,jdbcType=VARCHAR},</if>
  251. <if test="device.updateBy!=null"> #{device.updateBy,jdbcType=VARCHAR},</if>
  252. <if test="device.dateCreate!=null"> #{device.dateCreate,jdbcType=TIMESTAMP},</if>
  253. <if test="device.dateUpdate!=null"> #{device.dateUpdate,jdbcType=TIMESTAMP},</if>
  254. <if test="device.planId!=null"> #{device.planId,jdbcType=INTEGER},</if>
  255. <if test="device.waterMeterNo!=null"> #{device.waterMeterNo,jdbcType=VARCHAR},</if>
  256. <if test="device.waterMeterFileNo!=null"> #{device.waterMeterFileNo,jdbcType=VARCHAR},</if>
  257. <if test="device.customerId!=null"> #{device.customerId,jdbcType=INTEGER},</if>
  258. <if test="device.udipId!=null"> #{device.udipId,jdbcType=VARCHAR},</if>
  259. <if test="device.registerStatus!=null"> #{device.registerStatus,jdbcType=INTEGER}</if>
  260. </trim>
  261. </insert>
  262. <!--auto generated Code-->
  263. <insert id="insertList">
  264. INSERT INTO sc_device(
  265. id,
  266. device_no,
  267. device_type,
  268. sys_id,
  269. site_id,
  270. building_id,
  271. `floor`,
  272. loc_desc,
  273. related_device_no,
  274. manufacturer_id,
  275. device_status,
  276. `status`,
  277. is_tag,
  278. x_coordinates,
  279. y_coordinates,
  280. create_by,
  281. update_by,
  282. date_create,
  283. date_update,
  284. plan_id,
  285. water_meter_no,
  286. water_meter_file_no,
  287. customer_id,
  288. udip_id
  289. )VALUES
  290. <foreach collection="devices" item="device" index="index" separator=",">
  291. (
  292. #{device.id,jdbcType=BIGINT},
  293. #{device.deviceNo,jdbcType=VARCHAR},
  294. #{device.deviceType,jdbcType=BIGINT},
  295. #{device.sysId,jdbcType=BIGINT},
  296. #{device.siteId,jdbcType=BIGINT},
  297. #{device.buildingId,jdbcType=BIGINT},
  298. #{device.floor,jdbcType=INTEGER},
  299. #{device.locDesc,jdbcType=VARCHAR},
  300. #{device.relatedDeviceNo,jdbcType=BIGINT},
  301. #{device.manufacturerId,jdbcType=BIGINT},
  302. #{device.deviceStatus,jdbcType=INTEGER},
  303. #{device.status,jdbcType=INTEGER},
  304. #{device.isTag,jdbcType=INTEGER},
  305. #{device.xCoordinates,jdbcType=DECIMAL},
  306. #{device.yCoordinates,jdbcType=DECIMAL},
  307. #{device.createBy,jdbcType=VARCHAR},
  308. #{device.updateBy,jdbcType=VARCHAR},
  309. #{device.dateCreate,jdbcType=TIMESTAMP},
  310. #{device.dateUpdate,jdbcType=TIMESTAMP},
  311. #{device.planId,jdbcType=INTEGER},
  312. #{device.waterMeterNo,jdbcType=VARCHAR},
  313. #{device.waterMeterFileNo,jdbcType=VARCHAR},
  314. #{device.customerId,jdbcType=INTEGER},
  315. #{device.udipId,jdbcType=VARCHAR}
  316. )
  317. </foreach>
  318. </insert>
  319. <!--auto generated Code-->
  320. <update id="updateByPrimaryKeySelective">
  321. UPDATE sc_device
  322. <set>
  323. <if test="device.deviceNo != null"> device_no = #{device.deviceNo,jdbcType=VARCHAR},</if>
  324. <if test="device.deviceType != null"> device_type = #{device.deviceType,jdbcType=BIGINT},</if>
  325. <if test="device.sysId != null"> sys_id = #{device.sysId,jdbcType=BIGINT},</if>
  326. <if test="device.siteId != null"> site_id = #{device.siteId,jdbcType=BIGINT},</if>
  327. <if test="device.buildingId != null"> building_id = #{device.buildingId,jdbcType=BIGINT},</if>
  328. <if test="device.floor != null"> `floor` = #{device.floor,jdbcType=INTEGER},</if>
  329. <if test="device.locDesc != null"> loc_desc = #{device.locDesc,jdbcType=VARCHAR},</if>
  330. <if test="device.relatedDeviceNo != null"> related_device_no = #{device.relatedDeviceNo,jdbcType=BIGINT},</if>
  331. <if test="device.manufacturerId != null"> manufacturer_id = #{device.manufacturerId,jdbcType=BIGINT},</if>
  332. <if test="device.deviceStatus != null"> device_status = #{device.deviceStatus,jdbcType=INTEGER},</if>
  333. <if test="device.status != null"> `status` = #{device.status,jdbcType=INTEGER},</if>
  334. <if test="device.isTag != null"> is_tag = #{device.isTag,jdbcType=INTEGER},</if>
  335. <if test="device.xCoordinates != null"> x_coordinates = #{device.xCoordinates,jdbcType=DECIMAL},</if>
  336. <if test="device.yCoordinates != null"> y_coordinates = #{device.yCoordinates,jdbcType=DECIMAL},</if>
  337. <if test="device.updateBy != null"> update_by = #{device.updateBy,jdbcType=VARCHAR},</if>
  338. <if test="device.dateUpdate != null"> date_update = #{device.dateUpdate,jdbcType=TIMESTAMP},</if>
  339. <if test="device.planId != null"> plan_id = #{device.planId,jdbcType=INTEGER},</if>
  340. <if test="device.waterMeterNo != null"> water_meter_no = #{device.waterMeterNo,jdbcType=VARCHAR},</if>
  341. <if test="device.waterMeterFileNo != null"> water_meter_file_no = #{device.waterMeterFileNo,jdbcType=VARCHAR},</if>
  342. <if test="device.customerId != null"> customer_id = #{device.customerId,jdbcType=INTEGER},</if>
  343. <if test="device.udipId != null"> udip_id = #{device.udipId,jdbcType=VARCHAR},</if>
  344. <if test="device.registerStatus != null"> register_status = #{device.registerStatus,jdbcType=INTEGER},</if>
  345. <if test="device.syncStatus != null"> sync_status = #{device.syncStatus,jdbcType=INTEGER}</if>
  346. </set>
  347. WHERE id = #{device.id,jdbcType=BIGINT}
  348. </update>
  349. <select id="getList" resultType="com.bz.smart_city.dto.DeviceDto">
  350. select sd.*,
  351. sdt.equipment_type,sdt.model,sdt.is_valve,sdm.name manufacturer_name,
  352. sb.name as building_name,sc.channel_name as system_name,
  353. sb.longitude,sb.latitude,
  354. sb.province,sb.city,sb.region,sb.community,scom.name as community_name,
  355. swrd.concentrator_id,swrd.collector_id,swrd.channel_number_id,swrd.port,swrd.issue_status,
  356. scon.serial_number as concentrator_name,scol.collector_no as collector_name,
  357. scus.customer_name,
  358. sil.plan_time,sil.install_time,sil.accept_time,
  359. swmed.days,swmed.last_error_type,
  360. swmed.meter_reading,swmed.valve_status,
  361. swmed.valve_button_status,
  362. sd.sync_status
  363. from sc_device sd
  364. left join sc_device_type sdt on (sdt.id = sd.device_type and sdt.status = 1)
  365. left join sc_device_manufacturer sdm on (sdm.id = sd.manufacturer_id and sdm.status = 1)
  366. left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)
  367. left join sc_channel sc on (sc.id = sd.sys_id and sc.status = 1)
  368. left join sc_community scom on ( scom.id = sb.community and scom.status = 1)
  369. left join sc_water_related_device swrd on ( swrd.device_id = sd.id and swrd.status = 1)
  370. left join sc_concentrator scon on ( scon.id = swrd.concentrator_id and scon.status = 1)
  371. left join sc_collector scol on ( scol.id = swrd.collector_id)
  372. left join sc_water_meter_error_days swmed on ( swmed.device_id = sd.id)
  373. left join sc_customer scus on ( scus.id = sd.customer_id)
  374. left join sc_install_list sil on (sil.device_id = sd.id)
  375. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
  376. where sd.status = 1
  377. <if test="sysId != null"> AND sd.sys_id = #{sysId}</if>
  378. <if test="sysId == null"> AND sd.sys_id <![CDATA[ <> ]]> -99</if>
  379. <if test="buildingId != null"> AND sd.building_id = #{buildingId}</if>
  380. <if test="siteId != null"> AND sd.site_id = #{siteId}</if>
  381. <if test="deviceNo != null and deviceNo != ''"> AND (sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_file_no LIKE concat('%',#{deviceNo},'%'))</if>
  382. <if test="status != null"> AND sd.device_status = #{status}</if>
  383. <if test="manufacturerId != null"> AND sd.manufacturer_id = #{manufacturerId}</if>
  384. <if test="equipmentType != null and equipmentType != ''"> AND sdt.equipment_type LIKE concat('%',#{equipmentType},'%')</if>
  385. <if test="model != null and model != ''"> AND sdt.model LIKE concat('%',#{model},'%')</if>
  386. <if test="deviceTypeId != null"> AND sd.device_type = #{deviceTypeId}</if>
  387. <if test="floor != null"> AND sd.floor = #{floor}</if>
  388. <if test="isTag != null"> AND sd.is_tag = #{isTag}</if>
  389. <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
  390. <if test="province != null"> and sb.province = #{province}</if>
  391. <if test="city != null"> and sb.city = #{city}</if>
  392. <if test="region != null"> and sb.region = #{region}</if>
  393. <if test="community != null"> and sb.community = #{community}</if>
  394. <if test="concentratorNo != null and concentratorNo != ''"> AND scon.serial_number LIKE concat('%',#{concentratorNo},'%')</if>
  395. <if test="collectorNo != null and collectorNo != ''"> AND scol.collector_no LIKE concat('%',#{collectorNo},'%')</if>
  396. <if test="errorType != null and errorType != ''"> AND swmed.last_error_type LIKE concat('%',#{errorType},'%')</if>
  397. <if test="customerId != null"> and sd.customer_id = #{customerId}</if>
  398. <if test="valveStatus != null and valveStatus == 0"> and swmed.valve_status = #{valveStatus} and sdt.is_valve = 1</if>
  399. <if test="valveStatus != null and valveStatus == 1"> and (swmed.valve_status = #{valveStatus} or swmed.valve_status is null ) and sdt.is_valve = 1</if>
  400. <if test="valveStatus != null and valveStatus == 2"> and sdt.is_valve = 0</if>
  401. <if test="registerStatus != null"> and sd.register_status = #{registerStatus}</if>
  402. <if test="issueStatus != null"> and swrd.issue_status = #{issueStatus}</if>
  403. <if test="syncStatus != null"> and sd.sync_status = #{syncStatus}</if>
  404. <if test="startReading != null"> and swmed.meter_reading >= #{startReading} </if>
  405. <if test="endReading != null"> and swmed.meter_reading <![CDATA[ <= ]]> #{endReading} </if>
  406. <if test="days != null">
  407. <choose>
  408. <when test="days == 0">
  409. and (swmed.days = #{days} or swmed.days is null )
  410. </when>
  411. <otherwise>
  412. and swmed.days = #{days}
  413. </otherwise>
  414. </choose>
  415. </if>
  416. <if test="startDays != null"> and swmed.days >= #{startDays} </if>
  417. <if test="endDays != null"> and swmed.days <![CDATA[ <= ]]> #{endDays} </if>
  418. <if test="programItems != null and programItems.size() != 0"> and
  419. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  420. sdd.${item.dimensionCode} = #{item.dimensionValue}
  421. </foreach>
  422. </if>
  423. <if test="sortColumn != null and sortColumn != ''">
  424. <if test="sortOrder != null and sortOrder != ''">
  425. order by ${sortColumn} ${sortOrder}
  426. </if>
  427. </if>
  428. </select>
  429. <!--自定义getList的count统计-->
  430. <select id="getList_COUNT" resultType="Long">
  431. select count(1)
  432. from sc_device sd
  433. <if test="(equipmentType != null and equipmentType != '') or (model != null and model != '') or (valveStatus != null)">left join sc_device_type sdt on (sdt.id = sd.device_type and sdt.status = 1)</if>
  434. <if test="province != null or city != null or region != null or community != null">left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)</if>
  435. <if test="(concentratorNo != null and concentratorNo != '') or (collectorNo != null and collectorNo != '') or issueStatus != null">left join sc_water_related_device swrd on ( swrd.device_id = sd.id and swrd.status = 1)</if>
  436. <if test="concentratorNo != null and concentratorNo != ''">left join sc_concentrator scon on ( scon.id = swrd.concentrator_id and scon.status = 1)</if>
  437. <if test="collectorNo != null and collectorNo != ''">left join sc_collector scol on ( scol.id = swrd.collector_id)</if>
  438. <if test="(errorType != null and errorType != '') or days != null or startDays != null or endDays != null or (valveStatus != null) or startReading != null or endReading != null">left join sc_water_meter_error_days swmed on ( swmed.device_id = sd.id)</if>
  439. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
  440. where sd.status = 1
  441. <if test="sysId != null"> AND sd.sys_id = #{sysId}</if>
  442. <if test="buildingId != null"> AND sd.building_id = #{buildingId}</if>
  443. <if test="siteId != null"> AND sd.site_id = #{siteId}</if>
  444. <if test="deviceNo != null and deviceNo != ''"> AND (sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_file_no LIKE concat('%',#{deviceNo},'%'))</if>
  445. <if test="status != null"> AND sd.device_status = #{status}</if>
  446. <if test="manufacturerId != null"> AND sd.manufacturer_id = #{manufacturerId}</if>
  447. <if test="equipmentType != null and equipmentType != ''"> AND sdt.equipment_type LIKE concat('%',#{equipmentType},'%')</if>
  448. <if test="model != null and model != ''"> AND sdt.model LIKE concat('%',#{model},'%')</if>
  449. <if test="deviceTypeId != null"> AND sd.device_type = #{deviceTypeId}</if>
  450. <if test="floor != null"> AND sd.floor = #{floor}</if>
  451. <if test="isTag != null"> AND sd.is_tag = #{isTag}</if>
  452. <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
  453. <if test="province != null"> and sb.province = #{province}</if>
  454. <if test="city != null"> and sb.city = #{city}</if>
  455. <if test="region != null"> and sb.region = #{region}</if>
  456. <if test="community != null"> and sb.community = #{community}</if>
  457. <if test="concentratorNo != null and concentratorNo != ''"> AND scon.serial_number LIKE concat('%',#{concentratorNo},'%')</if>
  458. <if test="collectorNo != null and collectorNo != ''"> AND scol.collector_no LIKE concat('%',#{collectorNo},'%')</if>
  459. <if test="errorType != null and errorType != ''"> AND swmed.last_error_type LIKE concat('%',#{errorType},'%')</if>
  460. <if test="customerId != null"> and sd.customer_id = #{customerId}</if>
  461. <if test="valveStatus != null and valveStatus == 0"> and swmed.valve_status = #{valveStatus} and sdt.is_valve = 1</if>
  462. <if test="valveStatus != null and valveStatus == 1"> and (swmed.valve_status = #{valveStatus} or swmed.valve_status is null ) and sdt.is_valve = 1</if>
  463. <if test="valveStatus != null and valveStatus == 2"> and sdt.is_valve = 0</if>
  464. <if test="registerStatus != null"> and sd.register_status = #{registerStatus}</if>
  465. <if test="issueStatus != null"> and swrd.issue_status = #{issueStatus}</if>
  466. <if test="syncStatus != null"> and sd.sync_status = #{syncStatus}</if>
  467. <if test="startReading != null"> and swmed.meter_reading >= #{startReading} </if>
  468. <if test="endReading != null"> and swmed.meter_reading <![CDATA[ <= ]]> #{endReading} </if>
  469. <if test="days != null">
  470. <choose>
  471. <when test="days == 0">
  472. and (swmed.days = #{days} or swmed.days is null )
  473. </when>
  474. <otherwise>
  475. and swmed.days = #{days}
  476. </otherwise>
  477. </choose>
  478. </if>
  479. <if test="startDays != null"> and swmed.days >= #{startDays} </if>
  480. <if test="endDays != null"> and swmed.days <![CDATA[ <= ]]> #{endDays} </if>
  481. <if test="programItems != null and programItems.size() != 0"> and
  482. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  483. sdd.${item.dimensionCode} = #{item.dimensionValue}
  484. </foreach>
  485. </if>
  486. </select>
  487. <select id="getWaterMeterListByDeviceNo" resultType="com.bz.smart_city.dto.DeviceDto">
  488. select sd.*,sdt.equipment_type,sdt.model,sdm.name manufacturer_name,sb.name as building_name,sc.channel_name as system_name,
  489. sb.longitude,sb.latitude,
  490. sb.province,sb.city,sb.region,sb.community,scom.name as community_name,
  491. scon.serial_number as concentrator_name,scol.collector_no as collector_name,swmed.days,swmed.last_error_type,scus.customer_name,
  492. sil.plan_time,sil.install_time,sil.accept_time,
  493. swmed.meter_reading,
  494. swmed.valve_status,
  495. swmed.valve_button_status
  496. from sc_device sd
  497. left join sc_device_type sdt on (sdt.id = sd.device_type and sdt.status = 1)
  498. left join sc_device_manufacturer sdm on (sdm.id = sd.manufacturer_id and sdm.status = 1)
  499. left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)
  500. left join sc_channel sc on (sc.id = sd.sys_id and sc.status = 1)
  501. left join sc_community scom on ( scom.id = sb.community and scom.status = 1)
  502. left join sc_water_related_device swrd on ( swrd.device_id = sd.id and swrd.status = 1)
  503. left join sc_concentrator scon on ( scon.id = swrd.concentrator_id and scon.status = 1)
  504. left join sc_collector scol on ( scol.id = swrd.collector_id)
  505. left join sc_water_meter_error_days swmed on ( swmed.device_id = sd.id)
  506. left join sc_customer scus on ( scus.id = sd.customer_id)
  507. left join sc_install_list sil on (sil.device_id = sd.id)
  508. where sd.status = 1
  509. <if test="deviceNo != null and deviceNo != ''">
  510. AND sd.device_no = #{deviceNo}
  511. </if>
  512. <if test="waterMeterNo != null and waterMeterNo != ''">
  513. AND right(sd.water_meter_no,9) = right(#{waterMeterNo},9)
  514. </if>
  515. </select>
  516. <select id="getSyncMeterDeviceList" resultType="com.bz.smart_city.dto.JinNanSyncDTO">
  517. select
  518. sd.id as device_id ,
  519. sd.water_meter_no as meter_no,
  520. mu.user_no,
  521. IFNULL(swmed.meter_reading,'0') as wsv ,
  522. IFNULL(sd.last_receive_time,now()) as read_date
  523. from
  524. sc_device sd
  525. left join sc_water_meter_error_days swmed on ( swmed.device_id = sd.id)
  526. left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)
  527. left join sc_meter_user mu on (sd.water_meter_no = mu.meter_no)
  528. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
  529. where sd.status = 1
  530. <if test="sysId != null"> AND sd.sys_id = #{sysId}</if>
  531. <if test="sysId == null"> AND sd.sys_id != -99</if>
  532. <if test="buildingId != null"> AND sd.building_id = #{buildingId}</if>
  533. <if test="siteId != null"> AND sd.site_id = #{siteId}</if>
  534. <if test="deviceNo != null and deviceNo != ''"> AND (sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_file_no LIKE concat('%',#{deviceNo},'%'))</if>
  535. <if test="status != null"> AND sd.device_status = #{status}</if>
  536. <if test="customerId != null"> and sd.customer_id = #{customerId}</if>
  537. <if test="programItems != null and programItems.size() != 0"> and
  538. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  539. sdd.${item.dimensionCode} = #{item.dimensionValue}
  540. </foreach>
  541. </if>
  542. <if test="errorType != null and errorType != ''"> AND swmed.last_error_type LIKE concat('%',#{errorType},'%')</if>
  543. <if test="days != null"> and swmed.days = #{days} </if>
  544. <if test="province != null"> and sb.province = #{province}</if>
  545. <if test="city != null"> and sb.city = #{city}</if>
  546. <if test="region != null"> and sb.region = #{region}</if>
  547. <if test="community != null"> and sb.community = #{community}</if>
  548. <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
  549. </select>
  550. <update id="batchDelete">
  551. update sc_device set status = 0,date_update=NOW(),update_by=#{updateBy}
  552. where status = 1
  553. <if test="deviceIds != null">
  554. and id in <foreach collection="deviceIds" item="item" open="(" separator="," close=")">#{item}</foreach>
  555. </if>
  556. </update>
  557. <select id="deleteQuery" resultType="java.lang.Long">
  558. select site_id from sc_device where device_type = #{deviceTypeId} and status = 1 group by site_id
  559. </select>
  560. <update id="deleteBySiteId">
  561. update sc_device set status = 0,date_update = NOW(),update_by=#{updateBy}
  562. where status = 1 and site_id = #{siteId}
  563. </update>
  564. <select id="findByDeviceNoUnique" resultType="int">
  565. select count(1) from sc_device where status = 1 and device_no = #{deviceNo}
  566. <if test="id != null"> and id != #{id}</if>
  567. </select>
  568. <select id="findByWaterMeterNoUnique" resultType="int">
  569. select count(1) from sc_device where status = 1 and water_meter_no = #{waterMeterNo}
  570. <if test="id != null"> and id != #{id}</if>
  571. </select>
  572. <select id="getGatewayList" resultType="com.bz.smart_city.dto.DeviceDto">
  573. select sd.*,sdt.equipment_type,sdt.model,sdm.name manufacturer_name
  574. from sc_device sd
  575. left join sc_device_type sdt on sdt.id = sd.device_type and sdt.status = 1
  576. left join sc_device_manufacturer sdm on sdm.id = sd.manufacturer_id and sdm.status = 1
  577. where sd.status = 1 and sdt.device_type = 2
  578. <if test="siteId != null"> AND sd.site_id = #{siteId}</if>
  579. <if test="deviceTypeId != null"> AND sd.device_type = #{deviceTypeId} </if>
  580. <if test="deviceNo != null and deviceNo != ''"> AND sd.device_no LIKE concat('%',#{deviceNo},'%')</if>
  581. order by sd.date_create desc
  582. </select>
  583. <update id="deleteBySysId">
  584. update sc_device set status = 0,date_update = NOW(),update_by=#{updateBy}
  585. where status = 1 and sys_id = #{sysId}
  586. </update>
  587. <select id="findByDeviceNo" resultMap="BaseResultMap">
  588. select id,device_no from sc_device where status = 1 and device_no = #{deviceNo}
  589. </select>
  590. <select id="findDeviceDetail" resultType="com.bz.smart_city.dto.DeviceDto">
  591. select sd.*,
  592. sdt.equipment_type,sdt.model,sdt.is_valve,sdm.name manufacturer_name,
  593. sb.name as building_name,sc.channel_name as system_name,
  594. sb.longitude,sb.latitude,
  595. sb.province,sb.city,sb.region,sb.community,scom.name as community_name,
  596. swrd.concentrator_id,swrd.collector_id,swrd.channel_number_id,swrd.port,swrd.issue_status,
  597. scon.serial_number as concentrator_name,scol.collector_no as collector_name,
  598. scn.channel_name as channel_number_name,
  599. scus.customer_name,
  600. sil.plan_time,sil.install_time,sil.accept_time,
  601. swmed.days,swmed.last_error_type,
  602. swmed.meter_reading,swmed.valve_status,
  603. swmed.valve_button_status,
  604. sd.sync_status
  605. from sc_device sd
  606. left join sc_device_type sdt on (sdt.id = sd.device_type and sdt.status = 1)
  607. left join sc_device_manufacturer sdm on (sdm.id = sd.manufacturer_id and sdm.status = 1)
  608. left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)
  609. left join sc_channel sc on (sc.id = sd.sys_id and sc.status = 1)
  610. left join sc_community scom on ( scom.id = sb.community and scom.status = 1)
  611. left join sc_water_related_device swrd on ( swrd.device_id = sd.id and swrd.status = 1)
  612. left join sc_concentrator scon on ( scon.id = swrd.concentrator_id and scon.status = 1)
  613. left join sc_collector scol on ( scol.id = swrd.collector_id)
  614. left join sc_channel_number scn on ( scn.id = swrd.channel_number_id)
  615. left join sc_water_meter_error_days swmed on ( swmed.device_id = sd.id)
  616. left join sc_customer scus on ( scus.id = sd.customer_id)
  617. left join sc_install_list sil on (sil.device_id = sd.id)
  618. where sd.status = 1 and sd.id = #{deviceId}
  619. </select>
  620. <select id="findByDeviceId" resultMap="BaseResultMap">
  621. select * from sc_device where id = #{deviceId} and status = 1
  622. </select>
  623. <update id="batchUpdate" parameterType="list">
  624. UPDATE sc_device
  625. <trim prefix="set" suffixOverrides=",">
  626. <trim prefix="building_id =case" suffix="end,">
  627. <foreach collection="list" item="item">
  628. <if test="item.buildingId!=null">
  629. when id=#{item.id} then #{item.buildingId}
  630. </if>
  631. </foreach>
  632. </trim>
  633. <trim prefix="site_id =case" suffix="end,">
  634. <foreach collection="list" item="item">
  635. <if test="item.siteId!=null">
  636. when id=#{item.id} then #{item.siteId}
  637. </if>
  638. </foreach>
  639. </trim>
  640. <trim prefix="Loc_desc =case" suffix="end,">
  641. <foreach collection="list" item="item">
  642. <if test="item.locDesc!=null">
  643. when id=#{item.id} then #{item.locDesc}
  644. </if>
  645. </foreach>
  646. </trim>
  647. <trim prefix="water_meter_no =case" suffix="end,">
  648. <foreach collection="list" item="item">
  649. <if test="item.waterMeterNo!=null">
  650. when id=#{item.id} then #{item.waterMeterNo}
  651. </if>
  652. </foreach>
  653. </trim>
  654. <trim prefix="water_meter_file_no =case" suffix="end,">
  655. <foreach collection="list" item="item">
  656. <if test="item.waterMeterFileNo!=null">
  657. when id=#{item.id} then #{item.waterMeterFileNo}
  658. </if>
  659. </foreach>
  660. </trim>
  661. </trim>
  662. <where>
  663. id in <foreach collection="list" item="item" open="(" separator="," close=")">#{item.id}</foreach>
  664. </where>
  665. </update>
  666. <select id="getDeviceStatistics" resultType="int">
  667. select count(1) from sc_device
  668. where status = 1
  669. and building_id is not null
  670. <if test="siteId != null"> and site_id = #{siteId} </if>
  671. <if test="channelList != null and channelList.size() != 0">
  672. and sys_id in <foreach collection="channelList" item="item" open="(" separator="," close=")">#{item.id} </foreach>
  673. </if>
  674. <if test="deviceStatus != null and deviceStatus != ''"> and device_status = #{deviceStatus} </if>
  675. </select>
  676. <select id="countDevice" resultType="int">
  677. select
  678. count(1)
  679. from
  680. sc_device
  681. where status = 1
  682. <if test="device.siteId != null"> and site_id = #{device.siteId} </if>
  683. <if test="device.sysId != null"> and sys_id = #{device.sysId} </if>
  684. <if test="device.deviceType != null"> and device_type = #{device.deviceType} </if>
  685. <if test="device.deviceStatusList != null and device.deviceStatusList.size() != 0">
  686. and device_status in
  687. <foreach collection="device.deviceStatusList" item="item" open="(" separator="," close=")">#{item} </foreach>
  688. </if>
  689. <if test="device.sysIds != null and device.sysIds.size() != 0">
  690. and sys_id in
  691. <foreach collection="device.sysIds" item="item" open="(" separator="," close=")">#{item} </foreach>
  692. </if>
  693. order by date_create asc
  694. </select>
  695. <select id="getDeviceList" resultType="com.bz.smart_city.dto.DeviceDto">
  696. SELECT
  697. d.id as id,
  698. d.device_no as device_no,
  699. d.site_id as site_id,
  700. d.sys_id as sys_id,
  701. d.building_id as building_id,
  702. d.floor as floor,
  703. d.loc_desc as loc_desc,
  704. d.device_type as deviceType,
  705. d.device_status as device_status,
  706. d.water_meter_no as water_meter_no,
  707. d.water_meter_file_no as water_meter_file_no,
  708. b.province as province,
  709. b.city as city,
  710. b.region as region,
  711. b.community as community,
  712. b.`name` as building_name,
  713. d.customer_id as customer_id,
  714. d.last_receive_time as last_receive_time,
  715. d.date_create as date_create
  716. FROM
  717. sc_device d
  718. LEFT JOIN sc_building b ON ( b.id = d.building_id AND b.`status` = 1 )
  719. WHERE 1=1
  720. <if test="device.siteId != null"> and d.site_id = #{device.siteId} </if>
  721. <if test="device.sysId != null"> and d.sys_id = #{device.sysId} </if>
  722. <if test="device.deviceType != null"> and device_type = #{device.deviceType} </if>
  723. <if test="device.deviceStatusList != null and device.deviceStatusList.size() != 0">
  724. and d.device_status in
  725. <foreach collection="device.deviceStatusList" item="item" open="(" separator="," close=")">#{item} </foreach>
  726. </if>
  727. <if test="device.sysIds != null and device.sysIds.size() != 0">
  728. and d.sys_id in
  729. <foreach collection="device.sysIds" item="item" open="(" separator="," close=")">#{item} </foreach>
  730. </if>
  731. and d.status = 1
  732. order by d.id desc,d.date_create asc
  733. limit #{offset}, #{limit}
  734. </select>
  735. <select id="getDeviceStatusCount" resultType="com.bz.smart_city.dto.DeviceStatusCountDto">
  736. SELECT
  737. count(1) as device_count,
  738. ifnull(SUM(IF(d.`device_status` = 1, 1, 0)),0) as normalCount,
  739. ifnull(SUM(IF(d.`device_status` = 2, 1, 0)),0) as alarm_count,
  740. ifnull(SUM(IF(d.`device_status` = 3, 1, 0)),0) as fault_count,
  741. ifnull(SUM(IF(d.`device_status` = 4, 1, 0)),0) as offline_count,
  742. ifnull(SUM(IF(d.`device_status` = 5, 1, 0)),0) as unused_count
  743. FROM
  744. sc_device d
  745. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = d.id and sdd.status = 1)</if>
  746. WHERE
  747. d.`status` = 1 and d.building_id is not null and d.sys_id != -99
  748. <if test="siteList != null and siteList.size() != 0">and d.site_id in <foreach collection="siteList" item="item" open="(" separator="," close=")">#{item.id}</foreach></if>
  749. <if test="programItems != null and programItems.size() != 0"> and
  750. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  751. sdd.${item.dimensionCode} = #{item.dimensionValue}
  752. </foreach>
  753. </if>
  754. </select>
  755. <select id="getInstallList" resultType="com.bz.smart_city.dto.DeviceDto">
  756. select sd.*,sdt.equipment_type,sdt.model,sdm.name manufacturer_name,sb.name as building_name,sc.channel_name as system_name,
  757. sb.longitude,sb.latitude,
  758. sb.province,sb.city,sb.region,sb.community,scom.name as community_name,
  759. scon.serial_number as concentrator_name,scol.collector_no as collector_name,swmed.days,swmed.last_error_type,swmed.meter_reading,scus.customer_name,
  760. sil.plan_time,sil.install_time,sil.accept_time,sil.new_meter_start,sil.id as install_id,sil.old_meter_end,sd.register_status,sdt.is_valve,sdt.is_register,
  761. sd.sync_status
  762. from sc_device sd
  763. left join sc_device_type sdt on (sdt.id = sd.device_type and sdt.status = 1)
  764. left join sc_device_manufacturer sdm on (sdm.id = sd.manufacturer_id and sdm.status = 1)
  765. left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)
  766. left join sc_channel sc on (sc.id = sd.sys_id and sc.status = 1)
  767. left join sc_community scom on ( scom.id = sb.community and scom.status = 1)
  768. left join sc_water_related_device swrd on ( swrd.device_id = sd.id and swrd.status = 1)
  769. left join sc_concentrator scon on ( scon.id = swrd.concentrator_id and scon.status = 1)
  770. left join sc_collector scol on ( scol.id = swrd.collector_id)
  771. left join sc_water_meter_error_days swmed on ( swmed.device_id = sd.id)
  772. left join sc_customer scus on ( scus.id = sd.customer_id)
  773. left join sc_install_list sil on (sil.device_id = sd.id)
  774. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
  775. where sd.status = 1 and sil.status = 1
  776. <if test="sysId != null"> AND sd.sys_id = #{sysId}</if>
  777. <if test="siteId != null"> AND sd.site_id = #{siteId}</if>
  778. <if test="deviceNo != null and deviceNo != ''"> AND (sd.device_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_no LIKE concat('%',#{deviceNo},'%') or sd.water_meter_file_no LIKE concat('%',#{deviceNo},'%'))</if>
  779. <if test="status != null"> AND sd.device_status = #{status}</if>
  780. <if test="errorType != null and errorType != ''"> AND swmed.last_error_type LIKE concat('%',#{errorType},'%')</if>
  781. <if test="customerId != null"> and sd.customer_id = #{customerId}</if>
  782. <if test="province != null"> and sb.province = #{province}</if>
  783. <if test="city != null"> and sb.city = #{city}</if>
  784. <if test="region != null"> and sb.region = #{region}</if>
  785. <if test="community != null"> and sb.community = #{community}</if>
  786. <if test="buildingId != null"> and sd.building_id = #{buildingId}</if>
  787. <if test="locDesc != null and locDesc != ''"> AND sd.loc_desc LIKE concat('%',#{locDesc},'%')</if>
  788. <if test="deviceTypeId != null"> and sd.device_type = #{deviceTypeId}</if>
  789. <if test="registerStatus != null and registerStatus == 1"> and sd.register_status = #{registerStatus} and sdt.is_register = 1</if>
  790. <if test="registerStatus != null and registerStatus == 0"> and sd.register_status = #{registerStatus} and sdt.is_register = 1</if>
  791. <if test="startDate != null"> and sil.install_time <![CDATA[ >= ]]> #{startDate}</if>
  792. <if test="endDate != null"> and sil.install_time <![CDATA[ <= ]]> #{endDate}</if>
  793. <if test="programItems != null and programItems.size() != 0"> and
  794. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  795. sdd.${item.dimensionCode} = #{item.dimensionValue}
  796. </foreach>
  797. </if>
  798. <if test="sortColumn != null and sortColumn != ''">
  799. <if test="sortOrder != null and sortOrder != ''">
  800. order by ${sortColumn} ${sortOrder}
  801. </if>
  802. </if>
  803. <if test="sortColumn == null or sortColumn == ''">
  804. order by sil.install_time desc
  805. </if>
  806. <!--order by sil.install_time desc-->
  807. </select>
  808. <select id="queryDeviceByNo" resultType="com.bz.smart_city.dto.DeviceDto">
  809. select
  810. sd.*,
  811. sb.province,
  812. sb.city,
  813. sb.region,
  814. sb.name as building_name,
  815. sa1.`name` as province_name,
  816. sa2.`name` as city_name ,
  817. sa3.`name` as region_name,
  818. scom.name as community_name,
  819. scus.customer_name
  820. from
  821. sc_device sd
  822. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
  823. left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)
  824. left join sc_area sa1 on (sa1.id = sb.province)
  825. left join sc_area sa2 on (sa2.id = sb.city)
  826. left join sc_area sa3 on (sa3.id = sb.region)
  827. left join sc_community scom on ( scom.id = sb.community and scom.status = 1)
  828. left join sc_customer scus on ( scus.id = sd.customer_id)
  829. where sd.status = 1
  830. <if test="programItems != null and programItems.size() != 0"> and
  831. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  832. sdd.${item.dimensionCode} = #{item.dimensionValue}
  833. </foreach>
  834. </if>
  835. <if test="deviceNo != null and deviceNo != ''"> AND sd.device_no LIKE concat('%',#{deviceNo},'%')</if>
  836. <if test="waterMeterNo != null and waterMeterNo != ''"> and sd.water_meter_no LIKE concat('%',#{waterMeterNo},'%') </if>
  837. <if test="sysId != null"> AND sd.sys_id = #{sysId}</if>
  838. <if test="siteId != null"> AND sd.site_id = #{siteId}</if>
  839. </select>
  840. <select id="queryDeviceByClearingPlan" resultType="com.bz.smart_city.dto.DeviceDto">
  841. SELECT
  842. d.id,
  843. d.water_meter_no,
  844. d.water_meter_file_no,
  845. d.device_no,
  846. d.device_type,
  847. d.building_id,
  848. d.loc_desc ,
  849. d.device_status,
  850. b.community,
  851. b.`name` as building_name,
  852. c.`name` as community_name
  853. FROM
  854. sc_device d
  855. left join sc_building b on (d.building_id = b.id)
  856. left join sc_community c on (b.community = c.id)
  857. WHERE
  858. d.`status` = 1
  859. AND d.site_id = 1
  860. AND d.sys_id IN ( SELECT channel_id FROM sc_w_meter_type wt WHERE wt.parent_id IN ( 1, 2 ) )
  861. AND d.id IN (
  862. SELECT
  863. dd.device_id
  864. FROM
  865. sc_device_dimension dd
  866. LEFT JOIN sc_clearing_plan cp ON (
  867. FIND_IN_SET( dd.customer, cp.clearing_customer )
  868. OR FIND_IN_SET( dd.community, cp.clearing_community )
  869. OR FIND_IN_SET( dd.building, cp.clearing_building )
  870. )
  871. WHERE
  872. cp.id = #{clearingPlanId}
  873. )
  874. </select>
  875. <select id="getDeviceCustomerInfo" resultType="com.bz.smart_city.dto.DeviceCustomerInfo">
  876. select
  877. sd.id as device_id,
  878. sd.device_no as device_no,
  879. sd.loc_desc as location,
  880. sil.user_name,
  881. sil.user_phone,
  882. sil.install_time
  883. from sc_device sd
  884. left join sc_install_list sil on (sil.device_id = sd.id and sil.status = 1)
  885. where sd.status = 1 and sd.sys_id != -99 and sd.building_id = #{buildingId}
  886. </select>
  887. <select id="getDeviceListByCustomer" resultType="com.bz.smart_city.dto.DeviceDto">
  888. select
  889. <include refid="Base_Column_List" />
  890. from
  891. sc_device
  892. where status = 1
  893. and customer_id = #{customerId}
  894. and device_status = #{deviceStatus}
  895. </select>
  896. <select id="findDeviceIdByDeviceNo" resultType="java.lang.Long">
  897. select id from sc_device where status = 1 and device_no = #{deviceNo}
  898. <if test="id != null"> and id != #{id}</if>
  899. </select>
  900. <select id="findDeviceIdByWaterMeterNo" resultType="java.lang.Long">
  901. select id from sc_device where status = 1 and water_meter_no = #{waterMeterNo}
  902. <if test="id != null"> and id != #{id}</if>
  903. </select>
  904. <select id="getJinNanSyncMeterDeviceList" resultType="com.bz.smart_city.dto.JinNanSyncDTO">
  905. SELECT
  906. d.id as device_id ,
  907. d.water_meter_no as meter_no,
  908. mu.user_no,
  909. IFNULL(mdd.read_data,'0') as wsv ,
  910. IFNULL(mdd.read_time,now()) as read_date
  911. FROM
  912. sc_device d
  913. left join sc_meter_user mu on (d.water_meter_no = mu.meter_no)
  914. left join (SELECT
  915. mrr.device_id,
  916. mrr.read_time,
  917. mrr.read_data
  918. FROM
  919. sc_meter_read_record mrr
  920. WHERE
  921. mrr.read_date = (
  922. SELECT
  923. max( read_date )
  924. FROM
  925. sc_meter_read_record
  926. WHERE
  927. customer_id IN ( 3, 4, 5, 6 )
  928. AND read_status = 2
  929. AND sys_id = 40
  930. )
  931. AND customer_id IN ( 3, 4, 5, 6 )
  932. AND read_status = 2
  933. AND sys_id = 40) mdd on (d.id = mdd.device_id)
  934. WHERE
  935. d.`status` = 1
  936. AND d.customer_id IN ( 3, 4, 5, 6 )
  937. </select>
  938. <select id="getPushDeviceDataList" resultType="java.util.HashMap">
  939. SELECT
  940. d.device_no AS deviceNo,
  941. dt.equipment_type AS deviceType,
  942. DATE_FORMAT(d.date_update,'%Y-%m-%d') AS dateCreate,
  943. ifnull(m.factory,f.`name`) as factory,
  944. m.user_name AS userName,
  945. '0' AS beginWSV,
  946. ifnull(m.area_name,c.`name`) AS areaName,
  947. d.loc_desc AS location,
  948. d.water_meter_no AS meterNumber,
  949. ifnull(m.meter_no,d.water_meter_no) as meter_no,
  950. ifnull(m.user_address,b.`name`) AS userAddress,
  951. m.user_no AS userNumber,
  952. m.user_phone AS userPhone,
  953. DATE_FORMAT(m.archive_time,'%Y-%m-%d') AS archiveTime,
  954. m.caliber
  955. FROM
  956. sc_device d
  957. LEFT JOIN sc_meter_info m ON ( CONCAT('91000',d.water_meter_no) = m.meter_no )
  958. LEFT JOIN sc_device_type dt ON ( d.device_type = dt.id )
  959. LEFT JOIN sc_building b on (d.building_id =b.id)
  960. LEFT JOIN sc_community c on (b.community = c.id)
  961. left join sc_device_manufacturer f on (dt.manufacturer_id = f.id)
  962. where d.`status` = 1
  963. and d.sys_id != -99
  964. and d.sys_id != 55
  965. and d.id in (
  966. SELECT
  967. dd.device_id
  968. FROM sc_device_dimension dd
  969. WHERE
  970. <trim prefixOverrides="or" >
  971. <if test="customers != null and customers != '' ">
  972. FIND_IN_SET( dd.customer, #{customers} )
  973. </if>
  974. <if test="communitys != null and communitys != '' ">
  975. or FIND_IN_SET( dd.community, #{communitys} )
  976. </if>
  977. <if test="buildings != null and buildings != '' ">
  978. or FIND_IN_SET( dd.building, #{buildings} )
  979. </if>
  980. </trim>
  981. )
  982. and d.date_update >= #{beginDate ,jdbcType=TIMESTAMP }
  983. and d.date_update <![CDATA[ < ]]> #{endDate ,jdbcType=TIMESTAMP }
  984. </select>
  985. <select id="findFaultByCommunity" resultType="com.bz.smart_city.dto.assistant.PlanCommunityDTO">
  986. SELECT
  987. *
  988. FROM
  989. (
  990. SELECT
  991. sc.id AS community_id,
  992. sc.`name` AS community_name,
  993. sum( IF ( sd.device_status = 5, 1, 0 ) ) AS un_used_count,
  994. sum( IF ( sd.device_status = 2, 1, 0 ) ) AS fault_count
  995. FROM
  996. sc_device sd
  997. LEFT JOIN sc_building sb ON ( sd.building_id = sb.id )
  998. LEFT JOIN sc_community sc ON ( sb.community = sc.id )
  999. WHERE
  1000. sd.`status` = 1
  1001. AND sd.customer_id = #{customerId}
  1002. <if test="communityName != null and communityName !='' ">
  1003. and sc.`name` LIKE concat('%',#{communityName},'%')
  1004. </if>
  1005. GROUP BY
  1006. sc.id,
  1007. sc.`name`
  1008. ) tmp
  1009. WHERE
  1010. ( un_used_count + fault_count ) != 0
  1011. </select>
  1012. <select id="findFaultByBuilding" resultType="com.bz.smart_city.dto.assistant.PlanBuildingDTO">
  1013. SELECT
  1014. *
  1015. FROM
  1016. (
  1017. SELECT
  1018. sb.id AS building_id,
  1019. sb.`name` AS building_name,
  1020. sum( IF ( sd.device_status = 5, 1, 0 ) ) AS un_used_count,
  1021. sum( IF ( sd.device_status = 2, 1, 0 ) ) AS fault_count
  1022. FROM
  1023. sc_device sd
  1024. LEFT JOIN sc_building sb ON ( sd.building_id = sb.id )
  1025. WHERE
  1026. sd.`status` = 1
  1027. AND sd.customer_id = #{customerId}
  1028. and sb.community = #{communityId}
  1029. GROUP BY
  1030. sb.id,
  1031. sb.`name`
  1032. ) tmp
  1033. WHERE
  1034. ( un_used_count + fault_count ) != 0
  1035. </select>
  1036. <select id="findFaultList" resultType="com.bz.smart_city.dto.assistant.InstallListDTO">
  1037. select
  1038. sc.id as device_id ,
  1039. sc.device_no as device_no,
  1040. sc.water_meter_no as electronic_no ,
  1041. sc.loc_desc as location,
  1042. sc.device_status as device_status
  1043. from
  1044. sc_device sc
  1045. where sc.`status` = 1
  1046. and sc.customer_id = #{customerId}
  1047. and sc.device_status in (2,5)
  1048. and sc.building_id = #{buildingId}
  1049. <if test="floor != null and floor != 0 ">
  1050. and sc.floor = #{floor}
  1051. </if>
  1052. <if test="deviceStatus != null and deviceStatus != 0">
  1053. and sc.device_status = #{deviceStatus}
  1054. </if>
  1055. </select>
  1056. <select id="findByDeviceIdIgnore" resultMap="BaseResultMap">
  1057. select * from sc_device where id = #{deviceId}
  1058. </select>
  1059. <select id="findByAccountId" resultType="com.bz.smart_city.entity.Device">
  1060. select MAX(device.metercode) as metercode,account.accountnumber as accountnumber
  1061. from pay_base_account account
  1062. LEFT JOIN sc_device device on device.account_id=account.id
  1063. where account.id=#{accountId}
  1064. group by account.accountnumber
  1065. </select>
  1066. <select id="queryDeviceInfoList" resultType="com.bz.smart_city.dto.DeviceDto">
  1067. select sd.*,
  1068. sdt.equipment_type,sdt.model,sdm.name manufacturer_name,sb.name as building_name,sc.channel_name as system_name,
  1069. sb.longitude,sb.latitude,
  1070. sb.province,sb.city,sb.region,sb.community,scom.name as community_name,
  1071. scus.customer_name,
  1072. sdt.is_valve
  1073. from sc_device sd
  1074. left join sc_device_type sdt on (sdt.id = sd.device_type and sdt.status = 1)
  1075. left join sc_device_manufacturer sdm on (sdm.id = sd.manufacturer_id and sdm.status = 1)
  1076. left join sc_building sb on (sb.id = sd.building_id and sb.status = 1)
  1077. left join sc_channel sc on (sc.id = sd.sys_id and sc.status = 1)
  1078. left join sc_community scom on ( scom.id = sb.community and scom.status = 1)
  1079. left join sc_customer scus on ( scus.id = sd.customer_id)
  1080. <if test="programItems != null and programItems.size() != 0">left join sc_device_dimension sdd on (sdd.device_id = sd.id and sdd.status = 1)</if>
  1081. where sd.status = 1
  1082. <if test="siteId != null"> AND sd.site_id = #{siteId}</if>
  1083. <if test="deviceNo != null and deviceNo != ''"> AND sd.device_no = #{deviceNo}</if>
  1084. <if test="waterMeterNo != null and waterMeterNo != ''"> AND sd.water_meter_no = #{waterMeterNo}</if>
  1085. <if test="programItems != null and programItems.size() != 0"> and
  1086. <foreach collection="programItems" item="item" open="(" separator=" or " close=")">
  1087. sdd.${item.dimensionCode} = #{item.dimensionValue}
  1088. </foreach>
  1089. </if>
  1090. </select>
  1091. <select id="findByFileNo" resultType="com.bz.smart_city.entity.Device">
  1092. select b.water_meter_file_no ,b.id from sc_customer a left join sc_device b on a.id=b.customer_id
  1093. where
  1094. a.customer_no=#{customerNo}
  1095. and b.water_meter_file_no in
  1096. <foreach collection="fileNos" item="item" separator="," open="(" close=")">
  1097. #{item}
  1098. </foreach>
  1099. </select>
  1100. <select id="meterSync" resultType="com.bz.smart_city.dto.sync.MeterSyncDto">
  1101. select
  1102. sd.device_no,
  1103. sd.loc_desc,
  1104. sd.customer_id,
  1105. sd.water_meter_no,
  1106. sd.water_meter_file_no as file_no,
  1107. sd.status,
  1108. sd.date_create,
  1109. sd.date_update,
  1110. sil.new_meter_start as initial_data,
  1111. CONCAT_WS('/',sdm.name,sdt.equipment_type,sdt.model) as device_type
  1112. from sc_device sd
  1113. left join sc_install_list sil on(sil.device_id = sd.id)
  1114. left join sc_device_type sdt on(sdt.id = sd.device_type)
  1115. left join sc_device_manufacturer sdm on(sdm.id = sdt.manufacturer_id)
  1116. where sd.status = 1
  1117. and sd.customer_id = #{customerId}
  1118. <if test="createDate != null and createDate != ''"> and DATE_FORMAT(sd.date_create, '%Y%m%d' ) = #{createDate}</if>
  1119. and sd.water_meter_file_no in <foreach collection="fileNo" item="item" open="(" separator="," close=")">#{item}</foreach>
  1120. </select>
  1121. </mapper>