Browse Source

货款调账数据传输异常处理

hejq 7 years ago
parent
commit
0840a1831d

+ 5 - 5
src/main/java/com/uas/platform/b2b/erp/controller/PurchaseAPBillController.java

@@ -4,7 +4,7 @@ import com.uas.platform.b2b.erp.model.PurchaseAPBill;
 import com.uas.platform.b2b.erp.service.PurchaseAPBillService;
 import com.uas.platform.b2b.erp.support.ErpBufferedLogger;
 import com.uas.platform.b2b.model.ApbillAdjustment;
-import com.uas.platform.b2b.service.ApbillAdjustmentService;
+import com.uas.platform.b2b.service.ApBillAdjustmentService;
 import com.uas.platform.b2b.service.PurchaseApBillService;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import com.uas.platform.core.util.serializer.FlexJsonUtils;
@@ -15,8 +15,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
+import java.io.*;
+import java.net.*;
 import java.util.List;
 
 /**
@@ -37,7 +37,7 @@ public class PurchaseAPBillController {
 	private PurchaseAPBillService purchaseAPBillService;
 
 	@Autowired
-	private ApbillAdjustmentService apbillAdjustmentService;
+	private ApBillAdjustmentService apbillAdjustmentService;
 
 	private final static ErpBufferedLogger logger = BufferedLoggerManager.getLogger(ErpBufferedLogger.class);
 
@@ -103,6 +103,6 @@ public class PurchaseAPBillController {
 	public void nonPostAdjustment(@RequestParam("data") String data) throws UnsupportedEncodingException {
 		String jsonStr = URLDecoder.decode(data, "UTF-8");
 		List<PurchaseAPBill> apBills = FlexJsonUtils.fromJsonArray(jsonStr, PurchaseAPBill.class);
-		apbillAdjustmentService.nonPosting(apbillAdjustmentService.convertnonPostAdjustment(apBills));
+		apbillAdjustmentService.nonPosting(apbillAdjustmentService.convertNonPostAdjustment(apBills));
 	}
 }

+ 10 - 0
src/main/java/com/uas/platform/b2b/erp/exception/NotFoundUtils.java

@@ -31,4 +31,14 @@ public class NotFoundUtils {
     public static void OrderNotFound(String paramString, String sign) {
         throw new NotFoundException(String.format("%s未找到", new Object[]{paramString}), new Throwable(sign));
     }
+
+    /**
+     * 单据未找到
+     *
+     * @param source 异常来源
+     * @param enUU 企业UU
+     */
+    public static void EnterpriseNotFound(String source, Long enUU) {
+        throw new NotFoundException(String.format("%s, %d对应企业未找到", new Object[]{source, enUU}), new Throwable());
+    }
 }

+ 7 - 4
src/main/java/com/uas/platform/b2b/erp/model/PurchaseAPBill.java

@@ -7,7 +7,11 @@ import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.core.model.Status;
 import org.springframework.util.CollectionUtils;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * 采购方角度ERP应付票据单
@@ -274,9 +278,8 @@ public class PurchaseAPBill extends KeyEntity {
 	public List<String> getProductCode() {
 	    List<String> codeStr = new ArrayList<>();
 		if (!CollectionUtils.isEmpty(details)) {
-            details.forEach(detail -> {
-                codeStr.add(detail.getAbd_prodcode());
-            });
+            details.stream().filter(detail -> null != detail.getAbd_prodcode())
+                .forEach(detail -> codeStr.add(detail.getAbd_prodcode()));
 		}
 		return codeStr;
 	}

+ 8 - 3
src/main/java/com/uas/platform/b2b/erp/service/impl/PurchaseAPBillServiceImpl.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2b.erp.service.impl;
 
 import com.uas.platform.b2b.dao.EnterpriseDao;
 import com.uas.platform.b2b.dao.PurchaseApBillDao;
+import com.uas.platform.b2b.erp.exception.NotFoundUtils;
 import com.uas.platform.b2b.erp.model.PurchaseAPBill;
 import com.uas.platform.b2b.erp.model.PurchaseAPBillDetail;
 import com.uas.platform.b2b.erp.service.PurchaseAPBillService;
@@ -73,7 +74,7 @@ public class PurchaseAPBillServiceImpl implements PurchaseAPBillService {
 
 	@Override
 	public List<PurchaseApBill> convertNonPostingApBills(List<PurchaseAPBill> apBills) {
-		List<PurchaseApBill> purchaseApBills = new ArrayList<PurchaseApBill>();
+		List<PurchaseApBill> purchaseApBills = new ArrayList<>();
 		if (!CollectionUtils.isEmpty(apBills)) {
 			Long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (PurchaseAPBill apBill : apBills) {
@@ -101,8 +102,12 @@ public class PurchaseAPBillServiceImpl implements PurchaseAPBillService {
 				if (!CollectionUtils.isEmpty(apBill.getDetails())) {
 					for (PurchaseAPBillDetail detail : apBill.getDetails()) {
 						ApbillAdjustment adjust = new ApbillAdjustment(apBill, detail);
-						Enterprise enterprise = enterpriseDao.findEnterpriseByUu(adjust.getEnuu());
-						adjust.setReceivename(enterprise.getEnName());
+						Enterprise enterprise = enterpriseDao.findOne(adjust.getEnuu());
+						if (null != enterprise) {
+                            adjust.setReceivename(enterprise.getEnName());
+                        } else {
+                            NotFoundUtils.EnterpriseNotFound("货款调账:[" + adjust.getInoutno() + "], 序号[" + adjust.getDetno() + "]", adjust.getEnuu());
+                        }
 						if (!products.isEmpty()) {
                             ProductInfo product = products.get(adjust.getProdcode());
                             if (null != product) {

+ 36 - 0
src/main/java/com/uas/platform/b2b/service/ApBillAdjustmentService.java

@@ -0,0 +1,36 @@
+package com.uas.platform.b2b.service;
+
+import com.uas.platform.b2b.erp.model.PurchaseAPBill;
+import com.uas.platform.b2b.model.ApbillAdjustment;
+
+import java.util.List;
+
+/**
+ * 货款调账接口
+ *
+ * @author US50
+ */
+public interface ApBillAdjustmentService {
+
+	/**
+	 * 批量保存、修改货款调账
+	 * 
+	 * @param apBillAdjustments 货款调账
+	 */
+    void save(List<ApbillAdjustment> apBillAdjustments);
+
+	/**
+	 * 将ERP的已反过账的货款调账,转为反过账的货款调账
+	 * 
+	 * @param apBills
+	 * @return
+	 */
+    List<ApbillAdjustment> convertNonPostAdjustment(List<PurchaseAPBill> apBills);
+
+    /**
+     * 反过账货款调账
+     *
+     * @param adjustments 货款调账信息
+     */
+    void nonPosting(List<ApbillAdjustment> adjustments);
+}

+ 0 - 38
src/main/java/com/uas/platform/b2b/service/ApbillAdjustmentService.java

@@ -1,38 +0,0 @@
-package com.uas.platform.b2b.service;
-
-import java.util.List;
-
-import com.uas.platform.b2b.erp.model.PurchaseAPBill;
-import com.uas.platform.b2b.model.ApbillAdjustment;
-
-public interface ApbillAdjustmentService {
-
-	/**
-	 * 批量保存、修改货款调账
-	 * 
-	 * @param changeItems
-	 * @return
-	 */
-	public void save(List<ApbillAdjustment> apBilladjustments);
-
-	/**
-	 * 获取本企业的货款调账
-	 * 
-	 * @return
-	 */
-	public List<ApbillAdjustment> getAdjustList(List<Long> filter, String keyword, Long fromDate, Long endDate);
-
-	/**
-	 * 将ERP的已反过账的货款调账,转为反过账的货款调账
-	 * 
-	 * @param apBills
-	 * @return
-	 */
-	public List<ApbillAdjustment> convertnonPostAdjustment(List<PurchaseAPBill> apBills);
-
-	/**
-	 * 
-	 * @param Adjustment
-	 */
-	public void nonPosting(List<ApbillAdjustment> adjustments);
-}

+ 67 - 0
src/main/java/com/uas/platform/b2b/service/impl/ApBillAdjustmentServiceImpl.java

@@ -0,0 +1,67 @@
+package com.uas.platform.b2b.service.impl;
+
+import com.uas.platform.b2b.dao.ApbillAdjustmentDao;
+import com.uas.platform.b2b.erp.model.PurchaseAPBill;
+import com.uas.platform.b2b.model.ApbillAdjustment;
+import com.uas.platform.b2b.service.ApBillAdjustmentService;
+import com.uas.platform.b2b.support.SystemSession;
+import com.uas.platform.core.model.Constant;
+import com.uas.platform.core.model.Status;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 货款调账实现方法
+ *
+ * @author US50
+ */
+@Service
+public class ApBillAdjustmentServiceImpl implements ApBillAdjustmentService {
+
+	@Autowired
+	private ApbillAdjustmentDao apbillAdjustmentDao;
+
+	@Override
+	public void save(List<ApbillAdjustment> apBillAdjustments) {
+        apbillAdjustmentDao.save(apBillAdjustments);
+	}
+
+	@Override
+	public List<ApbillAdjustment> convertNonPostAdjustment(List<PurchaseAPBill> apBills) {
+		List<ApbillAdjustment> adjusts = new ArrayList<>();
+		if (!CollectionUtils.isEmpty(apBills)) {
+			Long enUU = SystemSession.getUser().getEnterprise().getUu();
+			for (PurchaseAPBill apBill : apBills) {
+				List<ApbillAdjustment> list = apbillAdjustmentDao.findByCustuuAndInoutno(enUU, apBill.getAb_code());
+				if (!CollectionUtils.isEmpty(list)) {
+					for (ApbillAdjustment adjust : list) {
+						adjusts.add(adjust);
+					}
+				}
+			}
+		}
+		return adjusts;
+	}
+
+	@Override
+	public void nonPosting(List<ApbillAdjustment> adjustments) {
+		if (!CollectionUtils.isEmpty(adjustments)) {
+			for (ApbillAdjustment adjustment : adjustments) {
+				if (adjustment.getSendstatus() != null) {
+					// 已传输到供应商ERP,修改单据反过账状态
+					if (adjustment.getSendstatus() == Status.DOWNLOADED.value()) {
+						adjustment.setNonposting(Constant.YES);
+						apbillAdjustmentDao.save(adjustment);
+					}
+				} else {
+					// 未传输到供应商ERP,直接删除平台上的单据
+					apbillAdjustmentDao.delete(adjustment);
+				}
+			}
+		}
+	}
+}

+ 0 - 162
src/main/java/com/uas/platform/b2b/service/impl/ApbillAdjustmentServiceImpl.java

@@ -1,162 +0,0 @@
-package com.uas.platform.b2b.service.impl;
-
-import com.uas.platform.b2b.dao.ApbillAdjustmentDao;
-import com.uas.platform.b2b.dao.CommonDao;
-import com.uas.platform.b2b.erp.model.PurchaseAPBill;
-import com.uas.platform.b2b.model.ApbillAdjustment;
-import com.uas.platform.b2b.service.ApbillAdjustmentService;
-import com.uas.platform.b2b.support.SystemSession;
-import com.uas.platform.core.model.Constant;
-import com.uas.platform.core.model.Status;
-import org.apache.axis.utils.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-
-@Service
-public class ApbillAdjustmentServiceImpl implements ApbillAdjustmentService {
-
-	@Autowired
-	private ApbillAdjustmentDao apbillAdjustmentDao;
-
-	@Autowired
-	private CommonDao commonDao;
-
-	@Override
-	public void save(List<ApbillAdjustment> apBilladjustments) {
-        apbillAdjustmentDao.save(apBilladjustments);
-	}
-
-	@Override
-	public List<ApbillAdjustment> getAdjustList(List<Long> filter, String keyword, Long fromDate, Long endDate) {
-		Long enuu = SystemSession.getUser().getEnterprise().getUu();
-		String querySql = "select t.aa_id id,t.aa_currency currency,t.aa_custname custname,t.aa_custuu custuu,t.aa_detno detno,t.aa_enuu enuu,"
-				+ " t.aa_factory factory,t.aa_inoutno inoutno,t.aa_ordercode ordercode,t.aa_prodspec prodspec,t.aa_prodcode prodcode,t.aa_prodtitle prodtitle,t.aa_qty qty,"
-				+ "t.aa_rate rate,t.aa_receivecode receivecode,t.aa_receivename receivename,t.aa_sendcode sendcode,t.aa_sourceid sourceid,t.aa_orderprice orderprice,t.aa_orderdate orderdate,"
-				+ "t.aa_taxrate taxrate,t.aa_thischeckqty thischeckqty,t.aa_whname whname,t.aa_ycheckqty ycheckqty,t.aa_prid prid from purc$apbilladjustment t where t.aa_enuu =?";
-		if (!StringUtils.isEmpty(keyword)) {
-			String[] strs = keyword.split("\\|");
-			if (strs.length == 1) {
-				querySql = querySql + " and t.aa_custname = '" + strs[0] + "'";
-			}
-			if (strs.length == 2) {
-				if (strs[0].length() != 0) {
-					querySql = querySql + " and t.aa_custname = '" + strs[0] + "'";
-				}
-				querySql = querySql + " and t.aa_receivename = '" + strs[1] + "'";
-			}
-			if (strs.length == 3) {
-				if (strs[0].length() != 0) {
-					querySql = querySql + " and t.aa_custname = '" + strs[0] + "'";
-				}
-				if (strs[1].length() != 0) {
-					querySql = querySql + " and t.aa_receivename = '" + strs[1] + "'";
-				}
-				querySql = querySql + " and t.aa_factory = '" + strs[2] + "'";
-			}
-			if (strs.length == 4) {
-				if (strs[0].length() != 0) {
-					querySql = querySql + " and t.aa_custname = '" + strs[0] + "'";
-				}
-				if (strs[1].length() != 0) {
-					querySql = querySql + " and t.aa_receivename = '" + strs[1] + "'";
-				}
-				if (strs[2].length() != 0) {
-					querySql = querySql + " and t.aa_factory = '" + strs[2] + "'";
-				}
-				querySql = querySql + " and t.aa_prodtitle = '" + strs[3] + "'";
-			}
-			if (strs.length == 5) {
-				if (strs[0].length() != 0) {
-					querySql = querySql + " and t.aa_custname = '" + strs[0] + "'";
-				}
-				if (strs[1].length() != 0) {
-					querySql = querySql + " and t.aa_receivename = '" + strs[1] + "'";
-				}
-				if (strs[2].length() != 0) {
-					querySql = querySql + " and t.aa_factory = '" + strs[2] + "'";
-				}
-				if (strs[3].length() != 0) {
-					querySql = querySql + " and t.aa_prodtitle = '" + strs[3] + "'";
-				}
-				querySql = querySql + " and t.aa_prodspec = '" + strs[4] + "'";
-			}
-		}
-		if (fromDate != null) {
-			querySql = querySql + " and t.aa_orderdate>=" + "str_to_date('"
-					+ new java.sql.Date(new Date(fromDate).getTime())
-					+ "','%Y-%m-%d')";
-		}
-		if (endDate != null) {
-			querySql = querySql + " and t.aa_orderdate <=" + "str_to_date('"
-					+ new java.sql.Date(new Date(endDate).getTime())
-					+ "','%Y-%m-%d')";
-		}
-		Object[] args = new Object[] { enuu };
-		if (!CollectionUtils.isEmpty(filter)) {
-			String[] str = new String[filter.size()];
-			Long[] lon = new Long[filter.size() + 1];
-			String s = "";
-			for (int i = 0; i < filter.size(); i++) {
-				if (i != filter.size() - 1) {
-					str[i] = "?,";
-				} else {
-					str[i] = "?";
-				}
-				lon[i + 1] = filter.get(i);
-				s = s + str[i];
-			}
-			querySql = querySql + " and t.aa_custuu in (" + s + ")";
-			lon[0] = enuu;
-			args = lon;
-		}
-		querySql = querySql + " order by t.aa_orderdate desc";
-		try {
-			List<ApbillAdjustment> list = commonDao.query(querySql, args, ApbillAdjustment.class);
-			return list;
-		} catch (EmptyResultDataAccessException e) {
-			return null;
-		}
-	}
-
-	@Override
-	public List<ApbillAdjustment> convertnonPostAdjustment(List<PurchaseAPBill> apBills) {
-		List<ApbillAdjustment> adjusts = new ArrayList<ApbillAdjustment>();
-		if (!CollectionUtils.isEmpty(apBills)) {
-			Long enUU = SystemSession.getUser().getEnterprise().getUu();
-			for (PurchaseAPBill apBill : apBills) {
-				List<ApbillAdjustment> list = apbillAdjustmentDao.findByCustuuAndInoutno(enUU, apBill.getAb_code());
-				if (!CollectionUtils.isEmpty(list)) {
-					for (ApbillAdjustment adjust : list) {
-						adjusts.add(adjust);
-					}
-				}
-			}
-		}
-		return adjusts;
-	}
-
-	@Override
-	public void nonPosting(List<ApbillAdjustment> adjustments) {
-		if (!CollectionUtils.isEmpty(adjustments)) {
-			for (ApbillAdjustment adjustment : adjustments) {
-				if (adjustment.getSendstatus() != null) {
-					// 已传输到供应商ERP,修改单据反过账状态
-					if (adjustment.getSendstatus() == Status.DOWNLOADED.value()) {
-						adjustment.setNonposting(Constant.YES);
-						apbillAdjustmentDao.save(adjustment);
-					}
-				} else {
-					// 未传输到供应商ERP,直接删除平台上的单据
-					apbillAdjustmentDao.delete(adjustment);
-				}
-			}
-		}
-	}
-}

+ 3 - 20
src/main/java/com/uas/platform/b2b/support/CollectionUtil.java

@@ -1,11 +1,10 @@
 package com.uas.platform.b2b.support;
 
 import com.uas.platform.b2b.erp.model.KeyEntity;
-import com.uas.platform.b2b.model.AbstractRedDotKey;
 import org.springframework.util.CollectionUtils;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
+import java.io.*;
+import java.net.*;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -50,7 +49,7 @@ public class CollectionUtil {
         if (!CollectionUtils.isEmpty(paramArray)) {
             for (KeyEntity param : paramArray) {
                 List<String> codeList = param.getProductCode();
-                if (!CollectionUtils.isEmpty(codeList)) {
+                if (!CollectionUtils.isEmpty(codeList) && null != codeList) {
                     for (String code : codeList) {
                         try {
                             codeSet.add(URLEncoder.encode(code, "UTF-8"));
@@ -64,22 +63,6 @@ public class CollectionUtil {
         return codeSet;
     }
 
-    /**
-     * 用继承自AbstractRedDotKey的类,重写获取原表ID的方法
-     *
-     * @param paramArray
-     * @return
-     */
-    public static Set<Long> getRedDotIdCollection(Collection<? extends AbstractRedDotKey> paramArray) {
-        Set<Long> idSet = new HashSet<>();
-        if (!CollectionUtils.isEmpty(paramArray)) {
-            for (AbstractRedDotKey param : paramArray) {
-                idSet.add(param.RedDotKey());
-            }
-        }
-        return idSet;
-    }
-
     /**
      * 集合是否为空
      *