This commit is contained in:
2024-01-31 14:54:49 +08:00
parent 71e28fd448
commit 2fd8b3d341
48 changed files with 1657 additions and 583 deletions

View File

@@ -1,5 +1,6 @@
package com.gxwebsoft.tower.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -22,6 +23,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
@@ -97,10 +100,7 @@ public class TowerIncomeController extends BaseController {
towerIncome.setUserId(loginUser.getUserId());
}
if (towerIncomeService.save(towerIncome)) {
LambdaUpdateWrapper<TowerContract> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(TowerContract::getContractId, towerIncome.getIncomeId())
.setSql("`total_income_amount` = `total_income_amount` + " + towerIncome.getAmount());
towerContractService.update(null, updateWrapper);
reCalIncome(towerIncome.getContractId());
return success(towerIncome.getIncomeId());
}
return fail("添加失败");
@@ -111,15 +111,8 @@ public class TowerIncomeController extends BaseController {
@ApiOperation("修改收款管理")
@PutMapping()
public ApiResult<?> update(@RequestBody TowerIncome towerIncome) {
QueryWrapper<TowerIncome> queryWrapper = new QueryWrapper<>();
queryWrapper.select("sum(`amount`) as `total_income_amount`");
TowerIncome towerIncomeAll = towerIncomeService.getOne(queryWrapper);
LambdaUpdateWrapper<TowerContract> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(TowerContract::getContractId, towerIncome.getIncomeId())
.set(TowerContract::getTotalIncomeAmount, towerIncomeAll.getTotalIncomeAmount());
towerContractService.update(null, updateWrapper);
if (towerIncomeService.updateById(towerIncome)) {
reCalIncome(towerIncome.getContractId());
return success(towerIncome.getIncomeId());
}
return fail("修改失败");
@@ -130,7 +123,9 @@ public class TowerIncomeController extends BaseController {
@ApiOperation("删除收款管理")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
int contractId = towerIncomeService.getById(id).getContractId();
if (towerIncomeService.removeById(id)) {
reCalIncome(contractId);
return success("删除成功");
}
return fail("删除失败");
@@ -163,10 +158,38 @@ public class TowerIncomeController extends BaseController {
@ApiOperation("批量删除收款管理")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
List<Integer> contractIdList = new ArrayList<>();
for (int id : ids) {
int contractId = towerIncomeService.getById(id).getContractId();
if (!contractIdList.contains(contractId)) {
contractIdList.add(contractId);
}
}
if (towerIncomeService.removeByIds(ids)) {
for (int contractId : contractIdList) {
this.reCalIncome(contractId);
}
return success("删除成功");
}
return fail("删除失败");
}
private void reCalIncome(int contractId) {
QueryWrapper<TowerIncome> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("contract_id", contractId)
.select("sum(`amount`) as `total_income_amount`");
TowerIncome towerIncomeAll = towerIncomeService.getOne(queryWrapper);
LambdaUpdateWrapper<TowerContract> updateWrapper = new LambdaUpdateWrapper<>();
BigDecimal totalIncomeAmount;
if (towerIncomeAll != null) {
totalIncomeAmount = towerIncomeAll.getTotalIncomeAmount();
} else {
totalIncomeAmount = BigDecimal.valueOf(0);
}
updateWrapper.eq(TowerContract::getContractId, contractId)
.set(TowerContract::getTotalIncomeAmount, totalIncomeAmount);
towerContractService.update(updateWrapper);
}
}