KwsDeviceMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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.sckw.slope.detection.dao.mysql.KwsDeviceMapper">
  4. <resultMap id="BaseResultMap" type="com.sckw.slope.detection.model.dos.mysql.KwsDevice">
  5. <!--@mbg.generated-->
  6. <!--@Table kws_device-->
  7. <id column="id" jdbcType="BIGINT" property="id" />
  8. <result column="attribute" jdbcType="INTEGER" property="attribute" />
  9. <result column="name" jdbcType="VARCHAR" property="name" />
  10. <result column="alias" jdbcType="VARCHAR" property="alias" />
  11. <result column="sn_code" jdbcType="VARCHAR" property="snCode" />
  12. <result column="sn_code_full_name" jdbcType="VARCHAR" property="snCodeFullName" />
  13. <result column="model_id" jdbcType="BIGINT" property="modelId" />
  14. <result column="mountain_id" jdbcType="VARCHAR" property="mountainId" />
  15. <result column="valid_time" jdbcType="TIMESTAMP" property="validTime" />
  16. <result column="secret_key" jdbcType="VARCHAR" property="secretKey" />
  17. <result column="relevance_level" jdbcType="VARCHAR" property="relevanceLevel" />
  18. <result column="inter_face" jdbcType="VARCHAR" property="interFace" />
  19. <result column="related" jdbcType="VARCHAR" property="related" />
  20. <result column="remark" jdbcType="VARCHAR" property="remark" />
  21. <result column="status" jdbcType="TINYINT" property="status" />
  22. <result column="create_by" jdbcType="BIGINT" property="createBy" />
  23. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  24. <result column="update_by" jdbcType="BIGINT" property="updateBy" />
  25. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  26. <result column="del_flag" jdbcType="TINYINT" property="delFlag" />
  27. <result column="online" jdbcType="TINYINT" property="online" />
  28. </resultMap>
  29. <sql id="Base_Column_List">
  30. <!--@mbg.generated-->
  31. id, `attribute`, `name`, `alias`, sn_code, model_id, valid_time, secret_key, inter_face,relevance_level,sn_code_full_name,
  32. remark, `status`, create_by, create_time, update_by, update_time, del_flag,mountain_id,related,check_time,online
  33. </sql>
  34. <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
  35. <!--@mbg.generated-->
  36. select
  37. <include refid="Base_Column_List"/>
  38. from kws_device
  39. where del_flag = 0
  40. and id = #{id,jdbcType=BIGINT}
  41. </select>
  42. <select id="selectByDeviceParam" resultType="com.sckw.slope.detection.model.vo.DeviceVo">
  43. select DISTINCT d.id,
  44. d.name,
  45. manufacturer,
  46. m.name as m_name,
  47. m.device_type,
  48. d.remark,
  49. d.update_by,
  50. d.update_time,
  51. p.`name` as project_name,
  52. d.status,
  53. m.`name` as mName
  54. from kws_device as d
  55. inner join kws_device_model as m on d.model_id = m.id
  56. left join kws_project_device as pd on d.id = pd.device_id
  57. left join kws_project as p on pd.project_id = p.id
  58. WHERE d.del_flag = 0
  59. and m.del_flag = 0
  60. <if test="deviceQuery.mountainId != null and deviceQuery.mountainId != ''">
  61. and d.mountain_id = #{deviceQuery.mountainId,jdbcType=BIGINT}
  62. , '%')
  63. </if>
  64. <if test="deviceQuery.deviceName != null and deviceQuery.deviceName != ''">
  65. and d.name like concat('%', #{deviceQuery.deviceName}
  66. , '%')
  67. </if>
  68. <if test="deviceQuery.projectName != null and deviceQuery.projectName != ''">
  69. and p.name like concat('%', #{deviceQuery.projectName}
  70. , '%')
  71. </if>
  72. <if test="deviceQuery.id != null and deviceQuery.id != ''">
  73. and id = #{deviceQuery.id,jdbcType=BIGINT}
  74. </if>
  75. <if test="deviceQuery.deviceType != null and deviceQuery.deviceType != ''">
  76. and m.device_type = #{deviceQuery.deviceType,jdbcType=BIGINT}
  77. </if>
  78. <if test="deviceQuery.status != null and deviceQuery.status != ''">
  79. and d.status = #{deviceQuery.status,jdbcType=TINYINT}
  80. </if>
  81. <if test="deviceQuery.projectId != null and deviceQuery.projectId != ''">
  82. and p.id= #{deviceQuery.projectId,jdbcType=TINYINT}
  83. </if>
  84. <if test="deviceQuery.attribute != null and deviceQuery.attribute != ''">
  85. and attribute = #{deviceQuery.attribute,jdbcType=TINYINT}
  86. </if>
  87. order by d.create_time desc
  88. </select>
  89. <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
  90. <!--@mbg.generated-->
  91. delete
  92. from kws_device
  93. where id = #{id,jdbcType=BIGINT}
  94. </delete>
  95. <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsDevice">
  96. <!--@mbg.generated-->
  97. insert into kws_device
  98. <trim prefix="(" suffix=")" suffixOverrides=",">
  99. <if test="id != null">
  100. id,
  101. </if>
  102. <if test="attribute != null">
  103. `attribute`,
  104. </if>
  105. <if test="name != null">
  106. `name`,
  107. </if>
  108. <if test="alias != null">
  109. `alias`,
  110. </if>
  111. <if test="snCode != null">
  112. sn_code,
  113. </if>
  114. <if test="modelId != null">
  115. model_id,
  116. </if>
  117. <if test="validTime != null">
  118. valid_time,
  119. </if>
  120. <if test="secretKey != null">
  121. secret_key,
  122. </if>
  123. <if test="interFace != null">
  124. interface,
  125. </if>
  126. <if test="remark != null">
  127. remark,
  128. </if>
  129. <if test="status != null">
  130. `status`,
  131. </if>
  132. <if test="createBy != null">
  133. create_by,
  134. </if>
  135. <if test="createTime != null">
  136. create_time,
  137. </if>
  138. <if test="updateBy != null">
  139. update_by,
  140. </if>
  141. <if test="updateTime != null">
  142. update_time,
  143. </if>
  144. <if test="delFlag != null">
  145. del_flag,
  146. </if>
  147. </trim>
  148. <trim prefix="values (" suffix=")" suffixOverrides=",">
  149. <if test="id != null">
  150. #{id,jdbcType=BIGINT},
  151. </if>
  152. <if test="attribute != null">
  153. #{attribute,jdbcType=INTEGER},
  154. </if>
  155. <if test="name != null">
  156. #{name,jdbcType=VARCHAR},
  157. </if>
  158. <if test="alias != null">
  159. #{alias,jdbcType=VARCHAR},
  160. </if>
  161. <if test="snCode != null">
  162. #{snCode,jdbcType=VARCHAR},
  163. </if>
  164. <if test="modelId != null">
  165. #{modelId,jdbcType=BIGINT},
  166. </if>
  167. <if test="validTime != null">
  168. #{validTime,jdbcType=TIMESTAMP},
  169. </if>
  170. <if test="secretKey != null">
  171. #{secretKey,jdbcType=VARCHAR},
  172. </if>
  173. <if test="interFace != null">
  174. #{interFace,jdbcType=VARCHAR},
  175. </if>
  176. <if test="remark != null">
  177. #{remark,jdbcType=VARCHAR},
  178. </if>
  179. <if test="status != null">
  180. #{status,jdbcType=TINYINT},
  181. </if>
  182. <if test="createBy != null">
  183. #{createBy,jdbcType=BIGINT},
  184. </if>
  185. <if test="createTime != null">
  186. #{createTime,jdbcType=TIMESTAMP},
  187. </if>
  188. <if test="updateBy != null">
  189. #{updateBy,jdbcType=BIGINT},
  190. </if>
  191. <if test="updateTime != null">
  192. #{updateTime,jdbcType=TIMESTAMP},
  193. </if>
  194. <if test="delFlag != null">
  195. #{delFlag,jdbcType=TINYINT},
  196. </if>
  197. </trim>
  198. </insert>
  199. <update id="updateByPrimaryKeySelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsDevice">
  200. <!--@mbg.generated-->
  201. update kws_device
  202. <set>
  203. <if test="attribute != null">
  204. `attribute` = #{attribute,jdbcType=INTEGER},
  205. </if>
  206. <if test="name != null">
  207. `name` = #{name,jdbcType=VARCHAR},
  208. </if>
  209. <if test="alias != null">
  210. `alias` = #{alias,jdbcType=VARCHAR},
  211. </if>
  212. <if test="snCode != null">
  213. sn_code = #{snCode,jdbcType=VARCHAR},
  214. </if>
  215. <if test="modelId != null">
  216. model_id = #{modelId,jdbcType=BIGINT},
  217. </if>
  218. <if test="validTime != null">
  219. valid_time = #{validTime,jdbcType=TIMESTAMP},
  220. </if>
  221. <if test="secretKey != null">
  222. secret_key = #{secretKey,jdbcType=VARCHAR},
  223. </if>
  224. <if test="interFace != null">
  225. inter_face = #{interFace,jdbcType=VARCHAR},
  226. </if>
  227. <if test="remark != null">
  228. remark = #{remark,jdbcType=VARCHAR},
  229. </if>
  230. <if test="status != null">
  231. `status` = #{status,jdbcType=TINYINT},
  232. </if>
  233. <if test="createBy != null">
  234. create_by = #{createBy,jdbcType=BIGINT},
  235. </if>
  236. <if test="createTime != null">
  237. create_time = #{createTime,jdbcType=TIMESTAMP},
  238. </if>
  239. <if test="updateBy != null">
  240. update_by = #{updateBy,jdbcType=BIGINT},
  241. </if>
  242. <if test="updateTime != null">
  243. update_time = #{updateTime,jdbcType=TIMESTAMP},
  244. </if>
  245. <if test="delFlag != null">
  246. del_flag = #{delFlag,jdbcType=TINYINT},
  247. </if>
  248. </set>
  249. where id = #{id,jdbcType=BIGINT}
  250. </update>
  251. <update id="updateByPrimaryKey" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsDevice">
  252. <!--@mbg.generated-->
  253. update kws_device
  254. set `attribute` = #{attribute,jdbcType=INTEGER},
  255. `name` = #{name,jdbcType=VARCHAR},
  256. `alias` = #{alias,jdbcType=VARCHAR},
  257. sn_code = #{snCode,jdbcType=VARCHAR},
  258. model_id = #{modelId,jdbcType=BIGINT},
  259. valid_time = #{validTime,jdbcType=TIMESTAMP},
  260. secret_key = #{secretKey,jdbcType=VARCHAR},
  261. inter_face = #{interFace,jdbcType=VARCHAR},
  262. remark = #{remark,jdbcType=VARCHAR},
  263. `status` = #{status,jdbcType=TINYINT},
  264. create_by = #{createBy,jdbcType=BIGINT},
  265. create_time = #{createTime,jdbcType=TIMESTAMP},
  266. update_by = #{updateBy,jdbcType=BIGINT},
  267. update_time = #{updateTime,jdbcType=TIMESTAMP},
  268. del_flag = #{delFlag,jdbcType=TINYINT}
  269. where id = #{id,jdbcType=BIGINT}
  270. </update>
  271. <select id="selectDeviceAllNotDeviceRelation" resultType="com.sckw.slope.detection.model.dto.DeviceDataDTO">
  272. SELECT c.id AS deviceId,
  273. c.alias as deviceAlias,
  274. c.`name` AS deviceName
  275. FROM kws_project a
  276. LEFT JOIN kws_device c ON a.mountain_id = c.mountain_id
  277. LEFT JOIN kws_device_model d ON c.model_id = d.id
  278. WHERE a.del_flag = 0
  279. AND c.del_flag = 0
  280. AND d.del_flag = 0
  281. AND c.id NOT in (SELECT DISTINCT a.relate_device_id
  282. FROM kws_device_relation a
  283. LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id where a.del_flag = 0)
  284. AND c.id NOT in (SELECT DISTINCT a.device_id
  285. FROM kws_device_relation a
  286. LEFT JOIN kws_project b ON a.mountain_id = b.mountain_id where a.del_flag = 0)
  287. <if test="projectId != null and projectId != ''">
  288. AND a.id = #{projectId}
  289. </if>
  290. </select>
  291. <select id="selectDeviceAllAndProjectData"
  292. resultType="com.sckw.slope.detection.model.vo.AffiliationDeviceVO">
  293. SELECT a.id as deviceId,
  294. a.`name` as name,
  295. a.attribute as attribute,
  296. a.alias as alias,
  297. a.logic_alt as logicAlt,
  298. a.logic_lat as logicLat,
  299. a.logic_lng as logicLng
  300. FROM kws_device a
  301. LEFT JOIN kws_project_device b ON a.id = b.device_id
  302. LEFT JOIN kws_project c ON b.project_id = c.id
  303. WHERE
  304. a.del_flag=0
  305. and b.del_flag=0
  306. and c.del_flag=0
  307. and c.id = #{projectId}
  308. </select>
  309. <select id="selectDeviceAllByProjectAndMountainId" resultType="com.sckw.slope.detection.model.dto.ThresholdSelectDTO">
  310. SELECT b.id AS deviceId,
  311. b.alias AS deviceAlias,
  312. b.`name` AS deviceName
  313. FROM kws_project_device a
  314. LEFT JOIN kws_device b ON a.device_id = b.id
  315. WHERE a.del_flag = 0
  316. AND b.del_flag = 0
  317. AND a.mountain_id = b.mountain_id
  318. <if test="projectId != null and projectId != ''">
  319. and a.project_id = #{projectId}
  320. </if>
  321. <if test="mountainId != null and mountainId != ''">
  322. and a.mountain_id = #{mountainId}
  323. </if>
  324. <if test="status != null and status.size() > 0">
  325. and b.status in
  326. <foreach collection="status" separator="," open="(" close=")" item="status">
  327. #{status}
  328. </foreach>
  329. </if>
  330. </select>
  331. <select id="selectCountByProject" resultType="int">
  332. SELECT count(distinct c.id)
  333. FROM kws_project a
  334. LEFT JOIN kws_project_device b
  335. ON a.id = b.project_id
  336. LEFT JOIN kws_device c ON b.device_id = c.id
  337. WHERE a.del_flag = 0
  338. AND b.del_flag = 0
  339. AND c.del_flag = 0
  340. and a.mountain_id = b.mountain_id
  341. and b.mountain_id = c.mountain_id
  342. <if test="projectId != null and projectId != ''">
  343. and a.id=#{projectId}
  344. </if>
  345. </select>
  346. <select id="selectDeviceOnlineRateCountByProject" resultType="int">
  347. SELECT count(distinct c.id)
  348. FROM kws_project a
  349. LEFT JOIN kws_project_device b
  350. ON a.id = b.project_id
  351. LEFT JOIN kws_device c ON b.device_id = c.id
  352. WHERE a.del_flag = 0
  353. AND b.del_flag = 0
  354. AND c.del_flag = 0
  355. and a.mountain_id = b.mountain_id
  356. and b.mountain_id = c.mountain_id
  357. and c.online = 1
  358. <if test="projectId != null and projectId != ''">
  359. and a.id=#{projectId}
  360. </if>
  361. </select>
  362. <select id="selectListByModelType" resultType="java.util.Map">
  363. SELECT b.id as deviceId,
  364. b.name as deviceName,
  365. c.id as deviceModelId,
  366. c.`name` as deviceModelName,
  367. c.device_type as deviceType
  368. FROM kws_device b
  369. LEFT JOIN kws_device_model c ON b.model_id = c.id
  370. WHERE b.del_flag = 0
  371. and c.del_flag = 0
  372. <if test="modelType != null and modelType != ''">
  373. and c.device_type = #{modelType}
  374. </if>
  375. </select>
  376. </mapper>