refactor: convert controllers to reactive mono and remove unused spring security oauth2 dependency

This commit is contained in:
zzi666
2024-05-22 21:32:23 +08:00
parent 5a2718be12
commit b30fdfd8b2
99 changed files with 515 additions and 626 deletions
-6
View File
@@ -31,12 +31,6 @@
<dependencies>
<!--Spring Security OAuth2-->
<!--<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>-->
<!-- DC3 Api 相关 -->
<dependency>
<groupId>io.github.pnoker</groupId>
@@ -28,8 +28,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
* @since 2022.1.0
*/
@SpringBootApplication
// 开发环境无需注册中心
// @EnableDiscoveryClient
@EnableTransactionManagement
@MapperScan("io.github.pnoker.center.auth.mapper")
public class AuthApplication {
@@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import java.util.List;
@@ -55,14 +56,14 @@ public class DictionaryController implements BaseController {
* @return 字典列表
*/
@GetMapping("/tenant")
public R<List<DictionaryVO>> tenantDictionary() {
public Mono<R<List<DictionaryVO>>> tenantDictionary() {
try {
List<DictionaryBO> entityBOList = dictionaryService.tenantDictionary();
List<DictionaryVO> entityVOList = dictionaryForAuthBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVOList);
return Mono.just(R.ok(entityVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -72,14 +73,14 @@ public class DictionaryController implements BaseController {
* @return 字典列表
*/
@GetMapping("/limited_ip")
public R<List<DictionaryVO>> limitedIpDictionary() {
public Mono<R<List<DictionaryVO>>> limitedIpDictionary() {
try {
List<DictionaryBO> entityBOList = dictionaryService.limitedIpDictionary(getTenantId());
List<DictionaryVO> entityVOList = dictionaryForAuthBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVOList);
return Mono.just(R.ok(entityVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.Objects;
@@ -61,15 +62,15 @@ public class LimitedIpController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody LimitedIpVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody LimitedIpVO entityVO) {
try {
LimitedIpBO entityBO = limitedIpBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
limitedIpService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -80,13 +81,13 @@ public class LimitedIpController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
limitedIpService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -101,14 +102,14 @@ public class LimitedIpController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody LimitedIpVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody LimitedIpVO entityVO) {
try {
LimitedIpBO entityBO = limitedIpBuilder.buildBOByVO(entityVO);
limitedIpService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -119,14 +120,14 @@ public class LimitedIpController implements BaseController {
* @return LimitedIpVO {@link LimitedIpVO}
*/
@GetMapping("/id/{id}")
public R<LimitedIpVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<LimitedIpVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
LimitedIpBO entityBO = limitedIpService.selectById(id);
LimitedIpVO entityVO = limitedIpBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -137,14 +138,14 @@ public class LimitedIpController implements BaseController {
* @return {@link LimitedIpBO}
*/
@GetMapping("/ip/{ip}")
public R<LimitedIpVO> selectByIp(@NotNull @PathVariable(value = "ip") String ip) {
public Mono<R<LimitedIpVO>> selectByIp(@NotNull @PathVariable(value = "ip") String ip) {
try {
LimitedIpBO entityBO = limitedIpService.selectByIp(ip);
LimitedIpVO entityVO = limitedIpBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -155,7 +156,7 @@ public class LimitedIpController implements BaseController {
* @return 带分页的 {@link LimitedIpBO}
*/
@PostMapping("/list")
public R<Page<LimitedIpVO>> list(@RequestBody(required = false) LimitedIpQuery entityQuery) {
public Mono<R<Page<LimitedIpVO>>> list(@RequestBody(required = false) LimitedIpQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new LimitedIpQuery();
@@ -163,10 +164,10 @@ public class LimitedIpController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<LimitedIpBO> entityPageBO = limitedIpService.selectByPage(entityQuery);
Page<LimitedIpVO> entityPageVO = limitedIpBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -177,12 +178,12 @@ public class LimitedIpController implements BaseController {
* @return 当前IP是否在限制IP中
*/
@GetMapping("/check/{ip}")
public R<Boolean> checkValid(@NotNull @PathVariable(value = "ip") String ip) {
public Mono<R<Boolean>> checkValid(@NotNull @PathVariable(value = "ip") String ip) {
try {
return Boolean.TRUE.equals(limitedIpService.checkValid(ip)) ? R.ok() : R.fail();
return Boolean.TRUE.equals(limitedIpService.checkValid(ip)) ? Mono.just(R.ok()) : Mono.just(R.fail());
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.Objects;
@@ -61,14 +62,14 @@ public class TenantController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody TenantVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody TenantVO entityVO) {
try {
TenantBO entityBO = tenantBuilder.buildBOByVO(entityVO);
tenantService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -79,13 +80,13 @@ public class TenantController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
tenantService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -100,14 +101,14 @@ public class TenantController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody TenantVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody TenantVO entityVO) {
try {
TenantBO entityBO = tenantBuilder.buildBOByVO(entityVO);
tenantService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -118,14 +119,14 @@ public class TenantController implements BaseController {
* @return TenantVO {@link TenantVO}
*/
@GetMapping("/id/{id}")
public R<TenantVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<TenantVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
TenantBO entityBO = tenantService.selectById(id);
TenantVO entityVO = tenantBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -136,17 +137,17 @@ public class TenantController implements BaseController {
* @return {@link TenantBO}
*/
@GetMapping("/code/{code}")
public R<TenantBO> selectByCode(@NotNull @PathVariable(value = "code") String code) {
public Mono<R<TenantBO>> selectByCode(@NotNull @PathVariable(value = "code") String code) {
try {
TenantBO select = tenantService.selectByCode(code);
if (!Objects.isNull(select)) {
return R.ok(select);
return Mono.just(R.ok(select));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
return R.fail(ResponseEnum.NO_RESOURCE.getText());
return Mono.just(R.fail(ResponseEnum.NO_RESOURCE.getText()));
}
/**
@@ -156,17 +157,17 @@ public class TenantController implements BaseController {
* @return 带分页的 {@link TenantBO}
*/
@PostMapping("/list")
public R<Page<TenantVO>> list(@RequestBody(required = false) TenantQuery entityQuery) {
public Mono<R<Page<TenantVO>>> list(@RequestBody(required = false) TenantQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new TenantQuery();
}
Page<TenantBO> entityPageBO = tenantService.selectByPage(entityQuery);
Page<TenantVO> entityPageVO = tenantBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -29,6 +29,7 @@ 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 reactor.core.publisher.Mono;
import java.util.Objects;
@@ -56,9 +57,9 @@ public class TokenController implements BaseController {
* @return 盐值
*/
@PostMapping("/salt")
public R<String> generateSalt(@Validated @RequestBody TokenQuery entityVO) {
public Mono<R<String>> generateSalt(@Validated @RequestBody TokenQuery entityVO) {
String salt = tokenService.generateSalt(entityVO.getName(), entityVO.getTenant());
return !Objects.isNull(salt) ? R.ok(salt, "The salt will expire in 5 minutes") : R.fail();
return !Objects.isNull(salt) ? Mono.just(R.ok(salt, "The salt will expire in 5 minutes")) : Mono.just(R.fail());
}
/**
@@ -68,9 +69,9 @@ public class TokenController implements BaseController {
* @return Token 令牌
*/
@PostMapping("/generate")
public R<String> generateToken(@Validated @RequestBody TokenQuery entityVO) {
public Mono<R<String>> generateToken(@Validated @RequestBody TokenQuery entityVO) {
String token = tokenService.generateToken(entityVO.getName(), entityVO.getSalt(), entityVO.getPassword(), entityVO.getTenant());
return !Objects.isNull(token) ? R.ok(token, "The token will expire in 12 hours.") : R.fail();
return !Objects.isNull(token) ? Mono.just(R.ok(token, "The token will expire in 12 hours.")) : Mono.just(R.fail());
}
/**
@@ -80,7 +81,7 @@ public class TokenController implements BaseController {
* @return 是否有效, 并返回过期时间
*/
@PostMapping("/check")
public R<Boolean> checkValid(@Validated @RequestBody TokenQuery entityVO) {
public Mono<R<Boolean>> checkValid(@Validated @RequestBody TokenQuery entityVO) {
TokenValid tokenValid = tokenService.checkValid(entityVO.getName(), entityVO.getSalt(), entityVO.getToken(), entityVO.getTenant());
boolean valid = tokenValid.isValid();
@@ -93,7 +94,7 @@ public class TokenController implements BaseController {
message = "The token has expired in " + expireTime;
}
return R.ok(valid, message);
return Mono.just(R.ok(valid, message));
}
/**
@@ -103,7 +104,7 @@ public class TokenController implements BaseController {
* @return 是否注销成功
*/
@PostMapping("/cancel")
public R<Boolean> cancelToken(@Validated @RequestBody TokenQuery entityVO) {
return Boolean.TRUE.equals(tokenService.cancelToken(entityVO.getName(), entityVO.getTenant())) ? R.ok() : R.fail();
public Mono<R<Boolean>> cancelToken(@Validated @RequestBody TokenQuery entityVO) {
return Boolean.TRUE.equals(tokenService.cancelToken(entityVO.getName(), entityVO.getTenant())) ? Mono.just(R.ok()) : Mono.just(R.fail());
}
}
@@ -33,6 +33,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.Objects;
@@ -64,14 +65,14 @@ public class UserLoginController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody UserLoginVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody UserLoginVO entityVO) {
try {
UserLoginBO entityBO = userLoginBuilder.buildBOByVO(entityVO);
userLoginService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -82,13 +83,13 @@ public class UserLoginController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
userLoginService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -103,14 +104,14 @@ public class UserLoginController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody UserLoginVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody UserLoginVO entityVO) {
try {
UserLoginBO entityBO = userLoginBuilder.buildBOByVO(entityVO);
userLoginService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -121,13 +122,13 @@ public class UserLoginController implements BaseController {
* @return 是否重置
*/
@PostMapping("/reset/{id}")
public R<Boolean> restPassword(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<Boolean>> restPassword(@NotNull @PathVariable(value = "id") Long id) {
try {
userPasswordService.restPassword(id);
return R.ok();
return Mono.just(R.ok());
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -138,14 +139,14 @@ public class UserLoginController implements BaseController {
* @return UserLoginVO {@link UserLoginVO}
*/
@GetMapping("/id/{id}")
public R<UserLoginVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<UserLoginVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
UserLoginBO entityBO = userLoginService.selectById(id);
UserLoginVO entityVO = userLoginBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -156,14 +157,14 @@ public class UserLoginController implements BaseController {
* @return {@link UserLoginBO}
*/
@GetMapping("/name/{name}")
public R<UserLoginVO> selectByName(@NotNull @PathVariable(value = "name") String name) {
public Mono<R<UserLoginVO>> selectByName(@NotNull @PathVariable(value = "name") String name) {
try {
UserLoginBO entityBO = userLoginService.selectByLoginName(name, false);
UserLoginVO entityVO = userLoginBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -174,16 +175,16 @@ public class UserLoginController implements BaseController {
* @return 带分页的 {@link UserLoginBO}
*/
@PostMapping("/list")
public R<Page<UserLoginVO>> list(@RequestBody(required = false) UserLoginQuery entityQuery) {
public Mono<R<Page<UserLoginVO>>> list(@RequestBody(required = false) UserLoginQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new UserLoginQuery();
}
Page<UserLoginBO> entityPageBO = userLoginService.selectByPage(entityQuery);
Page<UserLoginVO> entityPageVO = userLoginBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -194,11 +195,11 @@ public class UserLoginController implements BaseController {
* @return 是否有效
*/
@GetMapping("/check/{name}")
public R<Boolean> checkLoginNameValid(@NotNull @PathVariable(value = "name") String name) {
public Mono<R<Boolean>> checkLoginNameValid(@NotNull @PathVariable(value = "name") String name) {
try {
return Boolean.TRUE.equals(userLoginService.checkLoginNameValid(name)) ? R.ok() : R.fail();
return Boolean.TRUE.equals(userLoginService.checkLoginNameValid(name)) ? Mono.just(R.ok()) : Mono.just(R.fail());
} catch (Exception e) {
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
env: dev
group: ${user.name}
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_auth}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_auth}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_auth}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -28,8 +28,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
* @since 2022.1.0
*/
@SpringBootApplication
// 开发环境无需注册中心
// @EnableDiscoveryClient
@EnableTransactionManagement
@MapperScan({"io.github.pnoker.center.data.mapper", "io.github.pnoker.common.tdengine.mapper", "io.github.pnoker.common.prometheus.dashboard.rabbitmq.mapper"})
public class DataApplication {
@@ -28,6 +28,7 @@ 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 reactor.core.publisher.Mono;
import java.util.Objects;
@@ -55,20 +56,20 @@ public class DeviceEventController implements BaseController {
* @return Page Of DeviceEvent
*/
@PostMapping("/device")
public R<Page<DeviceEvent>> deviceEvent(@RequestBody(required = false) DeviceEventQuery deviceEventQuery) {
public Mono<R<Page<DeviceEvent>>> deviceEvent(@RequestBody(required = false) DeviceEventQuery deviceEventQuery) {
try {
if (Objects.isNull(deviceEventQuery)) {
deviceEventQuery = new DeviceEventQuery();
}
Page<DeviceEvent> page = eventService.deviceEvent(deviceEventQuery);
if (!Objects.isNull(page)) {
return R.ok(page);
return Mono.just(R.ok(page));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
return R.fail();
return Mono.just(R.fail());
}
}
@@ -27,6 +27,7 @@ import io.github.pnoker.common.entity.R;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.Map;
@@ -57,14 +58,14 @@ public class DeviceStatusController implements BaseController {
* @return Map String:String
*/
@PostMapping("/device")
public R<Map<Long, String>> deviceStatus(@RequestBody(required = false) DeviceQuery deviceQuery) {
public Mono<R<Map<Long, String>>> deviceStatus(@RequestBody(required = false) DeviceQuery deviceQuery) {
try {
deviceQuery.setTenantId(getTenantId());
Map<Long, String> statuses = deviceStatusService.device(deviceQuery);
return R.ok(statuses);
return Mono.just(R.ok(statuses));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -76,15 +77,15 @@ public class DeviceStatusController implements BaseController {
* @return Map String:String
*/
@GetMapping("/device/driver_id/{driverId}")
public R<Map<Long, String>> deviceStatusByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<Map<Long, String>>> deviceStatusByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
DeviceQuery deviceQuery = new DeviceQuery();
deviceQuery.setDriverId(driverId);
Map<Long, String> statuses = deviceStatusService.device(deviceQuery);
return R.ok(statuses);
return Mono.just(R.ok(statuses));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -96,13 +97,13 @@ public class DeviceStatusController implements BaseController {
* @return Map String:String
*/
@GetMapping("/device/profile_id/{profileId}")
public R<Map<Long, String>> deviceStatusByProfileId(@NotNull @PathVariable(value = "profileId") Long profileId) {
public Mono<R<Map<Long, String>>> deviceStatusByProfileId(@NotNull @PathVariable(value = "profileId") Long profileId) {
try {
Map<Long, String> statuses = deviceStatusService.deviceByProfileId(profileId);
return R.ok(statuses);
return Mono.just(R.ok(statuses));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -113,14 +114,14 @@ public class DeviceStatusController implements BaseController {
* @return
*/
@GetMapping("/deviceOnline/{deviceId}")
public R<DeviceRunVO> selectOnlineByDriverId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
public Mono<R<DeviceRunVO>> selectOnlineByDriverId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
try {
DeviceRunBO duration = deviceStatusService.selectOnlineByDeviceId(deviceId);
DeviceRunVO result = deviceDurationBuilder.buildVOByBOList(duration);
return R.ok(result);
return Mono.just(R.ok(result));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -131,14 +132,14 @@ public class DeviceStatusController implements BaseController {
* @return
*/
@GetMapping("/deviceOffline/{deviceId}")
public R<DeviceRunVO> selectOfflineByDriverId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
public Mono<R<DeviceRunVO>> selectOfflineByDriverId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
try {
DeviceRunBO duration = deviceStatusService.selectOfflineByDeviceId(deviceId);
DeviceRunVO result = deviceDurationBuilder.buildVOByBOList(duration);
return R.ok(result);
return Mono.just(R.ok(result));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -28,6 +28,7 @@ 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 reactor.core.publisher.Mono;
import java.util.Objects;
@@ -55,20 +56,20 @@ public class DriverEventController implements BaseController {
* @return Page Of DriverEvent
*/
@PostMapping("/driver")
public R<Page<DriverEvent>> driverEvent(@RequestBody(required = false) DriverEventQuery driverEventQuery) {
public Mono<R<Page<DriverEvent>>> driverEvent(@RequestBody(required = false) DriverEventQuery driverEventQuery) {
try {
if (Objects.isNull(driverEventQuery)) {
driverEventQuery = new DriverEventQuery();
}
Page<DriverEvent> page = eventService.driverEvent(driverEventQuery);
if (!Objects.isNull(page)) {
return R.ok(page);
return Mono.just(R.ok(page));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
return R.fail();
return Mono.just(R.fail());
}
}
@@ -27,6 +27,7 @@ import io.github.pnoker.common.entity.R;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.Map;
@@ -57,14 +58,14 @@ public class DriverStatusController implements BaseController {
* @return Map String:String
*/
@PostMapping("/driver")
public R<Map<Long, String>> driverStatus(@RequestBody(required = false) DriverQuery driverQuery) {
public Mono<R<Map<Long, String>>> driverStatus(@RequestBody(required = false) DriverQuery driverQuery) {
try {
driverQuery.setTenantId(getTenantId());
Map<Long, String> statuses = driverStatusService.driver(driverQuery);
return R.ok(statuses);
return Mono.just(R.ok(statuses));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -75,14 +76,14 @@ public class DriverStatusController implements BaseController {
* @return
*/
@GetMapping("/driverOnline/{driverId}")
public R<DriverRunVO> selectOnlineByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<DriverRunVO>> selectOnlineByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
DriverRunBO duration = driverStatusService.selectOnlineByDriverId(driverId);
DriverRunVO result = driverDurationBuilder.buildVOByBOList(duration);
return R.ok(result);
return Mono.just(R.ok(result));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -93,14 +94,14 @@ public class DriverStatusController implements BaseController {
* @return
*/
@GetMapping("/driverOffline/{driverId}")
public R<DriverRunVO> selectOfflineByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<DriverRunVO>> selectOfflineByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
DriverRunBO duration = driverStatusService.selectOfflineByDriverId(driverId);
DriverRunVO result = driverDurationBuilder.buildVOByBOList(duration);
return R.ok(result);
return Mono.just(R.ok(result));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -111,13 +112,13 @@ public class DriverStatusController implements BaseController {
* @return
*/
@GetMapping("/getDeviceOnlineByDriverId/{driverId}")
public R<String> getDeviceOnlineByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<String>> getDeviceOnlineByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
String result = driverStatusService.getDeviceOnlineByDriverId(driverId);
return R.ok(result);
return Mono.just(R.ok(result));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -128,13 +129,13 @@ public class DriverStatusController implements BaseController {
* @return
*/
@GetMapping("/getDeviceOfflineByDriverId/{driverId}")
public R<String> getDeviceOfflineByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<String>> getDeviceOfflineByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
String result = driverStatusService.getDeviceOfflineByDriverId(driverId);
return R.ok(result);
return Mono.just(R.ok(result));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -28,6 +28,7 @@ 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 reactor.core.publisher.Mono;
/**
* PointValue Controller
@@ -53,14 +54,14 @@ public class PointValueCommandController implements BaseController {
* @return PointValue
*/
@PostMapping("/read")
public R<Boolean> read(@Validated @RequestBody PointValueReadVO entityVO) {
public Mono<R<Boolean>> read(@Validated @RequestBody PointValueReadVO entityVO) {
try {
pointValueCommandService.read(entityVO);
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
return R.ok();
return Mono.just(R.ok());
}
/**
@@ -70,14 +71,14 @@ public class PointValueCommandController implements BaseController {
* @return PointValue
*/
@PostMapping("/write")
public R<Boolean> write(@Validated @RequestBody PointValueWriteVO entityVO) {
public Mono<R<Boolean>> write(@Validated @RequestBody PointValueWriteVO entityVO) {
try {
pointValueCommandService.write(entityVO);
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
return R.ok();
return Mono.just(R.ok());
}
}
@@ -28,6 +28,7 @@ import io.github.pnoker.common.entity.query.PointValueQuery;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Objects;
@@ -58,7 +59,7 @@ public class PointValueController implements BaseController {
* @return 带分页的 {@link PointValueBO}
*/
@PostMapping("/latest")
public R<Page<PointValueVO>> latest(@RequestBody PointValueQuery pointValueQuery) {
public Mono<R<Page<PointValueVO>>> latest(@RequestBody PointValueQuery pointValueQuery) {
try {
if (Objects.isNull(pointValueQuery)) {
pointValueQuery = new PointValueQuery();
@@ -66,10 +67,10 @@ public class PointValueController implements BaseController {
pointValueQuery.setTenantId(getTenantId());
Page<PointValueBO> entityPageBO = pointValueService.latest(pointValueQuery);
Page<PointValueVO> entityPageVO = pointValueBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -80,17 +81,17 @@ public class PointValueController implements BaseController {
* @return 带分页的 {@link PointValueBO}
*/
@PostMapping("/list")
public R<Page<PointValueVO>> list(@RequestBody(required = false) PointValueQuery entityQuery) {
public Mono<R<Page<PointValueVO>>> list(@RequestBody(required = false) PointValueQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new PointValueQuery();
}
Page<PointValueBO> entityPageBO = pointValueService.page(entityQuery);
Page<PointValueVO> entityPageVO = pointValueBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -102,16 +103,16 @@ public class PointValueController implements BaseController {
* @return 带分页的 {@link PointValueBO}
*/
@GetMapping("/history/device_id/{deviceId}/point_id/{pointId}")
public R<List<String>> history(
public Mono<R<List<String>>> history(
@NotNull @PathVariable(name = "deviceId") Long deviceId,
@NotNull @PathVariable(name = "pointId") Long pointId,
@RequestParam(name = "count", required = false, defaultValue = "100") Integer count) {
try {
List<String> history = pointValueService.history(deviceId, pointId, count);
return R.ok(history);
return Mono.just(R.ok(history));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
env: dev
group: ${user.name}
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_data}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_data}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_data}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
env: dev
group: ${user.name}
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_data}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_data}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_data}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -28,8 +28,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
* @since 2022.1.0
*/
@SpringBootApplication
// 开发环境无需注册中心
// @EnableDiscoveryClient
@EnableTransactionManagement
@MapperScan("io.github.pnoker.center.manager.mapper")
public class ManagerApplication {
@@ -35,6 +35,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import reactor.core.publisher.Mono;
import java.nio.file.Path;
import java.util.List;
@@ -68,15 +69,15 @@ public class DeviceController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody DeviceVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody DeviceVO entityVO) {
try {
DeviceBO entityBO = deviceBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
deviceService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -87,13 +88,13 @@ public class DeviceController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
deviceService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -104,14 +105,14 @@ public class DeviceController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody DeviceVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody DeviceVO entityVO) {
try {
DeviceBO entityBO = deviceBuilder.buildBOByVO(entityVO);
deviceService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -122,14 +123,14 @@ public class DeviceController implements BaseController {
* @return DeviceVO {@link DeviceVO}
*/
@GetMapping("/id/{id}")
public R<DeviceVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<DeviceVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
DeviceBO entityBO = deviceService.selectById(id);
DeviceVO entityVO = deviceBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -140,14 +141,14 @@ public class DeviceController implements BaseController {
* @return Map(ID, DeviceVO)
*/
@PostMapping("/ids")
public R<Map<Long, DeviceVO>> selectByIds(@RequestBody List<Long> deviceIds) {
public Mono<R<Map<Long, DeviceVO>>> selectByIds(@RequestBody List<Long> deviceIds) {
try {
List<DeviceBO> entityBOList = deviceService.selectByIds(deviceIds);
Map<Long, DeviceVO> deviceMap = entityBOList.stream().collect(Collectors.toMap(DeviceBO::getId, entityBO -> deviceBuilder.buildVOByBO(entityBO)));
return R.ok(deviceMap);
return Mono.just(R.ok(deviceMap));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -158,7 +159,7 @@ public class DeviceController implements BaseController {
* @return R Of DeviceVO Page
*/
@PostMapping("/list")
public R<Page<DeviceVO>> list(@RequestBody(required = false) DeviceQuery entityQuery) {
public Mono<R<Page<DeviceVO>>> list(@RequestBody(required = false) DeviceQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DeviceQuery();
@@ -166,10 +167,10 @@ public class DeviceController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DeviceBO> entityPageBO = deviceService.selectByPage(entityQuery);
Page<DeviceVO> entityPageVO = deviceBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -180,15 +181,15 @@ public class DeviceController implements BaseController {
* @return R of String
*/
@PostMapping("/import")
public R<String> importDevice(@Validated(Update.class) DeviceVO entityVO, @RequestParam("file") MultipartFile multipartFile) {
public Mono<R<String>> importDevice(@Validated(Update.class) DeviceVO entityVO, @RequestParam("file") MultipartFile multipartFile) {
try {
DeviceBO entityBO = deviceBuilder.buildBOByVO(entityVO);
deviceService.importDevice(entityBO, multipartFile);
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
return R.ok();
return Mono.just(R.ok());
}
/**
@@ -215,13 +216,13 @@ public class DeviceController implements BaseController {
* @return
*/
@GetMapping("/getDeviceByDriverId/{driverId}")
public R<String> getDeviceByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<String>> getDeviceByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
List<DeviceBO> deviceBOList = deviceService.selectByDriverId(driverId);
return R.ok(String.valueOf(deviceBOList.size()));
return Mono.just(R.ok(String.valueOf(deviceBOList.size())));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -32,6 +32,7 @@ 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 reactor.core.publisher.Mono;
import java.util.Objects;
@@ -61,7 +62,7 @@ public class DictionaryController implements BaseController {
* @return R Of DictionaryVO Page
*/
@PostMapping("/driver")
public R<Page<DictionaryVO>> driverDictionary(@RequestBody(required = false) DictionaryQuery entityQuery) {
public Mono<R<Page<DictionaryVO>>> driverDictionary(@RequestBody(required = false) DictionaryQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DictionaryQuery();
@@ -69,10 +70,10 @@ public class DictionaryController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DictionaryBO> entityPageBO = dictionaryService.driverDictionary(entityQuery);
Page<DictionaryVO> entityPageVO = dictionaryForManagerBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -83,7 +84,7 @@ public class DictionaryController implements BaseController {
* @return R Of DictionaryVO Page
*/
@PostMapping("/profile")
public R<Page<DictionaryVO>> profileDictionary(@RequestBody(required = false) DictionaryQuery entityQuery) {
public Mono<R<Page<DictionaryVO>>> profileDictionary(@RequestBody(required = false) DictionaryQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DictionaryQuery();
@@ -91,10 +92,10 @@ public class DictionaryController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DictionaryBO> entityPageBO = dictionaryService.profileDictionary(entityQuery);
Page<DictionaryVO> entityPageVO = dictionaryForManagerBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -105,7 +106,7 @@ public class DictionaryController implements BaseController {
* @return R Of DictionaryVO Page
*/
@PostMapping("/profile_point")
public R<Page<DictionaryVO>> pointDictionaryForProfile(@Validated(Parent.class) @RequestBody(required = false) DictionaryQuery entityQuery) {
public Mono<R<Page<DictionaryVO>>> pointDictionaryForProfile(@Validated(Parent.class) @RequestBody(required = false) DictionaryQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DictionaryQuery();
@@ -113,10 +114,10 @@ public class DictionaryController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DictionaryBO> entityPageBO = dictionaryService.pointDictionaryForProfile(entityQuery);
Page<DictionaryVO> entityPageVO = dictionaryForManagerBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -127,7 +128,7 @@ public class DictionaryController implements BaseController {
* @return R Of DictionaryVO Page
*/
@PostMapping("/device_point")
public R<Page<DictionaryVO>> pointDictionaryForDevice(@Validated(Parent.class) @RequestBody(required = false) DictionaryQuery entityQuery) {
public Mono<R<Page<DictionaryVO>>> pointDictionaryForDevice(@Validated(Parent.class) @RequestBody(required = false) DictionaryQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DictionaryQuery();
@@ -135,10 +136,10 @@ public class DictionaryController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DictionaryBO> entityPageBO = dictionaryService.pointDictionaryForDevice(entityQuery);
Page<DictionaryVO> entityPageVO = dictionaryForManagerBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -149,7 +150,7 @@ public class DictionaryController implements BaseController {
* @return R Of DictionaryVO Page
*/
@PostMapping("/device")
public R<Page<DictionaryVO>> deviceDictionary(@RequestBody(required = false) DictionaryQuery entityQuery) {
public Mono<R<Page<DictionaryVO>>> deviceDictionary(@RequestBody(required = false) DictionaryQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DictionaryQuery();
@@ -157,10 +158,10 @@ public class DictionaryController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DictionaryBO> entityPageBO = dictionaryService.deviceDictionary(entityQuery);
Page<DictionaryVO> entityPageVO = dictionaryForManagerBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -171,7 +172,7 @@ public class DictionaryController implements BaseController {
* @return R Of DictionaryVO Page
*/
@PostMapping("/driver_device")
public R<Page<DictionaryVO>> deviceDictionaryForDriver(@Validated(Parent.class) @RequestBody(required = false) DictionaryQuery entityQuery) {
public Mono<R<Page<DictionaryVO>>> deviceDictionaryForDriver(@Validated(Parent.class) @RequestBody(required = false) DictionaryQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DictionaryQuery();
@@ -179,9 +180,9 @@ public class DictionaryController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DictionaryBO> entityPageBO = dictionaryService.deviceDictionaryForDriver(entityQuery);
Page<DictionaryVO> entityPageVO = dictionaryForManagerBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
}
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Objects;
@@ -62,15 +63,15 @@ public class DriverAttributeConfigController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody DriverAttributeConfigVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody DriverAttributeConfigVO entityVO) {
try {
DriverAttributeConfigBO entityBO = driverAttributeConfigBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
driverAttributeConfigService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -81,13 +82,13 @@ public class DriverAttributeConfigController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
driverAttributeConfigService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -98,14 +99,14 @@ public class DriverAttributeConfigController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody DriverAttributeConfigVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody DriverAttributeConfigVO entityVO) {
try {
DriverAttributeConfigBO entityBO = driverAttributeConfigBuilder.buildBOByVO(entityVO);
driverAttributeConfigService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -116,14 +117,14 @@ public class DriverAttributeConfigController implements BaseController {
* @return DriverAttributeConfigVO {@link DriverAttributeConfigVO}
*/
@GetMapping("/id/{id}")
public R<DriverAttributeConfigVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<DriverAttributeConfigVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
DriverAttributeConfigBO entityBO = driverAttributeConfigService.selectById(id);
DriverAttributeConfigVO entityVO = driverAttributeConfigBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -135,15 +136,15 @@ public class DriverAttributeConfigController implements BaseController {
* @return DriverConfig
*/
@GetMapping("/device_id/{deviceId}/attribute_id/{attributeId}")
public R<DriverAttributeConfigVO> selectByDeviceIdAndAttributeId(@NotNull @PathVariable(value = "deviceId") Long deviceId,
@NotNull @PathVariable(value = "attributeId") Long attributeId) {
public Mono<R<DriverAttributeConfigVO>> selectByDeviceIdAndAttributeId(@NotNull @PathVariable(value = "deviceId") Long deviceId,
@NotNull @PathVariable(value = "attributeId") Long attributeId) {
try {
DriverAttributeConfigBO entityBO = driverAttributeConfigService.selectByAttributeIdAndDeviceId(deviceId, attributeId);
DriverAttributeConfigVO entityVO = driverAttributeConfigBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -154,14 +155,14 @@ public class DriverAttributeConfigController implements BaseController {
* @return DriverConfig 集合
*/
@GetMapping("/device_id/{deviceId}")
public R<List<DriverAttributeConfigVO>> selectByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
public Mono<R<List<DriverAttributeConfigVO>>> selectByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
try {
List<DriverAttributeConfigBO> entityBOList = driverAttributeConfigService.selectByDeviceId(deviceId);
List<DriverAttributeConfigVO> entityVOList = driverAttributeConfigBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVOList);
return Mono.just(R.ok(entityVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -172,7 +173,7 @@ public class DriverAttributeConfigController implements BaseController {
* @return Page Of DriverConfig
*/
@PostMapping("/list")
public R<Page<DriverAttributeConfigVO>> list(@RequestBody(required = false) DriverAttributeConfigQuery entityQuery) {
public Mono<R<Page<DriverAttributeConfigVO>>> list(@RequestBody(required = false) DriverAttributeConfigQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DriverAttributeConfigQuery();
@@ -180,10 +181,10 @@ public class DriverAttributeConfigController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DriverAttributeConfigBO> entityPageBO = driverAttributeConfigService.selectByPage(entityQuery);
Page<DriverAttributeConfigVO> entityPageVO = driverAttributeConfigBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -33,8 +33,9 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -64,15 +65,15 @@ public class DriverAttributeController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody DriverAttributeVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody DriverAttributeVO entityVO) {
try {
DriverAttributeBO entityBO = driverAttributeBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
driverAttributeService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -83,13 +84,13 @@ public class DriverAttributeController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
driverAttributeService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -100,14 +101,14 @@ public class DriverAttributeController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody DriverAttributeVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody DriverAttributeVO entityVO) {
try {
DriverAttributeBO entityBO = driverAttributeBuilder.buildBOByVO(entityVO);
driverAttributeService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -118,14 +119,14 @@ public class DriverAttributeController implements BaseController {
* @return DriverAttributeVO {@link DriverAttributeVO}
*/
@GetMapping("/id/{id}")
public R<DriverAttributeVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<DriverAttributeVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
DriverAttributeBO entityBO = driverAttributeService.selectById(id);
DriverAttributeVO entityVO = driverAttributeBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -136,16 +137,16 @@ public class DriverAttributeController implements BaseController {
* @return DriverAttribute
*/
@GetMapping("/driver_id/{id}")
public R<List<DriverAttributeVO>> selectByDriverId(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<List<DriverAttributeVO>>> selectByDriverId(@NotNull @PathVariable(value = "id") Long id) {
try {
List<DriverAttributeBO> entityBOList = driverAttributeService.selectByDriverId(id);
List<DriverAttributeVO> entityVO = driverAttributeBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (NotFoundException ne) {
return R.ok(new ArrayList<>());
return Mono.just(R.ok(Collections.emptyList()));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -156,7 +157,7 @@ public class DriverAttributeController implements BaseController {
* @return Page Of DriverAttribute
*/
@PostMapping("/list")
public R<Page<DriverAttributeVO>> list(@RequestBody(required = false) DriverAttributeQuery entityQuery) {
public Mono<R<Page<DriverAttributeVO>>> list(@RequestBody(required = false) DriverAttributeQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DriverAttributeQuery();
@@ -164,10 +165,10 @@ public class DriverAttributeController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DriverAttributeBO> entityPageBO = driverAttributeService.selectByPage(entityQuery);
Page<DriverAttributeVO> entityPageVO = driverAttributeBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Map;
@@ -65,15 +66,15 @@ public class DriverController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody DriverVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody DriverVO entityVO) {
try {
DriverBO entityBO = driverBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
driverService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -84,13 +85,13 @@ public class DriverController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
driverService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -101,14 +102,14 @@ public class DriverController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody DriverVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody DriverVO entityVO) {
try {
DriverBO entityBO = driverBuilder.buildBOByVO(entityVO);
driverService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -119,14 +120,14 @@ public class DriverController implements BaseController {
* @return DriverVO {@link DriverVO}
*/
@GetMapping("/id/{id}")
public R<DriverVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<DriverVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
DriverBO entityBO = driverService.selectById(id);
DriverVO entityVO = driverBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -137,14 +138,14 @@ public class DriverController implements BaseController {
* @return Map(ID, DriverVO)
*/
@PostMapping("/ids")
public R<Map<Long, DriverVO>> selectByIds(@RequestBody Set<Long> driverIds) {
public Mono<R<Map<Long, DriverVO>>> selectByIds(@RequestBody Set<Long> driverIds) {
try {
List<DriverBO> entityBOList = driverService.selectByIds(driverIds);
Map<Long, DriverVO> driverMap = entityBOList.stream().collect(Collectors.toMap(DriverBO::getId, entityBO -> driverBuilder.buildVOByBO(entityBO)));
return R.ok(driverMap);
return Mono.just(R.ok(driverMap));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -155,14 +156,14 @@ public class DriverController implements BaseController {
* @return Driver
*/
@GetMapping("/service/{serviceName}")
public R<DriverVO> selectByServiceName(@NotNull @PathVariable(value = "serviceName") String serviceName) {
public Mono<R<DriverVO>> selectByServiceName(@NotNull @PathVariable(value = "serviceName") String serviceName) {
try {
DriverBO entityBO = driverService.selectByServiceName(serviceName, getTenantId());
DriverVO entityVO = driverBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -173,7 +174,7 @@ public class DriverController implements BaseController {
* @return Page Of Driver
*/
@PostMapping("/list")
public R<Page<DriverVO>> list(@RequestBody(required = false) DriverQuery entityQuery) {
public Mono<R<Page<DriverVO>>> list(@RequestBody(required = false) DriverQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new DriverQuery();
@@ -181,10 +182,10 @@ public class DriverController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<DriverBO> entityPageBO = driverService.selectByPage(entityQuery);
Page<DriverVO> entityPageVO = driverBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.Objects;
@@ -61,15 +62,15 @@ public class GroupController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody GroupVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody GroupVO entityVO) {
try {
GroupBO entityBO = groupForManagerBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
groupService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -80,13 +81,13 @@ public class GroupController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
groupService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -97,14 +98,14 @@ public class GroupController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody GroupVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody GroupVO entityVO) {
try {
GroupBO entityBO = groupForManagerBuilder.buildBOByVO(entityVO);
groupService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -115,14 +116,14 @@ public class GroupController implements BaseController {
* @return GroupVO {@link GroupVO}
*/
@GetMapping("/id/{id}")
public R<GroupVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<GroupVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
GroupBO entityBO = groupService.selectById(id);
GroupVO entityVO = groupForManagerBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -133,7 +134,7 @@ public class GroupController implements BaseController {
* @return R Of GroupVO Page
*/
@PostMapping("/list")
public R<Page<GroupVO>> list(@RequestBody(required = false) GroupQuery entityQuery) {
public Mono<R<Page<GroupVO>>> list(@RequestBody(required = false) GroupQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new GroupQuery();
@@ -141,10 +142,10 @@ public class GroupController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<GroupBO> entityPageBO = groupService.selectByPage(entityQuery);
Page<GroupVO> entityPageVO = groupForManagerBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.Objects;
@@ -61,15 +62,15 @@ public class LabelController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody LabelVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody LabelVO entityVO) {
try {
LabelBO entityBO = labelForManagerBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
labelService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -80,13 +81,13 @@ public class LabelController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
labelService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -97,14 +98,14 @@ public class LabelController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody LabelVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody LabelVO entityVO) {
try {
LabelBO entityBO = labelForManagerBuilder.buildBOByVO(entityVO);
labelService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -115,14 +116,14 @@ public class LabelController implements BaseController {
* @return LabelVO {@link LabelVO}
*/
@GetMapping("/id/{id}")
public R<LabelVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<LabelVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
LabelBO entityBO = labelService.selectById(id);
LabelVO entityVO = labelForManagerBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -133,7 +134,7 @@ public class LabelController implements BaseController {
* @return R Of LabelVO Page
*/
@PostMapping("/list")
public R<Page<LabelVO>> list(@RequestBody(required = false) LabelQuery entityQuery) {
public Mono<R<Page<LabelVO>>> list(@RequestBody(required = false) LabelQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new LabelQuery();
@@ -141,10 +142,10 @@ public class LabelController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<LabelBO> entityPageBO = labelService.selectByPage(entityQuery);
Page<LabelVO> entityPageVO = labelForManagerBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
}
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Objects;
@@ -62,15 +63,15 @@ public class PointAttributeConfigController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody PointAttributeConfigVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody PointAttributeConfigVO entityVO) {
try {
PointAttributeConfigBO entityBO = pointAttributeConfigBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
pointAttributeConfigService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -81,13 +82,13 @@ public class PointAttributeConfigController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
pointAttributeConfigService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -98,14 +99,14 @@ public class PointAttributeConfigController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody PointAttributeConfigVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody PointAttributeConfigVO entityVO) {
try {
PointAttributeConfigBO entityBO = pointAttributeConfigBuilder.buildBOByVO(entityVO);
pointAttributeConfigService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -116,14 +117,14 @@ public class PointAttributeConfigController implements BaseController {
* @return PointAttributeConfigVO {@link PointAttributeConfigVO}
*/
@GetMapping("/id/{id}")
public R<PointAttributeConfigVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<PointAttributeConfigVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
PointAttributeConfigBO entityBO = pointAttributeConfigService.selectById(id);
PointAttributeConfigVO entityVO = pointAttributeConfigBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -136,16 +137,16 @@ public class PointAttributeConfigController implements BaseController {
* @return PointConfig
*/
@GetMapping("/attribute_id/{attributeId}/device_id/{deviceId}/point_id/{pointId}")
public R<PointAttributeConfigVO> selectByAttributeIdAndDeviceIdAndPointId(@NotNull @PathVariable(value = "attributeId") Long attributeId,
@NotNull @PathVariable(value = "deviceId") Long deviceId,
@NotNull @PathVariable(value = "pointId") Long pointId) {
public Mono<R<PointAttributeConfigVO>> selectByAttributeIdAndDeviceIdAndPointId(@NotNull @PathVariable(value = "attributeId") Long attributeId,
@NotNull @PathVariable(value = "deviceId") Long deviceId,
@NotNull @PathVariable(value = "pointId") Long pointId) {
try {
PointAttributeConfigBO entityBO = pointAttributeConfigService.selectByAttributeIdAndDeviceIdAndPointId(attributeId, deviceId, pointId);
PointAttributeConfigVO entityVO = pointAttributeConfigBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -157,15 +158,15 @@ public class PointAttributeConfigController implements BaseController {
* @return PointConfig
*/
@GetMapping("/device_id/{deviceId}/point_id/{pointId}")
public R<List<PointAttributeConfigVO>> selectByDeviceIdAndPointId(@NotNull @PathVariable(value = "deviceId") Long deviceId,
@NotNull @PathVariable(value = "pointId") Long pointId) {
public Mono<R<List<PointAttributeConfigVO>>> selectByDeviceIdAndPointId(@NotNull @PathVariable(value = "deviceId") Long deviceId,
@NotNull @PathVariable(value = "pointId") Long pointId) {
try {
List<PointAttributeConfigBO> entityBOList = pointAttributeConfigService.selectByDeviceIdAndPointId(deviceId, pointId);
List<PointAttributeConfigVO> entityVOList = pointAttributeConfigBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVOList);
return Mono.just(R.ok(entityVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -176,13 +177,13 @@ public class PointAttributeConfigController implements BaseController {
* @return PointConfig
*/
@GetMapping("/device_id/{deviceId}")
public R<List<PointAttributeConfigVO>> selectByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
public Mono<R<List<PointAttributeConfigVO>>> selectByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
try {
List<PointAttributeConfigBO> entityBOList = pointAttributeConfigService.selectByDeviceId(deviceId);
List<PointAttributeConfigVO> entityVOList = pointAttributeConfigBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVOList);
return Mono.just(R.ok(entityVOList));
} catch (Exception e) {
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -193,7 +194,7 @@ public class PointAttributeConfigController implements BaseController {
* @return Page Of PointConfig
*/
@PostMapping("/list")
public R<Page<PointAttributeConfigVO>> list(@RequestBody(required = false) PointAttributeConfigQuery entityQuery) {
public Mono<R<Page<PointAttributeConfigVO>>> list(@RequestBody(required = false) PointAttributeConfigQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new PointAttributeConfigQuery();
@@ -201,9 +202,9 @@ public class PointAttributeConfigController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<PointAttributeConfigBO> entityPageBO = pointAttributeConfigService.selectByPage(entityQuery);
Page<PointAttributeConfigVO> entityPageVO = pointAttributeConfigBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -33,8 +33,9 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -64,15 +65,15 @@ public class PointAttributeController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<PointAttributeBO> add(@Validated(Add.class) @RequestBody PointAttributeVO entityVO) {
public Mono<R<PointAttributeBO>> add(@Validated(Add.class) @RequestBody PointAttributeVO entityVO) {
try {
PointAttributeBO entityBO = pointAttributeBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
pointAttributeService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -83,13 +84,13 @@ public class PointAttributeController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
pointAttributeService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -100,14 +101,14 @@ public class PointAttributeController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody PointAttributeVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody PointAttributeVO entityVO) {
try {
PointAttributeBO entityBO = pointAttributeBuilder.buildBOByVO(entityVO);
pointAttributeService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -118,14 +119,14 @@ public class PointAttributeController implements BaseController {
* @return PointAttributeVO {@link PointAttributeVO}
*/
@GetMapping("/id/{id}")
public R<PointAttributeVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<PointAttributeVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
PointAttributeBO entityBO = pointAttributeService.selectById(id);
PointAttributeVO entityVO = pointAttributeBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -136,16 +137,16 @@ public class PointAttributeController implements BaseController {
* @return 位号属性Array
*/
@GetMapping("/driver_id/{id}")
public R<List<PointAttributeVO>> selectByDriverId(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<List<PointAttributeVO>>> selectByDriverId(@NotNull @PathVariable(value = "id") Long id) {
try {
List<PointAttributeBO> entityBOList = pointAttributeService.selectByDriverId(id);
List<PointAttributeVO> entityVO = pointAttributeBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (NotFoundException ne) {
return R.ok(new ArrayList<>());
return Mono.just(R.ok(Collections.emptyList()));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -156,7 +157,7 @@ public class PointAttributeController implements BaseController {
* @return Page Of PointAttribute
*/
@PostMapping("/list")
public R<Page<PointAttributeVO>> list(@RequestBody(required = false) PointAttributeQuery entityQuery) {
public Mono<R<Page<PointAttributeVO>>> list(@RequestBody(required = false) PointAttributeQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new PointAttributeQuery();
@@ -164,10 +165,10 @@ public class PointAttributeController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<PointAttributeBO> entityPageBO = pointAttributeService.selectByPage(entityQuery);
Page<PointAttributeVO> entityPageVO = pointAttributeBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -34,6 +34,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Map;
@@ -69,15 +70,15 @@ public class PointController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<PointBO> add(@Validated(Add.class) @RequestBody PointVO entityVO) {
public Mono<R<PointBO>> add(@Validated(Add.class) @RequestBody PointVO entityVO) {
try {
PointBO entityBO = pointBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
pointService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -88,13 +89,13 @@ public class PointController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
pointService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -105,14 +106,14 @@ public class PointController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody PointVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody PointVO entityVO) {
try {
PointBO entityBO = pointBuilder.buildBOByVO(entityVO);
pointService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -123,14 +124,14 @@ public class PointController implements BaseController {
* @return PointVO {@link PointVO}
*/
@GetMapping("/id/{id}")
public R<PointVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<PointVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
PointBO entityBO = pointService.selectById(id);
PointVO entityVO = pointBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -141,14 +142,14 @@ public class PointController implements BaseController {
* @return Map(ID, PointVO)
*/
@PostMapping("/ids")
public R<Map<Long, PointVO>> selectByIds(@RequestBody Set<Long> pointIds) {
public Mono<R<Map<Long, PointVO>>> selectByIds(@RequestBody Set<Long> pointIds) {
try {
List<PointBO> entityBOList = pointService.selectByIds(pointIds);
Map<Long, PointVO> deviceMap = entityBOList.stream().collect(Collectors.toMap(PointBO::getId, entityBO -> pointBuilder.buildVOByBO(entityBO)));
return R.ok(deviceMap);
return Mono.just(R.ok(deviceMap));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -159,14 +160,14 @@ public class PointController implements BaseController {
* @return Point 集合
*/
@GetMapping("/profile_id/{profileId}")
public R<List<PointVO>> selectByProfileId(@NotNull @PathVariable(value = "profileId") Long profileId) {
public Mono<R<List<PointVO>>> selectByProfileId(@NotNull @PathVariable(value = "profileId") Long profileId) {
try {
List<PointBO> entityBOList = pointService.selectByProfileId(profileId);
List<PointVO> entityVOList = pointBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVOList);
return Mono.just(R.ok(entityVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -177,14 +178,14 @@ public class PointController implements BaseController {
* @return Point Array
*/
@GetMapping("/device_id/{deviceId}")
public R<List<PointVO>> selectByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
public Mono<R<List<PointVO>>> selectByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
try {
List<PointBO> entityBOList = pointService.selectByDeviceId(deviceId);
List<PointVO> entityVOList = pointBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVOList);
return Mono.just(R.ok(entityVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -195,7 +196,7 @@ public class PointController implements BaseController {
* @return Page Of Point
*/
@PostMapping("/list")
public R<Page<PointVO>> list(@RequestBody(required = false) PointQuery entityQuery) {
public Mono<R<Page<PointVO>>> list(@RequestBody(required = false) PointQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new PointQuery();
@@ -203,10 +204,10 @@ public class PointController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<PointBO> entityPageBO = pointService.selectByPage(entityQuery);
Page<PointVO> entityPageVO = pointBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -217,18 +218,18 @@ public class PointController implements BaseController {
* @return Map String:String
*/
@PostMapping("/unit")
public R<Map<Long, String>> unit(@RequestBody Set<Long> pointIds) {
public Mono<R<Map<Long, String>>> unit(@RequestBody Set<Long> pointIds) {
try {
Map<Long, String> units = pointService.unit(pointIds);
if (!Objects.isNull(units)) {
Map<Long, String> unitCodeMap = units.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return R.ok(unitCodeMap);
return Mono.just(R.ok(unitCodeMap));
}
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
return R.fail();
return Mono.just(R.fail());
}
@@ -240,14 +241,14 @@ public class PointController implements BaseController {
* @return {@link R}<{@link Set}<{@link Long}>>
*/
@GetMapping("/selectPointStatisticsWithDevice/{pointId}")
public R<DeviceByPointVO> selectPointStatisticsWithDevice(@NotNull @PathVariable(value = "pointId") Long pointId) {
public Mono<R<DeviceByPointVO>> selectPointStatisticsWithDevice(@NotNull @PathVariable(value = "pointId") Long pointId) {
try {
DeviceByPointBO deviceByPointBO = pointService.selectPointStatisticsWithDevice(pointId);
DeviceByPointVO deviceByPointVO = deviceBuilder.buildVOPointByBO(deviceByPointBO);
return R.ok(deviceByPointVO);
return Mono.just(R.ok(deviceByPointVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -261,14 +262,14 @@ public class PointController implements BaseController {
* @return {@link R}<{@link Map}<{@link Long}, {@link String}>>
*/
@PostMapping("/selectPointStatisticsByDeviceId/{pointId}")
public R<List<PointDataVolumeRunVO>> selectPointStatisticsByDeviceId(@NotNull @PathVariable(value = "pointId") Long pointId, @NotNull @RequestBody Set<Long> deviceIds) {
public Mono<R<List<PointDataVolumeRunVO>>> selectPointStatisticsByDeviceId(@NotNull @PathVariable(value = "pointId") Long pointId, @NotNull @RequestBody Set<Long> deviceIds) {
try {
List<PointDataVolumeRunBO> list = pointService.selectPointStatisticsByDeviceId(pointId, deviceIds);
List<PointDataVolumeRunVO> pointDataVolumeRunVO = pointBuilder.buildVOPointDataByBO(list);
return R.ok(pointDataVolumeRunVO);
return Mono.just(R.ok(pointDataVolumeRunVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -280,13 +281,13 @@ public class PointController implements BaseController {
* @return {@link R}<{@link Map}<{@link Long}, {@link String}>>
*/
@GetMapping("/selectPointStatisticsByPointId/{pointId}")
public R<Long> selectPointStatisticsByPointId(@NotNull @PathVariable(value = "pointId") Long pointId) {
public Mono<R<Long>> selectPointStatisticsByPointId(@NotNull @PathVariable(value = "pointId") Long pointId) {
try {
PointDataVolumeRunDO pointDataVolumeRunDO = pointService.selectPointStatisticsByPointId(pointId);
return R.ok(Objects.isNull(pointDataVolumeRunDO.getTotal()) ? 0 : pointDataVolumeRunDO.getTotal());
return Mono.just(R.ok(Objects.isNull(pointDataVolumeRunDO.getTotal()) ? 0 : pointDataVolumeRunDO.getTotal()));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -297,13 +298,13 @@ public class PointController implements BaseController {
* @return
*/
@GetMapping("/selectPointByDeviceId/{deviceId}")
public R<Long> selectPointByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
public Mono<R<Long>> selectPointByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
try {
Long count = pointService.selectPointByDeviceId(deviceId);
return R.ok(count);
return Mono.just(R.ok(count));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -314,14 +315,14 @@ public class PointController implements BaseController {
* @return
*/
@GetMapping("/selectPointConfigByDeviceId/{deviceId}")
public R<PointConfigByDeviceVO> selectPointConfigByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
public Mono<R<PointConfigByDeviceVO>> selectPointConfigByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
try {
PointConfigByDeviceBO pointConfigByDeviceBO = pointService.selectPointConfigByDeviceId(deviceId);
PointConfigByDeviceVO pointConfigByDeviceVO = pointBuilder.buildVODeviceByBO(pointConfigByDeviceBO);
return R.ok(pointConfigByDeviceVO);
return Mono.just(R.ok(pointConfigByDeviceVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -334,14 +335,14 @@ public class PointController implements BaseController {
* @return
*/
@PostMapping("/selectDeviceStatisticsByPointId/{deviceId}")
public R<List<DeviceDataVolumeRunVO>> selectDeviceStatisticsByPointId(@NotNull @PathVariable(value = "deviceId") Long deviceId, @NotNull @RequestBody Set<Long> pointIds) {
public Mono<R<List<DeviceDataVolumeRunVO>>> selectDeviceStatisticsByPointId(@NotNull @PathVariable(value = "deviceId") Long deviceId, @NotNull @RequestBody Set<Long> pointIds) {
try {
List<DeviceDataVolumeRunBO> list = pointService.selectDeviceStatisticsByPointId(deviceId, pointIds);
List<DeviceDataVolumeRunVO> deviceDataVolumeRunVOList = pointBuilder.buildVODeviceDataByBO(list);
return R.ok(deviceDataVolumeRunVOList);
return Mono.just(R.ok(deviceDataVolumeRunVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -352,13 +353,13 @@ public class PointController implements BaseController {
* @return
*/
@GetMapping("/selectPointDataByDriverId/{driverId}")
public R<Long> selectPointDataByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<Long>> selectPointDataByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
PointDataVolumeRunDO pointDataVolumeRunDO = pointService.selectPointDataByDriverId(driverId);
return R.ok(Objects.isNull(pointDataVolumeRunDO.getTotal()) ? 0 : pointDataVolumeRunDO.getTotal());
return Mono.just(R.ok(Objects.isNull(pointDataVolumeRunDO.getTotal()) ? 0 : pointDataVolumeRunDO.getTotal()));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -369,25 +370,25 @@ public class PointController implements BaseController {
* @return
*/
@GetMapping("/selectPointByDriverId/{driverId}")
public R<Long> selectPointByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<Long>> selectPointByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
Long result = pointService.selectPointByDriverId(driverId);
return R.ok(result);
return Mono.just(R.ok(result));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@GetMapping("/selectPointDataStatisticsByDriverId/{driverId}")
public R<PointDataStatisticsByDriverIdVO> selectPointDataStatisticsByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
public Mono<R<PointDataStatisticsByDriverIdVO>> selectPointDataStatisticsByDriverId(@NotNull @PathVariable(value = "driverId") Long driverId) {
try {
PointDataStatisticsByDriverIdBO pointDataStatisticsByDriverIdBOList = pointService.selectPointDataStatisticsByDriverId(driverId);
PointDataStatisticsByDriverIdVO pointDataStatisticsByDriverIdVOList = pointBuilder.buildVOPointDataDriverByBO(pointDataStatisticsByDriverIdBOList);
return R.ok(pointDataStatisticsByDriverIdVOList);
return Mono.just(R.ok(pointDataStatisticsByDriverIdVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -32,6 +32,7 @@ import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Map;
@@ -65,15 +66,15 @@ public class ProfileController implements BaseController {
* @return R of String
*/
@PostMapping("/add")
public R<String> add(@Validated(Add.class) @RequestBody ProfileVO entityVO) {
public Mono<R<String>> add(@Validated(Add.class) @RequestBody ProfileVO entityVO) {
try {
ProfileBO entityBO = profileBuilder.buildBOByVO(entityVO);
entityBO.setTenantId(getTenantId());
profileService.save(entityBO);
return R.ok(ResponseEnum.ADD_SUCCESS);
return Mono.just(R.ok(ResponseEnum.ADD_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -84,13 +85,13 @@ public class ProfileController implements BaseController {
* @return R of String
*/
@PostMapping("/delete/{id}")
public R<String> delete(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<String>> delete(@NotNull @PathVariable(value = "id") Long id) {
try {
profileService.remove(id);
return R.ok(ResponseEnum.DELETE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.DELETE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -101,14 +102,14 @@ public class ProfileController implements BaseController {
* @return R of String
*/
@PostMapping("/update")
public R<String> update(@Validated(Update.class) @RequestBody ProfileVO entityVO) {
public Mono<R<String>> update(@Validated(Update.class) @RequestBody ProfileVO entityVO) {
try {
ProfileBO entityBO = profileBuilder.buildBOByVO(entityVO);
profileService.update(entityBO);
return R.ok(ResponseEnum.UPDATE_SUCCESS);
return Mono.just(R.ok(ResponseEnum.UPDATE_SUCCESS));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -119,14 +120,14 @@ public class ProfileController implements BaseController {
* @return ProfileVO {@link ProfileVO}
*/
@GetMapping("/id/{id}")
public R<ProfileVO> selectById(@NotNull @PathVariable(value = "id") Long id) {
public Mono<R<ProfileVO>> selectById(@NotNull @PathVariable(value = "id") Long id) {
try {
ProfileBO entityBO = profileService.selectById(id);
ProfileVO entityVO = profileBuilder.buildVOByBO(entityBO);
return R.ok(entityVO);
return Mono.just(R.ok(entityVO));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -137,14 +138,14 @@ public class ProfileController implements BaseController {
* @return Map(ID, ProfileVO)
*/
@PostMapping("/ids")
public R<Map<Long, ProfileVO>> selectByIds(@RequestBody Set<Long> profileIds) {
public Mono<R<Map<Long, ProfileVO>>> selectByIds(@RequestBody Set<Long> profileIds) {
try {
List<ProfileBO> entityBOList = profileService.selectByIds(profileIds);
Map<Long, ProfileVO> deviceMap = entityBOList.stream().collect(Collectors.toMap(ProfileBO::getId, entityBO -> profileBuilder.buildVOByBO(entityBO)));
return R.ok(deviceMap);
return Mono.just(R.ok(deviceMap));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -155,14 +156,14 @@ public class ProfileController implements BaseController {
* @return Profile 集合
*/
@GetMapping("/device_id/{deviceId}")
public R<List<ProfileVO>> selectByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
public Mono<R<List<ProfileVO>>> selectByDeviceId(@NotNull @PathVariable(value = "deviceId") Long deviceId) {
try {
List<ProfileBO> entityBOList = profileService.selectByDeviceId(deviceId);
List<ProfileVO> entityVOList = profileBuilder.buildVOListByBOList(entityBOList);
return R.ok(entityVOList);
return Mono.just(R.ok(entityVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -173,7 +174,7 @@ public class ProfileController implements BaseController {
* @return Page Of Profile
*/
@PostMapping("/list")
public R<Page<ProfileVO>> list(@RequestBody(required = false) ProfileQuery entityQuery) {
public Mono<R<Page<ProfileVO>>> list(@RequestBody(required = false) ProfileQuery entityQuery) {
try {
if (Objects.isNull(entityQuery)) {
entityQuery = new ProfileQuery();
@@ -181,9 +182,9 @@ public class ProfileController implements BaseController {
entityQuery.setTenantId(getTenantId());
Page<ProfileBO> entityPageBO = profileService.selectByPage(entityQuery);
Page<ProfileVO> entityPageVO = profileBuilder.buildVOPageByBOPage(entityPageBO);
return R.ok(entityPageVO);
return Mono.just(R.ok(entityPageVO));
} catch (Exception e) {
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
@@ -29,6 +29,7 @@ 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 reactor.core.publisher.Mono;
import java.util.List;
@@ -45,13 +46,13 @@ public class TopicController implements BaseController {
}
@PostMapping("/list")
public R<Page<List<TopicVO>>> query(@RequestBody(required = false) TopicQuery topicQuery) {
public Mono<R<Page<List<TopicVO>>>> query(@RequestBody(required = false) TopicQuery topicQuery) {
try {
Page<List<TopicVO>> topicVOList = topicService.query(topicQuery);
return R.ok(topicVOList);
return Mono.just(R.ok(topicVOList));
} catch (Exception e) {
log.error(e.getMessage(), e);
return R.fail(e.getMessage());
return Mono.just(R.fail(e.getMessage()));
}
}
}
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
env: dev
group: ${user.name}
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_manager}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_manager}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
datasource:
url: jdbc:mysql://${MYSQL_HOST:dc3-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:dc3_manager}?allowPublicKeyRetrieval=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
-5
View File
@@ -35,11 +35,6 @@
<artifactId>leshan-server-cf</artifactId>
<version>2.0.0-M10</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->
</dependencies>
</project>
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
driver:
schedule:
# 定时读数据
@@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
* @since 2022.1.0
*/
@SpringBootApplication
// 开发环境无需注册中心
// @EnableDiscoveryClient
@EnableTransactionManagement
public class GatewayApplication {
@@ -1,74 +0,0 @@
/*
* Copyright 2016-present the IoT DC3 original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.pnoker.gateway.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.pnoker.common.entity.R;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
import reactor.core.publisher.Mono;
/**
* 网关异常通用处理器, 只作用在webflux 环境下 , 优先级低于 {@link ResponseStatusExceptionHandler} 执行
*
* @author pnoker
* @since 2022.1.0
*/
@Slf4j
@Order(-1)
@Component
public class ExceptionConfig implements ErrorWebExceptionHandler {
@Resource
private ObjectMapper objectMapper;
@NonNull
@Override
public Mono<Void> handle(ServerWebExchange exchange, @NonNull Throwable throwable) {
ServerHttpResponse response = exchange.getResponse();
if (response.isCommitted()) {
return Mono.error(throwable);
}
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
if (throwable instanceof ResponseStatusException) {
response.setStatusCode(((ResponseStatusException) throwable).getStatusCode());
}
return response.writeWith(Mono.fromSupplier(() -> {
DataBufferFactory bufferFactory = response.bufferFactory();
try {
return bufferFactory.wrap(objectMapper.writeValueAsBytes(R.fail(throwable.getMessage())));
} catch (Exception e) {
log.error(e.getMessage(), e);
return bufferFactory.wrap(new byte[0]);
}
}));
}
}
@@ -17,21 +17,22 @@
package io.github.pnoker.gateway.config;
import io.github.pnoker.gateway.fallback.GatewayFallback;
import io.github.pnoker.gateway.filter.LimitedIpGlobalFilter;
import io.github.pnoker.gateway.filter.factory.AuthenticGatewayFilterFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import java.util.Objects;
/**
* 网关配置
* 自定义Route配置
*
* @author pnoker
* @since 2022.1.0
@@ -39,31 +40,40 @@ import org.springframework.web.reactive.function.server.ServerResponse;
@Slf4j
@Configuration
public class GatewayConfig {
private final GatewayFallback gatewayFallback;
public GatewayConfig(GatewayFallback gatewayFallback) {
this.gatewayFallback = gatewayFallback;
}
/**
* 根据 HostAddress 进行限流
*
* @return KeyResolver
*/
@Bean
@LoadBalanced
public WebClient.Builder loadBalancedWebClientBuilder() {
return WebClient.builder();
public KeyResolver hostKeyResolver() {
return exchange -> Mono.just(Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getHostString());
}
/**
* Redis 令牌桶 限流
*
* @return RedisRateLimiter
*/
@Bean
public LimitedIpGlobalFilter limitedIpGlobalFilter() {
return new LimitedIpGlobalFilter();
}
@Bean
public AuthenticGatewayFilterFactory authenticGatewayFilterFactory() {
return new AuthenticGatewayFilterFactory();
RedisRateLimiter redisRateLimiter() {
return new RedisRateLimiter(100, 2000);
}
/**
* fallback 配置
*
* @return RouterFunction
*/
@Bean
public RouterFunction<ServerResponse> routerFunction() {
return RouterFunctions.route(RequestPredicates.path("/fallback").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), gatewayFallback);
}
}
}
@@ -1,57 +0,0 @@
/*
* Copyright 2016-present the IoT DC3 original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.pnoker.gateway.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;
import java.util.Objects;
/**
* 自定义Route配置
*
* @author pnoker
* @since 2022.1.0
*/
@Slf4j
@Configuration
public class RouteConfig {
/**
* 根据 HostAddress 进行限流
*
* @return KeyResolver
*/
@Bean
public KeyResolver hostKeyResolver() {
return exchange -> Mono.just(Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getHostString());
}
/**
* Redis 令牌桶 限流
*
* @return RedisRateLimiter
*/
@Bean
RedisRateLimiter redisRateLimiter() {
return new RedisRateLimiter(100, 2000);
}
}
@@ -18,6 +18,7 @@ package io.github.pnoker.gateway.fallback;
import io.github.pnoker.common.entity.R;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -41,6 +42,7 @@ import java.util.Optional;
@Component
public class GatewayFallback implements HandlerFunction<ServerResponse> {
@NotNull
@Override
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
log.info(serverRequest.toString());
@@ -23,6 +23,7 @@ import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@@ -33,6 +34,7 @@ import reactor.core.publisher.Mono;
* @since 2022.1.0
*/
@Slf4j
@Component
public class LimitedIpGlobalFilter implements GlobalFilter, Ordered {
@GrpcClient(AuthConstant.SERVICE_NAME)
@@ -17,7 +17,6 @@
package io.github.pnoker.gateway.filter.factory;
import io.github.pnoker.gateway.filter.AuthenticGatewayFilter;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
@@ -34,8 +33,11 @@ import org.springframework.stereotype.Component;
@Component
public class AuthenticGatewayFilterFactory extends AbstractGatewayFilterFactory<Object> {
@Resource
private AuthenticGatewayFilter authenticGatewayFilter;
private final AuthenticGatewayFilter authenticGatewayFilter;
public AuthenticGatewayFilterFactory(AuthenticGatewayFilter authenticGatewayFilter) {
this.authenticGatewayFilter = authenticGatewayFilter;
}
@Override
public GatewayFilter apply(Object config) {
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Development environment, customizable configuration
# 开发环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
env: dev
group: ${user.name}
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Pre-release environment, customizable configuration
# 预发布环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
data:
redis:
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Product environment, customizable configuration
# 生产环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
data:
redis:
@@ -14,7 +14,7 @@
# limitations under the License.
#
# Test environment, customizable configuration
# 测试环境配置, 会覆盖 application-*.yml 中配置的内容
spring:
data:
redis: