Browse Source

Merge branch '84-wb' into '84-integrate'

feat:设备定时重启配置



See merge request !32

wangbo 2 năm trước cách đây
mục cha
commit
64c17643df

+ 50 - 0
smsb-customer-manager-adapter/src/main/java/com/inspur/customer/web/controller/tenant/TenantCommonAttributeController.java

@@ -0,0 +1,50 @@
+package com.inspur.customer.web.controller.tenant;
+
+import com.alibaba.cola.dto.Response;
+import com.alibaba.cola.dto.SingleResponse;
+import com.inspur.customer.client.tenant.TenantCommonAttributeService;
+import com.inspur.customer.object.tenant.TenantAttributeCO;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Objects;
+
+/**
+ * @Author wangbo13
+ * @Date 2023/2/14 11:18
+ * @Version 1.0
+ */
+@RestController
+public class TenantCommonAttributeController {
+
+    @DubboReference
+    private TenantCommonAttributeService commonAttributeService;
+
+    @PostMapping("/tenant/attribute/save")
+    public Response saveOrUpdateAttribute(@Validated @RequestBody TenantAttributeCO attribute){
+        Response checkResponse = checkParameters(attribute);
+        if(!checkResponse.isSuccess()){
+            return checkResponse;
+        }
+        return commonAttributeService.saveOrUpdate(attribute);
+    }
+
+    @GetMapping("/tenant/attribute/query")
+    public Response queryTenantAttribute(TenantAttributeCO attribute){
+        Response checkResponse = checkParameters(attribute);
+        if(!checkResponse.isSuccess()){
+            return checkResponse;
+        }
+        return commonAttributeService.queryTenantAttribute(attribute);
+    }
+
+    private Response checkParameters(TenantAttributeCO attribute){
+        if(Objects.isNull(attribute.getTenant()) || attribute.getTenant().equals(""))
+            return Response.buildFailure("400","参数出错: tenant不能为空");
+        if(Objects.isNull(attribute.getAttributeKey()) || attribute.getAttributeKey().equals(""))
+            return Response.buildFailure("400","参数出错: attributeKey不能为空");
+        return Response.buildSuccess();
+    }
+
+}

+ 70 - 0
smsb-customer-manager-app/src/main/java/com/inspur/customer/service/tenant/TenantCommonAttributeServiceImpl.java

@@ -0,0 +1,70 @@
+package com.inspur.customer.service.tenant;
+
+import com.alibaba.cola.dto.Response;
+import com.alibaba.cola.dto.SingleResponse;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.inspur.customer.client.tenant.TenantCommonAttributeService;
+import com.inspur.customer.constant.Constant;
+import com.inspur.customer.infrastructure.mapper.tenant.TenantCommonAttributeMapper;
+import com.inspur.customer.infrastructure.object.tenant.TenantCommonAttributeDO;
+import com.inspur.customer.object.tenant.TenantAttributeCO;
+import com.inspur.device.client.core.manage.SmsbDeviceService;
+import com.inspur.device.object.core.manage.SmsbDeviceDto;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.config.annotation.DubboService;
+import org.springframework.beans.BeanUtils;
+
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Objects;
+
+/**
+ * @Author wangbo13
+ * @Date 2023/2/14 11:15
+ * @Version 1.0
+ */
+@Slf4j
+@DubboService(interfaceClass = TenantCommonAttributeService.class)
+public class TenantCommonAttributeServiceImpl extends ServiceImpl<TenantCommonAttributeMapper, TenantCommonAttributeDO> implements TenantCommonAttributeService {
+    @DubboReference
+    private SmsbDeviceService deviceService;
+    @DubboReference
+    private SmsbDeviceService smsbDeviceService;
+
+    @Override
+    public Response saveOrUpdate(TenantAttributeCO attributeCO) {
+        TenantCommonAttributeDO tenantAttribute = queryOne(attributeCO.getTenant() ,attributeCO.getAttributeKey());
+        if(Objects.nonNull(tenantAttribute)){
+            tenantAttribute.setAttributeValue(attributeCO.getAttributeValue());
+            super.updateById(tenantAttribute);
+        }else {
+            tenantAttribute = new TenantCommonAttributeDO();
+            BeanUtils.copyProperties(attributeCO ,tenantAttribute);
+            super.save(tenantAttribute);
+        }
+        // send massage
+        smsbDeviceService.publishDeviceAttribute(attributeCO.getTenant());
+        return Response.buildSuccess();
+    }
+
+    private TenantCommonAttributeDO queryOne(String tenant,String key){
+        return super.getOne(new LambdaQueryWrapper<>(TenantCommonAttributeDO.class)
+            .eq(TenantCommonAttributeDO::getTenant, tenant)
+            .eq(TenantCommonAttributeDO::getAttributeKey, key)
+            .last("limit 1"));
+    }
+
+    @Override
+    public Response queryTenantAttribute(TenantAttributeCO attributeCO) {
+        TenantCommonAttributeDO tenantAttribute = queryOne(attributeCO.getTenant() ,attributeCO.getAttributeKey());
+        return SingleResponse.of(tenantAttribute);
+    }
+
+    @Override
+    public String queryAutorestartValue(String tenant) {
+        TenantCommonAttributeDO tenantAttribute = queryOne(tenant ,Constant.TenantAttribute.DEVICE_RESTART.key());
+        return Objects.nonNull(tenantAttribute) ? tenantAttribute.getAttributeValue() : null;
+    }
+}

+ 38 - 0
smsb-customer-manager-client/src/main/java/com/inspur/customer/client/tenant/TenantCommonAttributeService.java

@@ -0,0 +1,38 @@
+package com.inspur.customer.client.tenant;
+
+import com.alibaba.cola.dto.Response;
+import com.inspur.customer.object.tenant.TenantAttributeCO;
+
+import java.time.LocalTime;
+
+/**
+ * @Author wangbo13
+ * @Date 2023/2/14 11:16
+ * @Version 1.0
+ */
+public interface TenantCommonAttributeService {
+
+    /**
+     * 存在相同key-更新,不存在则保存
+     *
+     * @param attributeCO
+     * @return Response
+     */
+    Response saveOrUpdate(TenantAttributeCO attributeCO);
+
+    /**
+     * 获取租户下某个属性值
+     *
+     * @param attributeCO
+     * @return 属性值
+     */
+    Response queryTenantAttribute(TenantAttributeCO attributeCO);
+
+    /**
+     * 获取设备重启时间
+     *
+     * @param tenant
+     * @return LocalTime
+     */
+    String queryAutorestartValue(String tenant);
+}

+ 24 - 0
smsb-customer-manager-client/src/main/java/com/inspur/customer/constant/Constant.java

@@ -71,4 +71,28 @@ public final class Constant {
         }
 
     }
+
+    /**
+     * 租户公共属性
+     */
+    public enum TenantAttribute {
+        DEVICE_RESTART("autorestart", "设备定时重时间");
+
+        private final String key;
+        private final String describe;
+
+        TenantAttribute(String key, String describe) {
+            this.key = key;
+            this.describe = describe;
+        }
+
+        public String key() {
+            return this.key;
+        }
+
+        public String getDescribe() {
+            return this.describe;
+        }
+
+    }
 }

+ 31 - 0
smsb-customer-manager-client/src/main/java/com/inspur/customer/object/tenant/TenantAttributeCO.java

@@ -0,0 +1,31 @@
+package com.inspur.customer.object.tenant;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * @Author wangbo13
+ * @Date 2023/2/14 11:34
+ * @Version 1.0
+ */
+@Data
+public class TenantAttributeCO implements Serializable {
+    private static final long serialVersionUID = -6306767042786033321L;
+    /**
+     * 租户
+     */
+    @NotNull(message = "tenant不能为空")
+    private String tenant;
+    /**
+     * 属性key
+     */
+    @NotNull(message = "attributeKey不能为空")
+    private String attributeKey;
+
+    /**
+     * 属性值
+     */
+    private String attributeValue;
+}

+ 14 - 0
smsb-customer-manager-infrastructure/src/main/java/com/inspur/customer/infrastructure/mapper/tenant/TenantCommonAttributeMapper.java

@@ -0,0 +1,14 @@
+package com.inspur.customer.infrastructure.mapper.tenant;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.inspur.customer.infrastructure.object.tenant.TenantCommonAttributeDO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @Author wangbo13
+ * @Date 2023/2/14 11:12
+ * @Version 1.0
+ */
+@Mapper
+public interface TenantCommonAttributeMapper extends BaseMapper<TenantCommonAttributeDO> {
+}

+ 38 - 0
smsb-customer-manager-infrastructure/src/main/java/com/inspur/customer/infrastructure/object/tenant/TenantCommonAttributeDO.java

@@ -0,0 +1,38 @@
+package com.inspur.customer.infrastructure.object.tenant;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @Author wangbo13
+ * @Date 2023/2/14 11:09
+ * @Version 1.0
+ */
+@Data
+@TableName("tenant_common_attribute")
+public class TenantCommonAttributeDO implements Serializable {
+    private static final long serialVersionUID = -8752574182819977894L;
+    /**
+     * 主键
+     */
+    @TableId
+    private Long id;
+    /**
+     * 租户标识
+     */
+    private String tenant;
+    /**
+     * 属性key
+     */
+    @TableField("attribute_key")
+    private String attributeKey;
+    /**
+     * 属性value
+     */
+    @TableField("attribute_value")
+    private String attributeValue;
+}

+ 5 - 0
smsb-customer-manager-infrastructure/src/main/resources/mapper/tenant/TenantCommonAttributeMapper.xml

@@ -0,0 +1,5 @@
+<?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.inspur.customer.infrastructure.mapper.tenant.TenantCommonAttributeMapper">
+
+</mapper>