Browse Source

改变附件数据结构

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@692 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
suntg 11 years ago
parent
commit
e0035c8d6f

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

@@ -6,7 +6,6 @@ import java.util.List;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
 
 import com.uas.platform.b2b.dao.AttachDao;
 import com.uas.platform.b2b.erp.model.QuotationDown;
@@ -28,14 +27,10 @@ public class QuotationDownServiceImpl implements QuotationDownService {
 		if (!CollectionUtils.isEmpty(inquiryItems)) {
 			for (PurchaseInquiryItem item : inquiryItems) {
 				QuotationDown down = new QuotationDown(item);
-				if (StringUtils.hasText(item.getInquiry().getAttach())) {
-					String[] attachIds = item.getInquiry().getAttach().split(",");
+				if (!CollectionUtils.isEmpty(item.getInquiry().getAttachs())) {
 					List<RemoteFile> files = new ArrayList<RemoteFile>();
-					for (String attachId : attachIds) {
-						Attach attach = attachDao.findOne(Long.parseLong(attachId));
-						if (attach != null) {
-							files.add(new RemoteFile(attach));
-						}
+					for (Attach attach : item.getInquiry().getAttachs()) {
+						files.add(new RemoteFile(attach));
 					}
 					down.setFiles(files);
 				}

+ 24 - 45
src/main/java/com/uas/platform/b2b/erp/service/impl/SaleSampleDownServiceImpl.java

@@ -6,7 +6,6 @@ import java.util.List;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
 
 import com.uas.platform.b2b.dao.AttachDao;
 import com.uas.platform.b2b.dao.PurchaseProofingSendDao;
@@ -35,14 +34,10 @@ public class SaleSampleDownServiceImpl implements SaleSampleDownService {
 		if(!CollectionUtils.isEmpty(proofingItems)) {
 			for(PurchaseProofingItem proofingItem : proofingItems) {
 				SaleSampleDown sampleDown = new SaleSampleDown(proofingItem);
-				if (StringUtils.hasText(proofingItem.getProofing().getAttach())) {
-					String[] attachIds = proofingItem.getProofing().getAttach().split(",");
+				if (!CollectionUtils.isEmpty(proofingItem.getProofing().getAttachs())) {
 					List<RemoteFile> files = new ArrayList<RemoteFile>();
-					for (String attachId : attachIds) {
-						Attach attach = attachDao.findOne(Long.parseLong(attachId));
-						if (attach != null) {
-							files.add(new RemoteFile(attach));
-						}
+					for (Attach attach : proofingItem.getProofing().getAttachs()) {
+						files.add(new RemoteFile(attach));
 					}
 					sampleDown.setFiles(files);
 				}
@@ -59,14 +54,10 @@ public class SaleSampleDownServiceImpl implements SaleSampleDownService {
 		if(!CollectionUtils.isEmpty(proofingSends)) {
 			for(PurchaseProofingSend proofingSend : proofingSends){
 				SaleSampleSend sampleSend = new SaleSampleSend(proofingSend);
-				if (StringUtils.hasText(proofingSend.getAttach())) {
-					String[] attachIds = proofingSend.getAttach().split(",");
+				if (!CollectionUtils.isEmpty(proofingSend.getAttachs())) {
 					List<RemoteFile> files = new ArrayList<RemoteFile>();
-					for (String attachId : attachIds) {
-						Attach attach = attachDao.findOne(Long.parseLong(attachId));
-						if (attach != null) {
-							files.add(new RemoteFile(attach));
-						}
+					for (Attach attach : proofingSend.getAttachs()) {
+						files.add(new RemoteFile(attach));
 					}
 					sampleSend.setFiles(files);
 				}
@@ -95,49 +86,37 @@ public class SaleSampleDownServiceImpl implements SaleSampleDownService {
 		if(!CollectionUtils.isEmpty(proofingApprovals)) {
 			for(PurchaseProofingApproval proofingApproval : proofingApprovals) {
 				SaleSampleApproval approval = new SaleSampleApproval(proofingApproval);
-				if (StringUtils.hasText(proofingApproval.getAttach())) {
-					String[] attachIds = proofingApproval.getAttach().split(",");
+				//附件
+				if (!CollectionUtils.isEmpty(proofingApproval.getAttachs())) {
 					List<RemoteFile> files = new ArrayList<RemoteFile>();
-					for (String attachId : attachIds) {
-						Attach attach = attachDao.findOne(Long.parseLong(attachId));
-						if (attach != null) {
-							files.add(new RemoteFile(attach));
-						}
+					for (Attach attach : proofingApproval.getAttachs()) {
+						files.add(new RemoteFile(attach));
 					}
 					approval.setFiles(files);
 				}
-				if (StringUtils.hasText(proofingApproval.getPrdattach())) {
-					String[] attachIds = proofingApproval.getPrdattach().split(",");
+				//prd附件
+				if (!CollectionUtils.isEmpty(proofingApproval.getPrdAttachs())) {
 					List<RemoteFile> files = new ArrayList<RemoteFile>();
-					for (String attachId : attachIds) {
-						Attach attach = attachDao.findOne(Long.parseLong(attachId));
-						if (attach != null) {
-							files.add(new RemoteFile(attach));
-						}
+					for (Attach attach : proofingApproval.getPrdAttachs()) {
+						files.add(new RemoteFile(attach));
 					}
 					approval.setPrdfiles(files);
 				}
-				if (StringUtils.hasText(proofingApproval.getPpdattach())) {
-					String[] attachIds = proofingApproval.getPpdattach().split(",");
+				//pad附件
+				if (!CollectionUtils.isEmpty(proofingApproval.getPadAttachs())) {
 					List<RemoteFile> files = new ArrayList<RemoteFile>();
-					for (String attachId : attachIds) {
-						Attach attach = attachDao.findOne(Long.parseLong(attachId));
-						if (attach != null) {
-							files.add(new RemoteFile(attach));
-						}
+					for (Attach attach : proofingApproval.getPadAttachs()) {
+						files.add(new RemoteFile(attach));
 					}
-					approval.setPpdfiles(files);
+					approval.setPadfiles(files);
 				}
-				if (StringUtils.hasText(proofingApproval.getPadattach())) {
-					String[] attachIds = proofingApproval.getPadattach().split(",");
+				//ppd附件
+				if (!CollectionUtils.isEmpty(proofingApproval.getPpdAttachs())) {
 					List<RemoteFile> files = new ArrayList<RemoteFile>();
-					for (String attachId : attachIds) {
-						Attach attach = attachDao.findOne(Long.parseLong(attachId));
-						if (attach != null) {
-							files.add(new RemoteFile(attach));
-						}
+					for (Attach attach : proofingApproval.getPpdAttachs()) {
+						files.add(new RemoteFile(attach));
 					}
-					approval.setPadfiles(files);
+					approval.setPpdfiles(files);
 				}
 				saleSampleApprovals.add(approval);
 			}

+ 10 - 1
src/main/java/com/uas/platform/b2b/service/PurchaseProofingService.java

@@ -46,6 +46,14 @@ public interface PurchaseProofingService {
 	 */
 	public Page<PurchaseProofingItem> findAllByPageInfo(PageInfo pageInfo);
 	
+	/**
+	 * 根据送样申请单明细id获取对应的送样单
+	 * 
+	 * @param pageInfo
+	 * @return
+	 */
+	public List<PurchaseProofingSend> findSendsByItemId(Long itemId);
+	
 
 	/**
 	 * 用客户打样申请单ID查找客户打样申请单
@@ -58,8 +66,9 @@ public interface PurchaseProofingService {
 	/**
 	 * 送样(只供b2b平台上操作调用,因为平台上只能一个一个进行回复)
 	 * @param proofingSend
+	 * @return 
 	 */
-	public void send(PurchaseProofingSend proofingSend);
+	public PurchaseProofingSend send(PurchaseProofingSend proofingSend);
 
 	/**
 	 * 送样(只供从卖方ERP上传到平台时操作调用,因为平台上只能一个一个进行回复)

+ 3 - 2
src/main/java/com/uas/platform/b2b/service/impl/AttachServiceImpl.java

@@ -6,6 +6,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -68,7 +69,7 @@ public class AttachServiceImpl implements AttachService {
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
-		return new Attach(filename, path, description, size);
+		return new Attach(filename, path, description, size, new Date());
 	}
 
 	public String randomFileName(String fileName, String parentDir) {
@@ -89,7 +90,7 @@ public class AttachServiceImpl implements AttachService {
 					File file = new File(fileMap.get(entry));
 					if (file.exists()) {
 						Map<String, Object> params = entryParams.get(entry);
-						Attach attach = new Attach(String.valueOf(params.get("name")), fileMap.get(entry), description, file.length());
+						Attach attach = new Attach(String.valueOf(params.get("name")), fileMap.get(entry), description, file.length(), new Date());
 						attach = attachDao.save(attach);
 						attach.setSourceId(params.get("sourceId").toString());
 						attachs.add(attach);

+ 12 - 9
src/main/java/com/uas/platform/b2b/service/impl/PurchaseInquiryServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.platform.b2b.service.impl;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -15,8 +16,8 @@ import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
 
+import com.uas.platform.b2b.dao.AttachDao;
 import com.uas.platform.b2b.dao.PurchaseInquiryDao;
 import com.uas.platform.b2b.dao.PurchaseInquiryItemDao;
 import com.uas.platform.b2b.dao.PurchaseInquiryReplyDao;
@@ -45,6 +46,9 @@ public class PurchaseInquiryServiceImpl implements PurchaseInquiryService {
 
 	@Autowired
 	private PurchaseInquiryDao purchaseInquiryDao;
+	
+	@Autowired
+	private AttachDao attachDao;
 
 	@Override
 	public void save(List<PurchaseInquiryItem> inquiryItems) {
@@ -266,22 +270,21 @@ public class PurchaseInquiryServiceImpl implements PurchaseInquiryService {
 
 	@Override
 	public void saveAttach(List<Attach> attachs) {
+		List<Attach> validAttachs = new ArrayList<Attach>();
 		if (!CollectionUtils.isEmpty(attachs)) {
 			long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (Attach attach : attachs) {
 				List<PurchaseInquiry> inquiries = purchaseInquiryDao.findByEnUUAndSourceId(enUU, Long.parseLong(attach.getSourceId()));
 				if (!CollectionUtils.isEmpty(inquiries)) {
 					PurchaseInquiry inquiry = inquiries.get(0);
-					String atId = inquiry.getAttach();
-					if (!StringUtils.hasText(atId))
-						atId = "";
-					else
-						atId += ",";
-					atId += attach.getId();
-					inquiry.setAttach(atId);
-					purchaseInquiryDao.save(inquiry);
+					attach.setRelativeTable("purc$inquiry");
+					attach.setRelativeKey(inquiry.getId());
+					validAttachs.add(attach);
 				}
 			}
 		}
+		if (!CollectionUtils.isEmpty(validAttachs)) {
+			attachDao.save(validAttachs);
+		}
 	}
 }

+ 57 - 55
src/main/java/com/uas/platform/b2b/service/impl/PurchaseProofingServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.platform.b2b.service.impl;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -14,8 +15,8 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
 
+import com.uas.platform.b2b.dao.AttachDao;
 import com.uas.platform.b2b.dao.PurchaseProofingApprovalDao;
 import com.uas.platform.b2b.dao.PurchaseProofingDao;
 import com.uas.platform.b2b.dao.PurchaseProofingItemDao;
@@ -47,6 +48,9 @@ public class PurchaseProofingServiceImpl implements PurchaseProofingService{
 	@Autowired
 	private PurchaseProofingApprovalDao purchaseProofingApprovalDao;
 	
+	@Autowired
+	private AttachDao attachDao;
+	
 	@Override
 	public void save(List<PurchaseProofingItem> proofingItems) {
 		purchaseProofingItemDao.save(proofingItems);
@@ -65,128 +69,120 @@ public class PurchaseProofingServiceImpl implements PurchaseProofingService{
 
 	@Override
 	public void saveAttach(List<Attach> attachs) {
+		List<Attach>  validAttachs = new ArrayList<Attach>();
 		if (!CollectionUtils.isEmpty(attachs)) {
 			long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (Attach attach : attachs) {
 				List<PurchaseProofing> proofings = purchaseProofingDao.findByEnUUAndCode(enUU, attach.getSourceId());
 				if (!CollectionUtils.isEmpty(proofings)) {
 					PurchaseProofing proofing = proofings.get(0);
-					String atId = proofing.getAttach();
-					if (!StringUtils.hasText(atId))
-						atId = "";
-					else
-						atId += ",";
-					atId += attach.getId();
-					proofing.setAttach(atId);
-					purchaseProofingDao.save(proofing);
+					attach.setRelativeTable("purc$proofing");
+					attach.setRelativeKey(proofing.getId());
+					validAttachs.add(attach);
 				}
 			}
 		}
+		if(!CollectionUtils.isEmpty(validAttachs))
+			attachDao.save(validAttachs);
 	}
 	
 	@Override
 	public void saveSendAttach(List<Attach> attachs) {
+		List<Attach>  validAttachs = new ArrayList<Attach>();
 		if (!CollectionUtils.isEmpty(attachs)) {
 			long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (Attach attach : attachs) {
 				List<PurchaseProofingSend> proofingSends = purchaseProofingSendDao.findByProofingItemVendUUAndCode(enUU, attach.getSourceId());
 				if (!CollectionUtils.isEmpty(proofingSends)) {
 					PurchaseProofingSend proofingSend = proofingSends.get(0);
-					String atId = proofingSend.getAttach();
-					if (!StringUtils.hasText(atId))
-						atId = "";
-					else
-						atId += ",";
-					atId += attach.getId();
-					proofingSend.setAttach(atId);
-					purchaseProofingSendDao.save(proofingSend);
+					attach.setRelativeTable("purc$proofingsend");
+					attach.setRelativeKey(proofingSend.getId());
+					validAttachs.add(attach);
 				}
 			}
 		}
+		if(!CollectionUtils.isEmpty(validAttachs))
+			attachDao.save(validAttachs);
 	}
 
 	@Override
 	public void saveApprovalAttach(List<Attach> attachs) {
+		List<Attach> validAttachs = new ArrayList<Attach>();
 		if (!CollectionUtils.isEmpty(attachs)) {
 			long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (Attach attach : attachs) {
 				List<PurchaseProofingApproval> approvals = purchaseProofingApprovalDao.findByEnUUAndCode(enUU, attach.getSourceId());
 				if (!CollectionUtils.isEmpty(approvals)) {
 					PurchaseProofingApproval approval = approvals.get(0);
-					String atId = approval.getAttach();
-					if (!StringUtils.hasText(atId))
-						atId = "";
-					else
-						atId += ",";
-					atId += attach.getId();
-					approval.setAttach(atId);
-					purchaseProofingApprovalDao.save(approval);
+					attach.setRelativeTable("purc$proofingapproval");
+					attach.setRelativeKey(approval.getId());
+					validAttachs.add(attach);
 				}
 			}
 		}
+		if (!CollectionUtils.isEmpty(validAttachs)) {
+			attachDao.save(validAttachs);
+		}
 	}
 
 	@Override
 	public void saveApprovalPrdattach(List<Attach> attachs) {
+		List<Attach> validAttachs = new ArrayList<Attach>();
 		if (!CollectionUtils.isEmpty(attachs)) {
 			long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (Attach attach : attachs) {
 				List<PurchaseProofingApproval> approvals = purchaseProofingApprovalDao.findByEnUUAndCode(enUU, attach.getSourceId());
 				if (!CollectionUtils.isEmpty(approvals)) {
 					PurchaseProofingApproval approval = approvals.get(0);
-					String atId = approval.getPrdattach();
-					if (!StringUtils.hasText(atId))
-						atId = "";
-					else
-						atId += ",";
-					atId += attach.getId();
-					approval.setPrdattach(atId);
-					purchaseProofingApprovalDao.save(approval);
+					attach.setRelativeTable("purc$proofingapproval_prd");
+					attach.setRelativeKey(approval.getId());
+					validAttachs.add(attach);
 				}
 			}
 		}
+		if (!CollectionUtils.isEmpty(validAttachs)) {
+			attachDao.save(validAttachs);
+		}
 	}
 
 	@Override
 	public void saveApprovalPadattach(List<Attach> attachs) {
+		List<Attach> validAttachs = new ArrayList<Attach>();
 		if (!CollectionUtils.isEmpty(attachs)) {
 			long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (Attach attach : attachs) {
 				List<PurchaseProofingApproval> approvals = purchaseProofingApprovalDao.findByEnUUAndCode(enUU, attach.getSourceId());
 				if (!CollectionUtils.isEmpty(approvals)) {
 					PurchaseProofingApproval approval = approvals.get(0);
-					String atId = approval.getPadattach();
-					if (!StringUtils.hasText(atId))
-						atId = "";
-					else
-						atId += ",";
-					atId += attach.getId();
-					approval.setPadattach(atId);
-					purchaseProofingApprovalDao.save(approval);
+					attach.setRelativeTable("purc$proofingapproval_pad");
+					attach.setRelativeKey(approval.getId());
+					validAttachs.add(attach);
 				}
 			}
 		}
+		if (!CollectionUtils.isEmpty(validAttachs)) {
+			attachDao.save(validAttachs);
+		}
 	}
 
 	@Override
 	public void saveApprovalPpdattach(List<Attach> attachs) {
+		List<Attach> validAttachs = new ArrayList<Attach>();
 		if (!CollectionUtils.isEmpty(attachs)) {
 			long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (Attach attach : attachs) {
 				List<PurchaseProofingApproval> approvals = purchaseProofingApprovalDao.findByEnUUAndCode(enUU, attach.getSourceId());
 				if (!CollectionUtils.isEmpty(approvals)) {
 					PurchaseProofingApproval approval = approvals.get(0);
-					String atId = approval.getPpdattach();
-					if (!StringUtils.hasText(atId))
-						atId = "";
-					else
-						atId += ",";
-					atId += attach.getId();
-					approval.setPpdattach(atId);
-					purchaseProofingApprovalDao.save(approval);
+					attach.setRelativeTable("purc$proofingapproval_ppd");
+					attach.setRelativeKey(approval.getId());
+					validAttachs.add(attach);
 				}
 			}
 		}
+		if (!CollectionUtils.isEmpty(validAttachs)) {
+			attachDao.save(validAttachs);
+		}
 	}
 
 	@Override
@@ -223,8 +219,8 @@ public class PurchaseProofingServiceImpl implements PurchaseProofingService{
 	}
 
 	@Override
-	public void send(PurchaseProofingSend proofingSend) {
-		send(proofingSend, true);
+	public PurchaseProofingSend send(PurchaseProofingSend proofingSend) {
+		return send(proofingSend, true);
 	}
 
 	@Override
@@ -235,7 +231,7 @@ public class PurchaseProofingServiceImpl implements PurchaseProofingService{
 		}
 	}
 	
-	public void send(PurchaseProofingSend proofingSend, boolean isB2b) {
+	public PurchaseProofingSend send(PurchaseProofingSend proofingSend, boolean isB2b) {
 		if(isB2b) {//平台上的操作
 			proofingSend.setDate(new Date());
 			//设置传输到买方ERP的状态为未上传
@@ -252,7 +248,7 @@ public class PurchaseProofingServiceImpl implements PurchaseProofingService{
 			if(isB2b)//b2B上操作,报错
 				throw new IllegalOperatorException("客户打样申请已送样,不可重复送样");
 			else //卖方ERP的操作数据上传过来,忽略
-				return;
+				return null;
 		}
 		List<PurchaseProofingSend> proofingSends = purchaseProofingSendDao.findByProofingItemVendUUAndCode(
 				SystemSession.getUser().getEnterprise().getUu(), proofingSend.getCode());
@@ -260,12 +256,12 @@ public class PurchaseProofingServiceImpl implements PurchaseProofingService{
 			if(isB2b)//b2B上操作,报错
 				throw new IllegalOperatorException("送样单号已存在");
 			else //卖方ERP的操作数据上传过来,忽略
-				return;
+				return null;
 		}
 		proofingItem.setStatus((short) Status.SEND.value());
 		proofingSend.setProofingItem(proofingItem);
 		proofingSend.setSendQty(proofingItem.getQty());
-		purchaseProofingSendDao.save(proofingSend);
+		proofingSend = purchaseProofingSendDao.save(proofingSend);
 		purchaseProofingItemDao.save(proofingItem);
 		if(proofingItem.getProofing().getUserUU() != null) {
 			//推送给客户打样申请申请人||客户管理员账号
@@ -274,6 +270,7 @@ public class PurchaseProofingServiceImpl implements PurchaseProofingService{
 			XingePusher.pushSingleAccountIOS(proofingItem.getProofing().getUserUU().toString(), 
 					"供应商给你送样了  " + "供应商:" + SystemSession.getUser().getEnterprise().getEnName());
 		}
+		return proofingSend;
 	}
 
 	@Override
@@ -345,5 +342,10 @@ public class PurchaseProofingServiceImpl implements PurchaseProofingService{
 		}
 	}
 
+	@Override
+	public List<PurchaseProofingSend> findSendsByItemId(Long itemId) {
+		return purchaseProofingSendDao.findByProofingItemId(itemId);
+	}
+
 
 }