|
@@ -30,10 +30,7 @@ import com.jzg.commons.util.*;
|
|
|
import com.jzg.commons.util.idgen.IdGenerate;
|
|
import com.jzg.commons.util.idgen.IdGenerate;
|
|
|
import com.jzg.organization.client.EsmInsCompanyClient;
|
|
import com.jzg.organization.client.EsmInsCompanyClient;
|
|
|
import com.jzg.organization.client.InsFeeOrdersClient;
|
|
import com.jzg.organization.client.InsFeeOrdersClient;
|
|
|
-import com.jzg.organization.excel.listener.JyExcelListener;
|
|
|
|
|
-import com.jzg.organization.excel.listener.OtherExcelListener;
|
|
|
|
|
-import com.jzg.organization.excel.listener.ReceivbleExcelListener;
|
|
|
|
|
-import com.jzg.organization.excel.listener.SuperviseExcelListener;
|
|
|
|
|
|
|
+import com.jzg.organization.excel.listener.*;
|
|
|
import com.jzg.organization.mapper.*;
|
|
import com.jzg.organization.mapper.*;
|
|
|
import com.jzg.organization.service.ReceivableService;
|
|
import com.jzg.organization.service.ReceivableService;
|
|
|
import com.jzg.organization.service.SysUserJzgInfoSalesmanService;
|
|
import com.jzg.organization.service.SysUserJzgInfoSalesmanService;
|
|
@@ -1014,6 +1011,185 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
return importExcelResultVo;
|
|
return importExcelResultVo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导出应收开票模板
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String exportAccountsReceivableInvoiceTemplate() {
|
|
|
|
|
+ List<InvoiceReceivableExportExcelVo> emptyList = ListUtil.empty();
|
|
|
|
|
+
|
|
|
|
|
+ // 调用动态导出
|
|
|
|
|
+ return exportBaseService.upLoadFile(
|
|
|
|
|
+ InvoiceReceivableExportExcelVo.class,
|
|
|
|
|
+ emptyList,
|
|
|
|
|
+ "应收开票-导出模板-" + Instant.now()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ImportUpdateExcelResultVo importAccountsReceivableInvoice(MultipartFile file) {
|
|
|
|
|
+ String userName = baseController.getUserName();
|
|
|
|
|
+ log.info("用户[{}]导入平台协议文件",userName);
|
|
|
|
|
+ ImportUpdateExcelResultVo importExcelResultVo = new ImportUpdateExcelResultVo();
|
|
|
|
|
+ List<InvoiceReceivableExportExcelVo> receivableExportExcelVos = importInvoiceReceivableExcel(file);
|
|
|
|
|
+ if (CollUtil.isEmpty(receivableExportExcelVos)){
|
|
|
|
|
+ throw new SystemException("数据不能为空,导入失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ AssertionUtils.isEmpty(receivableExportExcelVos, "数据处理失败,导入失败");
|
|
|
|
|
+ // 获取保司名称
|
|
|
|
|
+ HttpResult<List<EsmInsCompany>> listHttpResult = esmInsCompanyClient.liveCompanyList();
|
|
|
|
|
+ AssertionUtils.isFail(listHttpResult.getCode() != 200, listHttpResult.getMsg());
|
|
|
|
|
+
|
|
|
|
|
+ int failedNumber = 0;
|
|
|
|
|
+ List<InvoiceReceivableExportExcelVo> failedExcel = new ArrayList<>();
|
|
|
|
|
+ // 只存储需要【修改】的数据
|
|
|
|
|
+ List<InsPlyIncome> updateExcel = new ArrayList<>();
|
|
|
|
|
+ List<InsPlyIncome> insertExcel = new ArrayList<>();
|
|
|
|
|
+ // 存储导入成功的订单号
|
|
|
|
|
+ List<String> successOrderNoList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ // 校验Excel内部保单号重复
|
|
|
|
|
+ Set<String> existPolicyNoSet = new HashSet<>();
|
|
|
|
|
+ Set<String> repeatPolicyNoSet = new HashSet<>();
|
|
|
|
|
+ Set<String> existCompanyIdSet = new HashSet<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (InvoiceReceivableExportExcelVo vo : receivableExportExcelVos) {
|
|
|
|
|
+ String policyNo = vo.getJqPolicyNo();
|
|
|
|
|
+ if (existPolicyNoSet.contains(policyNo)) {
|
|
|
|
|
+ repeatPolicyNoSet.add(policyNo);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ existPolicyNoSet.add(policyNo);
|
|
|
|
|
+ }
|
|
|
|
|
+ existCompanyIdSet.add(vo.getCompanyId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 导入只能一个保司
|
|
|
|
|
+ if (existCompanyIdSet.size() > 1) {
|
|
|
|
|
+ throw new SystemException("导入数据不能包含多个保险公司");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 处理数据
|
|
|
|
|
+ for (InvoiceReceivableExportExcelVo vo : receivableExportExcelVos) {
|
|
|
|
|
+ // 1. 空数据校验
|
|
|
|
|
+ ImportResultVo resultVo = vo.checkEmpty();
|
|
|
|
|
+ if (!resultVo.isSuccess()) {
|
|
|
|
|
+ failedNumber++;
|
|
|
|
|
+ vo.setErrorMessage(resultVo.getMessage());
|
|
|
|
|
+ failedExcel.add(vo);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. Excel内部保单号重复
|
|
|
|
|
+ if (repeatPolicyNoSet.contains(vo.getJqPolicyNo())) {
|
|
|
|
|
+ failedNumber++;
|
|
|
|
|
+ vo.setErrorMessage("保单号重复");
|
|
|
|
|
+ failedExcel.add(vo);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询数据库中是否已存在该协议
|
|
|
|
|
+ PtlAgreement ptlAgreement = ptlAgreementMapper.selectOne(new LambdaQueryWrapper<PtlAgreement>()
|
|
|
|
|
+ .eq(PtlAgreement::getAgreementCode, vo.getAgreementCode()));
|
|
|
|
|
+
|
|
|
|
|
+ // 数据库不存在 → 直接失败
|
|
|
|
|
+ if (Objects.isNull(ptlAgreement)) {
|
|
|
|
|
+ failedNumber++;
|
|
|
|
|
+ vo.setErrorMessage("协议编码在协议中不存在");
|
|
|
|
|
+ failedExcel.add(vo);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询数据库中是否已存在该保单号
|
|
|
|
|
+ InsPlyIncome existIncome = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
|
|
+ .eq(InsPlyIncome::getJqPolicyNo, vo.getJqPolicyNo()));
|
|
|
|
|
+
|
|
|
|
|
+ // 封装修改数据
|
|
|
|
|
+ InsPlyIncome insPlyIncome = new InsPlyIncome();
|
|
|
|
|
+ insPlyIncome.setId(IdGenerate.nextId());
|
|
|
|
|
+ insPlyIncome.setLicenseNo(vo.getLicenseNo());
|
|
|
|
|
+ insPlyIncome.setJqPolicyNo(vo.getJqPolicyNo());
|
|
|
|
|
+ insPlyIncome.setJqSuperviseCostsProportion(vo.getJqSuperviseCostsProportion());
|
|
|
|
|
+ insPlyIncome.setJqOtherCostsProportion(vo.getJqOtherCostsProportion());
|
|
|
|
|
+ insPlyIncome.setSyPolicyNo(vo.getSyPolicyNo());
|
|
|
|
|
+ insPlyIncome.setSySuperviseCostsProportion(vo.getSySuperviseCostsProportion());
|
|
|
|
|
+ insPlyIncome.setSyOtherCostsProportion(vo.getSyOtherCostsProportion());
|
|
|
|
|
+ insPlyIncome.setJyPolicyNo(vo.getJyPolicyNo());
|
|
|
|
|
+ insPlyIncome.setJySuperviseCostsProportion(vo.getJySuperviseCostsProportion());
|
|
|
|
|
+ insPlyIncome.setJyOtherCostsProportion(vo.getJyOtherCostsProportion());
|
|
|
|
|
+ // 签单时间
|
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ insPlyIncome.setSigningTime(LocalDateTime.parse(vo.getSigningTime(), formatter));
|
|
|
|
|
+ // 协议编号
|
|
|
|
|
+ insPlyIncome.setAgreementId(ptlAgreement.getId());
|
|
|
|
|
+ insPlyIncome.setAgreementName(ptlAgreement.getAgreementName());
|
|
|
|
|
+ insPlyIncome.setAgreementType(ptlAgreement.getAgreementType().toString());
|
|
|
|
|
+ // 险种编号
|
|
|
|
|
+ insPlyIncome.setProductId(vo.getProductId());
|
|
|
|
|
+ // 险种名称
|
|
|
|
|
+ insPlyIncome.setProductName(vo.getProductName());
|
|
|
|
|
+ // 被保险人姓名
|
|
|
|
|
+ insPlyIncome.setInsuredPerson(vo.getInsuredPerson());
|
|
|
|
|
+
|
|
|
|
|
+ // 数据库不存在 → 直接失败
|
|
|
|
|
+ if (Objects.isNull(existIncome)) {
|
|
|
|
|
+ // 加入修改列表
|
|
|
|
|
+ // 机构id
|
|
|
|
|
+ insPlyIncome.setDeptId(baseController.getUserDeptId());
|
|
|
|
|
+ insPlyIncome.setCompanyId(vo.getCompanyId());
|
|
|
|
|
+ insPlyIncome.setOrderNo(vo.getOrderNo());
|
|
|
|
|
+ insertExcel.add(insPlyIncome);
|
|
|
|
|
+ // 新增成功,记录订单号
|
|
|
|
|
+ successOrderNoList.add(vo.getOrderNo());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // 数据库已存在 → 继续后续校验
|
|
|
|
|
+ // 判断已开票 / 已结算
|
|
|
|
|
+ String settlementFlag = "1";
|
|
|
|
|
+ if (settlementFlag.equals(existIncome.getSuperviseSettlement()) || settlementFlag.equals(existIncome.getOtherSettlement())
|
|
|
|
|
+ || settlementFlag.equals(existIncome.getJySuperviseSettlement()) || settlementFlag.equals(existIncome.getJyOtherSettlement())
|
|
|
|
|
+ || settlementFlag.equals(existIncome.getPlatformSuperviseSettlement()) || settlementFlag.equals(existIncome.getPlatformOtherSettlement())) {
|
|
|
|
|
+ failedNumber++;
|
|
|
|
|
+ vo.setErrorMessage("应收数据已结算");
|
|
|
|
|
+ failedExcel.add(vo);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ insPlyIncome.setId(existIncome.getId());
|
|
|
|
|
+ // 加入修改列表
|
|
|
|
|
+ updateExcel.add(insPlyIncome);
|
|
|
|
|
+ // 更新成功,记录订单号
|
|
|
|
|
+ successOrderNoList.add(vo.getOrderNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 执行批量更新
|
|
|
|
|
+ if (CollUtil.isNotEmpty(updateExcel)) {
|
|
|
|
|
+ baseMapper.updateById(updateExcel);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ baseMapper.insert(insertExcel);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ===================== 生成失败数据下载链接 =====================
|
|
|
|
|
+ String failFileUrl = "";
|
|
|
|
|
+ if (CollUtil.isNotEmpty(failedExcel)) {
|
|
|
|
|
+ failFileUrl = exportBaseService.upLoadFile(
|
|
|
|
|
+ InvoiceReceivableExportExcelVo.class,
|
|
|
|
|
+ failedExcel,
|
|
|
|
|
+ "平台协议应收-导入失败-" + Instant.now()
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 返回结果
|
|
|
|
|
+ importExcelResultVo.setFailedData(failedExcel);
|
|
|
|
|
+ importExcelResultVo.setFailFileUrl(failFileUrl);
|
|
|
|
|
+ importExcelResultVo.setSuccessNumber(CollUtil.isNotEmpty(updateExcel) ? updateExcel.size() : insertExcel.size());
|
|
|
|
|
+ importExcelResultVo.setFailedNumber(failedNumber);
|
|
|
|
|
+ // 导出成功的orderNos
|
|
|
|
|
+ importExcelResultVo.setOrderNos(successOrderNoList);
|
|
|
|
|
+
|
|
|
|
|
+ return importExcelResultVo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -1133,6 +1309,20 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public List<InvoiceReceivableExportExcelVo> importInvoiceReceivableExcel(MultipartFile file) {
|
|
|
|
|
+ InvoiceReceivbleExcelListener listener = new InvoiceReceivbleExcelListener();
|
|
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
|
|
+ EasyExcel.read(inputStream, InvoiceReceivableExportExcelVo.class, listener)
|
|
|
|
|
+ .sheet()
|
|
|
|
|
+ .doRead();
|
|
|
|
|
+ List<InvoiceReceivableExportExcelVo> dataList = listener.getDataList();
|
|
|
|
|
+ return dataList;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public List<JyExcelVo> importJyExcel(MultipartFile file) {
|
|
public List<JyExcelVo> importJyExcel(MultipartFile file) {
|
|
|
JyExcelListener listener = new JyExcelListener();
|
|
JyExcelListener listener = new JyExcelListener();
|