Commit faa30c0f by huangjy

Merge remote-tracking branch 'origin/dev' into dev

parents 2b198f1b d1a1b786
...@@ -133,20 +133,21 @@ CREATE TABLE `saas_operation_log` ( ...@@ -133,20 +133,21 @@ CREATE TABLE `saas_operation_log` (
CREATE TABLE `plat_tenant` ( CREATE TABLE `plat_tenant` (
`id` varchar(64) NOT NULL COLLATE utf8mb4_general_ci COMMENT 'id', `id` varchar(64) NOT NULL COMMENT 'id',
`name` varchar(128) DEFAULT NULL COMMENT '名称', `name` varchar(128) DEFAULT NULL COMMENT '名称',
`status` varchar(10) NOT NULL COMMENT '状态 0停用 1启用', `status` varchar(10) NOT NULL COMMENT '状态 0停用 1启用',
`start_time` datetime NOT NULL COMMENT '租户有效期-开始时间', `start_time` datetime NOT NULL COMMENT '租户有效期-开始时间',
`end_time` datetime NOT NULL COMMENT '租户有效期-结束时间', `end_time` datetime NOT NULL COMMENT '租户有效期-结束时间',
`plat_user_id` varchar(64) NOT NULL COMMENT '租户管理员id', `plat_user_id` varchar(64) NOT NULL COMMENT '租户管理员id',
`menu_list` varchar(600) DEFAULT NULL COMMENT '菜单id列表 以逗号分隔', `menu_list` varchar(600) DEFAULT NULL COMMENT '菜单id列表 以逗号分隔',
`alert_channel` varchar(32) DEFAULT NULL COMMENT '告警渠道 1-短信 2-邮件 3-语音短信 4-云龄工单 5-晶奇工单', `alert_channel` varchar(32) DEFAULT NULL COMMENT '告警渠道 1-短信 2-邮件 3-语音短信 4-云龄工单 5-晶奇工单',
`create_date` datetime NOT NULL COMMENT '创建时间', `create_date` datetime NOT NULL COMMENT '创建时间',
`update_date` datetime NOT NULL COMMENT '更新时间', `update_date` datetime NOT NULL COMMENT '更新时间',
`del_flag` CHAR(1) DEFAULT NULL COMMENT '删除标识', `del_flag` char(1) DEFAULT NULL COMMENT '删除标识',
`create_by` varchar(64) NOT NULL COMMENT '创建人', `create_by` varchar(64) NOT NULL COMMENT '创建人',
`update_by` varchar(64) NOT NULL COMMENT '更新人', `update_by` varchar(64) NOT NULL COMMENT '更新人',
PRIMARY KEY (`id`) `iot_org_id` varchar(64) DEFAULT NULL COMMENT 'iot组织id',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 STATS_AUTO_RECALC=0 ROW_FORMAT=COMPACT COMMENT='租户管理'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 STATS_AUTO_RECALC=0 ROW_FORMAT=COMPACT COMMENT='租户管理';
CREATE TABLE `plat_tenant_menu` ( CREATE TABLE `plat_tenant_menu` (
......
package com.makeit.controller.saas;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.global.annotation.Action;
import com.makeit.module.admin.dto.saas.SaasMenuDTOVO;
import com.makeit.module.admin.dto.saas.SaasMenuQueryDTO;
import com.makeit.service.saas.SaasMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 平台端菜单 前端控制器
* </p>
*
* @author eugene young
* @since 2022-05-10
*/
@Api(tags = "saas端-菜单")
@RestController
@RequestMapping("/saas/menu")
public class SaasMenuController {
@Autowired
private SaasMenuService platMenuService;
@Action(module = "saas端-菜单", name = "列表", code = "plat:menu:list")
@ApiOperation("列表")
@PostMapping("list")
public ApiResponseEntity<List<SaasMenuDTOVO>> list(@RequestBody SaasMenuQueryDTO dto) {
return ApiResponseUtils.success(platMenuService.list(dto));
}
@Action(module = "saas端-菜单", name = "树形列表", code = "plat:menu:tree")
@ApiOperation("树形列表")
@PostMapping("tree")
public ApiResponseEntity<List<SaasMenuDTOVO>> tree(@RequestBody SaasMenuQueryDTO dto) {
return ApiResponseUtils.success(platMenuService.tree(dto));
}
@ApiOperation("列表(AuthIgnore)")
@PostMapping("listAuthIgnore")
public ApiResponseEntity<List<SaasMenuDTOVO>> listAuthIgnore(@RequestBody SaasMenuQueryDTO dto) {
return ApiResponseUtils.success(platMenuService.list(dto));
}
@ApiOperation("树形列表(AuthIgnore)")
@PostMapping("treeAuthIgnore")
public ApiResponseEntity<List<SaasMenuDTOVO>> treeAuthIgnore(@RequestBody SaasMenuQueryDTO dto) {
return ApiResponseUtils.success(platMenuService.tree(dto));
}
@Action(module = "saas端-菜单", name = "新增", code = "plat:menu:add")
@ApiOperation("新增")
@PostMapping("add")
public ApiResponseEntity<?> add(@Validated @RequestBody SaasMenuDTOVO dto) {
platMenuService.add(dto);
return ApiResponseUtils.success();
}
@Action(module = "saas端-菜单", name = "编辑", code = "plat:menu:edit")
@ApiOperation("编辑")
@PostMapping("edit")
public ApiResponseEntity<?> edit(@Validated @RequestBody SaasMenuDTOVO dto) {
platMenuService.edit(dto);
return ApiResponseUtils.success();
}
//@Action(module = "saas端-菜单", name = "详情", code = "plat:menu:view")
@ApiOperation("详情")
@PostMapping("view")
public ApiResponseEntity<SaasMenuDTOVO> view(@RequestBody BaseIdDTO dto) {
return ApiResponseUtils.success(platMenuService.view(dto.getId()));
}
@Action(module = "saas端-菜单", name = "删除", code = "plat:menu:del")
@ApiOperation("删除")
@PostMapping("del")
public ApiResponseEntity<?> del(@RequestBody BaseIdDTO dto) {
platMenuService.del(dto.getId());
return ApiResponseUtils.success();
}
@ApiOperation("同步")
@PostMapping("sync")
public ApiResponseEntity<?> sync() {
platMenuService.sync();
return ApiResponseUtils.success();
}
}
package com.makeit.task;
import com.makeit.module.iot.service.IotOrgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class IotSyncTask {
@Autowired
private IotOrgService iotOrgService;
@Scheduled(cron = "0 */1 * * * ?")
public void syncEquipmentInfo() {
log.info("开始执行同步设备信息接口");
log.info("结束执行同步设备信息接口");
}
@Scheduled(cron = "0 0/1 * * * ?")
public void syncDeviceLog() {
log.info("开始同步设备日志");
log.info("同步设备日志结束");
}
}
...@@ -49,5 +49,10 @@ public class PlatTenant extends BaseEntity { ...@@ -49,5 +49,10 @@ public class PlatTenant extends BaseEntity {
*/ */
private String alertChannel; private String alertChannel;
/**
* 新增租户时,会在iot创建一个组织
*/
private String iotOrgId;
} }
\ No newline at end of file
...@@ -22,6 +22,8 @@ import com.makeit.module.admin.dto.plat.PlatTenantDTOVO; ...@@ -22,6 +22,8 @@ import com.makeit.module.admin.dto.plat.PlatTenantDTOVO;
import com.makeit.module.admin.dto.plat.PlatTenantMenuDTO; import com.makeit.module.admin.dto.plat.PlatTenantMenuDTO;
import com.makeit.module.admin.dto.plat.PlatTenantStatusDTO; import com.makeit.module.admin.dto.plat.PlatTenantStatusDTO;
import com.makeit.module.admin.vo.plat.PlatTenantVO; import com.makeit.module.admin.vo.plat.PlatTenantVO;
import com.makeit.module.iot.service.IotOrgService;
import com.makeit.module.iot.vo.OrganizationEntity;
import com.makeit.module.system.service.SysConfigService; import com.makeit.module.system.service.SysConfigService;
import com.makeit.service.platform.auth.PlatOrgService; import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.auth.PlatUserService; import com.makeit.service.platform.auth.PlatUserService;
...@@ -75,6 +77,9 @@ implements PlatTenantService { ...@@ -75,6 +77,9 @@ implements PlatTenantService {
@Autowired @Autowired
private PlatOrgService platOrgService; private PlatOrgService platOrgService;
@Autowired
private IotOrgService iotOrgService;
private LambdaQueryWrapper<PlatTenant> listLambdaQueryWrapper(PlatTenantVO dto, boolean userAccountLike) { private LambdaQueryWrapper<PlatTenant> listLambdaQueryWrapper(PlatTenantVO dto, boolean userAccountLike) {
List<String> tenantUserIdList = new ArrayList<>(10); List<String> tenantUserIdList = new ArrayList<>(10);
...@@ -192,6 +197,13 @@ implements PlatTenantService { ...@@ -192,6 +197,13 @@ implements PlatTenantService {
checkName(dto); checkName(dto);
checkDate(dto); checkDate(dto);
PlatTenant tntTenant = BeanDtoVoUtils.convert(dto, PlatTenant.class); PlatTenant tntTenant = BeanDtoVoUtils.convert(dto, PlatTenant.class);
//新租户同步到iot
PlatTenantVO platTenantVO = new PlatTenantVO();
platTenantVO.setName(dto.getName());
OrganizationEntity organizationEntity = iotOrgService.syncTenantInfoToIot(platTenantVO);
tntTenant.setIotOrgId(organizationEntity.getId());
save(tntTenant); save(tntTenant);
dto.setId(tntTenant.getId()); dto.setId(tntTenant.getId());
......
package com.makeit.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.makeit.common.entity.BaseBusEntity;
import com.makeit.common.entity.BaseEntity;
import com.makeit.entity.platform.device.PlatDevice;
import com.makeit.entity.saas.PlatTenant;
import com.makeit.enums.CommonEnum;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.iot.service.IotOrgService;
import com.makeit.module.iot.vo.DeviceInstanceEntity;
import com.makeit.service.platform.device.PlatDeviceService;
import com.makeit.service.saas.PlatTenantService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@Component
@Slf4j
public class IotSyncTask {
@Autowired
private IotOrgService iotOrgService;
@Autowired
private PlatTenantService platTenantService;
@Autowired
private PlatDeviceService platDeviceService;
/**
* 一小时同步一次
* 启用状态的租户才同步
* 新增和更新平台端设备表
*/
@Scheduled(cron = "0 0 */1 * * ?")
// @Scheduled(cron = "0 */1 * * * ?")
@TenantIdIgnore
public void syncEquipmentInfo() {
log.info("开始执行同步设备信息接口");
LambdaQueryWrapper<PlatTenant> tenantLambdaQueryWrapper = new LambdaQueryWrapper<PlatTenant>().eq(PlatTenant::getStatus, CommonEnum.YES.getValue());
List<PlatTenant> platTenants = platTenantService.list(tenantLambdaQueryWrapper);
for (PlatTenant platTenant : platTenants) {
String iotOrgId = platTenant.getIotOrgId();
if(StringUtils.isBlank(iotOrgId)){
continue;
}
//查询iot设备
List<DeviceInstanceEntity> iotDeviceList = iotOrgService.getOrgDevice(iotOrgId);
if(CollectionUtils.isEmpty(iotDeviceList)){
continue;
}
//查询平台设备
Set<String> iotDeviceIdSet = iotDeviceList.stream().map(DeviceInstanceEntity::getId).collect(Collectors.toSet());
LambdaQueryWrapper<PlatDevice> deviceLambdaQueryWrapper = new LambdaQueryWrapper<PlatDevice>().eq(BaseBusEntity::getTenantId, platTenant.getId())
.in(BaseEntity::getId, iotDeviceIdSet);
List<PlatDevice> deviceList = platDeviceService.list(deviceLambdaQueryWrapper);
//更新平台设备
Collection<PlatDevice> platDevices = convertToPlatDevice(iotDeviceList, deviceList,platTenant.getId());
platDeviceService.saveOrUpdateBatch(platDevices);
}
log.info("结束执行同步设备信息接口");
}
@Scheduled(cron = "0 0/1 * * * ?")
public void syncDeviceLog() {
log.info("开始同步设备日志");
log.info("同步设备日志结束");
}
private Collection<PlatDevice> convertToPlatDevice(List<DeviceInstanceEntity> iotDeviceList, List<PlatDevice> deviceList,String tenantId){
Map<String, PlatDevice> deviceMap = deviceList.stream().collect(Collectors.toMap(PlatDevice::getOriDeviceId, v -> v, (a, b) -> a));
iotDeviceList.forEach(iotDevice->{
PlatDevice platDevice = deviceMap.get(iotDevice.getId());
if(platDevice==null){
platDevice=new PlatDevice();
platDevice.setTenantId(tenantId);
}
platDevice.setOriDeviceId(iotDevice.getId());
platDevice.setName(iotDevice.getName());
platDevice.setProductName(iotDevice.getProductName());
platDevice.setProductId(iotDevice.getProductId());
LocalDateTime registryTime = LocalDateTime.ofEpochSecond(iotDevice.getRegistryTime()/1000, 0, ZoneOffset.ofHours(8));
platDevice.setRegistrationDate(registryTime);
platDevice.setDescription(iotDevice.getDescribe());
String state = iotDevice.getState();
platDevice.setStatus(StringUtils.equals("online",state)?CommonEnum.YES.getValue() : CommonEnum.NO.getValue());
// platDevice.setFirmwareVersion();
// platDevice.setLastOnlineData();
// platDevice.setOrgId();
// platDevice.setCityOrgId();
// platDevice.setDistrictOrgId();
// platDevice.setStreetOrgId();
// platDevice.setOrgPath();
// platDevice.setId();
// platDevice.setCreateDate();
// platDevice.setUpdateDate();
// platDevice.setDelFlag();
// platDevice.setCreateBy();
// platDevice.setUpdateBy();
deviceMap.put(iotDevice.getId(),platDevice);
});
return deviceMap.values();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment