|
|
@@ -323,6 +323,28 @@ public class InquiryForSaleServiceImpl implements InquiryForSaleService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
private PublicInquiryItem SaveInquiryItems(PublicInquiry inquiry, PublicInquiryItem inquiryItem) throws Exception {
|
|
|
+ // 计算合计价格 dongbw 2018年9月5日 15:08:24 bom求购明细价格分析需要
|
|
|
+ Double sumPrice = 0d;
|
|
|
+ Double needQty = inquiryItem.getNeedquantity();
|
|
|
+ Double maxQty = 0d;
|
|
|
+ Double maxPrice = 0d;
|
|
|
+ List<PublicInquiryReply> replies = inquiryItem.getReplies();
|
|
|
+ for (int i = 0; i < replies.size(); i++) {
|
|
|
+ maxQty = replies.get(i).getLapQty();
|
|
|
+ maxPrice = replies.get(i).getPrice();
|
|
|
+ if (needQty < maxQty) {
|
|
|
+ if (i == 0) {
|
|
|
+ sumPrice = replies.get(i).getPrice() * needQty;
|
|
|
+ } else {
|
|
|
+ sumPrice = replies.get(i - 1).getPrice() * needQty;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (needQty > maxQty) {
|
|
|
+ sumPrice = maxPrice * needQty;
|
|
|
+ }
|
|
|
+ inquiryItem.setSumPrice(sumPrice);
|
|
|
long start = System.currentTimeMillis();
|
|
|
Set<PublicInquiryItem> items = new HashSet<PublicInquiryItem>();
|
|
|
int number = 1;
|
|
|
@@ -342,7 +364,7 @@ public class InquiryForSaleServiceImpl implements InquiryForSaleService {
|
|
|
inquiryItem.setEndDate(inquiry.getEndDate());
|
|
|
}
|
|
|
inquiryItem.setBusinessCode(enterprise.getBusinesscode());
|
|
|
- inquiryItem.setDate(new Date(System.currentTimeMillis()));
|
|
|
+ inquiryItem.setDate(inquiry.getDate());
|
|
|
inquiryItem.setOfferTime(new Date(System.currentTimeMillis()));
|
|
|
inquiryItem.setInquiry(inquiry);
|
|
|
inquiryItem.setNumber((short) number);
|
|
|
@@ -475,6 +497,7 @@ public class InquiryForSaleServiceImpl implements InquiryForSaleService {
|
|
|
inquiryItem.setReplies(replies);
|
|
|
inquiryItem.setCurrency(currency);
|
|
|
inquiryItem.setTaxrate(taxrate);
|
|
|
+
|
|
|
// 先判断客户询价单是否存在这张单据
|
|
|
if (CollectionUtils.isEmpty(saleInquiries)) {
|
|
|
inquiry = new PublicInquiry(item.getInquiry());
|
|
|
@@ -708,58 +731,117 @@ public class InquiryForSaleServiceImpl implements InquiryForSaleService {
|
|
|
|
|
|
@Override
|
|
|
public ModelMap saveQuote(PublicInquiryItem publicInquiryItem) {
|
|
|
- long start = System.currentTimeMillis();
|
|
|
ModelMap result = new ModelMap();
|
|
|
result.put("success", false);
|
|
|
- // 判断报价人信息
|
|
|
- if (StringUtils.isEmpty(publicInquiryItem) || StringUtils.isEmpty(publicInquiryItem.getVendUU()) || StringUtils.isEmpty(publicInquiryItem.getVendUserUU())) {
|
|
|
- result.put("message", "报价人信息不能为空");
|
|
|
+ // 验证报价单信息
|
|
|
+ if (validatePublicItem(publicInquiryItem, result)) {
|
|
|
return result;
|
|
|
}
|
|
|
+ Long sourceId;
|
|
|
+ if (null != publicInquiryItem.getSourceId()) {
|
|
|
+ sourceId = publicInquiryItem.getSourceId();
|
|
|
+ } else {
|
|
|
+ sourceId = publicInquiryItem.getId();
|
|
|
+ }
|
|
|
// 是否为自己的询价 并查询公共询价的信息
|
|
|
- PurcInquiryItemInfo item = inquiryItemInfoDao.findOne(publicInquiryItem.getSourceId());
|
|
|
- if (StringUtils.isEmpty(item)) {
|
|
|
- result.put("message", "找不到当前公共询价");
|
|
|
+ PurcInquiryItemInfo item = inquiryItemInfoDao.findOne(sourceId);
|
|
|
+ // 验证询价明细信息
|
|
|
+ if (validatePurcInquiryItem(publicInquiryItem, result, item)) {
|
|
|
return result;
|
|
|
}
|
|
|
- if (item.getInquiry() != null && item.getInquiry().getEnUU().equals(publicInquiryItem.getVendUU())) {
|
|
|
- result.put("message", "不能对自己单据进行报价");
|
|
|
+ // 验证是否重复
|
|
|
+ if (validateRepeat(publicInquiryItem, result)) {
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ // 拼接报价单主表
|
|
|
+ PublicInquiry inquiry = getPublicInquiry(item);
|
|
|
+
|
|
|
+ // 拼接报价单明细
|
|
|
+ PublicInquiryItem inquiryItem = getPublicInquiryItem(publicInquiryItem, item);
|
|
|
+ inquiryItem.setInquiry(inquiry);
|
|
|
+ // 调用回复询价接口
|
|
|
+ return replyInquiry(result, inquiry, inquiryItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateRepeat(PublicInquiryItem publicInquiryItem, ModelMap result) {
|
|
|
PublicInquiryItem existInquiry = infoDao.findByVendUUAndSourceId(publicInquiryItem.getVendUU(), publicInquiryItem.getSourceId());
|
|
|
// 是否重复报价
|
|
|
if (null != existInquiry) {
|
|
|
result.put("message", "该单据已报价,不能重复报价");
|
|
|
- return result;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validatePurcInquiryItem(PublicInquiryItem publicInquiryItem, ModelMap result, PurcInquiryItemInfo item) {
|
|
|
+ if (StringUtils.isEmpty(item)) {
|
|
|
+ result.put("message", "找不到当前公共询价");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (item.getInquiry() != null && item.getInquiry().getEnUU().equals(publicInquiryItem.getVendUU())) {
|
|
|
+ result.put("message", "不能对自己单据进行报价");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validatePublicItem(PublicInquiryItem publicInquiryItem, ModelMap result) {
|
|
|
+ // 判断报价人信息
|
|
|
+ if (StringUtils.isEmpty(publicInquiryItem) || StringUtils.isEmpty(publicInquiryItem.getVendUU()) || StringUtils.isEmpty(publicInquiryItem.getVendUserUU())) {
|
|
|
+ result.put("message", "报价人信息不能为空");
|
|
|
+ return true;
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(publicInquiryItem.getReplies())) {
|
|
|
result.put("message", "未找到报价信息");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 报价接口调用
|
|
|
+ * @param result ModelMap
|
|
|
+ * @param inquiry 报价明细
|
|
|
+ * @param inquiryItem 报价明细
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ModelMap replyInquiry(ModelMap result, PublicInquiry inquiry, PublicInquiryItem inquiryItem) {
|
|
|
+ try {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ inquiryItem = SaveInquiryItems(inquiry, inquiryItem);
|
|
|
+ System.out.println("报价总耗时:" + (System.currentTimeMillis() - start));
|
|
|
+ start = System.currentTimeMillis();
|
|
|
+ // 报价成功后保存到个人物料库中
|
|
|
+ if (null != inquiryItem && !StringUtils.isEmpty(inquiryItem.getInbrand()) && !StringUtils.isEmpty(inquiryItem.getCmpCode())) {
|
|
|
+ saveInquiryItemProduct(inquiryItem);
|
|
|
+ System.out.println("报价成功,添加个人库耗时:" + (System.currentTimeMillis() - start));
|
|
|
+ }
|
|
|
+ result.put("success", true);
|
|
|
+ result.put("content", inquiryItem);
|
|
|
+ return result;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ result.put("message", e.getMessage());
|
|
|
return result;
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接报价单主表
|
|
|
+ * @param item 询价明细
|
|
|
+ * @return 报价主表
|
|
|
+ */
|
|
|
+ private PublicInquiry getPublicInquiry(PurcInquiryItemInfo item) {
|
|
|
// 是否已经已经转报价
|
|
|
List<PublicInquiry> saleInquiries = inquiryDao.findByEnUUAndCode(item.getInquiry().getEnUU(), item.getInquiry().getCode());
|
|
|
PublicInquiry inquiry = new PublicInquiry();
|
|
|
- // 报价明细
|
|
|
- PublicInquiryItem inquiryItem = new PublicInquiryItem( item);
|
|
|
- inquiryItem.setMinOrderQty(publicInquiryItem.getMinOrderQty());
|
|
|
- inquiryItem.setMinPackQty(publicInquiryItem.getMinPackQty());
|
|
|
- inquiryItem.setLeadtime(publicInquiryItem.getLeadtime());
|
|
|
- inquiryItem.setQutoApp(publicInquiryItem.getQutoApp());
|
|
|
- inquiryItem.setReplies(publicInquiryItem.getReplies());
|
|
|
- inquiryItem.setCurrency(publicInquiryItem.getCurrency());
|
|
|
- inquiryItem.setTaxrate(publicInquiryItem.getTaxrate());
|
|
|
- inquiryItem.setVendUU(publicInquiryItem.getVendUU());
|
|
|
- inquiryItem.setVendUserUU(publicInquiryItem.getVendUserUU());
|
|
|
- inquiryItem.setReplaceCmpCode(publicInquiryItem.getReplaceCmpCode());
|
|
|
- inquiryItem.setReplaceBrand(publicInquiryItem.getReplaceBrand());
|
|
|
- inquiryItem.setReplaceSpec(publicInquiryItem.getReplaceSpec());
|
|
|
- inquiryItem.setIsReplace(publicInquiryItem.getIsReplace());
|
|
|
if (CollectionUtils.isEmpty(saleInquiries)) {
|
|
|
// 附件
|
|
|
if (!CollectionUtils.isEmpty(inquiry.getAttachs())) {
|
|
|
Set<Attach> attachs = new HashSet<Attach>();
|
|
|
- for (com.uas.ps.inquiry.model.Attach attach : inquiry.getAttachs()) {
|
|
|
- com.uas.ps.inquiry.model.Attach newAttach = new com.uas.ps.inquiry.model.Attach();
|
|
|
+ for (Attach attach : inquiry.getAttachs()) {
|
|
|
+ Attach newAttach = new Attach();
|
|
|
newAttach.setDate(new Date());
|
|
|
newAttach.setDescription(attach.getDescription());
|
|
|
newAttach.setName(attach.getName());
|
|
|
@@ -780,26 +862,51 @@ public class InquiryForSaleServiceImpl implements InquiryForSaleService {
|
|
|
inquiry = inquiryDao.save(inquiry);
|
|
|
} else { // 已经存在
|
|
|
inquiry = saleInquiries.get(0);
|
|
|
- inquiryItem.setInquiry(inquiry);
|
|
|
- }
|
|
|
- try {
|
|
|
- System.out.println("构造报价单耗时:" + (System.currentTimeMillis() - start));
|
|
|
- inquiryItem = SaveInquiryItems(inquiry, inquiryItem);
|
|
|
- System.out.println("报价总耗时:" + (System.currentTimeMillis() - start));
|
|
|
- start = System.currentTimeMillis();
|
|
|
- // 报价成功后保存到个人物料库中
|
|
|
- if (null != inquiryItem && !StringUtils.isEmpty(inquiryItem.getInbrand()) && !StringUtils.isEmpty(inquiryItem.getCmpCode())) {
|
|
|
- saveInquiryItemProduct(inquiryItem);
|
|
|
- System.out.println("报价成功,添加个人库耗时:" + (System.currentTimeMillis() - start));
|
|
|
- }
|
|
|
- result.put("success", true);
|
|
|
- result.put("content", inquiryItem);
|
|
|
- return result;
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- result.put("message", e.getMessage());
|
|
|
- return result;
|
|
|
}
|
|
|
+ return inquiry;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接报价明细
|
|
|
+ * @param publicInquiryItem 报价明细参数
|
|
|
+ * @param item 询价明细
|
|
|
+ * @return 报价明细
|
|
|
+ */
|
|
|
+ private PublicInquiryItem getPublicInquiryItem(PublicInquiryItem publicInquiryItem, PurcInquiryItemInfo item) {
|
|
|
+ // 报价明细
|
|
|
+ PublicInquiryItem inquiryItem = new PublicInquiryItem(item);
|
|
|
+ inquiryItem.setMinOrderQty(publicInquiryItem.getMinOrderQty());
|
|
|
+ inquiryItem.setMinPackQty(publicInquiryItem.getMinPackQty());
|
|
|
+ inquiryItem.setLeadtime(publicInquiryItem.getLeadtime());
|
|
|
+ inquiryItem.setQutoApp(publicInquiryItem.getQutoApp());
|
|
|
+ inquiryItem.setReplies(publicInquiryItem.getReplies());
|
|
|
+ inquiryItem.setCurrency(publicInquiryItem.getCurrency());
|
|
|
+ inquiryItem.setTaxrate(publicInquiryItem.getTaxrate());
|
|
|
+ inquiryItem.setVendUU(publicInquiryItem.getVendUU());
|
|
|
+ inquiryItem.setVendUserUU(publicInquiryItem.getVendUserUU());
|
|
|
+ inquiryItem.setReplaceCmpCode(publicInquiryItem.getReplaceCmpCode());
|
|
|
+ inquiryItem.setReplaceBrand(publicInquiryItem.getReplaceBrand());
|
|
|
+ inquiryItem.setReplaceSpec(publicInquiryItem.getReplaceSpec());
|
|
|
+ inquiryItem.setIsReplace(publicInquiryItem.getIsReplace());
|
|
|
+// // 计算合计价格 dongbw 2018年9月5日 15:08:24 bom求购明细价格分析需要
|
|
|
+// Double sumPrice = 0d;
|
|
|
+// Double needQty = inquiryItem.getNeedquantity();
|
|
|
+// List<PublicInquiryReply> replies = inquiryItem.getReplies();
|
|
|
+// for (int i = 0; i < replies.size(); i++) {
|
|
|
+// needQty = needQty - replies.get(i).getLapQty();
|
|
|
+// if (needQty > 0) {
|
|
|
+// if (i == 0) {
|
|
|
+// sumPrice += replies.get(i).getPrice() * replies.get(i).getLapQty();
|
|
|
+// } else {
|
|
|
+// sumPrice += replies.get(i).getPrice() * (replies.get(i).getLapQty() - replies.get(i - 1).getLapQty());
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// sumPrice += replies.get(i).getPrice() * needQty;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// inquiryItem.setSumPrice(sumPrice);
|
|
|
+ return inquiryItem;
|
|
|
}
|
|
|
|
|
|
private InquiryEnRemind itemConvertEnRemind(PurcInquiryItem item) {
|