|
|
@@ -16,16 +16,24 @@
|
|
|
*/
|
|
|
package org.springblade.los.finance.genleg.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
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.basic.acc.entity.Accounts;
|
|
|
+import org.springblade.los.basic.acc.service.IAccountsService;
|
|
|
+import org.springblade.los.basic.business.entity.BusinessType;
|
|
|
+import org.springblade.los.basic.business.service.IBusinessTypeService;
|
|
|
+import org.springblade.los.basic.cur.service.IBCurrencyService;
|
|
|
+import org.springblade.los.billno.entity.BusinessBillNo;
|
|
|
+import org.springblade.los.billno.service.IBusinessBillNoService;
|
|
|
import org.springblade.los.business.aea.entity.AeaBills;
|
|
|
import org.springblade.los.business.aea.service.IAeaBillsService;
|
|
|
import org.springblade.los.business.amends.entity.Amends;
|
|
|
@@ -36,18 +44,27 @@ 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.dto.PeriodVouchersAccItems;
|
|
|
+import org.springblade.los.finance.genleg.dto.PeriodVouchersTemplate;
|
|
|
+import org.springblade.los.finance.genleg.entity.FinGenleg;
|
|
|
+import org.springblade.los.finance.genleg.entity.FinGenlegCalc;
|
|
|
import org.springblade.los.finance.genleg.entity.FinPeriod;
|
|
|
import org.springblade.los.finance.genleg.mapper.FinPeriodMapper;
|
|
|
+import org.springblade.los.finance.genleg.service.IFinGenlegCalcService;
|
|
|
+import org.springblade.los.finance.genleg.service.IFinGenlegService;
|
|
|
import org.springblade.los.finance.genleg.service.IFinPeriodService;
|
|
|
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.entity.FinVouchersItems;
|
|
|
import org.springblade.los.finance.vouchers.service.IFinVouchersService;
|
|
|
import org.springblade.system.feign.ISysClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
@@ -83,6 +100,19 @@ public class FinPeriodServiceImpl extends ServiceImpl<FinPeriodMapper, FinPeriod
|
|
|
|
|
|
private final IFinVouchersService finVouchersService;
|
|
|
|
|
|
+ private final IFinGenlegCalcService finGenlegCalcService;
|
|
|
+
|
|
|
+ private final IFinGenlegService finGenlegService;
|
|
|
+
|
|
|
+ private final IBusinessTypeService bBusinessTypeService;
|
|
|
+
|
|
|
+ private final IBusinessBillNoService businessBillNoService;
|
|
|
+
|
|
|
+ private final IAccountsService accountsService;
|
|
|
+
|
|
|
+ private final IBCurrencyService bCurrencyService;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<FinPeriodVO> selectFinPeriodPage(IPage<FinPeriodVO> page, FinPeriodVO finPeriod) {
|
|
|
return page.setRecords(baseMapper.selectFinPeriodPage(page, finPeriod));
|
|
|
@@ -92,53 +122,73 @@ public class FinPeriodServiceImpl extends ServiceImpl<FinPeriodMapper, FinPeriod
|
|
|
@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>()
|
|
|
+ List<FinPeriod> finPeriodList = baseMapper.selectList(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()));
|
|
|
+ .eq(FinPeriod::getBranchId, deptUtils.getDeptPid())
|
|
|
+ .gt(FinPeriod::getBeginDate, finPeriod.getBeginDate())
|
|
|
+ );
|
|
|
+ if (!finPeriodList.isEmpty()) {
|
|
|
+ FinPeriod detail = baseMapper.selectOne(new LambdaQueryWrapper<FinPeriod>()
|
|
|
+ .eq(FinPeriod::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinPeriod::getIsDeleted, 0)
|
|
|
+ .eq(FinPeriod::getBranchId, deptUtils.getDeptPid())
|
|
|
+ .eq(FinPeriod::getBeginDate, finPeriod.getBeginDate()));
|
|
|
+ if (detail != null) {
|
|
|
+ List<Long> ids = finPeriodList.stream().map(FinPeriod::getId).filter(id -> !id.equals(detail.getId())).distinct().collect(Collectors.toList());
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ baseMapper.deleteBatchIds(ids);
|
|
|
+ }
|
|
|
+ detail.setIsClosed(0);
|
|
|
+ detail.setCloseDate(null);
|
|
|
+ detail.setLockingStatus(0);
|
|
|
+ detail.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ detail.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ detail.setUpdateTime(new Date());
|
|
|
+ baseMapper.updateById(detail);
|
|
|
}
|
|
|
- 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);
|
|
|
+ List<FinVouchers> finVouchersList = finVouchersService.list(new LambdaQueryWrapper<FinVouchers>()
|
|
|
+ .eq(FinVouchers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinVouchers::getIsDeleted, 0)
|
|
|
+ .eq(FinVouchers::getBranchId, deptUtils.getDeptPid())
|
|
|
+ .gt(FinVouchers::getVoucherDate, finPeriod.getBeginDate()));
|
|
|
+ if (!finVouchersList.isEmpty()) {
|
|
|
+ for (FinVouchers item : finVouchersList) {
|
|
|
+ item.setVoucherStatus(0);
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ }
|
|
|
+ finVouchersService.updateBatchById(finVouchersList);
|
|
|
+ }
|
|
|
+ LocalDate date = finPeriod.getBeginDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ Integer periodYear = date.getYear();
|
|
|
+ Integer periodMonth = date.lengthOfMonth();
|
|
|
+ List<FinGenlegCalc> finGenlegCalcList = finGenlegCalcService.list(new LambdaQueryWrapper<FinGenlegCalc>()
|
|
|
+ .eq(FinGenlegCalc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinGenlegCalc::getBranchId, deptUtils.getDeptPid())
|
|
|
+ .gt(FinGenlegCalc::getAccyear, periodYear)
|
|
|
+ .ge(FinGenlegCalc::getAccmonth, periodMonth)
|
|
|
+ );
|
|
|
+ if (!finGenlegCalcList.isEmpty()) {
|
|
|
+ List<Long> ids = finGenlegCalcList.stream().map(FinGenlegCalc::getId).distinct().collect(Collectors.toList());
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ finGenlegCalcService.removeByIds(ids);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<FinGenleg> finGenlegList = finGenlegService.list(new LambdaQueryWrapper<FinGenleg>()
|
|
|
+ .eq(FinGenleg::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinGenleg::getBranchId, deptUtils.getDeptPid())
|
|
|
+ .gt(FinGenleg::getAccyear, periodYear)
|
|
|
+ .ge(FinGenleg::getAccmonth, periodMonth)
|
|
|
+ );
|
|
|
+ if (!finGenlegCalcList.isEmpty()) {
|
|
|
+ List<Long> ids = finGenlegList.stream().map(FinGenleg::getId).distinct().collect(Collectors.toList());
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ finGenlegService.removeByIds(ids);
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- finPeriod.setUpdateUser(AuthUtil.getUserId());
|
|
|
- finPeriod.setUpdateTime(new Date());
|
|
|
- finPeriod.setUpdateUserName(AuthUtil.getUserName());
|
|
|
}
|
|
|
- this.saveOrUpdate(finPeriod);
|
|
|
return R.data(finPeriod);
|
|
|
}
|
|
|
|
|
|
@@ -366,8 +416,20 @@ public class FinPeriodServiceImpl extends ServiceImpl<FinPeriodMapper, FinPeriod
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R currentPeriod(Query query, FinPeriod finPeriod) {
|
|
|
- return null;
|
|
|
+ public R currentPeriod(FinPeriod finPeriod) {
|
|
|
+ FinPeriod detail = baseMapper.selectOne(new LambdaQueryWrapper<FinPeriod>()
|
|
|
+ .eq(FinPeriod::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinPeriod::getIsDeleted, 0)
|
|
|
+ .eq(FinPeriod::getIsClosed, 0)
|
|
|
+ );
|
|
|
+ List<PeriodVouchersTemplate> list = new ArrayList<>();
|
|
|
+ if (detail != null) {
|
|
|
+ PeriodVouchersTemplate exchange = JSONObject.parseObject(detail.getExchange(), PeriodVouchersTemplate.class);
|
|
|
+ list.add(exchange);
|
|
|
+ PeriodVouchersTemplate period = JSONObject.parseObject(detail.getPeriod(), PeriodVouchersTemplate.class);
|
|
|
+ list.add(period);
|
|
|
+ }
|
|
|
+ return R.data(list);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -389,6 +451,14 @@ public class FinPeriodServiceImpl extends ServiceImpl<FinPeriodMapper, FinPeriod
|
|
|
detail.setUpdateUser(AuthUtil.getUserId());
|
|
|
detail.setIsClosed(1);
|
|
|
detail.setCloseDate(new Date());
|
|
|
+ if (ObjectUtils.isNotNull(detail.getPeriodVouchersTemplate())) {
|
|
|
+ detail.getPeriodVouchersTemplate().setStatus(detail.getIsClosed());
|
|
|
+ if ("FM-CURRENCY-PL-TRANSFER".equals(detail.getPeriodVouchersTemplate().getBsType())) {
|
|
|
+ detail.setExchange(JSON.toJSONString(detail.getPeriodVouchersTemplate()));
|
|
|
+ } else {
|
|
|
+ detail.setPeriod(JSON.toJSONString(detail.getPeriodVouchersTemplate()));
|
|
|
+ }
|
|
|
+ }
|
|
|
baseMapper.updateById(finPeriod);
|
|
|
|
|
|
List<FinVouchers> finVouchersList = finVouchersService.list(new LambdaQueryWrapper<FinVouchers>()
|
|
|
@@ -421,6 +491,14 @@ public class FinPeriodServiceImpl extends ServiceImpl<FinPeriodMapper, FinPeriod
|
|
|
finPeriodNew.setBeginDate(Date.from(firstDayOfNextMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
finPeriodNew.setEndDate(Date.from(lastDayOfNextMonth.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
}
|
|
|
+ if (ObjectUtils.isNotNull(detail.getPeriodVouchersTemplate())) {
|
|
|
+ finPeriodNew.setPeriodVouchersTemplate(detail.getPeriodVouchersTemplate());
|
|
|
+ if ("FM-CURRENCY-PL-TRANSFER".equals(detail.getPeriodVouchersTemplate().getBsType())) {
|
|
|
+ finPeriodNew.setExchange(JSON.toJSONString(finPeriodNew.getPeriodVouchersTemplate()));
|
|
|
+ } else {
|
|
|
+ finPeriodNew.setPeriod(JSON.toJSONString(finPeriodNew.getPeriodVouchersTemplate()));
|
|
|
+ }
|
|
|
+ }
|
|
|
this.submit(finPeriodNew);
|
|
|
return R.data(finPeriod);
|
|
|
}
|
|
|
@@ -524,6 +602,17 @@ public class FinPeriodServiceImpl extends ServiceImpl<FinPeriodMapper, FinPeriod
|
|
|
finPeriod.setUpdateUserName(AuthUtil.getUserName());
|
|
|
}
|
|
|
this.saveOrUpdate(finPeriod);
|
|
|
+ if (ObjectUtils.isNotNull(finPeriod.getPeriodVouchersTemplate())) {
|
|
|
+ finPeriod.getPeriodVouchersTemplate().setId(finPeriod.getId() + "");
|
|
|
+ finPeriod.getPeriodVouchersTemplate().setStatus(finPeriod.getIsClosed());
|
|
|
+ finPeriod.getPeriodVouchersTemplate().setDate(finPeriod.getPeriodYear() + "-" + finPeriod.getPeriodMonth());
|
|
|
+ if ("FM-CURRENCY-PL-TRANSFER".equals(finPeriod.getPeriodVouchersTemplate().getBsType())) {
|
|
|
+ finPeriod.setExchange(JSON.toJSONString(finPeriod.getPeriodVouchersTemplate()));
|
|
|
+ } else {
|
|
|
+ finPeriod.setPeriod(JSON.toJSONString(finPeriod.getPeriodVouchersTemplate()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.updateById(finPeriod);
|
|
|
return R.data(finPeriod);
|
|
|
}
|
|
|
|
|
|
@@ -544,4 +633,309 @@ public class FinPeriodServiceImpl extends ServiceImpl<FinPeriodMapper, FinPeriod
|
|
|
return R.data(finPeriod);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
|
|
|
+ public R open(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 (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);
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(finPeriod);
|
|
|
+ return R.data(finPeriod);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FinPeriod detail(FinPeriod finPeriod) {
|
|
|
+ FinPeriod detail = baseMapper.selectById(finPeriod.getId());
|
|
|
+ if (detail != null) {
|
|
|
+ if ("FM-CURRENCY-PL-TRANSFER".equals(finPeriod.getType())) {
|
|
|
+ PeriodVouchersTemplate exchange = JSONObject.parseObject(detail.getExchange(), PeriodVouchersTemplate.class);
|
|
|
+ detail.setPeriodVouchersTemplate(exchange);
|
|
|
+ } else {
|
|
|
+ PeriodVouchersTemplate period = JSONObject.parseObject(detail.getPeriod(), PeriodVouchersTemplate.class);
|
|
|
+ detail.setPeriodVouchersTemplate(period);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R generateVouchers(PeriodVouchersTemplate periodVouchersTemplate) {
|
|
|
+ if (ObjectUtils.isNull(periodVouchersTemplate.getDate())) {
|
|
|
+ throw new RuntimeException("模板数据错误,请联系管理员");
|
|
|
+ }
|
|
|
+ String[] arr = periodVouchersTemplate.getDate().split("-");
|
|
|
+ Integer year = Integer.parseInt(arr[0]);
|
|
|
+ Integer month = Integer.parseInt(arr[1]);
|
|
|
+ if (finVouchersService.count(new LambdaQueryWrapper<FinVouchers>()
|
|
|
+ .eq(FinVouchers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinVouchers::getIsDeleted, 0)
|
|
|
+ .eq(FinVouchers::getAccountYear, year)
|
|
|
+ .eq(FinVouchers::getAccountMonth, month)
|
|
|
+ .eq(FinVouchers::getVoucherType, periodVouchersTemplate.getVkno())
|
|
|
+ .eq(FinVouchers::getVoucherSource, periodVouchersTemplate.getBsType())) > 0) {
|
|
|
+ throw new RuntimeException("凭证已生成,请勿重复生成");
|
|
|
+ }
|
|
|
+ List<PeriodVouchersAccItems> accItems = periodVouchersTemplate.getAccItems();
|
|
|
+ if (accItems.isEmpty()) {
|
|
|
+ throw new RuntimeException("模版科目明细不能为空");
|
|
|
+ }
|
|
|
+ FinVouchers finVouchers = new FinVouchers();
|
|
|
+ List<BusinessType> businessTypeList = bBusinessTypeService.list(new LambdaQueryWrapper<BusinessType>()
|
|
|
+ .eq(BusinessType::getIsDeleted, 0)
|
|
|
+ .eq(BusinessType::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BusinessType::getStatus, 0));
|
|
|
+ //创建凭证主表信息
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BusinessType businessType = businessTypeList.stream().filter(e -> e.getCode().equals("PZDH")).findFirst().orElse(null);
|
|
|
+ if (businessType == null) {
|
|
|
+ throw new RuntimeException("未找到可用业务类型");
|
|
|
+ }
|
|
|
+ BusinessBillNo businessBillNo = new BusinessBillNo();
|
|
|
+ businessBillNo.setBusinessTypeId(businessType.getId());
|
|
|
+ businessBillNo.setCode("PZDH-Z");
|
|
|
+ R clientBillNo = businessBillNoService.getBillNoLos(businessBillNo);
|
|
|
+ if (!clientBillNo.isSuccess()) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ throw new RuntimeException("生成订单编号失败");
|
|
|
+ }
|
|
|
+ finVouchers.setBillNo((String) clientBillNo.getData());
|
|
|
+ finVouchers.setVoucherType("转");
|
|
|
+ BusinessBillNo businessBillNo1 = new BusinessBillNo();
|
|
|
+ businessBillNo1.setBusinessTypeId(businessType.getId());
|
|
|
+ businessBillNo1.setCode("转");
|
|
|
+ R voucherNo = businessBillNoService.getVoucherNoLos(businessBillNo1);
|
|
|
+ if (!clientBillNo.isSuccess()) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ throw new RuntimeException("生成凭证号失败");
|
|
|
+ }
|
|
|
+ finVouchers.setVoucherNo((String) voucherNo.getData());
|
|
|
+ finVouchers.setVoucherSource(periodVouchersTemplate.getBsType());
|
|
|
+ finVouchers.setVoucherDate(new Date());
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ finVouchers.setAccountYear(currentDate.getYear());
|
|
|
+ finVouchers.setAccountMonth(currentDate.getMonthValue());
|
|
|
+ finVouchers.setAccountDay(currentDate.getDayOfMonth());
|
|
|
+ finVouchers.setCreateTime(new Date());
|
|
|
+ finVouchers.setCreateUser(AuthUtil.getUserId());
|
|
|
+ finVouchers.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ finVouchers.setSrcId(Long.parseLong(periodVouchersTemplate.getId()));
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ finVouchers.setCreateDept(deptId);
|
|
|
+ finVouchers.setBranchId(branchId);
|
|
|
+ finVouchers.setCreateDeptName(deptName);
|
|
|
+ }
|
|
|
+ finVouchersService.save(finVouchers);
|
|
|
+ List<FinVouchersItems> finVouchersItemsList = new ArrayList<>();
|
|
|
+ //获取所需科目列表信息
|
|
|
+ String accountsCode = accItems.stream().map(PeriodVouchersAccItems::getAccNo).collect(Collectors.joining(","));
|
|
|
+ List<Accounts> accountsList = accountsService.list(new LambdaQueryWrapper<Accounts>()
|
|
|
+ .eq(Accounts::getStatus, 0)
|
|
|
+ .apply("find_in_set(code,'" + accountsCode + "')"));
|
|
|
+ if (!accountsList.isEmpty()) {
|
|
|
+ List<Long> ids = accountsList.stream().map(Accounts::getId).collect(Collectors.toList());
|
|
|
+ List<FinGenlegCalc> finGenlegCalcList = finGenlegCalcService.list(new LambdaQueryWrapper<FinGenlegCalc>()
|
|
|
+ .eq(FinGenlegCalc::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinGenlegCalc::getBranchId, deptUtils.getDeptPid())
|
|
|
+ .in(FinGenlegCalc::getAccId, ids));
|
|
|
+ /*List<FinGenleg> finGenlegList = finGenlegService.list(new LambdaQueryWrapper<FinGenleg>()
|
|
|
+ .eq(FinGenleg::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FinGenleg::getBranchId, deptUtils.getDeptPid())
|
|
|
+ .in(FinGenleg::getAccId, ids));*/
|
|
|
+ int count = 0;
|
|
|
+ //循环复制凭证明细信息
|
|
|
+ for (Accounts item : accountsList) {
|
|
|
+ count++;
|
|
|
+ FinVouchersItems finVouchersItems = new FinVouchersItems();
|
|
|
+ finVouchersItems.setCreateTime(new Date());
|
|
|
+ finVouchersItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ finVouchersItems.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ finVouchersItems.setCreateDept(deptId);
|
|
|
+ finVouchersItems.setBranchId(branchId);
|
|
|
+ finVouchersItems.setCreateDeptName(deptName);
|
|
|
+ }
|
|
|
+ finVouchersItems.setPid(finVouchers.getId());
|
|
|
+ finVouchersItems.setBillNo(finVouchers.getBillNo());
|
|
|
+ finVouchersItems.setVoucherSource(finVouchers.getVoucherSource());
|
|
|
+ finVouchersItems.setVoucherType(finVouchers.getVoucherType());
|
|
|
+ finVouchersItems.setVoucherNo(finVouchers.getVoucherNo());
|
|
|
+ finVouchersItems.setVoucherDate(finVouchers.getVoucherDate());
|
|
|
+ finVouchersItems.setAccountYear(finVouchers.getAccountYear());
|
|
|
+ finVouchersItems.setAccountMonth(finVouchers.getAccountMonth());
|
|
|
+ finVouchersItems.setAccountDay(finVouchers.getAccountDay());
|
|
|
+ finVouchersItems.setAccountId(item.getId());
|
|
|
+ finVouchersItems.setAccountCode(item.getCode());
|
|
|
+ finVouchersItems.setAccountCnName(item.getCnName());
|
|
|
+ finVouchersItems.setAccountEnName(item.getEnName());
|
|
|
+ finVouchersItems.setAccountProperty(item.getProperty());
|
|
|
+ finVouchersItems.setAccountLevel(item.getLevel());
|
|
|
+ finVouchersItems.setDc(item.getDc());
|
|
|
+ finVouchersItems.setCurCode(item.getCurCode());
|
|
|
+
|
|
|
+ if (1 == item.getIsCorp() || 1 == item.getIsDept() || 1 == item.getIsEmpl()) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /*判断是否人民币,美元
|
|
|
+ * 人民币 判断模版借贷方向与科目借贷方向是否一致 true D+D=正 D+C=负 C+C=正 C+D=负
|
|
|
+ * 美元 判断模版借贷方向与科目借贷方向是否一致 true D+D=正 D+C=负 C+C=正 C+D=负
|
|
|
+ * 借或贷金额为零时跳过本次循环
|
|
|
+ * */
|
|
|
+ /*if ("CNY".equals(item.getCurCode())) {
|
|
|
+ finVouchersItems.setExrate(new BigDecimal("1"));
|
|
|
+ if ("D".equals(item.getDc())) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(amount[count - 1]) != 0) {
|
|
|
+ finVouchersItems.setAmountDr(amount[count - 1]);
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0.00").compareTo(amount[count - 1]) != 0) {
|
|
|
+ finVouchersItems.setAmountCr(amount[count - 1]);
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ finVouchersItems.setExrate(periodVouchersTemplate.getExrate());
|
|
|
+ if ("D".equals(item.getDc())) {
|
|
|
+ if (new BigDecimal("0.00").compareTo(amount[count - 1]) != 0) {
|
|
|
+ finVouchersItems.setAmountDrUsd(amount[count - 1]);
|
|
|
+ finVouchersItems.setAmountDr(finVouchersItems.getAmountDrUsd().multiply(periodVouchersTemplate.getExrate()));
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (new BigDecimal("0.00").compareTo(amount[count - 1]) != 0) {
|
|
|
+ finVouchersItems.setAmountCrUsd(amount[count - 1]);
|
|
|
+ finVouchersItems.setAmountCr(finVouchersItems.getAmountCrUsd().multiply(periodVouchersTemplate.getExrate()));
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算借,贷人民币与美金合计人民币金额
|
|
|
+ finVouchersItems.setAmountDrLoc(ObjectUtils.isNull(finVouchersItems.getAmountDr()) ? new BigDecimal("0") : finVouchersItems.getAmountDr()
|
|
|
+ .add(bCurrencyService.converterCny("USD", ObjectUtils.isNull(finVouchersItems.getAmountDrUsd()) ? new BigDecimal("0") : finVouchersItems.getAmountDrUsd(), "D", "1")));
|
|
|
+ finVouchersItems.setAmountCrLoc(ObjectUtils.isNull(finVouchersItems.getAmountCr()) ? new BigDecimal("0") : finVouchersItems.getAmountCr()
|
|
|
+ .add(bCurrencyService.converterCny("USD", ObjectUtils.isNull(finVouchersItems.getAmountCrUsd()) ? new BigDecimal("0") : finVouchersItems.getAmountCrUsd(), "C", "1")));
|
|
|
+ finVouchersItems.setIsCorp(item.getIsCorp());
|
|
|
+ //判断是否核算客户 true 向明细中客户字段复制
|
|
|
+ if (1 == finVouchersItems.getIsCorp()) {
|
|
|
+ if (bCorps != null) {
|
|
|
+ finVouchersItems.setCorpId(bCorps.getId());
|
|
|
+ finVouchersItems.setCorpCnName(bCorps.getCnName());
|
|
|
+ finVouchersItems.setCorpEnName(bCorps.getEnName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finVouchersItems.setIsDept(item.getIsDept());
|
|
|
+ //判断是否核算部门 true 向明细中部门字段复制
|
|
|
+ if (1 == finVouchersItems.getIsDept()) {
|
|
|
+ if (dept != null) {
|
|
|
+ finVouchersItems.setDeptId(dept.getId());
|
|
|
+ finVouchersItems.setDeptName(dept.getDeptName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finVouchersItems.setIsEmpl(item.getIsEmpl());
|
|
|
+ //判断是否核算职员 true 向明细中职员字段复制
|
|
|
+ if (1 == finVouchersItems.getIsEmpl()) {
|
|
|
+ if (user != null) {
|
|
|
+ finVouchersItems.setEmplId(user.getId());
|
|
|
+ finVouchersItems.setEmplName(user.getName());
|
|
|
+ } else {
|
|
|
+ if (userSrc != null) {
|
|
|
+ finVouchersItems.setEmplId(userSrc.getId());
|
|
|
+ finVouchersItems.setEmplName(userSrc.getCnName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ finVouchersItems.setLineNo(count);
|
|
|
+ finVouchersItems.setDescr(periodVouchersTemplate.getDescr());
|
|
|
+ finVouchersItemsList.add(finVouchersItems);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("未找到对应科目信息");
|
|
|
+ }
|
|
|
+
|
|
|
+// finVouchersItemsService.saveOrUpdateBatch(finVouchersItemsList);
|
|
|
+ BigDecimal amountDrCNY = new BigDecimal("0.00");
|
|
|
+ BigDecimal amountCrCNY = new BigDecimal("0.00");
|
|
|
+ BigDecimal amountDrUSD = new BigDecimal("0.00");
|
|
|
+ BigDecimal amountCrUSD = new BigDecimal("0.00");
|
|
|
+ amountDrCNY = amountDrCNY.add(finVouchersItemsList.stream()
|
|
|
+ .filter(e -> "CNY".equals(e.getCurCode()) && "D".equals(e.getDc())).map(FinVouchersItems::getAmountDr)
|
|
|
+ .filter(ObjectUtils::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ finVouchers.setAmountDr(amountDrCNY);
|
|
|
+ amountCrCNY = amountCrCNY.add(finVouchersItemsList.stream()
|
|
|
+ .filter(e -> "CNY".equals(e.getCurCode()) && "C".equals(e.getDc())).map(FinVouchersItems::getAmountCr)
|
|
|
+ .filter(ObjectUtils::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ finVouchers.setAmountCr(amountCrCNY);
|
|
|
+ amountDrUSD = amountDrUSD.add(finVouchersItemsList.stream()
|
|
|
+ .filter(e -> "USD".equals(e.getCurCode()) && "D".equals(e.getDc())).map(FinVouchersItems::getAmountDrUsd)
|
|
|
+ .filter(ObjectUtils::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ finVouchers.setAmountDrUsd(amountDrUSD);
|
|
|
+ amountCrUSD = amountCrUSD.add(finVouchersItemsList.stream()
|
|
|
+ .filter(e -> "USD".equals(e.getCurCode()) && "C".equals(e.getDc())).map(FinVouchersItems::getAmountCrUsd)
|
|
|
+ .filter(ObjectUtils::isNotNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ finVouchers.setAmountCrUsd(amountCrUSD);
|
|
|
+ finVouchers.setAmountDrLoc(amountDrCNY.add(bCurrencyService.converterCny("USD", amountDrUSD, "D", "1")));
|
|
|
+ finVouchers.setAmountCrLoc(amountCrCNY.add(bCurrencyService.converterCny("USD", amountCrUSD, "C", "1")));
|
|
|
+ finVouchers.setDescr(finVouchersItemsList.get(0).getDescr());
|
|
|
+ if (finVouchersItemsList.stream().anyMatch(e -> "USD".equals(e.getCurCode()))) {
|
|
|
+ finVouchers.setIsForeign(1);
|
|
|
+ }
|
|
|
+ finVouchersService.updateById(finVouchers);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|