ソースを参照

维护产品下的设备数量

xucaiqin 2 年 前
コミット
7c12a918b2

+ 2 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/mapper/IotProductMapper.java

@@ -47,4 +47,6 @@ public interface IotProductMapper extends BaseMapper<IotProduct> {
      * @return
      */
     List<TopicVo> queryProductTopic(@Param("type") Integer type);
+
+    void updateSize(@Param("productId") Long productId,@Param("size") Integer size);
 }

+ 8 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/java/com/middle/platform/manage/biz/service/IotDeviceService.java

@@ -87,6 +87,7 @@ public class IotDeviceService {
         iotDevice.setEnableFlag(1);
         iotDevice.setRemark(iotDevicePara.getRemark());
         iotDeviceMapper.insert(iotDevice);
+        iotProductMapper.updateSize(iotDevicePara.getProductId(), 1);
         return true;
     }
 
@@ -96,11 +97,17 @@ public class IotDeviceService {
      * @param id
      * @return
      */
+    @Transactional(rollbackFor = Exception.class)
     public Object remove(Long id) {
+        IotDevice iotDevice1 = iotDeviceMapper.selectById(id);
+        if (Objects.isNull(iotDevice1)) {
+            throw new BusinessException("设备不存在");
+        }
         IotDevice iotDevice = new IotDevice();
         iotDevice.setDeleteTime(LocalDateTime.now());
         iotDevice.setDelFlag(Global.DEL);
         iotDeviceMapper.update(iotDevice, new LambdaQueryWrapper<IotDevice>().eq(IotDevice::getId, id).eq(IotDevice::getDelFlag, Global.UN_DEL));
+        iotProductMapper.updateSize(iotDevice1.getProductId(), -1);
         return true;
     }
 
@@ -207,6 +214,7 @@ public class IotDeviceService {
 
     /**
      * 查询设备信息
+     *
      * @param guid
      * @return
      */

+ 7 - 0
iot-module/iot-module-manage/iot-module-manage-biz/src/main/resources/mapper/IotProductMapper.xml

@@ -105,4 +105,11 @@
             and ip.del_flag = 0
         </where>
     </select>
+
+    <update id="updateSize">
+        update iot_product ip
+        set ip.size = ip.size + (#{size,jdbcType=INTEGER})
+        where ip.id = #{productId,jdbcType=BIGINT}
+          and ip.del_flag = 0
+    </update>
 </mapper>