|
|
@@ -24,7 +24,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.uas.platform.b2b.core.util.ContextUtils;
|
|
|
import com.uas.platform.b2b.core.util.ThreadTask;
|
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
|
@@ -145,137 +144,118 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
@Override
|
|
|
public ModelMap save(PurcInquiryInfo inquiryInfo, List<VendorAndContact> contacts, FileUpload uploadItem) {
|
|
|
ModelMap map = new ModelMap();
|
|
|
- Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- Long useruu = SystemSession.getUser().getUserUU();
|
|
|
- PurcInquiry inquiry = new PurcInquiry();
|
|
|
- Set<Attach> attachs = new HashSet<Attach>();
|
|
|
- if (uploadItem.getFile() != null) {// 附件存在
|
|
|
- Attach attach = attachService.upload(uploadItem, "productAttach", "平台客户上传物料照片或附件");
|
|
|
- if (attach == null) {
|
|
|
- map.put("error", "文件太大");
|
|
|
- } else {
|
|
|
- attachs.add(attach);
|
|
|
- inquiry.setAttachs(attachs);
|
|
|
+ PurcInquiry old = inquiryDao.findByCode(inquiryInfo.getCode());
|
|
|
+ if (old == null) { // 判断是否存在,防止重复
|
|
|
+ Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ Long useruu = SystemSession.getUser().getUserUU();
|
|
|
+ PurcInquiry inquiry = new PurcInquiry();
|
|
|
+ Set<Attach> attachs = new HashSet<Attach>();
|
|
|
+ if (uploadItem.getFile() != null) {// 附件存在
|
|
|
+ Attach attach = attachService.upload(uploadItem, "productAttach", "平台客户上传物料照片或附件");
|
|
|
+ if (attach == null) {
|
|
|
+ map.put("error", "文件太大");
|
|
|
+ } else {
|
|
|
+ attachs.add(attach);
|
|
|
+ inquiry.setAttachs(attachs);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- // 先判断供应商是否存在
|
|
|
- if (!CollectionUtils.isEmpty(contacts)) {
|
|
|
- if (inquiry.getId() == null) {// 新增
|
|
|
- inquiry.setDate(new Date());
|
|
|
- inquiry.setCode(inquiryInfo.getCode());
|
|
|
- inquiry.setEnUU(enuu);
|
|
|
- inquiry.setCode(inquiryInfo.getCode());
|
|
|
- inquiry.setEndDate(inquiryInfo.getEndDate());
|
|
|
- inquiry.setRemark(inquiryInfo.getRemark());
|
|
|
- inquiry.setEnvironment(inquiryInfo.getEnvironment());
|
|
|
- inquiry.setEnterprise(enterpriseDao.findEnterpriseInfoByUu(enuu));
|
|
|
- inquiry.setRecorder(SystemSession.getUser().getUserName());
|
|
|
- inquiry.setRecorderUU(SystemSession.getUser().getUserUU());
|
|
|
- inquiry.setEnteryStatus(Status.UNAPPLY.value());
|
|
|
- inquiry.setPriceType(inquiryInfo.getPriceType());
|
|
|
- inquiry.setIsOpen((short) inquiryInfo.getIsOpen());
|
|
|
- inquiry.setInvoice(inquiryInfo.getInvoice());
|
|
|
- inquiry.setShip(inquiryInfo.getShip());
|
|
|
- inquiry.setCurrency(inquiryInfo.getCurrency());
|
|
|
- inquiry.setIfTax(inquiryInfo.getIfTax());
|
|
|
- inquiry.setInquirytype(inquiryInfo.getInquirytype());
|
|
|
- Set<PurcInquiryItem> items = new HashSet<PurcInquiryItem>();
|
|
|
- Short i = 1;
|
|
|
- for (VendorAndContact contact : contacts) {
|
|
|
- if (!CollectionUtils.isEmpty(inquiryInfo.getInquiryItems())) {
|
|
|
- for (PurcInquiryItem purcitem : inquiryInfo.getInquiryItems()) {
|
|
|
- PurcInquiryItem item = new PurcInquiryItem();
|
|
|
- Product product = new Product();
|
|
|
- Enterprise vendorEn = enterpriseDao.findEnterpriseByUu(contact.getEnuu());
|
|
|
- if (purcitem.getProductId() != null) {// 点击选择出来的,一般带有id
|
|
|
- product = productDao.findOne(purcitem.getProductId());
|
|
|
- item.setProduct(product);
|
|
|
- item.setProductId(product.getId());
|
|
|
- } else {// 导入或手动输入的一般不带有id
|
|
|
- List<Product> products = productDao.findByEnUUAndCode(
|
|
|
- SystemSession.getUser().getEnterprise().getUu(),
|
|
|
- purcitem.getProdCode());
|
|
|
- if (products.size() > 0) {
|
|
|
- product = products.get(0);
|
|
|
- }
|
|
|
- if (product.getId() != null) {// 存在直接选择
|
|
|
- item.setProduct(product);
|
|
|
- item.setProductId(product.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.setShipAddr(SystemSession.getUser().getEnterprise().getEnAddress());
|
|
|
- // 导入的物料这里没有填写规格
|
|
|
- product.setSpec(purcitem.getProdTitle());
|
|
|
- product = productDao.save(product);
|
|
|
+ // 先判断供应商是否存在
|
|
|
+ if (!CollectionUtils.isEmpty(contacts)) {
|
|
|
+ if (inquiry.getId() == null) {// 新增
|
|
|
+ inquiry.setDate(new Date());
|
|
|
+ inquiry.setCode(inquiryInfo.getCode());
|
|
|
+ inquiry.setEnUU(enuu);
|
|
|
+ inquiry.setCode(inquiryInfo.getCode());
|
|
|
+ inquiry.setEndDate(inquiryInfo.getEndDate());
|
|
|
+ inquiry.setRemark(inquiryInfo.getRemark());
|
|
|
+ inquiry.setEnvironment(inquiryInfo.getEnvironment());
|
|
|
+ inquiry.setEnterprise(enterpriseDao.findEnterpriseInfoByUu(enuu));
|
|
|
+ inquiry.setRecorder(SystemSession.getUser().getUserName());
|
|
|
+ inquiry.setRecorderUU(SystemSession.getUser().getUserUU());
|
|
|
+ inquiry.setEnteryStatus(Status.UNAPPLY.value());
|
|
|
+ inquiry.setPriceType(inquiryInfo.getPriceType());
|
|
|
+ inquiry.setIsOpen((short) inquiryInfo.getIsOpen());
|
|
|
+ inquiry.setInvoice(inquiryInfo.getInvoice());
|
|
|
+ inquiry.setShip(inquiryInfo.getShip());
|
|
|
+ inquiry.setCurrency(inquiryInfo.getCurrency());
|
|
|
+ inquiry.setIfTax(inquiryInfo.getIfTax());
|
|
|
+ inquiry.setInquirytype(inquiryInfo.getInquirytype());
|
|
|
+ Set<PurcInquiryItem> items = new HashSet<PurcInquiryItem>();
|
|
|
+ Short i = 1;
|
|
|
+ for (VendorAndContact contact : contacts) {
|
|
|
+ if (!CollectionUtils.isEmpty(inquiryInfo.getInquiryItems())) {
|
|
|
+ for (PurcInquiryItem purcitem : inquiryInfo.getInquiryItems()) {
|
|
|
+ PurcInquiryItem item = new PurcInquiryItem();
|
|
|
+ Product product = new Product();
|
|
|
+ Enterprise vendorEn = enterpriseDao.findEnterpriseByUu(contact.getEnuu());
|
|
|
+ if (purcitem.getProductId() != null) {// 点击选择出来的,一般带有id
|
|
|
+ product = productDao.findOne(purcitem.getProductId());
|
|
|
item.setProduct(product);
|
|
|
item.setProductId(product.getId());
|
|
|
+ } else {// 导入或手动输入的一般不带有id
|
|
|
+ List<Product> products = productDao.findByEnUUAndCode(
|
|
|
+ SystemSession.getUser().getEnterprise().getUu(), purcitem.getProdCode());
|
|
|
+ if (products.size() > 0) {
|
|
|
+ product = products.get(0);
|
|
|
+ }
|
|
|
+ if (product.getId() != null) {// 存在直接选择
|
|
|
+ item.setProduct(product);
|
|
|
+ item.setProductId(product.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.setShipAddr(SystemSession.getUser().getEnterprise().getEnAddress());
|
|
|
+ // 导入的物料这里没有填写规格
|
|
|
+ product.setSpec(purcitem.getProdTitle());
|
|
|
+ product = productDao.save(product);
|
|
|
+ item.setProduct(product);
|
|
|
+ item.setProductId(product.getId());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- item.setInquiry(inquiry);
|
|
|
- item.setNumber(i);
|
|
|
- item.setCurrency(contact.getCurrency());
|
|
|
- item.setFromDate(new Date());
|
|
|
- item.setToDate(purcitem.getToDate());
|
|
|
- // 币别为RMB税率17,其他税率为0
|
|
|
- if (contact.getRate() != null) {
|
|
|
- item.setTaxrate(contact.getRate());
|
|
|
- } else {
|
|
|
- if (item.getCurrency().equals(RMB)) {
|
|
|
- item.setTaxrate((float) 17);
|
|
|
+ item.setInquiry(inquiry);
|
|
|
+ item.setNumber(i);
|
|
|
+ item.setCurrency(contact.getCurrency());
|
|
|
+ item.setFromDate(new Date());
|
|
|
+ item.setToDate(purcitem.getToDate());
|
|
|
+ // 币别为RMB税率17,其他税率为0
|
|
|
+ if (contact.getRate() != null) {
|
|
|
+ item.setTaxrate(contact.getRate());
|
|
|
} else {
|
|
|
- item.setTaxrate((float) 0);
|
|
|
+ if (item.getCurrency().equals(RMB)) {
|
|
|
+ item.setTaxrate((float) 17);
|
|
|
+ } else {
|
|
|
+ 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++;
|
|
|
}
|
|
|
- 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++;
|
|
|
}
|
|
|
}
|
|
|
+ List<PurcInquiryItem> purcitems = purcInquiryItemDao.save(items);
|
|
|
+ if (purcitems.get(0).getId() != null) {
|
|
|
+ map.put("success", "询价单保存成功");
|
|
|
+ map.put("id", purcitems.get(0).getInquiry().getId());
|
|
|
+ logger.log("询价单", "平台新增询价单", useruu, SystemSession.getUser().getIp());
|
|
|
+ } else {
|
|
|
+ map.put("error", "询价单保存失败");
|
|
|
+ }
|
|
|
}
|
|
|
- System.out.println(JSON.toJSON(items));
|
|
|
- List<PurcInquiryItem> purcitems = purcInquiryItemDao.save(items);
|
|
|
- if (purcitems.get(0).getId() != null) {
|
|
|
- map.put("success", "询价单保存成功");
|
|
|
- map.put("id", purcitems.get(0).getInquiry().getId());
|
|
|
- logger.log("询价单", "平台新增询价单", useruu, SystemSession.getUser().getIp());
|
|
|
- } else {
|
|
|
- map.put("error", "询价单保存失败");
|
|
|
- }
|
|
|
- } // TODO 暂未设想更新逻辑
|
|
|
- // else {// 更新
|
|
|
- // PurcInquiry purcInquiry =
|
|
|
- // inquiryDao.findOne(inquiry.getId());
|
|
|
- // purcInquiry.setAttachs(inquiry.getAttachs());
|
|
|
- // purcInquiry.setDate(new Date());
|
|
|
- // purcInquiry.setEndDate(inquiry.getEndDate());
|
|
|
- // purcInquiry.setEnvironment(inquiry.getEnvironment());
|
|
|
- // purcInquiry.setRemark(inquiry.getRemark());
|
|
|
- // if (!CollectionUtils.isEmpty(contacts)) {
|
|
|
- // if (!CollectionUtils.isEmpty(inquiry.getInquiryItems())) {
|
|
|
- // for (PurcInquiryItem item : inquiry.getInquiryItems()) {
|
|
|
- // PurcInquiryItem purcItem =
|
|
|
- // purcInquiryItemDao.findOne(item.getId());
|
|
|
- // purcItem.setCurrency(item.getCurrency());
|
|
|
- // purcItem.setInquiry(purcInquiry);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //
|
|
|
- // }
|
|
|
+ }
|
|
|
}
|
|
|
return map;
|
|
|
}
|