|
|
@@ -0,0 +1,92 @@
|
|
|
+package com.uas.platform.b2c.prod.commodity.service.impl;
|
|
|
+
|
|
|
+import com.uas.platform.b2c.core.constant.Status;
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
+import com.uas.platform.b2c.prod.commodity.dao.ProductAttachSubmitDao;
|
|
|
+import com.uas.platform.b2c.prod.commodity.dao.ProductDao;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.Product;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.ProductAttachSubmit;
|
|
|
+import com.uas.platform.b2c.prod.commodity.service.ProductAttachService;
|
|
|
+import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
|
|
|
+import com.uas.platform.b2c.prod.product.component.modal.Component;
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import java.util.Date;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by wangyc on 2018/6/26.
|
|
|
+ *
|
|
|
+ * @version 2018/6/26 18:12 wangyc
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ProductAttachServiceImpl implements ProductAttachService {
|
|
|
+
|
|
|
+ private final ProductDao productDao;
|
|
|
+
|
|
|
+ private final ProductAttachSubmitDao productAttachSubmitDao;
|
|
|
+
|
|
|
+ private final ComponentDao componentDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public ProductAttachServiceImpl(ProductDao productDao, ProductAttachSubmitDao productAttachSubmitDao,
|
|
|
+ ComponentDao componentDao) {
|
|
|
+ this.productDao = productDao;
|
|
|
+ this.productAttachSubmitDao = productAttachSubmitDao;
|
|
|
+ this.componentDao = componentDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductAttachSubmit submit(Long productId, String attach) {
|
|
|
+ if (StringUtils.isEmpty(attach)) {
|
|
|
+ throw new IllegalOperatorException("规格书为空,请上传规格书");
|
|
|
+ } else {
|
|
|
+ Product product = productDao.findOne(productId);
|
|
|
+ if (product == null) {
|
|
|
+ throw new IllegalOperatorException("此物料不存在,请重新确认物料信息");
|
|
|
+ } else {
|
|
|
+ ProductAttachSubmit productAttachSubmit = productAttachSubmitDao.findByProductIdAndStatus(productId,
|
|
|
+ Status.UNAUDIT.value());
|
|
|
+ // 更新物料规格书申请
|
|
|
+ if (productAttachSubmit != null) {
|
|
|
+ productAttachSubmit = completeSubmit(productAttachSubmit, product, attach);
|
|
|
+ // 新增物料规格书申请
|
|
|
+ } else {
|
|
|
+ productAttachSubmit = new ProductAttachSubmit();
|
|
|
+ productAttachSubmit = completeSubmit(productAttachSubmit, product, attach);
|
|
|
+ }
|
|
|
+ return productAttachSubmitDao.save(productAttachSubmit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 补充申请
|
|
|
+ * @param submit 申请
|
|
|
+ * @param product 物料信息
|
|
|
+ * @param attach 规格书
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ProductAttachSubmit completeSubmit(ProductAttachSubmit submit, Product product, String attach) {
|
|
|
+ submit.setUploadAttach(attach);
|
|
|
+ submit.setProductId(product.getId());
|
|
|
+ submit.setProduct(product);
|
|
|
+ submit.setCreateTime(new Date());
|
|
|
+ if (SystemSession.getUser().getUserUU() != null && SystemSession.getUser().getEnterprise() != null) {
|
|
|
+ submit.setSubmitUu(SystemSession.getUser().getUserUU());
|
|
|
+ submit.setSubmitEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("此功能仅供企业下属用户使用,请以企业下属用户身份登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ submit.setUuid("");
|
|
|
+ if (product.getCmpUuId() != null) {
|
|
|
+ Component component = componentDao.findByUuid(product.getCmpUuId());
|
|
|
+ if (component != null) {
|
|
|
+ submit.setUuid(product.getCmpUuId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return submit;
|
|
|
+ }
|
|
|
+}
|