|
|
@@ -1,5 +1,6 @@
|
|
|
package com.uas.platform.b2c.prod.commodity.service.impl;
|
|
|
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
import com.uas.platform.b2c.core.utils.StringUtilB2C;
|
|
|
import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
|
|
|
@@ -10,19 +11,29 @@ import com.uas.platform.b2c.prod.commodity.model.Product;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.CommodityInOutboundService;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.InOutboundDetailService;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.ProductService;
|
|
|
+import com.uas.platform.b2c.prod.commodity.type.InOutBoundType;
|
|
|
import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
|
|
|
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.LogicalExpression;
|
|
|
+import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
+import com.uas.platform.core.persistence.criteria.SimpleExpression;
|
|
|
import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* description
|
|
|
@@ -110,7 +121,7 @@ public class CommodityInOutboundServiceImpl implements CommodityInOutboundServic
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResultMap inOutBound(String detail, String type) {
|
|
|
+ public ResultMap inOutBound(String detail, String type, String enName) {
|
|
|
if (StringUtilB2C.isEmpty(detail)) {
|
|
|
return new ResultMap(CodeType.NO_INFO, "传入的信息为空");
|
|
|
} else {
|
|
|
@@ -135,13 +146,26 @@ public class CommodityInOutboundServiceImpl implements CommodityInOutboundServic
|
|
|
CommodityInOutbound inOutbound = new CommodityInOutbound(type);
|
|
|
inOutbound.setInOutId(inOutboundId);
|
|
|
Short i = 1;
|
|
|
+ Set<InOutboundDetail> set = new HashSet<>();
|
|
|
if (CollectionUtils.isNotEmpty(prids)) {
|
|
|
List<Product> products = productService.findByProductId(prids);
|
|
|
for (InOutboundDetail inOutboundDetail : detaiList) {
|
|
|
- inOutboundDetail.setDetno(i++);
|
|
|
- inOutboundDetail.setCommodityInOutbound(inOutbound);
|
|
|
for (Product product : products) {
|
|
|
if (inOutboundDetail.getProductId().longValue() == product.getId().longValue()) {
|
|
|
+ if (InOutBoundType.INBOUND.equals(type) || InOutBoundType.OTHER_INBOUND.equals(type) || InOutBoundType.PURCHASE_INBOUND.equals(type)) {
|
|
|
+ product.setErpReserve(NumberUtil.add(product.getErpReserve(), inOutboundDetail.getQty()));
|
|
|
+ } else {
|
|
|
+ //出库
|
|
|
+ if (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) == 0) {
|
|
|
+ break;
|
|
|
+ } else if (NumberUtil.compare(product.getErpReserve(), inOutboundDetail.getQty()) > 0) {
|
|
|
+ product.setErpReserve(NumberUtil.sub(product.getErpReserve(), inOutboundDetail.getQty()));
|
|
|
+ } else {
|
|
|
+ inOutboundDetail.setQty(product.getErpReserve());
|
|
|
+ product.setErpReserve(DoubleConstant.zero);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
inOutboundDetail.setBrandCn(product.getPbrand());
|
|
|
inOutboundDetail.setBrandEn(product.getPbranden());
|
|
|
inOutboundDetail.setBrandId(product.getPbrandid());
|
|
|
@@ -151,18 +175,74 @@ public class CommodityInOutboundServiceImpl implements CommodityInOutboundServic
|
|
|
inOutboundDetail.setKindId(product.getKindid());
|
|
|
inOutboundDetail.setKindName(product.getKind());
|
|
|
inOutboundDetail.setSpec(product.getSpec());
|
|
|
+ set.add(inOutboundDetail);
|
|
|
+ inOutboundDetail.setDetno(i++);
|
|
|
+ inOutboundDetail.setCommodityInOutbound(inOutbound);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
throw new IllegalOperatorException("没有需要操作的信息");
|
|
|
}
|
|
|
- Set<InOutboundDetail> details = new HashSet<>();
|
|
|
- details.addAll(detaiList);
|
|
|
- inOutbound.setInOutboundDetails(details);
|
|
|
+ if (CollectionUtils.isNotEmpty(set)) {
|
|
|
+ return ResultMap.success("剩余库存为0,不能出库");
|
|
|
+ }
|
|
|
+ inOutbound.setInOutboundDetails(set);
|
|
|
+ inOutbound.setAffiliatedEnterprise(enName);
|
|
|
CommodityInOutbound commodityInOutbound = commodityInOutboundDao.save(inOutbound);
|
|
|
//重新计算成本价、在售产品的库存信息需要更新
|
|
|
+ List<Long> pridList = new ArrayList<>();
|
|
|
+ pridList.addAll(prids);
|
|
|
+ productService.updateProductsByInBound(pridList);
|
|
|
return ResultMap.success(commodityInOutbound);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 出入库的记录
|
|
|
+ *
|
|
|
+ * @param params 分页信息
|
|
|
+ * @param keyword 关键字
|
|
|
+ * @param type 类型
|
|
|
+ * @param fromDate 开始时间
|
|
|
+ * @param toDate 结束时间
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<CommodityInOutbound> getCommodityInOutboundByPage(PageParams params, String keyword, String type, Long fromDate, Long toDate) {
|
|
|
+ final PageInfo info = new PageInfo(params);
|
|
|
+ Long enuu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ info.filter("enuu", enuu);
|
|
|
+ if (fromDate != null) {
|
|
|
+ info.expression(PredicateUtils.gte("createTime", new Date(fromDate), false));
|
|
|
+ }
|
|
|
+ if (toDate != null) {
|
|
|
+ info.expression(PredicateUtils.lte("createTime", new Date(toDate), false));
|
|
|
+ }
|
|
|
+ if (org.apache.commons.lang.StringUtils.isNotEmpty(keyword)) {
|
|
|
+ SimpleExpression[] simpArrs = new SimpleExpression[3];
|
|
|
+ simpArrs[0] = new SimpleExpression("affiliatedEnterprise", keyword, CriterionExpression.Operator.LIKE, true);
|
|
|
+ simpArrs[1] = new SimpleExpression("inOutId", keyword, CriterionExpression.Operator.LIKE, true);
|
|
|
+ simpArrs[2] = new SimpleExpression("operaterUserName", keyword, CriterionExpression.Operator.LIKE, true);
|
|
|
+ LogicalExpression logical = new LogicalExpression(simpArrs, CriterionExpression.Operator.OR);
|
|
|
+ info.expression(logical);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (org.apache.commons.lang.StringUtils.isNotEmpty(type)) {
|
|
|
+ SimpleExpression[] simpArrs = new SimpleExpression[2];
|
|
|
+ simpArrs[0] = new SimpleExpression("opertatorType", type, CriterionExpression.Operator.EQ, true);
|
|
|
+ simpArrs[1] = new SimpleExpression("type", type, CriterionExpression.Operator.EQ, true);
|
|
|
+ LogicalExpression logical = new LogicalExpression(simpArrs, CriterionExpression.Operator.OR);
|
|
|
+ info.expression(logical);
|
|
|
+
|
|
|
+ }
|
|
|
+ return commodityInOutboundDao.findAll(new Specification<CommodityInOutbound>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<CommodityInOutbound> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ query.where(info.getPredicates(root, query, cb));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, info);
|
|
|
+ }
|
|
|
}
|