|
|
@@ -16,13 +16,45 @@
|
|
|
*/
|
|
|
package org.springblade.los.finance.genleg.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import io.seata.spring.annotation.GlobalTransactional;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.los.Util.IDeptUtils;
|
|
|
+import org.springblade.los.business.aea.entity.AeaBills;
|
|
|
+import org.springblade.los.business.aea.service.IAeaBillsService;
|
|
|
+import org.springblade.los.business.amends.entity.Amends;
|
|
|
+import org.springblade.los.business.amends.service.IAmendsService;
|
|
|
+import org.springblade.los.business.customsDeclaration.entity.CustomsDeclaration;
|
|
|
+import org.springblade.los.business.customsDeclaration.service.ICustomsDeclarationService;
|
|
|
+import org.springblade.los.business.sea.entity.Bills;
|
|
|
+import org.springblade.los.business.sea.service.IBillsService;
|
|
|
+import org.springblade.los.excel.ReviewFailedExcel;
|
|
|
+import org.springblade.los.excel.UnbookkeptExcel;
|
|
|
import org.springblade.los.finance.genleg.entity.FinPeriod;
|
|
|
-import org.springblade.los.finance.genleg.vo.FinPeriodVO;
|
|
|
import org.springblade.los.finance.genleg.mapper.FinPeriodMapper;
|
|
|
import org.springblade.los.finance.genleg.service.IFinPeriodService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springblade.los.finance.genleg.vo.FinPeriodVO;
|
|
|
+import org.springblade.los.finance.stl.entity.FinStlBills;
|
|
|
+import org.springblade.los.finance.stl.service.IFinStlBillsService;
|
|
|
+import org.springblade.los.finance.vouchers.entity.FinVouchers;
|
|
|
+import org.springblade.los.finance.vouchers.service.IFinVouchersService;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 业务-财务期间 服务实现类
|
|
|
@@ -31,11 +63,485 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
* @since 2024-02-29
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class FinPeriodServiceImpl extends ServiceImpl<FinPeriodMapper, FinPeriod> implements IFinPeriodService {
|
|
|
|
|
|
+
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ private final IDeptUtils deptUtils;
|
|
|
+
|
|
|
+ private final IBillsService billsService;
|
|
|
+
|
|
|
+ private final IAeaBillsService aeaBillsService;
|
|
|
+
|
|
|
+ private final IAmendsService amendsService;
|
|
|
+
|
|
|
+ private final ICustomsDeclarationService customsDeclarationService;
|
|
|
+
|
|
|
+ private final IFinStlBillsService finStlBillsService;
|
|
|
+
|
|
|
+ private final IFinVouchersService finVouchersService;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<FinPeriodVO> selectFinPeriodPage(IPage<FinPeriodVO> page, FinPeriodVO finPeriod) {
|
|
|
return page.setRecords(baseMapper.selectFinPeriodPage(page, finPeriod));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R init(FinPeriod finPeriod) {
|
|
|
+ String deptId = "";
|
|
|
+ String deptName = "";
|
|
|
+ String branchId = deptUtils.getDeptPid() + "";
|
|
|
+ //获取部门ids对应中文名
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ deptId = AuthUtil.getDeptId();
|
|
|
+ R<List<String>> res = sysClient.getDeptNames(AuthUtil.getDeptId());
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ deptName = String.join(",", res.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (baseMapper.selectCount(new LambdaQueryWrapper<FinPeriod>()
|
|
|
+ .eq(FinPeriod::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinPeriod::getIsDeleted, 0)
|
|
|
+ .eq(FinPeriod::getBranchId, branchId)) > 0) {
|
|
|
+ throw new RuntimeException("本年度已有账期,请勿重复生成");
|
|
|
+ }
|
|
|
+ if (finPeriod.getId() == null) {
|
|
|
+ if (ObjectUtils.isNotNull(finPeriod.getBeginDate())) {
|
|
|
+ LocalDate date = finPeriod.getBeginDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ finPeriod.setPeriodYear(date.getYear());
|
|
|
+ finPeriod.setPeriodMonth(date.lengthOfMonth());
|
|
|
+ } else {
|
|
|
+ LocalDate date = LocalDate.now();
|
|
|
+ finPeriod.setPeriodYear(date.getYear());
|
|
|
+ finPeriod.setPeriodMonth(date.lengthOfMonth());
|
|
|
+ // 获取当前月的第一天
|
|
|
+ LocalDate firstDayOfMonth = date.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ // 获取当前月的最后一天
|
|
|
+ LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ finPeriod.setBeginDate(Date.from(firstDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ finPeriod.setEndDate(Date.from(lastDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ }
|
|
|
+ finPeriod.setCreateTime(new Date());
|
|
|
+ finPeriod.setCreateUser(AuthUtil.getUserId());
|
|
|
+ finPeriod.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ finPeriod.setCreateDept(deptId);
|
|
|
+ finPeriod.setBranchId(branchId);
|
|
|
+ finPeriod.setCreateDeptName(deptName);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ finPeriod.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ finPeriod.setUpdateTime(new Date());
|
|
|
+ finPeriod.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(finPeriod);
|
|
|
+ return R.data(finPeriod);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R locking(FinPeriod finPeriod) {
|
|
|
+ if (finPeriod.getId() == null) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ FinPeriod detail = baseMapper.selectById(finPeriod.getId());
|
|
|
+ if (1 == detail.getLockingStatus()) {
|
|
|
+ throw new RuntimeException("该期间已锁定,请勿重复锁定!");
|
|
|
+ }
|
|
|
+ List<ReviewFailedExcel> reviewFailedExcelList = new ArrayList<>();
|
|
|
+ List<UnbookkeptExcel> unbookkeptExcelList = new ArrayList<>();
|
|
|
+ List<Bills> billsList = billsService.list(new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .eq(Bills::getBranchId, detail.getBranchId())
|
|
|
+ .apply("((business_type = 'SE' and etd >=" + detail.getBeginDate() + " and etd <= " + detail.getEndDate() + " ) " +
|
|
|
+ "or (business_type = 'SI' and eta >=" + detail.getBeginDate() + " and eta <= " + detail.getEndDate() + "))"));
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ List<Bills> bills = billsList.stream().filter(e -> e.getBillStatus().equals(3)).collect(Collectors.toList());
|
|
|
+ for (Bills item : bills) {
|
|
|
+ ReviewFailedExcel reviewFailedExcel = new ReviewFailedExcel();
|
|
|
+ if ("SE".equals(item.getBusinessType())) {
|
|
|
+ reviewFailedExcel.setBusinessType("海运出口");
|
|
|
+ } else {
|
|
|
+ reviewFailedExcel.setBusinessType("海运进口");
|
|
|
+ }
|
|
|
+ reviewFailedExcel.setBillNo(item.getBillNo());
|
|
|
+ reviewFailedExcel.setBusinessDate(item.getBillDate());
|
|
|
+ reviewFailedExcel.setMblno(item.getMblno());
|
|
|
+ reviewFailedExcel.setOperator(item.getOperatorName());
|
|
|
+ if ("SALES".equals(item.getSrcType())) {
|
|
|
+ reviewFailedExcel.setSalesperson(item.getSrcCnName());
|
|
|
+ }
|
|
|
+ reviewFailedExcelList.add(reviewFailedExcel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<AeaBills> aeaBillsList = aeaBillsService.list(new LambdaQueryWrapper<AeaBills>()
|
|
|
+ .eq(AeaBills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(AeaBills::getIsDeleted, 0)
|
|
|
+ .eq(AeaBills::getBranchId, detail.getBranchId())
|
|
|
+ .apply("((business_type = 'AE' and etd >=" + detail.getBeginDate() + " and etd <= " + detail.getEndDate() + " ) " +
|
|
|
+ "or (business_type = 'AI' and eta >=" + detail.getBeginDate() + " and eta <= " + detail.getEndDate() + "))"));
|
|
|
+ if (!aeaBillsList.isEmpty()) {
|
|
|
+ List<AeaBills> aeaBills = aeaBillsList.stream().filter(e -> e.getBillStatus().equals(3)).collect(Collectors.toList());
|
|
|
+ for (AeaBills item : aeaBills) {
|
|
|
+ ReviewFailedExcel reviewFailedExcel = new ReviewFailedExcel();
|
|
|
+ if ("AE".equals(item.getBusinessType())) {
|
|
|
+ reviewFailedExcel.setBusinessType("空运出口");
|
|
|
+ } else {
|
|
|
+ reviewFailedExcel.setBusinessType("空运进口");
|
|
|
+ }
|
|
|
+ reviewFailedExcel.setBillNo(item.getBillNo());
|
|
|
+ reviewFailedExcel.setBusinessDate(item.getBillDate());
|
|
|
+ reviewFailedExcel.setMblno(item.getMblno());
|
|
|
+ reviewFailedExcel.setOperator(item.getOperatorName());
|
|
|
+ if ("SALES".equals(item.getSrcType())) {
|
|
|
+ reviewFailedExcel.setSalesperson(item.getSrcCnName());
|
|
|
+ }
|
|
|
+ reviewFailedExcelList.add(reviewFailedExcel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Amends> amendsList = amendsService.list(new LambdaQueryWrapper<Amends>()
|
|
|
+ .eq(Amends::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Amends::getIsDeleted, 0)
|
|
|
+ .eq(Amends::getBranchId, detail.getBranchId())
|
|
|
+ .apply("((business_type = 'SEA' and etd >=" + detail.getBeginDate() + " and etd <= " + detail.getEndDate() + " ) " +
|
|
|
+ "or (business_type = 'SIA' and eta >=" + detail.getBeginDate() + " and eta <= " + detail.getEndDate() + "))" +
|
|
|
+ "or (business_type = 'AEA' and etd >=" + detail.getBeginDate() + " and etd <= " + detail.getEndDate() + "))" +
|
|
|
+ "or (business_type = 'AIA' and eta >=" + detail.getBeginDate() + " and eta <= " + detail.getEndDate() + "))"
|
|
|
+ ));
|
|
|
+ if (!amendsList.isEmpty()) {
|
|
|
+ List<Amends> bills = amendsList.stream().filter(e -> e.getBillStatus().equals(3)).collect(Collectors.toList());
|
|
|
+ List<Bills> billsList1 = new ArrayList<>();
|
|
|
+ List<AeaBills> aeaBillsList1 = new ArrayList<>();
|
|
|
+ if (!bills.isEmpty()) {
|
|
|
+ List<Long> billsId = bills.stream().map(Amends::getOrigId).collect(Collectors.toList());
|
|
|
+ if (!billsId.isEmpty()) {
|
|
|
+ billsList1 = billsService.list(new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .eq(Bills::getBranchId, detail.getBranchId())
|
|
|
+ .in(Bills::getId, billsId)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ List<Long> aeaBillsId = bills.stream().map(Amends::getOrigId).collect(Collectors.toList());
|
|
|
+ if (!aeaBillsId.isEmpty()) {
|
|
|
+ aeaBillsList1 = aeaBillsService.list(new LambdaQueryWrapper<AeaBills>()
|
|
|
+ .eq(AeaBills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(AeaBills::getIsDeleted, 0)
|
|
|
+ .eq(AeaBills::getBranchId, detail.getBranchId())
|
|
|
+ .in(AeaBills::getId, aeaBillsId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Amends item : bills) {
|
|
|
+ ReviewFailedExcel reviewFailedExcel = new ReviewFailedExcel();
|
|
|
+ if ("AEA".equals(item.getBusinessType())) {
|
|
|
+ if (!aeaBillsList1.isEmpty()) {
|
|
|
+ AeaBills aeaBills = aeaBillsList1.stream().filter(e -> e.getId().equals(item.getOrigId())).findFirst().orElse(null);
|
|
|
+ if (aeaBills != null && "SALES".equals(aeaBills.getSrcType())) {
|
|
|
+ reviewFailedExcel.setSalesperson(aeaBills.getSrcCnName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reviewFailedExcel.setBusinessType("空运出口Amends");
|
|
|
+ } else if ("AIA".equals(item.getBusinessType())) {
|
|
|
+ if (!aeaBillsList1.isEmpty()) {
|
|
|
+ AeaBills aeaBills = aeaBillsList1.stream().filter(e -> e.getId().equals(item.getOrigId())).findFirst().orElse(null);
|
|
|
+ if (aeaBills != null && "SALES".equals(aeaBills.getSrcType())) {
|
|
|
+ reviewFailedExcel.setSalesperson(aeaBills.getSrcCnName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reviewFailedExcel.setBusinessType("空运进口Amends");
|
|
|
+ } else if ("SIA".equals(item.getBusinessType())) {
|
|
|
+ if (!billsList1.isEmpty()) {
|
|
|
+ Bills aeaBills = billsList1.stream().filter(e -> e.getId().equals(item.getOrigId())).findFirst().orElse(null);
|
|
|
+ if (aeaBills != null && "SALES".equals(aeaBills.getSrcType())) {
|
|
|
+ reviewFailedExcel.setSalesperson(aeaBills.getSrcCnName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reviewFailedExcel.setBusinessType("海运进口Amends");
|
|
|
+ } else if ("SEA".equals(item.getBusinessType())) {
|
|
|
+ if (!billsList1.isEmpty()) {
|
|
|
+ Bills aeaBills = billsList1.stream().filter(e -> e.getId().equals(item.getOrigId())).findFirst().orElse(null);
|
|
|
+ if (aeaBills != null && "SALES".equals(aeaBills.getSrcType())) {
|
|
|
+ reviewFailedExcel.setSalesperson(aeaBills.getSrcCnName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reviewFailedExcel.setBusinessType("海运出口Amends");
|
|
|
+ }
|
|
|
+ reviewFailedExcel.setBillNo(item.getBillNo());
|
|
|
+ reviewFailedExcel.setBusinessDate(item.getBillDate());
|
|
|
+ reviewFailedExcel.setMblno(item.getMblno());
|
|
|
+ reviewFailedExcel.setOperator(item.getOperatorName());
|
|
|
+ reviewFailedExcelList.add(reviewFailedExcel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CustomsDeclaration> customsDeclarationList = customsDeclarationService.list(new LambdaQueryWrapper<CustomsDeclaration>()
|
|
|
+ .eq(CustomsDeclaration::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(CustomsDeclaration::getIsDeleted, 0)
|
|
|
+ .eq(CustomsDeclaration::getBranchId, detail.getBranchId())
|
|
|
+ .gt(CustomsDeclaration::getDeclareDate, detail.getBeginDate())
|
|
|
+ .lt(CustomsDeclaration::getDeclareDate, detail.getEndDate())
|
|
|
+ );
|
|
|
+ if (!customsDeclarationList.isEmpty()) {
|
|
|
+ List<CustomsDeclaration> bills = customsDeclarationList.stream().filter(e -> e.getBillStatus().equals(3)).collect(Collectors.toList());
|
|
|
+ for (CustomsDeclaration item : bills) {
|
|
|
+ ReviewFailedExcel reviewFailedExcel = new ReviewFailedExcel();
|
|
|
+ if ("BGSE".equals(item.getBusinessType())) {
|
|
|
+ reviewFailedExcel.setBusinessType("海运报关");
|
|
|
+ } else if ("BGSI".equals(item.getBusinessType())) {
|
|
|
+ reviewFailedExcel.setBusinessType("海运报关");
|
|
|
+ } else if ("BGAE".equals(item.getBusinessType())) {
|
|
|
+ reviewFailedExcel.setBusinessType("空运报关");
|
|
|
+ } else if ("BGAI".equals(item.getBusinessType())) {
|
|
|
+ reviewFailedExcel.setBusinessType("空运报关");
|
|
|
+ }
|
|
|
+ reviewFailedExcel.setBillNo(item.getBillNo());
|
|
|
+ reviewFailedExcel.setBusinessDate(item.getBillDate());
|
|
|
+ reviewFailedExcel.setMblno(item.getMblno());
|
|
|
+ reviewFailedExcel.setOperator(item.getCreateUserName());
|
|
|
+ if ("SALES".equals(item.getSrcType())) {
|
|
|
+ reviewFailedExcel.setSalesperson(item.getSrcCnName());
|
|
|
+ }
|
|
|
+ reviewFailedExcelList.add(reviewFailedExcel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<FinStlBills> finStlBillsList = finStlBillsService.list(new LambdaQueryWrapper<FinStlBills>()
|
|
|
+ .eq(FinStlBills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinStlBills::getIsDeleted, 0)
|
|
|
+ .eq(FinStlBills::getBusinessType, "STL")
|
|
|
+ .eq(FinStlBills::getBranchId, detail.getBranchId())
|
|
|
+ .gt(FinStlBills::getBillDate, detail.getBeginDate())
|
|
|
+ .lt(FinStlBills::getBillDate, detail.getEndDate())
|
|
|
+ );
|
|
|
+ if (!finStlBillsList.isEmpty()) {
|
|
|
+ List<FinStlBills> bills = finStlBillsList.stream().filter(e -> e.getBillStatus().equals("3")).collect(Collectors.toList());
|
|
|
+ if (!bills.isEmpty()) {
|
|
|
+ List<Long> ids = bills.stream().map(FinStlBills::getId).collect(Collectors.toList());
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ List<FinVouchers> finVouchersList = finVouchersService.list(new LambdaQueryWrapper<FinVouchers>()
|
|
|
+ .eq(FinVouchers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinVouchers::getIsDeleted, 0)
|
|
|
+ .eq(FinVouchers::getBranchId, detail.getBranchId())
|
|
|
+ .in(FinVouchers::getSrcId, ids)
|
|
|
+ .gt(FinVouchers::getVoucherDate, detail.getBeginDate())
|
|
|
+ .lt(FinVouchers::getVoucherDate, detail.getEndDate()));
|
|
|
+ for (FinStlBills item : bills) {
|
|
|
+ FinVouchers finVouchers = finVouchersList.stream().filter(e -> e.getSrcId().equals(item.getId())).findFirst().orElse(null);
|
|
|
+ if (finVouchers == null) {
|
|
|
+ ReviewFailedExcel reviewFailedExcel = new ReviewFailedExcel();
|
|
|
+ reviewFailedExcel.setBusinessType("结算中心");
|
|
|
+ reviewFailedExcel.setBillNo(item.getBillNo());
|
|
|
+ reviewFailedExcel.setBusinessDate(item.getBillDate());
|
|
|
+ reviewFailedExcel.setMblno(item.getMblno());
|
|
|
+ reviewFailedExcel.setOperator(item.getCreateUserName());
|
|
|
+ reviewFailedExcel.setSalesperson(item.getSalesName());
|
|
|
+ reviewFailedExcelList.add(reviewFailedExcel);
|
|
|
+ } else {
|
|
|
+ UnbookkeptExcel unbookkeptExcel = new UnbookkeptExcel();
|
|
|
+ unbookkeptExcel.setYear(finVouchers.getAccountYear() + "");
|
|
|
+ unbookkeptExcel.setMonth(finVouchers.getAccountMonth() + "");
|
|
|
+ unbookkeptExcel.setVoucherNumber(finVouchers.getVoucherNo());
|
|
|
+ unbookkeptExcel.setVoucherDate(finVouchers.getVoucherDate());
|
|
|
+ unbookkeptExcel.setOperator(finVouchers.getCreateUserName());
|
|
|
+ unbookkeptExcelList.add(unbookkeptExcel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!reviewFailedExcelList.isEmpty()) {
|
|
|
+ return R.data(reviewFailedExcelList, "审核未通过");
|
|
|
+ }
|
|
|
+ if (!unbookkeptExcelList.isEmpty()) {
|
|
|
+ return R.data(reviewFailedExcelList, "凭证未记账");
|
|
|
+ }
|
|
|
+ detail.setUpdateTime(new Date());
|
|
|
+ detail.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ detail.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ detail.setLockingStatus(1);
|
|
|
+ baseMapper.updateById(finPeriod);
|
|
|
+ return R.data(finPeriod);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R currentPeriod(Query query, FinPeriod finPeriod) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R close(FinPeriod finPeriod) {
|
|
|
+ if (finPeriod.getId() == null) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ FinPeriod detail = baseMapper.selectById(finPeriod.getId());
|
|
|
+ if (0 == detail.getLockingStatus()) {
|
|
|
+ throw new RuntimeException("该期间未锁定,请先锁定在结转!");
|
|
|
+ }
|
|
|
+ if (1 == detail.getIsClosed()) {
|
|
|
+ throw new RuntimeException("该期间已结转,请勿重复结转!");
|
|
|
+ }
|
|
|
+ detail.setUpdateTime(new Date());
|
|
|
+ detail.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ detail.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ detail.setIsClosed(1);
|
|
|
+ detail.setCloseDate(new Date());
|
|
|
+ baseMapper.updateById(finPeriod);
|
|
|
+
|
|
|
+ List<FinVouchers> finVouchersList = finVouchersService.list(new LambdaQueryWrapper<FinVouchers>()
|
|
|
+ .eq(FinVouchers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinVouchers::getIsDeleted, 0)
|
|
|
+ .eq(FinVouchers::getBranchId, detail.getBranchId())
|
|
|
+ .eq(FinVouchers::getVoucherSource, "SYSTEM")
|
|
|
+ .eq(FinVouchers::getAccountYear, detail.getPeriodYear())
|
|
|
+ .eq(FinVouchers::getAccountMonth, detail.getPeriodMonth())
|
|
|
+ .gt(FinVouchers::getVoucherDate, detail.getBeginDate())
|
|
|
+ .lt(FinVouchers::getVoucherDate, detail.getEndDate()));
|
|
|
+ if (finVouchersList.size() != 2) {
|
|
|
+ throw new RuntimeException("请先生成本期汇兑损益,期间损益凭证在进行结转");
|
|
|
+ }
|
|
|
+ FinPeriod finPeriodNew = new FinPeriod();
|
|
|
+ if (ObjectUtils.isNotNull(finPeriod.getBeginDate())) {
|
|
|
+ finPeriodNew.setBeginDate(finPeriod.getBeginDate());
|
|
|
+ finPeriodNew.setEndDate(finPeriod.getEndDate());
|
|
|
+ } else {
|
|
|
+ LocalDate date = detail.getBeginDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ // 获取下个月的第一天
|
|
|
+ LocalDate firstDayOfNextMonth = date.with(TemporalAdjusters.firstDayOfNextMonth());
|
|
|
+ // 获取下个月的最后一天
|
|
|
+ LocalDate lastDayOfNextMonth;
|
|
|
+ if (firstDayOfNextMonth.getMonthValue() == 12) {
|
|
|
+ lastDayOfNextMonth = firstDayOfNextMonth.withDayOfMonth(31);
|
|
|
+ } else {
|
|
|
+ lastDayOfNextMonth = firstDayOfNextMonth.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ }
|
|
|
+ finPeriodNew.setBeginDate(Date.from(firstDayOfNextMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ finPeriodNew.setEndDate(Date.from(lastDayOfNextMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ }
|
|
|
+ this.submit(finPeriodNew);
|
|
|
+ return R.data(finPeriod);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R unclose(FinPeriod finPeriod) {
|
|
|
+ if (finPeriod.getId() == null) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ FinPeriod detail = baseMapper.selectById(finPeriod.getId());
|
|
|
+ if (0 == detail.getIsClosed()) {
|
|
|
+ throw new RuntimeException("该期间未结转,操作失败!");
|
|
|
+ }
|
|
|
+ detail.setUpdateTime(new Date());
|
|
|
+ detail.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ detail.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ detail.setIsClosed(0);
|
|
|
+ detail.setCloseDate(null);
|
|
|
+ baseMapper.updateById(finPeriod);
|
|
|
+ LocalDate date = detail.getBeginDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ // 获取下个月的第一天
|
|
|
+ LocalDate firstDayOfNextMonth = date.with(TemporalAdjusters.firstDayOfNextMonth());
|
|
|
+ // 获取下个月的最后一天
|
|
|
+ LocalDate lastDayOfNextMonth;
|
|
|
+ if (firstDayOfNextMonth.getMonthValue() == 12) {
|
|
|
+ lastDayOfNextMonth = firstDayOfNextMonth.withDayOfMonth(31);
|
|
|
+ } else {
|
|
|
+ lastDayOfNextMonth = firstDayOfNextMonth.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ }
|
|
|
+ FinPeriod finPeriodNew = baseMapper.selectOne(new LambdaQueryWrapper<FinPeriod>()
|
|
|
+ .eq(FinPeriod::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinPeriod::getIsDeleted, 0)
|
|
|
+ .eq(FinPeriod::getBranchId, detail.getBranchId())
|
|
|
+ .eq(FinPeriod::getIsClosed, 1)
|
|
|
+ .eq(FinPeriod::getBeginDate, firstDayOfNextMonth)
|
|
|
+ .eq(FinPeriod::getEndDate, lastDayOfNextMonth));
|
|
|
+ if (finPeriodNew != null) {
|
|
|
+ baseMapper.deleteById(finPeriodNew.getId());
|
|
|
+ } else {
|
|
|
+ List<FinPeriod> finPeriodList = baseMapper.selectList(new LambdaQueryWrapper<FinPeriod>()
|
|
|
+ .eq(FinPeriod::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinPeriod::getIsDeleted, 0)
|
|
|
+ .eq(FinPeriod::getBranchId, detail.getBranchId()));
|
|
|
+ if (finPeriodList.size() != 1) {
|
|
|
+ throw new RuntimeException("未查到下期数据,操作失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.data(finPeriod);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R submit(FinPeriod finPeriod) {
|
|
|
+ String deptId = "";
|
|
|
+ String deptName = "";
|
|
|
+ String branchId = deptUtils.getDeptPid() + "";
|
|
|
+ //获取部门ids对应中文名
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ deptId = AuthUtil.getDeptId();
|
|
|
+ R<List<String>> res = sysClient.getDeptNames(AuthUtil.getDeptId());
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ deptName = String.join(",", res.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (baseMapper.selectCount(new LambdaQueryWrapper<FinPeriod>()
|
|
|
+ .eq(FinPeriod::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinPeriod::getIsDeleted, 0)
|
|
|
+ .eq(FinPeriod::getBranchId, branchId)) > 0) {
|
|
|
+ throw new RuntimeException("本年度已有账期,请勿重复生成");
|
|
|
+ }
|
|
|
+ if (finPeriod.getId() == null) {
|
|
|
+ if (ObjectUtils.isNotNull(finPeriod.getBeginDate())) {
|
|
|
+ LocalDate date = finPeriod.getBeginDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ finPeriod.setPeriodYear(date.getYear());
|
|
|
+ finPeriod.setPeriodMonth(date.lengthOfMonth());
|
|
|
+ } else {
|
|
|
+ LocalDate date = LocalDate.now();
|
|
|
+ finPeriod.setPeriodYear(date.getYear());
|
|
|
+ finPeriod.setPeriodMonth(date.lengthOfMonth());
|
|
|
+ // 获取当前月的第一天
|
|
|
+ LocalDate firstDayOfMonth = date.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ // 获取当前月的最后一天
|
|
|
+ LocalDate lastDayOfMonth = date.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ finPeriod.setBeginDate(Date.from(firstDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ finPeriod.setEndDate(Date.from(lastDayOfMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ }
|
|
|
+ finPeriod.setCreateTime(new Date());
|
|
|
+ finPeriod.setCreateUser(AuthUtil.getUserId());
|
|
|
+ finPeriod.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ finPeriod.setCreateDept(deptId);
|
|
|
+ finPeriod.setBranchId(branchId);
|
|
|
+ finPeriod.setCreateDeptName(deptName);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ finPeriod.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ finPeriod.setUpdateTime(new Date());
|
|
|
+ finPeriod.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(finPeriod);
|
|
|
+ return R.data(finPeriod);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R revokeLocking(FinPeriod finPeriod) {
|
|
|
+ if (finPeriod.getId() == null) {
|
|
|
+ throw new RuntimeException("缺少必要参数");
|
|
|
+ }
|
|
|
+ FinPeriod detail = baseMapper.selectById(finPeriod.getId());
|
|
|
+ if (0 == detail.getLockingStatus()) {
|
|
|
+ throw new RuntimeException("该期间未锁定,操作失败!");
|
|
|
+ }
|
|
|
+ detail.setUpdateTime(new Date());
|
|
|
+ detail.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ detail.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ detail.setLockingStatus(0);
|
|
|
+ baseMapper.updateById(finPeriod);
|
|
|
+ return R.data(finPeriod);
|
|
|
+ }
|
|
|
+
|
|
|
}
|