You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
5.1 KiB
138 lines
5.1 KiB
package {{ package.Controller }};
|
|
import {{ package.Entity }}.{{ table.entity }};
|
|
import {{ package.Service }}.{{ table.entity }}Service;
|
|
import {{ package.Common }}.vo.Result;
|
|
|
|
//--- import 固定引入 ---//
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.validation.Valid;
|
|
import java.util.List;
|
|
//--- import 固定引入 ---//
|
|
|
|
/**
|
|
* <p>
|
|
* {{ table.comment }} 前端控制器
|
|
* </p>
|
|
* @Author: {{author}}
|
|
* @Date: {{date}}
|
|
* @Wechat: {{ wechat }}
|
|
*/
|
|
@Api(tags = "{{ table.comment }}")
|
|
{% if restControllerStyle %}
|
|
@RestController
|
|
{% else %}
|
|
@Controller
|
|
{% endif %}
|
|
@RequestMapping("{{ table.tabToPath }}")
|
|
public class {{ table.entity }}Controller {
|
|
|
|
@Resource
|
|
private {{ table.entity }}Service {{table.lowerEntity}}Service;
|
|
|
|
@ApiOperation(value = "{{ table.comment }}分页列表查询", response = {{ table.entity }}.class)
|
|
@PostMapping(value = "/page")
|
|
public Result<Page<{{ table.entity }}>> page(@Valid @RequestBody {{ table.entity }} param,@RequestHeader("token") String token,
|
|
@RequestHeader(value = "version", defaultValue = "1.0") String version) {
|
|
Page<{{ table.entity }}> page = {{table.lowerEntity}}Service.page(param);
|
|
return Result.OK(page);
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "{{ table.comment }}根据条件查询")
|
|
@PostMapping(value = "/info")
|
|
public Result<Object> info(@Valid @RequestBody {{ table.entity }} param,
|
|
@RequestHeader("token") String token,
|
|
@RequestHeader(value = "version", defaultValue = "1.0") String version) {
|
|
if (token ==null) {
|
|
return Result.error("token不能为空");
|
|
}
|
|
{{ table.entity }} data = {{table.lowerEntity}}Service.info(param);
|
|
return Result.OK(data);
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "{{ table.comment }}新增")
|
|
@PostMapping(value = "/add")
|
|
public Result add(@Valid @RequestBody {{ table.entity }} param,
|
|
@RequestHeader("token") String token,
|
|
@RequestHeader(value = "version", defaultValue = "1.0") String version) {
|
|
if (token ==null) {
|
|
return Result.error("token不能为空");
|
|
}
|
|
{{table.lowerEntity}}Service.add(param);
|
|
return Result.OK();
|
|
}
|
|
|
|
@ApiOperation(value = "{{ table.comment }}修改")
|
|
@PostMapping(value = "/modify")
|
|
public Result modify(@Valid @RequestBody {{ table.entity }} param,
|
|
@RequestHeader("token") String token,
|
|
@RequestHeader(value = "version", defaultValue = "1.0") String version) {
|
|
if (token ==null) {
|
|
return Result.error("token不能为空");
|
|
}
|
|
{{table.entity}} info = {{table.lowerEntity}}Service.info(Integer.valueOf(param.getId()));
|
|
if (info ==null) {
|
|
return Result.error(String.format("[%s]记录不存在", info));
|
|
}
|
|
{{table.lowerEntity}}Service.modify(param);
|
|
return Result.OK();
|
|
}
|
|
|
|
@ApiOperation(value = "{{ table.comment }}删除(单个条目)")
|
|
@GetMapping(value = "/remove/{id}")
|
|
public Result remove(@PathVariable Integer id,
|
|
@RequestHeader("token") String token,
|
|
@RequestHeader(value = "version", defaultValue = "1.0") String version) {
|
|
|
|
{{table.lowerEntity}}Service.remove(id);
|
|
return Result.OK();
|
|
}
|
|
|
|
@ApiOperation(value = "{{ table.comment }}删除(多个条目)")
|
|
@PostMapping(value = "/removes")
|
|
public Result removes(@Valid @RequestBody List<Integer> ids,
|
|
@RequestHeader("token") String token,
|
|
@RequestHeader(value = "version", defaultValue = "1.0") String version) {
|
|
{{table.lowerEntity}}Service.removes(ids);
|
|
return Result.OK();
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "枚举自增分页列表查询", response = HealthEnums.class)
|
|
@PostMapping(value = "/optionList")
|
|
public Result<?> allList(@Valid @RequestBody HealthEnums param,
|
|
@RequestHeader("token") String token,
|
|
@RequestHeader(value = "version", defaultValue = "1.0") String version) {
|
|
List<HealthEnums> list = healthEnumsService.list(param);
|
|
if (list == null) {
|
|
return Result.error("无数据");
|
|
}
|
|
List<HealthEnumsOption> option = new ArrayList<>();
|
|
list.forEach(item -> {
|
|
AtomicReference<Boolean> isExt = new AtomicReference<>(false);
|
|
option.forEach(item2 -> {
|
|
if (item.getFieldName().equals(item2.getFieldName())
|
|
&& item.getFieldLabel().equals(item2.getFieldLabel())) {
|
|
item2.getOptions().add(item);
|
|
isExt.set(true);
|
|
}
|
|
});
|
|
if(!isExt.get()){
|
|
HealthEnumsOption optionItem = new HealthEnumsOption();
|
|
optionItem.setFieldName(item.getFieldName());
|
|
optionItem.setFieldLabel(item.getFieldLabel());
|
|
optionItem.setOptions(new ArrayList<>());
|
|
optionItem.getOptions().add(item);
|
|
option.add(optionItem);
|
|
}
|
|
});
|
|
return Result.OK( option );
|
|
}
|
|
|
|
}
|
|
|