Преглед изворни кода

feat: 优化生成对账单方法

hejq пре 7 година
родитељ
комит
4888c5a4eb

+ 16 - 0
src/main/java/com/uas/platform/b2b/dao/PurcApCheckDao.java

@@ -0,0 +1,16 @@
+package com.uas.platform.b2b.dao;
+
+import com.uas.platform.b2b.model.PurcApCheck;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 应收对账单
+ *
+ * @author hejq
+ * @date 2018-12-27 10:03
+ */
+@Repository
+public interface PurcApCheckDao extends JpaRepository<PurcApCheck, Long>, JpaSpecificationExecutor<PurcApCheck> {
+}

+ 8 - 0
src/main/java/com/uas/platform/b2b/dao/PurchaseApCheckItemDao.java

@@ -10,6 +10,12 @@ import org.springframework.stereotype.Repository;
 import java.util.Collection;
 import java.util.List;
 
+/**
+ * 应收对账单明细
+ *
+ * @author hejq
+ * @date 2018-12-27 9:20
+ */
 @Repository
 public interface PurchaseApCheckItemDao
 		extends JpaSpecificationExecutor<PurchaseApCheckItem>, JpaRepository<PurchaseApCheckItem, Long> {
@@ -39,4 +45,6 @@ public interface PurchaseApCheckItemDao
 	 */
 	@Query("select p.billed from PurchaseApCheckItem p where p.id= :id")
 	Double getBilledById(@Param("id") Long id);
+
+	List<PurchaseApCheckItem> findByApCheckId(Long apCheckId);
 }

+ 115 - 0
src/main/java/com/uas/platform/b2b/model/ApCheckTable.java

@@ -0,0 +1,115 @@
+package com.uas.platform.b2b.model;
+
+/**
+ * 对账表
+ *
+ * @author hejq
+ * @date 2018-12-26 14:59
+ */
+public class ApCheckTable {
+
+    /**
+     * 客户采购验收单
+     */
+    public static final String SALE_ACCEPT = "purc$acceptitem";
+
+    /**
+     * 客户采购验收单对账数量
+     */
+    public static final String SALE_ACCEPT_QTY = "pai_ycheckqty";
+
+    /**
+     * 客户采购验收单明细id
+     */
+    public static final String SALE_ACCEPT_ID = "pai_id";
+
+    /**
+     * 客户采购验退单
+     */
+    public static final String SALE_RETURN = "purc$returnitem";
+
+    /**
+     * 客户采购验退单对账数量
+     */
+    public static final String SALE_RETURN_QTY = "pri_ycheckqty";
+
+    /**
+     * 客户采购验退单明细id
+     */
+    public static final String SALE_RETURN_ID = "pri_id";
+
+    /**
+     * 不良品入库单
+     */
+    public static final String SALE_BADIN = "purc$badinitem";
+
+    /**
+     * 不良品入库单对账数量
+     */
+    public static final String SALE_BADIN_QTY = "pbi_ycheckqty";
+
+    /**
+     * 不良品入库单id
+     */
+    public static final String SALE_BADIN_ID = "pbi_id";
+
+    /**
+     * 不良品出库单对账数量
+     */
+    public static final String SALE_BADOUT_QTY = "poi_ycheckqty";
+
+    /**
+     * 不良品出库单明细id
+     */
+    public static final String SALE_BADOUT_ID = "poi_id";
+
+    /**
+     * 不良品出库单
+     */
+    public static final String SALE_BADOUT = "purc$badoutitem";
+
+    /**
+     * 货款调账单对账数量
+     */
+    public static final String ADJUSTMENT_QTY = "aa_ycheckqty";
+
+    /**
+     * 货款调账单明细id
+     */
+    public static final String ADJUSTMENT_ID = "aa_id";
+
+    /**
+     * 货款调账单
+     */
+    public static final String ADJUSTMENT = "purc$apbilladjustment";
+
+    /**
+     * 委外验收单对账数量
+     */
+    public static final String MAKE_ACCEPT_QTY = "mai_ycheckqty";
+
+    /**
+     * 委外验收单明细id
+     */
+    public static final String MAKE_ACCEPT_ID = "mai_id";
+
+    /**
+     * 委外验收单
+     */
+    public static final String MAKE_ACCEPT = "make$acceptitem";
+
+    /**
+     * 委外验退单对账数量
+     */
+    public static final String MAKE_RETURN_QTY = "mri_ycheckqty";
+
+    /**
+     * 委外验退单明细id
+     */
+    public static final String MAKE_RETURN_ID = "mri_id";
+
+    /**
+     * 委外验退单
+     */
+    public static final String MAKE_RETURN = "make$returnitem";
+}

+ 40 - 0
src/main/java/com/uas/platform/b2b/model/OrderRedDotAll.java

@@ -146,4 +146,44 @@ public class OrderRedDotAll implements Serializable {
     public void setDate(Date date) {
         this.date = date;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof OrderRedDotAll)) {
+            return false;
+        }
+
+        OrderRedDotAll redDotAll = (OrderRedDotAll) o;
+
+        if (id != null ? !id.equals(redDotAll.id) : redDotAll.id != null) {
+            return false;
+        }
+        if (orderId != null ? !orderId.equals(redDotAll.orderId) : redDotAll.orderId != null) {
+            return false;
+        }
+        if (orderType != null ? !orderType.equals(redDotAll.orderType) : redDotAll.orderType != null) {
+            return false;
+        }
+        if (enUU != null ? !enUU.equals(redDotAll.enUU) : redDotAll.enUU != null) {
+            return false;
+        }
+        if (vendUU != null ? !vendUU.equals(redDotAll.vendUU) : redDotAll.vendUU != null) {
+            return false;
+        }
+        return date != null ? date.equals(redDotAll.date) : redDotAll.date == null;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = id != null ? id.hashCode() : 0;
+        result = 31 * result + (orderId != null ? orderId.hashCode() : 0);
+        result = 31 * result + (orderType != null ? orderType.hashCode() : 0);
+        result = 31 * result + (enUU != null ? enUU.hashCode() : 0);
+        result = 31 * result + (vendUU != null ? vendUU.hashCode() : 0);
+        result = 31 * result + (date != null ? date.hashCode() : 0);
+        return result;
+    }
 }

+ 391 - 0
src/main/java/com/uas/platform/b2b/model/PurcApCheck.java

@@ -0,0 +1,391 @@
+package com.uas.platform.b2b.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import java.io.*;
+import java.util.Date;
+
+/**
+ * 买家应付(卖家应收)对账单
+ * @author hejq
+ */
+@Entity
+@Table(name = "purc$apcheck")
+public class PurcApCheck implements Serializable {
+
+	/**
+	 * 序列号
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * ID
+	 */
+	@Id
+	@GeneratedValue(strategy = GenerationType.AUTO)
+	@Column(name = "pa_id")
+	private Long id;
+
+	/**
+	 * 对账起始日期
+	 */
+	@Column(name = "pa_begindate")
+	private Date beginDate;
+
+	/**
+	 * 对账截止日期
+	 */
+	@Column(name = "pa_enddate")
+	private Date endDate;
+
+	/**
+	 * 录单日期
+	 */
+	@Column(name = "pa_recorddate")
+	private Date recordDate;
+
+	/**
+	 * 录单人
+	 */
+	@Column(name = "pa_recorder")
+	private String recorder;
+
+	/**
+	 * 录单人UU
+	 */
+	@Column(name = "pa_recorderuu")
+	private Long recorderUU;
+
+	/**
+	 * 应收日期
+	 */
+	@Column(name = "pa_apdate")
+	private Date apDate;
+
+	/**
+	 * 对账状态
+	 */
+	@Column(name = "pa_checkstatus")
+	private String checkStatus;
+
+	/**
+	 * 备注
+	 */
+	@Column(name = "pa_remark")
+	private String remark;
+
+	/**
+	 * 提交日期
+	 */
+	@Column(name = "pa_commitdate")
+	private Date commitDate;
+
+	/**
+	 * 作废日期
+	 */
+	@Column(name = "pa_resdate")
+	private Date resDate;
+
+	/**
+	 * 作废人
+	 */
+	@Column(name = "pa_resman")
+	private String resMan;
+
+	/**
+	 * 上传状态
+	 */
+	@Column(name = "pa_status")
+	private Short status;
+
+	/**
+	 * 对账总额
+	 */
+	@Column(name = "pa_checkamount")
+	private Double checkAmount;
+
+	/**
+	 * 币别
+	 */
+	@Column(name = "pa_currency")
+	private String currency;
+
+	/**
+	 * 汇率
+	 */
+	@Column(name = "pa_taxrate")
+	private Double taxrate;
+
+	/**
+	 * 汇率
+	 */
+	@Column(name = "pa_rate")
+	private Double rate;
+
+	/**
+	 * 收款方式
+	 */
+	@Column(name = "pa_payments")
+	private String payments;
+
+	/**
+	 * 客户UU
+	 */
+	@Column(name = "pa_custuu")
+	private Long custUu;
+
+	/**
+	 * 客户名称
+	 */
+	@Column(name = "pa_custname")
+	private String custName;
+
+	/**
+	 * 供应商UU
+	 */
+	@Column(name = "pa_enuu")
+	private Long enUu;
+
+    /**
+     * 供应商名称
+     */
+	@Transient
+    private String vendorName;
+
+	/**
+	 * 单据编号
+	 */
+	@Column(name = "pa_code")
+	private String code;
+
+	/**
+	 * 客户回复原因
+	 */
+	@Column(name = "pa_custreply")
+	private String custreply;
+
+	/**
+	 * 打印次数
+	 */
+	@Column(name = "pa_print")
+	private Short print;
+
+	/**
+	 * 不同意原因
+	 */
+	@Column(name = "pa_reason")
+	private String reason;
+
+    public String getCustreply() {
+		return custreply;
+	}
+
+	public void setCustreply(String custreply) {
+		this.custreply = custreply;
+	}
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Date getBeginDate() {
+		return beginDate;
+	}
+
+	public void setBeginDate(Date beginDate) {
+		this.beginDate = beginDate;
+	}
+
+	public Date getEndDate() {
+		return endDate;
+	}
+
+	public void setEndDate(Date endDate) {
+		this.endDate = endDate;
+	}
+
+	public Date getRecordDate() {
+		return recordDate;
+	}
+
+	public void setRecordDate(Date recordDate) {
+		this.recordDate = recordDate;
+	}
+
+	public String getRecorder() {
+		return recorder;
+	}
+
+	public void setRecorder(String recorder) {
+		this.recorder = recorder;
+	}
+
+	public Date getApDate() {
+		return apDate;
+	}
+
+	public void setApDate(Date apDate) {
+		this.apDate = apDate;
+	}
+
+	public String getCheckStatus() {
+		return checkStatus;
+	}
+
+	public void setCheckStatus(String checkStatus) {
+		this.checkStatus = checkStatus;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+
+	public Date getCommitDate() {
+		return commitDate;
+	}
+
+	public void setCommitDate(Date commitDate) {
+		this.commitDate = commitDate;
+	}
+
+	public Date getResDate() {
+		return resDate;
+	}
+
+	public void setResDate(Date resDate) {
+		this.resDate = resDate;
+	}
+
+	public String getResMan() {
+		return resMan;
+	}
+
+	public void setResMan(String resMan) {
+		this.resMan = resMan;
+	}
+
+	public Short getStatus() {
+		return status;
+	}
+
+	public void setStatus(Short status) {
+		this.status = status;
+	}
+
+	public Double getCheckAmount() {
+		return checkAmount;
+	}
+
+	public void setCheckAmount(Double checkAmount) {
+		this.checkAmount = checkAmount;
+	}
+
+	public String getCurrency() {
+		return currency;
+	}
+
+	public void setCurrency(String currency) {
+		this.currency = currency;
+	}
+
+	public Double getTaxrate() {
+		return taxrate;
+	}
+
+	public void setTaxrate(Double taxrate) {
+		this.taxrate = taxrate;
+	}
+
+	public String getPayments() {
+		return payments;
+	}
+
+	public void setPayments(String payments) {
+		this.payments = payments;
+	}
+
+	public Long getCustUu() {
+		return custUu;
+	}
+
+	public void setCustUu(Long custUu) {
+		this.custUu = custUu;
+	}
+
+	public String getCustName() {
+		return custName;
+	}
+
+	public void setCustName(String custName) {
+		this.custName = custName;
+	}
+
+	public Long getEnUu() {
+		return enUu;
+	}
+
+	public void setEnUu(Long enUu) {
+		this.enUu = enUu;
+	}
+
+    public String getVendorName() {
+        return vendorName;
+    }
+
+    public void setVendorName(String vendorName) {
+        this.vendorName = vendorName;
+    }
+
+    public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public Double getRate() {
+		return rate;
+	}
+
+	public void setRate(Double rate) {
+		this.rate = rate;
+	}
+
+	public Short getPrint() {
+		return print;
+	}
+
+	public void setPrint(Short print) {
+		this.print = print;
+	}
+
+	public Long getRecorderUU() {
+		return recorderUU;
+	}
+
+	public void setRecorderUU(Long recorderUU) {
+		this.recorderUU = recorderUU;
+	}
+
+	public String getReason() {
+		return reason;
+	}
+
+	public void setReason(String reason) {
+		this.reason = reason;
+	}
+}

+ 0 - 1
src/main/java/com/uas/platform/b2b/model/PurchaseApCheckItem.java

@@ -55,7 +55,6 @@ public class PurchaseApCheckItem implements Serializable {
     @Column(name = "pai_custuseruu")
     private Long custUserUU;
 
-
     /**
 	 * 客户物料ID
 	 */

+ 1 - 5
src/main/java/com/uas/platform/b2b/model/SourceForApcheck.java

@@ -16,11 +16,7 @@ public class SourceForApcheck {
 		super();
 		this.sourceid = item.getSourceId();
 		this.sourcetable = item.getSourceTable();
-		if (item.getOldYCheckQty() == null) {
-			this.newYCheckQty = item.getCheckQty();
-		} else {
-			this.newYCheckQty = item.getCheckQty() + item.getOldYCheckQty();
-		}
+		this.newYCheckQty = item.getOldYCheckQty() == null ? item.getCheckQty() : item.getCheckQty() + item.getOldYCheckQty();
 
 	}
 

+ 107 - 50
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApCheckServiceImpl.java

@@ -4,21 +4,23 @@ 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.StringUtil;
 import com.uas.platform.b2b.dao.CommonDao;
 import com.uas.platform.b2b.dao.CommunalLogDao;
 import com.uas.platform.b2b.dao.EnterpriseDao;
+import com.uas.platform.b2b.dao.PurcApCheckDao;
 import com.uas.platform.b2b.dao.PurchaseApCheckDao;
 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;
 import com.uas.platform.b2b.model.Enterprise;
 import com.uas.platform.b2b.model.OrderRedDotAll;
 import com.uas.platform.b2b.model.OrderType;
+import com.uas.platform.b2b.model.PurcApCheck;
 import com.uas.platform.b2b.model.PurchaseApCheck;
 import com.uas.platform.b2b.model.PurchaseApCheckDone;
 import com.uas.platform.b2b.model.PurchaseApCheckItem;
@@ -48,6 +50,7 @@ import com.uas.platform.core.model.Status;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
 import com.uas.ps.core.util.StringUtils;
 import com.uas.search.b2b.model.SPage;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
@@ -73,6 +76,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 对账单
@@ -91,6 +95,7 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
     private final UserService userService;
     private final VendorDao vendorDao;
     private final CommunalLogDao communalLogDao;
+    private final PurcApCheckDao apCheckDao;
     @Autowired
     private ErpProdIODetailService erpProdIODetailService;
 
@@ -117,7 +122,8 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
     public PurchaseApCheckServiceImpl(PurchaseApCheckDao purchaseApCheckDao, PurchaseApCheckTodoDao purchaseApCheckTodoDao,
                                       PurchaseApCheckDoneDao purchaseApCheckDoneDao, PurchaseApCheckItemDao purchaseApCheckItemDao,
                                       CommonDao commonDao, OrderRedDotService redDotService, EnterpriseDao enterpriseDao,
-                                      UserService userService, VendorDao vendorDao, CommunalLogDao communalLogDao) {
+                                      UserService userService, VendorDao vendorDao, CommunalLogDao communalLogDao,
+                                      PurcApCheckDao apCheckDao) {
         this.purchaseApCheckDao = purchaseApCheckDao;
         this.redDotService = redDotService;
         this.purchaseApCheckTodoDao = purchaseApCheckTodoDao;
@@ -128,6 +134,7 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
         this.userService = userService;
         this.vendorDao = vendorDao;
         this.communalLogDao = communalLogDao;
+        this.apCheckDao = apCheckDao;
         ExecutorService executorService = Executors.newCachedThreadPool();
         executor = new BoundedExecutor(executorService, 1600);
     }
@@ -337,7 +344,7 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
 	@Override
 	@Transactional(rollbackFor = SQLException.class)
 	public PurchaseApCheck save(PurchaseApCheck purchaseApCheck) {
-		Date date = new Date();
+		Date date = new Date(System.currentTimeMillis());
         purchaseApCheck.setRecordDate(date);
         purchaseApCheck.setCommitDate(date);
         SimpleDateFormat sdf = new SimpleDateFormat("yyMMddhhmmss_sss");
@@ -346,68 +353,93 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
 		purchaseApCheck.setRecorder(SystemSession.getUser().getUserName());
 		purchaseApCheck.setRecorderUU(SystemSession.getUser().getUserUU());
         purchaseApCheck.setStatus((short) Status.NOT_UPLOAD.value());
-		Short number = 0;
-		List<PurchaseApCheckItem> items = new ArrayList<PurchaseApCheckItem>();
 		// 保存成功的同时来源单据更新一下
 		List<SourceForApcheck> sources = new ArrayList<>();
+        PurcApCheck apCheck = new PurcApCheck();
+        BeanUtils.copyProperties(purchaseApCheck, apCheck, PurcApCheck.class);
+        apCheck = apCheckDao.save(apCheck);
 		for (PurchaseApCheckItem item : purchaseApCheck.getItems()) {
 			SourceForApcheck source = new SourceForApcheck(item);
 			sources.add(source);
-			item.setNumber(++number);
-			item.setApCheck(purchaseApCheck);
-			items.add(item);
 		}
-		updateSourceInfo(sources);
-        items = purchaseApCheckItemDao.save(items);
+        updateSourceInfo(sources);
+        saveCheckItemsByJdbcTemplate(purchaseApCheck.getItems(), apCheck.getId());
         List<PurchaseApCheck> apChecks = new ArrayList<>();
-        apChecks.add(items.get(0).getApCheck());
+        purchaseApCheck.setId(apCheck.getId());
+        apChecks.add(purchaseApCheck);
         saveUserOrders(apChecks);
-		return purchaseApCheck;
+        return purchaseApCheck;
 	}
 
+    /**
+     * 采用jdbcTemplate批量存储名
+     * @param items 对账明细
+     * @param apCheckId 主表id
+     */
+    private void saveCheckItemsByJdbcTemplate(Set<PurchaseApCheckItem> items, final Long apCheckId) {
+	    if (!CollectionUtils.isEmpty(items)) {
+            final Short[] num = {1};
+	        commonDao.getJdbcTemplate().batchUpdate("insert into purc$apcheckitem(pai_number, pai_custuseruu, pai_prid, pai_ordercode,pai_orderclass, " +
+                "pai_orderdetno, pai_inoutno, pai_inoutnodetno, pai_prodcode, pai_prodtitle, pai_prodspec, pai_produnit, pai_price,pai_taxrate, pai_checkqty, " +
+                "pai_amount, pai_custcheckqty, pai_remark, pai_status, pai_sourcetable, pai_sourceid, pai_source_date, pai_oldycheckqty, pai_receivecode, pai_receivename, " +
+                "pai_sendcode, pai_whname, pai_billed, pai_paid) " +
+                "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
+                items, items.size(), (pa, i) -> {
+	                pa.setObject(1, num[0]++);
+                    pa.setObject(2, i.getCustUserUU());
+                    pa.setObject(3, i.getPrid());
+                    pa.setObject(4, i.getOrderCode());
+                    pa.setObject(5, i.getOrderClass());
+                    pa.setObject(6, i.getOrderDetno());
+                    pa.setObject(7, i.getInoutno());
+                    pa.setObject(8, i.getInoutnodetno());
+                    pa.setObject(9, i.getProdCode());
+                    pa.setObject(10, i.getProdTitle());
+
+                    pa.setObject(11, i.getProdSpec());
+                    pa.setObject(12, i.getProdUnit());
+                    pa.setObject(13, i.getPrice());
+                    pa.setObject(14, i.getTaxrate());
+                    pa.setObject(15, i.getCheckQty());
+                    pa.setObject(16, i.getAmount());
+                    pa.setObject(17, i.getCustCheckQty());
+                    pa.setObject(18, i.getRemark());
+                    pa.setObject(19, i.getStatus());
+                    pa.setObject(20, i.getSourceTable());
+
+                    pa.setObject(21, i.getSourceId());
+                    pa.setObject(22, i.getSourceDate());
+                    pa.setObject(23, i.getOldYCheckQty());
+                    pa.setObject(24, i.getReceiveCode());
+                    pa.setObject(25, i.getReceiveName());
+                    pa.setObject(26, i.getSendcode());
+                    pa.setObject(27, i.getWhname());
+                    pa.setObject(28, i.getBilled());
+                    pa.setObject(29, apCheckId);
+                });
+        }
+    }
+
     /**
      * 更新来源表数据
      *
-     * @param list 来源库信息
+     * @param sourceApCheckList 来源库信息
      * @return 保存结果
      */
-	public boolean updateSourceInfo(List<SourceForApcheck> list) {
-		if (!CollectionUtils.isEmpty(list)) {
-		    List<String> sqls = new ArrayList<>();
-			for (SourceForApcheck source : list) {
-				if (source.hasInfo()) {
-					String idName = null;
-					String yCheckQtyName = null;
-					if (source.getSourcetable().equals("purc$returnitem")) {
-						idName = "pri_id";
-						yCheckQtyName = "pri_ycheckqty";
-					} else if (source.getSourcetable().equals("purc$acceptitem")) {
-						idName = "pai_id";
-						yCheckQtyName = "pai_ycheckqty";
-					} else if (source.getSourcetable().equals("purc$badinitem")) {
-						idName = "pbi_id";
-						yCheckQtyName = "pbi_ycheckqty";
-					} else if (source.getSourcetable().equals("purc$badoutitem")) {
-						idName = "poi_id";
-						yCheckQtyName = "poi_ycheckqty";
-					} else if (source.getSourcetable().equals("make$acceptitem")) {
-						idName = "mai_id";
-						yCheckQtyName = "mai_ycheckqty";
-					} else if (source.getSourcetable().equals("make$returnitem")) {
-						idName = "mri_id";
-						yCheckQtyName = "mri_ycheckqty";
-					} else if (source.getSourcetable().equals("purc$apbilladjustment")) {
-						idName = "aa_id";
-						yCheckQtyName = "aa_ycheckqty";
-					}
-					String sql = "update " + source.getSourcetable() + " set " + yCheckQtyName + " = "
-							+ source.getNewYCheckQty() + " where " + idName + " = " + source.getSourceid();
-                    sqls.add(sql);
-				}
-			}
-			if (!CollectionUtils.isEmpty(sqls)) {
+	public boolean updateSourceInfo(List<SourceForApcheck> sourceApCheckList) {
+		if (!CollectionUtils.isEmpty(sourceApCheckList)) {
+		    String saleAcceptSql = setSql(sourceApCheckList, ApCheckTable.SALE_ACCEPT, ApCheckTable.SALE_ACCEPT_QTY, ApCheckTable.SALE_ACCEPT_ID);
+            String saleReturnSql = setSql(sourceApCheckList, ApCheckTable.SALE_RETURN, ApCheckTable.SALE_RETURN_QTY, ApCheckTable.SALE_RETURN_ID);
+            String saleBadInSql = setSql(sourceApCheckList, ApCheckTable.SALE_BADIN, ApCheckTable.SALE_BADIN_QTY, ApCheckTable.SALE_BADIN_ID);
+            String saleBadOutSql = setSql(sourceApCheckList, ApCheckTable.SALE_BADOUT, ApCheckTable.SALE_BADOUT_QTY, ApCheckTable.SALE_BADOUT_ID);
+            String makeAcceptSql = setSql(sourceApCheckList, ApCheckTable.MAKE_ACCEPT, ApCheckTable.MAKE_ACCEPT_QTY, ApCheckTable.MAKE_ACCEPT_ID);
+            String makeReturnSql = setSql(sourceApCheckList, ApCheckTable.MAKE_RETURN, ApCheckTable.MAKE_RETURN_QTY, ApCheckTable.MAKE_RETURN_ID);
+            String adjustmentSql = setSql(sourceApCheckList, ApCheckTable.ADJUSTMENT, ApCheckTable.ADJUSTMENT_QTY, ApCheckTable.ADJUSTMENT_ID);
+            List<String> sqlList = Stream.of(saleAcceptSql, saleReturnSql, saleBadInSql, saleBadOutSql, makeAcceptSql, makeReturnSql, adjustmentSql)
+                .filter(str -> !StringUtils.isEmpty(str)).collect(Collectors.toList());
+            if (!CollectionUtils.isEmpty(sqlList)) {
 			    try {
-			        commonDao.getJdbcTemplate().batchUpdate(sqls.toArray(new String[sqls.size()]));
+			        commonDao.getJdbcTemplate().batchUpdate(sqlList.toArray(new String[sqlList.size()]));
                 } catch (RuntimeException e) {
                     System.out.println("生成对账单批量更新来源数据失败: " + e.getMessage());
                     throw new IllegalOperatorException("保存失败!");
@@ -418,7 +450,32 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
 		throw new IllegalOperatorException("保存失败!");
 	}
 
-	@Override
+    private String setSql(List<SourceForApcheck> sourceApCheckList, String tableName, String qtyColumn, String idColumn) {
+        List<SourceForApcheck> filterList = sourceApCheckList.stream()
+            .filter(source -> source.hasInfo() && tableName.equals(source.getSourcetable()))
+            .collect(Collectors.toList());
+	    if (CollectionUtils.isEmpty(filterList)) {
+	        return null;
+        }
+	    StringBuffer sql = new StringBuffer("update ").append(tableName)
+            .append(" set ").append(qtyColumn).append(" = case ")
+            .append(idColumn).append(" ");
+        StringBuffer idString = new StringBuffer();
+        filterList.forEach(apCheck -> {
+            sql.append(" when ").append(apCheck.getSourceid()).append(" then ").append(20);
+            if (idString.length() > 0) {
+                idString.append(",");
+            }
+            idString.append(apCheck.getSourceid());
+        });
+        if (idString.length() == 0) {
+            throw new IllegalOperatorException("更新失败");
+        }
+        sql.append(" end where ").append(idColumn).append(" in (").append(idString).append(")");
+        return sql.toString();
+    }
+
+    @Override
 	public Page<PurchaseApCheck> findAllByPageInfo(final PageInfo pageInfo, final String keyword,
 			SearchFilter searchFilter) {
 		if (searchFilter != null) {