|
|
@@ -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;
|
|
|
+ }
|
|
|
+}
|