|
|
@@ -101,12 +101,14 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
public ModelMap save(PurcInquiryInfo inquiryInfo, List<VendorAndContact> contacts, FileUpload uploadItem) throws Exception {
|
|
|
ModelMap map = new ModelMap();
|
|
|
PurcInquiry old = inquiryDao.findByCode(inquiryInfo.getCode());
|
|
|
- if (old == null) { // 判断是否存在,防止重复
|
|
|
+ // 判断是否存在,防止重复
|
|
|
+ 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) {// 附件存在
|
|
|
+ // 附件存在
|
|
|
+ if (uploadItem.getFile() != null) {
|
|
|
Attach attach = attachService.upload(uploadItem, "productAttach", "平台客户上传物料照片或附件");
|
|
|
if (attach == null) {
|
|
|
map.put("error", "文件太大");
|
|
|
@@ -117,98 +119,89 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
}
|
|
|
// 先判断供应商是否存在
|
|
|
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(Constant.NO);
|
|
|
- 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());
|
|
|
+ inquiry.setDate(new Date(System.currentTimeMillis()));
|
|
|
+ BeanUtils.copyProperties(inquiryInfo, inquiry, PurcInquiry.class);
|
|
|
+ inquiry.setEnUU(enuu);
|
|
|
+ inquiry.setEnterprise(enterpriseDao.findEnterpriseInfoByUu(enuu));
|
|
|
+ inquiry.setRecorder(SystemSession.getUser().getUserName());
|
|
|
+ inquiry.setRecorderUU(SystemSession.getUser().getUserUU());
|
|
|
+ inquiry.setEnteryStatus(Status.UNAPPLY.value());
|
|
|
+ inquiry.setIsOpen(Constant.NO);
|
|
|
+ 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());
|
|
|
+ // 点击选择出来的,一般带有id
|
|
|
+ if (purcitem.getProductId() != null) {
|
|
|
+ product = productDao.findOne(purcitem.getProductId());
|
|
|
+ item.setProduct(product);
|
|
|
+ item.setProductId(product.getId());
|
|
|
+ // 导入或手动输入的一般不带有id
|
|
|
+ } else {
|
|
|
+ List<Product> products = productDao.findByEnUUAndPcmpcodeAndPbrand(
|
|
|
+ SystemSession.getUser().getEnterprise().getUu(), purcitem.getCmpCode(), purcitem.getBrand());
|
|
|
+ if (products.size() > 0) {
|
|
|
+ product = products.get(0);
|
|
|
+ }
|
|
|
+ // 存在直接选择
|
|
|
+ if (product.getId() != null) {
|
|
|
item.setProduct(product);
|
|
|
item.setProductId(product.getId());
|
|
|
- } else {// 导入或手动输入的一般不带有id
|
|
|
- List<Product> products = productDao.findByEnUUAndPcmpcodeAndPbrand(
|
|
|
- SystemSession.getUser().getEnterprise().getUu(), purcitem.getCmpCode(), purcitem.getBrand());
|
|
|
- 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.setSpec(purcitem.getProdTitle());
|
|
|
- product.setCreateTime(new Date());
|
|
|
- Long proId = ProductUtils.updateOne(product);
|
|
|
- item.setProductId(proId);
|
|
|
- }
|
|
|
+ } 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);
|
|
|
+ item.setProductId(proId);
|
|
|
}
|
|
|
- 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());
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ } else {
|
|
|
+ if (item.getCurrency().equals(RMB)) {
|
|
|
+ item.setTaxrate((float) 16);
|
|
|
} else {
|
|
|
- if (item.getCurrency().equals(RMB)) {
|
|
|
- item.setTaxrate((float) 17);
|
|
|
- } else {
|
|
|
- item.setTaxrate((float) 0);
|
|
|
- }
|
|
|
+ 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", "询价单保存失败");
|
|
|
- }
|
|
|
+ }
|
|
|
+ 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", "询价单保存失败");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -218,7 +211,8 @@ public class PurcInquiryServiceImpl implements PurcInquiryService {
|
|
|
@Override
|
|
|
public ModelMap saveAndSubmit(PurcInquiryInfo inquiryInfo, List<VendorAndContact> contacts, FileUpload uploadItem) throws Exception {
|
|
|
// 先进行保存
|
|
|
- Object inquiryId = save(inquiryInfo, contacts, uploadItem).get("id");// 取出id进行更新状态
|
|
|
+ // 取出id进行更新状态
|
|
|
+ Object inquiryId = save(inquiryInfo, contacts, uploadItem).get("id");
|
|
|
// 再进行提交
|
|
|
ModelMap map = sumbit(Long.valueOf(inquiryId.toString()));
|
|
|
return map;
|