diff --git a/src/main/java/com/cloudservice/ccs/biz/IWorkloadStatisticsBiz.java b/src/main/java/com/cloudservice/ccs/biz/IWorkloadStatisticsBiz.java index ab85feb9c12dfe74d20579dc2dd27027683ed1fd..08cf5b8d5536f6ddb4f449e8b661d4404c662a86 100644 --- a/src/main/java/com/cloudservice/ccs/biz/IWorkloadStatisticsBiz.java +++ b/src/main/java/com/cloudservice/ccs/biz/IWorkloadStatisticsBiz.java @@ -1,6 +1,8 @@ package com.cloudservice.ccs.biz; import com.cloudservice.ccs.entity.WorkloadStatistics; +import com.cloudservice.ccs.entity.WorkloadStatisticsAggregation; +import com.cloudservice.ccs.entity.WorkloadStatisticsWithAverage; import java.util.List; @@ -15,4 +17,8 @@ public interface IWorkloadStatisticsBiz { WorkloadStatistics getOne(Integer id); List getAll(); + + List getAllWithAverage(); + + WorkloadStatisticsAggregation getAggregation(); } diff --git a/src/main/java/com/cloudservice/ccs/biz/impl/WorkloadStatisticsImpl.java b/src/main/java/com/cloudservice/ccs/biz/impl/WorkloadStatisticsImpl.java index 1727b7183e41efdbb74eddf9afb9b5d33ea0e5cc..bcaf414b4b5267f29dad50a5b03565be15254675 100644 --- a/src/main/java/com/cloudservice/ccs/biz/impl/WorkloadStatisticsImpl.java +++ b/src/main/java/com/cloudservice/ccs/biz/impl/WorkloadStatisticsImpl.java @@ -2,11 +2,14 @@ package com.cloudservice.ccs.biz.impl; import com.cloudservice.ccs.biz.IWorkloadStatisticsBiz; import com.cloudservice.ccs.entity.WorkloadStatistics; +import com.cloudservice.ccs.entity.WorkloadStatisticsAggregation; +import com.cloudservice.ccs.entity.WorkloadStatisticsWithAverage; import com.cloudservice.ccs.exception.WorkloadStatisticsException; import com.cloudservice.ccs.mapper.WorkLoadStatisticsMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; @Service @@ -51,4 +54,25 @@ public class WorkloadStatisticsImpl implements IWorkloadStatisticsBiz { public List getAll() { return workLoadStatisticsMapper.getAll(); } + + @Override + public List getAllWithAverage() { + List workloadStatisticsList = workLoadStatisticsMapper.getAll(); + List result = new ArrayList<>(); + for (WorkloadStatistics workloadStatistics : workloadStatisticsList) { + WorkloadStatisticsWithAverage item = WorkloadStatisticsWithAverage.fromWorkloadStatistics(workloadStatistics); + item.calculateAverage(); + result.add(item); + } + return result; + } + + @Override + public WorkloadStatisticsAggregation getAggregation() { + WorkloadStatisticsAggregation part1 = workLoadStatisticsMapper.getStatisticsPartOfAggregation(), + part2 = workLoadStatisticsMapper.getSessionPartOfAggregation(); + part1.setMaxSessionTime(part2.getMaxSessionTime()); + part1.setMaxMessageCount(part2.getMaxMessageCount()); + return part1; + } } diff --git a/src/main/java/com/cloudservice/ccs/controller/AttendanceStatisticsController.java b/src/main/java/com/cloudservice/ccs/controller/AttendanceStatisticsController.java index ee674e134d093cf754237a07a2000dd4b91f3268..a2d7993c5511b182cb47feb63d9f6a4e1722bc02 100644 --- a/src/main/java/com/cloudservice/ccs/controller/AttendanceStatisticsController.java +++ b/src/main/java/com/cloudservice/ccs/controller/AttendanceStatisticsController.java @@ -1,6 +1,7 @@ package com.cloudservice.ccs.controller; import com.cloudservice.ccs.biz.IAttendanceStatisticsBiz; +import com.cloudservice.ccs.entity.ApiResult; import com.cloudservice.ccs.entity.AttendanceStatistics; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -18,31 +19,34 @@ public class AttendanceStatisticsController { private IAttendanceStatisticsBiz attendanceStatisticsBiz; @PostMapping("/") - void save(@RequestBody AttendanceStatistics attendanceStatistics) { + ApiResult save(@RequestBody AttendanceStatistics attendanceStatistics) { // 接口问题待讨论:是否应当返回生成的 id? attendanceStatisticsBiz.save(attendanceStatistics); + return ApiResult.success(); } @PutMapping("/{id}") - void update(@PathVariable Integer id, @RequestBody AttendanceStatistics attendanceStatistics) { + ApiResult update(@PathVariable Integer id, @RequestBody AttendanceStatistics attendanceStatistics) { attendanceStatisticsBiz.update(id, attendanceStatistics); + return ApiResult.success(); } @DeleteMapping("/{id}") - void delete(@PathVariable Integer id) { + ApiResult delete(@PathVariable Integer id) { attendanceStatisticsBiz.delete(id); + return ApiResult.success(); } @GetMapping("/{id}") - ResponseEntity queryById(@PathVariable Integer id) { + ApiResult queryById(@PathVariable Integer id) { AttendanceStatistics result = attendanceStatisticsBiz.getOne(id); - return new ResponseEntity<>(result, HttpStatus.OK); + return ApiResult.successWithData(result); } @GetMapping("/") - ResponseEntity>> queryAll() { + ApiResult queryAll() { Map> result = new HashMap<>(); result.put("attendance-statistics", attendanceStatisticsBiz.getAll()); - return new ResponseEntity<>(result, HttpStatus.OK); + return ApiResult.successWithData(result); } } diff --git a/src/main/java/com/cloudservice/ccs/controller/BlackListController.java b/src/main/java/com/cloudservice/ccs/controller/BlackListController.java index e08fcf0a69d65e45c1d608b8a1db2298e7a9e127..0ba16eef68ea8e2a654df57bbcdb932e17bb0248 100644 --- a/src/main/java/com/cloudservice/ccs/controller/BlackListController.java +++ b/src/main/java/com/cloudservice/ccs/controller/BlackListController.java @@ -1,6 +1,7 @@ package com.cloudservice.ccs.controller; import com.cloudservice.ccs.biz.IBlackListBiz; +import com.cloudservice.ccs.entity.ApiResult; import com.cloudservice.ccs.entity.BlackList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -18,31 +19,34 @@ public class BlackListController { private IBlackListBiz blackListBiz; @PostMapping("/") - void save(@RequestBody BlackList blackList) { + ApiResult save(@RequestBody BlackList blackList) { // 接口问题待讨论:是否应当返回生成的 id? blackListBiz.save(blackList); + return ApiResult.success(); } @PutMapping("/{id}") - void update(@PathVariable Integer id, @RequestBody BlackList blackList) { + ApiResult update(@PathVariable Integer id, @RequestBody BlackList blackList) { blackListBiz.update(id, blackList); + return ApiResult.success(); } @DeleteMapping("/{id}") - void delete(@PathVariable Integer id) { + ApiResult delete(@PathVariable Integer id) { blackListBiz.delete(id); + return ApiResult.success(); } @GetMapping("/{id}") - ResponseEntity queryById(@PathVariable Integer id) { + ApiResult queryById(@PathVariable Integer id) { BlackList result = blackListBiz.getOne(id); - return new ResponseEntity<>(result, HttpStatus.OK); + return ApiResult.successWithData(result); } @GetMapping("/") - ResponseEntity>> queryAll() { + ApiResult queryAll() { Map> result = new HashMap<>(); result.put("black-list", blackListBiz.getAll()); - return new ResponseEntity<>(result, HttpStatus.OK); + return ApiResult.successWithData(result); } } diff --git a/src/main/java/com/cloudservice/ccs/controller/CommonWordController.java b/src/main/java/com/cloudservice/ccs/controller/CommonWordController.java index 2e5a5f507faae58372fa3147c11ea86f3e07fcf8..e78151acbecf76c68a7e116d3c36c2a5cb3aac18 100644 --- a/src/main/java/com/cloudservice/ccs/controller/CommonWordController.java +++ b/src/main/java/com/cloudservice/ccs/controller/CommonWordController.java @@ -1,48 +1,49 @@ -package com.cloudservice.ccs.controller; - -import com.cloudservice.ccs.biz.ICommonWordBiz; -import com.cloudservice.ccs.entity.CommonWord; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@RestController -@RequestMapping("/common-word") -public class CommonWordController { - @Autowired - private ICommonWordBiz commonWordBiz; - - @PostMapping("/") - void save(@RequestBody CommonWord commonWord) { - // 接口问题待讨论:是否应当返回生成的 id? - commonWordBiz.save(commonWord); - } - -@PutMapping("/{id}") - void update(@PathVariable Integer id, @RequestBody CommonWord commonWord) { - commonWordBiz.update(id, commonWord); - } - -@DeleteMapping("/{id}") - void delete(@PathVariable Integer id) { - commonWordBiz.delete(id); - } - -@GetMapping("/{id}") - ResponseEntity queryById(@PathVariable Integer id) { - CommonWord result = commonWordBiz.getOne(id); - return new ResponseEntity<>(result, HttpStatus.OK); - } - -@GetMapping("/") - ResponseEntity>> queryAll() { - Map> result = new HashMap<>(); - result.put("common-word", commonWordBiz.getAll()); - return new ResponseEntity<>(result, HttpStatus.OK); - } -} +//package com.cloudservice.ccs.controller; +// +//import com.cloudservice.ccs.biz.ICommonWordBiz; +//import com.cloudservice.ccs.entity.ApiResult; +//import com.cloudservice.ccs.entity.CommonWord; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.http.HttpStatus; +//import org.springframework.http.ResponseEntity; +//import org.springframework.web.bind.annotation.*; +// +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map; +// +//@RestController +//@RequestMapping("/common-word") +//public class CommonWordController { +// @Autowired +// private ICommonWordBiz commonWordBiz; +// +// @PostMapping("/") +// void save(@RequestBody CommonWord commonWord) { +// // 接口问题待讨论:是否应当返回生成的 id? +// commonWordBiz.save(commonWord); +// } +// +//@PutMapping("/{id}") +//ApiResult update(@PathVariable Integer id, @RequestBody CommonWord commonWord) { +// commonWordBiz.update(id, commonWord); +// } +// +//@DeleteMapping("/{id}") +// ApiResult delete(@PathVariable Integer id) { +// commonWordBiz.delete(id); +// } +// +//@GetMapping("/{id}") +// ApiResult queryById(@PathVariable Integer id) { +// CommonWord result = commonWordBiz.getOne(id); +// return ApiResult.successWithData(result); +// } +// +//@GetMapping("/") +// ApiResult queryAll() { +// Map> result = new HashMap<>(); +// result.put("common-word", commonWordBiz.getAll()); +// return ApiResult.successWithData(result); +// } +//} diff --git a/src/main/java/com/cloudservice/ccs/controller/CustomerServiceController.java b/src/main/java/com/cloudservice/ccs/controller/CustomerServiceController.java index ef5d7ae011f31a308f71c0f79cc70b9ac51acc92..159637146205ff2e288bededbfbdc94c657c5281 100644 --- a/src/main/java/com/cloudservice/ccs/controller/CustomerServiceController.java +++ b/src/main/java/com/cloudservice/ccs/controller/CustomerServiceController.java @@ -1,6 +1,7 @@ package com.cloudservice.ccs.controller; import com.cloudservice.ccs.biz.ICustomerServiceBiz; +import com.cloudservice.ccs.entity.ApiResult; import com.cloudservice.ccs.entity.CustomerService; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -21,41 +22,44 @@ public class CustomerServiceController { // @RequiresPermissions("all") @PostMapping("/") - void save(@RequestBody CustomerService customerService) { + ApiResult save(@RequestBody CustomerService customerService) { // 接口问题待讨论:是否应当返回生成的 id? customerServiceBiz.save(customerService); + return ApiResult.success(); } // @RequiresPermissions("all") @PutMapping("/{id}") - void update(@PathVariable Integer id, @RequestBody CustomerService customerService) { + ApiResult update(@PathVariable Integer id, @RequestBody CustomerService customerService) { customerServiceBiz.update(id, customerService); + return ApiResult.success(); } // @RequiresPermissions("all") @PutMapping("/{id}/partial") - void partialUpdate(@PathVariable Integer id, @RequestBody Map fields) { + ApiResult partialUpdate(@PathVariable Integer id, @RequestBody Map fields) { customerServiceBiz.partialUpdate(id, fields); + return ApiResult.success(); } // @RequiresPermissions("all") @DeleteMapping("/{id}") - void delete(@PathVariable Integer id) { + ApiResult delete(@PathVariable Integer id) { customerServiceBiz.delete(id); + return ApiResult.success(); } // @RequiresPermissions("all") @GetMapping("/{id}") - ResponseEntity queryById(@PathVariable Integer id) { + ApiResult queryById(@PathVariable Integer id) { CustomerService result = customerServiceBiz.getOne(id); - return new ResponseEntity<>(result, HttpStatus.OK); + return ApiResult.successWithData(result); } // @RequiresPermissions("all") @GetMapping("/") - ResponseEntity>> queryAll() { - Map> result = new HashMap<>(); - result.put("customer-services", customerServiceBiz.getAll()); - return new ResponseEntity<>(result, HttpStatus.OK); + ApiResult queryAll() { + List result = customerServiceBiz.getAll(); + return ApiResult.successWithData(result); } } diff --git a/src/main/java/com/cloudservice/ccs/controller/LoginController.java b/src/main/java/com/cloudservice/ccs/controller/LoginController.java index 0d5189ca3735ee890f28503640334de384230a79..8f9597a91ce24d5b5db8630c48b1637ac418c894 100644 --- a/src/main/java/com/cloudservice/ccs/controller/LoginController.java +++ b/src/main/java/com/cloudservice/ccs/controller/LoginController.java @@ -1,5 +1,6 @@ package com.cloudservice.ccs.controller; +import com.cloudservice.ccs.entity.ApiResult; import com.cloudservice.ccs.entity.LoginData; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; @@ -17,22 +18,18 @@ import java.util.Map; @RestController public class LoginController { @PostMapping("/login") - public ResponseEntity> doLogin(@RequestBody LoginData loginData){ + public ApiResult doLogin(@RequestBody LoginData loginData){ String email = loginData.getEmail(), password = loginData.getPassword(); Subject subject = SecurityUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(email,password); subject.login(token); - Map map = new HashMap<>(1); - map.put("result", "success"); - return new ResponseEntity<>(map, HttpStatus.OK); + return ApiResult.success(); } @PostMapping("/logout") - public ResponseEntity> doLogout() { + public ApiResult doLogout() { Subject subject = SecurityUtils.getSubject(); subject.logout(); - Map map = new HashMap<>(1); - map.put("result", "success"); - return new ResponseEntity<>(map, HttpStatus.OK); + return ApiResult.success(); } } diff --git a/src/main/java/com/cloudservice/ccs/controller/WorkloadStatisticsController.java b/src/main/java/com/cloudservice/ccs/controller/WorkloadStatisticsController.java index 20dd44bbeba725d0b6eae3442be8a8a09d6cb3b1..ce75a94d1a4552c28a1e6c11246076459b7fc8fc 100644 --- a/src/main/java/com/cloudservice/ccs/controller/WorkloadStatisticsController.java +++ b/src/main/java/com/cloudservice/ccs/controller/WorkloadStatisticsController.java @@ -2,13 +2,16 @@ package com.cloudservice.ccs.controller; import com.cloudservice.ccs.biz.IWorkloadStatisticsBiz; +import com.cloudservice.ccs.entity.ApiResult; import com.cloudservice.ccs.entity.WorkloadStatistics; +import com.cloudservice.ccs.entity.WorkloadStatisticsWithAverage; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,32 +23,45 @@ public class WorkloadStatisticsController { IWorkloadStatisticsBiz workloadStatisticsBiz; @PostMapping("/") - void save(@RequestBody WorkloadStatistics workloadStatistics) { + ApiResult save(@RequestBody WorkloadStatistics workloadStatistics) { // 接口问题待讨论:是否应当返回生成的 id? workloadStatisticsBiz.save(workloadStatistics); + return ApiResult.success(); } @PutMapping("/{id}") - void update(@PathVariable Integer id, @RequestBody WorkloadStatistics workloadStatistics) { + ApiResult update(@PathVariable Integer id, @RequestBody WorkloadStatistics workloadStatistics) { workloadStatisticsBiz.update(id, workloadStatistics); + return ApiResult.success(); } @DeleteMapping("/{id}") - void delete(@PathVariable Integer id) { + ApiResult delete(@PathVariable Integer id) { workloadStatisticsBiz.delete(id); + return ApiResult.success(); } @GetMapping("/{id}") - ResponseEntity queryById(@PathVariable Integer id) { + ApiResult queryById(@PathVariable Integer id) { WorkloadStatistics result = workloadStatisticsBiz.getOne(id); - return new ResponseEntity<>(result, HttpStatus.OK); + return ApiResult.successWithData(result); } @RequiresPermissions("all") @GetMapping("/") - ResponseEntity>> queryAll() { - Map> result = new HashMap<>(); - result.put("workload-statistics", workloadStatisticsBiz.getAll()); - return new ResponseEntity<>(result, HttpStatus.OK); + ApiResult queryAll() { + List result = workloadStatisticsBiz.getAll(); + return ApiResult.successWithData(result); + } + + @GetMapping("/with-average") + ApiResult queryAllWithAverage() { + List result = workloadStatisticsBiz.getAllWithAverage(); + return ApiResult.successWithData(result); + } + + @GetMapping("/aggregation") + ApiResult queryAggregation() { + return ApiResult.successWithData(workloadStatisticsBiz.getAggregation()); } } diff --git a/src/main/java/com/cloudservice/ccs/entity/ApiResult.java b/src/main/java/com/cloudservice/ccs/entity/ApiResult.java new file mode 100644 index 0000000000000000000000000000000000000000..e089ac4577b485d3eb6f2fbb318bc8775c0d9251 --- /dev/null +++ b/src/main/java/com/cloudservice/ccs/entity/ApiResult.java @@ -0,0 +1,30 @@ +package com.cloudservice.ccs.entity; + +import com.cloudservice.ccs.util.Constant; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ApiResult { + + private String error; + + private Object data; + + public static ApiResult success() { + return new ApiResult(null, null); + } + + public static ApiResult successWithData(Object data) { + return new ApiResult(null, data); + } + + public static ApiResult failure() { + return new ApiResult(Constant.DEFAULT_ERROR_MESSAGE, null); + } + + public static ApiResult failureWithData(Object data) { + return new ApiResult(Constant.DEFAULT_ERROR_MESSAGE, data); + } +} diff --git a/src/main/java/com/cloudservice/ccs/entity/ErrorResponse.java b/src/main/java/com/cloudservice/ccs/entity/ErrorResponse.java deleted file mode 100644 index bad8d26c62c209f8ccc08d79b0f8e3ac03c55ca0..0000000000000000000000000000000000000000 --- a/src/main/java/com/cloudservice/ccs/entity/ErrorResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.cloudservice.ccs.entity; - -import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.Data; - -import java.util.Date; - -@Data -public class ErrorResponse { - private Date timestamp; - private String exception; - private Integer status; - private String error; - private String message; -} diff --git a/src/main/java/com/cloudservice/ccs/entity/WorkloadStatisticsAggregation.java b/src/main/java/com/cloudservice/ccs/entity/WorkloadStatisticsAggregation.java new file mode 100644 index 0000000000000000000000000000000000000000..3ad99ed95a7bdfc42bd9864eb166e08e93386e96 --- /dev/null +++ b/src/main/java/com/cloudservice/ccs/entity/WorkloadStatisticsAggregation.java @@ -0,0 +1,16 @@ +package com.cloudservice.ccs.entity; + +import lombok.Data; + +@Data +public class WorkloadStatisticsAggregation { + private Integer totalMessageCount; + private Integer totalSessionCount; + private Integer averageMessageCount; + private Integer totalSessionTime; + private Integer averageSessionTime; + private Integer totalEffectiveMessageCount; + private Integer totalEndSessionCount; + private Integer maxMessageCount; + private Integer maxSessionTime; +} diff --git a/src/main/java/com/cloudservice/ccs/entity/WorkloadStatisticsWithAverage.java b/src/main/java/com/cloudservice/ccs/entity/WorkloadStatisticsWithAverage.java new file mode 100644 index 0000000000000000000000000000000000000000..eff4cc7531f725c4027ea65c7d1ef5ac511b604d --- /dev/null +++ b/src/main/java/com/cloudservice/ccs/entity/WorkloadStatisticsWithAverage.java @@ -0,0 +1,29 @@ +package com.cloudservice.ccs.entity; + +import lombok.Builder; +import lombok.Data; + +@Data +public class WorkloadStatisticsWithAverage extends WorkloadStatistics { + + private Integer averageSessionTime; + + private Integer averageMessageCount; + + public static WorkloadStatisticsWithAverage fromWorkloadStatistics(WorkloadStatistics workloadStatistics) { + WorkloadStatisticsWithAverage res = new WorkloadStatisticsWithAverage(); + res.setId(workloadStatistics.getId()); + res.setNickName(workloadStatistics.getNickName()); + res.setTotalMessageCount(workloadStatistics.getTotalMessageCount()); + res.setTotalSessionCount(workloadStatistics.getTotalSessionCount()); + res.setTotalEffectiveSessionCount(workloadStatistics.getTotalEffectiveSessionCount()); + res.setTotalEndSessionCount(workloadStatistics.getTotalEndSessionCount()); + res.setTotalSessionTime(workloadStatistics.getTotalSessionTime()); + return res; + } + + public void calculateAverage() { + this.setAverageSessionTime(this.getTotalSessionTime() / this.getTotalSessionCount()); + this.setAverageMessageCount(this.getTotalMessageCount() / this.getTotalSessionCount()); + } +} diff --git a/src/main/java/com/cloudservice/ccs/exception/BaseException.java b/src/main/java/com/cloudservice/ccs/exception/BaseException.java index 8956c62cc85c8240d315c79ac580c6e0b6458046..79aa4de11d044f7556bd7dc26a7164f46e1255ca 100644 --- a/src/main/java/com/cloudservice/ccs/exception/BaseException.java +++ b/src/main/java/com/cloudservice/ccs/exception/BaseException.java @@ -1,15 +1,12 @@ package com.cloudservice.ccs.exception; +import com.cloudservice.ccs.util.Constant; import lombok.Data; import org.springframework.http.HttpStatus; @Data public class BaseException extends RuntimeException { - private String error = "General error"; - - private Integer status = 400; - - private HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; + private String error = Constant.DEFAULT_ERROR_MESSAGE; public BaseException(String message) { super(message); diff --git a/src/main/java/com/cloudservice/ccs/exception/GlobalExceptionHandler.java b/src/main/java/com/cloudservice/ccs/exception/GlobalExceptionHandler.java index 8fb30eac1f8761fd548847713b2fd626954adbbb..84f8bb67456ae9d6f81fba0d58555e995eb5321f 100644 --- a/src/main/java/com/cloudservice/ccs/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/cloudservice/ccs/exception/GlobalExceptionHandler.java @@ -1,16 +1,11 @@ package com.cloudservice.ccs.exception; -import com.cloudservice.ccs.entity.ErrorResponse; -import org.apache.shiro.authc.AuthenticationException; +import com.cloudservice.ccs.entity.ApiResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import java.util.Date; - @RestControllerAdvice public class GlobalExceptionHandler { @@ -21,35 +16,23 @@ public class GlobalExceptionHandler { * 剩余的异常由 Spring Boot 处理 */ @ExceptionHandler(BaseException.class) - public ResponseEntity handleBaseException(BaseException e) { + public ApiResult handleBaseException(BaseException e) { if (logger.isDebugEnabled()) { - logger.debug(e.getClass().getName() + ": " + e.getMessage()); + logger.debug(e.getClass().getName() + "[" + e.getError() + "]: " + e.getMessage()); e.printStackTrace(); } - ErrorResponse errorResponse = new ErrorResponse(); - errorResponse.setTimestamp(new Date()); - errorResponse.setException(e.getClass().getName()); - errorResponse.setStatus(e.getStatus()); - errorResponse.setError(e.getError()); - errorResponse.setMessage(e.getMessage()); - return new ResponseEntity<>(errorResponse, e.getHttpStatus()); + return new ApiResult(e.getError(), e.getClass().getName() + ": " + e.getMessage()); } /** * 处理认证、鉴权相关异常并返回对应的错误响应 */ - @ExceptionHandler(AuthenticationException.class) - public ResponseEntity handleAuthenticationException(AuthenticationException e) { + @ExceptionHandler(Exception.class) + public ApiResult handleException(Exception e) { if (logger.isDebugEnabled()) { logger.debug(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } - ErrorResponse errorResponse = new ErrorResponse(); - errorResponse.setTimestamp(new Date()); - errorResponse.setException(e.getClass().getName()); - errorResponse.setStatus(400); - errorResponse.setError("Authentication failure"); - errorResponse.setMessage(e.getMessage()); - return new ResponseEntity<>(errorResponse, HttpStatus.FORBIDDEN); + return ApiResult.failureWithData(e.getClass().getName() + ": " + e.getMessage()); } } diff --git a/src/main/java/com/cloudservice/ccs/mapper/WorkLoadStatisticsMapper.java b/src/main/java/com/cloudservice/ccs/mapper/WorkLoadStatisticsMapper.java index 502563ecb775e86a7659b9fe525abc774db3f2a5..91247321bce3698dc9fcb239f668872212540446 100644 --- a/src/main/java/com/cloudservice/ccs/mapper/WorkLoadStatisticsMapper.java +++ b/src/main/java/com/cloudservice/ccs/mapper/WorkLoadStatisticsMapper.java @@ -3,6 +3,7 @@ package com.cloudservice.ccs.mapper; import com.cloudservice.ccs.entity.VisitorInfo; import com.cloudservice.ccs.entity.WorkloadStatistics; +import com.cloudservice.ccs.entity.WorkloadStatisticsAggregation; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -18,4 +19,8 @@ public interface WorkLoadStatisticsMapper { WorkloadStatistics getOne(Integer id); List getAll(); + + WorkloadStatisticsAggregation getStatisticsPartOfAggregation(); + + WorkloadStatisticsAggregation getSessionPartOfAggregation(); } diff --git a/src/main/java/com/cloudservice/ccs/util/Constant.java b/src/main/java/com/cloudservice/ccs/util/Constant.java new file mode 100644 index 0000000000000000000000000000000000000000..e6245abd6e40b0a751eb2fc8975cbcb4f1d6950f --- /dev/null +++ b/src/main/java/com/cloudservice/ccs/util/Constant.java @@ -0,0 +1,5 @@ +package com.cloudservice.ccs.util; + +public class Constant { + public static final String DEFAULT_ERROR_MESSAGE = "error"; +} diff --git a/src/main/resources/mapper/WorkLoadStatisticsMapper.xml b/src/main/resources/mapper/WorkLoadStatisticsMapper.xml index 0283717e0bfdb5da96ad3d4d9d3ae918d2f782da..95f1519ce2af965fe7a6b153c65b93f02fff8fc7 100644 --- a/src/main/resources/mapper/WorkLoadStatisticsMapper.xml +++ b/src/main/resources/mapper/WorkLoadStatisticsMapper.xml @@ -36,4 +36,20 @@ + + + \ No newline at end of file