feat: 工会报销-慰问优化

This commit is contained in:
2026-11-17 11:36:38 +08:00
parent 02a85fe27b
commit ca0c14df31
19 changed files with 768 additions and 120 deletions
@@ -65,8 +65,14 @@ public class ActivityBudgetAllocationEditController {
Sql sql = applyStatisticsService.getsql(year, unionId, clubId, budgetTypeCode, activityMatter, budgetReimburseType);
List<NutMap> list = applyStatisticsService.listMap(sql);
list = list.stream().filter(v -> !v.getBoolean("isSchoolBudget")).toList();
double declareTotalBudgetMoney = list.stream().mapToDouble(map -> map.getDouble("declareTotalBudgetMoney")).sum();
double totalBudgetMoney = list.stream().mapToDouble(map -> map.getDouble("totalBudgetMoney")).sum();
BigDecimal declareTotalBudgetMoney = list.stream()
.map(map -> map.getAs("declareTotalBudgetMoney", BigDecimal.class))
.filter(value -> value != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalBudgetMoney = list.stream()
.map(map -> map.getAs("totalBudgetMoney", BigDecimal.class))
.filter(value -> value != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
return Result.success(Map.of("declareTotalBudgetMoney", declareTotalBudgetMoney, "totalBudgetMoney", totalBudgetMoney));
}
@@ -28,6 +28,7 @@ import org.nutz.mvc.annotation.Param;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@@ -135,8 +136,14 @@ public class ActivityBudgetApplyListController {
Sql sql = activityBudgetService.getSqlByApplyList(null, year, activityMatter, budgetReimburseType, cnd);
sql.setCondition(cnd);
List<NutMap> list = activityBudgetService.listMap(sql);
double declareTotalBudgetMoney = list.stream().mapToDouble(map -> map.getDouble("declareTotalBudgetMoney")).sum();
double totalBudgetMoney = list.stream().mapToDouble(map -> map.getDouble("totalBudgetMoney")).sum();
BigDecimal declareTotalBudgetMoney = list.stream()
.map(map -> map.getAs("declareTotalBudgetMoney", BigDecimal.class))
.filter(value -> value != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalBudgetMoney = list.stream()
.map(map -> map.getAs("totalBudgetMoney", BigDecimal.class))
.filter(value -> value != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
return Result.success(Map.of("declareTotalBudgetMoney", declareTotalBudgetMoney, "totalBudgetMoney", totalBudgetMoney));
}
@@ -28,6 +28,7 @@ import org.nutz.mvc.annotation.Ok;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -74,8 +75,14 @@ public class ActivityBudgetApplyStatisticsController {
Sql sql = activityBudgetService.getsql(year, unionId, clubId, outlayManageSource, activityMatter, budgetReimburseType);
List<NutMap> list = activityBudgetService.listMap(sql);
list = list.stream().filter(v -> !v.getBoolean("isSchoolBudget")).toList();
double declareTotalBudgetMoney = list.stream().mapToDouble(map -> map.getDouble("declareTotalBudgetMoney")).sum();
double totalBudgetMoney = list.stream().mapToDouble(map -> map.getDouble("totalBudgetMoney")).sum();
BigDecimal declareTotalBudgetMoney = list.stream()
.map(map -> map.getAs("declareTotalBudgetMoney", BigDecimal.class))
.filter(value -> value != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalBudgetMoney = list.stream()
.map(map -> map.getAs("totalBudgetMoney", BigDecimal.class))
.filter(value -> value != null)
.reduce(BigDecimal.ZERO, BigDecimal::add);
return Result.success(Map.of("declareTotalBudgetMoney", declareTotalBudgetMoney, "totalBudgetMoney", totalBudgetMoney));
}
@@ -7,6 +7,7 @@ import lombok.experimental.Accessors;
import org.nutz.dao.entity.annotation.*;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @ClassName ActivityBudgetType
@@ -36,8 +37,8 @@ public class ActivityBudgetType extends BaseModel implements Serializable {
@Column
@Comment("金额")
@ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
private Double budgetTypeMoney;
@ColDefine(customType = "decimal(10,2)")
private BigDecimal budgetTypeMoney;
@Column
@Comment("备注")
@@ -0,0 +1,182 @@
package com.budwk.app.zhgh.dayofficework.outlay.outlayManage.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.budwk.app.base.constant.RoleConstant;
import com.budwk.app.base.page.Pagination;
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.web.commons.auth.utils.AuthUtil;
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import java.util.List;
@IocBean
@At("/platform/outlay/outlayManage")
@Ok("json:full")
public class OutlayBudgetLogController {
private static final String VIEW = "beetl:/platform/zhgh/dayofficework/outlay/outlayManage/common/budgetLog.html";
private static final String SCHOOL_PERMISSION = "outlay.outlayManage.school.budgetLog";
private static final String UNION_PERMISSION = "outlay.outlayManage.union.budgetLog";
@Inject
private BaseService baseService;
@At("/schoolBudgetLog")
@Ok(VIEW)
@SaCheckPermission(SCHOOL_PERMISSION)
public void schoolIndex() {
}
@At("/unionBudgetLog")
@Ok(VIEW)
@SaCheckPermission(UNION_PERMISSION)
public void unionIndex() {
}
@At("/schoolBudgetLog/pageData")
@SaCheckPermission(SCHOOL_PERMISSION)
public Result schoolPageData(PageForm pageForm, Integer year, String kind) {
return pageData(pageForm, year, kind, "school", null);
}
@At("/unionBudgetLog/pageData")
@SaCheckPermission(UNION_PERMISSION)
public Result unionPageData(PageForm pageForm, Integer year, String kind, String unionId) {
if (!AuthUtil.hasRoleOr(RoleConstant.SYSADMIN.name(), RoleConstant.SCHOOL_UNION_ADMIN.name())) {
unionId = SecurityUtil.getUnionId();
if (StrUtil.isBlank(unionId)) {
return Result.success(new Pagination<>(1, 10, 0, List.of()));
}
}
return pageData(pageForm, year, kind, "union", unionId);
}
private Result pageData(PageForm pageForm, Integer year, String kind, String scope, String unionId) {
String events = """
WITH events AS (
SELECT CAST(l.id AS CHAR) AS id, l.sourceKey, l.budgetScope, l.budgetId, l.year,
l.unionId, l.unionName, l.kind, l.action, l.totalBefore, l.totalAfter,
l.usedBefore, l.usedAfter, COALESCE(l.totalChange, 0) AS totalChange,
COALESCE(l.usedChange, 0) AS usedChange, l.operatorId, l.operatorName,
l.remark, l.createdAt, l.id AS sortId
FROM outlay_budget_log l
WHERE l.budgetScope = @scope AND l.year = @year
AND (@unionId IS NULL OR l.unionId = @unionId)
"""
/* + """
UNION ALL
SELECT CONCAT('declaration:', ab.id), NULL, @scope, NULL, YEAR(ab.applyDate),
IF(@scope = 'union', ab.unionId, NULL), NULL, 'declaration', '预算申报',
NULL, NULL, NULL, NULL, COALESCE(ab.totalBudgetMoney, ab.declareTotalBudgetMoney, 0),
0, ab.userId, ab.userName, ab.activityMatter,
COALESCE(ins.updatedAt, ins.createdAt, ab.updatedAt, ab.createdAt), ins.id
FROM activity_budget ab
JOIN wf_process_instance ins ON ins.id = (
SELECT MAX(wpi.id)
FROM wf_process_instance wpi
JOIN wf_process_define pd ON pd.id = wpi.processDefineId AND pd.name = 'NDYSSB'
WHERE wpi.businessNo = CONVERT(ab.id USING utf8mb3) COLLATE utf8mb3_general_ci
AND COALESCE(wpi.delFlag, 0) = 0
) AND ins.state = 20
WHERE YEAR(ab.applyDate) = @year AND COALESCE(ab.delFlag, 0) = 0
AND COALESCE(ab.totalBudgetMoney, ab.declareTotalBudgetMoney, 0) <> 0
AND (
(@scope = 'school' AND (ab.outlayManageSource = 'ACTIVITY_BUDGET_TYPE_ONE'
OR (ab.outlayManageSource IN ('ACTIVITY_BUDGET_TYPE_TWO', 'ACTIVITY_BUDGET_TYPE_THREE')
AND ab.isSchoolBudget = 1)))
OR (@scope = 'union' AND ab.outlayManageSource = 'ACTIVITY_BUDGET_TYPE_TWO'
AND COALESCE(ab.isSchoolBudget, 0) = 0 AND ab.unionId IS NOT NULL
AND (@unionId IS NULL OR ab.unionId = @unionId))
)
""" */
+ """
)
""";
// 已保存的快照用于校准历史余额,申报金额单独累计后计入日志总额。
Sql sql = Sqls.create(events + """
, running AS (
SELECT e.*,
SUM(IF(kind = 'declaration', 0, totalChange)) OVER timeline AS quotaSum,
SUM(IF(kind = 'declaration', totalChange, 0)) OVER timeline AS declarationSum,
SUM(usedChange) OVER timeline AS usedSum,
COUNT(totalAfter) OVER timeline AS quotaSnapshot,
COUNT(usedAfter) OVER timeline AS usedSnapshot
FROM events e
WINDOW timeline AS (
PARTITION BY unionId ORDER BY createdAt, sortId, id ROWS UNBOUNDED PRECEDING
)
), balances AS (
SELECT r.*,
quotaSum + COALESCE(MAX(totalAfter - quotaSum) OVER (
PARTITION BY unionId, quotaSnapshot
), 0) AS quotaBalance,
usedSum + COALESCE(MAX(usedAfter - usedSum) OVER (
PARTITION BY unionId, usedSnapshot
), 0) AS usedBalance
FROM running r
)
SELECT l.id, l.sourceKey, l.budgetScope, l.budgetId, l.year, l.unionId, l.unionName,
l.kind, IF(l.action = '使用额度增加', '预算使用', l.action) AS action,
l.totalChange, l.usedChange,
l.totalChange - l.usedChange AS quotaChange,
COALESCE(l.totalBefore, l.quotaBalance - IF(l.kind = 'declaration', 0, l.totalChange))
+ l.declarationSum - IF(l.kind = 'declaration', l.totalChange, 0) AS totalBefore,
l.quotaBalance + l.declarationSum AS totalAfter,
COALESCE(l.usedBefore, l.usedBalance - l.usedChange) AS usedBefore,
l.usedBalance AS usedAfter,
COALESCE(NULLIF(l.operatorId, ''), NULLIF(audit.createdBy, '')) AS operatorId,
l.operatorName, l.createdAt,
COALESCE(NULLIF(TRIM(l.remark), ''), NULLIF(TRIM(audit.remark), ''),
NULLIF(CONCAT_WS(';',
CASE WHEN l.totalChange <> 0 THEN
CONCAT('预算总额度', IF(l.totalChange > 0, '增加 ', '减少 '), ABS(l.totalChange), ' 元')
END,
CASE WHEN l.action = '使用额度增加' THEN
CONCAT('使用预算,扣减可用额度 ', l.usedChange, ' 元')
WHEN l.usedChange <> 0 THEN
CONCAT('已使用额度', IF(l.usedChange > 0, '增加 ', '减少 '), ABS(l.usedChange), ' 元')
END
), ''), CONCAT(l.action, ',金额无变动')) AS remark,
COALESCE(l.unionName, su.name) AS displayUnionName,
COALESCE(NULLIF(l.operatorName, ''), usr.username, usr.loginname) AS displayOperatorName
FROM balances l
LEFT JOIN outlay_annual_allocate_log audit ON l.budgetScope = 'school'
AND l.sourceKey IS NULL AND l.action = '调整预算额度'
AND audit.id = (
SELECT IF(COUNT(*) = 1, MAX(a.id), NULL)
FROM outlay_annual_allocate_log a
WHERE a.allocateType = 'school' AND a.allocateId = CAST(l.year AS CHAR)
AND a.action = '修改预算'
AND a.createdAt BETWEEN l.createdAt - 5000 AND l.createdAt + 5000
AND JSON_UNQUOTE(JSON_EXTRACT(a.afterData, '$.id')) = l.budgetId
AND COALESCE(CAST(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(a.beforeData, '$.totalQuota')), 'null')
AS DECIMAL(14,2)), 0) = l.totalBefore
AND CAST(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(a.afterData, '$.totalQuota')), 'null')
AS DECIMAL(14,2)) = l.totalAfter
)
LEFT JOIN sys_union su ON su.id = l.unionId
LEFT JOIN sys_user usr ON usr.id = COALESCE(NULLIF(l.operatorId, ''), NULLIF(audit.createdBy, ''))
WHERE (@kind IS NULL OR l.kind = @kind)
ORDER BY l.createdAt DESC, l.sortId DESC, l.id DESC
""");
Sql countSql = Sqls.create(events + """
SELECT COUNT(*) FROM events WHERE (@kind IS NULL OR kind = @kind)
""");
for (Sql query : List.of(sql, countSql)) {
query.setParam("scope", scope).setParam("year", year == null ? DateUtil.thisYear() : year)
.setParam("unionId", StrUtil.isBlank(unionId) ? null : unionId)
.setParam("kind", StrUtil.isBlank(kind) ? null : kind);
}
return Result.success(baseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql, countSql));
}
}
@@ -1,6 +1,7 @@
package com.budwk.app.zhgh.dayofficework.outlay.outlayManage.school.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil;
import com.budwk.app.base.annotation.SLog;
import com.budwk.app.base.page.Pagination;
@@ -84,7 +85,16 @@ public class OutlayManageSchoolController {
@SLog(tag = "校工会预算分配", msg = "修改了预算分配的金额:${args[0]},id:${args[1]}")
@Aop(TransAop.READ_COMMITTED)
public Result doSubmit(String totalQuota, String id) {
BigDecimal total = new BigDecimal(totalQuota);
if (totalQuota == null || totalQuota.isBlank())
return Result.error("请输入校工会预算总额度");
BigDecimal total;
try {
total = new BigDecimal(totalQuota.trim());
} catch (NumberFormatException e) {
return Result.error("校工会预算总额度格式不正确");
}
if (total.signum() < 0 || total.scale() > 2 || total.compareTo(new BigDecimal("99999999.99")) > 0)
return Result.error("校工会预算总额度必须在 0 至 99999999.99 元之间,且最多保留两位小数");
List<NutMap> budgets = baseService.listMap(Sqls.create(
"SELECT id,year,totalQuota,usedQuota,delFlag FROM outlay_manage_school WHERE id=@id AND COALESCE(delFlag,0)=0 FOR UPDATE").setParam("id", id));
if (budgets.isEmpty()) return Result.error("校工会预算不存在");
@@ -92,9 +102,13 @@ public class OutlayManageSchoolController {
BigDecimal used = before.get("usedQuota") == null ? BigDecimal.ZERO : new BigDecimal(before.getString("usedQuota"));
if (total.compareTo(used) < 0)
return Result.error("校工会预算总额度不能低于已使用额度");
baseService.dao().update(OutlayManageSchool.class, Chain.make("totalQuota", total), Cnd.where("id", "=", id));
outlayAnnualAllocateService.auditSchoolBudget(before.getInt("year"), "修改预算", before,
outlayAnnualAllocateService.schoolBudgetSnapshot(id), null);
baseService.dao().update(OutlayManageSchool.class, Chain.make("totalQuota", total)
.add("updatedBy", StpUtil.getLoginIdAsString()).add("updatedAt", System.currentTimeMillis()),
Cnd.where("id", "=", id));
NutMap after = outlayAnnualAllocateService.schoolBudgetSnapshot(id);
String remark = "总额度由 " + (before.get("totalQuota") == null ? "0.00" : before.getString("totalQuota"))
+ " 元调整为 " + after.getString("totalQuota") + " 元";
outlayAnnualAllocateService.auditSchoolBudget(before.getInt("year"), "修改预算", before, after, remark);
return Result.success();
}
@@ -221,6 +221,7 @@ public class OutlayAnnualAllocateService extends BaseServiceImpl<OutlayManageUni
String schoolBudgetId = changeSchoolBudget(year, schoolBudgets, null, allocationTotal,
"下拨基础经费", "本次下拨 " + unions.size() + " 个分工会,共 " + allocationTotal.toPlainString() + " 元");
withBudgetAllocationLog("下拨基础经费", () -> {
writeGenerateRows("""
INSERT INTO outlay_manage_union
(id,year,unionId,unionName,unionCode,totalQuota,usedQuota,delFlag,createdAt,updatedAt,createdBy,updatedBy)
@@ -231,6 +232,7 @@ public class OutlayAnnualAllocateService extends BaseServiceImpl<OutlayManageUni
) v ON v.id=b.id
SET b.totalQuota=COALESCE(b.totalQuota,0)+v.delta,b.updatedAt=v.updatedAt,b.updatedBy=v.updatedBy
""", budgetUpdates);
});
writeGenerateRows("""
INSERT INTO outlay_annual_base
(id,year,unionId,memberCount,standard,calculatedMoney,allocateMoney,remark,status,version,createdAt,createdBy,updatedAt,updatedBy)
@@ -326,7 +328,10 @@ public class OutlayAnnualAllocateService extends BaseServiceImpl<OutlayManageUni
(confirmed ? "调整" : "下拨") + fundName,
confirmed || "base".equals(type) ? remark : projectName.trim());
}
if (!confirmed || budgetDelta.signum() != 0) syncBudget(year, unionId, budgetDelta);
if (!confirmed || budgetDelta.signum() != 0) {
String fundName = "base".equals(type) ? "基础经费" : "专项经费";
syncBudget(year, unionId, budgetDelta, (confirmed ? "调整" : "下拨") + fundName);
}
long now = System.currentTimeMillis();
String actor = StpUtil.getLoginIdAsString();
if (old == null) {
@@ -369,7 +374,7 @@ public class OutlayAnnualAllocateService extends BaseServiceImpl<OutlayManageUni
changeSchoolBudget(year, schoolBudgets, schoolBudgetId, amount.negate(),
"退回专项经费", before.getString("projectName"));
}
syncBudget(year, unionId, amount.negate());
syncBudget(year, unionId, amount.negate(), "退回专项经费");
}
execute(sql("""
@@ -407,7 +412,7 @@ public class OutlayAnnualAllocateService extends BaseServiceImpl<OutlayManageUni
refundBudgetId = chargedBudgetId;
refundTotal = refundTotal.add(amount);
}
syncBudget(year, row.getString("unionId"), amount.negate());
syncBudget(year, row.getString("unionId"), amount.negate(), "退回基础经费");
}
execute(sql("""
UPDATE outlay_annual_base
@@ -454,16 +459,16 @@ public class OutlayAnnualAllocateService extends BaseServiceImpl<OutlayManageUni
if (delta.signum() < 0 && used.add(delta).signum() < 0)
throw new BaseException("校工会已使用额度不足,无法退回下拨经费");
if (delta.signum() != 0) {
execute(sql("""
withBudgetAllocationLog(action, () -> execute(sql("""
UPDATE outlay_manage_school SET usedQuota=COALESCE(usedQuota,0)+@delta,updatedAt=@now,updatedBy=@actor
WHERE id=@id
""", "delta", delta, "id", id, "now", System.currentTimeMillis(), "actor", StpUtil.getLoginIdAsString()));
""", "delta", delta, "id", id, "now", System.currentTimeMillis(), "actor", StpUtil.getLoginIdAsString())));
auditSchoolBudget(year, action, budget, schoolBudgetSnapshot(id), remark);
}
return id;
}
private void syncBudget(int year, String unionId, BigDecimal delta) {
private void syncBudget(int year, String unionId, BigDecimal delta, String action) {
List<NutMap> budgets = listMap(sql("SELECT * FROM outlay_manage_union WHERE year=@year AND unionId=@unionId FOR UPDATE",
"year", year, "unionId", unionId));
if (budgets.size() > 1) throw new IllegalArgumentException("该分工会年度预算存在重复记录,不能下拨");
@@ -474,19 +479,36 @@ public class OutlayAnnualAllocateService extends BaseServiceImpl<OutlayManageUni
"year", year - 1, "unionId", unionId));
BigDecimal carry = previous == null ? BigDecimal.ZERO : new BigDecimal(previous.get("surplus").toString());
validateBudgetTotal(carry.add(delta));
execute(sql("""
withBudgetAllocationLog(action, () -> execute(sql("""
INSERT INTO outlay_manage_union (id,year,unionId,unionName,unionCode,totalQuota,usedQuota,delFlag,createdAt,updatedAt,createdBy,updatedBy)
SELECT @id,@year,id,name,unionCode,@money,0,0,@now,@now,@actor,@actor FROM sys_union WHERE id=@unionId
""", "id", UUID.randomUUID().toString().replace("-", ""), "year", year,
"unionId", unionId, "money", carry.add(delta), "now", System.currentTimeMillis(), "actor", StpUtil.getLoginIdAsString()));
"unionId", unionId, "money", carry.add(delta), "now", System.currentTimeMillis(), "actor", StpUtil.getLoginIdAsString())));
} else {
NutMap budget = budgets.get(0);
validateBudgetUpdate(budget, delta);
execute(sql("UPDATE outlay_manage_union SET totalQuota=COALESCE(totalQuota,0)+@delta,updatedAt=@now,updatedBy=@actor WHERE id=@id",
"delta", delta, "now", System.currentTimeMillis(), "actor", StpUtil.getLoginIdAsString(), "id", budget.getString("id")));
withBudgetAllocationLog(action, () -> execute(sql(
"UPDATE outlay_manage_union SET totalQuota=COALESCE(totalQuota,0)+@delta,updatedAt=@now,updatedBy=@actor WHERE id=@id",
"delta", delta, "now", System.currentTimeMillis(), "actor", StpUtil.getLoginIdAsString(), "id", budget.getString("id"))));
}
}
// 下拨事务中的额度更新与触发器共用连接,标记仅作用于本次写入。
private void withBudgetAllocationLog(String action, Runnable write) {
dao().run(connection -> {
try (PreparedStatement context = connection.prepareStatement("SET @outlay_budget_log_action = ?")) {
context.setString(1, action);
context.execute();
try {
write.run();
} finally {
context.setNull(1, java.sql.Types.VARCHAR);
context.execute();
}
}
});
}
private void validateBudgetTotal(BigDecimal total) {
if (!moneyValid(total)) throw new IllegalArgumentException("下拨后年度总额度超出允许范围");
}
@@ -44,6 +44,7 @@ import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@@ -137,8 +138,17 @@ public class UnionReimburseCollectController {
@At
@Aop(TransAop.READ_COMMITTED)
@SaCheckPermission(value = {"unionReimburse.collect", "h5.unionReimburse.collect"}, mode = SaMode.OR)
public Result updateActuallyAmount(String id,Double realMoney) {
return unionReimburseService.updateActuallyAmount(id, realMoney);
public Result updateActuallyAmount(String id, String realMoney) {
if (StrUtil.isBlank(realMoney)) {
return Result.error("实际报销金额必须大于0");
}
BigDecimal amount;
try {
amount = new BigDecimal(realMoney.trim());
} catch (NumberFormatException e) {
return Result.error("实际报销金额格式不正确");
}
return unionReimburseService.updateActuallyAmount(id, amount);
}
@At
@@ -37,7 +37,7 @@ public class UnionReimburseFundSourceInterceptor implements FlowInterceptor {
OutlayManageSchool outlayManageSchool = OutlayManageSchool.lockActive(dao, Cnd.where("year", "=", DateUtil.year(new Date())));
if (outlayManageSchool != null) {
//balance已使用额度
BigDecimal balance = outlayManageSchool.getUsedQuota().add(BigDecimal.valueOf(unionReimburse.getMoney()));
BigDecimal balance = outlayManageSchool.getUsedQuota().add(unionReimburse.getMoney());
outlayManageSchool.setUsedQuota(balance);
dao.updateIgnoreNull(outlayManageSchool);
@@ -45,7 +45,7 @@ public class UnionReimburseFundSourceInterceptor implements FlowInterceptor {
detail.setAdjustUserName(SecurityUtil.getUserUsername());
detail.setAdjustLoginName(SecurityUtil.getUserLoginname());
detail.setOutlayReimburseId(unionReimburse.getId());
detail.setAdjustMoney(BigDecimal.valueOf(unionReimburse.getMoney()));
detail.setAdjustMoney(unionReimburse.getMoney());
detail.setAdjustReason(unionReimburse.getReimburseProject());
detail.setProjectName(unionReimburse.getActivityName());
detail.setActivityNumber(unionReimburse.getActivityNumber());
@@ -61,7 +61,7 @@ public class UnionReimburseFundSourceInterceptor implements FlowInterceptor {
Cnd.where("unionId", "=", SecurityUtil.getUnionId()).and("year", "=", DateUtil.year(new Date())));
if (outlayManageUnion != null) {
//balance已使用额度
BigDecimal balance = outlayManageUnion.getUsedQuota().add(BigDecimal.valueOf(unionReimburse.getMoney()));
BigDecimal balance = outlayManageUnion.getUsedQuota().add(unionReimburse.getMoney());
outlayManageUnion.setUsedQuota(balance);
dao.updateIgnoreNull(outlayManageUnion);
@@ -69,7 +69,7 @@ public class UnionReimburseFundSourceInterceptor implements FlowInterceptor {
detail.setAdjustUserName(SecurityUtil.getUserUsername());
detail.setAdjustLoginName(SecurityUtil.getUserLoginname());
detail.setOutlayReimburseId(unionReimburse.getId());
detail.setAdjustMoney(BigDecimal.valueOf(unionReimburse.getMoney()));
detail.setAdjustMoney(unionReimburse.getMoney());
detail.setAdjustReason(unionReimburse.getReimburseProject());
detail.setProjectName(unionReimburse.getActivityName());
detail.setActivityNumber(unionReimburse.getActivityNumber());
@@ -85,7 +85,7 @@ public class UnionReimburseFundSourceInterceptor implements FlowInterceptor {
Cnd.where("year", "=", DateUtil.year(new Date())));
if (outlayManageClub != null) {
//balance已使用额度
BigDecimal balance = outlayManageClub.getUsedQuota().add(BigDecimal.valueOf(unionReimburse.getMoney()));
BigDecimal balance = outlayManageClub.getUsedQuota().add(unionReimburse.getMoney());
outlayManageClub.setUsedQuota(balance);
dao.updateIgnoreNull(outlayManageClub);
@@ -93,7 +93,7 @@ public class UnionReimburseFundSourceInterceptor implements FlowInterceptor {
detail.setAdjustUserName(SecurityUtil.getUserUsername());
detail.setAdjustLoginName(SecurityUtil.getUserLoginname());
detail.setOutlayReimburseId(unionReimburse.getId());
detail.setAdjustMoney(BigDecimal.valueOf(unionReimburse.getMoney()));
detail.setAdjustMoney(unionReimburse.getMoney());
detail.setAdjustReason(unionReimburse.getReimburseProject());
detail.setProjectName(unionReimburse.getActivityName());
detail.setActivityNumber(unionReimburse.getActivityNumber());
@@ -10,6 +10,7 @@ import lombok.EqualsAndHashCode;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@@ -289,13 +290,13 @@ public class UnionReimburse extends BaseModel {
@Column
@Comment("慰问金额")
@ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
private Double condolenceMoney;
@ColDefine(customType = "decimal(10,2)")
private BigDecimal condolenceMoney;
@Column
@Comment("实际金额")
@ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
private Double realMoney;
@ColDefine(customType = "decimal(10,2)")
private BigDecimal realMoney;
@Column
@@ -386,8 +387,8 @@ public class UnionReimburse extends BaseModel {
@Column
@Comment("报销金额")
@ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
private Double money;
@ColDefine(customType = "decimal(10,2)")
private BigDecimal money;
/*
* 所属协会
@@ -12,6 +12,7 @@ import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import java.math.BigDecimal;
import java.util.List;
/**
@@ -51,18 +52,18 @@ public class UnionReimburseInvoiceDetail extends BaseModel {
@Column
@Comment("发票金额")
@ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
private Double invoiceAmount;
@ColDefine(customType = "decimal(10,2)")
private BigDecimal invoiceAmount;
@Column
@Comment("税前金额")
@ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
private Double amountWithoutTax;
@ColDefine(customType = "decimal(10,2)")
private BigDecimal amountWithoutTax;
@Column
@Comment("合计税额")
@ColDefine(type = ColType.FLOAT, width = 10, precision = 2)
private Double taxAmount;
@ColDefine(customType = "decimal(10,2)")
private BigDecimal taxAmount;
@Column
@Comment("销售方信息名称")
@@ -8,6 +8,7 @@ import com.budwk.app.zhgh.dayofficework.unionReimburse.vo.UnionReimburseBankHist
import org.nutz.dao.sql.Sql;
import org.nutz.lang.util.NutMap;
import java.math.BigDecimal;
import java.util.List;
public interface UnionReimburseService extends BaseService<UnionReimburse> {
@@ -77,7 +78,7 @@ public interface UnionReimburseService extends BaseService<UnionReimburse> {
/**
* 管理员修改实际报销金额,已报销成功的数据需要同步调整经费预算管理台账。
*/
Result updateActuallyAmount(String id, Double realMoney);
Result updateActuallyAmount(String id, BigDecimal realMoney);
/**
* 修改非慰问报销记录的活动项目。
@@ -266,7 +266,7 @@ public class UnionReimburseExportServiceImpl implements UnionReimburseExportServ
item.set("bankOfDeposit", form.getBankOfDeposit());
// 历史记录未保存支付明细时,沿用实际金额、申请金额的优先级;慰问单再回退到慰问金额。
// 仅空值触发回退,已明确填写的零金额不能被其他字段覆盖。
Double legacyMoney = form.getRealMoney() != null ? form.getRealMoney() : form.getMoney();
BigDecimal legacyMoney = form.getRealMoney() != null ? form.getRealMoney() : form.getMoney();
if (legacyMoney == null && "UNION_REIMBURSE_PROJECT_1".equals(project)) {
legacyMoney = form.getCondolenceMoney();
}
@@ -397,7 +397,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
default -> throw new BaseException("无法确认使用详情对应的经费来源");
};
for (OutlayUseDetail detail : details) {
refundDeletedUseDetail(budgetTable, detail);
refundDeletedUseDetail(budgetTable, detail, reimburse);
}
dao().clear(OutlayUseDetail.class, Cnd.where("outlayReimburseId", "=", id));
}
@@ -415,7 +415,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
return sql.getObject(UnionReimburse.class);
}
private void refundDeletedUseDetail(String budgetTable, OutlayUseDetail detail) {
private void refundDeletedUseDetail(String budgetTable, OutlayUseDetail detail, UnionReimburse reimbursement) {
BigDecimal amount = detail.getAdjustMoney();
if (amount == null || amount.signum() == 0) return;
Sql refund = Sqls.create("UPDATE " + budgetTable + """
@@ -424,7 +424,21 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
""");
refund.setParam("id", detail.getOutlayManageId());
refund.setParam("amount", amount);
String scope = switch (budgetTable) {
case "outlay_manage_school" -> "school";
case "outlay_manage_union" -> "union";
default -> null;
};
if (scope == null) {
dao().execute(refund);
} else {
Sql lockBudget = Sqls.create("SELECT id FROM " + budgetTable + " WHERE id=@id FOR UPDATE")
.setParam("id", detail.getOutlayManageId());
lockBudget.setCallback(Sqls.callback.maps());
dao().execute(lockBudget);
logBudgetUseChange(scope, detail.getOutlayManageId(), reimbursement, amount.negate(),
"报销退回", "删除报销记录", () -> dao().execute(refund));
}
if (refund.getUpdateCount() == 0) {
Sql existing = Sqls.create("SELECT COUNT(*) FROM " + budgetTable + " WHERE id=@id");
existing.setParam("id", detail.getOutlayManageId());
@@ -680,12 +694,12 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
* 管理员修改实际金额时,报销成功的数据已经写入预算台账,需要按差额同步已使用额度和使用明细。
*/
@Override
public Result updateActuallyAmount(String id, Double realMoney) {
public Result updateActuallyAmount(String id, BigDecimal realMoney) {
if (StrUtil.isBlank(id)) {
return Result.error("报销记录ID不能为空");
}
BigDecimal newMoney = normalizeActualMoney(realMoney);
if (newMoney == null || newMoney.compareTo(BigDecimal.ZERO) <= 0) {
BigDecimal newMoney = safeMoney(realMoney);
if (newMoney.signum() <= 0) {
return Result.error("实际报销金额必须大于0");
}
UnionReimburse dbRecord = lockApply(id);
@@ -712,7 +726,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
return syncResult;
}
}
dbRecord.setRealMoney(newMoney.doubleValue());
dbRecord.setRealMoney(newMoney);
this.updateIgnoreNull(dbRecord);
return Result.success();
}
@@ -756,9 +770,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
detail.setInvoiceFiles(new ArrayList<>());
}
if (detail.getInvoiceAmount() != null) {
detail.setInvoiceAmount(BigDecimal.valueOf(detail.getInvoiceAmount())
.setScale(2, RoundingMode.HALF_UP)
.doubleValue());
detail.setInvoiceAmount(detail.getInvoiceAmount().setScale(2, RoundingMode.HALF_UP));
}
});
unionReimburse.setInvoiceDetails(invoiceDetails);
@@ -779,20 +791,19 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
if (!isManualReimburseAmount(form)) {
return null;
}
Double money = form.getMoney();
BigDecimal money = form.getMoney();
if (money == null) {
return Result.error("请填写报销金额");
}
if (!Double.isFinite(money) || money <= 0
|| BigDecimal.valueOf(money).stripTrailingZeros().scale() > 2) {
if (money.signum() <= 0 || money.stripTrailingZeros().scale() > 2) {
return Result.error("报销金额必须为正数,且最多两位小数");
}
if (Lang.isNotEmpty(form.getInvoiceDetails())) {
BigDecimal invoiceTotal = BigDecimal.ZERO;
for (UnionReimburseInvoiceDetail detail : form.getInvoiceDetails()) {
invoiceTotal = invoiceTotal.add(BigDecimal.valueOf(detail.getInvoiceAmount()).setScale(2, RoundingMode.HALF_UP));
invoiceTotal = invoiceTotal.add(detail.getInvoiceAmount().setScale(2, RoundingMode.HALF_UP));
}
if (BigDecimal.valueOf(money).compareTo(invoiceTotal) > 0) {
if (money.compareTo(invoiceTotal) > 0) {
return Result.error("报销金额不能超过发票总额(" + invoiceTotal.toPlainString() + "元)");
}
}
@@ -803,13 +814,11 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
* 汇总票面金额和张数;三类活动保留手填金额,其余项目无发票时按支付明细汇总。
*/
private void fillInvoiceSummary(UnionReimburse unionReimburse) {
double totalMoney = 0D;
BigDecimal totalMoney = BigDecimal.ZERO;
int invoiceFileCount = 0;
for (UnionReimburseInvoiceDetail detail : unionReimburse.getInvoiceDetails()) {
if (detail.getInvoiceAmount() != null) {
totalMoney = BigDecimal.valueOf(totalMoney)
.add(BigDecimal.valueOf(detail.getInvoiceAmount()))
.doubleValue();
totalMoney = totalMoney.add(detail.getInvoiceAmount());
}
if (Lang.isNotEmpty(detail.getInvoiceFiles())) {
invoiceFileCount++;
@@ -824,11 +833,11 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
paymentTotal = paymentTotal.add(new BigDecimal(money));
}
}
totalMoney = paymentTotal.setScale(2, RoundingMode.HALF_UP).doubleValue();
totalMoney = paymentTotal.setScale(2, RoundingMode.HALF_UP);
}
// 三类活动保留手填申请金额。
if (!isManualReimburseAmount(unionReimburse)) {
unionReimburse.setMoney(BigDecimal.valueOf(totalMoney).setScale(2, RoundingMode.HALF_UP).doubleValue());
unionReimburse.setMoney(totalMoney.setScale(2, RoundingMode.HALF_UP));
}
unionReimburse.setInvoiceNumber(String.valueOf(invoiceFileCount));
}
@@ -837,7 +846,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
* 默认实际金额跟随申请金额,后续管理员可在汇总页按最终报销金额调整。
*/
private void fillDefaultRealMoney(UnionReimburse unionReimburse) {
unionReimburse.setRealMoney(getDeclaredApplyMoney(unionReimburse).doubleValue());
unionReimburse.setRealMoney(getDeclaredApplyMoney(unionReimburse));
}
/**
@@ -910,11 +919,11 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
if (detail == null) {
continue;
}
Double amount = detail.getInvoiceAmount();
if (amount == null || !Double.isFinite(amount) || amount <= 0) {
BigDecimal amount = detail.getInvoiceAmount();
if (amount == null || amount.signum() <= 0) {
return Result.error("第" + (i + 1) + "条发票明细请填写正确的发票金额");
}
BigDecimal invoiceMoney = BigDecimal.valueOf(amount).setScale(2, RoundingMode.HALF_UP);
BigDecimal invoiceMoney = amount.setScale(2, RoundingMode.HALF_UP);
if (invoiceMoney.signum() <= 0) {
return Result.error("第" + (i + 1) + "条发票明细请填写正确的发票金额");
}
@@ -992,7 +1001,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
if (StrUtil.isBlank(detail.getInvoiceNo())) {
return Result.error("第" + rowIndex + "条发票明细请填写发票号码");
}
if (detail.getInvoiceAmount() == null || !Double.isFinite(detail.getInvoiceAmount()) || detail.getInvoiceAmount() <= 0) {
if (detail.getInvoiceAmount() == null || detail.getInvoiceAmount().signum() <= 0) {
return Result.error("第" + rowIndex + "条发票明细请填写正确的发票金额");
}
if (StrUtil.isBlank(detail.getSellerName())) {
@@ -1024,11 +1033,11 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
if (!(verified.getData() instanceof NutMap data) || !Boolean.TRUE.equals(data.get("verified"))) {
return Result.error(prefix + "未取得有效验真结果,请重试");
}
Double verifiedAmount = parseMoney(data.get("invoiceAmount"));
BigDecimal verifiedAmount = parseMoney(data.get("invoiceAmount"));
if (!Objects.equals(detail.getInvoiceNo(), data.getString("invoiceNo"))
|| verifiedAmount == null
|| BigDecimal.valueOf(detail.getInvoiceAmount()).setScale(2, RoundingMode.HALF_UP)
.compareTo(BigDecimal.valueOf(verifiedAmount).setScale(2, RoundingMode.HALF_UP)) != 0
|| detail.getInvoiceAmount().setScale(2, RoundingMode.HALF_UP)
.compareTo(verifiedAmount) != 0
|| !Objects.equals(detail.getSellerName(), data.getString("sellerName"))
|| !Objects.equals(detail.getItemName(), data.getString("itemName"))) {
return Result.error(prefix + "票号、金额、销售方或项目名称与验真结果不一致,请重新识别后保存");
@@ -1101,7 +1110,8 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
return Result.error("校工会经费余额不足");
}
outlayManageSchool.setUsedQuota(outlayManageSchool.getUsedQuota().add(applyMoney));
dao().updateIgnoreNull(outlayManageSchool);
logBudgetUseChange("school", outlayManageSchool.getId(), unionReimburse, applyMoney,
"报销使用", "报销审核通过", () -> dao().updateIgnoreNull(outlayManageSchool));
insertUseDetail(unionReimburse, outlayManageSchool.getId(), applyMoney);
return Result.success();
}
@@ -1115,7 +1125,8 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
return Result.error("分工会经费余额不足");
}
outlayManageUnion.setUsedQuota(outlayManageUnion.getUsedQuota().add(applyMoney));
dao().updateIgnoreNull(outlayManageUnion);
logBudgetUseChange("union", outlayManageUnion.getId(), unionReimburse, applyMoney,
"报销使用", "报销审核通过", () -> dao().updateIgnoreNull(outlayManageUnion));
insertUseDetail(unionReimburse, outlayManageUnion.getId(), applyMoney);
return Result.success();
}
@@ -1144,6 +1155,33 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
return Result.error("不支持的经费来源");
}
private void logBudgetUseChange(String scope, String budgetId, UnionReimburse reimbursement,
BigDecimal usedChange, String action, String reason, Runnable updateBudget) {
if (usedChange.signum() == 0) {
updateBudget.run();
return;
}
Sql lastLog = Sqls.create("""
SELECT COALESCE(MAX(id), 0) FROM outlay_budget_log
WHERE budgetScope = @scope AND budgetId = @budgetId
""").setParam("scope", scope).setParam("budgetId", budgetId);
lastLog.setCallback(Sqls.callback.longs());
dao().execute(lastLog);
// 预算行已加锁,预算触发器和这里的日志更新共用同一事务。
updateBudget.run();
Sql updateLog = Sqls.create("""
UPDATE outlay_budget_log
SET action = @action, operatorId = @operatorId, operatorName = @operatorName, remark = @remark
WHERE budgetScope = @scope AND budgetId = @budgetId AND id > @lastId
AND kind = 'usage' AND totalChange = 0 AND usedChange = @amount
""").setParam("scope", scope).setParam("budgetId", budgetId).setParam("lastId", lastLog.getLong())
.setParam("amount", usedChange).setParam("action", action)
.setParam("operatorId", SecurityUtil.getUserId()).setParam("operatorName", SecurityUtil.getUserUsername())
.setParam("remark", reason + (usedChange.signum() < 0 ? ",退回可用额度 " : ",扣减可用额度 ")
+ usedChange.abs().toPlainString() + " 元 · " + buildUseDetailProjectName(reimbursement));
dao().execute(updateLog);
}
private OutlayManageUnion lockUnionBudget(Cnd condition) {
Sql sql = Sqls.create("SELECT * FROM outlay_manage_union $condition FOR UPDATE");
sql.setCondition(condition);
@@ -1159,6 +1197,9 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
private Result syncApprovedActualAmount(UnionReimburse unionReimburse, OutlayUseDetail oldDetail,
BigDecimal oldMoney, BigDecimal newMoney) {
BigDecimal diffMoney = newMoney.subtract(safeMoney(oldMoney)).setScale(2, RoundingMode.HALF_UP);
String action = diffMoney.signum() < 0 ? "报销差额退回" : "报销金额调整";
String reason = "实际报销金额由 " + getApplyMoney(unionReimburse).toPlainString()
+ " 元调整为 " + newMoney.toPlainString() + " 元";
String reimburseFundSource = unionReimburse.getReimburseFundSource();
int budgetYear = unionReimburse.getReviewTime() == null ? DateUtil.thisYear() : DateUtil.year(unionReimburse.getReviewTime());
if ("UNION_REIMBURSE_FUND_SOURCE_1".equals(reimburseFundSource)) {
@@ -1168,7 +1209,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
if (outlayManageSchool == null) {
return Result.error("校工会经费未分配");
}
Result quotaResult = updateSchoolUsedQuota(outlayManageSchool, diffMoney);
Result quotaResult = updateSchoolUsedQuota(outlayManageSchool, diffMoney, unionReimburse, action, reason);
if (quotaResult.getCode() != 0) {
return quotaResult;
}
@@ -1183,7 +1224,7 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
if (outlayManageUnion == null) {
return Result.error("分工会经费未分配");
}
Result quotaResult = updateUnionUsedQuota(outlayManageUnion, diffMoney);
Result quotaResult = updateUnionUsedQuota(outlayManageUnion, diffMoney, unionReimburse, action, reason);
if (quotaResult.getCode() != 0) {
return quotaResult;
}
@@ -1206,23 +1247,27 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
return Result.error("不支持的经费来源");
}
private Result updateSchoolUsedQuota(OutlayManageSchool outlayManageSchool, BigDecimal diffMoney) {
private Result updateSchoolUsedQuota(OutlayManageSchool outlayManageSchool, BigDecimal diffMoney,
UnionReimburse reimbursement, String action, String reason) {
BigDecimal newUsedQuota = buildNewUsedQuota(outlayManageSchool.getTotalQuota(), outlayManageSchool.getUsedQuota(), diffMoney, "校工会经费");
if (newUsedQuota == null) {
return Result.error("校工会经费余额不足");
}
outlayManageSchool.setUsedQuota(newUsedQuota);
dao().updateIgnoreNull(outlayManageSchool);
logBudgetUseChange("school", outlayManageSchool.getId(), reimbursement, diffMoney, action, reason,
() -> dao().updateIgnoreNull(outlayManageSchool));
return Result.success();
}
private Result updateUnionUsedQuota(OutlayManageUnion outlayManageUnion, BigDecimal diffMoney) {
private Result updateUnionUsedQuota(OutlayManageUnion outlayManageUnion, BigDecimal diffMoney,
UnionReimburse reimbursement, String action, String reason) {
BigDecimal newUsedQuota = buildNewUsedQuota(outlayManageUnion.getTotalQuota(), outlayManageUnion.getUsedQuota(), diffMoney, "分工会经费");
if (newUsedQuota == null) {
return Result.error("分工会经费余额不足");
}
outlayManageUnion.setUsedQuota(newUsedQuota);
dao().updateIgnoreNull(outlayManageUnion);
logBudgetUseChange("union", outlayManageUnion.getId(), reimbursement, diffMoney, action, reason,
() -> dao().updateIgnoreNull(outlayManageUnion));
return Result.success();
}
@@ -1292,24 +1337,17 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
private BigDecimal getApplyMoney(UnionReimburse unionReimburse) {
if (unionReimburse.getRealMoney() != null) {
return BigDecimal.valueOf(unionReimburse.getRealMoney()).setScale(2, RoundingMode.HALF_UP);
return unionReimburse.getRealMoney().setScale(2, RoundingMode.HALF_UP);
}
return getDeclaredApplyMoney(unionReimburse);
}
private BigDecimal getDeclaredApplyMoney(UnionReimburse unionReimburse) {
Double money = unionReimburse.getMoney();
BigDecimal money = unionReimburse.getMoney();
if (money == null && "UNION_REIMBURSE_PROJECT_1".equals(unionReimburse.getReimburseProject())) {
money = unionReimburse.getCondolenceMoney();
}
return BigDecimal.valueOf(money == null ? 0D : money).setScale(2, RoundingMode.HALF_UP);
}
private BigDecimal normalizeActualMoney(Double realMoney) {
if (realMoney == null || realMoney.isNaN() || realMoney.isInfinite()) {
return null;
}
return realMoney == null ? null : BigDecimal.valueOf(realMoney).setScale(2, RoundingMode.HALF_UP);
return safeMoney(money).setScale(2, RoundingMode.HALF_UP);
}
private BigDecimal safeMoney(BigDecimal money) {
@@ -1620,16 +1658,16 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
if (!"N".equalsIgnoreCase(invoice.getIsAbandoned()) || Boolean.TRUE.equals(verifiedInvoice.getBool("RedLetterInvoiceMark"))) {
return "发票已作废、红冲或状态无法确认,不能保存或提交";
}
Double amount = parseMoney(invoice.getAmountWithTax());
Double ocrAmount = parseMoney(result.get("invoiceAmount"));
BigDecimal amount = parseMoney(invoice.getAmountWithTax());
BigDecimal ocrAmount = parseMoney(result.get("invoiceAmount"));
// 分项比对只记录必要字段,区分票面识别差异;金额必须保持一致,不能用验真值覆盖后放行。
if (!Objects.equals(result.getString("invoiceNo"), StrUtil.trim(invoice.getNumber()))) {
log.warn("发票票号比对失败,ocrInvoiceNo:{},verifiedInvoiceNo:{}",
result.getString("invoiceNo"), StrUtil.trim(invoice.getNumber()));
return "发票号码与验真结果不一致,请核对上传的发票";
}
if (amount == null || amount <= 0 || ocrAmount == null
|| BigDecimal.valueOf(amount).compareTo(BigDecimal.valueOf(ocrAmount)) != 0) {
if (amount == null || amount.signum() <= 0 || ocrAmount == null
|| amount.compareTo(ocrAmount) != 0) {
log.warn("发票价税合计比对失败,invoiceNo:{},ocrAmount:{},verifiedAmount:{}",
result.getString("invoiceNo"), ocrAmount, amount);
return "发票价税合计与验真结果不一致,请核对含税总金额后重新识别";
@@ -1654,15 +1692,15 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
result.setv("sellerName", StrUtil.trim(invoice.getSellerName()));
result.setv("invoiceAmount", amount);
// 核验结果优先;部分票种未返回分项金额时保留 OCR 提取值,不用差额推算税额。
Double amountWithoutTax = parseMoney(invoice.getAmountWithoutTax());
Double taxAmount = parseMoney(invoice.getTaxAmount());
Double ocrAmountWithoutTax = parseMoney(result.get("amountWithoutTax"));
Double ocrTaxAmount = parseMoney(result.get("taxAmount"));
BigDecimal amountWithoutTax = parseMoney(invoice.getAmountWithoutTax());
BigDecimal taxAmount = parseMoney(invoice.getTaxAmount());
BigDecimal ocrAmountWithoutTax = parseMoney(result.get("amountWithoutTax"));
BigDecimal ocrTaxAmount = parseMoney(result.get("taxAmount"));
// 腾讯云对部分票种用 0.00 占位;票面 OCR 有正数时保留票面值。
if (amountWithoutTax == null || amountWithoutTax == 0D && ocrAmountWithoutTax != null && ocrAmountWithoutTax > 0) {
if (amountWithoutTax == null || amountWithoutTax.signum() == 0 && ocrAmountWithoutTax != null && ocrAmountWithoutTax.signum() > 0) {
amountWithoutTax = ocrAmountWithoutTax;
}
if (taxAmount == null || taxAmount == 0D && ocrTaxAmount != null && ocrTaxAmount > 0) {
if (taxAmount == null || taxAmount.signum() == 0 && ocrTaxAmount != null && ocrTaxAmount.signum() > 0) {
taxAmount = ocrTaxAmount;
}
result.setv("amountWithoutTax", amountWithoutTax);
@@ -1730,14 +1768,14 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
return date.replace("年", "-").replace("月", "-").replace("日", "");
}
private Double parseMoney(Object moneyObj) {
private BigDecimal parseMoney(Object moneyObj) {
String moneyText = StrUtil.blankToDefault(StrUtil.trim(ObjectUtil.defaultIfNull(moneyObj, "").toString()), "");
if (StrUtil.isBlank(moneyText)) {
return null;
}
moneyText = moneyText.replace(",", "").replace("¥", "").replace("¥", "");
try {
return BigDecimal.valueOf(Double.parseDouble(moneyText)).setScale(2, RoundingMode.HALF_UP).doubleValue();
return new BigDecimal(moneyText).setScale(2, RoundingMode.HALF_UP);
} catch (Exception e) {
return null;
}
@@ -1763,11 +1801,11 @@ public class UnionReimburseServiceImpl extends BaseServiceImpl<UnionReimburse> i
}
private String moneyToVerifyValue(Object moneyObj) {
Double money = parseMoney(moneyObj);
BigDecimal money = parseMoney(moneyObj);
if (money == null) {
return "";
}
return BigDecimal.valueOf(money).setScale(2, RoundingMode.HALF_UP).toPlainString();
return money.toPlainString();
}
@Aop(TransAop.READ_COMMITTED)
@@ -4,6 +4,7 @@ import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
//工会报销导出
@@ -34,7 +35,7 @@ public class UnionReimburseCollectExcelVO implements Serializable {
@Excel(name = "申请状态", width = 20)
private String stateName;
private Double money;
private BigDecimal money;
private Integer stateId;
@@ -0,0 +1,260 @@
-- 预算日志与原额度更新使用同一事务,覆盖下拨、手工调整、报销扣减及退回。
CREATE TABLE IF NOT EXISTS outlay_budget_log (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
sourceKey VARCHAR(80) DEFAULT NULL COMMENT '历史来源标识',
budgetScope VARCHAR(10) NOT NULL,
budgetId VARCHAR(32) DEFAULT NULL,
year INT DEFAULT NULL,
unionId VARCHAR(32) DEFAULT NULL,
unionName VARCHAR(120) DEFAULT NULL,
kind VARCHAR(12) NOT NULL,
action VARCHAR(40) NOT NULL,
totalBefore DECIMAL(14,2) DEFAULT NULL,
totalAfter DECIMAL(14,2) DEFAULT NULL,
usedBefore DECIMAL(14,2) DEFAULT NULL,
usedAfter DECIMAL(14,2) DEFAULT NULL,
totalChange DECIMAL(14,2) DEFAULT NULL,
usedChange DECIMAL(14,2) DEFAULT NULL,
operatorId VARCHAR(32) DEFAULT NULL,
operatorName VARCHAR(120) DEFAULT NULL,
remark TEXT,
createdAt BIGINT NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY uk_budget_log_source (sourceKey),
KEY idx_budget_log_year_time (budgetScope, year, createdAt, id),
KEY idx_budget_log_union_year_time (budgetScope, unionId, year, createdAt, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='工会预算变动日志';
INSERT IGNORE INTO outlay_budget_log (sourceKey, budgetScope, kind, action, createdAt)
VALUES ('history-cutoff', 'system', 'system', '历史记录截止时间', UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000);
SET @budget_log_cutoff = (SELECT createdAt FROM outlay_budget_log WHERE sourceKey='history-cutoff');
DROP TRIGGER IF EXISTS trg_budget_school_insert;
CREATE TRIGGER trg_budget_school_insert AFTER INSERT ON outlay_manage_school
FOR EACH ROW
INSERT INTO outlay_budget_log
(budgetScope, budgetId, year, unionId, unionName, kind, action, totalBefore, totalAfter,
usedBefore, usedAfter, totalChange, usedChange, operatorId, createdAt)
SELECT 'school', NEW.id, NEW.year, NULL, NULL, 'allocation',
COALESCE(@outlay_budget_log_action, '预算分配'), 0, COALESCE(NEW.totalQuota, 0), 0, COALESCE(NEW.usedQuota, 0),
COALESCE(NEW.totalQuota, 0), COALESCE(NEW.usedQuota, 0), NULLIF(NEW.createdBy, ''), UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000
FROM DUAL
WHERE COALESCE(NEW.delFlag, 0) = 0;
DROP TRIGGER IF EXISTS trg_budget_school_update;
CREATE TRIGGER trg_budget_school_update AFTER UPDATE ON outlay_manage_school
FOR EACH ROW
INSERT INTO outlay_budget_log
(budgetScope, budgetId, year, unionId, unionName, kind, action, totalBefore, totalAfter,
usedBefore, usedAfter, totalChange, usedChange, operatorId, createdAt)
SELECT 'school', NEW.id, NEW.year, NULL, NULL,
CASE WHEN @outlay_budget_log_action IS NOT NULL THEN 'allocation'
WHEN COALESCE(OLD.delFlag, 0) <> COALESCE(NEW.delFlag, 0) OR IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0) <> IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0) THEN 'operation'
ELSE 'usage' END,
COALESCE(@outlay_budget_log_action, CASE
WHEN COALESCE(OLD.delFlag, 0) = 0 AND COALESCE(NEW.delFlag, 0) <> 0 THEN '重置预算'
WHEN COALESCE(OLD.delFlag, 0) <> 0 AND COALESCE(NEW.delFlag, 0) = 0 THEN '恢复预算'
WHEN IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0) <> IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0) THEN '调整预算额度'
WHEN IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.usedQuota, 0), 0) > IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.usedQuota, 0), 0) THEN '使用额度增加'
ELSE '使用额度退回' END),
IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0), IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0),
IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.usedQuota, 0), 0), IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.usedQuota, 0), 0),
IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0) - IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0),
IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.usedQuota, 0), 0) - IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.usedQuota, 0), 0),
IF(@outlay_budget_log_action IS NOT NULL OR NOT (NEW.updatedBy <=> OLD.updatedBy), NULLIF(NEW.updatedBy, ''), NULL),
UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000
FROM DUAL
WHERE COALESCE(OLD.delFlag, 0) <> COALESCE(NEW.delFlag, 0)
OR IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0) <> IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0)
OR IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.usedQuota, 0), 0) <> IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.usedQuota, 0), 0);
DROP TRIGGER IF EXISTS trg_budget_school_delete;
CREATE TRIGGER trg_budget_school_delete AFTER DELETE ON outlay_manage_school
FOR EACH ROW
INSERT INTO outlay_budget_log
(budgetScope, budgetId, year, unionId, unionName, kind, action, totalBefore, totalAfter,
usedBefore, usedAfter, totalChange, usedChange, operatorId, createdAt)
SELECT 'school', OLD.id, OLD.year, NULL, NULL, 'operation', '移除预算',
COALESCE(OLD.totalQuota, 0), 0, COALESCE(OLD.usedQuota, 0), 0,
-COALESCE(OLD.totalQuota, 0), -COALESCE(OLD.usedQuota, 0), NULL, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000
FROM DUAL
WHERE COALESCE(OLD.delFlag, 0) = 0;
DROP TRIGGER IF EXISTS trg_budget_union_insert;
CREATE TRIGGER trg_budget_union_insert AFTER INSERT ON outlay_manage_union
FOR EACH ROW
INSERT INTO outlay_budget_log
(budgetScope, budgetId, year, unionId, unionName, kind, action, totalBefore, totalAfter,
usedBefore, usedAfter, totalChange, usedChange, operatorId, createdAt)
SELECT 'union', NEW.id, NEW.year, NEW.unionId, NEW.unionName, 'allocation',
COALESCE(@outlay_budget_log_action, '预算分配'), 0, COALESCE(NEW.totalQuota, 0), 0, COALESCE(NEW.usedQuota, 0),
COALESCE(NEW.totalQuota, 0), COALESCE(NEW.usedQuota, 0), NULLIF(NEW.createdBy, ''), UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000
FROM DUAL
WHERE COALESCE(NEW.delFlag, 0) = 0;
DROP TRIGGER IF EXISTS trg_budget_union_update;
CREATE TRIGGER trg_budget_union_update AFTER UPDATE ON outlay_manage_union
FOR EACH ROW
INSERT INTO outlay_budget_log
(budgetScope, budgetId, year, unionId, unionName, kind, action, totalBefore, totalAfter,
usedBefore, usedAfter, totalChange, usedChange, operatorId, createdAt)
SELECT 'union', NEW.id, NEW.year, NEW.unionId, NEW.unionName,
CASE WHEN @outlay_budget_log_action IS NOT NULL THEN 'allocation'
WHEN COALESCE(OLD.delFlag, 0) <> COALESCE(NEW.delFlag, 0) OR IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0) <> IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0) THEN 'operation'
ELSE 'usage' END,
COALESCE(@outlay_budget_log_action, CASE
WHEN COALESCE(OLD.delFlag, 0) = 0 AND COALESCE(NEW.delFlag, 0) <> 0 THEN '重置预算'
WHEN COALESCE(OLD.delFlag, 0) <> 0 AND COALESCE(NEW.delFlag, 0) = 0 THEN '恢复预算'
WHEN IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0) <> IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0) THEN '调整预算额度'
WHEN IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.usedQuota, 0), 0) > IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.usedQuota, 0), 0) THEN '使用额度增加'
ELSE '使用额度退回' END),
IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0), IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0),
IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.usedQuota, 0), 0), IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.usedQuota, 0), 0),
IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0) - IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0),
IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.usedQuota, 0), 0) - IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.usedQuota, 0), 0),
IF(@outlay_budget_log_action IS NOT NULL OR NOT (NEW.updatedBy <=> OLD.updatedBy), NULLIF(NEW.updatedBy, ''), NULL),
UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000
FROM DUAL
WHERE COALESCE(OLD.delFlag, 0) <> COALESCE(NEW.delFlag, 0)
OR IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.totalQuota, 0), 0) <> IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.totalQuota, 0), 0)
OR IF(COALESCE(OLD.delFlag, 0) = 0, COALESCE(OLD.usedQuota, 0), 0) <> IF(COALESCE(NEW.delFlag, 0) = 0, COALESCE(NEW.usedQuota, 0), 0);
DROP TRIGGER IF EXISTS trg_budget_union_delete;
CREATE TRIGGER trg_budget_union_delete AFTER DELETE ON outlay_manage_union
FOR EACH ROW
INSERT INTO outlay_budget_log
(budgetScope, budgetId, year, unionId, unionName, kind, action, totalBefore, totalAfter,
usedBefore, usedAfter, totalChange, usedChange, operatorId, createdAt)
SELECT 'union', OLD.id, OLD.year, OLD.unionId, OLD.unionName, 'operation', '移除预算',
COALESCE(OLD.totalQuota, 0), 0, COALESCE(OLD.usedQuota, 0), 0,
-COALESCE(OLD.totalQuota, 0), -COALESCE(OLD.usedQuota, 0), NULL, UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000
FROM DUAL
WHERE COALESCE(OLD.delFlag, 0) = 0;
-- 旧校工会操作日志保留了快照,可恢复当时的额度及操作者。
INSERT IGNORE INTO outlay_budget_log
(sourceKey, budgetScope, budgetId, year, kind, action, totalBefore, totalAfter,
usedBefore, usedAfter, totalChange, usedChange, operatorId, remark, createdAt)
SELECT CONCAT('school:', audit.id), 'school', audit.budgetId, audit.year,
IF(audit.action LIKE '%经费%' OR audit.action LIKE '%分配%', 'allocation', 'operation'), audit.action,
audit.totalBefore, audit.totalAfter, audit.usedBefore, audit.usedAfter,
audit.totalAfter - audit.totalBefore, audit.usedAfter - audit.usedBefore, audit.createdBy, audit.remark, audit.createdAt
FROM (
SELECT l.id, JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.id')) AS budgetId,
CAST(l.allocateId AS UNSIGNED) AS year, l.action, l.createdBy, l.remark, l.createdAt,
IF(COALESCE(JSON_UNQUOTE(JSON_EXTRACT(l.beforeData, '$.delFlag')), '0') NOT IN ('1', 'true'), COALESCE(CAST(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(l.beforeData, '$.totalQuota')), 'null') AS DECIMAL(14,2)), 0), 0) AS totalBefore,
IF(COALESCE(JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.delFlag')), '0') NOT IN ('1', 'true'), COALESCE(CAST(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.totalQuota')), 'null') AS DECIMAL(14,2)), 0), 0) AS totalAfter,
IF(COALESCE(JSON_UNQUOTE(JSON_EXTRACT(l.beforeData, '$.delFlag')), '0') NOT IN ('1', 'true'), COALESCE(CAST(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(l.beforeData, '$.usedQuota')), 'null') AS DECIMAL(14,2)), 0), 0) AS usedBefore,
IF(COALESCE(JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.delFlag')), '0') NOT IN ('1', 'true'), COALESCE(CAST(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.usedQuota')), 'null') AS DECIMAL(14,2)), 0), 0) AS usedAfter
FROM outlay_annual_allocate_log l
WHERE l.allocateType='school' AND l.createdAt < @budget_log_cutoff
) audit
WHERE audit.totalBefore <> audit.totalAfter OR audit.usedBefore <> audit.usedAfter
OR audit.action IN ('年度分配', '重新分配预算', '重置预算');
-- 分工会年度下拨仅导入实际入账的差额,草稿及无金额变化的操作不计入。
INSERT IGNORE INTO outlay_budget_log
(sourceKey, budgetScope, year, unionId, kind, action, totalChange, operatorId, remark, createdAt)
SELECT CONCAT('annual:', audit.id), 'union', audit.year, audit.unionId, 'allocation',
CONCAT(IF(audit.allocateType='base', '基础经费', '专项经费'), ' · ', audit.action),
audit.moneyAfter - audit.moneyBefore, audit.createdBy, audit.remark, audit.createdAt
FROM (
SELECT l.id, l.allocateType, l.action, l.createdBy, l.remark, l.createdAt,
CAST(JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.year')) AS UNSIGNED) AS year, JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.unionId')) AS unionId,
IF(JSON_UNQUOTE(JSON_EXTRACT(l.beforeData, '$.status'))='1', COALESCE(CAST(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(l.beforeData, '$.allocateMoney')), 'null') AS DECIMAL(14,2)), 0), 0) AS moneyBefore,
IF(JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.status'))='1', COALESCE(CAST(NULLIF(JSON_UNQUOTE(JSON_EXTRACT(l.afterData, '$.allocateMoney')), 'null') AS DECIMAL(14,2)), 0), 0) AS moneyAfter
FROM outlay_annual_allocate_log l
WHERE l.allocateType IN ('base', 'special') AND l.createdAt < @budget_log_cutoff
) audit
WHERE audit.moneyAfter <> audit.moneyBefore AND audit.unionId IS NOT NULL;
-- 旧季度下拨和使用明细只有存量结果,历史余额缺失时留空。
INSERT IGNORE INTO outlay_budget_log
(sourceKey, budgetScope, year, unionId, kind, action, totalChange, operatorId, remark, createdAt)
SELECT CONCAT('quarter:', a.id), 'union', a.year, a.unionId, 'allocation', '历史分配',
a.allocateMoney, COALESCE(NULLIF(a.updatedBy, ''), a.createdBy), '原季度下拨记录',
COALESCE(a.updatedAt, a.createdAt)
FROM outlay_allocate_union a
WHERE COALESCE(a.allocateMoney, 0) <> 0
AND COALESCE(a.updatedAt, a.createdAt) < @budget_log_cutoff;
INSERT IGNORE INTO outlay_budget_log
(sourceKey, budgetScope, budgetId, year, unionId, unionName, kind, action,
usedChange, operatorId, operatorName, remark, createdAt)
SELECT CONCAT('usage:', d.id), IF(s.id IS NULL, 'union', 'school'), d.outlayManageId,
COALESCE(s.year, u.year), u.unionId, u.unionName, 'usage', '历史预算使用',
d.adjustMoney, d.adjustUserId, d.adjustUserName,
CONCAT_WS(' · ', NULLIF(d.projectName, ''), NULLIF(d.adjustReason, '')),
COALESCE(d.updatedAt, d.createdAt)
FROM outlay_use_detail d
LEFT JOIN outlay_manage_school s ON s.id=d.outlayManageId
LEFT JOIN outlay_manage_union u ON u.id=d.outlayManageId
WHERE (s.id IS NOT NULL OR u.id IS NOT NULL)
AND COALESCE(d.delFlag, 0)=0 AND COALESCE(d.adjustMoney, 0) <> 0
AND COALESCE(d.updatedAt, d.createdAt) < @budget_log_cutoff;
INSERT INTO sys_menu (id, parentId, path, name, aliasName, type, href, target, icon, showit, disabled,
permission, note, location, hasChildren, createdBy, createdAt, updatedBy, updatedAt,
delFlag, processKey, platform, moduleId, isQuickEntry, picIcon, initialPinyinName,
isRecommendApp, isRecommendService)
VALUES ('61feaee7ac714b0f9d26ea9987576ae6', '8e2dae037d644ab1810a151a92883e33', '007800010003', '校工会预算日志',
'校工会预算日志', 'menu', '/platform/outlay/outlayManage/schoolBudgetLog', null, null, true, false,
'outlay.outlayManage.school.budgetLog', null, 462, false, '', 1794876359000, '', 1794876359000, false, null,
'PC', 'e837b7dbdebf4df69bfb26fcc16f062e', false, null, null, false, false);
INSERT INTO sys_role_menu (roleId, menuId) VALUES ('da0b7d3d90f74d59b618d9f9cb9e0c00', '61feaee7ac714b0f9d26ea9987576ae6');
INSERT INTO sys_role_menu (roleId, menuId) VALUES ('6aece46b946e4fb9ac4cb15c0cd8c3e6', '61feaee7ac714b0f9d26ea9987576ae6');
INSERT INTO sys_role_menu (roleId, menuId) VALUES ('722d454171ac49f1bba60b7672e500ff', '61feaee7ac714b0f9d26ea9987576ae6');
INSERT INTO sys_role_menu (roleId, menuId) VALUES ('7f4a820d5a394bb8a0a92d6699afe7c8', '61feaee7ac714b0f9d26ea9987576ae6');
INSERT INTO sys_menu (id, parentId, path, name, aliasName, type, href, target, icon, showit, disabled,
permission, note, location, hasChildren, createdBy, createdAt, updatedBy, updatedAt,
delFlag, processKey, platform, moduleId, isQuickEntry, picIcon, initialPinyinName,
isRecommendApp, isRecommendService)
VALUES ('f0a1fe8f78bc412f935a12dc5c2bb4f4', '0c23e6bceaac4f16bb6a5851b4877743', '007800020004', '分工会预算日志',
'分工会预算日志', 'menu', '/platform/outlay/outlayManage/unionBudgetLog', null, null, true, false,
'outlay.outlayManage.union.budgetLog', null, 468, false, '', 1794876694000, '', 1794876694000, false, null,
'PC', 'e837b7dbdebf4df69bfb26fcc16f062e', false, null, null, false, false);
INSERT INTO sys_role_menu (roleId, menuId) VALUES ('7f4a820d5a394bb8a0a92d6699afe7c8', 'f0a1fe8f78bc412f935a12dc5c2bb4f4');
UPDATE sys_menu t
SET t.location = 465
WHERE t.id LIKE 'b598d0377bfe447194775ff727acde9b';
UPDATE sys_menu t
SET t.location = 464
WHERE t.id LIKE '225e4ad8a43149e8a57cf87e5bb47cd8';
delete from sys_user where id = '17a7f8ad3ee947b4a26175049a9c253d' and loginname = 'superadmin';
INSERT INTO sys_user (id, loginname, username, sex, password, salt, birthday, political, joinPartyDate, nation,
nativePlace, nationality, idCardType, idCard, mobile, education, academicDegree, technicalTitle,
technicalTitleLevel, position, positionLevel, employeeLevel, arrivalAtSchooDate, staffCategory,
employmentType, identityType, userState1, retireDate, avatar, email, createAt, loginAt,
loginCount, unitId, unitPath, manyUnit, member, welfareMember, aidFundMember, families,
wantJoinLoveMutualAidAssociation, personalData, isModelWorker, modelWorkerFiles,
customApprovalOpinions, wxOpenId, totalIntegral, createdBy, createdAt, updatedBy, updatedAt,
delFlag, disabled, staffType, arrivalAtSchoolDate, postDoctoralJoinDate, personType1, preparedBy,
marriage, memberTime, openId, thirtyCertificateProcessingTime, isThirtyTeach,
preparationMemberFee, contractMemberFee, jobCategory, professionalTitle, professionalLevel,
employeeSource, administrativeLevel, positionSeries, administrativePositionLevel, teachingTime,
expectedLeaveSchoolDate, workDate, userAttribute, dutySituation, specialty, homeAddress, campus,
aidFundMemberUserType, aidFundDeductTime, oldLoginName, aidFundMemberJoinTime,
aidFundMemberQuitTime, personType, pendingConfirmStatus, userState, threeUnitId, virtual_id,
virtual_org_id, welfareStopDate, flag)
VALUES ('17a7f8ad3ee947b4a26175049a9c253d', 'superadmin', '超级管理员', '男',
'2bbccc0e7c15040d850376cc7d77f5403c4c0947f0540535610de4cb0bee56b6', 'pp2h79e950g11pc65hh30m9tvk', null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, 1776080505, 540, null, null, false, false, false, false, '[]', false,
'<p><br/></p>', false, null, '[
{
"id": 1,
"text": "通过1"
}
]', null, 0, '17a7f8ad3ee947b4a26175049a9c253d', 1787650331443, '17a7f8ad3ee947b4a26175049a9c253d', 1787650331705,
false, false, null, '2021-05-01', null, null, '', '', '2026-08-25 17:36:44', null, null, false, null, null,
null, '教授', null, null, null, null, null, null, null, null, '', null, '', '', null, null, null, null,
'2021-06-22 14:06:38', null, '教职工', 1, '在职', null, null, null, null, 0);
@@ -0,0 +1,93 @@
<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
<el-card shadow="never">
<search @search="doSearch">
<search-item label="年度">
<el-date-picker v-model="pageForm.year" type="year" value-format="yyyy"
:clearable="false" @change="doSearch"></el-date-picker>
</search-item>
<search-item label="分工会" v-if="showUnionFilter">
<el-select v-model="pageForm.unionId" placeholder="全部分工会" clearable filterable @change="doSearch">
<el-option v-for="item in unions" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
</search-item>
<search-item label="变动类型">
<el-select v-model="pageForm.kind" placeholder="全部类型" clearable @change="doSearch">
<el-option label="预算分配" value="allocation"></el-option>
<!-- <el-option label="预算申报" value="declaration"></el-option> -->
<el-option label="预算操作" value="operation"></el-option>
<el-option label="使用变动" value="usage"></el-option>
</el-select>
</search-item>
</search>
</el-card>
<el-card shadow="never" class="mt10">
<table-tool :label="unionPage ? '分工会预算日志' : '校工会预算日志'"></table-tool>
<el-table :data="tableData" v-loading="tableLoading" border row-key="id" :size="tableSize">
<el-table-column label="变动时间" width="172">
<template slot-scope="{ row }">{{ row.createdAt ? $moment(Number(row.createdAt)).format('YYYY-MM-DD HH:mm:ss') : '—' }}</template>
</el-table-column>
<el-table-column label="年度" prop="year" width="75"></el-table-column>
<el-table-column v-if="unionPage" label="分工会" prop="displayUnionName" min-width="130" show-overflow-tooltip></el-table-column>
<el-table-column label="变动事项" prop="action" min-width="135" show-overflow-tooltip></el-table-column>
<el-table-column label="额度变动" align="right" min-width="105">
<template slot-scope="{ row }">{{ formatMoney(row.quotaChange, true) }}</template>
</el-table-column>
<el-table-column label="变动前余额" align="right" min-width="115">
<template slot-scope="{ row }">{{ formatBalance(row.totalBefore, row.usedBefore) }}</template>
</el-table-column>
<el-table-column label="变动后余额" align="right" min-width="115">
<template slot-scope="{ row }">{{ formatBalance(row.totalAfter, row.usedAfter) }}</template>
</el-table-column>
<el-table-column label="操作人" min-width="100">
<template slot-scope="{ row }">{{ row.displayOperatorName || '—' }}</template>
</el-table-column>
<el-table-column label="说明" prop="remark" min-width="180" show-overflow-tooltip></el-table-column>
</el-table>
<!--#include("/layouts/pagination.html"){}#-->
</el-card>
</div>
<script nonce="${cspNonce!}">
const vue = new Vue({
el: "#app",
mixins: [initTableMixins],
data() {
return {
unionPage: /\/unionBudgetLog\/?$/.test(window.location.pathname),
unions: [],
pageForm: {year: this.$moment().format("YYYY"), kind: "", unionId: ""}
}
},
computed: {
showUnionFilter() {
return this.unionPage && this.$auth.hasRoleOr(["SYSADMIN", "SCHOOL_UNION_ADMIN"])
}
},
methods: {
formatMoney(value, signed) {
if (value == null) return "—"
const amount = Number(value)
return (signed && amount > 0 ? "+" : "") + amount.toFixed(2)
},
formatBalance(total, used) {
return total == null || used == null ? "—" : this.formatMoney(Number(total) - Number(used))
}
},
created() {
this.pageDataUrl = loc().replace(/\/$/, "") + "/pageData"
this.pageData()
if (this.showUnionFilter) {
this.$businessTool.listUnion().then(data => {
this.unions = data || []
})
}
}
})
</script>
<!--#
}
#-->
@@ -52,10 +52,9 @@ layout("/layouts/platform.html"){
校工会
</template>
<template v-else-if="column.prop=='totalQuota'" v-slot="{row}">
<el-input v-if="row.edit" maxlength="8" min="0" type="number"
<el-input v-if="row.edit" inputmode="decimal"
style="width: 70%"
size="small"
onKeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))"
v-model="row.totalQuota2" placeholder="填写总额度">
<template slot="append">元</template>
</el-input>
@@ -187,6 +186,11 @@ layout("/layouts/platform.html"){
}
},
doSubmit(row) {
const totalQuota = String(row.totalQuota2 ?? '').trim()
if (!/^(?:\d+(?:\.\d{0,2})?|\.\d{1,2})$/.test(totalQuota) || Number(totalQuota) > 99999999.99) {
this.$message.warning('校工会预算总额度必须在 0 至 99999999.99 元之间,且最多保留两位小数')
return
}
this.$confirm('您确定要提交此条记录吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
@@ -194,7 +198,7 @@ layout("/layouts/platform.html"){
}).then(() => {
this.$axios.post("/platform/outlay/outlayManage/schoolManage/doSubmit", {
id: row.id,
totalQuota: row.totalQuota2
totalQuota
}).then((resp) => {
if (resp.code === 0) {
row.edit = false
@@ -170,7 +170,7 @@ const unionReimburseInfo = {
<span>{{ viewData.participants }}</span>
</el-descriptions-item>
<el-descriptions-item label="报销事由" :span="3" v-if="viewData.reimburseProject === 'UNION_REIMBURSE_PROJECT_1'">
<el-descriptions-item label="报销事由" :span="3" v-if="viewData.reimburseProject">
<span>{{ viewData.paymentNotes }}</span>
</el-descriptions-item>