♻️ Refactoring code.wrapper result of controller with R except activiti project

This commit is contained in:
lishangbu committed 2018-11-18 03:06:09 +08:00
1 parent fa01371f09
commit 7c614bc5bf
19 files changed
+91 -105

No files matched your search

@@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.plugins.Page;
import com.pig4cloud.pigx.codegen.entity.GenConfig;
import com.pig4cloud.pigx.codegen.service.SysGeneratorService;
import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
@@ -48,10 +49,9 @@ public class SysGeneratorController {
* @return 数据库表
*/
@GetMapping("/page")
public Page list(@RequestParam Map<String, Object> params) {
public R<Page> list(@RequestParam Map<String, Object> params) {
Query query = new Query(params);
query.setRecords(sysGeneratorService.queryPage(query));
return query;
return new R<>(query.setRecords(sysGeneratorService.queryPage(query)));
}
/**
@@ -1,5 +1,6 @@
package ${package}.${moduleName}.controller;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.plugins.Page;
@@ -19,9 +20,9 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/${pathName}")
@AllArgsConstructor
public class ${className}Controller {
@Autowired
private ${className}Service ${classname}Service;
private final ${className}Service ${classname}Service;
/**
@@ -30,8 +31,8 @@ public class ${className}Controller {
* @return
*/
@GetMapping("/page")
public Page page(@RequestParam Map<String, Object> params) {
return ${classname}Service.selectPage(new Query<>(params), new EntityWrapper<>());
public R<Page> page(@RequestParam Map<String, Object> params) {
return new R<>(${classname}Service.selectPage(new Query<>(params), new EntityWrapper<>()));
}
@@ -41,9 +42,8 @@ public class ${className}Controller {
* @return R
*/
@GetMapping("/{${pk.lowerAttrName}}")
public R info(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
${className} ${classname} = ${classname}Service.selectById(${pk.lowerAttrName});
return new R<>(${classname});
public R get${className}ById(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.selectById(${pk.lowerAttrName}));
}
/**
@@ -52,7 +52,7 @@ public class ${className}Controller {
* @return R
*/
@PostMapping
public R save(@RequestBody ${className} ${classname}){
public R save${className}(@RequestBody ${className} ${classname}){
return new R<>(${classname}Service.insert(${classname}));
}
@@ -62,7 +62,7 @@ public class ${className}Controller {
* @return R
*/
@PutMapping
public R update(@RequestBody ${className} ${classname}){
public R update${className}(@RequestBody ${className} ${classname}){
${classname}Service.updateById(${classname});
return new R<>(Boolean.TRUE);
}
@@ -73,7 +73,7 @@ public class ${className}Controller {
* @return R
*/
@DeleteMapping("/{${pk.lowerAttrName}}")
public R delete(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){
public R delete${className}ById(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.deleteById(${pk.lowerAttrName}));
}
@@ -27,7 +27,7 @@ export function fetchList(query) {
export function addObj(obj) {
return request({
url: '/${moduleName}/${pathName}/',
url: '/${moduleName}/${pathName}',
method: 'post',
data: obj
})
@@ -49,7 +49,7 @@ export function delObj(id) {
export function putObj(obj) {
return request({
url: '/${moduleName}/${pathName}/',
url: '/${moduleName}/${pathName}',
method: 'put',
data: obj
})
@@ -23,7 +23,7 @@ import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.daemon.entity.ExecutionLog;
import com.pig4cloud.pigx.daemon.service.ExecutionLogService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@@ -35,9 +35,10 @@ import java.util.Map;
*/
@RestController
@RequestMapping("/executionlog")
@AllArgsConstructor
public class ExecutionLogController {
@Autowired
private ExecutionLogService executionLogService;
private final ExecutionLogService executionLogService;
/**
@@ -47,8 +48,8 @@ public class ExecutionLogController {
* @return
*/
@GetMapping("/page")
public Page page(@RequestParam Map<String, Object> params) {
return executionLogService.selectPage(new Query<>(params), new EntityWrapper<>());
public R<Page> page(@RequestParam Map<String, Object> params) {
return new R<>(executionLogService.selectPage(new Query<>(params), new EntityWrapper<>()));
}
@@ -59,10 +60,8 @@ public class ExecutionLogController {
* @return R
*/
@GetMapping("/{id}")
public R info(@PathVariable("id") String id) {
ExecutionLog executionLog = executionLogService.selectById(id);
return new R<>(executionLog);
public R<ExecutionLog> info(@PathVariable("id") String id) {
return new R<>(executionLogService.selectById(id));
}
/**
@@ -71,11 +70,9 @@ public class ExecutionLogController {
* @param executionLog
* @return R
*/
@PostMapping("/save")
public R save(@RequestBody ExecutionLog executionLog) {
executionLogService.insert(executionLog);
return new R<>(Boolean.TRUE);
@PostMapping
public R<Boolean> save(@RequestBody ExecutionLog executionLog) {
return new R<>(executionLogService.insert(executionLog));
}
/**
@@ -84,11 +81,9 @@ public class ExecutionLogController {
* @param executionLog
* @return R
*/
@PutMapping("/update")
public R update(@RequestBody ExecutionLog executionLog) {
executionLogService.updateById(executionLog);
return new R<>(Boolean.TRUE);
@PutMapping
public R<Boolean> update(@RequestBody ExecutionLog executionLog) {
return new R<>(executionLogService.updateById(executionLog));
}
/**
@@ -98,8 +93,7 @@ public class ExecutionLogController {
* @return R
*/
@DeleteMapping("/{id}")
public R delete(@PathVariable String id) {
public R<Boolean> delete(@PathVariable String id) {
return new R<>(executionLogService.deleteById(id));
}
@@ -23,7 +23,7 @@ import com.pig4cloud.pigx.common.core.util.Query;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.daemon.entity.StatusTraceLog;
import com.pig4cloud.pigx.daemon.service.StatusTraceLogService;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@@ -34,11 +34,10 @@ import java.util.Map;
* @date 2018-08-03 22:15:45
*/
@RestController
@AllArgsConstructor
@RequestMapping("/statustracelog")
public class StatusTraceLogController {
@Autowired
private StatusTraceLogService statusTraceLogService;
private final StatusTraceLogService statusTraceLogService;
/**
* 列表
@@ -47,8 +46,8 @@ public class StatusTraceLogController {
* @return
*/
@GetMapping("/page")
public Page page(@RequestParam Map<String, Object> params) {
return statusTraceLogService.selectPage(new Query<>(params), new EntityWrapper<>());
public R<Page> page(@RequestParam Map<String, Object> params) {
return new R<>(statusTraceLogService.selectPage(new Query<>(params), new EntityWrapper<>()));
}
@@ -59,10 +58,8 @@ public class StatusTraceLogController {
* @return R
*/
@GetMapping("/{id}")
public R info(@PathVariable("id") String id) {
StatusTraceLog statusTraceLog = statusTraceLogService.selectById(id);
return new R<>(statusTraceLog);
public R<StatusTraceLog> info(@PathVariable("id") String id) {
return new R<>(statusTraceLogService.selectById(id));
}
/**
@@ -71,11 +68,9 @@ public class StatusTraceLogController {
* @param statusTraceLog
* @return R
*/
@PostMapping("/save")
public R save(@RequestBody StatusTraceLog statusTraceLog) {
statusTraceLogService.insert(statusTraceLog);
return new R<>(Boolean.TRUE);
@PostMapping
public R<Boolean> save(@RequestBody StatusTraceLog statusTraceLog) {
return new R<>(statusTraceLogService.insert(statusTraceLog));
}
/**
@@ -84,11 +79,9 @@ public class StatusTraceLogController {
* @param statusTraceLog
* @return R
*/
@PutMapping("/update")
public R update(@RequestBody StatusTraceLog statusTraceLog) {
statusTraceLogService.updateById(statusTraceLog);
return new R<>(Boolean.TRUE);
@PutMapping
public R<Boolean> update(@RequestBody StatusTraceLog statusTraceLog) {
return new R<>(statusTraceLogService.updateById(statusTraceLog));
}
/**
@@ -98,7 +91,7 @@ public class StatusTraceLogController {
* @return R
*/
@DeleteMapping("/{id}")
public R delete(@PathVariable("id") String id) {
public R<Boolean> delete(@PathVariable("id") String id) {
return new R<>(statusTraceLogService.deleteById(id));
}
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
public class DemoController {
@GetMapping("/")
@GetMapping("/user")
public Authentication user(Authentication authentication) {
return authentication;
}