PersPositionDao.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 into pers_position (
  178. <include refid="table_columns"/>
  179. )
  180. <foreach item="item" index="index" collection="list" open="values " separator="," >
  181. (#{item.latitude},#{item.operateTime}, #{item.adCode},#{item.longitude}, #{item.id},
  182. #{item.persId}, #{item.orgId}, #{item.groupId}, #{item.persName}, #{item.mobile},
  183. #{item.lon}, #{item.lat} )
  184. </foreach>
  185. </insert>
  186. <delete id="delete" parameterType="java.lang.String">
  187. delete from pers_position where ID = #{id}
  188. </delete>
  189. <delete id="deleteBy" parameterType="cn.com.goldenwater.dcproj.model.PersPosition">
  190. delete from pers_position
  191. <include refid="page_where"/>
  192. </delete>
  193. <update id="deleteInFlag" parameterType="java.lang.String">
  194. update pers_position set flag_valid = 0 where ID = #{id}
  195. </update>
  196. <update id="update" parameterType="cn.com.goldenwater.dcproj.model.PersPosition">
  197. update pers_position
  198. <trim prefix="set" suffixOverrides=",">
  199. <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
  200. <if test="id != null and id != ''">ID = #{id},</if>
  201. <if test="persId != null and persId != ''">PERS_ID = #{persId},</if>
  202. <if test="orgId != null and orgId != ''">ORG_ID = #{orgId},</if>
  203. <if test="groupId != null and groupId != ''">GROUP_ID = #{groupId},</if>
  204. <if test="persName != null and persName != ''">PERS_NAME = #{persName},</if>
  205. <if test="mobile != null and mobile != ''">MOBILE = #{mobile},</if>
  206. <if test="lon != null and lon != ''">LON = #{lon},</if>
  207. <if test="lat != null and lat != ''">LAT = #{lat},</if>
  208. </trim>
  209. <where>ID = #{id}</where>
  210. </update>
  211. <update id="updateBy" parameterType="cn.com.goldenwater.dcproj.model.PersPosition">
  212. update pers_position
  213. <trim prefix="set" suffixOverrides=",">
  214. <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
  215. <if test="id != null and id != ''">ID = #{id},</if>
  216. <if test="persId != null and persId != ''">PERS_ID = #{persId},</if>
  217. <if test="orgId != null and orgId != ''">ORG_ID = #{orgId},</if>
  218. <if test="groupId != null and groupId != ''">GROUP_ID = #{groupId},</if>
  219. <if test="persName != null and persName != ''">PERS_NAME = #{persName},</if>
  220. <if test="mobile != null and mobile != ''">MOBILE = #{mobile},</if>
  221. <if test="lon != null and lon != ''">LON = #{lon},</if>
  222. <if test="lat != null and lat != ''">LAT = #{lat},</if>
  223. </trim>
  224. <include refid="page_where"/>
  225. </update>
  226. <!-- 其他自定义SQL -->
  227. <!--根据人员id获取轨迹路线-->
  228. <select id="fingPositionByPersid" resultType="cn.com.goldenwater.dcproj.model.PersPosition">
  229. SELECT LATITUDE,
  230. date_format(OPERATE_TIME,'%Y-%m-%d %H:%i:%S') OPERATE_TIME,
  231. AD_CODE,
  232. LONGITUDE,
  233. ID,
  234. PERS_ID,
  235. ORG_ID,
  236. GROUP_ID,
  237. PERS_NAME,
  238. MOBILE,
  239. LON,
  240. LAT FROM pers_position WHERE PERS_ID = #{persid}
  241. <if test="sttm != null and sttm != ''">
  242. AND OPERATE_TIME BETWEEN str_to_date(#{sttm},'%Y-%m-%d %H:%i:%S') AND str_to_date(#{entm},'%Y-%m-%d
  243. HH24:MI:SS')
  244. </if>
  245. order by operate_time
  246. </select>
  247. <select id="fingPositionByPersidSimple" resultType="cn.com.goldenwater.dcproj.dto.LonLat">
  248. SELECT
  249. LON,
  250. LAT FROM pers_position WHERE PERS_ID = #{persid}
  251. <if test="sttm != null and sttm != ''">
  252. AND OPERATE_TIME BETWEEN str_to_date(#{sttm},'%Y-%m-%d %H:%i:%S') AND str_to_date(#{entm},'%Y-%m-%d
  253. HH24:MI:SS')
  254. </if>
  255. order by operate_time
  256. </select>
  257. <!--获取轨迹列表-->
  258. <select id="fingPositionList" parameterType="cn.com.goldenwater.dcproj.param.PersPositionBaseParam"
  259. resultType="cn.com.goldenwater.dcproj.model.PersPosition">
  260. SELECT LATITUDE,
  261. date_format(OPERATE_TIME,'%Y-%m-%d %H:%i:%S') OPERATE_TIME,
  262. AD_CODE,
  263. LONGITUDE,
  264. ID,
  265. PERS_ID,
  266. ORG_ID,
  267. GROUP_ID,
  268. PERS_NAME,
  269. MOBILE,
  270. LON,
  271. LAT FROM pers_position WHERE 1 = 1
  272. <if test="adCode != null and adCode != ''">and AD_CODE = #{adCode}</if>
  273. <if test="persId != null and persId != ''">and PERS_ID = #{persId}</if>
  274. <if test="orgId != null and orgId != ''">and ORG_ID = #{orgId}</if>
  275. <if test="groupId != null and groupId != ''">and GROUP_ID = #{groupId}</if>
  276. <if test="persName != null and persName != ''">and PERS_NAME = #{persName}</if>
  277. <if test="mobile != null and mobile != ''">and MOBILE = #{mobile}</if>
  278. <if test="sttm != null and sttm != '' and entm != null and entm != ''">
  279. and OPERATE_TIME BETWEEN str_to_date(#{sttm},'%Y-%m-%d %H:%i:%S') AND str_to_date(#{entm},'%Y-%m-%d %H:%i:%S')
  280. </if>
  281. </select>
  282. <select id="getOrgByPid" parameterType="String" resultType="cn.com.goldenwater.dcproj.model.BisInspOrg">
  283. SELECT * FROM BIS_INSP_ORG WHERE ORG_PID = #{orgPid}
  284. </select>
  285. <select id="countGroupOnline" parameterType="String" resultType="Integer">
  286. SELECT COUNT(*) FROM (
  287. SELECT DISTINCT rl.id FROM (
  288. SELECT DISTINCT USER_ID FROM
  289. BIS_INSP_LOG
  290. WHERE INTM &gt;= str_to_date(#{sttm}, '%Y-%m-%d %H:%i:%S')
  291. AND INTM &lt;= str_to_date(#{entm}, '%Y-%m-%d %H:%i:%S')
  292. <include refid="orgIdsql"/>
  293. GROUP BY USER_ID
  294. ) a LEFT JOIN BIS_INSP_ALL_RLATION rl
  295. ON a.USER_ID = rl.PERSID AND LENGTH(rl.id)=12
  296. LEFT JOIN BIS_INSP_ALL B ON RL.ID = B.ID
  297. WHERE B.STTM &lt;= str_to_date(#{sttm}, '%Y-%m-%d %H:%i:%S')
  298. AND B.ENTM &gt;= str_to_date(#{entm}, '%Y-%m-%d %H:%i:%S')
  299. GROUP BY rl.ID
  300. ) ss
  301. </select>
  302. <sql id="orgIdsql">
  303. <choose>
  304. <when test="orgId !=null and orgId !=''">
  305. AND ORG_ID=#{orgId}
  306. </when>
  307. <otherwise>
  308. AND ORG_ID is null
  309. </otherwise>
  310. </choose>
  311. </sql>
  312. <select id="getAllPersId" resultType="String">
  313. SELECT DISTINCT PERS_ID FROM pers_position
  314. </select>
  315. <select id="getDateList" resultType="String">
  316. SELECT DISTINCT date_format(OPERATE_TIME,'%Y-%m-%d') OP_TIME
  317. FROM pers_position WHERE PERS_ID=#{persId} ORDER BY OP_TIME
  318. </select>
  319. </mapper>