|
|
@@ -8,7 +8,6 @@ import com.uas.platform.b2b.event.PurchaseInquiryItemSaveReleaseEvent;
|
|
|
import com.uas.platform.b2b.model.*;
|
|
|
import com.uas.platform.b2b.model.ProductInfo;
|
|
|
import com.uas.platform.b2b.ps.InquiryUtils;
|
|
|
-import com.uas.platform.b2b.ps.ProductUtils;
|
|
|
import com.uas.platform.b2b.service.AttachService;
|
|
|
import com.uas.platform.b2b.service.PurcInquiryService;
|
|
|
import com.uas.platform.b2b.support.SystemSession;
|
|
|
@@ -21,6 +20,7 @@ import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.PageParams;
|
|
|
import com.uas.platform.core.model.Status;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
@@ -38,6 +38,12 @@ import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
import java.util.*;
|
|
|
|
|
|
+/**
|
|
|
+ * 采购询价
|
|
|
+ *
|
|
|
+ * @author hejq
|
|
|
+ * @date 2018-07-24 10:21
|
|
|
+ */
|
|
|
@Service
|
|
|
public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
|
|
|
@@ -134,52 +140,13 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
if (!CollectionUtils.isEmpty(inquiryInfo.getInquiryItems())) {
|
|
|
for (PurcInquiryItem purcitem : inquiryInfo.getInquiryItems()) {
|
|
|
PurcInquiryItem item = new PurcInquiryItem();
|
|
|
- ProductInfo productInfo = new ProductInfo();
|
|
|
Enterprise vendorEn = enterpriseDao.findEnterpriseByUu(contact.getEnuu());
|
|
|
// 点击选择出来的,一般带有id
|
|
|
- if (purcitem.getProductId() != null) {
|
|
|
- Product product = productDao.findOne(purcitem.getProductId());
|
|
|
- BeanUtils.copyProperties(product, productInfo, ProductInfo.class);
|
|
|
- item.setProduct(productInfo);
|
|
|
- item.setProductId(product.getId());
|
|
|
- // 导入或手动输入的一般不带有id
|
|
|
- } else {
|
|
|
- List<Product> products = productDao.findByEnUUAndPcmpcodeAndPbrand(
|
|
|
- SystemSession.getUser().getEnterprise().getUu(), purcitem.getCmpCode(), purcitem.getBrand());
|
|
|
- Product product = new Product();
|
|
|
- if (products.size() > 0) {
|
|
|
- product = products.get(0);
|
|
|
- }
|
|
|
- // 存在直接选择
|
|
|
- if (product.getId() != null) {
|
|
|
- BeanUtils.copyProperties(product, productInfo, ProductInfo.class);
|
|
|
- item.setProduct(productInfo);
|
|
|
- item.setProductId(productInfo.getId());
|
|
|
- } else { // 不存在,插入物料
|
|
|
- product = new Product();
|
|
|
- product.setBrand(purcitem.getInbrand());
|
|
|
- product.setCmpCode(purcitem.getCmpCode());
|
|
|
- product.setSourceApp(SOURCERAPP);
|
|
|
- product.setCode(purcitem.getProdCode());
|
|
|
- product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- product.setTitle(purcitem.getProdTitle());
|
|
|
- product.setCmpUuId(purcitem.getProdCode());
|
|
|
- product.setUnit(purcitem.getUnit());
|
|
|
- product.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
- // 导入的物料这里没有填写规格
|
|
|
- product.setSpec(purcitem.getProdTitle());
|
|
|
- product.setCreateTime(new Date(System.currentTimeMillis()));
|
|
|
- Long proId = ProductUtils.updateOne(product);
|
|
|
- BeanUtils.copyProperties(product, productInfo, ProductInfo.class);
|
|
|
- item.setProduct(productInfo);
|
|
|
- item.setProductId(proId);
|
|
|
- }
|
|
|
- }
|
|
|
+ BeanUtils.copyProperties(purcitem, item, PurcInquiryItem.class);
|
|
|
item.setInquiry(inquiry);
|
|
|
item.setNumber(i);
|
|
|
item.setCurrency(contact.getCurrency());
|
|
|
item.setFromDate(new Date(System.currentTimeMillis()));
|
|
|
- item.setToDate(purcitem.getToDate());
|
|
|
// 币别为RMB税率16,其他税率为0
|
|
|
if (contact.getRate() != null) {
|
|
|
item.setTaxrate(contact.getRate());
|
|
|
@@ -190,12 +157,10 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
item.setTaxrate((float) 0);
|
|
|
}
|
|
|
}
|
|
|
- item.setRemark(purcitem.getRemark());
|
|
|
item.setVendUU(contact.getEnuu());
|
|
|
item.setStatus((short) Status.NOT_REPLY.value());
|
|
|
item.setVendUserUU(vendorEn.getEnAdminuu());
|
|
|
item.setIsOpen(inquiryInfo.getIsOpen());
|
|
|
- item.setNeedquantity(purcitem.getNeedquantity());
|
|
|
items.add(item);
|
|
|
i++;
|
|
|
}
|
|
|
@@ -227,17 +192,17 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
@Override
|
|
|
public ModelMap sumbit(Long id) {
|
|
|
ModelMap map = new ModelMap();
|
|
|
- Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- Long useruu = SystemSession.getUser().getUserUU();
|
|
|
+ Enterprise enterprise = SystemSession.getUser().getEnterprise();
|
|
|
+ User user = SystemSession.getUser();
|
|
|
PurcInquiry inquiry = inquiryDao.findOne(id);
|
|
|
PurchaseInquiry saleInquiry = new PurchaseInquiry();
|
|
|
saleInquiry.setDate(new Date());
|
|
|
saleInquiry.setCode(inquiry.getCode());
|
|
|
- saleInquiry.setEnUU(enuu);
|
|
|
- saleInquiry.setEnterprise(enterpriseDao.findEnterpriseInfoByUu(enuu));
|
|
|
- saleInquiry.setRecorder(SystemSession.getUser().getUserName());
|
|
|
- saleInquiry.setRecorderUU(useruu);
|
|
|
- saleInquiry.setAuditor(SystemSession.getUser().getUserName());
|
|
|
+ saleInquiry.setEnUU(enterprise.getUu());
|
|
|
+ saleInquiry.setEnterprise(enterpriseDao.findEnterpriseInfoByUu(enterprise.getUu()));
|
|
|
+ saleInquiry.setRecorder(user.getUserName());
|
|
|
+ saleInquiry.setRecorderUU(user.getUserUU());
|
|
|
+ saleInquiry.setAuditor(user.getUserName());
|
|
|
saleInquiry.setSourceApp(SOURCERAPP);
|
|
|
saleInquiry.setSourceId(id);
|
|
|
saleInquiry.setInvoice(inquiry.getInvoice());
|
|
|
@@ -278,6 +243,8 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
saleItem.setSourceId(item.getId());
|
|
|
saleItem.setCurrency(item.getCurrency());
|
|
|
saleItem.setNeedquantity(item.getNeedquantity());
|
|
|
+ ProductInfo productInfo = setProductInfo(item);
|
|
|
+ saleItem.setProduct(productInfo);
|
|
|
Set<PurchaseInquiryReply> replies = new HashSet<PurchaseInquiryReply>();
|
|
|
PurchaseInquiryReply reply = new PurchaseInquiryReply();
|
|
|
reply.setLapQty((double) 0);
|
|
|
@@ -294,7 +261,7 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
inquiry.setEnteryStatus(Status.ENABLED.value());
|
|
|
inquiryDao.save(inquiry);
|
|
|
saveUserOrders(purcitems);
|
|
|
- logger.log("询价单", "平台提交询价单", useruu, SystemSession.getUser().getIp());
|
|
|
+ logger.log("询价单", "平台提交询价单", user.getUserUU(), user.getIp());
|
|
|
map.put("success", "询价单提交成功");
|
|
|
} else {
|
|
|
map.put("error", "询价单提交失败");
|
|
|
@@ -302,6 +269,24 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 将询价物料信息赋值给采购询价物料信息
|
|
|
+ *
|
|
|
+ * @param item
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ProductInfo setProductInfo(PurcInquiryItem item) {
|
|
|
+ ProductInfo productInfo = new ProductInfo();
|
|
|
+ productInfo.setSpec(item.getSpec());
|
|
|
+ productInfo.setCode(item.getProdCode());
|
|
|
+ productInfo.setCmpCode(item.getCmpCode());
|
|
|
+ productInfo.setBrand(item.getInbrand());
|
|
|
+ productInfo.setId(item.getProductId());
|
|
|
+ productInfo.setUnit(item.getUnit());
|
|
|
+ productInfo.setTitle(item.getProdTitle());
|
|
|
+ return productInfo;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存
|
|
|
*
|
|
|
@@ -393,6 +378,7 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
pageInfo.filter("enUU", SystemSession.getUser().getEnterprise().getUu());
|
|
|
pageInfo.filter("enteryStatus", Status.UNAPPLY.value());
|
|
|
return inquiryDao.findAll(new Specification<PurcInquiry>() {
|
|
|
+ @Override
|
|
|
public Predicate toPredicate(Root<PurcInquiry> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
|
|
|
}
|
|
|
@@ -405,6 +391,7 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
pageInfo.filter("enUU", SystemSession.getUser().getEnterprise().getUu());
|
|
|
pageInfo.filter("enteryStatus", Status.ENABLED.value());
|
|
|
return inquiryDao.findAll(new Specification<PurcInquiry>() {
|
|
|
+ @Override
|
|
|
public Predicate toPredicate(Root<PurcInquiry> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
|
|
|
}
|
|
|
@@ -454,7 +441,8 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
ModelMap map = new ModelMap();
|
|
|
if (old == null) {
|
|
|
Set<Attach> attachs = new HashSet<Attach>();
|
|
|
- if (uploadItem.getFile() != null) {// 附件存在
|
|
|
+ // 附件存在
|
|
|
+ if (uploadItem.getFile() != null) {
|
|
|
Attach attach = attachService.upload(uploadItem, "productAttach", "平台询价上传传物料照片或附件");
|
|
|
if (attach == null) {
|
|
|
map.put("error", "文件太大");
|
|
|
@@ -465,7 +453,7 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
}
|
|
|
Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
Long useruu = SystemSession.getUser().getUserUU();
|
|
|
- if (inquiryInfo.getId() == null) {// 新增
|
|
|
+ if (inquiryInfo.getId() == null) {
|
|
|
BeanUtils.copyProperties(inquiryInfo, inquiry, PurcInquiry.class);
|
|
|
inquiry.setRecorder(SystemSession.getUser().getUserName());
|
|
|
inquiry.setRecorderUU(SystemSession.getUser().getUserUU());
|
|
|
@@ -480,59 +468,13 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
if (!CollectionUtils.isEmpty(inquiryInfo.getInquiryItems())) {
|
|
|
for (PurcInquiryItem purcitem : inquiryInfo.getInquiryItems()) {
|
|
|
PurcInquiryItem item = new PurcInquiryItem();
|
|
|
- Product product = new Product();
|
|
|
- ProductInfo productInfo = new ProductInfo();
|
|
|
- // 点击选择出来的,一般带有id
|
|
|
- if (purcitem.getProductId() != null) {
|
|
|
- product = productDao.findOne(purcitem.getProductId());
|
|
|
- BeanUtils.copyProperties(product, productInfo, ProductInfo.class);
|
|
|
- item.setProduct(productInfo);
|
|
|
- item.setProductId(productInfo.getId());
|
|
|
- } else {// 导入或手动输入的一般不带有id
|
|
|
- List<Product> productList = productDao.findByEnUUAndPcmpcodeAndPbrand(
|
|
|
- SystemSession.getUser().getEnterprise().getUu(), purcitem.getCmpCode(),
|
|
|
- purcitem.getInbrand());
|
|
|
- product = CollectionUtils.isEmpty(productList) ? null : productList.get(0);
|
|
|
- // 存在直接选择
|
|
|
- if (product != null) {
|
|
|
- BeanUtils.copyProperties(product, productInfo, ProductInfo.class);
|
|
|
- item.setProduct(productInfo);
|
|
|
- item.setProductId(productInfo.getId());
|
|
|
- } else { // 不存在,插入物料
|
|
|
- product = new Product();
|
|
|
- product.setBrand(purcitem.getInbrand());
|
|
|
- product.setCmpCode(purcitem.getCmpCode());
|
|
|
- product.setSourceApp(SOURCERAPP);
|
|
|
- product.setCode(purcitem.getProdCode());
|
|
|
- product.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- product.setTitle(purcitem.getProdTitle());
|
|
|
- product.setCmpUuId(purcitem.getProdCode());
|
|
|
- product.setUnit(purcitem.getUnit());
|
|
|
- product.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
- product.setSpec(purcitem.getProdTitle());
|
|
|
- Long proId = ProductUtils.updateOne(product);
|
|
|
- product = productDao.findOne(proId);
|
|
|
- item.setProdCode(purcitem.getProdCode());
|
|
|
- item.setProdTitle(purcitem.getProdTitle());
|
|
|
- item.setSpec(purcitem.getSpec());
|
|
|
- item.setCmpCode(purcitem.getCmpCode());
|
|
|
- item.setInbrand(purcitem.getInbrand());
|
|
|
- if (null != product) {
|
|
|
- BeanUtils.copyProperties(product, productInfo, ProductInfo.class);
|
|
|
- item.setProduct(productInfo);
|
|
|
- item.setProductId(proId);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ BeanUtils.copyProperties(purcitem, item, PurcInquiryItem.class);
|
|
|
item.setNumber(i);
|
|
|
item.setCurrency(inquiry.getCurrency());
|
|
|
- item.setFromDate(new Date());
|
|
|
- item.setToDate(purcitem.getToDate());
|
|
|
- item.setDate(new Date());
|
|
|
- item.setRemark(purcitem.getRemark());
|
|
|
+ item.setFromDate(new Date(System.currentTimeMillis()));
|
|
|
+ item.setDate(new Date(System.currentTimeMillis()));
|
|
|
item.setStatus((short) Status.NOT_REPLY.value());
|
|
|
item.setIsOpen(inquiryInfo.getIsOpen());
|
|
|
- item.setNeedquantity(purcitem.getNeedquantity());
|
|
|
item.setUserUU(SystemSession.getUser().getUserUU());
|
|
|
item.setUserName(SystemSession.getUser().getUserName());
|
|
|
item.setUserTel(SystemSession.getUser().getUserTel());
|
|
|
@@ -558,7 +500,7 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
public ModelMap saveAndSubmitWithoutVendor(PurcInquiryInfo inquiryInfo, FileUpload uploadItem) throws Exception {
|
|
|
ModelMap map = new ModelMap();
|
|
|
// 先进行保存
|
|
|
- Object inquiryId = saveWithoutVendor(inquiryInfo, uploadItem).get("id");// 取出id进行更新状态
|
|
|
+ Object inquiryId = saveWithoutVendor(inquiryInfo, uploadItem).get("id");
|
|
|
if (inquiryId != null) {
|
|
|
map.put("success", "询价单发布成功");
|
|
|
} else {
|
|
|
@@ -621,40 +563,48 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
inquiryInfo.setShip(inquiry.getShip());
|
|
|
inquiryInfo.setInvoice(inquiry.getInvoice());
|
|
|
inquiryInfo.setInquirytype(inquiry.getInquirytype());
|
|
|
- Set<Long> ids = new HashSet<Long>();
|
|
|
- List<Long> idStrings = new ArrayList<>();
|
|
|
- Set<InquiryProductInfo> products = new HashSet<InquiryProductInfo>();
|
|
|
- if (!CollectionUtils.isEmpty(inquiry.getInquiryItems())) {
|
|
|
+ // 这里需要修改成用物料编号去判断了,因为可能物料id已经不存在了
|
|
|
+ Map<String, InquiryProductInfo> productInfoMap = distinctProdCode(inquiry.getInquiryItems());
|
|
|
+ Set<InquiryProductInfo> products = new HashSet<>();
|
|
|
+ for (Map.Entry<String, InquiryProductInfo> map : productInfoMap.entrySet()) {
|
|
|
+ InquiryProductInfo productInfo = map.getValue();
|
|
|
+ Set<PurchaseInquiryItemInfo> items = new HashSet<>();
|
|
|
for (PurchaseInquiryItemInfo item : inquiry.getInquiryItems()) {
|
|
|
- idStrings.add(item.getProductId());
|
|
|
- ids.addAll(idStrings);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(ids)) {
|
|
|
- for (Long idInfo : ids) {
|
|
|
- InquiryProductInfo productInfo = new InquiryProductInfo();
|
|
|
- Set<PurchaseInquiryItemInfo> items = new HashSet<PurchaseInquiryItemInfo>();
|
|
|
- Product product = productDao.findOne(idInfo);
|
|
|
- productInfo.setBrand(product.getBrand());
|
|
|
- productInfo.setId(product.getId());
|
|
|
- productInfo.setSpec(product.getSpec());
|
|
|
- productInfo.setCode(product.getCode());
|
|
|
- productInfo.setTitle(product.getTitle());
|
|
|
- productInfo.setUnit(product.getUnit());
|
|
|
- for (PurchaseInquiryItemInfo item : inquiry.getInquiryItems()) {
|
|
|
- if (item.getProductId().equals(idInfo)) {
|
|
|
- items.add(item);
|
|
|
- }
|
|
|
+ if (item.getProductCode().equals(map.getKey())) {
|
|
|
+ items.add(item);
|
|
|
}
|
|
|
- productInfo.setInquiryItems(items);
|
|
|
- products.add(productInfo);
|
|
|
- inquiryInfo.setProducts(products);
|
|
|
}
|
|
|
+ productInfo.setInquiryItems(items);
|
|
|
+ products.add(productInfo);
|
|
|
+ inquiryInfo.setProducts(products);
|
|
|
}
|
|
|
}
|
|
|
return inquiryInfo;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取物料编号信息
|
|
|
+ *
|
|
|
+ * @param inquiryItems 询价明细
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, InquiryProductInfo> distinctProdCode(Set<PurchaseInquiryItemInfo> inquiryItems) {
|
|
|
+ Map<String, InquiryProductInfo> productInfoMap = new HashedMap();
|
|
|
+ for (PurchaseInquiryItemInfo itemInfo : inquiryItems) {
|
|
|
+ InquiryProductInfo productInfo = new InquiryProductInfo();
|
|
|
+ productInfo.setBrand(itemInfo.getProductBrand());
|
|
|
+ productInfo.setCmpCode(itemInfo.getProductCmpCode());
|
|
|
+ productInfo.setCode(itemInfo.getProductCode());
|
|
|
+ productInfo.setSpec(itemInfo.getProductSpec());
|
|
|
+ productInfo.setTitle(itemInfo.getProductTitle());
|
|
|
+ productInfo.setUnit(itemInfo.getProductUnit());
|
|
|
+ productInfo.setId(itemInfo.getProductId());
|
|
|
+ productInfoMap.put(itemInfo.getProductCode(), productInfo);
|
|
|
+ }
|
|
|
+ return productInfoMap;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ModelMap releaseByWorkbook(Workbook workbook) {
|
|
|
ModelMap modelMap = new ModelMap();
|
|
|
@@ -662,10 +612,12 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
List<PurcInquiryProductInfo> infos = new ArrayList<PurcInquiryProductInfo>();
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
+ // 录入的值起始行
|
|
|
+ int valueNum = 3;
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
int total = 0;
|
|
|
if (headerRow != null) {
|
|
|
- for (int r = 3; r <= rowNum; r++) {
|
|
|
+ for (int r = valueNum; r <= rowNum; r++) {
|
|
|
Row row = sheet.getRow(r);
|
|
|
if (row != null && row.getCell(0) != null && row.getCell(1).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
total++;
|