|
|
@@ -0,0 +1,215 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.los.basic.acc.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 lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.los.basic.acc.entity.AccItemsOpenblc;
|
|
|
+import org.springblade.los.basic.acc.entity.Accounts;
|
|
|
+import org.springblade.los.basic.acc.mapper.AccountsMapper;
|
|
|
+import org.springblade.los.basic.acc.service.IAccItemsOpenblcService;
|
|
|
+import org.springblade.los.basic.acc.service.IAccountsService;
|
|
|
+import org.springblade.los.basic.acc.vo.AccountsVO;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 基础资料-科目代码 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2023-12-15
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class AccountsServiceImpl extends ServiceImpl<AccountsMapper, Accounts> implements IAccountsService {
|
|
|
+
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ private final IAccItemsOpenblcService accItemsOpenblcService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<AccountsVO> selectAccountsPage(IPage<AccountsVO> page, AccountsVO accounts) {
|
|
|
+ return page.setRecords(baseMapper.selectAccountsPage(page, accounts));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Accounts detail(Accounts accounts) {
|
|
|
+ Accounts detail = baseMapper.selectById(accounts.getId());
|
|
|
+ detail.setAccItemsOpenblcList(accItemsOpenblcService.list(new LambdaQueryWrapper<AccItemsOpenblc>()
|
|
|
+ .eq(AccItemsOpenblc::getAccountCode, detail.getCode())
|
|
|
+ .eq(AccItemsOpenblc::getAccountId, detail.getId())
|
|
|
+ .eq(AccItemsOpenblc::getTenantId, AuthUtil.getTenantId())));
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R submit(Accounts accounts) {
|
|
|
+ String deptId = "";
|
|
|
+ String deptName = "";
|
|
|
+ //获取部门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 (accounts.getId() == null) {
|
|
|
+ accounts.setCreateTime(new Date());
|
|
|
+ accounts.setCreateUser(AuthUtil.getUserId());
|
|
|
+ accounts.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ //获取部门ids对应中文名
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ accounts.setCreateDept(AuthUtil.getDeptId());
|
|
|
+ accounts.setBranchId(AuthUtil.getDeptId());
|
|
|
+ R<List<String>> res = sysClient.getDeptNames(AuthUtil.getDeptId());
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData())) {
|
|
|
+ accounts.setCreateDeptName(deptName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ accounts.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ accounts.setUpdateTime(new Date());
|
|
|
+ accounts.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(accounts.getParentCode())) {
|
|
|
+ accounts = selectSuperiorCode(accounts, accounts.getParentCode());
|
|
|
+ } else {
|
|
|
+ accounts.setIsDetail(1);
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(accounts);
|
|
|
+ if (ObjectUtils.isNotNull(accounts.getAccItemsOpenblcList())) {
|
|
|
+ for (AccItemsOpenblc item : accounts.getAccItemsOpenblcList()) {
|
|
|
+ item.setAccountCode(accounts.getCode());
|
|
|
+ item.setAccountId(accounts.getId());
|
|
|
+ item.setAccountCnName(accounts.getCnName());
|
|
|
+ item.setAccountEnName(accounts.getEnName());
|
|
|
+ item.setAccountFullName(accounts.getFullName());
|
|
|
+ item.setAccountProperty(accounts.getProperty());
|
|
|
+ item.setAccountLevel(accounts.getLevel());
|
|
|
+ item.setDc(accounts.getDc());
|
|
|
+ item.setIsForeign(accounts.getIsForeign());
|
|
|
+ item.setIsQuantity(accounts.getIsQuantity());
|
|
|
+ item.setIsCorp(accounts.getIsCorp());
|
|
|
+ item.setIsDept(accounts.getIsDept());
|
|
|
+ item.setIsEmpl(accounts.getIsEmpl());
|
|
|
+ item.setIsItem(accounts.getIsItem());
|
|
|
+ item.setCurCode(accounts.getCurCode());
|
|
|
+ item.setExrate(accounts.getExrate());
|
|
|
+ item.setUnitNo(accounts.getUnitNo());
|
|
|
+ item.setPrice(accounts.getPrice());
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ item.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ if (ObjectUtils.isNotNull(AuthUtil.getDeptId())) {
|
|
|
+ item.setCreateDept(deptId);
|
|
|
+ item.setBranchId(AuthUtil.getDeptId());
|
|
|
+ item.setCreateDeptName(deptName);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ accItemsOpenblcService.saveOrUpdateBatch(accounts.getAccItemsOpenblcList());
|
|
|
+ // 期初本币借方金额(CNY)
|
|
|
+ accounts.setAmountOpenDr(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountOpenDr)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //期初本币贷方金额(CNY)
|
|
|
+ accounts.setAmountOpenCr(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountOpenCr)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ // 期初本币余额(CNY)
|
|
|
+ accounts.setAmountOpenBlc(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountOpenBlc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ // 本期本币借方金额(CNY)
|
|
|
+ accounts.setAmountDr(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountDr)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //本期本币贷方金额(CNY)
|
|
|
+ accounts.setAmountCr(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountCr)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //本期本币余额(CNY)
|
|
|
+ accounts.setAmountBlc(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountBlc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //期初外币借方金额
|
|
|
+ accounts.setAmountOpenDrUsd(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountOpenDrUsd)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //期初外币贷方金额
|
|
|
+ accounts.setAmountOpenCrUsd(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountOpenCrUsd)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //期初外币期初余额
|
|
|
+ accounts.setAmountOpenUsdBlc(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountOpenUsdBlc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //本期外币借方金额
|
|
|
+ accounts.setAmountDrUsd(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountDrUsd)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //本期外币贷方金额
|
|
|
+ accounts.setAmountCrUsd(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountCrUsd)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //本期外币期初余额
|
|
|
+ accounts.setAmountUsdBlc(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getAmountUsdBlc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //期初数量借方金额
|
|
|
+ accounts.setQuantityOpenDr(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getQuantityOpenDr)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //期初数量贷方金额
|
|
|
+ accounts.setQuantityOpenCr(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getQuantityOpenCr)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //期初数量期初余额
|
|
|
+ accounts.setQuantityOpenBlc(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getQuantityOpenBlc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //本期数量借方金额
|
|
|
+ accounts.setQuantityDr(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getQuantityDr)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ //本期数量贷方金额
|
|
|
+ accounts.setQuantityCr(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getQuantityCr)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ // 本期数量期初余额
|
|
|
+ accounts.setQuantityBlc(accounts.getAccItemsOpenblcList().stream().map(AccItemsOpenblc::getQuantityBlc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(accounts);
|
|
|
+ return R.data(accounts);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Accounts selectSuperiorCode(Accounts accounts, String parentCode) {
|
|
|
+ Accounts accounts1 = baseMapper.selectOne(new LambdaQueryWrapper<Accounts>()
|
|
|
+ .eq(Accounts::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Accounts::getCode, parentCode));
|
|
|
+ if (accounts1 != null) {
|
|
|
+ accounts.setFullName(accounts1.getCnName() + "/" + accounts.getFullName());
|
|
|
+ accounts.setIsDetail(0);
|
|
|
+ if (ObjectUtils.isNotNull(accounts1.getParentCode())) {
|
|
|
+ this.selectSuperiorCode(accounts, accounts1.getParentCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return accounts;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|