101 lines
3.3 KiB
Java
101 lines
3.3 KiB
Java
package com.gunshi.project.hsz.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.project.hsz.entity.so.XlPlanPageSo;
|
|
import com.gunshi.project.hsz.model.XlPlan;
|
|
import com.gunshi.project.hsz.service.FileAssociationsService;
|
|
import com.gunshi.project.hsz.service.XlPlanService;
|
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
|
import com.gunshi.project.hsz.validate.markers.Update;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
@RestController
|
|
@RequestMapping("/xlPlan")
|
|
@Tag(name = "兴利计划")
|
|
public class XlPlanController extends AbstractCommonFileController {
|
|
|
|
@Autowired
|
|
private XlPlanService xlPlanService;
|
|
|
|
@Autowired
|
|
private FileAssociationsService fileService;
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<XlPlan> insert(@Validated(Insert.class) @RequestBody XlPlan dto) {
|
|
dto.setId(IdWorker.getId());
|
|
boolean flag = xlPlanService.saveData(dto);
|
|
if(flag){
|
|
fileService.saveFile(dto.getFiles(),getGroupId(),dto.getId().toString());
|
|
}
|
|
return R.ok(dto);
|
|
}
|
|
|
|
@Operation(summary = "修改")
|
|
@PostMapping("/update")
|
|
public R<XlPlan> update(@Validated(Update.class) @RequestBody XlPlan dto) {
|
|
|
|
boolean flag = xlPlanService.update(dto);
|
|
|
|
if (flag) {
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
|
}
|
|
return R.ok(flag ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
XlPlan byId = xlPlanService.getById(id);
|
|
if(Objects.isNull(byId)){
|
|
throw new IllegalArgumentException("该计划不存在");
|
|
}
|
|
boolean flag = xlPlanService.removeById(id);
|
|
if(flag){
|
|
fileService.deleteFile(getGroupId(),byId.getId().toString());
|
|
}
|
|
return R.ok(true);
|
|
}
|
|
|
|
@Operation(summary = "分页")
|
|
@PostMapping("/page")
|
|
public R<Page<XlPlan>> page(@RequestBody XlPlanPageSo pageSo) {
|
|
Page<XlPlan> res = xlPlanService.pageQuery(pageSo);
|
|
if(!CollectionUtils.isEmpty(res.getRecords())){
|
|
res.getRecords().forEach(o -> o.setFiles(
|
|
fileService.getFiles(getGroupId(),o.getId().toString())
|
|
));
|
|
}
|
|
return R.ok(res);
|
|
}
|
|
|
|
|
|
@Operation(summary = "列表")
|
|
@GetMapping("/list")
|
|
public R<List<XlPlan>> list() {
|
|
List<XlPlan> list = xlPlanService.lambdaQuery().list();
|
|
if(!CollectionUtils.isEmpty(list)){
|
|
list.forEach(o -> o.setFiles(fileService.getFiles(getGroupId(),o.getId().toString())));
|
|
}
|
|
return R.ok(list);
|
|
}
|
|
|
|
|
|
@Override
|
|
public String getGroupId() {
|
|
return "xlPlan";
|
|
}
|
|
}
|