diff --git a/src/main/java/com/zsc/edu/gateway/framework/response/GlobalResponseHandler.java b/src/main/java/com/zsc/edu/gateway/framework/response/GlobalResponseHandler.java index 9cee782..3de9f59 100644 --- a/src/main/java/com/zsc/edu/gateway/framework/response/GlobalResponseHandler.java +++ b/src/main/java/com/zsc/edu/gateway/framework/response/GlobalResponseHandler.java @@ -1,61 +1,61 @@ -package com.zsc.edu.gateway.framework.response; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.core.MethodParameter; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.server.ServerHttpRequest; -import org.springframework.http.server.ServerHttpResponse; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; - -/** - * 响应统一封装 - *

- * 将响应数据,封装成统一的数据格式。 - *

- * 通过本处理器,将接口方法返回的数据,统一封装到 ResponseResult 的 data 字段中,如果接口方法返回为 void,则 data 字段的值为 null。 - * - * @author zhuang - */ -@Slf4j -@RestControllerAdvice(basePackages = "com.zsc.edu.gateway") -public class GlobalResponseHandler implements ResponseBodyAdvice { - - /** - * 此组件是否支持给定的控制器方法返回类型和选定的 {@code HttpMessageConverter} 类型。 - * - * @return 如果应该调用 {@link #beforeBodyWrite} ,则为 {@code true};否则为false。 - */ - @Override - public boolean supports(MethodParameter returnType, Class> converterType) { - // 返回类型不为ResponseResult,才需要封装 - return returnType.getParameterType() != ResponseResult.class; - } - - /** - * 统一封装返回响应数据 - */ - @Override - public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, - Class> selectedConverterType, ServerHttpRequest request, - ServerHttpResponse response) { - - // 数据封装为ResponseResult:将接口方法返回的数据,封装到 ResponseResult.data 字段中。 - ResponseResult responseResult = ResponseResult.success(body); - - // 返回类型不是 String:直接返回 - if (returnType.getParameterType() != String.class) { - return responseResult; - } - - // 返回类型是 String:不能直接返回,需要进行额外处理 - // 1. 将 Content-Type 设为 application/json ;返回类型是String时,默认 Content-Type = text/plain - HttpHeaders headers = response.getHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - // 2. 将 ResponseResult 转为 Json字符串 再返回 - // (否则会报错 java.lang.ClassCastException: com.example.core.model.ResponseResult cannot be cast to java.lang.String) - return JsonUtil.toJson(responseResult); - } -} +//package com.zsc.edu.gateway.framework.response; +// +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.core.MethodParameter; +//import org.springframework.http.HttpHeaders; +//import org.springframework.http.MediaType; +//import org.springframework.http.converter.HttpMessageConverter; +//import org.springframework.http.server.ServerHttpRequest; +//import org.springframework.http.server.ServerHttpResponse; +//import org.springframework.web.bind.annotation.RestControllerAdvice; +//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; +// +///** +// * 响应统一封装 +// *

+// * 将响应数据,封装成统一的数据格式。 +// *

+// * 通过本处理器,将接口方法返回的数据,统一封装到 ResponseResult 的 data 字段中,如果接口方法返回为 void,则 data 字段的值为 null。 +// * +// * @author zhuang +// */ +//@Slf4j +//@RestControllerAdvice(basePackages = "com.zsc.edu.gateway") +//public class GlobalResponseHandler implements ResponseBodyAdvice { +// +// /** +// * 此组件是否支持给定的控制器方法返回类型和选定的 {@code HttpMessageConverter} 类型。 +// * +// * @return 如果应该调用 {@link #beforeBodyWrite} ,则为 {@code true};否则为false。 +// */ +// @Override +// public boolean supports(MethodParameter returnType, Class> converterType) { +// // 返回类型不为ResponseResult,才需要封装 +// return returnType.getParameterType() != ResponseResult.class; +// } +// +// /** +// * 统一封装返回响应数据 +// */ +// @Override +// public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, +// Class> selectedConverterType, ServerHttpRequest request, +// ServerHttpResponse response) { +// +// // 数据封装为ResponseResult:将接口方法返回的数据,封装到 ResponseResult.data 字段中。 +// ResponseResult responseResult = ResponseResult.success(body); +// +// // 返回类型不是 String:直接返回 +// if (returnType.getParameterType() != String.class) { +// return responseResult; +// } +// +// // 返回类型是 String:不能直接返回,需要进行额外处理 +// // 1. 将 Content-Type 设为 application/json ;返回类型是String时,默认 Content-Type = text/plain +// HttpHeaders headers = response.getHeaders(); +// headers.setContentType(MediaType.APPLICATION_JSON); +// // 2. 将 ResponseResult 转为 Json字符串 再返回 +// // (否则会报错 java.lang.ClassCastException: com.example.core.model.ResponseResult cannot be cast to java.lang.String) +// return JsonUtil.toJson(responseResult); +// } +//} diff --git a/src/main/java/com/zsc/edu/gateway/framework/response/ResponseResult.java b/src/main/java/com/zsc/edu/gateway/framework/response/ResponseResult.java index dd8ca08..654aaaf 100644 --- a/src/main/java/com/zsc/edu/gateway/framework/response/ResponseResult.java +++ b/src/main/java/com/zsc/edu/gateway/framework/response/ResponseResult.java @@ -1,265 +1,265 @@ -package com.zsc.edu.gateway.framework.response; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * 返回结果集 - * - * @author javadog - **/ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class ResponseResult { - -//TODO 返回封装处理 - /** - * 状态码 - */ - private Integer code; - - /** - * 状态信息 - */ - private Boolean status; - - /** - * 返回信息 - */ - private String message; - - /** - * 数据 - */ - private T data; - - /** - * 全参数方法 - * - * @param code 状态码 - * @param status 状态 - * @param message 返回信息 - * @param data 返回数据 - * @param 泛型 - * @return {@link ResponseResult} - */ - private static ResponseResult response(Integer code, Boolean status, String message, T data) { - - - ResponseResult responseResult = new ResponseResult<>(); - responseResult.setCode(code); - responseResult.setStatus(status); - responseResult.setMessage(message); - responseResult.setData(data); - return responseResult; - } - - /** - * 全参数方法 - * - * @param code 状态码 - * @param status 状态 - * @param message 返回信息 - * @param 泛型 - * @return {@link ResponseResult} - */ - private static ResponseResult response(Integer code, Boolean status, String message) { - - - ResponseResult responseResult = new ResponseResult<>(); - responseResult.setCode(code); - responseResult.setStatus(status); - responseResult.setMessage(message); - return responseResult; - } - - /** - * 成功返回(无参) - * - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult success() { - -// return response(HttpStatus.OK.value(), true, HttpStatus.OK.getReasonPhrase(), null); - return response(HttpStatusEnum.SUCCESS.getCode(), true, HttpStatusEnum.SUCCESS.getMessage(), null); - } - - /** - * 成功返回(枚举参数) - * - * @param httpResponseEnum 枚举参数 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult success(HttpStatusEnum httpResponseEnum) { - - - return response(httpResponseEnum.getCode(), true, httpResponseEnum.getMessage()); - } - - /** - * 成功返回(状态码+返回信息) - * - * @param code 状态码 - * @param message 返回信息 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult success(Integer code, String message) { - - - return response(code, true, message); - } - - /** - * 成功返回(返回信息 + 数据) - * - * @param message 返回信息 - * @param data 数据 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult success(String message, T data) { - - - return response(HttpStatusEnum.SUCCESS.getCode(), true, message, data); - } - - /** - * 成功返回(状态码+返回信息+数据) - * - * @param code 状态码 - * @param message 返回信息 - * @param data 数据 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult success(Integer code, String message, T data) { - - - return response(code, true, message, data); - } - - /** - * 成功返回(数据) - * - * @param data 数据 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult success(T data) { - - - return response(HttpStatusEnum.SUCCESS.getCode(), true, HttpStatusEnum.SUCCESS.getMessage(), data); - } - - /** - * 成功返回(返回信息) - * - * @param message 返回信息 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult success(String message) { - - - return response(HttpStatusEnum.SUCCESS.getCode(), true, message, null); - } - - /** - * 失败返回(无参) - * - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult fail() { - - - return response(HttpStatusEnum.ERROR.getCode(), false, HttpStatusEnum.ERROR.getMessage(), null); - } - - /** - * 失败返回(枚举) - * - * @param httpResponseEnum 枚举 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult fail(HttpStatusEnum httpResponseEnum) { - - - return response(httpResponseEnum.getCode(), false, httpResponseEnum.getMessage()); - } - - /** - * 失败返回(状态码+返回信息) - * - * @param code 状态码 - * @param message 返回信息 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult fail(Integer code, String message) { - - - return response(code, false, message); - } - - /** - * 失败返回(返回信息+数据) - * - * @param message 返回信息 - * @param data 数据 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult fail(String message, T data) { - - - return response(HttpStatusEnum.ERROR.getCode(), false, message, data); - } - - /** - * 失败返回(状态码+返回信息+数据) - * - * @param code 状态码 - * @param message 返回消息 - * @param data 数据 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult fail(Integer code, String message, T data) { - - - return response(code, false, message, data); - } - - /** - * 失败返回(数据) - * - * @param data 数据 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult fail(T data) { - - - return response(HttpStatusEnum.ERROR.getCode(), false, HttpStatusEnum.ERROR.getMessage(), data); - } - - /** - * 失败返回(返回信息) - * - * @param message 返回信息 - * @param 泛型 - * @return {@link ResponseResult} - */ - public static ResponseResult fail(String message) { - - - return response(HttpStatusEnum.ERROR.getCode(), false, message, null); - } -} +//package com.zsc.edu.gateway.framework.response; +// +//import lombok.AllArgsConstructor; +//import lombok.Data; +//import lombok.NoArgsConstructor; +// +///** +// * 返回结果集 +// * +// * @author javadog +// **/ +//@Data +//@AllArgsConstructor +//@NoArgsConstructor +//public class ResponseResult { +// +////TODO 返回封装处理 +// /** +// * 状态码 +// */ +// private Integer code; +// +// /** +// * 状态信息 +// */ +// private Boolean status; +// +// /** +// * 返回信息 +// */ +// private String message; +// +// /** +// * 数据 +// */ +// private T data; +// +// /** +// * 全参数方法 +// * +// * @param code 状态码 +// * @param status 状态 +// * @param message 返回信息 +// * @param data 返回数据 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// private static ResponseResult response(Integer code, Boolean status, String message, T data) { +// +// +// ResponseResult responseResult = new ResponseResult<>(); +// responseResult.setCode(code); +// responseResult.setStatus(status); +// responseResult.setMessage(message); +// responseResult.setData(data); +// return responseResult; +// } +// +// /** +// * 全参数方法 +// * +// * @param code 状态码 +// * @param status 状态 +// * @param message 返回信息 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// private static ResponseResult response(Integer code, Boolean status, String message) { +// +// +// ResponseResult responseResult = new ResponseResult<>(); +// responseResult.setCode(code); +// responseResult.setStatus(status); +// responseResult.setMessage(message); +// return responseResult; +// } +// +// /** +// * 成功返回(无参) +// * +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult success() { +// +//// return response(HttpStatus.OK.value(), true, HttpStatus.OK.getReasonPhrase(), null); +// return response(HttpStatusEnum.SUCCESS.getCode(), true, HttpStatusEnum.SUCCESS.getMessage(), null); +// } +// +// /** +// * 成功返回(枚举参数) +// * +// * @param httpResponseEnum 枚举参数 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult success(HttpStatusEnum httpResponseEnum) { +// +// +// return response(httpResponseEnum.getCode(), true, httpResponseEnum.getMessage()); +// } +// +// /** +// * 成功返回(状态码+返回信息) +// * +// * @param code 状态码 +// * @param message 返回信息 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult success(Integer code, String message) { +// +// +// return response(code, true, message); +// } +// +// /** +// * 成功返回(返回信息 + 数据) +// * +// * @param message 返回信息 +// * @param data 数据 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult success(String message, T data) { +// +// +// return response(HttpStatusEnum.SUCCESS.getCode(), true, message, data); +// } +// +// /** +// * 成功返回(状态码+返回信息+数据) +// * +// * @param code 状态码 +// * @param message 返回信息 +// * @param data 数据 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult success(Integer code, String message, T data) { +// +// +// return response(code, true, message, data); +// } +// +// /** +// * 成功返回(数据) +// * +// * @param data 数据 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult success(T data) { +// +// +// return response(HttpStatusEnum.SUCCESS.getCode(), true, HttpStatusEnum.SUCCESS.getMessage(), data); +// } +// +// /** +// * 成功返回(返回信息) +// * +// * @param message 返回信息 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult success(String message) { +// +// +// return response(HttpStatusEnum.SUCCESS.getCode(), true, message, null); +// } +// +// /** +// * 失败返回(无参) +// * +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult fail() { +// +// +// return response(HttpStatusEnum.ERROR.getCode(), false, HttpStatusEnum.ERROR.getMessage(), null); +// } +// +// /** +// * 失败返回(枚举) +// * +// * @param httpResponseEnum 枚举 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult fail(HttpStatusEnum httpResponseEnum) { +// +// +// return response(httpResponseEnum.getCode(), false, httpResponseEnum.getMessage()); +// } +// +// /** +// * 失败返回(状态码+返回信息) +// * +// * @param code 状态码 +// * @param message 返回信息 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult fail(Integer code, String message) { +// +// +// return response(code, false, message); +// } +// +// /** +// * 失败返回(返回信息+数据) +// * +// * @param message 返回信息 +// * @param data 数据 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult fail(String message, T data) { +// +// +// return response(HttpStatusEnum.ERROR.getCode(), false, message, data); +// } +// +// /** +// * 失败返回(状态码+返回信息+数据) +// * +// * @param code 状态码 +// * @param message 返回消息 +// * @param data 数据 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult fail(Integer code, String message, T data) { +// +// +// return response(code, false, message, data); +// } +// +// /** +// * 失败返回(数据) +// * +// * @param data 数据 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult fail(T data) { +// +// +// return response(HttpStatusEnum.ERROR.getCode(), false, HttpStatusEnum.ERROR.getMessage(), data); +// } +// +// /** +// * 失败返回(返回信息) +// * +// * @param message 返回信息 +// * @param 泛型 +// * @return {@link ResponseResult} +// */ +// public static ResponseResult fail(String message) { +// +// +// return response(HttpStatusEnum.ERROR.getCode(), false, message, null); +// } +//} diff --git a/src/main/java/com/zsc/edu/gateway/modules/attachment/controller/AttachmentController.java b/src/main/java/com/zsc/edu/gateway/modules/attachment/controller/AttachmentController.java index da6869b..25c1ecb 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/attachment/controller/AttachmentController.java +++ b/src/main/java/com/zsc/edu/gateway/modules/attachment/controller/AttachmentController.java @@ -100,6 +100,7 @@ public class AttachmentController { /** * 根据附件ID删除附件信息 */ + //TODO 上传时没有url @DeleteMapping("delete/{id}") public Boolean delete(@PathVariable("id") String id) { return service.removeById(id); diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/product/service/impl/ProductServiceImpl.java b/src/main/java/com/zsc/edu/gateway/modules/iot/product/service/impl/ProductServiceImpl.java index 4a9e783..522f074 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/product/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/product/service/impl/ProductServiceImpl.java @@ -61,7 +61,6 @@ public class ProductServiceImpl extends ServiceImpl productParamRepo.insert(productParams); return product; } - /** * 更新产品 */ @@ -98,7 +97,7 @@ public class ProductServiceImpl extends ServiceImpl /** * 分页查询产品 * - * @param query 查询表单 + * @param query 查询表单 * @param page 分页参数 */ @Override diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/record/service/impl/RecordServiceImpl.java b/src/main/java/com/zsc/edu/gateway/modules/iot/record/service/impl/RecordServiceImpl.java index 74a753f..75a6eb4 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/record/service/impl/RecordServiceImpl.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/record/service/impl/RecordServiceImpl.java @@ -23,13 +23,11 @@ import java.util.Optional; @Service public class RecordServiceImpl extends ServiceImpl implements RecordService { RedisUtils redisUtils; - @Override public Record create(Record record) { save(record); return record; } - @Override public List page(IPage page, String clientId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/mapper/ParamMapper.java b/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/mapper/ParamMapper.java index 3aeed26..cbb4c3f 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/mapper/ParamMapper.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/mapper/ParamMapper.java @@ -3,9 +3,6 @@ package com.zsc.edu.gateway.modules.iot.tsl.mapper; import com.zsc.edu.gateway.common.mapstruct.BaseMapper; import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto; import com.zsc.edu.gateway.modules.iot.tsl.entity.Param; -import org.mapstruct.Mapper; -import org.mapstruct.ReportingPolicy; -@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface ParamMapper extends BaseMapper { } diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/service/impl/EventServiceImpl.java b/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/service/impl/EventServiceImpl.java index e3e0720..14aee4f 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/service/impl/EventServiceImpl.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/service/impl/EventServiceImpl.java @@ -30,7 +30,6 @@ import java.util.List; @AllArgsConstructor public class EventServiceImpl extends ServiceImpl implements EventService { - private final EventMapper mapper; private final ParamMapper paramMapper; private final ParamRepository paramRepo; private final EventParamRepository eventParamRepo; @@ -104,7 +103,6 @@ public class EventServiceImpl extends ServiceImpl implem /** * 查询详情 - * * @param id Id * @return Event */ @@ -114,7 +112,7 @@ public class EventServiceImpl extends ServiceImpl implem } /** - * 删除 + *删除 */ @Override public boolean delete(Long id) { diff --git a/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/service/impl/ServeServiceImpl.java b/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/service/impl/ServeServiceImpl.java index a4c40d1..02e4d76 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/service/impl/ServeServiceImpl.java +++ b/src/main/java/com/zsc/edu/gateway/modules/iot/tsl/service/impl/ServeServiceImpl.java @@ -116,7 +116,6 @@ public class ServeServiceImpl extends ServiceImpl implem /** * 查询详情 - * * @param id 主键 * @return Serve */ @@ -124,7 +123,6 @@ public class ServeServiceImpl extends ServiceImpl implem public Serve detail(Long id) { return baseMapper.selectById(id); } - @Override public Boolean delete(Long id) { removeById(id); diff --git a/src/main/java/com/zsc/edu/gateway/modules/notice/service/impl/BulletinServiceImpl.java b/src/main/java/com/zsc/edu/gateway/modules/notice/service/impl/BulletinServiceImpl.java index 8e8c742..73576f1 100644 --- a/src/main/java/com/zsc/edu/gateway/modules/notice/service/impl/BulletinServiceImpl.java +++ b/src/main/java/com/zsc/edu/gateway/modules/notice/service/impl/BulletinServiceImpl.java @@ -93,6 +93,12 @@ public class BulletinServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(BulletinAttachment::getBulletinId, bulletin.getId()); + bulletinAttachmentRepository.delete(queryWrapper); + insertInto(bulletin.getId(), dto.getAttachmentIds()); + } return updateById(bulletin); } /** diff --git a/src/main/resources/db/gateway/public/iot_param.sql b/src/main/resources/db/gateway/public/iot_param.sql index 979ae41..5f8ace1 100644 --- a/src/main/resources/db/gateway/public/iot_param.sql +++ b/src/main/resources/db/gateway/public/iot_param.sql @@ -1,6 +1,6 @@ create table iot_param ( - id bigserial not null + id bigserial not null constraint iot_param_name_pk primary key, data_type integer, diff --git a/storage/attachment/8e68afa45f885d59b35fc2d0dec599fbaa7c3149 b/storage/attachment/8e68afa45f885d59b35fc2d0dec599fbaa7c3149 new file mode 100644 index 0000000..37d5479 Binary files /dev/null and b/storage/attachment/8e68afa45f885d59b35fc2d0dec599fbaa7c3149 differ