KwsDeviceMapper.xml 15 KB

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