DeviceInfoMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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.xy.mapper.DeviceInfoMapper">
  4. <resultMap id="queryPageMap" type="com.xy.mapper.entity.DeviceInfoQueryPage">
  5. <id column="device_id" property="deviceId"/>
  6. <result column="algorithm_id" property="algorithmId"/>
  7. <result column="device_name" property="deviceName"/>
  8. <result column="m" property="m"/>
  9. <result column="lon" property="lon"/>
  10. <result column="lat" property="lat"/>
  11. <result column="device_type" property="deviceType"/>
  12. <result column="merc_device_code" property="mercDeviceCode"/>
  13. <result column="merc_id" property="mercId"/>
  14. <result column="merc_code" property="mercCode"/>
  15. <result column="place_id" property="placeId"/>
  16. <result column="place_line_id" property="placeLineId"/>
  17. <result column="district_id" property="districtId"/>
  18. <result column="active_state" property="activeState"/>
  19. <result column="active_time" property="activeTime"/>
  20. <result column="busy_state" property="busyState"/>
  21. <result column="show_status" property="showStatus"/>
  22. <result column="freeze_status" property="freezeStatus"/>
  23. <result column="device_img" property="deviceImg"/>
  24. <result column="update_time" property="updateTime"/>
  25. <result column="merc_name" property="mercName"/>
  26. <result column="create_time" property="createTime"/>
  27. <result column="place_name" property="placeName"/>
  28. <result column="place_line_name" property="placeLineName"/>
  29. <result column="district_name" property="districtName"/>
  30. <association property="deviceSysinfo" javaType="com.xy.dto.DeviceSysinfoDto$Vo">
  31. <result column="sysinfo_device_sn" property="deviceSn"/>
  32. <result column="android_start_app_version" property="androidStartAppVersion"/>
  33. <result column="android_version" property="androidVersion"/>
  34. <result column="android_root_state" property="androidRootState"/>
  35. <result column="android_model" property="androidModel"/>
  36. <result column="sys_launcher" property="sysLauncher"/>
  37. <result column="sys_timezone" property="sysTimezone"/>
  38. <result column="sys_datetimeauto" property="sysDatetimeauto"/>
  39. <result column="sys_timezhoneauto" property="sysTimezhoneauto"/>
  40. <result column="app_upm_version" property="appUpmVersion"/>
  41. <result column="app_downm_version" property="appDownmVersion"/>
  42. <result column="sim_iccid" property="simIccid"/>
  43. <result column="sim_isp" property="simIsp"/>
  44. <result column="sim_company" property="simCompany"/>
  45. <result column="disk_space" property="diskSpace"/>
  46. <result column="memery_space" property="memerySpace"/>
  47. <result column="is_have_temp" property="isHaveTemp"/>
  48. <result column="is_have_light_main" property="isHaveLightMain"/>
  49. <result column="is_have_light_second" property="isHaveLightSecond"/>
  50. <result column="is_have_freeze" property="isHaveFreeze"/>
  51. <result column="is_have_heat" property="isHaveHeat"/>
  52. <result column="device_model" property="deviceModel"/>
  53. <result column="screen_type" property="screenType"/>
  54. </association>
  55. <association property="deviceStatus" javaType="com.xy.dto.DeviceStatusDto$Vo">
  56. <result column="sys_start_time" property="sysStartTime"/>
  57. <result column="sys_cur_time" property="sysCurTime"/>
  58. <result column="sys_power" property="sysPower"/>
  59. <result column="wifi_open" property="wifiOpen"/>
  60. <result column="blooth_open" property="bloothOpen"/>
  61. <result column="net_state" property="netState"/>
  62. <result column="net_type" property="netType"/>
  63. <result column="net_dbm" property="netDbm"/>
  64. <result column="door_state_l" property="doorStateL"/>
  65. <result column="door_state_r" property="doorStateR"/>
  66. <result column="lock_state_l" property="lockStateL"/>
  67. <result column="lock_state_r" property="lockStateR"/>
  68. <result column="temp_value" property="tempValue"/>
  69. <result column="temp_state" property="tempState"/>
  70. <result column="voice_volume" property="voiceVolume"/>
  71. <result column="light_main" property="lightMain"/>
  72. <result column="light_second" property="lightSecond"/>
  73. <result column="status_disk_space" property="diskSpace"/>
  74. <result column="disk_remain_space" property="diskRemainSpace"/>
  75. <result column="memery_remain_space" property="memeryRemainSpace"/>
  76. <result column="camera_l_main_state" property="cameraLMainState"/>
  77. <result column="camera_l_second_state" property="cameraLSecondState"/>
  78. <result column="device_state_l" property="deviceStateL"/>
  79. <result column="device_state_r" property="deviceStateR"/>
  80. <result column="status_update_time" property="updateTime"/>
  81. <result column="stock" property="stock"/>
  82. <result column="after_fill_stock" property="afterFillStock"/>
  83. <result column="stock_status" property="stockStatus"/>
  84. <result column="is_use_battery" property="isUseBattery"/>
  85. <result column="jg1_lock_state_l" property="jg1LockStateL"/>
  86. <result column="jg1_lock_state_r" property="jg1LockStateR"/>
  87. </association>
  88. <association property="deviceRegister" javaType="com.xy.dto.DeviceRegisterDto$Vo">
  89. <result column="register_num" property="registerNum"/>
  90. <result column="dr_device_sn" property="deviceSn"/>
  91. <result column="device_type" property="deviceType"/>
  92. <result column="device_pc" property="devicePc"/>
  93. <result column="asset_no" property="assetNo"/>
  94. <result column="dr_create_time" property="createTime"/>
  95. <result column="create_user" property="createUser"/>
  96. </association>
  97. </resultMap>
  98. <select id="listByAdminName" resultType="com.xy.dto.DeviceInfoDto$ListByAdminName">
  99. SELECT d.device_id, d.device_name, p.admin_name, d.device_type,d.algorithm_id
  100. FROM device_info d
  101. left join merc_place p on p.id = d.place_id
  102. <where>
  103. and d.merc_id = #{dto.mercId}
  104. and d.active_state = 1
  105. <if test="dto.deviceIdList != null and dto.deviceIdList.size > 0">
  106. and device_id in
  107. <foreach collection="dto.deviceIdList" index="index" item="item" open="(" separator="," close=")">
  108. #{item}
  109. </foreach>
  110. </if>
  111. <if test="dto.searchKey != null and dto.searchKey != ''">
  112. and CONCAT(IFNULL(d.device_name, ''), IFNULL(p.admin_name, '')) like CONCAT('%', #{dto.searchKey}, '%')
  113. </if>
  114. <if test="dto.algorithmId != null">
  115. and d.algorithm_id = #{dto.algorithmId}
  116. </if>
  117. </where>
  118. </select>
  119. <select id="pageByAdminName" resultType="com.xy.dto.DeviceInfoDto$ListByAdminName">
  120. SELECT d.device_id, d.device_name, p.admin_name,p.admin_id, d.device_type,p.region_name,p.place_name,m.name as
  121. merc_name,m.merc_code as merc_code
  122. FROM device_info d
  123. left join merc_place p on p.id = d.place_id
  124. left join merc m on m.id = d.merc_id
  125. <where>
  126. and d.merc_id = #{dto.mercId}
  127. and d.active_state = 1
  128. <if test="dto.deviceIdList != null and dto.deviceIdList.size > 0">
  129. and device_id in
  130. <foreach collection="dto.deviceIdList" index="index" item="item" open="(" separator="," close=")">
  131. #{item}
  132. </foreach>
  133. </if>
  134. <if test="dto.searchKey != null and dto.searchKey != ''">
  135. and CONCAT(IFNULL(d.device_name, ''), IFNULL(p.admin_name, '')) like CONCAT('%', #{dto.searchKey}, '%')
  136. </if>
  137. <if test="dto.deviceType != null">
  138. and d.device_type = #{dto.deviceType}
  139. </if>
  140. <if test="dto.placeId != null">
  141. and d.place_id = #{dto.placeId}
  142. </if>
  143. <if test="dto.deviceId != null">
  144. and d.device_id = #{dto.deviceId}
  145. </if>
  146. <if test="dto.regionName != null and dto.regionName != ''">
  147. and p.region_name = #{dto.regionName}
  148. </if>
  149. </where>
  150. order by p.admin_name asc,d.device_id desc
  151. </select>
  152. <!-- 分页查询 -->
  153. <select id="queryPage" resultMap="queryPageMap">
  154. select info.*,
  155. dr.register_num,
  156. dr.device_sn as dr_device_sn,
  157. dr.device_pc,
  158. dr.asset_no,
  159. dr.create_time as
  160. dr_create_time,
  161. dr.create_user,
  162. sysinfo.device_sn as sysinfo_device_sn,
  163. sysinfo.android_start_app_version,
  164. sysinfo.android_version,
  165. sysinfo.android_root_state,
  166. sysinfo.android_model,
  167. sysinfo.sys_launcher,
  168. sysinfo.sys_timezone,
  169. sysinfo.sys_datetimeauto,
  170. sysinfo.sys_timezhoneauto,
  171. sysinfo.app_upm_version,
  172. sysinfo.app_downm_version,
  173. sysinfo.sim_iccid,
  174. sysinfo.sim_isp,
  175. sysinfo.sim_company,
  176. sysinfo.disk_space,
  177. sysinfo.memery_space,
  178. sysinfo.create_time as sysinfo_create_time,
  179. sysinfo.is_have_temp,
  180. sysinfo.is_have_light_main,
  181. sysinfo.is_have_light_second,
  182. sysinfo.is_have_freeze,
  183. sysinfo.is_have_heat,
  184. sysinfo.device_model,
  185. sysinfo.screen_type,
  186. status.sys_start_time,
  187. status.sys_cur_time,
  188. status.sys_power,
  189. status.wifi_open,
  190. status.blooth_open,
  191. status.net_state,
  192. status.net_type,
  193. status.net_dbm,
  194. status.door_state_l,
  195. status.door_state_r,
  196. status.lock_state_l,
  197. status.lock_state_r,
  198. status.temp_value,
  199. status.temp_state,
  200. status.voice_volume,
  201. status.light_main,
  202. status.light_second,
  203. status.disk_space as status_disk_space,
  204. status.disk_remain_space,
  205. status.memery_remain_space,
  206. status.camera_l_main_state,
  207. status.camera_l_second_state,
  208. status.camera_r_main_state,
  209. status.camera_r_second_state,
  210. status.device_state_l,
  211. status.device_state_r,
  212. status.update_time as status_update_time,
  213. status.stock,
  214. status.after_fill_stock,
  215. status.stock_status,
  216. status.is_use_battery,
  217. status.jg1_lock_state_l,
  218. status.jg1_lock_state_r,
  219. mp.place_name,
  220. ml.line_name as place_line_name,
  221. sr.name as district_name
  222. <if test="queryPage.lon != null and queryPage.lon != ''">
  223. ,
  224. ROUND(
  225. 6378.138 * 2 * ASIN(
  226. SQRT(
  227. POW(
  228. SIN(
  229. (
  230. #{queryPage.lat} * PI() / 180 - info.lat * PI() / 180
  231. ) / 2
  232. ),
  233. 2
  234. ) +
  235. COS(#{queryPage.lat} * PI() / 180) * COS(info.lat * PI() / 180) * POW(
  236. SIN(
  237. (
  238. #{queryPage.lon} * PI() / 180 - info.lon * PI() / 180
  239. ) / 2
  240. ),
  241. 2
  242. )
  243. )
  244. ) * 1000
  245. ) AS m
  246. </if>
  247. from device_info info
  248. join device_sysinfo sysinfo on (info.device_id = sysinfo.device_id)
  249. join device_status status on (info.device_id = status.device_id)
  250. join device_register dr on (info.device_id = dr.device_id)
  251. left join merc mr on (info.merc_id = mr.id)
  252. left join merc_place mp on (info.place_id = mp.id)
  253. left join merc_line ml on (info.place_line_id = ml.id)
  254. left join sys_region sr on (info.district_id = sr.id)
  255. where 1 = 1
  256. <if test="queryPage.isBindMerc != null">
  257. <choose>
  258. <when test="queryPage.isBindMerc == true">
  259. and info.merc_id is not null
  260. </when>
  261. <otherwise>
  262. and (info.merc_id is null or info.merc_id = '')
  263. </otherwise>
  264. </choose>
  265. </if>
  266. <if test="queryPage.keyword != null and queryPage.keyword != ''">
  267. and CONCAT(IFNULL(info.device_name, ''), IFNULL(info.device_id, '')) LIKE
  268. CONCAT('%',#{queryPage.keyword},'%')
  269. </if>
  270. <if test="queryPage.showStatus != null">
  271. and info.show_status = #{queryPage.showStatus}
  272. </if>
  273. <if test="queryPage.deviceIdName != null and queryPage.deviceIdName != ''">
  274. and (
  275. LOCATE(#{queryPage.deviceIdName}, info.device_id) > 0 or
  276. LOCATE(#{queryPage.deviceIdName}, info.device_name)
  277. > 0
  278. )
  279. </if>
  280. <if test="queryPage.deviceId != null">
  281. and LOCATE(#{queryPage.deviceId}, info.device_id) > 0
  282. </if>
  283. <if test="queryPage.deviceIdList != null">
  284. and info.device_id IN
  285. <foreach collection="queryPage.deviceIdList" item="deviceId" open="(" close=")" separator=",">
  286. #{deviceId}
  287. </foreach>
  288. </if>
  289. <if test="queryPage.deviceName != null and queryPage.deviceName != ''">
  290. and LOCATE(#{queryPage.deviceName}, info.device_name) > 0
  291. </if>
  292. <if test="queryPage.no != null and queryPage.no != ''">
  293. and (
  294. LOCATE(#{queryPage.no}, info.merc_device_code) > 0 or
  295. LOCATE(#{queryPage.no}, sysinfo.device_sn) > 0 or
  296. LOCATE(#{queryPage.no}, sysinfo.sim_iccid) > 0
  297. )
  298. </if>
  299. <if test="queryPage.activeState != null">
  300. and info.active_state = #{queryPage.activeState}
  301. </if>
  302. <if test="queryPage.netState != null">
  303. and status.net_state = #{queryPage.netState}
  304. </if>
  305. <if test="queryPage.stockStatus != null">
  306. and status.stock_status = #{queryPage.stockStatus}
  307. </if>
  308. <if test="queryPage.busyState != null">
  309. and info.busy_state = #{queryPage.busyState}
  310. </if>
  311. <if test="queryPage.deviceType != null">
  312. and info.device_type = #{queryPage.deviceType}
  313. </if>
  314. <if test="queryPage.mercDeviceCode != null and queryPage.mercDeviceCode != ''">
  315. and LOCATE(#{queryPage.mercDeviceCode}, info.merc_device_code) > 0
  316. </if>
  317. <if test="queryPage.mercCode != null and queryPage.mercCode != ''">
  318. and info.merc_code = #{queryPage.mercCode}
  319. </if>
  320. <if test="queryPage.mercId != null">
  321. and info.merc_id = #{queryPage.mercId}
  322. </if>
  323. <if test="queryPage.merc != null and queryPage.merc != ''">
  324. and (
  325. info.merc_id = #{queryPage.merc} or LOCATE(#{queryPage.merc}, info.merc_code) > 0 or LOCATE(#{queryPage.merc}, mr.name) > 0
  326. )
  327. </if>
  328. <if test="queryPage.placeId != null">
  329. and info.place_id = #{queryPage.placeId}
  330. </if>
  331. <if test="queryPage.placeLineId != null">
  332. and info.place_line_id = #{queryPage.placeLineId}
  333. </if>
  334. <if test="queryPage.districtId != null">
  335. and info.district_id = #{queryPage.districtId}
  336. </if>
  337. <if test="queryPage.activeState != null">
  338. and info.active_state = #{queryPage.activeState}
  339. </if>
  340. <if test="queryPage.busyState != null">
  341. and info.busy_state = #{queryPage.busyState}
  342. </if>
  343. <if test="queryPage.appUpmVersion != null and queryPage.appUpmVersion != ''">
  344. and sysinfo.app_upm_version = #{queryPage.appUpmVersion}
  345. </if>
  346. <if test="queryPage.appDownmVersion != null and queryPage.appDownmVersion != ''">
  347. and sysinfo.app_downm_version = #{queryPage.appDownmVersion}
  348. </if>
  349. <if test="queryPage.beginActiveTime != null and queryPage.beginActiveTime != ''">
  350. and info.active_time >= #{queryPage.beginActiveTime}
  351. </if>
  352. <if test="queryPage.endActiveTime != null and queryPage.endActiveTime != ''">
  353. and info.active_time &lt;= #{queryPage.endActiveTime}
  354. </if>
  355. <if test="queryPage.lon != null and queryPage.lon != ''">
  356. <if test="queryPage.nearby != null">
  357. HAVING `m` &lt;= #{queryPage.nearby}
  358. </if>
  359. </if>
  360. <choose>
  361. <when test="queryPage.lon != null and queryPage.lon != ''">
  362. order by `m` asc
  363. </when>
  364. <otherwise>
  365. order by info.create_time desc
  366. </otherwise>
  367. </choose>
  368. <if test="queryPage.limitNum != null">
  369. limit #{queryPage.limitNum }
  370. </if>
  371. </select>
  372. <!-- 小程序首页设备列表线路分组 -->
  373. <select id="merHomeCountList" resultType="com.xy.dto.DeviceInfoDto$MercHomeCountVO">
  374. select count(*) deviceNum, IFNULL(district_id, -1) districtId
  375. from device_info
  376. <where>
  377. <if test="query.activeState != null and query.activeState != ''">
  378. and active_state = #{query.activeState}
  379. </if>
  380. <if test="query.busyStatus != null">
  381. and busy_state = #{query.busyStatus}
  382. </if>
  383. <if test="query.deviceType != null">
  384. and device_type = #{query.deviceType}
  385. </if>
  386. <if test="query.mercId != null">
  387. and merc_id = #{query.mercId}
  388. </if>
  389. <if test="query.deviceName != null and query.deviceName != ''">
  390. and device_name like concat('%', #{query.deviceName}, '%')
  391. </if>
  392. <if test="query.deviceIdList != null and query.deviceIdList.size > 0">
  393. and device_id in
  394. <foreach collection="query.deviceIdList" index="index" item="item" open="(" separator="," close=")">
  395. #{item}
  396. </foreach>
  397. </if>
  398. </where>
  399. group by district_id
  400. </select>
  401. <select id="netStateCount" resultType="com.xy.dto.DeviceInfoDto$NetStateCount">
  402. SELECT d.merc_id,net_state, count(*) as count
  403. FROM device_info d
  404. LEFT JOIN device_status s ON s.device_id = d.device_id
  405. <where>
  406. d.active_state = '1'
  407. <if test="mercIdList != null and mercIdList.size() > 0">
  408. AND d.merc_id IN
  409. <foreach collection="mercIdList" item="mercId" index="index"
  410. open="(" close=")" separator=",">
  411. #{mercId}
  412. </foreach>
  413. </if>
  414. </where>
  415. GROUP BY d.merc_id,s.net_state
  416. </select>
  417. <select id="placeDeviceNum" resultType="com.xy.dto.DeviceInfoDto$PlaceDeviceNumVo">
  418. SELECT place_id,count(*) as num
  419. FROM device_info
  420. <where>
  421. <if test="dto.placeId != null">
  422. AND place_id = #{dto.placeId}
  423. </if>
  424. <if test="dto.placeIdList != null and dto.placeIdList.size() > 0">
  425. AND place_id IN
  426. <foreach collection="dto.placeIdList" item="placeId" index="index" open="(" close=")" separator=",">
  427. #{placeId}
  428. </foreach>
  429. </if>
  430. </where>
  431. GROUP BY place_id
  432. </select>
  433. </mapper>