Browse Source

update:添加sim字段,修改设备查询接口

zhouzeyu 1 year ago
parent
commit
90c0523e08

+ 21 - 7
src/main/java/com/tuoren/forward/controller/DeviceController.java

@@ -1,5 +1,6 @@
 package com.tuoren.forward.controller;
 
+import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -42,14 +43,15 @@ public class DeviceController {
 	DeviceService deviceService;
 	
 	@PostMapping("search")
-    @ResponseBody
-    @Operation(summary = "查询设备")
+	@ResponseBody
+	@Operation(summary = "查询设备")
 	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
-	public ResultPage<DeviceResp> search(@RequestBody DeviceSearchReq req){
-		log.info("search>>:{}",req);
-		return deviceService.search(req);
+	public ResultPage<Device> blurrySearch(@RequestBody DeviceSearchReq req){
+		log.info("blurrySearch>>:{}",req);
+		return deviceService.blurrySearch(req);
 	}
-	
+
+
 	@PostMapping("detail")
     @ResponseBody
     @Operation(summary = "设备详情")
@@ -84,7 +86,19 @@ public class DeviceController {
 		}
 		return deviceService.edit(req);
 	}
-	
+
+	@HandleLog
+	@PostMapping("editMac")
+	@ResponseBody
+	@Operation(summary = "根据Mac修改设备")
+//	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
+	public Result editMac(@RequestBody DeviceAddReq req){
+		log.info("edit>>:{}",req);
+
+		return deviceService.editMac(req);
+	}
+
+
 	@HandleLog
 	@PostMapping("delete")
     @ResponseBody

+ 3 - 0
src/main/java/com/tuoren/forward/entity/Device.java

@@ -22,6 +22,9 @@ public class Device {
     @Schema(description = "是否删除:, '0':未删除.’'1' 删除")
     private String isDelete;
 
+    @Schema(description = "SIM 卡号")
+    private String sim;
+
     @Schema(description = "产品ID")
     private String productId;
 

+ 18 - 15
src/main/java/com/tuoren/forward/entity/req/DeviceAddReq.java

@@ -6,19 +6,22 @@ import lombok.Data;
 @Data
 @Schema(description = "设备")
 public class DeviceAddReq {
-	
-		@Schema(description = "ID")
-	    private String id;
-	
-	 	@Schema(description = "MAC")
-	    private String mac;
-
-	    @Schema(description = "设备名称")
-	    private String name;
-
-	    @Schema(description = "产品ID")
-	    private String productId;
-	    
-	    @Schema(description = "描述")
-	    private String description;
+
+    @Schema(description = "ID")
+    private String id;
+
+    @Schema(description = "MAC")
+    private String mac;
+
+    @Schema(description = "设备名称")
+    private String name;
+
+    @Schema(description = "SIM 卡号")
+    private String sim;
+
+    @Schema(description = "产品ID")
+    private String productId;
+
+    @Schema(description = "描述")
+    private String description;
 }

+ 1 - 3
src/main/java/com/tuoren/forward/entity/req/DeviceSearchReq.java

@@ -13,7 +13,5 @@ public class DeviceSearchReq extends PageReq{
 	
 	@Schema(description = "搜索内容")
     private String keyWord;
-	
-	@Schema(description = "产品ID")
-    private String productId;
+
 }

+ 19 - 11
src/main/java/com/tuoren/forward/mapper/DeviceMapper.java

@@ -5,9 +5,11 @@ import java.util.List;
 import com.tuoren.forward.annotation.SqlLimit;
 import com.tuoren.forward.entity.Device;
 import com.tuoren.forward.entity.dto.DeviceDto;
+import com.tuoren.forward.entity.req.DeviceSearchReq;
 import com.tuoren.forward.entity.resp.CountCategoryResp;
 import com.tuoren.forward.entity.resp.CountResp;
 import com.tuoren.forward.entity.resp.DeviceResp;
+import org.apache.ibatis.annotations.Select;
 
 @SqlLimit
 public interface DeviceMapper {
@@ -17,31 +19,37 @@ public interface DeviceMapper {
 
     int insertSelective(Device row);
 
-    
+
     Device selectByPrimaryKey(String id);
-    
+
     @SqlLimit(isWork = false)
     Device selectByMac(String mac);
-    
+
     @SqlLimit(isWork = false)
-    Device selectByMacOwner(String mac,String owner);
-    
+    Device selectByMacOwner(String mac, String owner);
+
     @SqlLimit(isWork = false)
-    Integer existByMacOwner(String mac,String owner);
-    
+    Integer existByMacOwner(String mac, String owner);
+
     @SqlLimit(alis = "d")
-    List<DeviceResp> select(DeviceDto row);
+    List<Device> blurrySearch(DeviceDto dto);
 
     CountCategoryResp countProviceDevice();
-    
+
     CountResp countOnlineDevice();
-    
+
     int updateByPrimaryKeySelective(Device row);
-    
+
     @SqlLimit(isWork = false)
     int updateByPrimaryKeySelective2(Device row);
 
     int updateByPrimaryKeyWithBLOBs(Device row);
 
     int updateByPrimaryKey(Device row);
+
+
+    @SqlLimit(isWork = false)
+    int updateByMac(Device row);
+
+
 }

+ 24 - 5
src/main/java/com/tuoren/forward/service/DeviceService.java

@@ -4,6 +4,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import com.github.pagehelper.PageInfo;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -62,17 +63,17 @@ public class DeviceService {
 	 * @param req
 	 * @return ResultPage<Device>
 	 */
-	public ResultPage<DeviceResp> search(DeviceSearchReq req){
+	public ResultPage<Device> blurrySearch(DeviceSearchReq req) {
 		Page<Object> page = PageHelper.startPage(req.getPage(), req.getSize());
 		DeviceDto dto = new DeviceDto();
 		BeanUtils.copyProperties(req, dto);
-		List<DeviceResp> devices = deviceMapper.select(dto);
+		List<Device> devices = deviceMapper.blurrySearch(dto);
 		return ResultPage.success(devices,page.getTotal());
 	}
 	
 	/**
 	 * @title 设备详情
-	 * @param req
+	 * @param
 	 * @return ResultData<Device>
 	 */
 	public ResultData<Device> detail(String mac){
@@ -115,12 +116,27 @@ public class DeviceService {
 		deviceMapper.updateByPrimaryKeySelective(device);
 		return Result.success();
 	}
-	
+
 	/**
-	 * @title 删除设备
+	 * @title 修改设备
 	 * @param req
 	 * @return Result
 	 */
+
+	public Result editMac(DeviceAddReq req) {
+		Date date = new Date();
+		Device device = new Device();
+		BeanUtils.copyProperties(req, device);
+		device.setModifytime(date);
+		deviceMapper.updateByMac(device);
+		return Result.success();
+	}
+
+	/**
+	 * @title 删除设备
+	 * @param
+	 * @return Result
+	 */
 	public Result delete(String id) {
 		deviceMapper.deleteByPrimaryKey(id);
 		return Result.success();
@@ -227,4 +243,7 @@ public class DeviceService {
 		}
 		return Result.success();
 	}
+
+
+
 }

+ 5 - 1
src/main/resources/db/migration/V1.0.2__dev_config.sql

@@ -25,7 +25,11 @@ CREATE TABLE `forward`.`regist_log`
 
 ALTER TABLE `forward`.`dev_config`
     ADD COLUMN `local_address` VARCHAR(45) NULL COMMENT '医院数据对接服务地址' AFTER `mqtt_topic`,
-ADD COLUMN `local_port` INT NULL COMMENT '医院数据对接服务端口' AFTER `local_address`;
+    ADD COLUMN `local_port` INT NULL COMMENT '医院数据对接服务端口' AFTER `local_address`;
+
+
+ALTER TABLE `device`
+    ADD COLUMN `sim` VARCHAR(45) NULL COMMENT 'SIM 卡号' AFTER `sim`;
 
 
 

+ 401 - 336
src/main/resources/mapper/DeviceMapper.xml

@@ -1,342 +1,407 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.tuoren.forward.mapper.DeviceMapper">
-  <resultMap id="BaseResultMap" type="com.tuoren.forward.entity.Device">
-    <id column="id" jdbcType="VARCHAR" property="id" />
-    <result column="mac" jdbcType="VARCHAR" property="mac" />
-    <result column="name" jdbcType="VARCHAR" property="name" />
-    <result column="alias" jdbcType="VARCHAR" property="alias" />
-    <result column="is_delete" jdbcType="CHAR" property="isDelete" />
-    <result column="product_id" jdbcType="VARCHAR" property="productId" />
-    <result column="description" jdbcType="VARCHAR" property="description" />
-    <result column="createtime" jdbcType="TIMESTAMP" property="createtime" />
-    <result column="modifytime" jdbcType="TIMESTAMP" property="modifytime" />
-    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
-    <result column="lat" jdbcType="VARCHAR" property="lat" />
-    <result column="lng" jdbcType="VARCHAR" property="lng" />
-    <result column="address" jdbcType="VARCHAR" property="address" />
-    <result column="radius" jdbcType="VARCHAR" property="radius" />
-  </resultMap>
-  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tuoren.forward.entity.Device">
-    <result column="data" jdbcType="LONGVARCHAR" property="data" />
-  </resultMap>
+    <resultMap id="BaseResultMap" type="com.tuoren.forward.entity.Device">
+        <id column="id" jdbcType="VARCHAR" property="id"/>
+        <result column="mac" jdbcType="VARCHAR" property="mac"/>
+        <result column="name" jdbcType="VARCHAR" property="name"/>
+        <result column="alias" jdbcType="VARCHAR" property="alias"/>
+        <result column="is_delete" jdbcType="CHAR" property="isDelete"/>
+        <result column="sim" jdbcType="VARCHAR" property="sim"/>
+        <result column="product_id" jdbcType="VARCHAR" property="productId"/>
+        <result column="description" jdbcType="VARCHAR" property="description"/>
+        <result column="createtime" jdbcType="TIMESTAMP" property="createtime"/>
+        <result column="modifytime" jdbcType="TIMESTAMP" property="modifytime"/>
+        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
+        <result column="lat" jdbcType="VARCHAR" property="lat"/>
+        <result column="lng" jdbcType="VARCHAR" property="lng"/>
+        <result column="address" jdbcType="VARCHAR" property="address"/>
+        <result column="radius" jdbcType="VARCHAR" property="radius"/>
+    </resultMap>
+    <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tuoren.forward.entity.Device">
+        <result column="data" jdbcType="LONGVARCHAR" property="data"/>
+    </resultMap>
 
-  <sql id="Base_Column_List">
-    id, mac, name, is_delete, product_id, description, createtime, modifytime, tenant_id
-  </sql>
-  <sql id="Blob_Column_List">
-    data
-  </sql>
-  <sql id="Base_Column_Relation">
-    d.id, d.mac, d.name, d.alias,d.is_delete isDelete, d.product_id productId, d.description, d.createtime, d.modifytime, 
+    <sql id="Base_Column_List">
+        id, mac, name, is_delete, sim, product_id, description, createtime, modifytime, tenant_id
+    </sql>
+    <sql id="Blob_Column_List">
+        data
+    </sql>
+    <sql id="Base_Column_Relation">
+        d
+        .
+        id
+        , d.mac, d.name, d.alias,d.is_delete isDelete,d.sim sim,d.product_id productId, d.description, d.createtime, d.modifytime,
     d.tenant_id tenantId, d.data
-  </sql>
-  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
-    select 
-    <include refid="Base_Column_List" />
-    ,
-    <include refid="Blob_Column_List" />
-    from device
-    where id = #{id,jdbcType=VARCHAR}
-  </select>
-  <select id="selectByMac" parameterType="java.lang.String"  resultMap="BaseResultMap">
-  	select <include refid="Base_Column_List" />
-  	from device
-  	where mac = #{mac,jdbcType=VARCHAR}
-  	limit 1
-  </select>
-  <select id="selectByMacOwner" parameterType="java.lang.String"  resultMap="BaseResultMap">
-  	select <include refid="Base_Column_List" />
-  	from device
-  	where mac = #{mac,jdbcType=VARCHAR}
-  	and tenant_id = #{owner}
-  	limit 1
-  </select>
-  <select id="existByMacOwner" parameterType="java.lang.Integer"  resultType="java.lang.Integer" >
-  	select 1
-  	from device
-  	where mac = #{mac,jdbcType=VARCHAR}
-  	and tenant_id = #{owner}
-  	limit 1
-  </select>
-  <select id="select" parameterType="DeviceDto" resultType="DeviceResp">
-    select 
-    <include refid="Base_Column_Relation" />,
-    p.name productName,u.username
-    from device d
-    left join product p on d.product_id = p.id
-    left join user u on d.tenant_id = u.id
-    <where>
-    	<if test="keyWord != null and keyWord != ''">
-    		(
-	    		d.name like CONCAT('%',#{keyWord,jdbcType=VARCHAR},'%')
-	    		or
-	    		d.mac like CONCAT('%',#{keyWord,jdbcType=VARCHAR},'%')
-    		)
-    	</if>
-    	<if test="productId != null and productId != ''">
-    		and d.product_id = #{productId,jdbcType=VARCHAR}
-    	</if>
-    </where>
-    <if test="sort != null and sort != ''">
-			order by ${sort} 
-			<if test="order != null "> ${order}</if>
-	</if>
-  </select>
-  
-  <select id="countProviceDevice" resultType="com.tuoren.forward.entity.resp.CountCategoryResp">
-  	select pro title,count(1) num from 
-	(SELECT left(address,2) pro FROM forward.device where address is not null) pro_device
-	group by pro
-  </select>
-  
-  <select id="countOnlineDevice" resultType="com.tuoren.forward.entity.resp.CountResp">
-  	select  count(1) num
-  	from device where timestampdiff(MINUTE,modifytime,now()) &lt; 60
-  </select>
-  
-  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
-    delete from device
-    where id = #{id,jdbcType=VARCHAR}
-  </delete>
-  <insert id="insert" parameterType="com.tuoren.forward.entity.Device">
-    insert into device (id, mac, name, alias,
-      is_delete, product_id, description, 
-      createtime, modifytime, tenant_id, 
-      lat,lng,address,radius,
-      data)
-    values (#{id,jdbcType=VARCHAR}, #{mac,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR} ,
-      #{isDelete,jdbcType=CHAR}, #{productId,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, 
-      #{createtime,jdbcType=TIMESTAMP}, #{modifytime,jdbcType=TIMESTAMP}, #{tenantId,jdbcType=VARCHAR}, 
-      #{lat,jdbcType=VARCHAR},#{lng,jdbcType=VARCHAR},#{address,jdbcType=VARCHAR},
-      #{radius,jdbcType=VARCHAR},#{data,jdbcType=LONGVARCHAR})
-  </insert>
-  <insert id="insertSelective" parameterType="com.tuoren.forward.entity.Device">
-    insert into device
-    <trim prefix="(" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        id,
-      </if>
-      <if test="mac != null">
-        mac,
-      </if>
-      <if test="name != null">
-        name,
-      </if>
-      <if test="alias != null">
-        alias,
-      </if>
-      <if test="isDelete != null">
-        is_delete,
-      </if>
-      <if test="productId != null">
-        product_id,
-      </if>
-      <if test="description != null">
-        description,
-      </if>
-      <if test="createtime != null">
-        createtime,
-      </if>
-      <if test="modifytime != null">
-        modifytime,
-      </if>
-      <if test="tenantId != null">
-        tenant_id,
-      </if>
-      <if test="lat != null">
-        lat,
-      </if>
-      <if test="lng != null">
-        lng,
-      </if>
-      <if test="address != null">
-        address,
-      </if>
-      <if test="radius != null">
-        radius,
-      </if>
-      <if test="data != null">
-        data,
-      </if>
-    </trim>
-    <trim prefix="values (" suffix=")" suffixOverrides=",">
-      <if test="id != null">
-        #{id,jdbcType=VARCHAR},
-      </if>
-      <if test="mac != null">
-        #{mac,jdbcType=VARCHAR},
-      </if>
-      <if test="name != null">
-        #{name,jdbcType=VARCHAR},
-      </if>
-      <if test="alias != null">
-        #{alias,jdbcType=VARCHAR},
-      </if>
-      <if test="isDelete != null">
-        #{isDelete,jdbcType=CHAR},
-      </if>
-      <if test="productId != null">
-        #{productId,jdbcType=VARCHAR},
-      </if>
-      <if test="description != null">
-        #{description,jdbcType=VARCHAR},
-      </if>
-      <if test="createtime != null">
-        #{createtime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="modifytime != null">
-        #{modifytime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="tenantId != null">
-        #{tenantId,jdbcType=VARCHAR},
-      </if>
-      <if test="lat != null">
-        #{lat,jdbcType=VARCHAR},
-      </if>
-      <if test="lng != null">
-        #{lng,jdbcType=VARCHAR},
-      </if>
-      <if test="address != null">
-        #{address,jdbcType=VARCHAR},
-      </if>
-      <if test="radius != null">
-        #{radius,jdbcType=VARCHAR},
-      </if>
-      <if test="data != null">
-        #{data,jdbcType=LONGVARCHAR},
-      </if>
-    </trim>
-  </insert>
-  <update id="updateByPrimaryKeySelective" parameterType="com.tuoren.forward.entity.Device">
-    update device
-    <set>
-      <if test="mac != null">
-        mac = #{mac,jdbcType=VARCHAR},
-      </if>
-      <if test="name != null">
-        name = #{name,jdbcType=VARCHAR},
-      </if>
-      <if test="alias != null">
-        alias = #{alias,jdbcType=VARCHAR},
-      </if>
-      <if test="isDelete != null">
-        is_delete = #{isDelete,jdbcType=CHAR},
-      </if>
-      <if test="productId != null">
-        product_id = #{productId,jdbcType=VARCHAR},
-      </if>
-      <if test="description != null">
-        description = #{description,jdbcType=VARCHAR},
-      </if>
-      <if test="createtime != null">
-        createtime = #{createtime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="modifytime != null">
-        modifytime = #{modifytime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="tenantId != null">
-        tenant_id = #{tenantId,jdbcType=VARCHAR},
-      </if>
-      <if test="lat != null">
-        lat = #{lat,jdbcType=VARCHAR},
-      </if>
-      <if test="lng != null">
-        lng = #{lng,jdbcType=VARCHAR},
-      </if>
-      <if test="address != null">
-        address = #{address,jdbcType=VARCHAR},
-      </if>
-      <if test="radius != null">
-        radius = #{radius,jdbcType=VARCHAR},
-      </if>
-      <if test="data != null">
-        data = #{data,jdbcType=LONGVARCHAR},
-      </if>
-    </set>
-    where id = #{id,jdbcType=VARCHAR}
-  </update>
-  <update id="updateByPrimaryKeySelective2" parameterType="com.tuoren.forward.entity.Device">
-    update device
-    <set>
-      <if test="mac != null">
-        mac = #{mac,jdbcType=VARCHAR},
-      </if>
-      <if test="name != null">
-        name = #{name,jdbcType=VARCHAR},
-      </if>
-      <if test="alias != null">
-        alias = #{alias,jdbcType=VARCHAR},
-      </if>
-      <if test="isDelete != null">
-        is_delete = #{isDelete,jdbcType=CHAR},
-      </if>
-      <if test="productId != null">
-        product_id = #{productId,jdbcType=VARCHAR},
-      </if>
-      <if test="description != null">
-        description = #{description,jdbcType=VARCHAR},
-      </if>
-      <if test="createtime != null">
-        createtime = #{createtime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="modifytime != null">
-        modifytime = #{modifytime,jdbcType=TIMESTAMP},
-      </if>
-      <if test="tenantId != null">
-        tenant_id = #{tenantId,jdbcType=VARCHAR},
-      </if>
-      <if test="lat != null">
-        lat = #{lat,jdbcType=VARCHAR},
-      </if>
-      <if test="lng != null">
-        lng = #{lng,jdbcType=VARCHAR},
-      </if>
-      <if test="address != null">
-        address = #{address,jdbcType=VARCHAR},
-      </if>
-      <if test="radius != null">
-        radius = #{radius,jdbcType=VARCHAR},
-      </if>
-      <if test="data != null">
-        data = #{data,jdbcType=LONGVARCHAR},
-      </if>
-    </set>
-    where id = #{id,jdbcType=VARCHAR}
-  </update>
-  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tuoren.forward.entity.Device">
-    update device
-    set mac = #{mac,jdbcType=VARCHAR},
-      name = #{name,jdbcType=VARCHAR},
-      alias = #{alias,jdbcType=VARCHAR},
-      is_delete = #{isDelete,jdbcType=CHAR},
-      product_id = #{productId,jdbcType=VARCHAR},
-      description = #{description,jdbcType=VARCHAR},
-      createtime = #{createtime,jdbcType=TIMESTAMP},
-      modifytime = #{modifytime,jdbcType=TIMESTAMP},
-      tenant_id = #{tenantId,jdbcType=VARCHAR},
-      lat = #{lat,jdbcType=VARCHAR},
-      lng = #{lng,jdbcType=VARCHAR},
-      address = #{address,jdbcType=VARCHAR},
-      radius = #{radius,jdbcType=VARCHAR},
-      data = #{data,jdbcType=LONGVARCHAR}
-    where id = #{id,jdbcType=VARCHAR}
-  </update>
-  <update id="updateByPrimaryKey" parameterType="com.tuoren.forward.entity.Device">
-    update device
-    set mac = #{mac,jdbcType=VARCHAR},
-      name = #{name,jdbcType=VARCHAR},
-      alias = #{alias,jdbcType=VARCHAR},
-      is_delete = #{isDelete,jdbcType=CHAR},
-      product_id = #{productId,jdbcType=VARCHAR},
-      description = #{description,jdbcType=VARCHAR},
-      createtime = #{createtime,jdbcType=TIMESTAMP},
-      modifytime = #{modifytime,jdbcType=TIMESTAMP},
-      tenant_id = #{tenantId,jdbcType=VARCHAR},
-      lat = #{lat,jdbcType=VARCHAR},
-      lng = #{lng,jdbcType=VARCHAR},
-      address = #{address,jdbcType=VARCHAR},
-      radius = #{radius,jdbcType=VARCHAR}
-    where id = #{id,jdbcType=VARCHAR}
-  </update>
+    </sql>
+    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
+        select
+        <include refid="Base_Column_List"/>
+        ,
+        <include refid="Blob_Column_List"/>
+        from device
+        where id = #{id,jdbcType=VARCHAR}
+    </select>
+    <select id="selectByMac" parameterType="java.lang.String" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from device
+        where mac = #{mac,jdbcType=VARCHAR}
+        limit 1
+    </select>
+    <select id="selectByMacOwner" parameterType="java.lang.String" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from device
+        where mac = #{mac,jdbcType=VARCHAR}
+        and tenant_id = #{owner}
+        limit 1
+    </select>
+    <select id="existByMacOwner" parameterType="java.lang.Integer" resultType="java.lang.Integer">
+        select 1
+        from device
+        where mac = #{mac,jdbcType=VARCHAR}
+          and tenant_id = #{owner} limit 1
+    </select>
+
+
+    <select id="blurrySearch" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from device
+        <where>
+            <if test="keyWord != null and keyWord != ''">
+                (
+                sim like CONCAT('%',#{keyWord,jdbcType=VARCHAR},'%')
+                or
+                mac like CONCAT('%',#{keyWord,jdbcType=VARCHAR},'%')
+                )
+            </if>
+        </where>
+        <if test="sort != null and sort != ''">
+            order by ${sort}
+            <if test="order != null ">
+                ${order}
+            </if>
+        </if>
+    </select>
+
+    <select id="countProviceDevice" resultType="com.tuoren.forward.entity.resp.CountCategoryResp">
+        select pro title, count(1) num
+        from (SELECT left (address, 2) pro FROM forward.device where address is not null) pro_device
+        group by pro
+    </select>
+
+    <select id="countOnlineDevice" resultType="com.tuoren.forward.entity.resp.CountResp">
+        select count(1) num
+        from device
+        where timestampdiff(MINUTE,modifytime, now()) &lt; 60
+    </select>
+
+    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
+        delete
+        from device
+        where id = #{id,jdbcType=VARCHAR}
+    </delete>
+    <insert id="insert" parameterType="com.tuoren.forward.entity.Device">
+        insert into device (id, mac, name, alias,
+                            is_delete, sim, product_id, description,
+                            createtime, modifytime, tenant_id,
+                            lat, lng, address, radius,
+                            data)
+        values (#{id,jdbcType=VARCHAR}, #{mac,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR},
+                #{isDelete,jdbcType=CHAR}, #{sim,jdbcType=VARCHAR}, #{productId,jdbcType=VARCHAR},
+                #{description,jdbcType=VARCHAR},
+                #{createtime,jdbcType=TIMESTAMP}, #{modifytime,jdbcType=TIMESTAMP}, #{tenantId,jdbcType=VARCHAR},
+                #{lat,jdbcType=VARCHAR}, #{lng,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
+                #{radius,jdbcType=VARCHAR}, #{data,jdbcType=LONGVARCHAR})
+    </insert>
+    <insert id="insertSelective" parameterType="com.tuoren.forward.entity.Device">
+        insert into device
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">
+                id,
+            </if>
+            <if test="mac != null">
+                mac,
+            </if>
+            <if test="name != null">
+                name,
+            </if>
+            <if test="alias != null">
+                alias,
+            </if>
+            <if test="isDelete != null">
+                is_delete,
+            </if>
+            <if test="sim != null">
+                sim,
+            </if>
+            <if test="productId != null">
+                product_id,
+            </if>
+            <if test="description != null">
+                description,
+            </if>
+            <if test="createtime != null">
+                createtime,
+            </if>
+            <if test="modifytime != null">
+                modifytime,
+            </if>
+            <if test="tenantId != null">
+                tenant_id,
+            </if>
+            <if test="lat != null">
+                lat,
+            </if>
+            <if test="lng != null">
+                lng,
+            </if>
+            <if test="address != null">
+                address,
+            </if>
+            <if test="radius != null">
+                radius,
+            </if>
+            <if test="data != null">
+                data,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">
+                #{id,jdbcType=VARCHAR},
+            </if>
+            <if test="mac != null">
+                #{mac,jdbcType=VARCHAR},
+            </if>
+            <if test="name != null">
+                #{name,jdbcType=VARCHAR},
+            </if>
+            <if test="alias != null">
+                #{alias,jdbcType=VARCHAR},
+            </if>
+            <if test="isDelete != null">
+                #{isDelete,jdbcType=CHAR},
+            </if>
+            <if test="sim != null">
+                #{sim,jdbcType=VARCHAR},
+            </if>
+            <if test="productId != null">
+                #{productId,jdbcType=VARCHAR},
+            </if>
+            <if test="description != null">
+                #{description,jdbcType=VARCHAR},
+            </if>
+            <if test="createtime != null">
+                #{createtime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="modifytime != null">
+                #{modifytime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="tenantId != null">
+                #{tenantId,jdbcType=VARCHAR},
+            </if>
+            <if test="lat != null">
+                #{lat,jdbcType=VARCHAR},
+            </if>
+            <if test="lng != null">
+                #{lng,jdbcType=VARCHAR},
+            </if>
+            <if test="address != null">
+                #{address,jdbcType=VARCHAR},
+            </if>
+            <if test="radius != null">
+                #{radius,jdbcType=VARCHAR},
+            </if>
+            <if test="data != null">
+                #{data,jdbcType=LONGVARCHAR},
+            </if>
+        </trim>
+    </insert>
+    <update id="updateByPrimaryKeySelective" parameterType="com.tuoren.forward.entity.Device">
+        update device
+        <set>
+            <if test="mac != null">
+                mac = #{mac,jdbcType=VARCHAR},
+            </if>
+            <if test="name != null">
+                name = #{name,jdbcType=VARCHAR},
+            </if>
+            <if test="alias != null">
+                alias = #{alias,jdbcType=VARCHAR},
+            </if>
+            <if test="isDelete != null">
+                is_delete = #{isDelete,jdbcType=CHAR},
+            </if>
+            <if test="sim != null">
+                sim = #{sim,jdbcType=VARCHAR},
+            </if>
+            <if test="productId != null">
+                product_id = #{productId,jdbcType=VARCHAR},
+            </if>
+            <if test="description != null">
+                description = #{description,jdbcType=VARCHAR},
+            </if>
+            <if test="createtime != null">
+                createtime = #{createtime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="modifytime != null">
+                modifytime = #{modifytime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="tenantId != null">
+                tenant_id = #{tenantId,jdbcType=VARCHAR},
+            </if>
+            <if test="lat != null">
+                lat = #{lat,jdbcType=VARCHAR},
+            </if>
+            <if test="lng != null">
+                lng = #{lng,jdbcType=VARCHAR},
+            </if>
+            <if test="address != null">
+                address = #{address,jdbcType=VARCHAR},
+            </if>
+            <if test="radius != null">
+                radius = #{radius,jdbcType=VARCHAR},
+            </if>
+            <if test="data != null">
+                data = #{data,jdbcType=LONGVARCHAR},
+            </if>
+        </set>
+        where id = #{id,jdbcType=VARCHAR}
+    </update>
+    <update id="updateByMac" parameterType="com.tuoren.forward.entity.Device">
+        update device
+        <set>
+            <if test="name != null">
+                name = #{name,jdbcType=VARCHAR},
+            </if>
+            <if test="alias != null">
+                alias = #{alias,jdbcType=VARCHAR},
+            </if>
+            <if test="isDelete != null">
+                is_delete = #{isDelete,jdbcType=CHAR},
+            </if>
+            <if test="sim != null">
+                sim = #{sim,jdbcType=VARCHAR},
+            </if>
+            <if test="productId != null">
+                product_id = #{productId,jdbcType=VARCHAR},
+            </if>
+            <if test="description != null">
+                description = #{description,jdbcType=VARCHAR},
+            </if>
+            <if test="createtime != null">
+                createtime = #{createtime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="modifytime != null">
+                modifytime = #{modifytime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="tenantId != null">
+                tenant_id = #{tenantId,jdbcType=VARCHAR},
+            </if>
+            <if test="lat != null">
+                lat = #{lat,jdbcType=VARCHAR},
+            </if>
+            <if test="lng != null">
+                lng = #{lng,jdbcType=VARCHAR},
+            </if>
+            <if test="address != null">
+                address = #{address,jdbcType=VARCHAR},
+            </if>
+            <if test="radius != null">
+                radius = #{radius,jdbcType=VARCHAR},
+            </if>
+        </set>
+        where mac = #{mac,jdbcType=VARCHAR}
+    </update>
+    <update id="updateByPrimaryKeySelective2" parameterType="com.tuoren.forward.entity.Device">
+        update device
+        <set>
+            <if test="mac != null">
+                mac = #{mac,jdbcType=VARCHAR},
+            </if>
+            <if test="name != null">
+                name = #{name,jdbcType=VARCHAR},
+            </if>
+            <if test="alias != null">
+                alias = #{alias,jdbcType=VARCHAR},
+            </if>
+            <if test="isDelete != null">
+                is_delete = #{isDelete,jdbcType=CHAR},
+            </if>
+            <if test="sim != null">
+                sim = #{sim,jdbcType=VARCHAR},
+            </if>
+            <if test="productId != null">
+                product_id = #{productId,jdbcType=VARCHAR},
+            </if>
+            <if test="description != null">
+                description = #{description,jdbcType=VARCHAR},
+            </if>
+            <if test="createtime != null">
+                createtime = #{createtime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="modifytime != null">
+                modifytime = #{modifytime,jdbcType=TIMESTAMP},
+            </if>
+            <if test="tenantId != null">
+                tenant_id = #{tenantId,jdbcType=VARCHAR},
+            </if>
+            <if test="lat != null">
+                lat = #{lat,jdbcType=VARCHAR},
+            </if>
+            <if test="lng != null">
+                lng = #{lng,jdbcType=VARCHAR},
+            </if>
+            <if test="address != null">
+                address = #{address,jdbcType=VARCHAR},
+            </if>
+            <if test="radius != null">
+                radius = #{radius,jdbcType=VARCHAR},
+            </if>
+            <if test="data != null">
+                data = #{data,jdbcType=LONGVARCHAR},
+            </if>
+        </set>
+        where id = #{id,jdbcType=VARCHAR}
+    </update>
+    <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tuoren.forward.entity.Device">
+        update device
+        set mac         = #{mac,jdbcType=VARCHAR},
+            name        = #{name,jdbcType=VARCHAR},
+            alias       = #{alias,jdbcType=VARCHAR},
+            is_delete   = #{isDelete,jdbcType=CHAR},
+            sim         = #{sim,jdbcType=VARCHAR},
+            product_id  = #{productId,jdbcType=VARCHAR},
+            description = #{description,jdbcType=VARCHAR},
+            createtime  = #{createtime,jdbcType=TIMESTAMP},
+            modifytime  = #{modifytime,jdbcType=TIMESTAMP},
+            tenant_id   = #{tenantId,jdbcType=VARCHAR},
+            lat         = #{lat,jdbcType=VARCHAR},
+            lng         = #{lng,jdbcType=VARCHAR},
+            address     = #{address,jdbcType=VARCHAR},
+            radius      = #{radius,jdbcType=VARCHAR},
+            data        = #{data,jdbcType=LONGVARCHAR}
+        where id = #{id,jdbcType=VARCHAR}
+    </update>
+    <update id="updateByPrimaryKey" parameterType="com.tuoren.forward.entity.Device">
+        update device
+        set mac         = #{mac,jdbcType=VARCHAR},
+            name        = #{name,jdbcType=VARCHAR},
+            alias       = #{alias,jdbcType=VARCHAR},
+            is_delete   = #{isDelete,jdbcType=CHAR},
+            sim         = #{sim,jdbcType=VARCHAR},
+            product_id  = #{productId,jdbcType=VARCHAR},
+            description = #{description,jdbcType=VARCHAR},
+            createtime  = #{createtime,jdbcType=TIMESTAMP},
+            modifytime  = #{modifytime,jdbcType=TIMESTAMP},
+            tenant_id   = #{tenantId,jdbcType=VARCHAR},
+            lat         = #{lat,jdbcType=VARCHAR},
+            lng         = #{lng,jdbcType=VARCHAR},
+            address     = #{address,jdbcType=VARCHAR},
+            radius      = #{radius,jdbcType=VARCHAR}
+        where id = #{id,jdbcType=VARCHAR}
+    </update>
 </mapper>