|
|
@@ -3,7 +3,7 @@ package com.uas.platform.b2b.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.uas.platform.b2b.constant.StringConstant;
|
|
|
import com.uas.platform.b2b.core.util.BoundedExecutor;
|
|
|
-import com.uas.platform.b2b.core.util.ContextUtils;
|
|
|
+import com.uas.platform.b2b.core.util.ThreadUtils;
|
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
|
import com.uas.platform.b2b.dao.CommunalLogDao;
|
|
|
import com.uas.platform.b2b.dao.EnterpriseDao;
|
|
|
@@ -13,7 +13,6 @@ import com.uas.platform.b2b.dao.PurchaseApCheckDoneDao;
|
|
|
import com.uas.platform.b2b.dao.PurchaseApCheckItemDao;
|
|
|
import com.uas.platform.b2b.dao.PurchaseApCheckTodoDao;
|
|
|
import com.uas.platform.b2b.dao.VendorDao;
|
|
|
-import com.uas.platform.b2b.event.PurchaseApCheckReplyReleaseEvent;
|
|
|
import com.uas.platform.b2b.model.ApCheckTable;
|
|
|
import com.uas.platform.b2b.model.CommunalLog;
|
|
|
import com.uas.platform.b2b.model.DateFilter;
|
|
|
@@ -64,7 +63,6 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
-import java.sql.SQLException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
@@ -76,7 +74,6 @@ import java.util.Set;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
-import java.util.stream.Collector;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
@@ -103,21 +100,6 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
|
|
|
private final static UsageBufferedLogger LOGGER = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
|
|
|
- /**
|
|
|
- * RMB
|
|
|
- */
|
|
|
- private final String RMB = "RMB";
|
|
|
-
|
|
|
- /**
|
|
|
- * 港币
|
|
|
- */
|
|
|
- private final String HKD = "HKD";
|
|
|
-
|
|
|
- /**
|
|
|
- * 美元
|
|
|
- */
|
|
|
- private final String USD = "USD";
|
|
|
-
|
|
|
private final BoundedExecutor executor;
|
|
|
|
|
|
@Autowired
|
|
|
@@ -160,14 +142,28 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
|
|
|
@Override
|
|
|
public void saveApChecks(List<PurchaseApCheckItem> checkItems) {
|
|
|
- if (checkItems != null && checkItems.size() > 0) {
|
|
|
- purchaseApCheckItemDao.save(checkItems);
|
|
|
- List <PurchaseApCheck> apChecks = PurchaseApCheckItem.distinct(checkItems);
|
|
|
+ if (!CollectionUtil.isEmpty(checkItems)) {
|
|
|
+ checkItems = purchaseApCheckItemDao.save(checkItems);
|
|
|
+ List<PurchaseApCheck> apChecks = PurchaseApCheckItem.distinct(checkItems);
|
|
|
saveUserOrders(apChecks);
|
|
|
- ContextUtils.publishEvent(new PurchaseApCheckReplyReleaseEvent(apChecks));
|
|
|
+ Set<Long> needRestoreIdList = checkItems.stream()
|
|
|
+ .filter(item -> Status.NOTAGREED.getPhrase().equals(item.getApCheck().getCheckStatus()))
|
|
|
+ .map(item -> item.getApCheck().getId())
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ restoreApCheckQty(needRestoreIdList);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 针对客户不同意单据,自动还原,不需要供应商这边处理
|
|
|
+ *
|
|
|
+ * @param needRestoreIdList 需要处理的对账单的id
|
|
|
+ */
|
|
|
+ private void restoreApCheckQty(Set<Long> needRestoreIdList) {
|
|
|
+ LOGGER.log("ERP不同意对账作废应收对账单", "关联id:" + needRestoreIdList);
|
|
|
+ ThreadUtils.task(() -> needRestoreIdList.forEach(this::cancelApCheck)).run();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成消息红点
|
|
|
*
|
|
|
@@ -183,56 +179,18 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean cancelApcheck(Long id) {
|
|
|
+ public boolean cancelApCheck(Long id) {
|
|
|
PurchaseApCheck check = purchaseApCheckDao.findOne(id);
|
|
|
if (check != null) {
|
|
|
- if (!CollectionUtils.isEmpty(check.getItems()) && check.getCheckStatus().equals("不同意")) {
|
|
|
- List<String> sqls = new ArrayList<>();
|
|
|
- for (PurchaseApCheckItem item : check.getItems()) {
|
|
|
- item.setCheckQty(0.0);
|
|
|
- Double newYCheckQtyVal = item.getOldYCheckQty();
|
|
|
- Long sourceIdVal = item.getSourceId();
|
|
|
- String sourceTable = null;
|
|
|
- String idName = null;
|
|
|
- String yCheckQtyName = null;
|
|
|
- if (item.getSourceTable() != null) {
|
|
|
- sourceTable = item.getSourceTable();
|
|
|
- } else {
|
|
|
- sourceTable = "";
|
|
|
- }
|
|
|
- if (sourceTable.equals("purc$returnitem")) {
|
|
|
- idName = "pri_id";
|
|
|
- yCheckQtyName = "pri_ycheckqty";
|
|
|
- } else if (sourceTable.equals("purc$acceptitem")) {
|
|
|
- idName = "pai_id";
|
|
|
- yCheckQtyName = "pai_ycheckqty";
|
|
|
- } else if (sourceTable.equals("purc$badinitem")) {
|
|
|
- idName = "pbi_id";
|
|
|
- yCheckQtyName = "pbi_ycheckqty";
|
|
|
- } else if (sourceTable.equals("purc$badoutitem")) {
|
|
|
- idName = "poi_id";
|
|
|
- yCheckQtyName = "poi_ycheckqty";
|
|
|
- } else if (sourceTable.equals("make$acceptitem")) {
|
|
|
- idName = "mai_id";
|
|
|
- yCheckQtyName = "mai_ycheckqty";
|
|
|
- } else if (sourceTable.equals("make$returnitem")) {
|
|
|
- idName = "mri_id";
|
|
|
- yCheckQtyName = "mri_ycheckqty";
|
|
|
- } else if (sourceTable.equals("purc$apbilladjustment")) {
|
|
|
- idName = "aa_id";
|
|
|
- yCheckQtyName = "aa_ycheckqty";
|
|
|
- }
|
|
|
- String sql = "update " + sourceTable + " set " + yCheckQtyName + " = " + newYCheckQtyVal + " where "
|
|
|
- + idName + " = " + sourceIdVal;
|
|
|
- sqls.add(sql);
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(sqls)) {
|
|
|
- try {
|
|
|
- commonDao.getJdbcTemplate().batchUpdate(sqls.toArray(new String[sqls.size()]));
|
|
|
- } catch (RuntimeException e) {
|
|
|
- System.out.println("生成对账单批量更新来源数据失败: " + e.getMessage());
|
|
|
- throw new IllegalOperatorException("保存失败!");
|
|
|
- }
|
|
|
+ List<SourceForApcheck> sources = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(check.getItems()) && Status.NOTAGREED.getPhrase().equals(check.getCheckStatus())) {
|
|
|
+ check.getItems().forEach(item -> {
|
|
|
+ item.setCheckQty(0.0);
|
|
|
+ SourceForApcheck source = new SourceForApcheck(item);
|
|
|
+ sources.add(source);
|
|
|
+ });
|
|
|
+ if (!CollectionUtil.isEmpty(sources)) {
|
|
|
+ updateSourceInfo(sources, "ERP上传不同意单据同步更新对账单");
|
|
|
}
|
|
|
}
|
|
|
check.setCheckStatus("已作废");
|
|
|
@@ -364,7 +322,7 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
SourceForApcheck source = new SourceForApcheck(item);
|
|
|
sources.add(source);
|
|
|
}
|
|
|
- updateSourceInfo(sources);
|
|
|
+ updateSourceInfo(sources, "生成对账单批量更新来源数据");
|
|
|
saveCheckItemsByJdbcTemplate(purchaseApCheck.getItems(), apCheck.getId());
|
|
|
List<PurchaseApCheck> apChecks = new ArrayList<>();
|
|
|
purchaseApCheck.setId(apCheck.getId());
|
|
|
@@ -426,9 +384,10 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
* 更新来源表数据
|
|
|
*
|
|
|
* @param sourceApCheckList 来源库信息
|
|
|
+ * @param path 路径
|
|
|
* @return 保存结果
|
|
|
*/
|
|
|
- public void updateSourceInfo(List<SourceForApcheck> sourceApCheckList) {
|
|
|
+ public void updateSourceInfo(List<SourceForApcheck> sourceApCheckList, String path) {
|
|
|
if (CollectionUtils.isEmpty(sourceApCheckList)) {
|
|
|
throw new IllegalOperatorException("保存失败!");
|
|
|
}
|
|
|
@@ -445,7 +404,7 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
try {
|
|
|
commonDao.getJdbcTemplate().batchUpdate(sqlList.toArray(new String[sqlList.size()]));
|
|
|
} catch (RuntimeException e) {
|
|
|
- System.out.println("生成对账单批量更新来源数据失败: " + e.getMessage());
|
|
|
+ System.out.println(path + "失败: " + e.getMessage());
|
|
|
throw new IllegalOperatorException("保存失败!");
|
|
|
}
|
|
|
}
|