|
@@ -1,10 +1,10 @@
|
|
|
package com.jeeplus.finance.invoice.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -16,30 +16,25 @@ import com.jeeplus.common.TokenProvider;
|
|
|
import com.jeeplus.core.query.QueryWrapperGenerator;
|
|
|
import com.jeeplus.finance.invoice.domain.*;
|
|
|
import com.jeeplus.finance.invoice.mapper.*;
|
|
|
-import com.jeeplus.finance.invoice.service.dto.CwFinanceInvoiceBaseDTO;
|
|
|
-import com.jeeplus.finance.invoice.service.dto.CwFinanceInvoiceDTO;
|
|
|
-import com.jeeplus.finance.invoice.service.dto.CwFinanceInvoiceDetailDTO;
|
|
|
-import com.jeeplus.finance.invoice.service.dto.CwFinanceInvoiceReceivablesDTO;
|
|
|
+import com.jeeplus.finance.invoice.service.dto.*;
|
|
|
import com.jeeplus.finance.invoice.service.mapstruct.*;
|
|
|
-import com.jeeplus.finance.projectRecords.domain.CwProjectRecords;
|
|
|
import com.jeeplus.finance.projectRecords.mapper.CwProjectRecordsMapper;
|
|
|
import com.jeeplus.finance.projectRecords.service.dto.CwProjectRecordsDTO;
|
|
|
import com.jeeplus.finance.projectReport.domain.CwProjectReportData;
|
|
|
import com.jeeplus.finance.projectReport.mapper.CwProjectReportMapper;
|
|
|
import com.jeeplus.finance.workClientInfo.domain.CwWorkClientBase;
|
|
|
import com.jeeplus.finance.workClientInfo.domain.CwWorkClientBilling;
|
|
|
+import com.jeeplus.finance.workClientInfo.mapper.CwWorkClientBillingMapper;
|
|
|
import com.jeeplus.finance.workClientInfo.service.CwWorkClientBillingService;
|
|
|
import com.jeeplus.finance.workClientInfo.service.CwWorkClientService;
|
|
|
//import com.jeeplus.pubmodules.oss.mapper.OssServiceMapper;
|
|
|
//import com.jeeplus.pubmodules.oss.service.OssService;
|
|
|
//import com.jeeplus.pubmodules.serialNumTpl.service.SerialnumTplService;
|
|
|
+import com.jeeplus.finance.workClientInfo.service.dto.CwWorkClientBillingDTO;
|
|
|
import com.jeeplus.sys.domain.User;
|
|
|
-import com.jeeplus.sys.feign.IOfficeApi;
|
|
|
-import com.jeeplus.sys.feign.IRoleApi;
|
|
|
-import com.jeeplus.sys.feign.IUserApi;
|
|
|
-import com.jeeplus.sys.feign.IWorkAttachmentApi;
|
|
|
+import com.jeeplus.sys.feign.*;
|
|
|
//import com.jeeplus.sys.service.UserService;
|
|
|
-import com.jeeplus.sys.service.dto.OfficeDTO;
|
|
|
+import com.jeeplus.sys.service.dto.AreaDTO;
|
|
|
import com.jeeplus.sys.service.dto.RoleDTO;
|
|
|
import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -50,12 +45,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -76,6 +69,8 @@ public class CwFinanceInvoiceService extends ServiceImpl<CwFinanceInvoiceMapper,
|
|
|
private CwProjectRecordsMapper cwProjectRecordsMapper;
|
|
|
@Resource
|
|
|
private CwProjectReportMapper cwProjectReportMapper;
|
|
|
+ @Resource
|
|
|
+ private CwWorkClientBillingMapper cwWorkClientBillingMapper;
|
|
|
|
|
|
|
|
|
// @Resource
|
|
@@ -668,10 +663,11 @@ public class CwFinanceInvoiceService extends ServiceImpl<CwFinanceInvoiceMapper,
|
|
|
|
|
|
public CwFinanceInvoice saveForm(CwFinanceInvoiceDTO cwFinanceInvoiceDTO) throws Exception{
|
|
|
CwFinanceInvoice cwFinanceInvoice = CwFinanceInvoiceWrapper.INSTANCE.toEntity(cwFinanceInvoiceDTO);
|
|
|
+ //获取当前登录人信息
|
|
|
+ UserDTO userDTO = SpringUtil.getBean ( IUserApi.class ).getByToken(TokenProvider.getCurrentToken());
|
|
|
if (ObjectUtil.isNotEmpty(cwFinanceInvoice)) {
|
|
|
if(StringUtils.isBlank(cwFinanceInvoice.getId())){
|
|
|
- //获取当前登录人信息
|
|
|
- UserDTO userDTO = SpringUtil.getBean ( IUserApi.class ).getByToken(TokenProvider.getCurrentToken());
|
|
|
+
|
|
|
//发票编号生成
|
|
|
String serialNum = SpringUtil.getBean ( IWorkAttachmentApi.class ).genSerialNum(userDTO.getCompanyDTO().getId(), CwFinanceInvoiceDTO.BIZ_CODE,TokenProvider.getCurrentToken());
|
|
|
cwFinanceInvoice.setNo(serialNum);
|
|
@@ -686,6 +682,10 @@ public class CwFinanceInvoiceService extends ServiceImpl<CwFinanceInvoiceMapper,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (StringUtils.isBlank(cwFinanceInvoice.getNo())){
|
|
|
+ String serialNum = SpringUtil.getBean ( IWorkAttachmentApi.class ).genSerialNum(userDTO.getCompanyDTO().getId(), CwFinanceInvoiceDTO.BIZ_CODE,TokenProvider.getCurrentToken());
|
|
|
+ cwFinanceInvoice.setNo(serialNum);
|
|
|
+ }
|
|
|
if(StringUtils.isNotEmpty(cwFinanceInvoiceDTO.getActualDrawerEmailAddress())){
|
|
|
cwFinanceInvoice.setActualDrawerEmailAddress(cwFinanceInvoiceDTO.getActualDrawerEmailAddress());
|
|
|
}
|
|
@@ -1214,4 +1214,425 @@ public class CwFinanceInvoiceService extends ServiceImpl<CwFinanceInvoiceMapper,
|
|
|
|
|
|
return filteredList;
|
|
|
}
|
|
|
+
|
|
|
+ private static final Pattern EMAIL_PATTERN = Pattern.compile("^[A-Za-z0-9+_.-]+@(.+)$");
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入发票数据
|
|
|
+ * @param listA
|
|
|
+ * @param arrayList
|
|
|
+ * @param hashMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String importFinance(List<CwFinanceImportDTO> listA, ArrayList<CwFinanceImportDTO> arrayList, HashMap<String, String> hashMap) {
|
|
|
+ //获取当前登录人信息
|
|
|
+ UserDTO userDTO = SpringUtil.getBean(IUserApi.class).getByToken(TokenProvider.getCurrentToken());
|
|
|
+ //查询全部的项目信息
|
|
|
+ List<CwProjectRecordsDTO> projectRecordsList = cwProjectRecordsMapper.selectAllList(userDTO.getId());
|
|
|
+ //查询全部的报告信息
|
|
|
+ List<CwProjectReportData> projectReportList = cwProjectReportMapper.getList(userDTO.getId());
|
|
|
+ //查询全部的发票信息
|
|
|
+ List<CwFinanceInvoiceDTO> invoiceDTOList = cwFinanceInvoiceMapper.getList(userDTO.getId());
|
|
|
+ //查询全部的客户信息
|
|
|
+ List<CwWorkClientBillingDTO> clientBillingList = cwWorkClientBillingMapper.getList();
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(listA)){
|
|
|
+ for (CwFinanceImportDTO cwFinanceImportDTO : listA) {
|
|
|
+ // 1. 报告号和项目编号校验
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getReportNo()) && StringUtils.isBlank(cwFinanceImportDTO.getProjectNo())) {
|
|
|
+ return "报告号和项目编号不能同时为空";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 项目开票金额校验
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getBaseAccount())){
|
|
|
+ double amount = Double.parseDouble(cwFinanceImportDTO.getBaseAccount());
|
|
|
+ if (amount < 0 && StringUtils.isBlank(cwFinanceImportDTO.getRedInvoiceRelevancyNumber())) {
|
|
|
+ return "开票金额为负时,必须填写关联红字发票的发票编号";
|
|
|
+ }
|
|
|
+ if (amount < 0 && StringUtils.isNotBlank(cwFinanceImportDTO.getRedInvoiceRelevancyNumber())) {
|
|
|
+ //将开票编号中的英文转为大写
|
|
|
+ String upperCaseRedInvoice = cwFinanceImportDTO.getRedInvoiceRelevancyNumber().toUpperCase();
|
|
|
+ boolean exists = invoiceDTOList.stream()
|
|
|
+ .anyMatch(invoice -> upperCaseRedInvoice.equals(invoice.getNo()));
|
|
|
+ if (exists) {
|
|
|
+ //根据关联红字发票编号查询发票信息
|
|
|
+ for (CwFinanceInvoiceDTO cwFinanceInvoiceDTO : invoiceDTOList) {
|
|
|
+ if (cwFinanceInvoiceDTO.getNo().equals(upperCaseRedInvoice)){
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceInvoiceDTO.getAccount())){
|
|
|
+ double parseDouble = Double.parseDouble(cwFinanceInvoiceDTO.getAccount());
|
|
|
+ if (parseDouble < 0){
|
|
|
+ return "关联红字发票编号——"+cwFinanceImportDTO.getRedInvoiceRelevancyNumber()+"的开票金额为负,请重新填写关联红字发票编号";
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return "关联红字发票编号——"+cwFinanceImportDTO.getRedInvoiceRelevancyNumber()+"的开票金额为空,请重新填写关联红字发票编号";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return "关联红字发票编号——"+cwFinanceImportDTO.getRedInvoiceRelevancyNumber()+"不存在,请重新填写";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return "项目开票金额不能为空";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 开票内容必填
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getBillingContent())) {
|
|
|
+ return "开票内容不能为空";
|
|
|
+ }
|
|
|
+ // 5. 邮箱校验
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getActualDrawerEmailAddress()) &&
|
|
|
+ !EMAIL_PATTERN.matcher(cwFinanceImportDTO.getActualDrawerEmailAddress()).matches()) {
|
|
|
+ return "接收邮箱格式不正确";
|
|
|
+ }
|
|
|
+ // 6.单位名称校验
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getBillingWorkplaceReal())){
|
|
|
+ return "单位名称不能为空";
|
|
|
+ }
|
|
|
+ //发票类型校验
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getType())){
|
|
|
+ return "发票类型不能为空";
|
|
|
+ }
|
|
|
+ //开票类型校验
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getBillingType())){
|
|
|
+ return "开票类型不能为空";
|
|
|
+ }
|
|
|
+ //发票类型校验
|
|
|
+ if ("专票".equals(cwFinanceImportDTO.getType()) && "企业开票".equals(cwFinanceImportDTO.getBillingType()) && StringUtils.isNotBlank(cwFinanceImportDTO.getBillingWorkplaceReal())){
|
|
|
+ //根据单位查询客户信息
|
|
|
+ boolean match = clientBillingList.stream().anyMatch(client -> cwFinanceImportDTO.getBillingWorkplaceReal().equals(client.getCompanyName()));
|
|
|
+ if (match){
|
|
|
+ for (CwWorkClientBillingDTO cwWorkClientBilling : clientBillingList) {
|
|
|
+ if (cwWorkClientBilling.getCompanyName().equals(cwFinanceImportDTO.getBillingWorkplaceReal())){
|
|
|
+ if (StringUtils.isBlank(cwWorkClientBilling.getTaxpayerIdentificationNo())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"下的纳税人识别号在系统中不存在,请填写";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cwWorkClientBilling.getAddress())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"下的地址在系统中不存在,请填写";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cwWorkClientBilling.getPhone())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"下的电话在系统中不存在,请填写";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cwWorkClientBilling.getAccountHolder())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"下的开户银行名称在系统中不存在,请填写";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cwWorkClientBilling.getAccount())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"下的银行账号在系统中不存在,请填写";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getTaxpayerIdentificationNo())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"在系统中不存在,纳税人识别号不能为空";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getAddress())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"在系统中不存在,地址不能为空";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getTelPhone())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"在系统中不存在,电话不能为空";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getOpenBank())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"在系统中不存在,开户银行名称不能为空";
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cwFinanceImportDTO.getBankAccount())){
|
|
|
+ return "客户名称——"+cwFinanceImportDTO.getBillingWorkplaceReal()+"在系统中不存在,银行账号不能为空";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ arrayList.add(cwFinanceImportDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<CwFinanceInvoice> invoiceArrayList = new ArrayList<>();
|
|
|
+ ArrayList<CwFinanceInvoiceBase> baseArrayList = new ArrayList<>();
|
|
|
+
|
|
|
+ //发票类型
|
|
|
+ String invoiceTypeDatas = SpringUtil.getBean ( IDictApi.class ).getDictValueListMapByDict ("invoice_type");
|
|
|
+ Map<String,Object> invoiceTypeValueDTOs = JSON.parseObject(invoiceTypeDatas, new TypeReference<Map<String,Object>>() {});
|
|
|
+ //开票类型
|
|
|
+ String invoiceBillingTypeDatas = SpringUtil.getBean ( IDictApi.class ).getDictValueListMapByDict ("invoice_billing_type");
|
|
|
+ Map<String,Object> invoiceBillingTypeValueDTOs = JSON.parseObject(invoiceBillingTypeDatas, new TypeReference<Map<String,Object>>() {});
|
|
|
+ //开票内容
|
|
|
+ String invoiceBillingContentDatas = SpringUtil.getBean ( IDictApi.class ).getDictValueListMapByDict ("invoice_billing_content");
|
|
|
+ Map<String,Object> invoiceBillingContentValueDTOs = JSON.parseObject(invoiceBillingContentDatas, new TypeReference<Map<String,Object>>() {});
|
|
|
+
|
|
|
+ //获取所有人信息
|
|
|
+ List<UserDTO> allUserInfo = SpringUtil.getBean(IUserApi.class).getAllUserInfo();
|
|
|
+ //区域
|
|
|
+ List<AreaDTO> areaDTOList = cwFinanceInvoiceMapper.getAllArea();
|
|
|
+ List<AreaDTO> buildTree = buildTree(areaDTOList);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(arrayList)){
|
|
|
+ for (CwFinanceImportDTO cwFinanceImportDTO : arrayList) {
|
|
|
+ CwFinanceInvoice cwFinanceInvoice = new CwFinanceInvoice();
|
|
|
+ String id = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ cwFinanceInvoice.setId(id);
|
|
|
+
|
|
|
+ CwFinanceInvoiceBase cwFinanceInvoiceBase = new CwFinanceInvoiceBase();
|
|
|
+ String baseId = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ cwFinanceInvoiceBase.setId(baseId);
|
|
|
+ cwFinanceInvoiceBase.setInvoiceId(id);
|
|
|
+
|
|
|
+ //保存报告或项目信息
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getProjectNo()) && StringUtils.isBlank(cwFinanceImportDTO.getReportNo())){
|
|
|
+ boolean exist = projectRecordsList.stream().anyMatch(records -> records.getProjectNumber().equals(cwFinanceImportDTO.getProjectNo()));
|
|
|
+ if (exist){
|
|
|
+ for (CwProjectRecordsDTO cwProjectRecords : projectRecordsList) {
|
|
|
+ if (cwProjectRecords.getProjectNumber().equals(cwFinanceImportDTO.getProjectNo())){
|
|
|
+ cwFinanceInvoiceBase.setProgramId(cwProjectRecords.getId());
|
|
|
+ cwFinanceInvoiceBase.setProgramNo(cwProjectRecords.getProjectNumber());
|
|
|
+ cwFinanceInvoiceBase.setProgramName(cwProjectRecords.getProjectName());
|
|
|
+ cwFinanceInvoiceBase.setType("1");
|
|
|
+ cwFinanceInvoiceBase.setContractId(cwProjectRecords.getContractId());
|
|
|
+ cwFinanceInvoiceBase.setContractName(cwProjectRecords.getContractName());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return "项目编号——"+cwFinanceImportDTO.getProjectNo()+"不是当前登录人所创建,请重新填写";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ((StringUtils.isNotBlank(cwFinanceImportDTO.getReportNo()) && StringUtils.isBlank(cwFinanceImportDTO.getProjectNo())) ||(StringUtils.isNotBlank(cwFinanceImportDTO.getReportNo()) && StringUtils.isNotBlank(cwFinanceImportDTO.getProjectNo()))){
|
|
|
+ boolean exist = projectReportList.stream().anyMatch(report -> report.getReportNo().equals(cwFinanceImportDTO.getReportNo()));
|
|
|
+ if (exist){
|
|
|
+ for (CwProjectReportData reportData : projectReportList) {
|
|
|
+ if (reportData.getReportNo().equals(cwFinanceImportDTO.getReportNo())){
|
|
|
+ cwFinanceInvoiceBase.setProgramId(reportData.getId());
|
|
|
+ cwFinanceInvoiceBase.setProgramNo(reportData.getProjectNumber());
|
|
|
+ cwFinanceInvoiceBase.setProgramName(reportData.getProjectName());
|
|
|
+ cwFinanceInvoiceBase.setType("2");
|
|
|
+ cwFinanceInvoiceBase.setContractName(reportData.getContractName());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return "报告号——"+cwFinanceImportDTO.getReportNo()+"不是当前登录人所创建,请重新填写";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开票金额
|
|
|
+ cwFinanceInvoice.setAccount(cwFinanceImportDTO.getBaseAccount());
|
|
|
+ cwFinanceInvoiceBase.setAccount(cwFinanceImportDTO.getBaseAccount());
|
|
|
+ //发票类型
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getType())){
|
|
|
+ for (String key : invoiceTypeValueDTOs.keySet()) {
|
|
|
+ if(cwFinanceImportDTO.getType().equals(key)){
|
|
|
+ cwFinanceInvoice.setType(String.valueOf(invoiceTypeValueDTOs.get(key)));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开票类型
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getBillingType())){
|
|
|
+ for (String key : invoiceBillingTypeValueDTOs.keySet()) {
|
|
|
+ if(cwFinanceImportDTO.getBillingType().equals(key)){
|
|
|
+ cwFinanceInvoice.setBillingType(String.valueOf(invoiceBillingTypeValueDTOs.get(key)));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //实际开票单位
|
|
|
+ if ("企业开票".equals(cwFinanceImportDTO.getBillingType())){
|
|
|
+ for (CwWorkClientBillingDTO cwWorkClientBilling : clientBillingList) {
|
|
|
+ if (cwWorkClientBilling.getCompanyName().equals(cwFinanceImportDTO.getBillingWorkplaceReal())){
|
|
|
+ cwFinanceInvoice.setBillingWorkplaceRealId(cwWorkClientBilling.getClientId());
|
|
|
+ cwFinanceInvoice.setBillingWorkplaceReal(cwWorkClientBilling.getCompanyName());
|
|
|
+ cwFinanceInvoice.setTaxpayerIdentificationNo(cwWorkClientBilling.getTaxpayerIdentificationNo());
|
|
|
+ cwFinanceInvoice.setAddress(cwWorkClientBilling.getAddress());
|
|
|
+ cwFinanceInvoice.setTelPhone(cwWorkClientBilling.getPhone());
|
|
|
+ cwFinanceInvoice.setOpenBank(cwWorkClientBilling.getAccountHolder());
|
|
|
+ cwFinanceInvoice.setBankAccount(cwWorkClientBilling.getAccount());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("个人开票".equals(cwFinanceImportDTO.getBillingType())){
|
|
|
+ cwFinanceInvoice.setName(cwFinanceImportDTO.getBillingWorkplaceReal());
|
|
|
+ cwFinanceInvoice.setTaxpayerIdentificationNo(cwFinanceImportDTO.getTaxpayerIdentificationNo());
|
|
|
+ cwFinanceInvoice.setAddress(cwFinanceImportDTO.getAddress());
|
|
|
+ cwFinanceInvoice.setTelPhone(cwFinanceImportDTO.getTelPhone());
|
|
|
+ cwFinanceInvoice.setOpenBank(cwFinanceImportDTO.getOpenBank());
|
|
|
+ cwFinanceInvoice.setBankAccount(cwFinanceImportDTO.getBankAccount());
|
|
|
+ }
|
|
|
+ //开票内容
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getBillingContent())){
|
|
|
+ for (String key : invoiceBillingContentValueDTOs.keySet()) {
|
|
|
+ if(cwFinanceImportDTO.getBillingContent().equals(key)){
|
|
|
+ cwFinanceInvoice.setBillingContent(String.valueOf(invoiceBillingContentValueDTOs.get(key)));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //开票内容要求
|
|
|
+ cwFinanceInvoice.setBillingContentTerms(cwFinanceImportDTO.getBillingContentTerms());
|
|
|
+ //关联红字发票编号
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getRedInvoiceRelevancyNumber())){
|
|
|
+ for (CwFinanceInvoiceDTO cwFinanceInvoiceDTO : invoiceDTOList) {
|
|
|
+ if (cwFinanceInvoiceDTO.getNo().equals(cwFinanceImportDTO.getRedInvoiceRelevancyNumber().toUpperCase())){
|
|
|
+ cwFinanceInvoice.setRedInvoiceFlag(1);
|
|
|
+ cwFinanceInvoice.setRedInvoiceRelevancyNumber(cwFinanceInvoiceDTO.getNo());
|
|
|
+ cwFinanceInvoice.setRedInvoiceRelevancyId(cwFinanceInvoiceDTO.getId());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //邮箱
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getActualDrawerEmailAddress())){
|
|
|
+ cwFinanceInvoice.setActualDrawerEmailAddress(cwFinanceImportDTO.getActualDrawerEmailAddress());
|
|
|
+ }
|
|
|
+ //实际开票人
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getBillingPeopleRealName())){
|
|
|
+ boolean match = allUserInfo.stream().anyMatch(user -> user.getName().equals(cwFinanceImportDTO.getBillingPeopleRealName()));
|
|
|
+ if (match){
|
|
|
+ Optional<String> matchedUser = allUserInfo.stream()
|
|
|
+ .filter(dto -> dto.getName().equals(cwFinanceImportDTO.getBillingPeopleRealName()))
|
|
|
+ .map(UserDTO::getId)
|
|
|
+ .findFirst();
|
|
|
+ cwFinanceInvoice.setBillingPeopleReal(matchedUser.get());
|
|
|
+ }else {
|
|
|
+ return "实际开票人——"+cwFinanceImportDTO.getBillingPeopleRealName()+"不存在,请重新填写";
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ cwFinanceInvoice.setBillingPeopleReal(userDTO.getId());
|
|
|
+ }
|
|
|
+ //对账人
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getReconciliationPeopleName())){
|
|
|
+ boolean match = allUserInfo.stream().anyMatch(user -> user.getName().equals(cwFinanceImportDTO.getReconciliationPeopleName()));
|
|
|
+ if (match){
|
|
|
+ Optional<String> matchedUser = allUserInfo.stream()
|
|
|
+ .filter(dto -> dto.getName().equals(cwFinanceImportDTO.getReconciliationPeopleName()))
|
|
|
+ .map(UserDTO::getId)
|
|
|
+ .findFirst();
|
|
|
+ cwFinanceInvoice.setReconciliationPeople(matchedUser.get());
|
|
|
+ }else {
|
|
|
+ return "对账人——"+cwFinanceImportDTO.getReconciliationPeopleName()+"不存在,请重新填写";
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ cwFinanceInvoice.setReconciliationPeople(userDTO.getId());
|
|
|
+ }
|
|
|
+ //对账地区
|
|
|
+ if (StringUtils.isNotBlank(cwFinanceImportDTO.getReconciliationArea())){
|
|
|
+ String lastLevelCode = findLastLevelCode(areaDTOList, cwFinanceImportDTO.getReconciliationArea());
|
|
|
+ if (StringUtils.isNotBlank(lastLevelCode)){
|
|
|
+ cwFinanceInvoice.setReconciliationArea(lastLevelCode);
|
|
|
+ }else {
|
|
|
+ return "对账地区——"+cwFinanceImportDTO.getReconciliationArea()+"不正确,请重新填写";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //收款类型
|
|
|
+ cwFinanceInvoice.setReceivablesType("1");
|
|
|
+ cwFinanceInvoice.setIsMultiple("0");
|
|
|
+ cwFinanceInvoice.setStatus("1");
|
|
|
+ cwFinanceInvoice.setCreateById(userDTO.getId());
|
|
|
+ cwFinanceInvoice.setCreateTime(new Date());
|
|
|
+ cwFinanceInvoice.setUpdateById(userDTO.getId());
|
|
|
+ cwFinanceInvoice.setUpdateTime(new Date());
|
|
|
+ cwFinanceInvoice.setTenantId(userDTO.getTenantDTO().getId());
|
|
|
+ cwFinanceInvoice.setDelFlag(0);
|
|
|
+ cwFinanceInvoice.setInvalidStatus("0");
|
|
|
+ cwFinanceInvoice.setReceivablesStatus("0");
|
|
|
+ invoiceArrayList.add(cwFinanceInvoice);
|
|
|
+
|
|
|
+ cwFinanceInvoiceBase.setCreateById(userDTO.getId());
|
|
|
+ cwFinanceInvoiceBase.setCreateTime(new Date());
|
|
|
+ cwFinanceInvoiceBase.setUpdateById(userDTO.getId());
|
|
|
+ cwFinanceInvoiceBase.setUpdateTime(new Date());
|
|
|
+ cwFinanceInvoiceBase.setTenantId(userDTO.getTenantDTO().getId());
|
|
|
+ cwFinanceInvoiceBase.setDelFlag(0);
|
|
|
+ baseArrayList.add(cwFinanceInvoiceBase);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //批量保存
|
|
|
+ if (CollectionUtils.isNotEmpty(invoiceArrayList) && CollectionUtils.isNotEmpty(baseArrayList) ){
|
|
|
+ // 每次最多插入 100 条数据
|
|
|
+ int batchSize = 100;
|
|
|
+ int totalSize = invoiceArrayList.size();
|
|
|
+ int totalSize1 = baseArrayList.size();
|
|
|
+
|
|
|
+ // 按批次处理插入
|
|
|
+ for (int i = 0; i < totalSize; i += batchSize) {
|
|
|
+ // 计算当前批次的结束位置
|
|
|
+ int endIndex = Math.min(i + batchSize, totalSize);
|
|
|
+ // 获取当前批次的子列表
|
|
|
+ List<CwFinanceInvoice> batchList = invoiceArrayList.subList(i, endIndex);
|
|
|
+
|
|
|
+ // 执行批量插入
|
|
|
+ cwFinanceInvoiceMapper.insertBatch(batchList);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < totalSize1; i += batchSize) {
|
|
|
+ // 计算当前批次的结束位置
|
|
|
+ int endIndex = Math.min(i + batchSize, totalSize1);
|
|
|
+ // 获取当前批次的子列表
|
|
|
+ List<CwFinanceInvoiceBase> batchList = baseArrayList.subList(i, endIndex);
|
|
|
+
|
|
|
+ // 执行批量插入
|
|
|
+ cwFinanceInvoiceBaseMapper.insertBatch(batchList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String findLastLevelCode(List<AreaDTO> areaDTOList, String reconciliationArea) {
|
|
|
+ // 按 "-" 拆分层级
|
|
|
+ String[] split = reconciliationArea.split("-");
|
|
|
+
|
|
|
+
|
|
|
+ List<AreaDTO> currentLevelList = areaDTOList;// 当前层级的 AreaDTO 列表
|
|
|
+ AreaDTO matchedArea = null; // 记录最后匹配的 AreaDTO
|
|
|
+
|
|
|
+ for (String name : split) {
|
|
|
+ // 在当前层级查找匹配的 name
|
|
|
+ Optional<AreaDTO> found = currentLevelList.stream()
|
|
|
+ .filter(area -> area.getName().equals(name))
|
|
|
+ .findFirst();
|
|
|
+
|
|
|
+ if (found.isPresent()) {
|
|
|
+ matchedArea = found.get(); // 记录匹配的节点
|
|
|
+ currentLevelList = matchedArea.getChildren(); // 进入子节点列表
|
|
|
+ } else {
|
|
|
+ return null; // 如果找不到,直接返回 null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return matchedArea != null ? matchedArea.getCode() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<AreaDTO> buildTree(List<AreaDTO> areaList) {
|
|
|
+ // 创建一个 Map 来保存 id 到 AreaDTO 的映射
|
|
|
+ Map<String, AreaDTO> areaMap = areaList.stream()
|
|
|
+ .collect(Collectors.toMap(AreaDTO::getId, area -> area));
|
|
|
+
|
|
|
+ // 用来存储树形结构的根节点
|
|
|
+ List<AreaDTO> rootList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (AreaDTO area : areaList) {
|
|
|
+ String parentId = area.getParent().getId();
|
|
|
+ if (parentId.equals("0") || StringUtils.isBlank(parentId)) {
|
|
|
+ // 如果 parentId 为 null 或 0,说明是根节点
|
|
|
+ rootList.add(area);
|
|
|
+ } else {
|
|
|
+ // 否则,把它添加到父节点的 children 列表中
|
|
|
+ AreaDTO parentArea = areaMap.get(parentId);
|
|
|
+ if (parentArea != null) {
|
|
|
+ parentArea.getChildren().add(area);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rootList;
|
|
|
+ }
|
|
|
}
|