KwsDeviceMapper.xml 14 KB

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