|
|
@@ -72,7 +72,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Pattern;
|
|
|
@@ -4347,7 +4349,7 @@ public class WorkInvoiceService extends CrudService<WorkInvoiceDao, WorkInvoice>
|
|
|
HashMap<String,Object> result = null;
|
|
|
try{
|
|
|
//调用工具类返回结果
|
|
|
- result = ALiYunSmsUtil.omsWorkInvoiceSuccessSms(user.getMobile(), workInvoice.getNumber());
|
|
|
+ result = ALiYunSmsUtil.omsWorkInvoiceSms(user.getMobile(), workInvoice.getNumber(), "成功");
|
|
|
Integer statusCode = (Integer) result.get("statusCode");
|
|
|
if (200 == statusCode) {
|
|
|
System.out.println("进入获取密码修改短信通知接口2。获取阿里云短信通知成功");
|
|
|
@@ -4529,7 +4531,7 @@ public class WorkInvoiceService extends CrudService<WorkInvoiceDao, WorkInvoice>
|
|
|
HashMap<String,Object> result = null;
|
|
|
try{
|
|
|
//调用工具类返回结果
|
|
|
- result = ALiYunSmsUtil.omsWorkInvoiceErrorSms(cwuser.getMobile(), workInvoice.getNumber());
|
|
|
+ result = ALiYunSmsUtil.omsWorkInvoiceSms(cwuser.getMobile(), workInvoice.getNumber(), "失败");
|
|
|
Integer statusCode = (Integer) result.get("statusCode");
|
|
|
if (200 == statusCode) {
|
|
|
System.out.println("进入获取密码修改短信通知接口2。获取阿里云短信通知成功");
|
|
|
@@ -4580,13 +4582,14 @@ public class WorkInvoiceService extends CrudService<WorkInvoiceDao, WorkInvoice>
|
|
|
|
|
|
//查询开票人员的手机号
|
|
|
User user = userDao.get(workInvoice.getCreateBy().getId());
|
|
|
+ //user.setMobile("18164266544");
|
|
|
if (StringUtils.isNotBlank(user.getMobile()) && mobilePattern.matcher(user.getMobile().trim()).matches() ) {
|
|
|
//验证手机号是否已经注册
|
|
|
if(userDao.validateMobile("mobile") == null){
|
|
|
HashMap<String,Object> result = null;
|
|
|
try{
|
|
|
//调用工具类返回结果
|
|
|
- result = ALiYunSmsUtil.omsWorkInvoiceErrorSms(user.getMobile(), workInvoice.getNumber());
|
|
|
+ result = ALiYunSmsUtil.omsWorkInvoiceSms(user.getMobile(), workInvoice.getNumber(), "失败");
|
|
|
Integer statusCode = (Integer) result.get("statusCode");
|
|
|
if (200 == statusCode) {
|
|
|
System.out.println("进入获取密码修改短信通知接口2。获取阿里云短信通知成功");
|
|
|
@@ -4647,6 +4650,7 @@ public class WorkInvoiceService extends CrudService<WorkInvoiceDao, WorkInvoice>
|
|
|
/**
|
|
|
* 查询同项目名称、价格、材料名称的数量是否只有一个
|
|
|
*/
|
|
|
+ @Transactional(readOnly = false)
|
|
|
public Map<String, List<WorkInvoiceReceiptInfo>> distinctProjectMaterialStorage(
|
|
|
List<WorkInvoiceReceiptInfo> workInvoiceReceiptInfo) {
|
|
|
|
|
|
@@ -4656,6 +4660,9 @@ public class WorkInvoiceService extends CrudService<WorkInvoiceDao, WorkInvoice>
|
|
|
Set<String> seen = new HashSet<>();
|
|
|
List<WorkInvoiceReceiptInfo> uniqueList = new ArrayList<>(); // 本次去重后的有效值
|
|
|
List<WorkInvoiceReceiptInfo> duplicateList = new ArrayList<>(); // 本次自身重复值
|
|
|
+ List<WorkInvoiceReceiptInfo> alreadyExistList = new ArrayList<>(); // 已经有收款信息的数据
|
|
|
+ List<WorkInvoiceReceiptInfo> inexistenceList = new ArrayList<>(); // 数据表中不存在的的数据
|
|
|
+ List<WorkInvoiceReceiptInfo> moneyMismatchingList = new ArrayList<>(); // 数据表中金额大于开票价的的数据
|
|
|
|
|
|
for (WorkInvoiceReceiptInfo item : workInvoiceReceiptInfo) {
|
|
|
String distinctStr = item.getDistinctStr();
|
|
|
@@ -4683,70 +4690,133 @@ public class WorkInvoiceService extends CrudService<WorkInvoiceDao, WorkInvoice>
|
|
|
List<WorkInvoiceReceipt> alreadyExistReceiptList = workInvoiceReceiptDao.getByInvoiceNumber(invoiceNumberList);
|
|
|
|
|
|
//遍历有效值和查出来的已经存在的收款信息进行对比,若存在同一发票号的信息,金额进行累加,若金额大于应收金额,则表示该条数据存在问题,所小于则表示部分收款,若等于 则表示完全收款,改成已收款
|
|
|
+ // 迭代器方式:内层循环安全删除
|
|
|
for (WorkInvoiceReceipt workInvoiceReceipt : alreadyExistReceiptList) {
|
|
|
- for (WorkInvoiceReceiptInfo invoiceReceiptInfo : uniqueList) {
|
|
|
- if(workInvoiceReceipt.getInvoiceNumber().equals(invoiceReceiptInfo.getInvoiceNumber())){
|
|
|
+ // 内层用迭代器遍历uniqueList,支持安全删除
|
|
|
+ Iterator<WorkInvoiceReceiptInfo> iterator = uniqueList.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ WorkInvoiceReceiptInfo invoiceReceiptInfo = iterator.next();
|
|
|
+ if (workInvoiceReceipt.getInvoiceNumber().equals(invoiceReceiptInfo.getInvoiceNumber())) {
|
|
|
+ alreadyExistList.add(invoiceReceiptInfo); // 加入待处理列表
|
|
|
+ invoiceReceiptInfo.setInvoiceId(workInvoiceReceipt.getInvoiceId());
|
|
|
+ iterator.remove(); // 迭代器安全删除,不会触发并发修改异常
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ //对剩下的有效数据进行处理
|
|
|
+ //判定金额和开票额是否一致,若一致,则表示全部收款,若小于开票额,表示部分收款,若大于,应当是填写错误,进行抛出,不进行导入
|
|
|
+ invoiceNumberList = Lists.newArrayList();
|
|
|
+ for (WorkInvoiceReceiptInfo invoiceReceiptInfo : uniqueList) {
|
|
|
+ invoiceNumberList.add(invoiceReceiptInfo.getInvoiceNumber());
|
|
|
+ }
|
|
|
+ //根据 invoiceNumberList 去进行查询已经存在的数据信息
|
|
|
+ List<WorkInvoiceDetail> invoiceDetailList = workInvoiceDetailDao.getInvoiceDetailByNumber(invoiceNumberList);
|
|
|
+ for (WorkInvoiceDetail workInvoiceDetail : invoiceDetailList) {
|
|
|
+ for (WorkInvoiceReceiptInfo info : uniqueList) {
|
|
|
+ if(workInvoiceDetail.getNumber().equals(info.getInvoiceNumber())){
|
|
|
+ info.setInvoiceId(workInvoiceDetail.getInvoiceId());
|
|
|
}
|
|
|
- invoiceNumberList.add(invoiceReceiptInfo.getInvoiceNumber());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //如果两者数据量不同,说明 要么发票号错误,要么该发票没有录入,需要抛出,其余的再进行比较金额
|
|
|
+ if(invoiceDetailList.size() != uniqueList.size()){
|
|
|
+ //将invoiceDetailList 和uniqueList 进行对比,如果uniqueList中存在 但是 invoiceDetailList 不存在,则就要将这个值从uniqueList删除并写入到 inexistenceList中
|
|
|
|
|
|
- // 第二步:获取历史数据并处理其distinctStr
|
|
|
- /*List<WorkInvoiceReceiptInfo> historyInfoList = dao.getByProjectId(projectId);
|
|
|
- for (WorkInvoiceReceiptInfo info : historyInfoList) {
|
|
|
- // 组合历史数据的distinctStr(材料名称+规格+含税价格)
|
|
|
- // 处理可能的null值,转为空字符串
|
|
|
- String invoiceName = (info.getInvoiceNumber() != null) ? info.getInvoiceNumber() : "";
|
|
|
- String buyerName = (info.getBuyerName() != null) ? info.getBuyerName() : "";
|
|
|
- String money = (info.getMoney() != null) ? info.getMoney().toString() : "";
|
|
|
- // 以逗号分隔组合
|
|
|
- String resultStr = invoiceName + "," + buyerName + "," + money;
|
|
|
+ // 1. 提取invoiceDetailList中所有发票号存入Set,用于O(1)快速判断是否存在(核心优化)
|
|
|
+ Set<String> detailInvoiceNumberSet = new HashSet<>();
|
|
|
+ for (WorkInvoiceDetail detail : invoiceDetailList) {
|
|
|
+ detailInvoiceNumberSet.add(detail.getNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 迭代器遍历uniqueList,安全删除+收集不存在的元素(避免ConcurrentModificationException)
|
|
|
+ Iterator<WorkInvoiceReceiptInfo> iterator = uniqueList.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ WorkInvoiceReceiptInfo uniqueInfo = iterator.next();
|
|
|
+ String uniqueInvoiceNo = uniqueInfo.getInvoiceNumber();
|
|
|
+ // 判断:uniqueList的发票号 在invoiceDetailList中不存在
|
|
|
+ if (!detailInvoiceNumberSet.contains(uniqueInvoiceNo)) {
|
|
|
+ inexistenceList.add(uniqueInfo); // 加入不存在的列表
|
|
|
+ iterator.remove(); // 迭代器安全删除,不会触发并发修改异常
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ //到此处 说明数据已经匹配几乎完成,现在还需要对有效的参数的金额进行匹配
|
|
|
+ for (WorkInvoiceDetail workInvoiceDetail : invoiceDetailList) {
|
|
|
+ for (WorkInvoiceReceiptInfo unique : uniqueList) {
|
|
|
+ if(workInvoiceDetail.getNumber().equals(unique.getInvoiceNumber())){
|
|
|
+ //判定金额是否相同,小于为-1 相同为0 大于为1
|
|
|
+ String totalMoney = workInvoiceDetail.getTotalMoney();
|
|
|
+ String money = unique.getMoney();
|
|
|
+ BigDecimal totalMoneyB = new BigDecimal(totalMoney);
|
|
|
+ BigDecimal moneyB = new BigDecimal(money);
|
|
|
+ // 核心比较:直接得到-1/0/1的结果
|
|
|
+ int compareResult = moneyB.compareTo(totalMoneyB);
|
|
|
+ // 后续可根据结果做业务处理
|
|
|
+ if (compareResult == 1) {
|
|
|
+ // totalMoney 小于 money 业务逻辑
|
|
|
+ //说明新导入的额度要大于开票额度
|
|
|
+ unique.setMoneyFlag(1);
|
|
|
+ } else if (compareResult == 0) {
|
|
|
+ // 金额相等 业务逻辑
|
|
|
+ //说明金额相等
|
|
|
+ unique.setMoneyFlag(0);
|
|
|
+ } else {
|
|
|
+ // totalMoney 大于 money 业务逻辑
|
|
|
+ //说明部分收款
|
|
|
+ unique.setMoneyFlag(-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 第三步:筛选历史数据中的distinctStr,用于比对
|
|
|
- Set<String> historyDistinctSet = new HashSet<>();
|
|
|
- for (WorkInvoiceReceiptInfo historyItem : historyInfoList) {
|
|
|
- String historyDistinctStr = historyItem.getDistinctStr();
|
|
|
- if (historyDistinctStr != null) {
|
|
|
- historyDistinctSet.add(historyDistinctStr);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 第四步:从uniqueList中移除与历史数据重复的项,并加入重复列表
|
|
|
- // 使用迭代器支持边遍历边删除
|
|
|
+ //对处理完的数据进行区分,大于1的值不能进行导入,需要剔除
|
|
|
Iterator<WorkInvoiceReceiptInfo> iterator = uniqueList.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
- WorkInvoiceReceiptInfo currentItem = iterator.next();
|
|
|
- String currentDistinctStr = currentItem.getDistinctStr();
|
|
|
-
|
|
|
- // 处理null值(从uniqueList移除并加入重复列表)
|
|
|
- if (currentDistinctStr == null) {
|
|
|
- iterator.remove();
|
|
|
- duplicateList.add(currentItem);
|
|
|
- continue;
|
|
|
+ WorkInvoiceReceiptInfo info = iterator.next();
|
|
|
+ // 判定moneyFlag为1(导入金额超开票金额),剔除并收集
|
|
|
+ if (info.getMoneyFlag() == 1) {
|
|
|
+ moneyMismatchingList.add(info); // 加入无效数据列表
|
|
|
+ iterator.remove(); // 从有效列表uniqueList中安全删除
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ //此处可以对剩余的数据进行处理了
|
|
|
|
|
|
- // 与历史数据重复:从uniqueList移除并加入重复列表
|
|
|
- if (historyDistinctSet.contains(currentDistinctStr)) {
|
|
|
- iterator.remove();
|
|
|
- duplicateList.add(currentItem);
|
|
|
+ List<WorkInvoiceReceipt> insertReceiptList = Lists.newArrayList();
|
|
|
+ for (WorkInvoiceReceiptInfo info : uniqueList) {
|
|
|
+ if (info.getMoneyFlag() == 0) {
|
|
|
+ info.setReceiptMoneyDate(new Date());
|
|
|
+ info.setReceiptMoney(1);
|
|
|
+ } else if(info.getMoneyFlag() == -1){
|
|
|
+ info.setReceiptMoney(2);
|
|
|
}
|
|
|
+ WorkInvoiceReceipt insertReceipt = new WorkInvoiceReceipt();
|
|
|
+ insertReceipt.setInvoiceId(info.getInvoiceId());
|
|
|
+ String dateStr = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
|
+ .withZone(ZoneId.systemDefault())
|
|
|
+ .format(Instant.ofEpochMilli(new Date().getTime()));
|
|
|
+ insertReceipt.setReceiptDate(dateStr);
|
|
|
+ insertReceipt.setCompanyName(info.getBuyerName());
|
|
|
+ insertReceipt.setMoney(Double.valueOf(info.getMoney()));
|
|
|
+ insertReceipt.preInsert();
|
|
|
+ insertReceiptList.add(insertReceipt);
|
|
|
}
|
|
|
+ //将收款信息添加到数据库中
|
|
|
+ workInvoiceReceiptDao.batchInsert(insertReceiptList);
|
|
|
+ //修改work_invoice表中 receipt_money_date 和 receipt_money 参数信息
|
|
|
+ dao.batchUpdateByForeach(uniqueList);
|
|
|
+
|
|
|
|
|
|
- // 1. 提取duplicateList中所有数据的唯一标识(distinctStr)
|
|
|
- Set<String> duplicateDistinctSet = new HashSet<>();
|
|
|
- for (WorkInvoiceReceiptInfo item : duplicateList) {
|
|
|
- String distinctStr = item.getDistinctStr();
|
|
|
- if (distinctStr != null) {
|
|
|
- duplicateDistinctSet.add(distinctStr);
|
|
|
- }
|
|
|
- }*/
|
|
|
|
|
|
// 最终返回处理后的列表
|
|
|
map.put("uniqueList", uniqueList); // 仅包含本次新增且不与历史重复的数据
|
|
|
map.put("duplicateList", duplicateList); // 包含自身重复和与历史重复的数据
|
|
|
+ map.put("alreadyExistList", alreadyExistList); // 已经有收款信息的数据
|
|
|
+ map.put("inexistenceList", inexistenceList); // 数据表中不存在的的数据 invoiceDetail 表中不存在,也就是说 没有开票信息
|
|
|
+ map.put("moneyMismatchingList", moneyMismatchingList); // 数据表中金额大于开票价的的数据
|
|
|
return map;
|
|
|
}
|
|
|
}
|