DeviceInfoMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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="sysinfo_create_time" property="createTime"/>
  48. </association>
  49. <association property="deviceStatus" javaType="com.xy.dto.DeviceStatusDto$Vo">
  50. <result column="sys_start_time" property="sysStartTime"/>
  51. <result column="sys_cur_time" property="sysCurTime"/>
  52. <result column="sys_power" property="sysPower"/>
  53. <result column="wifi_open" property="wifiOpen"/>
  54. <result column="blooth_open" property="bloothOpen"/>
  55. <result column="net_state" property="netState"/>
  56. <result column="net_type" property="netType"/>
  57. <result column="net_dbm" property="netDbm"/>
  58. <result column="door_state_l" property="doorStateL"/>
  59. <result column="door_state_r" property="doorStateR"/>
  60. <result column="lock_state_l" property="lockStateL"/>
  61. <result column="lock_state_r" property="lockStateR"/>
  62. <result column="temp_value" property="tempValue"/>
  63. <result column="temp_state" property="tempState"/>
  64. <result column="voice_volume" property="voiceVolume"/>
  65. <result column="light_main" property="lightMain"/>
  66. <result column="light_second" property="lightSecond"/>
  67. <result column="status_disk_space" property="diskSpace"/>
  68. <result column="disk_remain_space" property="diskRemainSpace"/>
  69. <result column="memery_remain_space" property="memeryRemainSpace"/>
  70. <result column="camera_l_main_state" property="cameraLMainState"/>
  71. <result column="camera_l_second_state" property="cameraLSecondState"/>
  72. <result column="device_state_l" property="deviceStateL"/>
  73. <result column="device_state_r" property="deviceStateR"/>
  74. <result column="status_update_time" property="updateTime"/>
  75. <result column="stock" property="stock"/>
  76. <result column="after_fill_stock" property="afterFillStock"/>
  77. <result column="stock_status" property="stockStatus"/>
  78. </association>
  79. <association property="deviceRegister" javaType="com.xy.dto.DeviceRegisterDto$Vo">
  80. <result column="register_num" property="registerNum"/>
  81. <result column="dr_device_sn" property="deviceSn"/>
  82. <result column="device_type" property="deviceType"/>
  83. <result column="device_pc" property="devicePc"/>
  84. <result column="asset_no" property="assetNo"/>
  85. <result column="dr_create_time" property="createTime"/>
  86. <result column="create_user" property="createUser"/>
  87. </association>
  88. </resultMap>
  89. <!-- 分页查询 -->
  90. <select id="queryPage" resultMap="queryPageMap">
  91. select info.*,
  92. dr.register_num,
  93. dr.device_sn as dr_device_sn,
  94. dr.device_pc,
  95. dr.asset_no,
  96. dr.create_time as
  97. dr_create_time,
  98. dr.create_user,
  99. sysinfo.device_sn as sysinfo_device_sn,
  100. sysinfo.android_start_app_version,
  101. sysinfo.android_version,
  102. sysinfo.android_root_state,
  103. sysinfo.android_model,
  104. sysinfo.sys_launcher,
  105. sysinfo.sys_timezone,
  106. sysinfo.sys_datetimeauto,
  107. sysinfo.sys_timezhoneauto,
  108. sysinfo.app_upm_version,
  109. sysinfo.app_downm_version,
  110. sysinfo.sim_iccid,
  111. sysinfo.sim_isp,
  112. sysinfo.sim_company,
  113. sysinfo.disk_space,
  114. sysinfo.memery_space,
  115. sysinfo.create_time as sysinfo_create_time,
  116. status.sys_start_time,
  117. status.sys_cur_time,
  118. status.sys_power,
  119. status.wifi_open,
  120. status.blooth_open,
  121. status.net_state,
  122. status.net_type,
  123. status.net_dbm,
  124. status.door_state_l,
  125. status.door_state_r,
  126. status.lock_state_l,
  127. status.lock_state_r,
  128. status.temp_value,
  129. status.temp_state,
  130. status.voice_volume,
  131. status.light_main,
  132. status.light_second,
  133. status.disk_space as status_disk_space,
  134. status.disk_remain_space,
  135. status.memery_remain_space,
  136. status.camera_l_main_state,
  137. status.camera_l_second_state,
  138. status.camera_r_main_state,
  139. status.camera_r_second_state,
  140. status.device_state_l,
  141. status.device_state_r,
  142. status.update_time as status_update_time,
  143. status.stock,
  144. status.after_fill_stock,
  145. status.stock_status,
  146. mp.place_name,
  147. ml.line_name as place_line_name,
  148. sr.name as district_name
  149. <if test="queryPage.lon != null and queryPage.lon != ''">
  150. ,
  151. ROUND(
  152. 6378.138 * 2 * ASIN(
  153. SQRT(
  154. POW(
  155. SIN(
  156. (
  157. #{queryPage.lat} * PI() / 180 - info.lat * PI() / 180
  158. ) / 2
  159. ),
  160. 2
  161. ) +
  162. COS(#{queryPage.lat} * PI() / 180) * COS(info.lat * PI() / 180) * POW(
  163. SIN(
  164. (
  165. #{queryPage.lon} * PI() / 180 - info.lon * PI() / 180
  166. ) / 2
  167. ),
  168. 2
  169. )
  170. )
  171. ) * 1000
  172. ) AS m
  173. </if>
  174. from device_info info
  175. join device_sysinfo sysinfo on (info.device_id = sysinfo.device_id)
  176. join device_status status on (info.device_id = status.device_id)
  177. join device_register dr on (info.device_id = dr.device_id)
  178. left join merc mr on (info.merc_id = mr.id)
  179. left join merc_place mp on (info.place_id = mp.id)
  180. left join merc_line ml on (info.place_line_id = ml.id)
  181. left join sys_region sr on (info.district_id = sr.id)
  182. where 1 = 1
  183. <if test="queryPage.isBindMerc != null">
  184. <choose>
  185. <when test="queryPage.isBindMerc == true">
  186. and info.merc_id is not null
  187. </when>
  188. <otherwise>
  189. and (info.merc_id is null or info.merc_id = '')
  190. </otherwise>
  191. </choose>
  192. </if>
  193. <if test="queryPage.showStatus != null">
  194. and info.show_status = #{queryPage.showStatus}
  195. </if>
  196. <if test="queryPage.deviceIdName != null and queryPage.deviceIdName != ''">
  197. and (
  198. LOCATE(#{queryPage.deviceIdName}, info.device_id) > 0 or
  199. LOCATE(#{queryPage.deviceIdName}, info.device_name)
  200. > 0
  201. )
  202. </if>
  203. <if test="queryPage.deviceId != null">
  204. and LOCATE(#{queryPage.deviceId}, info.device_id) > 0
  205. </if>
  206. <if test="queryPage.deviceIdList != null">
  207. and info.device_id IN
  208. <foreach collection="queryPage.deviceIdList" item="deviceId" open="(" close=")" separator=",">
  209. #{deviceId}
  210. </foreach>
  211. </if>
  212. <if test="queryPage.deviceName != null and queryPage.deviceName != ''">
  213. and LOCATE(#{queryPage.deviceName}, info.device_name) > 0
  214. </if>
  215. <if test="queryPage.no != null and queryPage.no != ''">
  216. and (
  217. LOCATE(#{queryPage.no}, info.merc_device_code) > 0 or
  218. LOCATE(#{queryPage.no}, sysinfo.device_sn) > 0 or
  219. LOCATE(#{queryPage.no}, sysinfo.sim_iccid) > 0
  220. )
  221. </if>
  222. <if test="queryPage.activeState != null">
  223. and info.active_state = #{queryPage.activeState}
  224. </if>
  225. <if test="queryPage.netState != null">
  226. and status.net_state = #{queryPage.netState}
  227. </if>
  228. <if test="queryPage.stockStatus != null">
  229. and status.stock_status = #{queryPage.stockStatus}
  230. </if>
  231. <if test="queryPage.busyState != null">
  232. and info.busy_state = #{queryPage.busyState}
  233. </if>
  234. <if test="queryPage.deviceType != null">
  235. and info.device_type = #{queryPage.deviceType}
  236. </if>
  237. <if test="queryPage.mercDeviceCode != null and queryPage.mercDeviceCode != ''">
  238. and LOCATE(#{queryPage.mercDeviceCode}, info.merc_device_code) > 0
  239. </if>
  240. <if test="queryPage.mercCode != null and queryPage.mercCode != ''">
  241. and info.merc_code = #{queryPage.mercCode}
  242. </if>
  243. <if test="queryPage.mercId != null">
  244. and info.merc_id = #{queryPage.mercId}
  245. </if>
  246. <if test="queryPage.merc != null and queryPage.merc != ''">
  247. and (
  248. info.merc_id = #{queryPage.merc} or info.merc_code = #{queryPage.merc} or
  249. LOCATE(#{queryPage.merc}, mr.name)
  250. > 0
  251. )
  252. </if>
  253. <if test="queryPage.placeId != null">
  254. and info.place_id = #{queryPage.placeId}
  255. </if>
  256. <if test="queryPage.placeLineId != null">
  257. and info.place_line_id = #{queryPage.placeLineId}
  258. </if>
  259. <if test="queryPage.districtId != null">
  260. and info.district_id = #{queryPage.districtId}
  261. </if>
  262. <if test="queryPage.activeState != null">
  263. and info.active_state = #{queryPage.activeState}
  264. </if>
  265. <if test="queryPage.busyState != null">
  266. and info.busy_state = #{queryPage.busyState}
  267. </if>
  268. <if test="queryPage.appUpmVersion != null and queryPage.appUpmVersion != ''">
  269. and sysinfo.app_upm_version = #{queryPage.appUpmVersion}
  270. </if>
  271. <if test="queryPage.appDownmVersion != null and queryPage.appDownmVersion != ''">
  272. and sysinfo.app_downm_version = #{queryPage.appDownmVersion}
  273. </if>
  274. <if test="queryPage.beginActiveTime != null and queryPage.beginActiveTime != ''">
  275. and info.active_time >= #{queryPage.beginActiveTime}
  276. </if>
  277. <if test="queryPage.endActiveTime != null and queryPage.endActiveTime != ''">
  278. and info.active_time &lt;= #{queryPage.endActiveTime}
  279. </if>
  280. <if test="queryPage.lon != null and queryPage.lon != ''">
  281. <if test="queryPage.nearby != null">
  282. HAVING `m` &lt;= #{queryPage.nearby}
  283. </if>
  284. </if>
  285. <choose>
  286. <when test="queryPage.lon != null and queryPage.lon != ''">
  287. order by `m` asc
  288. </when>
  289. <otherwise>
  290. order by info.create_time desc
  291. </otherwise>
  292. </choose>
  293. <if test="queryPage.limitNum != null">
  294. limit #{queryPage.limitNum }
  295. </if>
  296. </select>
  297. <!-- 小程序首页设备列表线路分组 -->
  298. <select id="merHomeCountList" resultType="com.xy.dto.DeviceInfoDto$MercHomeCountVO">
  299. select count(*) deviceNum, IFNULL(district_id, -1) districtId
  300. from device_info
  301. <where>
  302. <if test="query.activeState != null and query.activeState != ''">
  303. and active_state = #{query.activeState}
  304. </if>
  305. <if test="query.busyStatus != null">
  306. and busy_state = #{query.busyStatus}
  307. </if>
  308. <if test="query.deviceType != null">
  309. and device_type = #{query.deviceType}
  310. </if>
  311. <if test="query.mercId != null">
  312. and merc_id = #{query.mercId}
  313. </if>
  314. <if test="query.deviceName != null and query.deviceName != ''">
  315. and device_name like concat('%', #{query.deviceName}, '%')
  316. </if>
  317. <if test="query.deviceIdList != null and query.deviceIdList.size > 0">
  318. and device_id in
  319. <foreach collection="query.deviceIdList" index="index" item="item" open="(" separator="," close=")">
  320. #{item}
  321. </foreach>
  322. </if>
  323. </where>
  324. group by district_id
  325. </select>
  326. <select id="netStateCount" resultType="com.xy.dto.DeviceInfoDto$NetStateCount">
  327. SELECT d.merc_id,net_state, count(*) as count
  328. FROM device_info d
  329. LEFT JOIN device_status s ON s.device_id = d.device_id
  330. <where>
  331. d.active_state = '1'
  332. <if test="mercIdList != null and mercIdList.size() > 0">
  333. AND d.merc_id IN
  334. <foreach collection="mercIdList" item="mercId" index="index"
  335. open="(" close=")" separator=",">
  336. #{mercId}
  337. </foreach>
  338. </if>
  339. </where>
  340. GROUP BY d.merc_id,s.net_state
  341. </select>
  342. </mapper>