DeviceInfoMapper.xml 20 KB

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