Browse Source

【生成对账单方法优化,防止事务不一致】

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@4490 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
aof 10 years ago
parent
commit
aacbde8333

+ 11 - 11
src/main/java/com/uas/platform/b2b/controller/SaleApCheckController.java

@@ -109,6 +109,17 @@ public class SaleApCheckController {
 			throw new IllegalOperatorException("保存失败!");
 			throw new IllegalOperatorException("保存失败!");
 		}
 		}
 	}
 	}
+	
+	/**
+	 * 生成应收对账单的同时更新明细行来源表中,物料已转数
+	 * 
+	 */
+	@RequestMapping(value = "/update", method = RequestMethod.POST)
+	@ResponseBody
+	public void updateYCheckQty(@RequestBody String json) {
+		List<HashMap<String, Object>> list = FlexJsonUtils.fromJsonArray(json, HashMap.class);
+		purchaseApCheckService.updateYCheckQty(list);
+	}
 
 
 	/**
 	/**
 	 * 获得应收对账单,对应id
 	 * 获得应收对账单,对应id
@@ -123,17 +134,6 @@ public class SaleApCheckController {
 		return purchaseApCheckService.findById(id);
 		return purchaseApCheckService.findById(id);
 	}
 	}
 
 
-	/**
-	 * 生成应收对账单的同时更新明细行来源表中,物料已转数
-	 * 
-	 */
-	@RequestMapping(value = "/update", method = RequestMethod.POST)
-	@ResponseBody
-	public void updateYCheckQty(@RequestBody String json) {
-		List<HashMap<String, Object>> list = FlexJsonUtils.fromJsonArray(json, HashMap.class);
-		purchaseApCheckService.updateYCheckQty(list);
-	}
-
 	/**
 	/**
 	 * 删除最新生成未提交的应收对账单
 	 * 删除最新生成未提交的应收对账单
 	 */
 	 */

+ 8 - 0
src/main/java/com/uas/platform/b2b/core/util/SearchKeyUtils.java

@@ -27,12 +27,20 @@ public class SearchKeyUtils {
 	 */
 	 */
 	public static Set<String> splitToKeys(String paramString, boolean limit) {
 	public static Set<String> splitToKeys(String paramString, boolean limit) {
 		Set<String> keySet = new HashSet<String>();
 		Set<String> keySet = new HashSet<String>();
+		//TODO 需要将整个字符加进去匹配
+		//如 :RC0603JR-0733R,整体也能搜索到
+		//限制长度 50个字符串
+//		if(paramString.length() <=50) {
+//			keySet.add(paramString);
+//		}
 		if (StringUtils.hasText(paramString)) {
 		if (StringUtils.hasText(paramString)) {
 			String string = paramString;
 			String string = paramString;
 			if (string.endsWith(COMPANY_END))
 			if (string.endsWith(COMPANY_END))
 				string = string.substring(0, string.indexOf(COMPANY_END));
 				string = string.substring(0, string.indexOf(COMPANY_END));
+			System.out.println(string);
 			// 先按标点符号分成多个小字符串
 			// 先按标点符号分成多个小字符串
 			String[] strs = string.replaceAll("[\\pP‘’“”\\s]", ",").split(",");
 			String[] strs = string.replaceAll("[\\pP‘’“”\\s]", ",").split(",");
+			System.out.println(strs.length);
 			for (String str : strs) {
 			for (String str : strs) {
 				int maxLen = limit ? maxLength : str.length();
 				int maxLen = limit ? maxLength : str.length();
 				for (int len = minLength; len <= maxLen; len++) {
 				for (int len = minLength; len <= maxLen; len++) {

+ 10 - 0
src/main/java/com/uas/platform/b2b/event/PurchaseOrderSaveEvent.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2b.event;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
+import java.util.Set;
 
 
 import com.uas.platform.b2b.core.util.SearchKeyUtils;
 import com.uas.platform.b2b.core.util.SearchKeyUtils;
 import com.uas.platform.b2b.model.PurchaseOrderAll;
 import com.uas.platform.b2b.model.PurchaseOrderAll;
@@ -26,6 +27,15 @@ public class PurchaseOrderSaveEvent extends SaveEvent<PurchaseOrderIndex, Purcha
 		super(savedList);
 		super(savedList);
 	}
 	}
 
 
+	public static void main(String[] args) {
+		String s = "深圳市优软科技有限公司";
+		Set<String> sets = SearchKeyUtils.splitToKeys(s, true);
+		System.out.println(sets.size());
+		for(String ss : sets) {
+			System.out.println("::" + ss);
+		}
+	}
+	
 	@Override
 	@Override
 	public List<PurchaseOrderIndex> split(PurchaseOrderAll saved) {
 	public List<PurchaseOrderIndex> split(PurchaseOrderAll saved) {
 		long key = saved.getId();
 		long key = saved.getId();

+ 58 - 0
src/main/java/com/uas/platform/b2b/model/SourceForApcheck.java

@@ -0,0 +1,58 @@
+package com.uas.platform.b2b.model;
+
+/**
+ * 这个模型 记录出入库来源单信息
+ * @author aof
+ * @time 创建时间:2016年5月26日
+ */
+public class SourceForApcheck {
+	
+	private Long sourceId;
+	private String sourceTable;
+	private Double newYCheckQty;
+	
+	public SourceForApcheck(PurchaseApCheckItem item) {
+		super();
+		this.sourceId = item.getSourceId();
+		this.sourceTable = item.getSourceTable();
+		this.newYCheckQty = item.getCheckQty();
+	}
+
+	public Long getSourceId() {
+		return sourceId;
+	}
+
+	public void setSourceId(Long sourceId) {
+		this.sourceId = sourceId;
+	}
+
+	public String getSourceTable() {
+		return sourceTable;
+	}
+
+	public void setSourceTable(String sourceTable) {
+		this.sourceTable = sourceTable;
+	}
+
+	public Double getNewYCheckQty() {
+		return newYCheckQty;
+	}
+
+	public void setNewYCheckQty(Double newYCheckQty) {
+		this.newYCheckQty = newYCheckQty;
+	}
+
+	public boolean hasInfo() {
+		if(this.getNewYCheckQty() != null && this.getSourceId() != null && this.getSourceTable() != null) {
+			return true;
+		}
+		return false;
+	}
+	
+	@Override
+	public String toString() {
+		return "SourceForApcheck [sourceId=" + sourceId + ", sourceTable=" + sourceTable + ", newYCheckQty="
+				+ newYCheckQty + "]";
+	}
+	
+}

+ 47 - 1
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApCheckServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 import org.springframework.util.StringUtils;
 
 
@@ -34,8 +35,10 @@ import com.uas.platform.b2b.model.PurchaseApCheckEnd;
 import com.uas.platform.b2b.model.PurchaseApCheckItem;
 import com.uas.platform.b2b.model.PurchaseApCheckItem;
 import com.uas.platform.b2b.model.PurchaseApCheckTodo;
 import com.uas.platform.b2b.model.PurchaseApCheckTodo;
 import com.uas.platform.b2b.model.SearchFilter;
 import com.uas.platform.b2b.model.SearchFilter;
+import com.uas.platform.b2b.model.SourceForApcheck;
 import com.uas.platform.b2b.service.PurchaseApCheckService;
 import com.uas.platform.b2b.service.PurchaseApCheckService;
 import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.b2b.support.SystemSession;
+import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.Status;
 import com.uas.platform.core.model.Status;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
@@ -221,6 +224,7 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
 	
 	
 
 
 	@Override
 	@Override
+	@Transactional
 	public PurchaseApCheck save(PurchaseApCheck purchaseApCheck) {
 	public PurchaseApCheck save(PurchaseApCheck purchaseApCheck) {
 		purchaseApCheck.setRecordDate(new Date());
 		purchaseApCheck.setRecordDate(new Date());
 		Date d = new Date();
 		Date d = new Date();
@@ -230,18 +234,60 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
 		purchaseApCheck.setRecorder(SystemSession.getUser().getUserName());
 		purchaseApCheck.setRecorder(SystemSession.getUser().getUserName());
 		Short number = 0;
 		Short number = 0;
 		List<PurchaseApCheckItem> items = new ArrayList<PurchaseApCheckItem>();
 		List<PurchaseApCheckItem> items = new ArrayList<PurchaseApCheckItem>();
+		//保存成功的同时来源单据更新一下
+		List<SourceForApcheck> sources = new ArrayList<>();
 		for (PurchaseApCheckItem item : purchaseApCheck.getItems()) {
 		for (PurchaseApCheckItem item : purchaseApCheck.getItems()) {
+			SourceForApcheck source = new SourceForApcheck(item);
+			sources.add(source);
 			item.setNumber(++number);
 			item.setNumber(++number);
 			item.setApCheck(purchaseApCheck);
 			item.setApCheck(purchaseApCheck);
 			items.add(item);
 			items.add(item);
 		}
 		}
+		updateSourceInfo(sources);
 		items = purchaseApCheckItemDao.save(items);
 		items = purchaseApCheckItemDao.save(items);
-		if( ! CollectionUtils.isEmpty(items)) {
+		if (!CollectionUtils.isEmpty(items)) {
 			ContextUtils.publishEvent(new PurchaseApCheckSaveEvent(PurchaseApCheckItem.distinct(items)));
 			ContextUtils.publishEvent(new PurchaseApCheckSaveEvent(PurchaseApCheckItem.distinct(items)));
 		}
 		}
 		// TODO 把items转成主记录的形式
 		// TODO 把items转成主记录的形式
 		return purchaseApCheck;
 		return purchaseApCheck;
 	}
 	}
+	
+	public boolean updateSourceInfo(List<SourceForApcheck> list) {
+		if(!CollectionUtils.isEmpty(list)) {
+			for(SourceForApcheck source : list) {
+				if(source.hasInfo()) {
+					String idName = null;
+					String yCheckQtyName = null;
+					if (source.getSourceTable().equals("purc$returnitem")) {
+						idName = "pai_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";
+					}
+					String sql = "update " + source.getSourceTable() + " set " + yCheckQtyName + " = " + source.getNewYCheckQty() + " where "
+							+ idName + " = " + source.getSourceId();
+					jdbcTemplate.execute(sql);
+				} else {
+					throw new IllegalOperatorException("保存失败!");
+				}
+			}
+			return true;
+		}
+		throw new IllegalOperatorException("保存失败!");
+	}
 
 
 	@Override
 	@Override
 	public Page<PurchaseApCheck> findAllByPageInfo(final PageInfo pageInfo, final String keyword, SearchFilter searchFilter) {
 	public Page<PurchaseApCheck> findAllByPageInfo(final PageInfo pageInfo, final String keyword, SearchFilter searchFilter) {