|
@@ -1,6 +1,12 @@
|
|
|
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 cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.form.entity.SubjectBalanceBo;
|
|
|
import com.fjhx.form.entity.SubjectBalanceSelectDto;
|
|
@@ -8,12 +14,15 @@ import com.fjhx.form.entity.account.po.AccountSubjectsBalance;
|
|
|
import com.fjhx.form.mapper.FinanceReportMapper;
|
|
|
import com.fjhx.form.service.FinanceReportService;
|
|
|
import com.fjhx.form.service.account.AccountSubjectsBalanceService;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -81,4 +90,45 @@ public class FinanceReportServiceImpl implements FinanceReportService {
|
|
|
|
|
|
return subjectBalanceBos;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每月1日0点1分 赋值客户上月科目余额
|
|
|
+ */
|
|
|
+// @PostConstruct
|
|
|
+ @Scheduled(cron = "0 1 0 1 * ?")
|
|
|
+ public void autoSaveReceivableAccountsEnding() {
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ SecurityUtils.setTenantId("000000");
|
|
|
+
|
|
|
+ DateTime lastMonth = DateUtil.offsetMonth(new Date(), -1);
|
|
|
+
|
|
|
+
|
|
|
+ SubjectBalanceSelectDto dto = new SubjectBalanceSelectDto();
|
|
|
+ dto.setYear(DateUtil.year(lastMonth));
|
|
|
+ List<SubjectBalanceBo> subjectBalanceBos = subjectBalance(dto);
|
|
|
+
|
|
|
+ for (SubjectBalanceBo receivableAccount : subjectBalanceBos) {
|
|
|
+ Long subjectsId = receivableAccount.getSubjectsId();
|
|
|
+ int month = DateUtil.month(lastMonth) + 1;
|
|
|
+
|
|
|
+
|
|
|
+ DateTime parse = DateUtil.parse(StrUtil.format("{}-{}", dto.getYear(), month), "yyyy-MM");
|
|
|
+ AccountSubjectsBalance one = accountSubjectsBalanceService.getOne(q -> q
|
|
|
+ .eq(AccountSubjectsBalance::getSubjectsId, subjectsId)
|
|
|
+ .eq(AccountSubjectsBalance::getAccountDate, parse)
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(one)) {
|
|
|
+ one = new AccountSubjectsBalance();
|
|
|
+ one.setSubjectsId(subjectsId);
|
|
|
+ one.setAccountDate(parse);
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject json = JSONObject.parseObject(JSONObject.toJSONString(receivableAccount));
|
|
|
+ one.setBalance(json.getBigDecimal("month" + month + "Amount"));
|
|
|
+ accountSubjectsBalanceService.saveOrUpdate(one);
|
|
|
+ }
|
|
|
+
|
|
|
+ SecurityUtils.clearTenantId();
|
|
|
+ DynamicDataSourceContextHolder.clear();
|
|
|
+ }
|
|
|
}
|