Browse Source

客户打样申请+送样

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

+ 68 - 0
src/main/java/com/uas/platform/b2b/service/PurchaseProofingService.java

@@ -0,0 +1,68 @@
+package com.uas.platform.b2b.service;
+
+import java.util.List;
+
+import org.springframework.data.domain.Page;
+
+import com.uas.platform.b2b.model.Attach;
+import com.uas.platform.b2b.model.PurchaseProofingItem;
+import com.uas.platform.b2b.model.PurchaseProofingSend;
+import com.uas.platform.core.model.PageInfo;
+
+public interface PurchaseProofingService {
+
+	/**
+	 * 批量保存、修改客户打样申请单
+	 * 
+	 * @param changeItems
+	 * @return
+	 */
+	public void save(List<PurchaseProofingItem> proofingItems);
+	
+	/**
+	 * 保存客户打样申请单附件
+	 * @param attachs
+	 */
+	public void saveAttach(List<Attach> attachs);
+	
+	/**
+	 * 获取没有上传到卖家ERP的打样申请单
+	 * @return
+	 */
+	public List<PurchaseProofingItem> findNotUploadProofing();
+	
+	/**
+	 * 成功将平台上的客户打样申请单上传到卖家ERP后修改状态为已上传
+	 * @param idArray
+	 */
+	public void uploadProofingSuccess(String[] idArray);
+	
+	/**
+	 * 分页查找客户打样申请
+	 * 
+	 * @param pageInfo
+	 * @return
+	 */
+	public Page<PurchaseProofingItem> findAllByPageInfo(PageInfo pageInfo);
+	
+
+	/**
+	 * 用客户打样申请单ID查找客户打样申请单
+	 * 
+	 * @param id
+	 * @return
+	 */
+	public PurchaseProofingItem findById(Long id);
+	
+	/**
+	 * 送样(只供b2b平台上操作调用,因为平台上只能一个一个进行回复)
+	 * @param proofingSend
+	 */
+	public void send(PurchaseProofingSend proofingSend);
+
+	/**
+	 * 送样(只供从卖方ERP上传到平台时操作调用,因为平台上只能一个一个进行回复)
+	 * @param proofingSend
+	 */
+	public void send(List<PurchaseProofingSend> proofingSend);
+}

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

@@ -91,7 +91,7 @@ public class AttachServiceImpl implements AttachService {
 						Map<String, Object> params = entryParams.get(entry);
 						Attach attach = new Attach(String.valueOf(params.get("name")), fileMap.get(entry), description, file.length());
 						attach = attachDao.save(attach);
-						attach.setSourceId(Long.parseLong(params.get("sourceId").toString()));
+						attach.setSourceId(params.get("sourceId").toString());
 						attachs.add(attach);
 					}
 				}

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

@@ -269,7 +269,7 @@ public class PurchaseInquiryServiceImpl implements PurchaseInquiryService {
 		if (!CollectionUtils.isEmpty(attachs)) {
 			long enUU = SystemSession.getUser().getEnterprise().getUu();
 			for (Attach attach : attachs) {
-				List<PurchaseInquiry> inquiries = purchaseInquiryDao.findByEnUUAndSourceId(enUU, attach.getSourceId());
+				List<PurchaseInquiry> inquiries = purchaseInquiryDao.findByEnUUAndSourceId(enUU, Long.parseLong(attach.getSourceId()));
 				if (!CollectionUtils.isEmpty(inquiries)) {
 					PurchaseInquiry inquiry = inquiries.get(0);
 					String atId = inquiry.getAttach();

+ 159 - 0
src/main/java/com/uas/platform/b2b/service/impl/PurchaseProofingServiceImpl.java

@@ -0,0 +1,159 @@
+package com.uas.platform.b2b.service.impl;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+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.PurchaseProofingDao;
+import com.uas.platform.b2b.dao.PurchaseProofingItemDao;
+import com.uas.platform.b2b.dao.PurchaseProofingSendDao;
+import com.uas.platform.b2b.model.Attach;
+import com.uas.platform.b2b.model.PurchaseProofing;
+import com.uas.platform.b2b.model.PurchaseProofingItem;
+import com.uas.platform.b2b.model.PurchaseProofingSend;
+import com.uas.platform.b2b.service.PurchaseProofingService;
+import com.uas.platform.b2b.support.SystemSession;
+import com.uas.platform.b2b.support.XingePusher;
+import com.uas.platform.core.exception.IllegalOperatorException;
+import com.uas.platform.core.model.PageInfo;
+import com.uas.platform.core.model.Status;
+
+@Service
+public class PurchaseProofingServiceImpl implements PurchaseProofingService{
+	
+	@Autowired
+	private PurchaseProofingItemDao purchaseProofingItemDao;
+	
+	@Autowired
+	private PurchaseProofingDao purchaseProofingDao;
+	
+	@Autowired
+	private PurchaseProofingSendDao purchaseProofingSendDao;
+	
+	@Override
+	public void save(List<PurchaseProofingItem> proofingItems) {
+		purchaseProofingItemDao.save(proofingItems);
+		//发送推送消息
+		for(PurchaseProofingItem proofingItem : proofingItems) {
+			//每个明细发一个
+			if(proofingItem.getVendUserUU() != null) {
+				XingePusher.pushSingleAccountAndroid(proofingItem.getVendUserUU().toString(), 
+						"新增客户的打样申请单", "物料:" + proofingItem.getProofing().getProduct().getTitle(),
+						null);
+				XingePusher.pushSingleAccountIOS(proofingItem.getVendUserUU().toString(),
+						"新增客户的打样申请单" + "  物料:" + proofingItem.getProofing().getProduct().getTitle());
+			}
+		}
+	}
+
+	@Override
+	public void saveAttach(List<Attach> attachs) {
+		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);
+				}
+			}
+		}
+	}
+
+	@Override
+	public List<PurchaseProofingItem> findNotUploadProofing() {
+		return purchaseProofingItemDao.findByVendUUAndSendStatus(SystemSession.getUser().getEnterprise().getUu(), 
+				(short) Status.NOT_UPLOAD.value());
+	}
+
+	@Override
+	public void uploadProofingSuccess(String[] idArray) {
+		for(String id : idArray) {
+			PurchaseProofingItem proofingItem = purchaseProofingItemDao.findOne(Long.parseLong(id));
+			if(proofingItem != null) {
+				proofingItem.setSendStatus((short) Status.DOWNLOADED.value());
+				purchaseProofingItemDao.save(proofingItem);
+			}
+		}
+	}
+
+	@Override
+	public Page<PurchaseProofingItem> findAllByPageInfo(final PageInfo pageInfo) {
+		return purchaseProofingItemDao.findAll(new Specification<PurchaseProofingItem>() {
+
+			public Predicate toPredicate(Root<PurchaseProofingItem> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
+				query.where(pageInfo.getPredicates(root, query, builder));
+				return null;
+			}
+		}, pageInfo);
+	}
+
+	@Override
+	public PurchaseProofingItem findById(Long id) {
+		return purchaseProofingItemDao.findOne(id);
+	}
+
+	@Override
+	public void send(PurchaseProofingSend proofingSend) {
+		send(proofingSend, true);
+	}
+
+	@Override
+	@Transactional
+	public void send(List<PurchaseProofingSend> proofingSend) {
+		for(PurchaseProofingSend send : proofingSend) {
+			send(send, false);
+		}
+	}
+	
+	public void send(PurchaseProofingSend proofingSend, boolean isB2b) {
+		if(isB2b) {//平台上的操作
+			proofingSend.setDate(new Date());
+			//设置传输到买方ERP的状态为未上传
+			proofingSend.setSendStatus((short) Status.NOT_UPLOAD.value());
+			//设置传输到卖方ERP的状态为未上传
+			proofingSend.setBackStatus((short) Status.NOT_UPLOAD.value());
+			proofingSend.setRecorder(SystemSession.getUser().getUserName());
+		}//从卖方ERP传输过来的单据在类型转换时设置好了状态,所以此处不需要设置
+		PurchaseProofingItem proofingItem = purchaseProofingItemDao.findOne(proofingSend.getProofingItem().getId());
+		if(proofingItem == null) {
+			throw new IllegalOperatorException("不存在的客户打样申请");
+		}
+		if(proofingItem.getStatus() == Status.SEND.value()) {
+			throw new IllegalOperatorException("客户打样申请已送样,不可重复送样");
+		}
+		proofingItem.setStatus((short) Status.SEND.value());
+		proofingSend.setProofingItem(proofingItem);
+		proofingSend.setSendQty(proofingItem.getQty());
+		purchaseProofingSendDao.save(proofingSend);
+		purchaseProofingItemDao.save(proofingItem);
+		if(proofingItem.getProofing().getUserUU() != null) {
+			//推送给客户打样申请申请人||客户管理员账号
+			XingePusher.pushSingleAccountAndroid(proofingItem.getProofing().getUserUU().toString(), 
+					"供应商给你送样了", "供应商:" + SystemSession.getUser().getEnterprise().getEnName(), null);
+			XingePusher.pushSingleAccountIOS(proofingItem.getProofing().getUserUU().toString(), 
+					"供应商给你送样了  " + "供应商:" + SystemSession.getUser().getEnterprise().getEnName());
+		}
+	}
+
+
+}