diff --git a/src/main/java/com/budwk/app/zhgh/dayofficework/outlay/outlayManage/union/controller/OutlayManageUnionAllocateController.java b/src/main/java/com/budwk/app/zhgh/dayofficework/outlay/outlayManage/union/controller/OutlayManageUnionAllocateController.java index 520f6020..9edd6f48 100644 --- a/src/main/java/com/budwk/app/zhgh/dayofficework/outlay/outlayManage/union/controller/OutlayManageUnionAllocateController.java +++ b/src/main/java/com/budwk/app/zhgh/dayofficework/outlay/outlayManage/union/controller/OutlayManageUnionAllocateController.java @@ -25,6 +25,7 @@ import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.lang.Lang; import org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Ok; +import org.nutz.mvc.annotation.Param; import java.math.BigDecimal; import java.util.ArrayList; @@ -142,6 +143,69 @@ public class OutlayManageUnionAllocateController { return Result.success(); } + @At + @ApiOperation("一键批量分配所有工会额度") + @Aop(TransAop.READ_COMMITTED) + @SLog(tag = "分工会预算-季度预算分配", msg = "一键批量分配所有工会额度") + @SaCheckPermission("outlay.outlayManage.union.allocate") + public Result doBatchAllocate(@Param("allocateMoney") BigDecimal allocateMoney, + @Param("quarterly") Integer quarterly, + @Param("year") Integer year) { + List 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("当前季度没有分配记录!"); + } + + 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(); + } + @At @ApiOperation("重置预算季度记录") diff --git a/src/main/java/com/budwk/app/zhgh/dayofficework/outlay/outlayManage/union/controller/OutlayManageUnionUseDetailController.java b/src/main/java/com/budwk/app/zhgh/dayofficework/outlay/outlayManage/union/controller/OutlayManageUnionUseDetailController.java index 13549253..f5f0d912 100644 --- a/src/main/java/com/budwk/app/zhgh/dayofficework/outlay/outlayManage/union/controller/OutlayManageUnionUseDetailController.java +++ b/src/main/java/com/budwk/app/zhgh/dayofficework/outlay/outlayManage/union/controller/OutlayManageUnionUseDetailController.java @@ -18,6 +18,7 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.nutz.aop.interceptor.ioc.TransAop; import org.nutz.dao.Cnd; +import org.nutz.dao.Condition; import org.nutz.dao.Sqls; import org.nutz.dao.sql.Sql; import org.nutz.ioc.aop.Aop; @@ -118,9 +119,24 @@ public class OutlayManageUnionUseDetailController { @ApiOperation("查询分工会今年每个季度的分配情况") @SaCheckPermission("outlay.outlayManage.union.useDetail") public Result queryQuarterlyList(Integer year, String unionId){ - List allocateUnionList = outlayUseDetailService.dao().query(OutLayAllocateUnion.class, - Cnd.where(OutLayAllocateUnion::getYear, "=", year).and(OutLayAllocateUnion::getUnionId, "=", unionId) - .asc(OutLayAllocateUnion::getQuarterly)); + Sql sql = Sqls.create(""" + SELECT t1.* FROM outlay_allocate_union t1 + INNER JOIN ( + SELECT quarterly, MAX(id) as max_id + FROM outlay_allocate_union + WHERE year = @year AND unionId = @unionId AND delFlag = 0 + GROUP BY quarterly + ) t2 ON t1.id = t2.max_id + ORDER BY t1.quarterly ASC + """); + sql.setParam("year", year); + sql.setParam("unionId", unionId); + sql.setCallback(Sqls.callback.entities()); + sql.setEntity(outlayUseDetailService.dao().getEntity(OutLayAllocateUnion.class)); + + outlayUseDetailService.dao().execute(sql); + List allocateUnionList = sql.getList(OutLayAllocateUnion.class); + return Result.success(allocateUnionList); } diff --git a/src/main/resources/views/platform/zhgh/dayofficework/outlay/outlayManage/union/allocate/index.html b/src/main/resources/views/platform/zhgh/dayofficework/outlay/outlayManage/union/allocate/index.html index cf4bea1f..370df3b5 100644 --- a/src/main/resources/views/platform/zhgh/dayofficework/outlay/outlayManage/union/allocate/index.html +++ b/src/main/resources/views/platform/zhgh/dayofficework/outlay/outlayManage/union/allocate/index.html @@ -40,6 +40,8 @@ layout("/layouts/platform.html"){ + 一键分配 + 季度记录生成 @@ -95,6 +97,20 @@ layout("/layouts/platform.html"){ + + + + + + + + + + 取 消 + 确 定 + + @@ -119,6 +135,10 @@ layout("/layouts/platform.html"){ {prop: 'allocateMoney', label: '分配额度'}, ], quarterlyList: [], + batchAllocateDialogVisible: false, + batchAllocateForm: { + allocateMoney: 0 + } } }, methods: { @@ -176,6 +196,39 @@ layout("/layouts/platform.html"){ }) }) }, + showBatchAllocateDialog() { + if (this.tableData.length === 0) { + this.$message.warning('当前没有可分配的工会记录,请先生成季度记录') + return + } + this.batchAllocateForm = { + allocateMoney: 0 + } + this.batchAllocateDialogVisible = true + }, + doBatchAllocate() { + if (!this.batchAllocateForm.allocateMoney || this.batchAllocateForm.allocateMoney <= 0) { + this.$message.warning('请输入有效的分配额度') + return + } + + const quarter = this.$moment().quarter() + + this.formLoading = true + this.$axios.post("/platform/outlay/outlayManage/unionAllocate/doBatchAllocate", { + allocateMoney: this.batchAllocateForm.allocateMoney, + quarterly: quarter, + year: this.pageForm.year + }).then((resp) => { + if (resp.code === 0) { + this.$message.success(resp.msg) + this.batchAllocateDialogVisible = false + this.doSearch() + } + }).finally(() => { + this.formLoading = false + }) + }, }, created() { this.$businessTool.listUnion().then((data) => {