|
@@ -3,6 +3,9 @@ package com.fjhx.form.service.impl;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.util.DateUtils;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -12,26 +15,28 @@ import com.fjhx.account.service.account.AccountRunningWaterService;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.common.utils.excel.util.ExcelUtil;
|
|
|
-import com.fjhx.form.entity.RemitDetailSelectDto;
|
|
|
-import com.fjhx.form.entity.RemitDetailVo;
|
|
|
-import com.fjhx.form.entity.SubjectBalanceBo;
|
|
|
-import com.fjhx.form.entity.SubjectBalanceSelectDto;
|
|
|
+import com.fjhx.form.entity.*;
|
|
|
import com.fjhx.form.entity.calculate.po.CalculateItemBalance;
|
|
|
+import com.fjhx.form.entity.payable.po.PayableBalance;
|
|
|
import com.fjhx.form.mapper.FinanceReportMapper;
|
|
|
import com.fjhx.form.service.FinanceReportService;
|
|
|
import com.fjhx.form.service.calculate.CalculateItemBalanceService;
|
|
|
+import com.fjhx.form.service.payable.PayableBalanceService;
|
|
|
+import com.fjhx.supply.service.supplier.SupplierInfoService;
|
|
|
+import com.fjhx.wms.service.warehouse.WarehouseService;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
+import org.apache.commons.codec.Charsets;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class FinanceReportServiceImpl implements FinanceReportService {
|
|
@@ -41,6 +46,13 @@ public class FinanceReportServiceImpl implements FinanceReportService {
|
|
|
private CalculateItemBalanceService calculateItemBalanceService;
|
|
|
@Resource
|
|
|
private AccountRunningWaterService accountRunningWaterService;
|
|
|
+ @Resource
|
|
|
+ private SupplierInfoService supplierInfoService;
|
|
|
+ @Resource
|
|
|
+ private WarehouseService warehouseService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PayableBalanceService payableBalanceService;
|
|
|
|
|
|
@Override
|
|
|
public List<SubjectBalanceBo> subjectBalance(SubjectBalanceSelectDto dto) {
|
|
@@ -210,4 +222,187 @@ public class FinanceReportServiceImpl implements FinanceReportService {
|
|
|
.set(AccountRunningWater::getUpdateUser, SecurityUtils.getUserId())
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<AccountsPayableVo> getAccountsPayablePage(AccountsPayableSelectDto dto) {
|
|
|
+ Assert.notEmpty(dto.getYear(), "年份不能为空!");
|
|
|
+
|
|
|
+ Page<AccountsPayableVo> accountsPayablePage = financeReportMapper.getAccountsPayablePage(dto.getPage(), IWrapper.getWrapper(), dto.getYear());
|
|
|
+ List<AccountsPayableVo> records = accountsPayablePage.getRecords();
|
|
|
+
|
|
|
+ //赋值详情
|
|
|
+ setAccountsPayableInfo(records, dto);
|
|
|
+
|
|
|
+ return accountsPayablePage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 应付账款详情
|
|
|
+ */
|
|
|
+ private void setAccountsPayableInfo(List<AccountsPayableVo> records, AccountsPayableSelectDto dto) {
|
|
|
+ //获取年初数据
|
|
|
+ Map<String, BigDecimal> lastEndBalanceMap = payableBalanceService.mapKV(PayableBalance::getIdStr, PayableBalance::getEndBalance, q -> q
|
|
|
+ .eq(PayableBalance::getYear, dto.getYear() - 1));
|
|
|
+ //获取当年数据
|
|
|
+ Map<String, PayableBalance> balanceMap = payableBalanceService.mapKEntity(PayableBalance::getIdStr, q -> q.eq(PayableBalance::getYear, dto.getYear()));
|
|
|
+
|
|
|
+ for (AccountsPayableVo record : records) {
|
|
|
+ //赋值年初余额
|
|
|
+ record.setYearBeginBalance(lastEndBalanceMap.getOrDefault(record.getIdStr(), BigDecimal.ZERO));
|
|
|
+
|
|
|
+ //上月余额
|
|
|
+ BigDecimal lastMonthEndBalance = record.getYearBeginBalance();
|
|
|
+
|
|
|
+ //赋值备注
|
|
|
+ PayableBalance payableBalance = balanceMap.getOrDefault(record.getIdStr(), new PayableBalance());
|
|
|
+ record.setRemark(payableBalance.getRemark());
|
|
|
+
|
|
|
+ //将当前年数据转JSON
|
|
|
+ JSONObject balanceJson = JSONObject.parse(JSONObject.toJSONString(payableBalance));
|
|
|
+
|
|
|
+ //处理月数据
|
|
|
+ JSONObject dataJson = JSONObject.parse(record.getDataJson());
|
|
|
+ JSONObject monthJson = new JSONObject();
|
|
|
+ //赋值每月数据
|
|
|
+ for (int i = 1; i <= 12; i++) {
|
|
|
+ AccountsPayableVo.MonthDataVo monthData = dataJson.getObject(i + "", AccountsPayableVo.MonthDataVo.class);
|
|
|
+ if (ObjectUtil.isNull(monthData)) {
|
|
|
+ monthData = new AccountsPayableVo.MonthDataVo();
|
|
|
+ monthData.setArrivalAmount(BigDecimal.ZERO);
|
|
|
+ monthData.setArrivalAdjustAmount(BigDecimal.ZERO);
|
|
|
+ monthData.setBackAmount(BigDecimal.ZERO);
|
|
|
+ monthData.setTaxAmount(BigDecimal.ZERO);
|
|
|
+ monthData.setTaxAdjustAmount(BigDecimal.ZERO);
|
|
|
+ monthData.setPaymentAmount(BigDecimal.ZERO);
|
|
|
+ monthData.setEndAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ //调整借方发生额 为负数
|
|
|
+ monthData.setPaymentAmount(BigDecimal.ZERO.subtract(monthData.getPaymentAmount()));
|
|
|
+
|
|
|
+ //赋值税费调整
|
|
|
+ BigDecimal monthTaxAdjust = balanceJson.getBigDecimal("month" + i + "TaxAdjust");
|
|
|
+ if (ObjectUtil.isEmpty(monthTaxAdjust)) {
|
|
|
+ monthTaxAdjust = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ monthData.setTaxAdjustAmount(monthTaxAdjust);
|
|
|
+
|
|
|
+ monthJson.put(i + "", monthData);
|
|
|
+
|
|
|
+ //赋值余额
|
|
|
+ BigDecimal add = lastMonthEndBalance.add(monthData.getArrivalAmount()).add(monthData.getBackAmount()).add(monthData.getArrivalAdjustAmount())
|
|
|
+ .add(monthData.getTaxAmount()).add(monthTaxAdjust).add(monthData.getPaymentAmount());
|
|
|
+ monthData.setEndAmount(add);
|
|
|
+ lastMonthEndBalance = add;
|
|
|
+ }
|
|
|
+ record.setMonthData(monthJson);
|
|
|
+ }
|
|
|
+ //赋值供应商名称
|
|
|
+ supplierInfoService.attributeAssign(records, AccountsPayableVo::getSupplierId, (item, supplier) -> {
|
|
|
+ item.setSupplierName(supplier.getName());
|
|
|
+ item.setSupplierShortName(supplier.getShortName());
|
|
|
+ item.setSupplierTaxPoints(supplier.getPrivTaxPoints());
|
|
|
+ });
|
|
|
+ //赋值仓库名称
|
|
|
+ warehouseService.attributeAssign(records, AccountsPayableVo::getWarehouseId, (item, warehouse) -> {
|
|
|
+ item.setWarehouseName(warehouse.getName());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void accountsPayableExportExcel(HttpServletResponse response, AccountsPayableSelectDto dto) {
|
|
|
+ List<AccountsPayableVo> list = financeReportMapper.getAccountsPayablePage(IWrapper.getWrapper(), dto.getYear());
|
|
|
+
|
|
|
+ //赋值详情
|
|
|
+ setAccountsPayableInfo(list, dto);
|
|
|
+
|
|
|
+ //数据处理
|
|
|
+ List<List<Object>> writeList = new ArrayList<List<Object>>();
|
|
|
+ for (AccountsPayableVo accountsPayableVo : list) {
|
|
|
+ List<Object> item = new ArrayList<>();
|
|
|
+ item.add(accountsPayableVo.getSupplierShortName());
|
|
|
+ item.add(accountsPayableVo.getWarehouseName());
|
|
|
+ item.add(accountsPayableVo.getSupplierTaxPoints());
|
|
|
+ item.add(accountsPayableVo.getYearBeginBalance());
|
|
|
+
|
|
|
+ JSONObject monthData = accountsPayableVo.getMonthData();
|
|
|
+ for (int i = 1; i <= 12; i++) {
|
|
|
+ AccountsPayableVo.MonthDataVo month = monthData.getObject(1 + "", AccountsPayableVo.MonthDataVo.class);
|
|
|
+ item.add(month.getArrivalAmount());
|
|
|
+ item.add(month.getBackAmount());
|
|
|
+ item.add(month.getArrivalAdjustAmount());
|
|
|
+ item.add(month.getTaxAmount());
|
|
|
+ item.add(month.getTaxAdjustAmount());
|
|
|
+ item.add(month.getPaymentAmount());
|
|
|
+ item.add(month.getEndAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+ item.add(accountsPayableVo.getRemark());
|
|
|
+
|
|
|
+ writeList.add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ //标题
|
|
|
+ List<List<String>> headList = new ArrayList<List<String>>();
|
|
|
+ headList.add(Arrays.asList("", "简称"));
|
|
|
+ headList.add(Arrays.asList("", "入库仓库"));
|
|
|
+ headList.add(Arrays.asList("", "税点"));
|
|
|
+ headList.add(Arrays.asList("", "年初余额"));
|
|
|
+ for (int i = 1; i <= 12; i++) {
|
|
|
+ List<String> asList = Arrays.asList("到货金额", "退货金额", "货款调整", "税费", "税费调整", "借方发生额", "期末余额");
|
|
|
+ for (String ti : asList) {
|
|
|
+ headList.add(Arrays.asList(i + "月", ti));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ headList.add(Arrays.asList("", "备注"));
|
|
|
+
|
|
|
+ //导出
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding(Charsets.UTF_8.name());
|
|
|
+ String fileName = DateUtils.format(new Date(), DateUtils.DATE_FORMAT_14) + "导出数据";
|
|
|
+ fileName = URLEncoder.encode(fileName, Charsets.UTF_8.name());
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+ EasyExcel.write(response.getOutputStream()).sheet().head(headList).doWrite(writeList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每月1日0点1分 赋值上月应付余额
|
|
|
+ */
|
|
|
+// @PostConstruct
|
|
|
+ @Scheduled(cron = "0 1 0 1 * ?")
|
|
|
+ public void autoSaveAccountsPayablePageEnding() {
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ SecurityUtils.setTenantId("000000");
|
|
|
+
|
|
|
+ DateTime lastMonth = DateUtil.offsetMonth(new Date(), -1);
|
|
|
+ int year = DateUtil.year(lastMonth);
|
|
|
+ int month = DateUtil.month(lastMonth) + 1;
|
|
|
+
|
|
|
+ AccountsPayableSelectDto dto = new AccountsPayableSelectDto();
|
|
|
+ dto.setYear(year);
|
|
|
+ List<AccountsPayableVo> list = financeReportMapper.getAccountsPayablePage(IWrapper.getWrapper(), dto.getYear());
|
|
|
+ setAccountsPayableInfo(list, dto);
|
|
|
+
|
|
|
+ for (AccountsPayableVo accountsPayableVo : list) {
|
|
|
+ AccountsPayableVo.MonthDataVo monthData = accountsPayableVo.getMonthData().getObject(month + "", AccountsPayableVo.MonthDataVo.class);
|
|
|
+
|
|
|
+ PayableBalance payableBalance = payableBalanceService.getOne(q -> q
|
|
|
+ .eq(PayableBalance::getIdStr, accountsPayableVo.getIdStr()).eq(PayableBalance::getYear, year));
|
|
|
+ if (ObjectUtil.isEmpty(payableBalance)) {
|
|
|
+ payableBalance = new PayableBalance();
|
|
|
+ payableBalance.setIdStr(accountsPayableVo.getIdStr());
|
|
|
+ payableBalance.setYear(year);
|
|
|
+ }
|
|
|
+ payableBalance.setEndBalance(monthData.getEndAmount());
|
|
|
+
|
|
|
+ payableBalanceService.saveOrUpdate(payableBalance);
|
|
|
+ }
|
|
|
+
|
|
|
+ SecurityUtils.clearTenantId();
|
|
|
+ DynamicDataSourceContextHolder.clear();
|
|
|
+ }
|
|
|
}
|