|
|
@@ -1,5 +1,9 @@
|
|
|
package com.uas.platform.b2c.prod.commodity.service.impl;
|
|
|
|
|
|
+import com.uas.platform.b2c.b2b.dao.EnterpriseBaseInfoDao;
|
|
|
+import com.uas.platform.b2c.b2b.model.EnterpriseBaseInfo;
|
|
|
+import com.uas.platform.b2c.common.account.dao.UserBaseInfoDao;
|
|
|
+import com.uas.platform.b2c.common.account.model.UserBaseInfo;
|
|
|
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;
|
|
|
@@ -7,13 +11,39 @@ 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.brand.dao.BrandInfoDao;
|
|
|
+import com.uas.platform.b2c.prod.product.brand.modal.BrandInfo;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
|
|
|
import com.uas.platform.b2c.prod.product.component.modal.Component;
|
|
|
+import com.uas.platform.b2c.prod.product.component.service.ComponentService;
|
|
|
+import com.uas.platform.b2c.prod.product.kind.dao.KindDao;
|
|
|
+import com.uas.platform.b2c.prod.product.kind.dao.KindInfoDao;
|
|
|
+import com.uas.platform.b2c.prod.product.kind.model.Kind;
|
|
|
+import com.uas.platform.b2c.prod.product.kind.model.KindInfo;
|
|
|
import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import com.uas.platform.core.model.PageInfo;
|
|
|
+import com.uas.platform.core.model.PageParams;
|
|
|
+import com.uas.platform.core.persistence.criteria.CriterionExpression;
|
|
|
+import com.uas.platform.core.persistence.criteria.CriterionExpression.Operator;
|
|
|
+import com.uas.platform.core.persistence.criteria.LogicalExpression;
|
|
|
+import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
+import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
@@ -31,12 +61,130 @@ public class ProductAttachServiceImpl implements ProductAttachService {
|
|
|
|
|
|
private final ComponentDao componentDao;
|
|
|
|
|
|
+ private final BrandInfoDao brandInfoDao;
|
|
|
+
|
|
|
+ private final KindInfoDao kindInfoDao;
|
|
|
+
|
|
|
+ private final ComponentService componentService;
|
|
|
+
|
|
|
+ private final KindDao kindDao;
|
|
|
+
|
|
|
+ private final EnterpriseBaseInfoDao enterpriseBaseInfoDao;
|
|
|
+
|
|
|
+ private final UserBaseInfoDao userBaseInfoDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
public ProductAttachServiceImpl(ProductDao productDao, ProductAttachSubmitDao productAttachSubmitDao,
|
|
|
- ComponentDao componentDao) {
|
|
|
+ ComponentDao componentDao, BrandInfoDao brandInfoDao, KindInfoDao kindInfoDao, ComponentService componentService, KindDao kindDao, EnterpriseBaseInfoDao enterpriseBaseInfoDao, UserBaseInfoDao userBaseInfoDao) {
|
|
|
this.productDao = productDao;
|
|
|
this.productAttachSubmitDao = productAttachSubmitDao;
|
|
|
this.componentDao = componentDao;
|
|
|
+ this.brandInfoDao = brandInfoDao;
|
|
|
+ this.kindInfoDao = kindInfoDao;
|
|
|
+ this.componentService = componentService;
|
|
|
+ this.kindDao = kindDao;
|
|
|
+ this.enterpriseBaseInfoDao = enterpriseBaseInfoDao;
|
|
|
+ this.userBaseInfoDao = userBaseInfoDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ProductAttachSubmit> getPageInfo(PageParams params, String keywords, String status) {
|
|
|
+ final PageInfo pageInfo = new PageInfo(params);
|
|
|
+
|
|
|
+ // 过滤状态
|
|
|
+ Integer statusCode = 0;
|
|
|
+ switch (status) {
|
|
|
+ case "all" : break;
|
|
|
+ case "unaudit" : statusCode = Status.UNAUDIT.value(); break;
|
|
|
+ case "audited" : statusCode = Status.AUDITED.value(); break;
|
|
|
+ case "notallow" : statusCode = Status.NOTALLOW.value(); break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageInfo.getSort() == null) {
|
|
|
+ pageInfo.sorting(Direction.DESC, "createTime");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (statusCode != 0) {
|
|
|
+ pageInfo.expression(new SimpleExpression("status", statusCode, Operator.EQ));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 过滤提交人姓名、企业
|
|
|
+ if (!StringUtils.isEmpty(keywords)) {
|
|
|
+ SimpleExpression submiterName = new SimpleExpression("submiter.userName", keywords, CriterionExpression.Operator.LIKE);
|
|
|
+ SimpleExpression submiterEnName = new SimpleExpression("submitEn.enName", keywords, CriterionExpression.Operator.LIKE);
|
|
|
+ SimpleExpression[] simpleExpressions = new SimpleExpression[]{submiterName, submiterEnName};
|
|
|
+ LogicalExpression logicalExpression = PredicateUtils.or(simpleExpressions);
|
|
|
+ pageInfo.expression(logicalExpression);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<ProductAttachSubmit> page = productAttachSubmitDao.findAll(new Specification<ProductAttachSubmit>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<ProductAttachSubmit> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ query.where(pageInfo.getPredicates(root, query, cb));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+
|
|
|
+ List<ProductAttachSubmit> submits = page.getContent();
|
|
|
+ if (!CollectionUtils.isEmpty(submits)) {
|
|
|
+ for (ProductAttachSubmit submit : submits) {
|
|
|
+ submit = completeReturnSubmit(submit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new PageImpl<>(submits, pageInfo, page.getTotalElements());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductAttachSubmit getOne(Long id) {
|
|
|
+ ProductAttachSubmit productAttachSubmit = productAttachSubmitDao.findOne(id);
|
|
|
+ if (productAttachSubmit == null) {
|
|
|
+ throw new IllegalOperatorException("申请不存在,请重新确认申请信息");
|
|
|
+ } else {
|
|
|
+ return completeReturnSubmit(productAttachSubmit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 补全返回的申请信息
|
|
|
+ * @param submit 申请信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ProductAttachSubmit completeReturnSubmit(ProductAttachSubmit submit) {
|
|
|
+ if (submit.getAuditEnuu() != null) {
|
|
|
+ EnterpriseBaseInfo enterpriseBaseInfo = enterpriseBaseInfoDao.findOne(submit.getSubmitEnuu());
|
|
|
+ if (enterpriseBaseInfo != null) {
|
|
|
+ submit.setAuditEn(enterpriseBaseInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (submit.getAuditUu() != null) {
|
|
|
+ UserBaseInfo userBaseInfo = userBaseInfoDao.findUserByUserUU(submit.getSubmitUu());
|
|
|
+ if (userBaseInfo != null) {
|
|
|
+ submit.setAuditer(userBaseInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (submit.getProductId() != null) {
|
|
|
+ Product product = productDao.findOne(submit.getProductId());
|
|
|
+ if (product != null) {
|
|
|
+ submit.setProduct(product);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (submit.getKindId() != null) {
|
|
|
+ KindInfo kindInfo = kindInfoDao.findOne(submit.getKindId());
|
|
|
+ if (kindInfo != null) {
|
|
|
+ submit.setKind(kindInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (submit.getBrandId() != null) {
|
|
|
+ BrandInfo brandInfo = brandInfoDao.findOne(submit.getBrandId());
|
|
|
+ if (brandInfo != null) {
|
|
|
+ submit.setBrand(brandInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return submit;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -75,6 +223,7 @@ public class ProductAttachServiceImpl implements ProductAttachService {
|
|
|
submit.setProductId(product.getId());
|
|
|
submit.setProduct(product);
|
|
|
submit.setCreateTime(new Date());
|
|
|
+ submit.setCode(product.getPcmpcode());
|
|
|
if (SystemSession.getUser().getUserUU() != null && SystemSession.getUser().getEnterprise() != null) {
|
|
|
submit.setSubmitUu(SystemSession.getUser().getUserUU());
|
|
|
submit.setSubmitEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
@@ -94,12 +243,98 @@ public class ProductAttachServiceImpl implements ProductAttachService {
|
|
|
|
|
|
@Override
|
|
|
public ResultMap auditSuccess(ProductAttachSubmit submit) {
|
|
|
- return null;
|
|
|
+ if (submit.getId() == null) {
|
|
|
+ return new ResultMap(CodeType.NOT_EXiST, "此申请不存在,请重新确认申请信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ ProductAttachSubmit exsitedSubmit = productAttachSubmitDao.findOne(submit.getId());
|
|
|
+ if (exsitedSubmit == null) {
|
|
|
+ return new ResultMap(CodeType.NOT_EXiST, "此申请不存在,请重新确认申请信息");
|
|
|
+ } else {
|
|
|
+ exsitedSubmit.setBrandId(submit.getBrandId());
|
|
|
+ exsitedSubmit.setKindId(submit.getKindId());
|
|
|
+ exsitedSubmit.setSpec(submit.getSpec());
|
|
|
+ if (StringUtils.isEmpty(exsitedSubmit.getUploadAttach())) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "此申请规格书为空,请重新确认申请信息");
|
|
|
+ }
|
|
|
+ if (exsitedSubmit.getBrandId() == null || exsitedSubmit.getKindId() == null) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "商城类目、品牌不完善,请重新确认申请信息");
|
|
|
+ }
|
|
|
+ BrandInfo brandInfo = brandInfoDao.findOne(exsitedSubmit.getBrandId());
|
|
|
+ if (brandInfo == null) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "商城品牌不存在,请重新填写商城品牌");
|
|
|
+ }
|
|
|
+ KindInfo kindInfo = kindInfoDao.findOne(exsitedSubmit.getKindId());
|
|
|
+ if (kindInfo == null) {
|
|
|
+ return new ResultMap(CodeType.PARAMETER_ERROR, "商城物料名称(类目)不存在,请重新填写商城物料名称(类目)");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标准型号
|
|
|
+ if (StringUtils.isEmpty(exsitedSubmit.getUuid())) {
|
|
|
+ Component component = componentDao.findByUuid(exsitedSubmit.getUuid());
|
|
|
+ // 实际为非标物料
|
|
|
+ if (component == null) {
|
|
|
+ return new ResultMap(CodeType.ERROR_STATE, "该物料匹配的标准器件不存在,请重新确认该物料信息");
|
|
|
+ // 标准物料无规格书,更新规格书
|
|
|
+ } else if (component.getAttach() == null){
|
|
|
+ component = addComponent(exsitedSubmit, component.getId());
|
|
|
+ return ResultMap.success(auditSubmit(exsitedSubmit));
|
|
|
+ // 标准物料有规格书,返回两规格书
|
|
|
+ } else {
|
|
|
+ return ResultMap.success(componentAttachNotNull(exsitedSubmit, component.getAttach()));
|
|
|
+ }
|
|
|
+ // 非标型号
|
|
|
+ } else {
|
|
|
+ List<Component> components = componentDao.findByBrandidAndCode(submit.getBrandId(), submit.getCode());
|
|
|
+ if (!CollectionUtils.isEmpty(components)) {
|
|
|
+ Component component = components.get(0);
|
|
|
+ if (component.getAttach() != null) {
|
|
|
+ return ResultMap.success(componentAttachNotNull(exsitedSubmit, component.getAttach()));
|
|
|
+ } else {
|
|
|
+ component = addComponent(exsitedSubmit, component.getId());
|
|
|
+ return ResultMap.success(auditSubmit(exsitedSubmit));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Component component = addComponent(exsitedSubmit, null);
|
|
|
+ return ResultMap.success(auditSubmit(exsitedSubmit));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 完善审核信息
|
|
|
+ * @param submit
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ProductAttachSubmit auditSubmit(ProductAttachSubmit submit) {
|
|
|
+ submit.setStatus(Status.AUDITED.value());
|
|
|
+ submit.setAuditTime(new Date());
|
|
|
+ submit.setAuditUu(SystemSession.getUser().getUserUU());
|
|
|
+ submit.setAuditEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ return productAttachSubmitDao.save(submit);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 器件规格书不为空时,返回两个规格书
|
|
|
+ * @param submit
|
|
|
+ * @param attach
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> componentAttachNotNull(ProductAttachSubmit submit, String attach) {
|
|
|
+ submit.setMallAttach(attach);
|
|
|
+ productAttachSubmitDao.save(submit);
|
|
|
+
|
|
|
+ // 返回标准器件规格书、用户上传规格书
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("uploadAttach", submit.getUploadAttach());
|
|
|
+ map.put("mallAttach", attach);
|
|
|
+
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ResultMap auditFailed(Long submitId, String reason) {
|
|
|
- ResultMap map = new ResultMap();
|
|
|
ProductAttachSubmit submit = productAttachSubmitDao.findOne(submitId);
|
|
|
if (submit == null) {
|
|
|
return new ResultMap(CodeType.NOT_EXiST, "此申请不存在,请重新确认申请信息");
|
|
|
@@ -125,4 +360,31 @@ public class ProductAttachServiceImpl implements ProductAttachService {
|
|
|
public ResultMap chooseAttach(String attach, ProductAttachSubmit productAttachSubmit) {
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ private Component addComponent(ProductAttachSubmit submit, Long componentId) {
|
|
|
+ // 更新器件
|
|
|
+ if (componentId != null) {
|
|
|
+ Component component = componentDao.findOne(componentId);
|
|
|
+ if (component != null) {
|
|
|
+ component.setAttach(submit.getUploadAttach());
|
|
|
+ component.setVersion((short) ((component.getVersion() == null ? 0 : component.getVersion()) + 1));
|
|
|
+ component.setModifyTime(new Date());
|
|
|
+ component.setDescription(submit.getSpec());
|
|
|
+ return componentDao.save(component);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ // 新增器件
|
|
|
+ } else {
|
|
|
+ Component component = new Component(submit);
|
|
|
+ component.setUuid(componentService.createUuid(component));
|
|
|
+ component = componentDao.save(component);
|
|
|
+
|
|
|
+ // 更新类目uuid后缀游标,以便之后生成uuid
|
|
|
+ Kind kind = kindDao.findOne(component.getKindid());
|
|
|
+ kind.setComponentsuffix(kind.getComponentsuffix() + 1);
|
|
|
+ kindDao.save(kind);
|
|
|
+
|
|
|
+ return component;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|