|
@@ -5,6 +5,8 @@ import edu.travel.interfaces.InsertGroups;
|
|
|
import edu.travel.interfaces.UpdateGroups;
|
|
|
import edu.travel.resp.BaseResponse;
|
|
|
import edu.travel.resp.PageResponse;
|
|
|
+import edu.travel.rpc.RPCBaseResponse;
|
|
|
+import edu.travel.rpc.RPCPageResponse;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.http.HttpStatus;
|
|
@@ -21,50 +23,49 @@ import java.util.List;
|
|
|
|
|
|
public class BaseController<T> {
|
|
|
@Autowired
|
|
|
- @Lazy
|
|
|
private IService<T> service;
|
|
|
@GetMapping("/getById")
|
|
|
- public BaseResponse getById(String id) {
|
|
|
+ public RPCBaseResponse getById(String id) {
|
|
|
T byId = service.getById(id);
|
|
|
- return PageResponse.out(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), byId);
|
|
|
+ return new RPCBaseResponse(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), byId);
|
|
|
}
|
|
|
@PostMapping("/updateById")
|
|
|
@Transactional
|
|
|
- public BaseResponse<T> updateTargetById(@RequestBody T entity) {
|
|
|
+ public RPCBaseResponse<T> updateTargetById(@RequestBody T entity) {
|
|
|
boolean update = service.updateById(entity);
|
|
|
if (update) {
|
|
|
- return PageResponse.out(200,"success",entity);
|
|
|
+ return new RPCBaseResponse<>(200,"success",entity);
|
|
|
}
|
|
|
- return PageResponse.out(500,"error",entity);
|
|
|
+ return new RPCBaseResponse(500,"error",entity);
|
|
|
}
|
|
|
@PostMapping("/save")
|
|
|
@Transactional
|
|
|
- public BaseResponse<T> saveTarget(@RequestBody T entity) {
|
|
|
+ public RPCBaseResponse<T> saveTarget(@RequestBody T entity) {
|
|
|
boolean save = service.save(entity);
|
|
|
if (save) {
|
|
|
- return PageResponse.out(200,"success",entity);
|
|
|
+ return new RPCBaseResponse<>(200,"success",entity);
|
|
|
}
|
|
|
- return PageResponse.out(500,"error",entity);
|
|
|
+ return new RPCBaseResponse<>(500,"error",entity);
|
|
|
}
|
|
|
@PostMapping("/deleteById")
|
|
|
@Transactional
|
|
|
- public BaseResponse<T> deleteTargetById(@RequestBody List<String> ids) {
|
|
|
+ public RPCBaseResponse<T> deleteTargetById(@RequestBody List<String> ids) {
|
|
|
if (ids == null || ids.isEmpty()) {
|
|
|
- return PageResponse.out(404,"error,not found delete data",null);
|
|
|
+ return new RPCBaseResponse<>(404,"error,not found delete data",null);
|
|
|
}
|
|
|
boolean byIds = service.removeByIds(ids);
|
|
|
if (byIds) {
|
|
|
- return PageResponse.out(200,"success",null);
|
|
|
+ return new RPCBaseResponse<>(200,"success",null);
|
|
|
}
|
|
|
- return PageResponse.out(500,"error, delete data error",null);
|
|
|
+ return new RPCBaseResponse<>(500,"error, delete data error",null);
|
|
|
}
|
|
|
@GetMapping("/list")
|
|
|
- public BaseResponse<List<T>> listAll() {
|
|
|
+ public RPCBaseResponse<List<T>> listAll() {
|
|
|
List<T> list = service.list();
|
|
|
if (list.isEmpty()) {
|
|
|
- return PageResponse.out(404,"error,not found delete data",null);
|
|
|
+ return new RPCBaseResponse<>(404,"error,not found delete data",null);
|
|
|
}
|
|
|
- return PageResponse.out(200,"success",list);
|
|
|
+ return new RPCBaseResponse<>(200,"success",list);
|
|
|
}
|
|
|
|
|
|
|