Merge remote-tracking branch 'origin/main'

This commit is contained in:
2026-04-21 14:28:55 +08:00
4 changed files with 224 additions and 119 deletions
@@ -0,0 +1,47 @@
package com.budwk.app.zhgh.dayofficework.outlay.outlayManage.service;
import com.budwk.app.base.result.Result;
import com.budwk.app.base.service.BaseService;
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.union.model.OutLayAllocateUnion;
import java.math.BigDecimal;
/**
* 分工会季度额度分配服务。
*
* <p>该服务统一处理季度额度的分配、批量分配和重置回滚,
* 保证季度记录与年度预算表金额始终同步。</p>
*
* @author zhf
*/
public interface OutlayManageUnionAllocateService extends BaseService<OutLayAllocateUnion> {
/**
* 修改单个分工会的季度分配金额。
*
* @param id outlay_allocate_union 表主键,用于定位当前编辑的季度分配记录
* @param allocateMoney 本次要设置的季度分配金额,传入的是最终金额,不是增量金额
* @return Result 成功时返回 success;失败时返回错误信息,前端据此提示用户
*/
Result doEdit(String id, BigDecimal allocateMoney);
/**
* 批量设置某一季度所有分工会的分配金额。
*
* @param allocateMoney 本次批量设置的季度分配金额,所有命中的分工会都会写入该金额
* @param quarterly 要操作的季度,例如 1/2/3/4
* @param year 要操作的年份,用于筛选对应季度的有效分配记录
* @return Result 成功时返回 success;失败时返回错误信息
*/
Result doBatchAllocate(BigDecimal allocateMoney, Integer quarterly, Integer year);
/**
* 重置当前季度的分配记录。
*
* <p>重置时会先回滚 outlay_manage_union.totalQuota
* 再将当前季度的 outlay_allocate_union 记录标记删除。</p>
*
* @return Result 成功时返回 success;失败时返回错误信息
*/
Result deleteAllocateRecord();
}
@@ -0,0 +1,167 @@
package com.budwk.app.zhgh.dayofficework.outlay.outlayManage.service.impl;
import cn.hutool.core.date.DateUtil;
import com.budwk.app.base.result.Result;
import com.budwk.app.base.service.impl.BaseServiceImpl;
import com.budwk.app.sys.models.Sys_union;
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.service.OutlayManageUnionAllocateService;
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.union.model.OutLayAllocateUnion;
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.union.model.OutlayManageUnion;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import java.math.BigDecimal;
import java.util.List;
/**
* 分工会季度额度分配实现。
*
* @author zhf
*/
@IocBean(args = {"refer:dao"})
public class OutlayManageUnionAllocateServiceImpl extends BaseServiceImpl<OutLayAllocateUnion> implements OutlayManageUnionAllocateService {
public OutlayManageUnionAllocateServiceImpl(Dao dao) {
super(dao);
}
@Override
public Result doEdit(String id, BigDecimal allocateMoney) {
OutLayAllocateUnion allocateUnion = fetch(id);
if (Lang.isEmpty(allocateUnion)) {
return Result.error("分配记录不存在!");
}
int currentQuarter = getCurrentQuarter();
if (allocateUnion.getQuarterly() < currentQuarter) {
return Result.error("当前是第【" + currentQuarter + "季度】无法修改【第" + allocateUnion.getQuarterly() + "季度】的额度!");
}
applyAllocateMoney(allocateUnion, allocateMoney);
return Result.success();
}
@Override
public Result doBatchAllocate(BigDecimal allocateMoney, Integer quarterly, Integer year) {
List<OutLayAllocateUnion> allocateUnionList = dao().query(OutLayAllocateUnion.class,
Cnd.where(OutLayAllocateUnion::getQuarterly, "=", quarterly)
.and(OutLayAllocateUnion::getYear, "=", year)
.and(OutLayAllocateUnion::getDelFlag, "=", false));
if (allocateUnionList == null || allocateUnionList.isEmpty()) {
return Result.error("当前季度没有分配记录!");
}
for (OutLayAllocateUnion allocateUnion : allocateUnionList) {
applyAllocateMoney(allocateUnion, allocateMoney);
}
return Result.success();
}
@Override
public Result deleteAllocateRecord() {
int currentQuarter = getCurrentQuarter();
List<OutLayAllocateUnion> allocateUnionList = dao().query(OutLayAllocateUnion.class,
Cnd.where(OutLayAllocateUnion::getQuarterly, "=", currentQuarter)
.and(OutLayAllocateUnion::getYear, "=", DateUtil.thisYear())
.and(OutLayAllocateUnion::getDelFlag, "=", false));
if (allocateUnionList == null || allocateUnionList.isEmpty()) {
return Result.error("当前季度还未分配,无法重置!");
}
for (OutLayAllocateUnion allocateUnion : allocateUnionList) {
rollbackAllocateMoney(allocateUnion);
}
dao().update(OutLayAllocateUnion.class, Chain.make("delFlag", true),
Cnd.where(OutLayAllocateUnion::getQuarterly, "=", currentQuarter)
.and(OutLayAllocateUnion::getYear, "=", DateUtil.thisYear())
.and(OutLayAllocateUnion::getDelFlag, "=", false));
return Result.success();
}
/**
* 按“先回退旧额度,再写入新额度”的方式同步季度记录和年度预算表。
*
* @param allocateUnion 当前季度分配记录,包含分工会、年份、旧分配额度等上下文
* @param newAllocateMoney 本次最终要保存的季度分配金额
*/
private void applyAllocateMoney(OutLayAllocateUnion allocateUnion, BigDecimal newAllocateMoney) {
BigDecimal oldAllocateMoney = defaultValue(allocateUnion.getAllocateMoney());
OutlayManageUnion manageUnion = dao().fetch(OutlayManageUnion.class,
Cnd.where(OutlayManageUnion::getUnionId, "=", allocateUnion.getUnionId())
.and(OutlayManageUnion::getYear, "=", DateUtil.thisYear()));
if (Lang.isEmpty(manageUnion)) {
manageUnion = buildManageUnion(allocateUnion, newAllocateMoney);
insert(manageUnion);
} else {
// 当前 totalQuota 里已经包含了旧季度额度,因此要先减旧值,再加新值,避免重复累加。
BigDecimal newTotalQuota = defaultValue(manageUnion.getTotalQuota())
.subtract(oldAllocateMoney)
.add(newAllocateMoney);
dao().update(OutlayManageUnion.class, Chain.make("totalQuota", newTotalQuota),
Cnd.where(OutlayManageUnion::getId, "=", manageUnion.getId()));
}
dao().update(OutLayAllocateUnion.class, Chain.make("allocateMoney", newAllocateMoney),
Cnd.where(OutLayAllocateUnion::getId, "=", allocateUnion.getId()));
}
/**
* 回滚当前季度已分配到年度预算表中的金额。
*
* @param allocateUnion 当前季度分配记录,allocateMoney 表示本次需要从年度额度中扣回的金额
*/
private void rollbackAllocateMoney(OutLayAllocateUnion allocateUnion) {
OutlayManageUnion manageUnion = dao().fetch(OutlayManageUnion.class,
Cnd.where(OutlayManageUnion::getUnionId, "=", allocateUnion.getUnionId())
.and(OutlayManageUnion::getYear, "=", DateUtil.thisYear()));
if (Lang.isEmpty(manageUnion)) {
return;
}
BigDecimal newTotalQuota = defaultValue(manageUnion.getTotalQuota())
.subtract(defaultValue(allocateUnion.getAllocateMoney()));
dao().update(OutlayManageUnion.class, Chain.make("totalQuota", newTotalQuota),
Cnd.where(OutlayManageUnion::getId, "=", manageUnion.getId()));
}
/**
* 当前年份预算表不存在时,按“分配前额度 + 本次分配额度”创建年度预算记录。
*
* @param allocateUnion 当前季度分配记录,allocateHeadMoney 表示生成记录时的剩余额度快照
* @param allocateMoney 本次要设置的季度分配额度
* @return OutlayManageUnion 新建的年度预算实体
*/
private OutlayManageUnion buildManageUnion(OutLayAllocateUnion allocateUnion, BigDecimal allocateMoney) {
Sys_union union = dao().fetch(Sys_union.class, allocateUnion.getUnionId());
OutlayManageUnion manageUnion = new OutlayManageUnion();
manageUnion.setYear(DateUtil.thisYear());
manageUnion.setUnionId(allocateUnion.getUnionId());
manageUnion.setTotalQuota(defaultValue(allocateUnion.getAllocateHeadMoney()).add(allocateMoney));
manageUnion.setUsedQuota(BigDecimal.ZERO);
if (Lang.isNotEmpty(union)) {
manageUnion.setUnionName(union.getName());
manageUnion.setUnionCode(union.getUnionCode());
}
return manageUnion;
}
/**
* 统一处理空金额,避免金额运算时出现空指针。
*
* @param value 可能为空的金额字段
* @return BigDecimal 非空金额;为空时返回 0
*/
private BigDecimal defaultValue(BigDecimal value) {
return value == null ? BigDecimal.ZERO : value;
}
/**
* 计算当前自然季度。
*
* @return int 当前季度,取值范围 1-4
*/
private int getCurrentQuarter() {
return DateUtil.month(DateUtil.date()) / 3 + 1;
}
}
@@ -9,13 +9,13 @@ import com.budwk.app.base.param.PageForm;
import com.budwk.app.base.result.Result;
import com.budwk.app.base.service.BaseService;
import com.budwk.app.sys.models.Sys_union;
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.service.OutlayManageUnionAllocateService;
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.union.model.OutLayAllocateUnion;
import com.budwk.app.zhgh.dayofficework.outlay.outlayManage.union.model.OutlayManageUnion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
@@ -45,6 +45,8 @@ public class OutlayManageUnionAllocateController {
@Inject
private BaseService baseService;
@Inject
private OutlayManageUnionAllocateService outlayManageUnionAllocateService;
@At("")
@Ok("beetl:/platform/zhgh/dayofficework/outlay/outlayManage/union/allocate/index.html")
@@ -88,59 +90,7 @@ public class OutlayManageUnionAllocateController {
if (StrUtil.isEmpty(allocateMoney) || StrUtil.isEmpty(id)) {
return Result.error("参数错误!");
}
OutLayAllocateUnion allocateUnion = baseService.dao().fetch(OutLayAllocateUnion.class, id);
int quarter = DateUtil.month(DateUtil.date()) / 3 + 1;
if (allocateUnion.getQuarterly() < quarter) {
return Result.error("当前是第【" + quarter + "季度】无法修改【第" + allocateUnion.getQuarterly() + "季度】的额度!");
}
baseService.dao().update(OutLayAllocateUnion.class, Chain.make("allocateMoney", allocateMoney),
Cnd.where(OutLayAllocateUnion::getId, "=", id));
//找出今年工会的预算表
OutlayManageUnion newOutlayManageUnion = baseService.dao().fetch(OutlayManageUnion.class,
Cnd.where(OutlayManageUnion::getUnionId, "=", allocateUnion.getUnionId())
.and(OutlayManageUnion::getYear, "=", DateUtil.thisYear()));
if (allocateUnion.getQuarterly() == 1) {
//如果是第一季度,添加年度预算表
Sys_union union = baseService.dao().fetch(Sys_union.class, allocateUnion.getUnionId());
//找出去年剩余的钱
OutlayManageUnion oldOutlayManageUnion = baseService.dao().fetch(OutlayManageUnion.class,
Cnd.where(OutlayManageUnion::getUnionId, "=", allocateUnion.getUnionId())
.and(OutlayManageUnion::getYear, "=", DateUtil.thisYear() - 1));
BigDecimal newTotalQuota = Lang.isNotEmpty(oldOutlayManageUnion) ? oldOutlayManageUnion.getTotalQuota().subtract(oldOutlayManageUnion.getUsedQuota()) : new BigDecimal(allocateMoney);
if (Lang.isNotEmpty(newOutlayManageUnion)) {
//如果有今年的预算,代表第一季度已经分配过一次,现在修改
newOutlayManageUnion.setTotalQuota(newTotalQuota);
baseService.update(newOutlayManageUnion);
} else {
OutlayManageUnion manageUnion = new OutlayManageUnion();
manageUnion.setYear(DateUtil.thisYear());
manageUnion.setUnionId(union.getId());
manageUnion.setUnionName(union.getName());
manageUnion.setUnionCode(union.getUnionCode());
//找出去年剩余多少钱,
if (Lang.isNotEmpty(oldOutlayManageUnion)) {
BigDecimal surplusMoney = oldOutlayManageUnion.getTotalQuota().subtract(oldOutlayManageUnion.getUsedQuota());
//去年剩余的钱加上当年的分配金额
manageUnion.setTotalQuota(surplusMoney.add(new BigDecimal(allocateMoney)));
} else {
manageUnion.setTotalQuota(new BigDecimal(allocateMoney));
}
manageUnion.setUsedQuota(BigDecimal.ZERO);
baseService.insert(manageUnion);
}
} else {
baseService.dao().update(OutlayManageUnion.class,
Chain.make("totalQuota", newOutlayManageUnion.getTotalQuota().add(new BigDecimal(allocateMoney))),
Cnd.where(OutlayManageUnion::getId, "=", newOutlayManageUnion.getId()));
}
return Result.success();
return outlayManageUnionAllocateService.doEdit(id, new BigDecimal(allocateMoney));
}
@At
@@ -151,79 +101,20 @@ public class OutlayManageUnionAllocateController {
public Result doBatchAllocate(@Param("allocateMoney") BigDecimal allocateMoney,
@Param("quarterly") Integer quarterly,
@Param("year") Integer year) {
List<OutLayAllocateUnion> allocateUnionList = baseService.dao().query(OutLayAllocateUnion.class,
Cnd.where(OutLayAllocateUnion::getQuarterly, "=", quarterly)
.and(OutLayAllocateUnion::getYear, "=", year)
.and(OutLayAllocateUnion::getDelFlag, "=", 0));
if (allocateUnionList == null || allocateUnionList.isEmpty()) {
return Result.error("当前季度没有分配记录!");
if (allocateMoney == null || quarterly == null || year == null) {
return Result.error("参数错误!");
}
for (OutLayAllocateUnion allocateUnion : allocateUnionList) {
baseService.dao().update(OutLayAllocateUnion.class,
Chain.make("allocateMoney", allocateMoney),
Cnd.where(OutLayAllocateUnion::getId, "=", allocateUnion.getId()));
OutlayManageUnion newOutlayManageUnion = baseService.dao().fetch(OutlayManageUnion.class,
Cnd.where(OutlayManageUnion::getUnionId, "=", allocateUnion.getUnionId())
.and(OutlayManageUnion::getYear, "=", DateUtil.thisYear()));
if (allocateUnion.getQuarterly() == 1) {
Sys_union union = baseService.dao().fetch(Sys_union.class, allocateUnion.getUnionId());
OutlayManageUnion oldOutlayManageUnion = baseService.dao().fetch(OutlayManageUnion.class,
Cnd.where(OutlayManageUnion::getUnionId, "=", allocateUnion.getUnionId())
.and(OutlayManageUnion::getYear, "=", DateUtil.thisYear() - 1));
BigDecimal newTotalQuota = Lang.isNotEmpty(oldOutlayManageUnion)
? oldOutlayManageUnion.getTotalQuota().subtract(oldOutlayManageUnion.getUsedQuota())
: allocateMoney;
if (Lang.isNotEmpty(newOutlayManageUnion)) {
newOutlayManageUnion.setTotalQuota(newTotalQuota);
baseService.update(newOutlayManageUnion);
} else {
OutlayManageUnion manageUnion = new OutlayManageUnion();
manageUnion.setYear(DateUtil.thisYear());
manageUnion.setUnionId(union.getId());
manageUnion.setUnionName(union.getName());
manageUnion.setUnionCode(union.getUnionCode());
if (Lang.isNotEmpty(oldOutlayManageUnion)) {
BigDecimal surplusMoney = oldOutlayManageUnion.getTotalQuota().subtract(oldOutlayManageUnion.getUsedQuota());
manageUnion.setTotalQuota(surplusMoney.add(allocateMoney));
} else {
manageUnion.setTotalQuota(allocateMoney);
}
manageUnion.setUsedQuota(BigDecimal.ZERO);
baseService.insert(manageUnion);
}
} else {
baseService.dao().update(OutlayManageUnion.class,
Chain.make("totalQuota", newOutlayManageUnion.getTotalQuota().add(allocateMoney)),
Cnd.where(OutlayManageUnion::getId, "=", newOutlayManageUnion.getId()));
}
}
return Result.success();
return outlayManageUnionAllocateService.doBatchAllocate(allocateMoney, quarterly, year);
}
@At
@ApiOperation("重置预算季度记录")
@Aop(TransAop.READ_COMMITTED)
@SLog(tag = "分工会预算-季度预算分配", msg = "重置预算季度记录")
@SaCheckPermission("outlay.outlayManage.union.allocate")
public Result deleteAllocateRecord() {
int quarter = DateUtil.month(DateUtil.date()) / 3 + 1;
// 查询当前季度
int count = baseService.dao().count(OutLayAllocateUnion.class, Cnd.where(OutLayAllocateUnion::getQuarterly, "=", quarter)
.and(OutLayAllocateUnion::getYear, "=", DateUtil.thisYear()));
if (count == 0) {
return Result.error("当前季度还未分配,无法重置!");
}
baseService.dao().update(OutLayAllocateUnion.class, Chain.make("delFlag", 1),
Cnd.where(OutLayAllocateUnion::getQuarterly, "=", quarter)
.and(OutLayAllocateUnion::getYear, "=", DateUtil.thisYear()));
return Result.success();
return outlayManageUnionAllocateService.deleteAllocateRecord();
}
@At
@@ -59,7 +59,7 @@ public class AIdFundPayRecordController {
@At("")
@Ok("beetl:/platform/zhgh/staffbenefit/medicalMutualAid/aidFund/paexportYearPayRecordyRecord/index.html")
@Ok("beetl:/platform/zhgh/staffbenefit/medicalMutualAid/aidFund/payRecord/index.html")
@SaCheckPermission("medicalMutualAid.aidFund.payRecord")
public void index() {
}