|
|
@@ -181,49 +181,51 @@ public class AmountApprovalManage { |
|
|
|
if (req.getApprovalAmount() != null && NumberUtil.isGreater(currTotalApprovalAmount, reviewAmount)) { |
|
|
|
throw ReturnException.wrap("暂不允许下达资金"); |
|
|
|
} |
|
|
|
Integer nextYear = null; |
|
|
|
if (approved) { |
|
|
|
if (ObjUtil.isAllEmpty(req.getCarryOverAmount(), req.getApprovalAmount())) { |
|
|
|
throw ReturnException.wrap("下达资金或结转资金不能为空"); |
|
|
|
} |
|
|
|
if (req.getCarryOverAmount() != null) { |
|
|
|
ProjectApprovalAmount lastApprovalAmount = projectApprovalAmountService.getByProjectCode(project.getProjectCode()); |
|
|
|
if (lastApprovalAmount != null && lastApprovalAmount.getApprovalAmount() == null) { |
|
|
|
throw ReturnException.wrap("上一年度未下达资金"); |
|
|
|
} |
|
|
|
if (lastApprovalAmount != null && NumberUtil.isGreater(req.getCarryOverAmount(), lastApprovalAmount.getApprovalAmount())) { |
|
|
|
throw ReturnException.wrap("结转资金不允许超过上一年度下达资金"); |
|
|
|
ProjectApprovalAmount last = projectApprovalAmountService.last(project.getProjectCode()); |
|
|
|
BigDecimal lastTotalAmount = DecimalUtil.sum(last.getApprovalAmount(), last.getCarryOverAmount()); |
|
|
|
if (NumberUtil.isGreater(req.getCarryOverAmount(), lastTotalAmount)) { |
|
|
|
throw ReturnException.wrap("结转资金不允许超过上一年度总资金"); |
|
|
|
} |
|
|
|
nextYear = last.getApprovalYear() + 1; |
|
|
|
} |
|
|
|
} else if (ObjUtil.hasNull(req.getReviewAmount() == null, req.getApprovalAmount())) { |
|
|
|
throw ReturnException.wrap("评审总投资和下达资金不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
Wrapper<Project> wrapper = Wrappers.lambdaUpdate(Project.class) |
|
|
|
.set(StrUtil.isNotBlank(req.getApprovalAmountFile()), Project::getApprovalAmountFile, req.getApprovalAmountFile()) |
|
|
|
.set(Project::getApprovalAmount, currTotalApprovalAmount) |
|
|
|
.set(req.getReviewAmount() != null, Project::getReviewAmount, req.getReviewAmount()) |
|
|
|
.set(Project::getUpdateOn, LocalDateTime.now()) |
|
|
|
.set(Project::getUpdateBy, LoginUserUtil.getUserId()) |
|
|
|
.eq(Project::getId, project.getId()); |
|
|
|
|
|
|
|
Integer currProjectYear = getLastApprovalYear(project); |
|
|
|
if (nextYear == null) { |
|
|
|
nextYear = getLastApprovalYear(project); |
|
|
|
} |
|
|
|
if (req.getApprovalAmount() != null) { |
|
|
|
Wrapper<Project> projectWrapper = Wrappers.lambdaUpdate(Project.class) |
|
|
|
.set(StrUtil.isNotBlank(req.getApprovalAmountFile()), Project::getApprovalAmountFile, req.getApprovalAmountFile()) |
|
|
|
.set(Project::getApprovalAmount, currTotalApprovalAmount) |
|
|
|
.set(req.getReviewAmount() != null, Project::getReviewAmount, req.getReviewAmount()) |
|
|
|
.set(Project::getUpdateOn, LocalDateTime.now()) |
|
|
|
.set(Project::getUpdateBy, LoginUserUtil.getUserId()) |
|
|
|
.eq(Project::getId, project.getId()); |
|
|
|
projectService.update(projectWrapper); |
|
|
|
} |
|
|
|
ProjectApprovalAmount projectApprovalAmount = new ProjectApprovalAmount(); |
|
|
|
projectApprovalAmount.setApprovalYear(currProjectYear); |
|
|
|
projectApprovalAmount.setApprovalYear(nextYear); |
|
|
|
projectApprovalAmount.setApprovalAmount(req.getApprovalAmount()); |
|
|
|
projectApprovalAmount.setProjectId(project.getId()); |
|
|
|
projectApprovalAmount.setProjectCode(project.getProjectCode()); |
|
|
|
projectApprovalAmount.setCarryOverAmount(req.getCarryOverAmount()); |
|
|
|
projectApprovalAmountService.save(projectApprovalAmount); |
|
|
|
projectService.update(wrapper); |
|
|
|
} |
|
|
|
|
|
|
|
private Integer getLastApprovalYear(Project project) { |
|
|
|
ProjectApprovalAmount lastApprovalAmount = projectApprovalAmountService.getByProjectCode(project.getProjectCode()); |
|
|
|
ProjectApprovalAmount last = projectApprovalAmountService.last(project.getProjectCode()); |
|
|
|
Integer currProjectYear; |
|
|
|
if (lastApprovalAmount == null) { |
|
|
|
if (last == null) { |
|
|
|
currProjectYear = project.getProjectYear(); |
|
|
|
} else { |
|
|
|
currProjectYear = lastApprovalAmount.getApprovalYear() + 1; |
|
|
|
currProjectYear = last.getApprovalYear() + 1; |
|
|
|
} |
|
|
|
return currProjectYear; |
|
|
|
} |
|
|
@@ -247,8 +249,15 @@ public class AmountApprovalManage { |
|
|
|
} |
|
|
|
|
|
|
|
public List<ProjectApprovalAmountDTO> listApprovalAmounts(String projectCode) { |
|
|
|
List<ProjectApprovalAmount> approvalAmounts = projectApprovalAmountService.listByProjectCode(projectCode); |
|
|
|
return BeanUtil.copyToList(approvalAmounts, ProjectApprovalAmountDTO.class); |
|
|
|
List<ProjectApprovalAmount> approvalAmounts = projectApprovalAmountService.listAsc(projectCode); |
|
|
|
List<ProjectApprovalAmountDTO> retData = BeanUtil.copyToList(approvalAmounts, ProjectApprovalAmountDTO.class); |
|
|
|
for (int i = 0; i < retData.size() - 1; i++) { |
|
|
|
ProjectApprovalAmountDTO curr = retData.get(i); |
|
|
|
ProjectApprovalAmountDTO next = retData.get(i + 1); |
|
|
|
curr.setCarryOverAmount(next.getCarryOverAmount()); |
|
|
|
next.setCarryOverAmount(null); |
|
|
|
} |
|
|
|
return retData; |
|
|
|
} |
|
|
|
|
|
|
|
} |