|
|
@ -1,14 +1,22 @@
|
|
|
|
package cn.iocoder.yudao.module.bs.service.budget;
|
|
|
|
package cn.iocoder.yudao.module.bs.service.budget;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetCreateReqVO;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetCreateReqVO;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetExportReqVO;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetExportReqVO;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetPageReqVO;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetPageReqVO;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetUpdateReqVO;
|
|
|
|
import cn.iocoder.yudao.module.bs.controller.admin.budget.vo.BudgetUpdateReqVO;
|
|
|
|
import cn.iocoder.yudao.module.bs.convert.budget.BudgetConvert;
|
|
|
|
import cn.iocoder.yudao.module.bs.convert.budget.BudgetConvert;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.budget.BudgetDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.dataobject.expenseclaim.ExpenseClaimDO;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.mysql.budget.BudgetMapper;
|
|
|
|
import cn.iocoder.yudao.module.bs.dal.mysql.budget.BudgetMapper;
|
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
|
|
|
|
|
import org.apache.commons.io.filefilter.FalseFileFilter;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
|
@ -36,6 +44,7 @@ public class BudgetServiceImpl extends MPJBaseServiceImpl<BudgetMapper, BudgetDO
|
|
|
|
public Long createBudget(BudgetCreateReqVO createReqVO) {
|
|
|
|
public Long createBudget(BudgetCreateReqVO createReqVO) {
|
|
|
|
// 插入
|
|
|
|
// 插入
|
|
|
|
BudgetDO budget = BudgetConvert.INSTANCE.convert(createReqVO);
|
|
|
|
BudgetDO budget = BudgetConvert.INSTANCE.convert(createReqVO);
|
|
|
|
|
|
|
|
|
|
|
|
setBaseField(budget);
|
|
|
|
setBaseField(budget);
|
|
|
|
budgetMapper.insert(budget);
|
|
|
|
budgetMapper.insert(budget);
|
|
|
|
// 返回
|
|
|
|
// 返回
|
|
|
@ -53,6 +62,15 @@ public class BudgetServiceImpl extends MPJBaseServiceImpl<BudgetMapper, BudgetDO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setBaseField(BudgetDO budget) {
|
|
|
|
private void setBaseField(BudgetDO budget) {
|
|
|
|
|
|
|
|
boolean isAdd = budget.getId() == null ? true : false;
|
|
|
|
|
|
|
|
BudgetDO budgetDO = getBudgetDO(budget.getDeptId(), DateUtil.beginOfYear(DateUtil.date()));
|
|
|
|
|
|
|
|
if (isAdd && budgetDO != null) {
|
|
|
|
|
|
|
|
throw exception(new ErrorCode(500, "保存失败,当前部门该年度预算数据已存在"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isAdd && !budgetDO.getId().equals(budget.getId())) {
|
|
|
|
|
|
|
|
throw exception(new ErrorCode(500, "保存失败,当前部门该年度预算数据已存在"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
budget.setBudgetYear(DateUtil.beginOfYear(DateUtil.date(budget.getBudgetYear())).toLocalDateTime());
|
|
|
|
budget.setOccupyAmount(BigDecimal.ZERO);
|
|
|
|
budget.setOccupyAmount(BigDecimal.ZERO);
|
|
|
|
budget.setUsedAmount(BigDecimal.ZERO);
|
|
|
|
budget.setUsedAmount(BigDecimal.ZERO);
|
|
|
|
budget.setRemainAmount(BigDecimal.ZERO);
|
|
|
|
budget.setRemainAmount(BigDecimal.ZERO);
|
|
|
@ -92,4 +110,23 @@ public class BudgetServiceImpl extends MPJBaseServiceImpl<BudgetMapper, BudgetDO
|
|
|
|
return budgetMapper.selectList(exportReqVO);
|
|
|
|
return budgetMapper.selectList(exportReqVO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public CommonResult updateByClaimSettle(ExpenseClaimDO claimDO) {
|
|
|
|
|
|
|
|
BudgetDO budgetDO = getBudgetDO(claimDO.getCostDeptId(), DateUtil.beginOfYear(DateUtil.date(claimDO.getCreateTime())));
|
|
|
|
|
|
|
|
if (budgetDO != null) {
|
|
|
|
|
|
|
|
budgetDO.setUsedAmount(budgetDO.getUsedAmount().add(claimDO.getAmount()));
|
|
|
|
|
|
|
|
budgetDO.setRemainAmount(NumberUtil.max(BigDecimal.ZERO, budgetDO.getAmount().subtract(budgetDO.getUsedAmount())));
|
|
|
|
|
|
|
|
updateById(budgetDO);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return CommonResult.success();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BudgetDO getBudgetDO(Long deptId, DateTime dateTime) {
|
|
|
|
|
|
|
|
LambdaQueryWrapperX<BudgetDO> query = new LambdaQueryWrapperX<>();
|
|
|
|
|
|
|
|
//根据部门和年度查找预算
|
|
|
|
|
|
|
|
query.eq(BudgetDO::getDeptId, deptId);
|
|
|
|
|
|
|
|
query.apply("budget_year = {0}", dateTime);
|
|
|
|
|
|
|
|
BudgetDO budgetDO = getOne(query);
|
|
|
|
|
|
|
|
return budgetDO;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|