|
|
@@ -8,6 +8,7 @@ import com.uas.platform.b2c.core.config.SysConf;
|
|
|
import com.uas.platform.b2c.core.constant.IntegerConstant;
|
|
|
import com.uas.platform.b2c.core.constant.ShortConstant;
|
|
|
import com.uas.platform.b2c.core.constant.SplitChar;
|
|
|
+import com.uas.platform.b2c.core.constant.Status;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
@@ -17,6 +18,7 @@ import com.uas.platform.b2c.prod.commodity.dao.*;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.*;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.*;
|
|
|
import com.uas.platform.b2c.prod.commodity.type.ProductConstant;
|
|
|
+import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
import com.uas.platform.b2c.prod.product.brand.modal.Brand;
|
|
|
import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
|
|
|
@@ -45,7 +47,6 @@ import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.model.Constant;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
-import com.uas.platform.core.model.Status;
|
|
|
import com.uas.platform.core.model.Type;
|
|
|
import com.uas.platform.core.persistence.criteria.LogicalExpression;
|
|
|
import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
@@ -1382,7 +1383,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
Long uu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
ResultMap registerAddress = enterpriseService.getCurrencyByRegisterAddress();
|
|
|
String currency = null;
|
|
|
- List<Goods> goodsList = new ArrayList<>();
|
|
|
Set<String> uuids = new HashSet<>();
|
|
|
if (registerAddress.getCode() != CodeType.OK.code()) {
|
|
|
currency = StringConstant.RMB;
|
|
|
@@ -1405,11 +1405,11 @@ public class ProductServiceImpl implements ProductService {
|
|
|
String sql = null;
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
if ((prIdLong != null) && (prIdLong.size() != 0)) {
|
|
|
- sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where ifnull(pp.pr_batchcount, 0) = 0 and p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled, 0) = 1 and p.pr_id in (:ids) and p.pr_id not in (select DISTINCT go_productid from trade$goods where go_productid is not null);";
|
|
|
+ sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled, 0) = 1 and p.pr_id in (:ids);";
|
|
|
map.put("ids", prIdLong);
|
|
|
} else {
|
|
|
// 暂时不会进入当前循环,速度比较低
|
|
|
- sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where ifnull(pp.pr_batchcount, 0) = 0 and p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled,0) = 1 and ifnull(p.pr_standard, 0) = (:standard) and p.pr_enuu = (:enuu) and p.pr_id not in (select DISTINCT go_productid from trade$goods where go_productid is not null);";
|
|
|
+ sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled, 0) = 1 and ifnull(p.pr_standard, 0) = (:standard) and p.pr_enuu = (:enuu);";
|
|
|
map.put("enuu", uu);
|
|
|
map.put("standard", standard);
|
|
|
}
|
|
|
@@ -1429,16 +1429,19 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
List<Goods> goodses = productDetailPutOn(sourceAppNotPutOn, storeName, storeid, currency, property);
|
|
|
- goodsList.addAll(goodses);
|
|
|
+ if (CollectionUtils.isEmpty(goodses)) {
|
|
|
+ return new ResultMap(CodeType.OK.code(), "没有可上架的信息,产品上架必填字段为空或可上架数量为0");
|
|
|
+ }
|
|
|
List<Goods> result = new ArrayList<Goods>();
|
|
|
- goodsService.publishERPProductByBatch(goodsList, uuids, result);
|
|
|
+ goodsService.publishERPProductByBatch(goodses, uuids, result);
|
|
|
List<Long> prids = new ArrayList<>();
|
|
|
for (Goods goods : result) {
|
|
|
prids.add(goods.getProductid());
|
|
|
}
|
|
|
List<ProductPrivate> productPrivates = productPrivateDao.findByPrIds(prids);
|
|
|
for (ProductPrivate productPrivate : productPrivates) {
|
|
|
- productPrivate.setBatchCount(IntegerConstant.YES_SHORT);
|
|
|
+ Integer count = productPrivate.getBatchCount() == null ? 0 : productPrivate.getBatchCount();
|
|
|
+ productPrivate.setBatchCount(count + IntegerConstant.YES_SHORT);
|
|
|
}
|
|
|
productPrivateDao.save(productPrivates);
|
|
|
for (String uuid : uuids) {
|
|
|
@@ -1450,9 +1453,14 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
if ((sourceAppNotPutOn.size() - result.size()) != 0) {
|
|
|
if (!StringUtils.isEmpty(message)) {
|
|
|
- message = message + " ,";
|
|
|
+ message = message + ",";
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(ids)) {
|
|
|
+ // message = message + "失败" + (sourceAppNotPutOn.size() - result.size()) + "个,原因:产品必填字段为空或可上架数量为0";
|
|
|
+ } else {
|
|
|
+ message = message + "失败" + (ids.split(SplitChar.COMMA).length - result.size()) + "个,原因:产品必填字段为空或可上架数量为0";
|
|
|
}
|
|
|
- message = "失败" + (sourceAppNotPutOn.size()- result.size()) + "个, 失败原因:产品上架必填字段为空, 请完善";
|
|
|
+
|
|
|
}
|
|
|
return new ResultMap(CodeType.OK.code(), message);
|
|
|
}
|
|
|
@@ -1505,19 +1513,10 @@ public class ProductServiceImpl implements ProductService {
|
|
|
g.setMaxDelivery(property.getMaxDelivery());
|
|
|
g.setMinDelivery(property.getMinDelivery());
|
|
|
g.setProdNum(product.getProdNum());
|
|
|
- List<String> tags = goodsDao.findTagByProductid(product.getId());
|
|
|
- Integer i = 1;
|
|
|
- String tag = StringConstant.SELF_TAG;
|
|
|
- while(tags.contains(tag + i)) {
|
|
|
- i++;
|
|
|
- }
|
|
|
- g.setTag(tag + i);
|
|
|
g.setBreakUp(Boolean.FALSE);
|
|
|
- g.setReserve(product.getErpReserve());
|
|
|
+
|
|
|
String packaging = (detail == null || detail.getPackaging() == null) ? product.getPackaging(): detail.getPackaging();
|
|
|
- if (packaging == null) {
|
|
|
- packaging = StringConstant.DEFAULTPACKAGING;
|
|
|
- }
|
|
|
+ packaging = packaging == null ? StringConstant.DEFAULTPACKAGING : packaging;
|
|
|
g.setPackaging(packaging);
|
|
|
|
|
|
String produceDate = (detail == null || detail.getProduceDate() == null) ? product.getProduceDate() : detail.getProduceDate();
|
|
|
@@ -1525,38 +1524,90 @@ public class ProductServiceImpl implements ProductService {
|
|
|
|
|
|
Double minPackQty = (detail == null || detail.getMinPackQty() == null) ? product.getMinPackQty() : detail.getMinPackQty();
|
|
|
Double minBuyQty = detail != null ? detail.getMinBuyQty() : null;
|
|
|
- int minPackQtyCom = NumberUtil.compare(minPackQty, DoubleConstant.zero);
|
|
|
- int minBuyQtyCom = NumberUtil.compare(minBuyQty, DoubleConstant.zero);
|
|
|
- if (minPackQtyCom == 0 && minBuyQtyCom == 0) {
|
|
|
- return new ResultMap(CodeType.NOT_COMPLETE_INFO, "上架必填信息缺失");
|
|
|
- } else {
|
|
|
- if (minPackQtyCom == 0 || minBuyQtyCom == 0) {
|
|
|
- minPackQty = minBuyQtyCom == 0 ? minPackQty : minBuyQty;
|
|
|
- minBuyQty = minPackQty;
|
|
|
- }
|
|
|
- double remainder = minBuyQty % minPackQty;
|
|
|
- minBuyQty = NumberUtil.sub(minBuyQty, remainder);
|
|
|
- int k = NumberUtil.compare(minBuyQty, minPackQty);
|
|
|
- if (k < 0) {
|
|
|
- minBuyQty = minPackQty;
|
|
|
- }
|
|
|
+ ResultMap resultMap = g.adjustMinBuyAndMinPack(minPackQty, minBuyQty);
|
|
|
+ if (resultMap.getCode() != CodeType.OK.code()) {
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
- g.setMinPackQty(minPackQty);
|
|
|
- g.setMinBuyQty(minBuyQty);
|
|
|
+
|
|
|
double price = NumberUtil.mul(detail.getPrice(), property.getFluctuateRate());
|
|
|
price = NumberUtil.fractionNumCeil(price, IntegerConstant.PRICE_FRACTION);
|
|
|
+ if (NumberUtil.compare(price, DoubleConstant.zero) < 1) {
|
|
|
+ return new ResultMap(CodeType.NOT_PERMIT.code(), "单价为0", null);
|
|
|
+ }
|
|
|
List<GoodsQtyPrice> list = new ArrayList<>();
|
|
|
- GoodsQtyPrice price1 = new GoodsQtyPrice();
|
|
|
- price1.setStart(g.getMinBuyQty());
|
|
|
- price1.setEnd(DoubleConstant.maxReserve);
|
|
|
- if (currency.equals(StringConstant.RMB)) {
|
|
|
- price1.setRMBPrice(price);
|
|
|
+ GoodsQtyPrice qtyPrice = GoodsQtyPrice.createGoodsQtyPrice(g.getCurrencyName(), g.getMinBuyQty(), DoubleConstant.maxReserve, price);
|
|
|
+ list.add(qtyPrice);
|
|
|
+ g.setPrices(list);
|
|
|
+
|
|
|
+ List<Goods> goodses1 = goodsDao.findByProductId(g.getProductid());
|
|
|
+ Goods sku = GoodsUtil.sameSKU(goodses1, g);
|
|
|
+ GoodsUtil.setTag(goodses1, sku);
|
|
|
+
|
|
|
+ Double erpReserve = getGoodsReserveByErpReserve(product.getErpReserve(), goodses1);
|
|
|
+ if (NumberUtil.compare(erpReserve, DoubleConstant.zero) > 0) {
|
|
|
+ if (sku.getStatus() == null || sku.getStatus().intValue() == Status.REMOVED.value()) {
|
|
|
+ sku.setReserve(erpReserve);
|
|
|
+ } else {
|
|
|
+ sku.setReserve(NumberUtil.add(sku.getReserve(), erpReserve));
|
|
|
+ }
|
|
|
+ return new ResultMap(CodeType.OK.code(), "成功", sku);
|
|
|
} else {
|
|
|
- price1.setUSDPrice(price);
|
|
|
+ return new ResultMap(CodeType.NOT_PERMIT.code(), "没有可上架的数量", null);
|
|
|
}
|
|
|
- list.add(price1);
|
|
|
- g.setPrices(list);
|
|
|
- return new ResultMap(CodeType.OK.code(), "成功", g);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算还剩多少空闲库存
|
|
|
+ *
|
|
|
+ * @param erpReserve erp 的空闲库存
|
|
|
+ * @param goodses1 需要减去 库存的的goods 的
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Double getGoodsReserveByErpReserve(Double erpReserve, List<Goods> goodses1) {
|
|
|
+ List<String> batches = new ArrayList<>();
|
|
|
+ // 目前只统计goods 在售的库存,下架和保存状态的不做调整
|
|
|
+ for (Goods goods : goodses1) {
|
|
|
+ if (goods.getStatus().intValue() == Status.UNAVAILABLE.value() || goods.getStatus().intValue() == Status.AVAILABLE.value()) {
|
|
|
+ erpReserve = NumberUtil.sub(erpReserve, goods.getReserve());
|
|
|
+ }
|
|
|
+ //batches.add(goods.getBatchCode());
|
|
|
+ }
|
|
|
+ //Double qty = getQtyInOrderToBeUpload(batches);
|
|
|
+ // erpReserve = NumberUtil.sub(erpReserve, qty);
|
|
|
+ return erpReserve;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单中还未上传到UAS的数量
|
|
|
+ *
|
|
|
+ * @param batches 批次信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Double getQtyInOrderToBeUpload(List<String> batches) {
|
|
|
+ if (CollectionUtils.isEmpty(batches)) {
|
|
|
+ return DoubleConstant.zero;
|
|
|
+ } else {
|
|
|
+ List<Integer> statuses = new ArrayList<>();
|
|
|
+ statuses.add(Status.TOBEPAID.value());
|
|
|
+ statuses.add(Status.TOBEPAIDAGAGIN.value());
|
|
|
+ statuses.add(Status.CANCELTOBECONFIRMED.value());
|
|
|
+ Double orderDetailQty = orderDetailDao.getgetSumQtyByBatchcodesAndStatus(batches, statuses);
|
|
|
+
|
|
|
+ List<Integer> puStatus = new ArrayList<>();
|
|
|
+ puStatus.add(Status.CONFIRMED.value());
|
|
|
+ puStatus.add(Status.PAID.value());
|
|
|
+ //获取平台还未上传的销售单
|
|
|
+ String sql = "select sum(detail_number) from trade$purchase p left join trade$purchase_detail pd on p.id = pd.purchase_id where p.pu_sendstatus = 202 and pd.go_batch in (:batches) and pd.detail_status in (:status);";
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("batches", batches);
|
|
|
+ map.put("status", puStatus);
|
|
|
+ Double purchaseDetailQty = namedParameterJdbcTemplate.queryForObject(sql, map, Double.class);
|
|
|
+ double qty = NumberUtil.add(orderDetailQty, purchaseDetailQty);
|
|
|
+ return qty;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|