DeviceInfoMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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="device_name" property="deviceName"/>
  7. <result column="m" property="m"/>
  8. <result column="lon" property="lon"/>
  9. <result column="lat" property="lat"/>
  10. <result column="device_type" property="deviceType"/>
  11. <result column="merc_device_code" property="mercDeviceCode"/>
  12. <result column="merc_id" property="mercId"/>
  13. <result column="merc_code" property="mercCode"/>
  14. <result column="place_id" property="placeId"/>
  15. <result column="place_line_id" property="placeLineId"/>
  16. <result column="district_id" property="districtId"/>
  17. <result column="active_state" property="activeState"/>
  18. <result column="active_time" property="activeTime"/>
  19. <result column="busy_state" property="busyState"/>
  20. <result column="show_status" property="showStatus"/>
  21. <result column="freeze_status" property="freezeStatus"/>
  22. <result column="device_img" property="deviceImg"/>
  23. <result column="update_time" property="updateTime"/>
  24. <result column="merc_name" property="mercName"/>
  25. <result column="create_time" property="createTime"/>
  26. <association property="deviceSysinfo" javaType="com.xy.dto.DeviceSysinfoDto$Vo">
  27. <result column="sysinfo_device_sn" property="deviceSn"/>
  28. <result column="android_start_app_version" property="androidStartAppVersion"/>
  29. <result column="android_version" property="androidVersion"/>
  30. <result column="android_root_state" property="androidRootState"/>
  31. <result column="android_model" property="androidModel"/>
  32. <result column="sys_launcher" property="sysLauncher"/>
  33. <result column="sys_timezone" property="sysTimezone"/>
  34. <result column="sys_datetimeauto" property="sysDatetimeauto"/>
  35. <result column="sys_timezhoneauto" property="sysTimezhoneauto"/>
  36. <result column="app_upm_version" property="appUpmVersion"/>
  37. <result column="app_downm_version" property="appDownmVersion"/>
  38. <result column="sim_iccid" property="simIccid"/>
  39. <result column="sim_isp" property="simIsp"/>
  40. <result column="sim_company" property="simCompany"/>
  41. <result column="disk_space" property="diskSpace"/>
  42. <result column="memery_space" property="memerySpace"/>
  43. <result column="sysinfo_create_time" property="createTime"/>
  44. </association>
  45. <association property="deviceStatus" javaType="com.xy.dto.DeviceStatusDto$Vo">
  46. <result column="sys_start_time" property="sysStartTime"/>
  47. <result column="sys_cur_time" property="sysCurTime"/>
  48. <result column="sys_power" property="sysPower"/>
  49. <result column="wifi_open" property="wifiOpen"/>
  50. <result column="blooth_open" property="bloothOpen"/>
  51. <result column="net_state" property="netState"/>
  52. <result column="net_type" property="netType"/>
  53. <result column="net_dbm" property="netDbm"/>
  54. <result column="door_state_l" property="doorStateL"/>
  55. <result column="door_state_r" property="doorStateR"/>
  56. <result column="lock_state_l" property="lockStateL"/>
  57. <result column="lock_state_r" property="lockStateR"/>
  58. <result column="temp_value" property="tempValue"/>
  59. <result column="temp_state" property="tempState"/>
  60. <result column="voice_volume" property="voiceVolume"/>
  61. <result column="light_main" property="lightMain"/>
  62. <result column="light_second" property="lightSecond"/>
  63. <result column="disk_space" property="diskSpace"/>
  64. <result column="disk_remain_space" property="diskRemainSpace"/>
  65. <result column="memery_remain_space" property="memeryRemainSpace"/>
  66. <result column="camera_l_main_state" property="cameraLMainState"/>
  67. <result column="camera_l_second_state" property="cameraLSecondState"/>
  68. <result column="device_state_l" property="deviceStateL"/>
  69. <result column="device_state_r" property="deviceStateR"/>
  70. <result column="update_time" property="updateTime"/>
  71. <result column="stock" property="stock"/>
  72. <result column="after_fill_stock" property="afterFillStock"/>
  73. <result column="stock_status" property="stockStatus"/>
  74. </association>
  75. <association property="deviceRegister" javaType="com.xy.dto.DeviceRegisterDto$Vo">
  76. <result column="register_num" property="registerNum"/>
  77. <result column="dr_device_sn" property="deviceSn"/>
  78. <result column="device_type" property="deviceType"/>
  79. <result column="device_pc" property="devicePc"/>
  80. <result column="asset_no" property="assetNo"/>
  81. <result column="dr_create_time" property="createTime"/>
  82. <result column="create_user" property="createUser"/>
  83. </association>
  84. </resultMap>
  85. <!-- 分页查询 -->
  86. <select id="queryPage" resultMap="queryPageMap">
  87. select
  88. info.*,
  89. dr.register_num, dr.device_sn as dr_device_sn, dr.device_type, dr.device_pc, dr.asset_no, dr.create_time as
  90. dr_create_time, dr.create_user,
  91. sysinfo.device_sn as sysinfo_device_sn, sysinfo.android_start_app_version, sysinfo.android_version,
  92. sysinfo.android_root_state, sysinfo.android_model, sysinfo.sys_launcher,
  93. sysinfo.sys_timezone, sysinfo.sys_datetimeauto, sysinfo.sys_timezhoneauto, sysinfo.app_upm_version,
  94. sysinfo.app_downm_version, sysinfo.sim_iccid, sysinfo.sim_isp,
  95. sysinfo.sim_company, sysinfo.disk_space, sysinfo.memery_space, sysinfo.create_time as sysinfo_create_time,
  96. status.sys_start_time, status.sys_cur_time, status.sys_power, status.wifi_open, status.blooth_open,
  97. status.net_state, status.net_type, status.net_dbm, status.door_state_l,
  98. status.door_state_r, status.lock_state_l, status.lock_state_r, status.temp_value, status.temp_state,
  99. status.voice_volume, status.light_main, status.light_second, status.disk_space,
  100. status.disk_remain_space, status.memery_space, status.memery_remain_space, status.camera_l_main_state,
  101. status.camera_l_second_state, status.camera_r_main_state, status.camera_r_second_state,
  102. status.device_state_l, status.device_state_r, status.update_time,
  103. status.stock, status.after_fill_stock, status.stock_status,
  104. mr.name as merc_name,
  105. mp.place_name,
  106. ml.line_name as place_line_name,
  107. sr.name as district_name
  108. <if test="queryPage.lon != null and queryPage.lon != ''">
  109. ,ROUND(
  110. 6378.138 * 2 * ASIN(
  111. SQRT(
  112. POW(
  113. SIN(
  114. (
  115. #{queryPage.lat} * PI() / 180 - info.lat * PI() / 180
  116. ) / 2
  117. ),
  118. 2
  119. ) + COS(#{queryPage.lat} * PI() / 180) * COS(info.lat * PI() / 180) * POW(
  120. SIN(
  121. (
  122. #{queryPage.lon} * PI() / 180 - info.lon * PI() / 180
  123. ) / 2
  124. ),
  125. 2
  126. )
  127. )
  128. ) * 1000
  129. ) AS m
  130. </if>
  131. from device_info info
  132. join device_sysinfo sysinfo on(info.device_id = sysinfo.device_id)
  133. join device_status status on(info.device_id = status.device_id)
  134. join device_register dr on(info.device_id = dr.device_id)
  135. left join merc mr on(info.merc_id = mr.id)
  136. left join merc_place mp on(info.place_id = mp.id)
  137. left join merc_line ml on(info.place_line_id = ml.id)
  138. left join sys_region sr on(info.district_id = sr.id)
  139. where
  140. 1 = 1
  141. <if test="queryPage.isBindMerc != null">
  142. <choose>
  143. <when test="queryPage.isBindMerc == true">
  144. and info.merc_id is not null
  145. </when>
  146. <otherwise>
  147. and (info.merc_id is null or info.merc_id = '')
  148. </otherwise>
  149. </choose>
  150. </if>
  151. <if test="queryPage.showStatus != null">
  152. and info.show_status = #{queryPage.showStatus}
  153. </if>
  154. <if test="queryPage.deviceIdName != null and queryPage.deviceIdName != ''">
  155. and (
  156. LOCATE(#{queryPage.deviceIdName}, info.device_id) > 0 or LOCATE(#{queryPage.deviceIdName}, info.device_name)
  157. > 0
  158. )
  159. </if>
  160. <if test="queryPage.deviceId != null">
  161. and LOCATE(#{queryPage.deviceId}, info.device_id) > 0
  162. </if>
  163. <if test="queryPage.deviceIdList != null">
  164. and device_id IN
  165. <foreach collection="queryPage.deviceIdList" item="deviceId" open="(" close=")" separator=",">
  166. #{deviceId}
  167. </foreach>
  168. </if>
  169. <if test="queryPage.deviceName != null and queryPage.deviceName != ''">
  170. and LOCATE(#{queryPage.deviceName}, sysinfo.device_name) > 0
  171. </if>
  172. <if test="queryPage.no != null and queryPage.no != ''">
  173. and (
  174. LOCATE(#{queryPage.no}, info.merc_device_code) > 0 or LOCATE(#{queryPage.no}, sysinfo.device_sn) > 0 or
  175. LOCATE(#{queryPage.no}, sysinfo.sim_iccid) > 0
  176. )
  177. </if>
  178. <if test="queryPage.activeState != null">
  179. and info.active_state = #{queryPage.activeState}
  180. </if>
  181. <if test="queryPage.netState != null">
  182. and status.net_state = #{queryPage.netState}
  183. </if>
  184. <if test="queryPage.stockStatus != null">
  185. and status.stock_status = #{queryPage.stockStatus}
  186. </if>
  187. <if test="queryPage.busyState != null">
  188. and info.busy_state = #{queryPage.busyState}
  189. </if>
  190. <if test="queryPage.deviceType != null">
  191. and info.device_type = #{queryPage.deviceType}
  192. </if>
  193. <if test="queryPage.mercDeviceCode != null and queryPage.mercDeviceCode != ''">
  194. and LOCATE(#{queryPage.mercDeviceCode}, info.merc_device_code) > 0
  195. </if>
  196. <if test="queryPage.mercCode != null and queryPage.mercCode != ''">
  197. and info.merc_code = #{queryPage.mercCode}
  198. </if>
  199. <if test="queryPage.mercId != null">
  200. and info.merc_id = #{queryPage.mercId}
  201. </if>
  202. <if test="queryPage.merc != null and queryPage.merc != ''">
  203. and (
  204. info.merc_id = #{queryPage.merc} or info.merc_code = #{queryPage.merc} or LOCATE(#{queryPage.merc}, mr.name)
  205. > 0
  206. )
  207. </if>
  208. <if test="queryPage.placeId != null">
  209. and info.place_id = #{queryPage.placeId}
  210. </if>
  211. <if test="queryPage.placeLineId != null">
  212. and info.place_line_id = #{queryPage.placeLineId}
  213. </if>
  214. <if test="queryPage.districtId != null">
  215. and info.district_id = #{queryPage.districtId}
  216. </if>
  217. <if test="queryPage.activeState != null">
  218. and info.active_state = #{queryPage.activeState}
  219. </if>
  220. <if test="queryPage.busyState != null">
  221. and info.busy_state = #{queryPage.busyState}
  222. </if>
  223. <if test="queryPage.appUpmVersion != null and queryPage.appUpmVersion != ''">
  224. and sysinfo.app_upm_version = #{queryPage.appUpmVersion}
  225. </if>
  226. <if test="queryPage.appDownmVersion != null and queryPage.appDownmVersion != ''">
  227. and sysinfo.app_downm_version = #{queryPage.appDownmVersion}
  228. </if>
  229. <if test="queryPage.beginActiveTime != null and queryPage.beginActiveTime != ''">
  230. and info.active_time >= #{queryPage.beginActiveTime}
  231. </if>
  232. <if test="queryPage.endActiveTime != null and queryPage.endActiveTime != ''">
  233. and info.active_time &lt;= #{queryPage.endActiveTime}
  234. </if>
  235. <if test="queryPage.lon != null and queryPage.lon != ''">
  236. <if test="queryPage.nearby != null">
  237. HAVING `m` &lt;= #{queryPage.nearby}
  238. </if>
  239. </if>
  240. <choose>
  241. <when test="queryPage.lon != null and queryPage.lon != ''">
  242. order by `m` asc
  243. </when>
  244. <otherwise>
  245. order by info.create_time desc
  246. </otherwise>
  247. </choose>
  248. <if test="queryPage.limitNum != null">
  249. limit #{queryPage.limitNum }
  250. </if>
  251. </select>
  252. <!-- 小程序首页设备列表线路分组 -->
  253. <select id="merHomeCountList" resultType="com.xy.dto.DeviceInfoDto$MercHomeCountVO">
  254. select count(*) deviceNum, IFNULL(place_line_id,-1) placeLineId
  255. from device_info
  256. <where>
  257. active_state='1'
  258. <if test="query.mercId != null">
  259. and merc_id = #{query.mercId}
  260. </if>
  261. <if test="query.deviceName != null and query.deviceName != ''">
  262. and device_name like concat('%', #{query.deviceName}, '%')
  263. </if>
  264. <if test="query.deviceId != null">
  265. and device_id = #{query.deviceId}
  266. </if>
  267. </where>
  268. group by place_line_id
  269. </select>
  270. </mapper>