欣影管理平台接口完善
parent
0a47351737
commit
42540df186
@ -0,0 +1,39 @@
|
||||
package com.shxy.xymanager_admin.controller;
|
||||
|
||||
import com.shxy.xymanager_common.annotation.Log;
|
||||
import com.shxy.xymanager_common.base.BaseController;
|
||||
import com.shxy.xymanager_common.base.ResponseReult;
|
||||
import com.shxy.xymanager_common.bean.ServiceBody;
|
||||
import com.shxy.xymanager_common.bean.ServiceStatus;
|
||||
import com.shxy.xymanager_common.model.TerminalListModel;
|
||||
import com.shxy.xymanager_service.service.TerminalService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@Api(value = "设备接口", tags = "设备接口相关")
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class TerminalController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
TerminalService terminalService;
|
||||
|
||||
@ApiOperation(value = "获取设备列表", notes = "获取设备列表接口", httpMethod = "POST")
|
||||
@ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")})
|
||||
@RequestMapping("/getTerminalList")
|
||||
@Log(title = "获取设备列表", type = "查询")
|
||||
public ResponseReult<TerminalListModel> getTerminalList() {
|
||||
ServiceBody<TerminalListModel> serviceBody = terminalService.getTerminalList();
|
||||
if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
|
||||
return ResponseReult.success(serviceBody.getData());
|
||||
} else {
|
||||
return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.shxy.xymanager_common.base;
|
||||
|
||||
|
||||
public class BaseEntity {
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package com.shxy.xymanager_common.base;
|
||||
|
||||
import com.shxy.xymanager_common.exception.IErrorCode;
|
||||
import com.shxy.xymanager_common.util.http.HttpStatus;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
// @ApiModel: 用对象来接收参数
|
||||
@ApiModel(value = "接口返回", description = "接口响应返回")
|
||||
public class ResponseReult<T> implements Serializable {
|
||||
/**
|
||||
* 返回对象
|
||||
*/
|
||||
@ApiModelProperty(value = "返回对象", name = "返回对象")
|
||||
private T data;
|
||||
/**
|
||||
* 返回状态码
|
||||
*/
|
||||
@ApiModelProperty(value = "返回状态码", name = "返回状态码", required = true)
|
||||
private int code;
|
||||
/**
|
||||
* 返回描述
|
||||
*/
|
||||
@ApiModelProperty(value = "返回描述", name = "返回描述")
|
||||
private String msg;
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public void setCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static <T> ResponseReult<T> success(T obj) {
|
||||
ResponseReult<T> success = ResponseReult.success();
|
||||
if (obj != null) {
|
||||
success.setData(obj);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static <T> ResponseReult<T> success() {
|
||||
ResponseReult<T> response = new ResponseReult<>();
|
||||
response.setCode(HttpStatus.HTTP_OK, "操作成功");
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败消息
|
||||
*
|
||||
* @return 失败消息
|
||||
*/
|
||||
public static <T> ResponseReult<T> error() {
|
||||
ResponseReult<T> response = ResponseReult.error(HttpStatus.HTTP_INTERNAL_ERROR, "操作失败");
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败消息
|
||||
*
|
||||
* @return 失败消息
|
||||
*/
|
||||
public static <T> ResponseReult<T> error(int code, String msg) {
|
||||
ResponseReult<T> response = new ResponseReult<>();
|
||||
response.setCode(code, msg);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
*
|
||||
* @param errorCode 错误码
|
||||
*/
|
||||
public static <T> ResponseReult<T> error(IErrorCode errorCode) {
|
||||
return ResponseReult.error(errorCode.getCode(), errorCode.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
*
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public static <T> ResponseReult<T> error(String message) {
|
||||
return ResponseReult.error(HttpStatus.HTTP_INTERNAL_ERROR, message);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.shxy.xymanager_common.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* service服务请求返回
|
||||
*
|
||||
* @author 晶晶
|
||||
*/
|
||||
@Data
|
||||
public class ServiceBody<T> {
|
||||
|
||||
/**
|
||||
* 返回体
|
||||
*/
|
||||
private T data;
|
||||
/**
|
||||
* 返回状态码
|
||||
*/
|
||||
private int code;
|
||||
/**
|
||||
* 错误描述
|
||||
*/
|
||||
private String msg;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.shxy.xymanager_common.bean;
|
||||
|
||||
/**
|
||||
* 返回状态码
|
||||
*
|
||||
* @author xzg
|
||||
*/
|
||||
public class ServiceStatus {
|
||||
/**
|
||||
* 操作成功
|
||||
*/
|
||||
public static final int SUCCESS = 200;
|
||||
/**
|
||||
* 操作失败
|
||||
*/
|
||||
public static final int ERROR = 400;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.shxy.xymanager_common.exception;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 自定义API异常
|
||||
* Created by 晶晶 on 2022/3/24.
|
||||
*/
|
||||
@Data
|
||||
public class ApiException extends RuntimeException {
|
||||
private IErrorCode errorCode;
|
||||
private int error;
|
||||
|
||||
public ApiException(IErrorCode errorCode) {
|
||||
super(errorCode.getMessage());
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public ApiException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ApiException(int errorcode, String message) {
|
||||
super(message);
|
||||
this.error = errorcode;
|
||||
}
|
||||
|
||||
public ApiException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ApiException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.shxy.xymanager_common.exception;
|
||||
|
||||
import com.shxy.xymanager_common.base.ResponseReult;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
* Created by macro on 2020/2/27.
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = ApiException.class)
|
||||
public ResponseReult handle(ApiException e) {
|
||||
if (e.getErrorCode() != null) {
|
||||
return ResponseReult.error(e.getErrorCode());
|
||||
}
|
||||
if (e.getError() != 0) {
|
||||
|
||||
return ResponseReult.error(e.getError(), e.getMessage());
|
||||
}
|
||||
return ResponseReult.error(e.getMessage());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = SQLException.class)
|
||||
public ResponseReult handleValidException(SQLException e) {
|
||||
int errorCode = e.getErrorCode();
|
||||
String message = e.getMessage();
|
||||
return ResponseReult.error(errorCode, message);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||
public ResponseReult handleValidException(MethodArgumentNotValidException e) {
|
||||
BindingResult bindingResult = e.getBindingResult();
|
||||
String message = null;
|
||||
if (bindingResult.hasErrors()) {
|
||||
FieldError fieldError = bindingResult.getFieldError();
|
||||
if (fieldError != null) {
|
||||
message = fieldError.getField()+fieldError.getDefaultMessage();
|
||||
}
|
||||
}
|
||||
return ResponseReult.error(message);
|
||||
}
|
||||
//
|
||||
// @ResponseBody
|
||||
// @ExceptionHandler(value = BindException.class)
|
||||
// public CommonResult handleValidException(BindException e) {
|
||||
// BindingResult bindingResult = e.getBindingResult();
|
||||
// String message = null;
|
||||
// if (bindingResult.hasErrors()) {
|
||||
// FieldError fieldError = bindingResult.getFieldError();
|
||||
// if (fieldError != null) {
|
||||
// message = fieldError.getField()+fieldError.getDefaultMessage();
|
||||
// }
|
||||
// }
|
||||
// return CommonResult.validateFailed(message);
|
||||
// }
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.shxy.xymanager_common.exception;
|
||||
|
||||
/**
|
||||
* 常用API返回对象接口
|
||||
*
|
||||
*/
|
||||
public interface IErrorCode {
|
||||
/**
|
||||
* 返回码
|
||||
*/
|
||||
int getCode();
|
||||
|
||||
/**
|
||||
* 返回信息
|
||||
*/
|
||||
String getMessage();
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package com.shxy.xymanager_common.exception.base;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.shxy.xymanager_common.util.MessageUtils;
|
||||
|
||||
/**
|
||||
* 基础异常
|
||||
*
|
||||
* @author xzg
|
||||
*/
|
||||
public class BaseException extends RuntimeException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 所属模块
|
||||
*/
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 错误码对应的参数
|
||||
*/
|
||||
private Object[] args;
|
||||
|
||||
/**
|
||||
* 错误消息
|
||||
*/
|
||||
private String defaultMessage;
|
||||
|
||||
public BaseException(String module, String code, Object[] args, String defaultMessage)
|
||||
{
|
||||
this.module = module;
|
||||
this.code = code;
|
||||
this.args = args;
|
||||
this.defaultMessage = defaultMessage;
|
||||
}
|
||||
|
||||
public BaseException(String module, String code, Object[] args)
|
||||
{
|
||||
this(module, code, args, null);
|
||||
}
|
||||
|
||||
public BaseException(String module, String defaultMessage)
|
||||
{
|
||||
this(module, null, null, defaultMessage);
|
||||
}
|
||||
|
||||
public BaseException(String code, Object[] args)
|
||||
{
|
||||
this(null, code, args, null);
|
||||
}
|
||||
|
||||
public BaseException(String defaultMessage)
|
||||
{
|
||||
this(null, null, null, defaultMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
String message = null;
|
||||
if (!StrUtil.isEmpty(code))
|
||||
{
|
||||
message = MessageUtils.message(code, args);
|
||||
}
|
||||
if (message == null)
|
||||
{
|
||||
message = defaultMessage;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getModule()
|
||||
{
|
||||
return module;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public Object[] getArgs()
|
||||
{
|
||||
return args;
|
||||
}
|
||||
|
||||
public String getDefaultMessage()
|
||||
{
|
||||
return defaultMessage;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.shxy.xymanager_common.exception.file;
|
||||
|
||||
|
||||
import com.shxy.xymanager_common.exception.base.BaseException;
|
||||
|
||||
/**
|
||||
* 文件信息异常类
|
||||
*
|
||||
* @author xzg
|
||||
*/
|
||||
public class FileException extends BaseException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FileException(String code, Object[] args)
|
||||
{
|
||||
super("file", code, args, null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.shxy.xymanager_common.exception.file;
|
||||
|
||||
/**
|
||||
* 文件名称超长限制异常类
|
||||
*
|
||||
* @author xzg
|
||||
*/
|
||||
public class FileNameLengthLimitExceededException extends FileException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FileNameLengthLimitExceededException(int defaultFileNameLength)
|
||||
{
|
||||
super("upload.filename.exceed.length", new Object[] { defaultFileNameLength });
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.shxy.xymanager_common.exception.file;
|
||||
|
||||
/**
|
||||
* 文件名大小限制异常类
|
||||
*
|
||||
* @author xzg
|
||||
*/
|
||||
public class FileSizeLimitExceededException extends FileException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FileSizeLimitExceededException(long defaultMaxSize)
|
||||
{
|
||||
super("upload.exceed.maxSize", new Object[] { defaultMaxSize });
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.shxy.xymanager_common.exception.file;
|
||||
|
||||
|
||||
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 文件上传 误异常类
|
||||
*
|
||||
* @author xzg
|
||||
*/
|
||||
public class InvalidExtensionException extends FileUploadException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String[] allowedExtension;
|
||||
private String extension;
|
||||
private String filename;
|
||||
|
||||
public InvalidExtensionException(String[] allowedExtension, String extension, String filename)
|
||||
{
|
||||
super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
|
||||
this.allowedExtension = allowedExtension;
|
||||
this.extension = extension;
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public String[] getAllowedExtension()
|
||||
{
|
||||
return allowedExtension;
|
||||
}
|
||||
|
||||
public String getExtension()
|
||||
{
|
||||
return extension;
|
||||
}
|
||||
|
||||
public String getFilename()
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
public static class InvalidImageExtensionException extends InvalidExtensionException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename)
|
||||
{
|
||||
super(allowedExtension, extension, filename);
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidFlashExtensionException extends InvalidExtensionException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename)
|
||||
{
|
||||
super(allowedExtension, extension, filename);
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidMediaExtensionException extends InvalidExtensionException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename)
|
||||
{
|
||||
super(allowedExtension, extension, filename);
|
||||
}
|
||||
}
|
||||
|
||||
public static class InvalidVideoExtensionException extends InvalidExtensionException
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename)
|
||||
{
|
||||
super(allowedExtension, extension, filename);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.shxy.xymanager_common.page;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.shxy.xymanager_common.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 分页数据
|
||||
*
|
||||
* @author 晶晶
|
||||
*/
|
||||
public class PageDomain {
|
||||
/**
|
||||
* 当前记录起始索引
|
||||
*/
|
||||
private Integer pageNum;
|
||||
|
||||
/**
|
||||
* 每页显示记录数
|
||||
*/
|
||||
private Integer pageSize;
|
||||
|
||||
/**
|
||||
* 排序列
|
||||
*/
|
||||
private String orderByColumn;
|
||||
|
||||
/**
|
||||
* 排序的方向desc或者asc
|
||||
*/
|
||||
private String isAsc = "asc";
|
||||
|
||||
/**
|
||||
* 分页参数合理化
|
||||
*/
|
||||
private Boolean reasonable = true;
|
||||
|
||||
public String getOrderBy() {
|
||||
if (StrUtil.isEmpty(orderByColumn)) {
|
||||
return "";
|
||||
}
|
||||
return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;
|
||||
}
|
||||
|
||||
public Integer getPageNum() {
|
||||
return pageNum;
|
||||
}
|
||||
|
||||
public void setPageNum(Integer pageNum) {
|
||||
this.pageNum = pageNum;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public String getOrderByColumn() {
|
||||
return orderByColumn;
|
||||
}
|
||||
|
||||
public void setOrderByColumn(String orderByColumn) {
|
||||
this.orderByColumn = orderByColumn;
|
||||
}
|
||||
|
||||
public String getIsAsc() {
|
||||
return isAsc;
|
||||
}
|
||||
|
||||
public void setIsAsc(String isAsc) {
|
||||
if (StringUtils.isNotEmpty(isAsc)) {
|
||||
// 兼容前端排序类型
|
||||
if ("ascending".equals(isAsc)) {
|
||||
isAsc = "asc";
|
||||
} else if ("descending".equals(isAsc)) {
|
||||
isAsc = "desc";
|
||||
}
|
||||
this.isAsc = isAsc;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean getReasonable() {
|
||||
if (StringUtils.isNull(reasonable)) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return reasonable;
|
||||
}
|
||||
|
||||
public void setReasonable(Boolean reasonable) {
|
||||
this.reasonable = reasonable;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.shxy.xymanager_common.page;
|
||||
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.shxy.xymanager_common.util.StringUtils;
|
||||
import com.shxy.xymanager_common.util.http.HttpStatus;
|
||||
import com.shxy.xymanager_common.util.sql.SqlUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PageUtils {
|
||||
/**
|
||||
* 设置请求分页数据
|
||||
*/
|
||||
public static void startPage() {
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
Integer pageNum = pageDomain.getPageNum();
|
||||
Integer pageSize = pageDomain.getPageSize();
|
||||
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
|
||||
String orderBy = SqlUtils.escapeOrderBySql(pageDomain.getOrderBy());
|
||||
Boolean reasonable = pageDomain.getReasonable();
|
||||
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求分页数据
|
||||
*/
|
||||
public static void SetPage(int pagenum, int pagesize) {
|
||||
PageHelper.startPage(pagenum, pagesize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化查询的数据
|
||||
*/
|
||||
public static PageInfo getPageData(List list) {
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置请求排序数据
|
||||
*/
|
||||
public static void startOrderBy() {
|
||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
||||
if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) {
|
||||
String orderBy = SqlUtils.escapeOrderBySql(pageDomain.getOrderBy());
|
||||
PageHelper.orderBy(orderBy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应请求分页数据
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static TableDataInfo getDataTable(List<?> list) {
|
||||
TableDataInfo rspData = new TableDataInfo();
|
||||
rspData.setCode(HttpStatus.HTTP_OK);
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setRows(list);
|
||||
rspData.setTotal(new PageInfo(list).getTotal());
|
||||
return rspData;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.shxy.xymanager_common.page;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 表格分页数据对象
|
||||
*
|
||||
* @author 晶晶
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "批量查询接口返回", description = "接口响应返回")
|
||||
public class TableDataInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
private long total;
|
||||
|
||||
/**
|
||||
* 列表数据
|
||||
*/
|
||||
private List<?> rows;
|
||||
|
||||
/**
|
||||
* 消息状态码
|
||||
*/
|
||||
private int code;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 表格数据对象
|
||||
*/
|
||||
public TableDataInfo() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
*/
|
||||
public TableDataInfo(List<?> list, int total) {
|
||||
this.rows = list;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<?> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<?> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.shxy.xymanager_common.page;
|
||||
|
||||
|
||||
import com.shxy.xymanager_common.util.ServletUtils;
|
||||
|
||||
/**
|
||||
* 表格数据处理
|
||||
*
|
||||
* @author xzg
|
||||
*/
|
||||
public class TableSupport {
|
||||
/**
|
||||
* 当前记录起始索引
|
||||
*/
|
||||
public static final String PAGE_NUM = "pageNum";
|
||||
|
||||
/**
|
||||
* 每页显示记录数
|
||||
*/
|
||||
public static final String PAGE_SIZE = "pageSize";
|
||||
|
||||
/**
|
||||
* 排序列
|
||||
*/
|
||||
public static final String ORDER_BY_COLUMN = "orderByColumn";
|
||||
|
||||
/**
|
||||
* 排序的方向 "desc" 或者 "asc".
|
||||
*/
|
||||
public static final String IS_ASC = "isAsc";
|
||||
|
||||
/**
|
||||
* 分页参数合理化
|
||||
*/
|
||||
public static final String REASONABLE = "reasonable";
|
||||
|
||||
/**
|
||||
* 封装分页对象
|
||||
*/
|
||||
public static PageDomain getPageDomain() {
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(ServletUtils.getParameterToInt(PAGE_NUM));
|
||||
pageDomain.setPageSize(ServletUtils.getParameterToInt(PAGE_SIZE));
|
||||
pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
|
||||
pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
|
||||
pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
|
||||
return pageDomain;
|
||||
}
|
||||
|
||||
public static PageDomain buildPageRequest() {
|
||||
return getPageDomain();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.shxy.xymanager_common;
|
||||
package com.shxy.xymanager_common.util;
|
||||
|
||||
import com.shxy.xymanager_common.util.StringUtils;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.shxy.xymanager_common;
|
||||
package com.shxy.xymanager_common.util;
|
||||
|
||||
import com.shxy.xymanager_common.util.CharsetKit;
|
||||
import com.shxy.xymanager_common.util.StringUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.shxy.xymanager_common.util;
|
||||
|
||||
import com.shxy.xymanager_common.util.spring.SpringUtils;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
/**
|
||||
* 获取i18n资源文件
|
||||
*
|
||||
* @author xzg
|
||||
*/
|
||||
public class MessageUtils
|
||||
{
|
||||
/**
|
||||
* 根据消息键和参数 获取消息 委托给spring messageSource
|
||||
*
|
||||
* @param code 消息键
|
||||
* @param args 参数
|
||||
* @return 获取国际化翻译值
|
||||
*/
|
||||
public static String message(String code, Object... args)
|
||||
{
|
||||
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
|
||||
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package com.shxy.xymanager_common;
|
||||
package com.shxy.xymanager_common.util;
|
||||
|
||||
import com.shxy.xymanager_common.util.StringUtils;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
@ -1,6 +1,4 @@
|
||||
package com.shxy.xymanager_common;
|
||||
|
||||
import com.shxy.xymanager_common.util.StringUtils;
|
||||
package com.shxy.xymanager_common.util;
|
||||
|
||||
/**
|
||||
* 字符串格式化
|
@ -0,0 +1,48 @@
|
||||
package com.shxy.xymanager_common.util.http;
|
||||
|
||||
public class HttpStatus {
|
||||
public static final int HTTP_OK = 200;
|
||||
public static final int HTTP_CREATED = 201;
|
||||
public static final int HTTP_ACCEPTED = 202;
|
||||
public static final int HTTP_NOT_AUTHORITATIVE = 203;
|
||||
public static final int HTTP_NO_CONTENT = 204;
|
||||
public static final int HTTP_RESET = 205;
|
||||
public static final int HTTP_PARTIAL = 206;
|
||||
public static final int HTTP_MULT_CHOICE = 300;
|
||||
public static final int HTTP_MOVED_PERM = 301;
|
||||
public static final int HTTP_MOVED_TEMP = 302;
|
||||
public static final int HTTP_SEE_OTHER = 303;
|
||||
public static final int HTTP_NOT_MODIFIED = 304;
|
||||
public static final int HTTP_USE_PROXY = 305;
|
||||
public static final int HTTP_TEMP_REDIRECT = 307;
|
||||
public static final int HTTP_PERMANENT_REDIRECT = 308;
|
||||
public static final int HTTP_BAD_REQUEST = 400;
|
||||
public static final int HTTP_UNAUTHORIZED = 401;
|
||||
public static final int HTTP_PAYMENT_REQUIRED = 402;
|
||||
public static final int HTTP_FORBIDDEN = 403;
|
||||
public static final int HTTP_NOT_FOUND = 404;
|
||||
public static final int HTTP_BAD_METHOD = 405;
|
||||
public static final int HTTP_NOT_ACCEPTABLE = 406;
|
||||
public static final int HTTP_PROXY_AUTH = 407;
|
||||
public static final int HTTP_CLIENT_TIMEOUT = 408;
|
||||
public static final int HTTP_CONFLICT = 409;
|
||||
public static final int HTTP_GONE = 410;
|
||||
public static final int HTTP_LENGTH_REQUIRED = 411;
|
||||
public static final int HTTP_PRECON_FAILED = 412;
|
||||
public static final int HTTP_ENTITY_TOO_LARGE = 413;
|
||||
public static final int HTTP_REQ_TOO_LONG = 414;
|
||||
public static final int HTTP_UNSUPPORTED_TYPE = 415;
|
||||
public static final int HTTP_INTERNAL_ERROR = 500;
|
||||
public static final int HTTP_NOT_IMPLEMENTED = 501;
|
||||
public static final int HTTP_BAD_GATEWAY = 502;
|
||||
public static final int HTTP_UNAVAILABLE = 503;
|
||||
public static final int HTTP_GATEWAY_TIMEOUT = 504;
|
||||
public static final int HTTP_VERSION = 505;
|
||||
|
||||
public HttpStatus() {
|
||||
}
|
||||
|
||||
public static boolean isRedirected(int responseCode) {
|
||||
return responseCode == 301 || responseCode == 302 || responseCode == 303 || responseCode == 307 || responseCode == 308;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.shxy.xymanager_service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.shxy.xymanager_common.bean.ServiceBody;
|
||||
import com.shxy.xymanager_common.entity.Terminals;
|
||||
import com.shxy.xymanager_common.exception.Asserts;
|
||||
import com.shxy.xymanager_common.model.TerminalListModel;
|
||||
import com.shxy.xymanager_dao.dao.TerminalsDao;
|
||||
import com.shxy.xymanager_service.service.TerminalService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 设备服务实现层
|
||||
*
|
||||
* @author 晶晶
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TerminalServiceImpl implements TerminalService {
|
||||
|
||||
@Autowired
|
||||
private TerminalsDao terminalsDao;
|
||||
|
||||
/**
|
||||
* 提交建议
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ServiceBody<TerminalListModel> getTerminalList() {
|
||||
TerminalListModel terminalListModel = new TerminalListModel();
|
||||
List<Terminals> terminals = terminalsDao.selectAll();
|
||||
boolean empty = CollectionUtil.isEmpty(terminals);
|
||||
if (empty) {
|
||||
terminalListModel.setTerminalBeanList(new ArrayList<>());
|
||||
} else {
|
||||
List<TerminalListModel.TerminalBean> list = BeanUtil.copyToList(terminals, TerminalListModel.TerminalBean.class, CopyOptions.create().ignoreCase());
|
||||
terminalListModel.setTerminalBeanList(list);
|
||||
}
|
||||
return Asserts.success(terminalListModel);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.shxy.xymanager_service.service;
|
||||
|
||||
import com.shxy.xymanager_common.bean.ServiceBody;
|
||||
import com.shxy.xymanager_common.model.TerminalListModel;
|
||||
|
||||
/**
|
||||
* 设备接口
|
||||
*
|
||||
* @author 晶晶
|
||||
*/
|
||||
public interface TerminalService {
|
||||
/**
|
||||
* 获取所有设备接口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
ServiceBody<TerminalListModel> getTerminalList();
|
||||
|
||||
}
|
Loading…
Reference in New Issue