Commit 367cf61e689099189b11cdf91810c548c8cab2dc
Merge branch '20220424' into 'master'
refactor: 第三方平台用户绑定和解绑接口逻辑优化 See merge request huang/thingsboard3.3.2!85
Showing
16 changed files
with
424 additions
and
36 deletions
@@ -3,7 +3,6 @@ package org.thingsboard.server.controller.yunteng; | @@ -3,7 +3,6 @@ package org.thingsboard.server.controller.yunteng; | ||
3 | import io.swagger.annotations.Api; | 3 | import io.swagger.annotations.Api; |
4 | import io.swagger.annotations.ApiOperation; | 4 | import io.swagger.annotations.ApiOperation; |
5 | import lombok.RequiredArgsConstructor; | 5 | import lombok.RequiredArgsConstructor; |
6 | -import org.apache.commons.lang3.StringUtils; | ||
7 | import org.springframework.http.ResponseEntity; | 6 | import org.springframework.http.ResponseEntity; |
8 | import org.springframework.security.access.prepost.PreAuthorize; | 7 | import org.springframework.security.access.prepost.PreAuthorize; |
9 | import org.springframework.web.bind.annotation.GetMapping; | 8 | import org.springframework.web.bind.annotation.GetMapping; |
@@ -11,8 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -11,8 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
11 | import org.springframework.web.bind.annotation.RequestParam; | 10 | import org.springframework.web.bind.annotation.RequestParam; |
12 | import org.springframework.web.bind.annotation.RestController; | 11 | import org.springframework.web.bind.annotation.RestController; |
13 | import org.thingsboard.server.common.data.EntityType; | 12 | import org.thingsboard.server.common.data.EntityType; |
14 | -import org.thingsboard.server.common.data.alarm.Alarm; | ||
15 | -import org.thingsboard.server.common.data.alarm.AlarmInfo; | 13 | +import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
16 | import org.thingsboard.server.common.data.alarm.AlarmStatus; | 14 | import org.thingsboard.server.common.data.alarm.AlarmStatus; |
17 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 15 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
18 | import org.thingsboard.server.common.data.page.TimePageLink; | 16 | import org.thingsboard.server.common.data.page.TimePageLink; |
@@ -24,7 +22,9 @@ import org.thingsboard.server.controller.BaseController; | @@ -24,7 +22,9 @@ import org.thingsboard.server.controller.BaseController; | ||
24 | import org.thingsboard.server.dao.yunteng.entities.YtAlarmEntity; | 22 | import org.thingsboard.server.dao.yunteng.entities.YtAlarmEntity; |
25 | import org.thingsboard.server.dao.yunteng.service.YtAlarmInfoService; | 23 | import org.thingsboard.server.dao.yunteng.service.YtAlarmInfoService; |
26 | 24 | ||
27 | -import java.util.*; | 25 | +import java.util.HashMap; |
26 | +import java.util.List; | ||
27 | +import java.util.Map; | ||
28 | 28 | ||
29 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | 29 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
30 | 30 | ||
@@ -44,7 +44,7 @@ public class YtAlarmInfoController extends BaseController { | @@ -44,7 +44,7 @@ public class YtAlarmInfoController extends BaseController { | ||
44 | 44 | ||
45 | //分页测试通过 | 45 | //分页测试通过 |
46 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | 46 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") |
47 | - @ApiOperation(value="查询") | 47 | + @ApiOperation(value = "查询") |
48 | @GetMapping(params = {PAGE_SIZE, PAGE}) | 48 | @GetMapping(params = {PAGE_SIZE, PAGE}) |
49 | public YtPageData<YtAlarmEntity> pageAlarmInfo( | 49 | public YtPageData<YtAlarmEntity> pageAlarmInfo( |
50 | @RequestParam(PAGE_SIZE) int pageSize, | 50 | @RequestParam(PAGE_SIZE) int pageSize, |
@@ -52,6 +52,7 @@ public class YtAlarmInfoController extends BaseController { | @@ -52,6 +52,7 @@ public class YtAlarmInfoController extends BaseController { | ||
52 | @RequestParam(value = "status", required = false) List<AlarmStatus> status, | 52 | @RequestParam(value = "status", required = false) List<AlarmStatus> status, |
53 | @RequestParam(value = "textSearch", required = false) String textSearch, | 53 | @RequestParam(value = "textSearch", required = false) String textSearch, |
54 | @RequestParam(value = "alarmType", required = false) String alarmType, | 54 | @RequestParam(value = "alarmType", required = false) String alarmType, |
55 | + @RequestParam(value = "severity", required = false) AlarmSeverity severity, | ||
55 | @RequestParam(value = "organizationId", required = false) String organizationId, | 56 | @RequestParam(value = "organizationId", required = false) String organizationId, |
56 | @RequestParam(value = "deviceId", required = false) String deviceId, | 57 | @RequestParam(value = "deviceId", required = false) String deviceId, |
57 | @RequestParam(value = "deviceType", required = false) DeviceTypeEnum deviceType, | 58 | @RequestParam(value = "deviceType", required = false) DeviceTypeEnum deviceType, |
@@ -67,12 +68,11 @@ public class YtAlarmInfoController extends BaseController { | @@ -67,12 +68,11 @@ public class YtAlarmInfoController extends BaseController { | ||
67 | if (orderType != null) { | 68 | if (orderType != null) { |
68 | pageFilter.put(ORDER_TYPE, orderType.name()); | 69 | pageFilter.put(ORDER_TYPE, orderType.name()); |
69 | } | 70 | } |
70 | - return alarmInfoService.alarmPage(pageFilter,getCurrentUser().getTenantId(),alarmType,startTime,endTime,status,deviceId,deviceType, EntityType.DEVICE,organizationId); | 71 | + return alarmInfoService.alarmPage(pageFilter, getCurrentUser().getTenantId(), severity,alarmType, startTime, endTime, status, deviceId, deviceType, EntityType.DEVICE, organizationId); |
71 | } | 72 | } |
72 | 73 | ||
73 | 74 | ||
74 | - | ||
75 | - @ApiOperation(value="告警类型") | 75 | + @ApiOperation(value = "告警类型") |
76 | @GetMapping() | 76 | @GetMapping() |
77 | public ResponseEntity<List<SysDictDTO>> alarmType() throws ThingsboardException { | 77 | public ResponseEntity<List<SysDictDTO>> alarmType() throws ThingsboardException { |
78 | List result = alarmInfoService.alarmType(getCurrentUser().getTenantId()); | 78 | List result = alarmInfoService.alarmType(getCurrentUser().getTenantId()); |
@@ -80,5 +80,4 @@ public class YtAlarmInfoController extends BaseController { | @@ -80,5 +80,4 @@ public class YtAlarmInfoController extends BaseController { | ||
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | - | ||
84 | } | 83 | } |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtRpcRecordController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import io.swagger.annotations.Api; | ||
5 | +import io.swagger.annotations.ApiOperation; | ||
6 | +import lombok.RequiredArgsConstructor; | ||
7 | +import org.springframework.web.bind.annotation.GetMapping; | ||
8 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
9 | +import org.springframework.web.bind.annotation.RequestParam; | ||
10 | +import org.springframework.web.bind.annotation.RestController; | ||
11 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
12 | +import org.thingsboard.server.common.data.id.DeviceId; | ||
13 | +import org.thingsboard.server.common.data.id.EntityId; | ||
14 | +import org.thingsboard.server.common.data.rpc.RpcStatus; | ||
15 | +import org.thingsboard.server.common.data.yunteng.dto.YtRpcRecordDTO; | ||
16 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
17 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
18 | +import org.thingsboard.server.controller.BaseController; | ||
19 | +import org.thingsboard.server.dao.yunteng.entities.YtRpcRecordEntity; | ||
20 | +import org.thingsboard.server.dao.yunteng.service.YtRpcRecordService; | ||
21 | + | ||
22 | +import java.util.UUID; | ||
23 | + | ||
24 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
25 | + | ||
26 | +/** | ||
27 | + * @author Administrator | ||
28 | + */ | ||
29 | +@RestController | ||
30 | +@RequestMapping("api/yt/rpc") | ||
31 | +@Api(tags = {"命令下发记录"}) | ||
32 | +@RequiredArgsConstructor | ||
33 | +public class YtRpcRecordController extends BaseController { | ||
34 | + private final YtRpcRecordService recordService; | ||
35 | + | ||
36 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | ||
37 | + @ApiOperation("分页") | ||
38 | + public YtPageData<YtRpcRecordDTO> pageAlarmProfile( | ||
39 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
40 | + @RequestParam(PAGE) int page, | ||
41 | + @RequestParam(value = "status", required = false) RpcStatus status, | ||
42 | + @RequestParam(value = "name", required = false) String name, | ||
43 | + @RequestParam(value = "tbDeviceId", required = false) String tbDeviceId, | ||
44 | +// @RequestParam(value = "oneway", required = false) Boolean oneway, | ||
45 | + @RequestParam(value = "organizationId", required = false) String organizationId, | ||
46 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
47 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
48 | + throws ThingsboardException { | ||
49 | + | ||
50 | + | ||
51 | + IPage<YtRpcRecordEntity> pageInfrom = recordService.getPage(page, pageSize, orderBy, orderType); | ||
52 | + return recordService.pageDatas(pageInfrom, getCurrentUser().getCurrentTenantId(), tbDeviceId,null, status, organizationId, name); | ||
53 | + } | ||
54 | + | ||
55 | + | ||
56 | +} |
@@ -65,16 +65,15 @@ public class YtThirdPlatformController extends BaseController { | @@ -65,16 +65,15 @@ public class YtThirdPlatformController extends BaseController { | ||
65 | @ApiOperation("绑定") | 65 | @ApiOperation("绑定") |
66 | public JwtTokenPair saveOrUpdateAlarmProfile( | 66 | public JwtTokenPair saveOrUpdateAlarmProfile( |
67 | @Validated @RequestBody YtThirdUserDTO dto) throws ThingsboardException { | 67 | @Validated @RequestBody YtThirdUserDTO dto) throws ThingsboardException { |
68 | - UserDTO userDto = thirdService.saveOrUpdate(dto); | 68 | + UserDTO userDto = thirdService.bindUser(dto); |
69 | return buildJwtToken(userDto); | 69 | return buildJwtToken(userDto); |
70 | } | 70 | } |
71 | 71 | ||
72 | @DeleteMapping | 72 | @DeleteMapping |
73 | - @ApiOperation("删除") | ||
74 | - public boolean deleteAlarmProfile(@Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) | 73 | + @ApiOperation("解绑") |
74 | + public boolean deleteAlarmProfile(@Validated(DeleteGroup.class) @RequestBody YtThirdUserDTO dto) | ||
75 | throws ThingsboardException { | 75 | throws ThingsboardException { |
76 | - deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
77 | - return thirdService.deleteDataByIds(deleteDTO); | 76 | + return thirdService.unbindUser(getCurrentUser().getCurrentTenantId(), dto.getAppUserId(),dto.getThirdUserId()); |
78 | } | 77 | } |
79 | 78 | ||
80 | @GetMapping("login/{thirdId}") | 79 | @GetMapping("login/{thirdId}") |
@@ -59,7 +59,8 @@ public enum ErrorMessage { | @@ -59,7 +59,8 @@ public enum ErrorMessage { | ||
59 | DEVICE_LOSED(400039,"设备相关参数丢失"), | 59 | DEVICE_LOSED(400039,"设备相关参数丢失"), |
60 | SCENE_REACT_NOT_EXTIED(400040,"场景联动不存在"), | 60 | SCENE_REACT_NOT_EXTIED(400040,"场景联动不存在"), |
61 | DEVICE_USED_SCENE_REACT(400041,"场景联动【%s】正在使用该设备"), | 61 | DEVICE_USED_SCENE_REACT(400041,"场景联动【%s】正在使用该设备"), |
62 | - SCENE_REACT_USED_ALARM_PROFILE(400041,"场景联动正在使用该告警配置"), | 62 | + SCENE_REACT_USED_ALARM_PROFILE(400042,"场景联动正在使用该告警配置"), |
63 | + APP_USER_BINDED(400043,"账号【%s】已绑定"), | ||
63 | HAVE_NO_PERMISSION(500002,"没有修改权限"); | 64 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
64 | private final int code; | 65 | private final int code; |
65 | private String message; | 66 | private String message; |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/YtRpcRecordDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
4 | +import com.fasterxml.jackson.databind.JsonNode; | ||
5 | +import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
6 | +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
7 | +import io.swagger.annotations.ApiModelProperty; | ||
8 | +import lombok.Data; | ||
9 | +import lombok.EqualsAndHashCode; | ||
10 | +import org.thingsboard.server.common.data.TenantProfile; | ||
11 | +import org.thingsboard.server.common.data.rpc.RpcStatus; | ||
12 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | ||
13 | +import org.thingsboard.server.common.data.yunteng.enums.LoginMethodEnum; | ||
14 | +import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; | ||
15 | + | ||
16 | +import javax.validation.constraints.NotEmpty; | ||
17 | +import java.time.LocalDateTime; | ||
18 | + | ||
19 | +/** | ||
20 | + * @author Administrator | ||
21 | + */ | ||
22 | +@Data | ||
23 | +public class YtRpcRecordDTO { | ||
24 | + private String id; | ||
25 | + | ||
26 | + @ApiModelProperty(value = "设备主键") | ||
27 | + private String deviceId; | ||
28 | + private String deviceName; | ||
29 | + private String tbDeviceId; | ||
30 | + @ApiModelProperty(value = "设备类型:GATEWAY,DIRECT_CONNECTION,SENSOR") | ||
31 | + private DeviceTypeEnum deviceType; | ||
32 | + private String deviceSn; | ||
33 | + | ||
34 | + | ||
35 | + @ApiModelProperty(value = "设备组织ID") | ||
36 | + private String organizationId; | ||
37 | + @ApiModelProperty(value = "设备组织名称") | ||
38 | + private String organizationName; | ||
39 | + | ||
40 | + @ApiModelProperty(value = "租户ID") | ||
41 | + private String tenantId; | ||
42 | + @ApiModelProperty(value = "租户名称") | ||
43 | + private String tenantName; | ||
44 | + | ||
45 | + | ||
46 | + private Long createTime; | ||
47 | + private Long expirationTime; | ||
48 | + | ||
49 | + @ApiModelProperty(value = "RPC请求内容") | ||
50 | + private JsonNode request; | ||
51 | + | ||
52 | + @ApiModelProperty(value = "RPC响应内容") | ||
53 | + private JsonNode response; | ||
54 | + @ApiModelProperty(value = "RPC扩展信息") | ||
55 | + private JsonNode additionalInfo; | ||
56 | + @ApiModelProperty(value = "RPC状态") | ||
57 | + private RpcStatus status; | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | +} |
1 | +package org.thingsboard.server.dao.yunteng.entities; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
4 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
5 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | ||
6 | +import com.fasterxml.jackson.databind.JsonNode; | ||
7 | +import lombok.Data; | ||
8 | +import lombok.EqualsAndHashCode; | ||
9 | +import org.apache.ibatis.type.EnumTypeHandler; | ||
10 | +import org.hibernate.annotations.Type; | ||
11 | +import org.thingsboard.server.common.data.rpc.RpcStatus; | ||
12 | +import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; | ||
13 | +import org.thingsboard.server.dao.model.ModelConstants; | ||
14 | + | ||
15 | +import javax.persistence.Column; | ||
16 | +import javax.persistence.EnumType; | ||
17 | +import javax.persistence.Enumerated; | ||
18 | +import java.util.UUID; | ||
19 | + | ||
20 | +import static org.thingsboard.server.dao.model.ModelConstants.*; | ||
21 | + | ||
22 | +/** | ||
23 | + * @author Administrator | ||
24 | + */ | ||
25 | +@Data | ||
26 | +@EqualsAndHashCode(callSuper = true) | ||
27 | +@TableName(ModelConstants.RPC_TABLE_NAME) | ||
28 | +public class YtRpcRecordEntity extends TenantBaseEntity { | ||
29 | + | ||
30 | + private String deviceId; | ||
31 | + | ||
32 | + private long expirationTime; | ||
33 | + | ||
34 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
35 | + private JsonNode request; | ||
36 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
37 | + private JsonNode response; | ||
38 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
39 | + private JsonNode additionalInfo; | ||
40 | + | ||
41 | + @TableField(typeHandler = EnumTypeHandler.class) | ||
42 | + private RpcStatus status; | ||
43 | + | ||
44 | + | ||
45 | +} |
@@ -9,6 +9,7 @@ import org.apache.commons.lang3.StringUtils; | @@ -9,6 +9,7 @@ import org.apache.commons.lang3.StringUtils; | ||
9 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
10 | import org.thingsboard.server.common.data.EntityType; | 10 | import org.thingsboard.server.common.data.EntityType; |
11 | import org.thingsboard.server.common.data.alarm.AlarmInfo; | 11 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
12 | +import org.thingsboard.server.common.data.alarm.AlarmSeverity; | ||
12 | import org.thingsboard.server.common.data.alarm.AlarmStatus; | 13 | import org.thingsboard.server.common.data.alarm.AlarmStatus; |
13 | import org.thingsboard.server.common.data.id.TenantId; | 14 | import org.thingsboard.server.common.data.id.TenantId; |
14 | import org.thingsboard.server.common.data.page.PageData; | 15 | import org.thingsboard.server.common.data.page.PageData; |
@@ -42,7 +43,7 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | @@ -42,7 +43,7 @@ public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | ||
42 | private final YtAlarmMapper ytJpaAarmDao; | 43 | private final YtAlarmMapper ytJpaAarmDao; |
43 | private final OrganizationMapper organizationMapper; | 44 | private final OrganizationMapper organizationMapper; |
44 | @Override | 45 | @Override |
45 | - public YtPageData<YtAlarmEntity> alarmPage(Map<String, Object> pageMap, TenantId tenantId, String alarmType, Long startTime, Long endTime, List<AlarmStatus> status, String deviceId, DeviceTypeEnum deviceType, EntityType originatorType, String organizationId) { | 46 | + public YtPageData<YtAlarmEntity> alarmPage(Map<String, Object> pageMap, TenantId tenantId, AlarmSeverity severity, String alarmType, Long startTime, Long endTime, List<AlarmStatus> status, String deviceId, DeviceTypeEnum deviceType, EntityType originatorType, String organizationId) { |
46 | IPage<YtAlarmEntity> page= getPage(pageMap, ModelConstants.CREATED_TIME_PROPERTY,false); | 47 | IPage<YtAlarmEntity> page= getPage(pageMap, ModelConstants.CREATED_TIME_PROPERTY,false); |
47 | List<String> ids =new ArrayList<>(); | 48 | List<String> ids =new ArrayList<>(); |
48 | if(StringUtils.isNotBlank(organizationId)){ | 49 | if(StringUtils.isNotBlank(organizationId)){ |
@@ -55,7 +56,7 @@ private final OrganizationMapper organizationMapper; | @@ -55,7 +56,7 @@ private final OrganizationMapper organizationMapper; | ||
55 | 56 | ||
56 | } | 57 | } |
57 | 58 | ||
58 | - IPage<YtAlarmEntity> tbDatas = ytJpaAarmDao.alarmPage(page,tenantId.getId(),alarmType,startTime,endTime,status,deviceId,deviceType, originatorType,ids.size()>0?ids:null); | 59 | + IPage<YtAlarmEntity> tbDatas = ytJpaAarmDao.alarmPage(page,tenantId.getId(),severity,alarmType,startTime,endTime,status,deviceId,deviceType, originatorType,ids.size()>0?ids:null); |
59 | YtPageData<YtAlarmEntity> result = new YtPageData<>(tbDatas.getRecords(), tbDatas.getTotal()); | 60 | YtPageData<YtAlarmEntity> result = new YtPageData<>(tbDatas.getRecords(), tbDatas.getTotal()); |
60 | return result; | 61 | return result; |
61 | } | 62 | } |
1 | +package org.thingsboard.server.dao.yunteng.impl; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import lombok.RequiredArgsConstructor; | ||
5 | +import lombok.extern.slf4j.Slf4j; | ||
6 | +import org.springframework.stereotype.Service; | ||
7 | +import org.thingsboard.server.common.data.StringUtils; | ||
8 | +import org.thingsboard.server.common.data.id.DeviceId; | ||
9 | +import org.thingsboard.server.common.data.id.EntityId; | ||
10 | +import org.thingsboard.server.common.data.id.TenantId; | ||
11 | +import org.thingsboard.server.common.data.rpc.RpcStatus; | ||
12 | +import org.thingsboard.server.common.data.yunteng.dto.YtRpcRecordDTO; | ||
13 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
14 | +import org.thingsboard.server.dao.yunteng.entities.YtRpcRecordEntity; | ||
15 | +import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; | ||
16 | +import org.thingsboard.server.dao.yunteng.mapper.YtRpcRecordMapper; | ||
17 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
18 | +import org.thingsboard.server.dao.yunteng.service.YtRpcRecordService; | ||
19 | + | ||
20 | +import java.util.ArrayList; | ||
21 | +import java.util.List; | ||
22 | +import java.util.UUID; | ||
23 | +import java.util.stream.Collectors; | ||
24 | + | ||
25 | +/** | ||
26 | + * @author Administrator | ||
27 | + */ | ||
28 | +@Slf4j | ||
29 | +@Service | ||
30 | +@RequiredArgsConstructor | ||
31 | +public class YtRpcRecordServiceImpl extends AbstractBaseService<YtRpcRecordMapper, YtRpcRecordEntity> | ||
32 | + implements YtRpcRecordService { | ||
33 | + | ||
34 | + | ||
35 | + private final OrganizationMapper organizationMapper; | ||
36 | + | ||
37 | + @Override | ||
38 | + public YtPageData<YtRpcRecordDTO> pageDatas(IPage<YtRpcRecordEntity> pageInfrom, String tenantId, String deviceId, Boolean oneway, RpcStatus status, String organizationId, String name) { | ||
39 | + List<String> organization = null; | ||
40 | + if (StringUtils.isNotEmpty(organizationId)) { | ||
41 | + List<String> organizationFilter = new ArrayList<>(); | ||
42 | + organizationFilter.add(organizationId); | ||
43 | + organization = organizationMapper.findOrganizationTreeList(tenantId, organizationFilter).stream().map(org -> org.getId()).collect(Collectors.toList()); | ||
44 | + } | ||
45 | + | ||
46 | + IPage<YtRpcRecordDTO> page = baseMapper.getPageDatas(pageInfrom, tenantId, deviceId,name, status, organization, null); | ||
47 | + return getPageData(page, YtRpcRecordDTO.class); | ||
48 | + } | ||
49 | + | ||
50 | + | ||
51 | +} |
@@ -60,7 +60,7 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf | @@ -60,7 +60,7 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf | ||
60 | 60 | ||
61 | @Override | 61 | @Override |
62 | @Transactional(rollbackFor = Exception.class) | 62 | @Transactional(rollbackFor = Exception.class) |
63 | - public UserDTO saveOrUpdate(YtThirdUserDTO dto) { | 63 | + public UserDTO bindUser(YtThirdUserDTO dto) { |
64 | User user = null; | 64 | User user = null; |
65 | switch (dto.getLoginMethod()) { | 65 | switch (dto.getLoginMethod()) { |
66 | case PHONE: | 66 | case PHONE: |
@@ -73,21 +73,21 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf | @@ -73,21 +73,21 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf | ||
73 | if (user == null) { | 73 | if (user == null) { |
74 | throw new YtDataValidationException(ErrorMessage.USER_NOT_EXISTS.getMessage()); | 74 | throw new YtDataValidationException(ErrorMessage.USER_NOT_EXISTS.getMessage()); |
75 | } | 75 | } |
76 | + | ||
77 | + Wrapper filter = new QueryWrapper<YtThirdUserEntity>().lambda() | ||
78 | + .eq(YtThirdUserEntity::getAppUserId, user.getId()); | ||
79 | + YtThirdUserEntity oldBind = baseMapper.selectOne(filter); | ||
80 | + if(oldBind != null){ | ||
81 | + throw new YtDataValidationException(String.format(ErrorMessage.APP_USER_BINDED.getMessage(),user.getUsername())); | ||
82 | + } | ||
83 | + | ||
76 | if (StringUtils.isEmpty(user.getAvatar()) && StringUtils.isNotEmpty(dto.getAvatarUrl())) { | 84 | if (StringUtils.isEmpty(user.getAvatar()) && StringUtils.isNotEmpty(dto.getAvatarUrl())) { |
77 | user.setAvatar(dto.getAvatarUrl()); | 85 | user.setAvatar(dto.getAvatarUrl()); |
78 | userMapper.updateById(user); | 86 | userMapper.updateById(user); |
79 | } | 87 | } |
80 | dto.setAppUserId(user.getId()); | 88 | dto.setAppUserId(user.getId()); |
89 | + baseMapper.insert(dto.getEntity(YtThirdUserEntity.class)); | ||
81 | 90 | ||
82 | - Wrapper filter = new QueryWrapper<YtThirdUserEntity>().lambda() | ||
83 | - .eq(YtThirdUserEntity::getThirdUserId, dto.getThirdUserId()); | ||
84 | - YtThirdUserEntity oldVideo = baseMapper.selectOne(filter); | ||
85 | - if (null == oldVideo) { | ||
86 | - baseMapper.insert(dto.getEntity(YtThirdUserEntity.class)); | ||
87 | - } else { | ||
88 | - dto.setId(oldVideo.getId()); | ||
89 | - baseMapper.updateById(dto.getEntity(YtThirdUserEntity.class)); | ||
90 | - } | ||
91 | return user.getDTO(UserDTO.class); | 91 | return user.getDTO(UserDTO.class); |
92 | } | 92 | } |
93 | 93 | ||
@@ -159,16 +159,22 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf | @@ -159,16 +159,22 @@ public class YtThirdPlatformServiceImpl extends AbstractBaseService<YtThirdPlatf | ||
159 | 159 | ||
160 | @Override | 160 | @Override |
161 | @Transactional(rollbackFor = Exception.class) | 161 | @Transactional(rollbackFor = Exception.class) |
162 | - public boolean deleteDataByIds(DeleteDTO deleteDTO) { | 162 | + public boolean unbindUser(String tenantId,String appUserId,String thirdUserId) { |
163 | + | ||
164 | + User user = userMapper.selectById(appUserId); | ||
165 | + if(!tenantId.equals(user.getTenantId())){ | ||
166 | + throw new YtDataValidationException(ErrorMessage.NO_PERMISSION.getMessage()); | ||
167 | + } | ||
163 | Wrapper filter = new QueryWrapper<YtThirdUserEntity>().lambda() | 168 | Wrapper filter = new QueryWrapper<YtThirdUserEntity>().lambda() |
164 | - .in(YtThirdUserEntity::getId, deleteDTO.getIds()); | 169 | + .eq(YtThirdUserEntity::getAppUserId,appUserId) |
170 | + .eq(YtThirdUserEntity::getThirdUserId,thirdUserId); | ||
165 | return baseMapper.delete(filter) > 0; | 171 | return baseMapper.delete(filter) > 0; |
166 | } | 172 | } |
167 | 173 | ||
168 | @Override | 174 | @Override |
169 | public UserDTO login(String thirdUserId) { | 175 | public UserDTO login(String thirdUserId) { |
170 | - return baseMapper.login(thirdUserId) | ||
171 | - .getDTO(UserDTO.class); | 176 | + User user = baseMapper.login(thirdUserId); |
177 | + return user==null?null:user.getDTO(UserDTO.class); | ||
172 | } | 178 | } |
173 | 179 | ||
174 | @Override | 180 | @Override |
@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper; | @@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Mapper; | ||
6 | import org.apache.ibatis.annotations.Param; | 6 | import org.apache.ibatis.annotations.Param; |
7 | import org.thingsboard.server.common.data.EntityType; | 7 | import org.thingsboard.server.common.data.EntityType; |
8 | import org.thingsboard.server.common.data.alarm.AlarmInfo; | 8 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
9 | +import org.thingsboard.server.common.data.alarm.AlarmSeverity; | ||
9 | import org.thingsboard.server.common.data.alarm.AlarmStatus; | 10 | import org.thingsboard.server.common.data.alarm.AlarmStatus; |
10 | import org.thingsboard.server.common.data.id.TenantId; | 11 | import org.thingsboard.server.common.data.id.TenantId; |
11 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | 12 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
@@ -25,6 +26,7 @@ public interface YtAlarmMapper extends BaseMapper<YtAlarmEntity> { | @@ -25,6 +26,7 @@ public interface YtAlarmMapper extends BaseMapper<YtAlarmEntity> { | ||
25 | IPage<YtAlarmEntity> alarmPage( | 26 | IPage<YtAlarmEntity> alarmPage( |
26 | IPage<?> page | 27 | IPage<?> page |
27 | ,@Param("tenantId") UUID tenantId | 28 | ,@Param("tenantId") UUID tenantId |
29 | + ,@Param("severity") AlarmSeverity severity | ||
28 | ,@Param("alarmType")String alarmType | 30 | ,@Param("alarmType")String alarmType |
29 | ,@Param("startTime")Long startTime | 31 | ,@Param("startTime")Long startTime |
30 | ,@Param("endTime")Long endTime | 32 | ,@Param("endTime")Long endTime |
1 | +package org.thingsboard.server.dao.yunteng.mapper; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
5 | +import org.apache.ibatis.annotations.Mapper; | ||
6 | +import org.apache.ibatis.annotations.Param; | ||
7 | +import org.thingsboard.server.common.data.id.DeviceId; | ||
8 | +import org.thingsboard.server.common.data.id.EntityId; | ||
9 | +import org.thingsboard.server.common.data.id.TenantId; | ||
10 | +import org.thingsboard.server.common.data.rpc.RpcStatus; | ||
11 | +import org.thingsboard.server.common.data.yunteng.dto.YtRpcRecordDTO; | ||
12 | +import org.thingsboard.server.dao.yunteng.entities.YtRpcRecordEntity; | ||
13 | + | ||
14 | +import java.util.List; | ||
15 | +import java.util.UUID; | ||
16 | + | ||
17 | +/** | ||
18 | + * @author Administrator | ||
19 | + */ | ||
20 | +@Mapper | ||
21 | +public interface YtRpcRecordMapper extends BaseMapper<YtRpcRecordEntity> { | ||
22 | + /** | ||
23 | + * @param page | ||
24 | + * @param tenantId | ||
25 | + * @param name | ||
26 | + * @param status | ||
27 | + * @param organizationId | ||
28 | + * @return | ||
29 | + */ | ||
30 | + IPage<YtRpcRecordDTO> getPageDatas(IPage<?> page, @Param("tenantId") String tenantId, @Param("tbDeviceId") String tbDeviceId, @Param("name") String name, @Param("status") RpcStatus status, @Param("organization") List<String> organizationId, @Param("oneway") String oneway); | ||
31 | +} |
@@ -3,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.service; | @@ -3,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.service; | ||
3 | import org.thingsboard.server.common.data.EntityType; | 3 | import org.thingsboard.server.common.data.EntityType; |
4 | import org.thingsboard.server.common.data.alarm.Alarm; | 4 | import org.thingsboard.server.common.data.alarm.Alarm; |
5 | import org.thingsboard.server.common.data.alarm.AlarmInfo; | 5 | import org.thingsboard.server.common.data.alarm.AlarmInfo; |
6 | +import org.thingsboard.server.common.data.alarm.AlarmSeverity; | ||
6 | import org.thingsboard.server.common.data.alarm.AlarmStatus; | 7 | import org.thingsboard.server.common.data.alarm.AlarmStatus; |
7 | import org.thingsboard.server.common.data.id.TenantId; | 8 | import org.thingsboard.server.common.data.id.TenantId; |
8 | import org.thingsboard.server.common.data.page.TimePageLink; | 9 | import org.thingsboard.server.common.data.page.TimePageLink; |
@@ -35,7 +36,7 @@ public interface YtAlarmInfoService { | @@ -35,7 +36,7 @@ public interface YtAlarmInfoService { | ||
35 | * @param organizationId 告警所属组织 | 36 | * @param organizationId 告警所属组织 |
36 | * @return | 37 | * @return |
37 | */ | 38 | */ |
38 | - YtPageData<YtAlarmEntity> alarmPage(Map<String, Object> pageMap, TenantId tenantId, String alarmType, Long startTime, Long endTime, List<AlarmStatus> status, String deviceId, DeviceTypeEnum deviceType, EntityType originatorType, String organizationId); | 39 | + YtPageData<YtAlarmEntity> alarmPage(Map<String, Object> pageMap, TenantId tenantId, AlarmSeverity severity,String alarmType, Long startTime, Long endTime, List<AlarmStatus> status, String deviceId, DeviceTypeEnum deviceType, EntityType originatorType, String organizationId); |
39 | 40 | ||
40 | 41 | ||
41 | /** | 42 | /** |
1 | +package org.thingsboard.server.dao.yunteng.service; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import com.fasterxml.jackson.databind.JsonNode; | ||
5 | +import org.thingsboard.server.common.data.id.DeviceId; | ||
6 | +import org.thingsboard.server.common.data.id.EntityId; | ||
7 | +import org.thingsboard.server.common.data.id.TenantId; | ||
8 | +import org.thingsboard.server.common.data.rpc.RpcStatus; | ||
9 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
10 | +import org.thingsboard.server.common.data.yunteng.dto.YtRpcRecordDTO; | ||
11 | +import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; | ||
12 | +import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; | ||
13 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
14 | +import org.thingsboard.server.dao.yunteng.entities.YtRpcRecordEntity; | ||
15 | +import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; | ||
16 | + | ||
17 | +import java.util.UUID; | ||
18 | + | ||
19 | +/** | ||
20 | + * 第三方平台用户管理相关接口 | ||
21 | + * 例如:微信小程序、钉钉等。 | ||
22 | + * @author Administrator | ||
23 | + */ | ||
24 | +public interface YtRpcRecordService extends BaseService<YtRpcRecordEntity> { | ||
25 | + | ||
26 | + /** | ||
27 | + * | ||
28 | + * RPC记录分页数据 | ||
29 | + * @param pageInfrom 分页信息 | ||
30 | + * @param tenantId 租户ID | ||
31 | + * @param oneway 响应方式:是否单向 | ||
32 | + * @param status RPC状态 | ||
33 | + * @param organizationId 组织ID | ||
34 | + * @param name 名称,例如:设备、命令、组织、租户 | ||
35 | + * @return | ||
36 | + */ | ||
37 | + YtPageData<YtRpcRecordDTO> pageDatas(IPage<YtRpcRecordEntity> pageInfrom, String tenantId, String deviceId, Boolean oneway, RpcStatus status, String organizationId, String name); | ||
38 | + | ||
39 | + | ||
40 | +} |
@@ -7,7 +7,6 @@ import org.thingsboard.server.common.data.yunteng.dto.UserDTO; | @@ -7,7 +7,6 @@ import org.thingsboard.server.common.data.yunteng.dto.UserDTO; | ||
7 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; | 7 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; |
8 | import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; | 8 | import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; |
9 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | 9 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
10 | -import org.thingsboard.server.dao.yunteng.entities.User; | ||
11 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; | 10 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; |
12 | 11 | ||
13 | /** | 12 | /** |
@@ -32,13 +31,15 @@ public interface YtThirdPlatformService extends BaseService<YtThirdUserEntity> { | @@ -32,13 +31,15 @@ public interface YtThirdPlatformService extends BaseService<YtThirdUserEntity> { | ||
32 | * @param dto | 31 | * @param dto |
33 | * @return | 32 | * @return |
34 | */ | 33 | */ |
35 | - UserDTO saveOrUpdate(YtThirdUserDTO dto); | 34 | + UserDTO bindUser(YtThirdUserDTO dto); |
36 | 35 | ||
37 | /** | 36 | /** |
38 | - * @param deleteDTO | 37 | + * 第三方平台用户与系统用户解绑 |
38 | + * @param appUserId | ||
39 | + * @param thirdUserId | ||
39 | * @return | 40 | * @return |
40 | */ | 41 | */ |
41 | - boolean deleteDataByIds(DeleteDTO deleteDTO); | 42 | + boolean unbindUser(String tenantId,String appUserId,String thirdUserId); |
42 | 43 | ||
43 | /** | 44 | /** |
44 | * 第三方登录 | 45 | * 第三方登录 |
@@ -43,6 +43,9 @@ | @@ -43,6 +43,9 @@ | ||
43 | LEFT JOIN iotfs_organization org ON org.id = d.organization_id | 43 | LEFT JOIN iotfs_organization org ON org.id = d.organization_id |
44 | <where> | 44 | <where> |
45 | m.tenant_id = #{tenantId} | 45 | m.tenant_id = #{tenantId} |
46 | + <if test="severity!=null"> | ||
47 | + AND severity = #{severity} | ||
48 | + </if> | ||
46 | <if test="alarmType!=null"> | 49 | <if test="alarmType!=null"> |
47 | AND type LIKE CONCAT('%',#{alarmType},'%') | 50 | AND type LIKE CONCAT('%',#{alarmType},'%') |
48 | </if> | 51 | </if> |
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
3 | + | ||
4 | +<mapper namespace="org.thingsboard.server.dao.yunteng.mapper.YtRpcRecordMapper"> | ||
5 | + <resultMap type="org.thingsboard.server.common.data.yunteng.dto.YtRpcRecordDTO" id="dataMap"> | ||
6 | + <result property="id" column="id"/> | ||
7 | + <result property="deviceName" column="device_name"/> | ||
8 | + <result property="tbDeviceId" column="tb_device_id"/> | ||
9 | + <result property="deviceId" column="device_id"/> | ||
10 | + <result property="deviceType" column="device_type" typeHandler="org.apache.ibatis.type.EnumTypeHandler" /> | ||
11 | + <result property="deviceSn" column="sn"/> | ||
12 | + <result property="createTime" column="create_time"/> | ||
13 | + <result property="expirationTime" column="expiration_time"/> | ||
14 | + <result property="request" column="request" | ||
15 | + typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> | ||
16 | + <result property="response" column="response" | ||
17 | + typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> | ||
18 | + <result property="additionalInfo" column="additional_info" | ||
19 | + typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> | ||
20 | + <result property="status" column="status" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> | ||
21 | + <result property="organizationId" column="organization_id"/> | ||
22 | + <result property="organizationName" column="organization_name"/> | ||
23 | + <result column="tenant_name" property="tenantName"/> | ||
24 | + <result column="tenant_id" property="tenantId"/> | ||
25 | +<!-- <association property="request" javaType="org.thingsboard.server.common.data.yunteng.dto.YtRpcRequestDTO">--> | ||
26 | +<!-- <result column="deviceId" property="deviceId" typeHandler="org.thingsboard.server.dao.yunteng.mapper.UUIDTypeHandler"/>--> | ||
27 | +<!-- <result column="oneway" property="oneway"/>--> | ||
28 | +<!-- <result column="tenant_enabled" property="retries"/>--> | ||
29 | +<!-- <result column="tenant_expire_time" property="body" />--> | ||
30 | +<!-- </association>--> | ||
31 | + </resultMap> | ||
32 | + | ||
33 | + | ||
34 | + | ||
35 | + <sql id="basicColumns"> | ||
36 | + base.id,base.created_time AS create_time,base.expiration_time,base.request,base.response,base.additional_info,base.status | ||
37 | + </sql> | ||
38 | + | ||
39 | + <sql id="detailColumns"> | ||
40 | + <include refid="basicColumns"/> | ||
41 | + ,org.id AS organization_id,org.name AS organization_name | ||
42 | + ,dev.name AS device_name,dev.tb_device_id,dev.device_type,dev.sn,dev.tenant_id,dev.id AS device_id | ||
43 | + ,ten.title AS tenant_name | ||
44 | + </sql> | ||
45 | + <select id="getPageDatas" resultMap="dataMap"> | ||
46 | + SELECT <include refid="detailColumns"/> | ||
47 | + FROM rpc base | ||
48 | + LEFT JOIN iotfs_device dev ON base.device_id =dev.tb_device_id::uuid | ||
49 | + LEFT JOIN iotfs_organization org ON dev.organization_id = org.id | ||
50 | + LEFT JOIN tenant ten ON base.tenant_id = ten.id | ||
51 | + <where> | ||
52 | + 1=1 | ||
53 | + <if test="tenantId !=null and tenantId !=''"> | ||
54 | + AND base.tenant_id = #{tenantId}::uuid | ||
55 | + </if> | ||
56 | + <if test="tbDeviceId !=null "> | ||
57 | + AND base.device_id = #{tbDeviceId}::uuid | ||
58 | + </if> | ||
59 | + <if test="name !=null and name !=''"> | ||
60 | + AND ( | ||
61 | + dev.name LIKE concat('%',#{name}::TEXT,'%') | ||
62 | + OR | ||
63 | + org.name LIKE concat('%',#{name}::TEXT,'%') | ||
64 | + OR | ||
65 | + ten.title LIKE concat('%',#{name}::TEXT,'%') | ||
66 | + OR | ||
67 | + base.request LIKE concat('%',#{name}::TEXT,'%') | ||
68 | + ) | ||
69 | + </if> | ||
70 | + <if test="oneway !=null and name !=''"> | ||
71 | + AND base.request LIKE concat('%',#{oneway}::TEXT,'%') | ||
72 | + </if> | ||
73 | + <if test="status !=null"> | ||
74 | + AND base.status = #{status} | ||
75 | + </if> | ||
76 | + <if test="organization !=null"> | ||
77 | + AND dev.organization_id IN | ||
78 | + <foreach collection="organization" item="organizationId" open="(" separator="," close=")"> | ||
79 | + #{organizationId} | ||
80 | + </foreach> | ||
81 | + </if> | ||
82 | + </where> | ||
83 | + </select> | ||
84 | + | ||
85 | + | ||
86 | + | ||
87 | + | ||
88 | + | ||
89 | + | ||
90 | +</mapper> |