Просмотр исходного кода

新增设备信息同步机制

liuyaowen 1 год назад
Родитель
Сommit
56ef781bc0

+ 10 - 16
src/main/java/com/yunfeiyun/agmp/iotm/device/controller/IotDeviceController.java

@@ -40,8 +40,7 @@ public class IotDeviceController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('iot:device:list')")
     @GetMapping("/list")
-    public TableDataInfo list(IotDevice iotDevice)
-    {
+    public TableDataInfo list(IotDevice iotDevice) {
         startPage();
         List<IotDevice> list = iotDeviceService.selectIotDeviceList(iotDevice);
         return getDataTable(list);
@@ -53,8 +52,7 @@ public class IotDeviceController extends BaseController
     @PreAuthorize("@ss.hasPermi('iot:device:export')")
     @Log(title = "设备基础", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, IotDevice iotDevice)
-    {
+    public void export(HttpServletResponse response, IotDevice iotDevice) {
         List<IotDevice> list = iotDeviceService.selectIotDeviceList(iotDevice);
         ExcelUtil<IotDevice> util = new ExcelUtil<IotDevice>(IotDevice.class);
         util.exportExcel(response, list, "设备基础数据");
@@ -64,10 +62,9 @@ public class IotDeviceController extends BaseController
      * 获取设备基础详细信息
      */
     @PreAuthorize("@ss.hasPermi('iot:device:query')")
-    @GetMapping(value = "/info/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Long id)
-    {
-        return success(iotDeviceService.selectIotDeviceById(id));
+    @GetMapping(value = "/info/{devBid}")
+    public AjaxResult getInfo(@PathVariable("devBid") String devBid) {
+        return success(iotDeviceService.selectIotDeviceByDevBid(devBid));
     }
 
     /**
@@ -76,8 +73,7 @@ public class IotDeviceController extends BaseController
     @PreAuthorize("@ss.hasPermi('iot:device:add')")
     @Log(title = "设备基础", businessType = BusinessType.INSERT)
     @PostMapping("/add")
-    public AjaxResult add(@RequestBody IotDevice iotDevice)
-    {
+    public AjaxResult add(@RequestBody IotDevice iotDevice) {
         return toAjax(iotDeviceService.insertIotDevice(iotDevice));
     }
 
@@ -87,8 +83,7 @@ public class IotDeviceController extends BaseController
     @PreAuthorize("@ss.hasPermi('iot:device:edit')")
     @Log(title = "设备基础", businessType = BusinessType.UPDATE)
     @PutMapping("/edit")
-    public AjaxResult edit(@RequestBody IotDevice iotDevice)
-    {
+    public AjaxResult edit(@RequestBody IotDevice iotDevice) {
         return toAjax(iotDeviceService.updateIotDevice(iotDevice));
     }
 
@@ -97,9 +92,8 @@ public class IotDeviceController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('iot:device:remove')")
     @Log(title = "设备基础", businessType = BusinessType.DELETE)
-	@DeleteMapping("/delete/{ids}")
-    public AjaxResult remove(@PathVariable Long[] ids)
-    {
-        return toAjax(iotDeviceService.deleteIotDeviceByIds(ids));
+	@DeleteMapping("/delete/{devBid}")
+    public AjaxResult remove(@PathVariable String devBid) {
+        return toAjax(iotDeviceService.deleteIotDeviceByDevBid(devBid));
     }
 }

+ 2 - 9
src/main/java/com/yunfeiyun/agmp/iotm/device/mapper/IotDeviceMapper.java

@@ -18,7 +18,7 @@ public interface IotDeviceMapper
      * @param id 设备基础主键
      * @return 设备基础
      */
-    public IotDevice selectIotDeviceById(Long id);
+    public IotDevice selectIotDeviceByDevBid(String devBid);
 
     /**
      * 查询设备基础列表
@@ -50,13 +50,6 @@ public interface IotDeviceMapper
      * @param id 设备基础主键
      * @return 结果
      */
-    public int deleteIotDeviceById(Long id);
+    public int deleteIotDeviceByDevBid(String devBid);
 
-    /**
-     * 批量删除设备基础
-     * 
-     * @param ids 需要删除的数据主键集合
-     * @return 结果
-     */
-    public int deleteIotDeviceByIds(Long[] ids);
 }

+ 5 - 11
src/main/java/com/yunfeiyun/agmp/iotm/device/service/IIotDeviceService.java

@@ -14,11 +14,11 @@ public interface IIotDeviceService
 {
     /**
      * 查询设备基础
-     * 
-     * @param id 设备基础主键
+     *
+     * @param devBid 设备基础主键
      * @return 设备基础
      */
-    public IotDevice selectIotDeviceById(Long id);
+    public IotDevice selectIotDeviceByDevBid(String devBid);
 
     /**
      * 查询设备基础列表
@@ -44,13 +44,7 @@ public interface IIotDeviceService
      */
     public int updateIotDevice(IotDevice iotDevice);
 
-    /**
-     * 批量删除设备基础
-     * 
-     * @param ids 需要删除的设备基础主键集合
-     * @return 结果
-     */
-    public int deleteIotDeviceByIds(Long[] ids);
+
 
     /**
      * 删除设备基础信息
@@ -58,5 +52,5 @@ public interface IIotDeviceService
      * @param id 设备基础主键
      * @return 结果
      */
-    public int deleteIotDeviceById(Long id);
+    public int deleteIotDeviceByDevBid(String devBid);
 }

+ 28 - 24
src/main/java/com/yunfeiyun/agmp/iotm/device/service/impl/IotDeviceServiceImpl.java

@@ -5,9 +5,12 @@ import java.util.List;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iotm.device.mapper.IotDeviceMapper;
 import com.yunfeiyun.agmp.iotm.device.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iotm.mq.service.AgmpTosMsgService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+
 /**
  * 设备基础Service业务层处理
  * 
@@ -19,17 +22,19 @@ public class IotDeviceServiceImpl implements IIotDeviceService
 {
     @Autowired
     private IotDeviceMapper iotDeviceMapper;
+    @Resource
+    private AgmpTosMsgService agmpTosMsgService;
 
     /**
      * 查询设备基础
-     * 
-     * @param id 设备基础主键
+     *
+     * @param devBid 设备基础主键
      * @return 设备基础
      */
     @Override
-    public IotDevice selectIotDeviceById(Long id)
+    public IotDevice selectIotDeviceByDevBid(String devBid)
     {
-        return iotDeviceMapper.selectIotDeviceById(id);
+        return iotDeviceMapper.selectIotDeviceByDevBid(devBid);
     }
 
     /**
@@ -51,9 +56,12 @@ public class IotDeviceServiceImpl implements IIotDeviceService
      * @return 结果
      */
     @Override
-    public int insertIotDevice(IotDevice iotDevice)
-    {
-        return iotDeviceMapper.insertIotDevice(iotDevice);
+    public int insertIotDevice(IotDevice iotDevice) {
+        iotDevice.setDevBid(iotDevice.getUUId());
+        iotDevice.setTid(iotDevice.getTid());
+        int result =  iotDeviceMapper.insertIotDevice(iotDevice);
+        agmpTosMsgService.sendIotDeviceInsertMsg(iotDevice);
+        return result;
     }
 
     /**
@@ -63,22 +71,13 @@ public class IotDeviceServiceImpl implements IIotDeviceService
      * @return 结果
      */
     @Override
-    public int updateIotDevice(IotDevice iotDevice)
-    {
-        return iotDeviceMapper.updateIotDevice(iotDevice);
+    public int updateIotDevice(IotDevice iotDevice) {
+        int result = iotDeviceMapper.updateIotDevice(iotDevice);
+        agmpTosMsgService.sendIotDeviceInsertMsg(iotDevice);
+        return result;
     }
 
-    /**
-     * 批量删除设备基础
-     * 
-     * @param ids 需要删除的设备基础主键
-     * @return 结果
-     */
-    @Override
-    public int deleteIotDeviceByIds(Long[] ids)
-    {
-        return iotDeviceMapper.deleteIotDeviceByIds(ids);
-    }
+
 
     /**
      * 删除设备基础信息
@@ -87,8 +86,13 @@ public class IotDeviceServiceImpl implements IIotDeviceService
      * @return 结果
      */
     @Override
-    public int deleteIotDeviceById(Long id)
-    {
-        return iotDeviceMapper.deleteIotDeviceById(id);
+    public int deleteIotDeviceByDevBid(String devBid) {
+        IotDevice iotDevice = iotDeviceMapper.selectIotDeviceByDevBid(devBid);
+        if(null == iotDevice){
+           return 0;
+        }
+        int result = iotDeviceMapper.deleteIotDeviceByDevBid(devBid);
+        agmpTosMsgService.sendIotDeviceDeleteMsg(iotDevice);
+        return result;
     }
 }

+ 39 - 0
src/main/java/com/yunfeiyun/agmp/iotm/mq/provider/TosMqProviderService.java

@@ -0,0 +1,39 @@
+package com.yunfeiyun.agmp.iotm.mq.provider;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.framework.mq.rabbitmq.consts.MqTosConsts;
+import com.yunfeiyun.agmp.common.framework.mq.rabbitmq.enums.TosActionEnums;
+import com.yunfeiyun.agmp.common.framework.mq.rabbitmq.model.SynGlobalTenantInfoDto;
+import com.yunfeiyun.agmp.common.utils.JSONUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+@ConditionalOnBean(name = "tosMqConfig")
+public class TosMqProviderService {
+
+    @Autowired
+    @Qualifier("tosRabbitTemplate")
+    private RabbitTemplate tosRabbitTemplate;
+
+
+    /**
+     * 往TOS发送
+     *
+     * @param message
+     */
+    public void sendToTos(TosActionEnums tosActionEnums,Object data,String desc) {
+        SynGlobalTenantInfoDto synGlobalTenantInfoDto = new SynGlobalTenantInfoDto();
+        synGlobalTenantInfoDto.setAction(tosActionEnums.getCode());
+        synGlobalTenantInfoDto.setDesc(desc);
+        synGlobalTenantInfoDto.setData(JSONObject.from(data));
+        tosRabbitTemplate.convertAndSend(MqTosConsts.ExchangeConsts.AGMP_TO_TOS_MSG_EXCHANGE, "", JSONUtils.toJSONString(synGlobalTenantInfoDto));
+    }
+
+
+}

+ 6 - 12
src/main/resources/mapper/IotDeviceMapper.xml

@@ -86,9 +86,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
     
-    <select id="selectIotDeviceById" parameterType="Long" resultMap="IotDeviceResult">
+    <select id="selectIotDeviceByDevBid" parameterType="String" resultMap="IotDeviceResult">
         <include refid="selectIotDeviceVo"/>
-        where id = #{id}
+        where devBid = #{devBid}
     </select>
         
     <insert id="insertIotDevice" parameterType="IotDevice" useGeneratedKeys="true" keyProperty="id">
@@ -170,7 +170,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <update id="updateIotDevice" parameterType="IotDevice">
         update IotDevice
         <trim prefix="SET" suffixOverrides=",">
-            <if test="devBid != null">devBid = #{devBid},</if>
             <if test="tid != null">tid = #{tid},</if>
             <if test="devtypeBid != null and devtypeBid != ''">devtypeBid = #{devtypeBid},</if>
             <if test="firmBid != null">firmBid = #{firmBid},</if>
@@ -205,17 +204,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="devCreateddate != null">devCreateddate = #{devCreateddate},</if>
             <if test="devDelstatus != null">devDelstatus = #{devDelstatus},</if>
         </trim>
-        where id = #{id}
+        where devBid = #{devBid}
     </update>
 
-    <delete id="deleteIotDeviceById" parameterType="Long">
-        delete from IotDevice where id = #{id}
+    <delete id="deleteIotDeviceByDevBid" parameterType="String">
+        delete from IotDevice where devBid = #{devBid}
     </delete>
 
-    <delete id="deleteIotDeviceByIds" parameterType="String">
-        delete from IotDevice where id in 
-        <foreach item="id" collection="array" open="(" separator="," close=")">
-            #{id}
-        </foreach>
-    </delete>
+
 </mapper>

+ 1 - 1
src/main/resources/mapper/TosDeviceclassMapper.xml

@@ -35,7 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
     
-    <select id="selectTosDeviceclassByDevclassBid" parameterType="Long" resultMap="TosDeviceclassResult">
+    <select id="selectTosDeviceclassByDevclassBid" parameterType="String" resultMap="TosDeviceclassResult">
         <include refid="selectTosDeviceclassVo"/>
         where String = #{devclassBid}
     </select>

+ 1 - 1
src/main/resources/mapper/TosFirmMapper.xml

@@ -98,7 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where firmBid = #{firmBid}
     </update>
 
-    <delete id="deleteTosFirmByFirmBid" parameterType="Long">
+    <delete id="deleteTosFirmByFirmBid" parameterType="String">
         delete from TosFirm where firmBid = #{firmBid}
     </delete>