预算计算
parent
95c9816d7a
commit
8f7a23fde3
|
|
@ -77,7 +77,7 @@ public class AttDamProfileController extends AbstractCommonFileController{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "列表")
|
@Operation(summary = "列表")
|
||||||
@GetMapping("/list")
|
@PostMapping("/list")
|
||||||
public R<List<AttDamProfile>> list() {
|
public R<List<AttDamProfile>> list() {
|
||||||
|
|
||||||
LambdaQueryWrapper<AttDamProfile> wq = new LambdaQueryWrapper();
|
LambdaQueryWrapper<AttDamProfile> wq = new LambdaQueryWrapper();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
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.mapper.FundBudgetMapper;
|
||||||
|
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.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 = "分页")
|
||||||
|
@PostMapping("/page")
|
||||||
|
public R<Page<FundBudget>> pageInfo(@RequestBody FundBudgetPageSo pageSo){
|
||||||
|
Page<FundBudget> page = fundBudgetService.pageInfo(pageSo);
|
||||||
|
for (FundBudget record : page.getRecords()) {
|
||||||
|
List<FileAssociations> files = fileService.getFiles(getGroupId(), record.getId().toString());
|
||||||
|
record.setFiles(files);
|
||||||
|
}
|
||||||
|
return R.ok(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(description = "新增")
|
||||||
|
@PostMapping("/insert")
|
||||||
|
public R<FundBudget> 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<FundBudget> 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<Boolean> 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.gunshi.project.ss.entity.so;
|
||||||
|
|
||||||
|
|
||||||
|
import com.gunshi.db.dto.PageSo;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FundBudgetPageSo {
|
||||||
|
|
||||||
|
@NotNull(message = "分页参数不能为空")
|
||||||
|
@Schema(description = "分页参数")
|
||||||
|
private PageSo pageSo;
|
||||||
|
|
||||||
|
private Integer budgetYear;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.gunshi.project.ss.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.gunshi.project.ss.model.FundBudget;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface FundBudgetMapper extends BaseMapper<FundBudget> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.gunshi.project.ss.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Schema(description = "经费预算")
|
||||||
|
@Data
|
||||||
|
@TableName("fund_budget")
|
||||||
|
public class FundBudget {
|
||||||
|
|
||||||
|
@TableId(value = "id",type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField("budget_year")
|
||||||
|
@Schema(description = "年度")
|
||||||
|
private Integer budgetYear;
|
||||||
|
|
||||||
|
@TableField("annual_income_budget")
|
||||||
|
@Schema(description = "年度支出预算")
|
||||||
|
private BigDecimal annualIncomeBudget;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField("annual_expenditure_budget")
|
||||||
|
@Schema(description = "年度收入预算")
|
||||||
|
private BigDecimal annualExpenditureBudget;
|
||||||
|
|
||||||
|
@TableField("budget_balance")
|
||||||
|
@Schema(description = "预算结余")
|
||||||
|
private BigDecimal budgetBalance;
|
||||||
|
|
||||||
|
@TableField("budget_desc")
|
||||||
|
@Schema(description = "预算说明")
|
||||||
|
private String budgetDesc;
|
||||||
|
|
||||||
|
@TableField("create_time")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<FileAssociations> files;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.gunshi.project.ss.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.gunshi.project.ss.entity.so.FundBudgetPageSo;
|
||||||
|
import com.gunshi.project.ss.mapper.FundBudgetMapper;
|
||||||
|
import com.gunshi.project.ss.model.FundBudget;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class FundBudgetService extends ServiceImpl<FundBudgetMapper, FundBudget> {
|
||||||
|
|
||||||
|
|
||||||
|
public Page<FundBudget> pageInfo(FundBudgetPageSo pageSo) {
|
||||||
|
LambdaQueryWrapper<FundBudget> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if(pageSo.getBudgetYear() != null){
|
||||||
|
queryWrapper.eq(FundBudget::getBudgetYear, pageSo.getBudgetYear());
|
||||||
|
}
|
||||||
|
Page<FundBudget> fundBudgetPage = baseMapper.selectPage(pageSo.getPageSo().toPage(), queryWrapper);
|
||||||
|
return fundBudgetPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean saveData(FundBudget fundBudget) {
|
||||||
|
LambdaQueryWrapper<FundBudget> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(FundBudget::getBudgetYear, fundBudget.getBudgetYear());
|
||||||
|
FundBudget one = baseMapper.selectOne(queryWrapper);
|
||||||
|
if(one != null){
|
||||||
|
throw new IllegalArgumentException("对不起,该年度预算已存在");
|
||||||
|
}
|
||||||
|
if(fundBudget.getAnnualIncomeBudget() != null && fundBudget.getAnnualExpenditureBudget() != null){
|
||||||
|
|
||||||
|
BigDecimal budget_balance = fundBudget.getAnnualIncomeBudget().subtract(fundBudget.getAnnualExpenditureBudget());
|
||||||
|
fundBudget.setBudgetBalance(budget_balance);
|
||||||
|
}
|
||||||
|
fundBudget.setCreateTime(LocalDateTime.now());
|
||||||
|
boolean save = save(fundBudget);
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean updateData(FundBudget fundBudget) {
|
||||||
|
FundBudget byId = getById(fundBudget.getId());
|
||||||
|
if(byId == null){
|
||||||
|
throw new IllegalArgumentException("对不起,该数据不存在");
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<FundBudget> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(FundBudget::getBudgetYear, fundBudget.getBudgetYear())
|
||||||
|
.ne(FundBudget::getId, fundBudget.getId());
|
||||||
|
FundBudget one = baseMapper.selectOne(queryWrapper);
|
||||||
|
if(one != null){
|
||||||
|
throw new IllegalArgumentException("对不起,该年度预算已存在");
|
||||||
|
}
|
||||||
|
boolean update = updateById(fundBudget);
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue