package com.gunshi.project.ss.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.core.result.R; import com.gunshi.project.ss.entity.so.FundBudgetPageSo; import com.gunshi.project.ss.model.FileAssociations; import com.gunshi.project.ss.model.FundBudget; import com.gunshi.project.ss.service.FileAssociationsService; import com.gunshi.project.ss.service.FundBudgetService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; @Tag(name = "经费预算") @RestController @RequestMapping(value="/fundBudget") public class FundBudgetController extends AbstractCommonFileController { @Autowired private FundBudgetService fundBudgetService; @Autowired private FileAssociationsService fileService; @Operation(description = "根据年份查询") @GetMapping("/get/{year}") public R get(@PathVariable("year") Integer year){ FundBudget res = fundBudgetService.getByYear(year); if(res!=null){ List files = fileService.getFiles(getGroupId(), res.getId().toString()); } return R.ok(res); } @Operation(description = "分页") @PostMapping("/page") public R> pageInfo(@RequestBody FundBudgetPageSo pageSo){ Page page = fundBudgetService.pageInfo(pageSo); for (FundBudget record : page.getRecords()) { List files = fileService.getFiles(getGroupId(), record.getId().toString()); record.setFiles(files); } return R.ok(page); } @Operation(description = "统计") @GetMapping("stat") public R stat(@RequestParam(value = "year",required = false) @Parameter(description = "年份") Integer year){ FundBudget res = fundBudgetService.stat(year); return R.ok(res); } @Operation(description = "新增") @PostMapping("/insert") public R insert(@RequestBody FundBudget fundBudget){ boolean flag = fundBudgetService.saveData(fundBudget); if(flag){ fileService.saveFile(fundBudget.getFiles(),getGroupId(),fundBudget.getId().toString()); } return R.ok(fundBudget); } @Operation(description = "更新") @PostMapping("/update") public R update(@RequestBody FundBudget fundBudget){ boolean flag = fundBudgetService.updateData(fundBudget); if(flag){ fileService.saveFile(fundBudget.getFiles(),getGroupId(),fundBudget.getId().toString()); } return R.ok(fundBudget); } @Operation(description = "删除") @GetMapping("/del/{id}") public R del(@PathVariable("id") Long id){ boolean flag = fundBudgetService.removeById(id); if(flag){ fileService.deleteFile(getGroupId(),id.toString()); } return R.ok(flag); } @Override public String getGroupId() { return "fundBudget"; } }