PersPositionDao.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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="cn.com.goldenwater.dcproj.dao.PersPositionDao">
  4. <resultMap type="cn.com.goldenwater.dcproj.model.PersPosition" id="persPositionResultMap">
  5. <result property="latitude" column="LATITUDE"/>
  6. <result property="operateTime" column="OPERATE_TIME"/>
  7. <result property="adCode" column="AD_CODE"/>
  8. <result property="longitude" column="LONGITUDE"/>
  9. <result property="id" column="ID"/>
  10. <result property="persId" column="PERS_ID"/>
  11. <result property="orgId" column="ORG_ID"/>
  12. <result property="groupId" column="GROUP_ID"/>
  13. <result property="persName" column="PERS_NAME"/>
  14. <result property="mobile" column="MOBILE"/>
  15. <result property="lon" column="LON"/>
  16. <result property="lat" column="LAT"/>
  17. <result property="status" column="STATUS"/>
  18. </resultMap>
  19. <sql id="table_columns">
  20. LATITUDE,
  21. OPERATE_TIME,
  22. AD_CODE,
  23. LONGITUDE,
  24. ID,
  25. PERS_ID,
  26. ORG_ID,
  27. GROUP_ID,
  28. PERS_NAME,
  29. MOBILE,
  30. LON,
  31. LAT
  32. </sql>
  33. <sql id="entity_properties">
  34. #{latitude},
  35. #{operateTime},
  36. #{adCode},
  37. #{longitude},
  38. #{id},
  39. #{persId},
  40. #{orgId},
  41. #{groupId},
  42. #{persName},
  43. #{mobile},
  44. #{lon},
  45. #{lat}
  46. </sql>
  47. <!-- 使用like用法:columnName like concat('%',#columnName#,'%') -->
  48. <sql id="page_where">
  49. <trim prefix="where" prefixOverrides="and | or ">
  50. <if test="operateTime != null">and OPERATE_TIME = #{operateTime}</if>
  51. <if test="operateTimeFrom != null">and OPERATE_TIME &gt;= #{operateTimeFrom}</if>
  52. <if test="operateTimeTo != null">and OPERATE_TIME &lt;= #{operateTimeTo}</if>
  53. <if test="adCode != null and adCode != ''">and AD_CODE = #{adCode}</if>
  54. <if test="id != null and id != ''">and ID = #{id}</if>
  55. <if test="persId != null and persId != ''">and PERS_ID = #{persId}</if>
  56. <if test="orgId != null and orgId != ''">and ORG_ID = #{orgId}</if>
  57. <if test="groupId != null and groupId != ''">and GROUP_ID = #{groupId}</if>
  58. <if test="persName != null and persName != ''">and PERS_NAME = #{persName}</if>
  59. <if test="mobile != null and mobile != ''">and MOBILE = #{mobile}</if>
  60. <if test="lon != null and lon != ''">and LON = #{lon}</if>
  61. <if test="lat != null and lat != ''">and LAT = #{lat}</if>
  62. </trim>
  63. </sql>
  64. <select id="get" resultMap="persPositionResultMap" parameterType="String">
  65. select
  66. <include refid="table_columns"/>
  67. from pers_position where ID = #{id}
  68. </select>
  69. <select id="getPersPosition" resultMap="persPositionResultMap" parameterType="String">
  70. select
  71. LATITUDE,
  72. OPERATE_TIME,
  73. AD_CODE,
  74. LONGITUDE,
  75. PERS_ID,
  76. ORG_ID,
  77. GROUP_ID,
  78. PERS_NAME,
  79. MOBILE,
  80. LON,
  81. LAT
  82. from pers_position_latest t1
  83. where t1.PERS_ID = #{persId}
  84. </select>
  85. <select id="getBy" resultMap="persPositionResultMap">
  86. select
  87. <include refid="table_columns"/>
  88. from pers_position
  89. <include refid="page_where"/>
  90. </select>
  91. <select id="findAll" resultMap="persPositionResultMap">
  92. select
  93. <include refid="table_columns"/>
  94. from pers_position
  95. </select>
  96. <select id="findList" resultMap="persPositionResultMap">
  97. select
  98. LATITUDE,
  99. OPERATE_TIME,
  100. AD_CODE,
  101. LONGITUDE,
  102. PERS_ID,
  103. t2.ORG_ID,
  104. GROUP_ID,
  105. t2.PERS_NAME,
  106. MOBILE,
  107. LON,
  108. LAT,
  109. case when OPERATE_TIME >= #{operateTime} then '1'
  110. else '0' end as status
  111. from
  112. <if test="persId != null and persId != ''">
  113. bis_insp_all_rlation t
  114. left join bis_insp_all_rlation t1 on t1.id like concat(t.id,'%')
  115. left join pers_position_latest t2 on t2.pers_id = t1.persid
  116. where t.persid=#{persId} and t2.pers_id is not null
  117. </if>
  118. <if test="id != null and id != ''">
  119. bis_insp_all_rlation t1
  120. left join pers_position_latest t2 on t2.pers_id = t1.persid
  121. where
  122. <foreach item="item" index="index" collection="id.split(',')" open="(" separator="OR" close=")">
  123. t1.id LIKE concat(#{item}, '%')
  124. </foreach>
  125. and t2.pers_id is not null
  126. </if>
  127. <if test="orgId != null and orgId != ''">
  128. BIS_INSP_ALL_RLATION_PERS t1
  129. left join pers_position_latest t2 on t2.pers_id = t1.guid
  130. where t1.ORG_ID like concat(#{orgId},'%') and t2.pers_id is not null
  131. </if>
  132. <if test="(persId == null or persId == '') and (id == null or id == '') and (orgId == null or orgId == '')">
  133. pers_position_latest t2
  134. </if>
  135. <if test="adCode != null and adCode != ''">t2.ad_code like concat(#{adCode},'%')</if>
  136. </select>
  137. <select id="findListByPersId" resultMap="persPositionResultMap">
  138. select
  139. <include refid="table_columns"/>
  140. from pers_position
  141. <include refid="page_where"/>
  142. order by OPERATE_TIME
  143. </select>
  144. <select id="selectCountByClassfyId" resultType="int">
  145. select count(distinct t4.pers_id) from bis_insp_all t1
  146. LEFT JOIN BIS_INSP_ALL_RLATION t2 ON t2.id = t1.id
  147. left join BIS_INSP_ALL_RLATION_PERS t3 ON t3.guid = t2.persid
  148. left join pers_position_latest t4 on t4.pers_id = t3.guid
  149. where t4.pers_id is not null
  150. and t1.id like concat(#{id}, '%')
  151. and t4.OPERATE_TIME >= #{operateTime}
  152. </select>
  153. <select id="selectCountByOrgId" resultType="int">
  154. select count(distinct t2.pers_id) from BIS_INSP_ALL_RLATION_PERS t1
  155. left join pers_position_latest t2 on t2.pers_id = t1.guid
  156. where t2.pers_id is not null
  157. and t1.ORG_ID IN (${orgId})
  158. and t2.OPERATE_TIME >= #{operateTime}
  159. </select>
  160. <select id="selectCount" resultType="int">
  161. select count(ID) from pers_position
  162. <include refid="page_where"/>
  163. </select>
  164. <select id="selectOnlineCount" resultType="int">
  165. select count(0) from pers_position_latest
  166. where OPERATE_TIME >= #{operateTime}
  167. </select>
  168. <insert id="insert" parameterType="cn.com.goldenwater.dcproj.model.PersPosition">
  169. insert into pers_position(
  170. <include refid="table_columns"/>
  171. )
  172. values (
  173. <include refid="entity_properties"/>
  174. )
  175. </insert>
  176. <insert id="insertList" parameterType="cn.com.goldenwater.dcproj.model.PersPosition">
  177. insert all into pers_position(
  178. <include refid="table_columns"/>
  179. )
  180. select
  181. <foreach collection="list" item="item" index="index" separator="UNION select">
  182. #{item.latitude},#{item.operateTime}, #{item.adCode},#{item.longitude}, #{item.id},
  183. #{item.persId}, #{item.orgId}, #{item.groupId}, #{item.persName}, #{item.mobile},
  184. #{item.lon}, #{item.lat} from dual
  185. </foreach>
  186. </insert>
  187. <delete id="delete" parameterType="java.lang.String">
  188. delete from pers_position where ID = #{id}
  189. </delete>
  190. <delete id="deleteBy" parameterType="cn.com.goldenwater.dcproj.model.PersPosition">
  191. delete from pers_position
  192. <include refid="page_where"/>
  193. </delete>
  194. <update id="deleteInFlag" parameterType="java.lang.String">
  195. update pers_position set flag_valid = 0 where ID = #{id}
  196. </update>
  197. <update id="update" parameterType="cn.com.goldenwater.dcproj.model.PersPosition">
  198. update pers_position
  199. <trim prefix="set" suffixOverrides=",">
  200. <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
  201. <if test="id != null and id != ''">ID = #{id},</if>
  202. <if test="persId != null and persId != ''">PERS_ID = #{persId},</if>
  203. <if test="orgId != null and orgId != ''">ORG_ID = #{orgId},</if>
  204. <if test="groupId != null and groupId != ''">GROUP_ID = #{groupId},</if>
  205. <if test="persName != null and persName != ''">PERS_NAME = #{persName},</if>
  206. <if test="mobile != null and mobile != ''">MOBILE = #{mobile},</if>
  207. <if test="lon != null and lon != ''">LON = #{lon},</if>
  208. <if test="lat != null and lat != ''">LAT = #{lat},</if>
  209. </trim>
  210. <where>ID = #{id}</where>
  211. </update>
  212. <update id="updateBy" parameterType="cn.com.goldenwater.dcproj.model.PersPosition">
  213. update pers_position
  214. <trim prefix="set" suffixOverrides=",">
  215. <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
  216. <if test="id != null and id != ''">ID = #{id},</if>
  217. <if test="persId != null and persId != ''">PERS_ID = #{persId},</if>
  218. <if test="orgId != null and orgId != ''">ORG_ID = #{orgId},</if>
  219. <if test="groupId != null and groupId != ''">GROUP_ID = #{groupId},</if>
  220. <if test="persName != null and persName != ''">PERS_NAME = #{persName},</if>
  221. <if test="mobile != null and mobile != ''">MOBILE = #{mobile},</if>
  222. <if test="lon != null and lon != ''">LON = #{lon},</if>
  223. <if test="lat != null and lat != ''">LAT = #{lat},</if>
  224. </trim>
  225. <include refid="page_where"/>
  226. </update>
  227. <!-- 其他自定义SQL -->
  228. <!--根据人员id获取轨迹路线-->
  229. <select id="fingPositionByPersid" resultType="cn.com.goldenwater.dcproj.model.PersPosition">
  230. SELECT LATITUDE,
  231. to_char(OPERATE_TIME,'YYYY-MM-DD HH24:MI:SS') OPERATE_TIME,
  232. AD_CODE,
  233. LONGITUDE,
  234. ID,
  235. PERS_ID,
  236. ORG_ID,
  237. GROUP_ID,
  238. PERS_NAME,
  239. MOBILE,
  240. LON,
  241. LAT FROM pers_position WHERE PERS_ID = #{persid}
  242. <if test="sttm != null and sttm != ''">
  243. AND OPERATE_TIME BETWEEN to_date(#{sttm},'YYYY-MM-DD HH24:MI:SS') AND to_date(#{entm},'YYYY-MM-DD
  244. HH24:MI:SS')
  245. </if>
  246. order by operate_time
  247. </select>
  248. <select id="fingPositionByPersidSimple" resultType="cn.com.goldenwater.dcproj.dto.LonLat">
  249. SELECT
  250. LON,
  251. LAT FROM pers_position WHERE PERS_ID = #{persid}
  252. <if test="sttm != null and sttm != ''">
  253. AND OPERATE_TIME BETWEEN to_date(#{sttm},'YYYY-MM-DD HH24:MI:SS') AND to_date(#{entm},'YYYY-MM-DD
  254. HH24:MI:SS')
  255. </if>
  256. order by operate_time
  257. </select>
  258. <!--获取轨迹列表-->
  259. <select id="fingPositionList" parameterType="cn.com.goldenwater.dcproj.param.PersPositionBaseParam"
  260. resultType="cn.com.goldenwater.dcproj.model.PersPosition">
  261. SELECT LATITUDE,
  262. to_char(OPERATE_TIME,'YYYY-MM-DD HH24:MI:SS') OPERATE_TIME,
  263. AD_CODE,
  264. LONGITUDE,
  265. ID,
  266. PERS_ID,
  267. ORG_ID,
  268. GROUP_ID,
  269. PERS_NAME,
  270. MOBILE,
  271. LON,
  272. LAT FROM pers_position WHERE 1 = 1
  273. <if test="adCode != null and adCode != ''">and AD_CODE = #{adCode}</if>
  274. <if test="persId != null and persId != ''">and PERS_ID = #{persId}</if>
  275. <if test="orgId != null and orgId != ''">and ORG_ID = #{orgId}</if>
  276. <if test="groupId != null and groupId != ''">and GROUP_ID = #{groupId}</if>
  277. <if test="persName != null and persName != ''">and PERS_NAME = #{persName}</if>
  278. <if test="mobile != null and mobile != ''">and MOBILE = #{mobile}</if>
  279. <if test="sttm != null and sttm != '' and entm != null and entm != ''">
  280. and OPERATE_TIME BETWEEN to_date(#{sttm},'YYYY-MM-DD HH24:MI:SS') AND to_date(#{entm},'YYYY-MM-DD
  281. HH24:MI:SS')
  282. </if>
  283. </select>
  284. <select id="getOrgByPid" parameterType="String" resultType="cn.com.goldenwater.dcproj.model.BisInspOrg">
  285. SELECT * FROM BIS_INSP_ORG WHERE ORG_PID = #{orgPid}
  286. </select>
  287. <select id="countGroupOnline" parameterType="String" resultType="Integer">
  288. SELECT COUNT(*) FROM (
  289. SELECT DISTINCT rl.id FROM (
  290. SELECT DISTINCT USER_ID FROM
  291. BIS_INSP_LOG
  292. WHERE INTM &gt;= TO_DATE(#{sttm}, 'yyyy-mm-dd hh24:mi:ss')
  293. AND INTM &lt;= TO_DATE(#{entm}, 'yyyy-mm-dd hh24:mi:ss')
  294. <include refid="orgIdsql"/>
  295. GROUP BY USER_ID
  296. ) a LEFT JOIN BIS_INSP_ALL_RLATION rl
  297. ON a.USER_ID = rl.PERSID AND LENGTH(rl.id)=12
  298. LEFT JOIN BIS_INSP_ALL B ON RL.ID = B.ID
  299. WHERE B.STTM &lt;= TO_DATE(#{sttm}, 'yyyy-mm-dd hh24:mi:ss')
  300. AND B.ENTM &gt;= TO_DATE(#{entm}, 'yyyy-mm-dd hh24:mi:ss')
  301. GROUP BY rl.ID
  302. )
  303. </select>
  304. <sql id="orgIdsql">
  305. <choose>
  306. <when test="orgId !=null and orgId !=''">
  307. AND ORG_ID=#{orgId}
  308. </when>
  309. <otherwise>
  310. AND ORG_ID is null
  311. </otherwise>
  312. </choose>
  313. </sql>
  314. <select id="getAllPersId" resultType="String">
  315. SELECT DISTINCT PERS_ID FROM pers_position
  316. </select>
  317. <select id="getDateList" resultType="String">
  318. SELECT DISTINCT TO_CHAR(OPERATE_TIME,'YYYY-MM-DD') OP_TIME
  319. FROM pers_position WHERE PERS_ID=#{persId} ORDER BY OP_TIME
  320. </select>
  321. </mapper>