|
|
@@ -10,11 +10,14 @@ import com.uas.platform.b2c.core.constant.ShortConstant;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.*;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.*;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.GoodsHistoryService;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.GoodsService;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.ProductService;
|
|
|
+import com.uas.platform.b2c.prod.commodity.service.UASBatchPutOnPropertyService;
|
|
|
import com.uas.platform.b2c.prod.commodity.type.ProductConstant;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
import com.uas.platform.b2c.prod.product.brand.modal.Brand;
|
|
|
@@ -23,6 +26,9 @@ import com.uas.platform.b2c.prod.product.component.dao.ComponentSubmitDao;
|
|
|
import com.uas.platform.b2c.prod.product.component.modal.Component;
|
|
|
import com.uas.platform.b2c.prod.product.component.modal.ComponentSubmit;
|
|
|
import com.uas.platform.b2c.prod.product.kind.model.Kind;
|
|
|
+import com.uas.platform.b2c.prod.store.model.StoreIn;
|
|
|
+import com.uas.platform.b2c.prod.store.model.StoreStatus;
|
|
|
+import com.uas.platform.b2c.prod.store.service.StoreInService;
|
|
|
import com.uas.platform.b2c.trade.order.dao.OrderDetailDao;
|
|
|
import com.uas.platform.b2c.trade.order.model.Order;
|
|
|
import com.uas.platform.b2c.trade.order.model.OrderDetail;
|
|
|
@@ -46,7 +52,6 @@ import com.uas.platform.core.model.Type;
|
|
|
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 oracle.jdbc.oracore.OracleType;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -55,8 +60,6 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.jdbc.core.CallableStatementCallback;
|
|
|
-import org.springframework.jdbc.core.CallableStatementCreator;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.StatementCallback;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -68,10 +71,10 @@ import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
import java.lang.reflect.Field;
|
|
|
-import java.sql.CallableStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.sql.Statement;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
@@ -155,6 +158,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private GoodsService goodsService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StoreInService storeInService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UASBatchPutOnPropertyService uasBatchPutOnPropertyService;
|
|
|
+
|
|
|
private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
|
|
|
|
|
|
@Override
|
|
|
@@ -1177,5 +1186,149 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return productDao.findOne(id);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户批量上架
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap batchPutOn() {
|
|
|
+ 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;
|
|
|
+ } else {
|
|
|
+ currency = registerAddress.getData().toString();
|
|
|
+ }
|
|
|
+ StoreIn storeIn = storeInService.findByEnUU(uu);
|
|
|
+ String storeName = null, storeid = null;
|
|
|
+ if (storeIn == null || storeIn.getStatus() != StoreStatus.OPENED) {
|
|
|
+ storeName = sysConf.getEnName();
|
|
|
+ storeid = sysConf.getStoreid();
|
|
|
+ } else {
|
|
|
+ storeName = storeIn.getStoreName();
|
|
|
+ storeid = storeIn.getUuid();
|
|
|
+ }
|
|
|
+ UASBatchPutOnProperty property = uasBatchPutOnPropertyService.get();
|
|
|
+ // 暂时先不考虑数据过多的情况
|
|
|
+// Integer count = productDao.findCountByEnUUAndSourceAppNotPutOn(uu, StringConstant.ERP);
|
|
|
+// if (count > 1000) {
|
|
|
+// pa
|
|
|
+// } else {
|
|
|
+// List<Product> sourceAppNotPutOn = productDao.findByEnUUAndSourceAppNotPutOn(uu, StringConstant.ERP);
|
|
|
+// List<Goods> goodses = productDetailPutOn(sourceAppNotPutOn, storeName, storeid, currency, property);
|
|
|
+// goodsList.addAll(goodses);
|
|
|
+// }
|
|
|
+
|
|
|
+ List<Product> sourceAppNotPutOn = productDao.findByEnUUAndSourceAppNotPutOn(uu, StringConstant.ERP);
|
|
|
+ if (sourceAppNotPutOn.size() == 0) {
|
|
|
+ return new ResultMap(CodeType.OK.code(), "没有可上架的信息", null);
|
|
|
+ }
|
|
|
+ List<Goods> goodses = productDetailPutOn(sourceAppNotPutOn, storeName, storeid, currency, property);
|
|
|
+ goodsList.addAll(goodses);
|
|
|
+ List<Goods> result = new ArrayList<Goods>();
|
|
|
+ goodsService.publishByBatch(goodsList, uuids, result);
|
|
|
+ for (String uuid : uuids) {
|
|
|
+ goodsService.updateComponentTradeInfos(uuid);
|
|
|
+ }
|
|
|
+ String message = "";
|
|
|
+ if (result.size() != 0) {
|
|
|
+ message = "成功上架" + result.size() + "个";
|
|
|
+ }
|
|
|
+ if ((sourceAppNotPutOn.size() - result.size()) != 0) {
|
|
|
+ if (!StringUtils.isEmpty(message)) {
|
|
|
+ message = " ,";
|
|
|
+ }
|
|
|
+ message = "失败" + (sourceAppNotPutOn.size()- result.size()) + "个";
|
|
|
+ }
|
|
|
+ return new ResultMap(CodeType.OK.code(), message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<Goods> productDetailPutOn(List<Product> products, String storeName, String storeid, String currency, UASBatchPutOnProperty property) {
|
|
|
+ List<Goods> goodses = new ArrayList<>();
|
|
|
+ for (Product product : products) {
|
|
|
+ ProductDetail productDetail = productDetailDao.findByProductId(product.getId());
|
|
|
+ ResultMap resultMap = productsConvertGoods(product, productDetail, storeName, storeid, currency, property);
|
|
|
+ if (resultMap.getCode() == CodeType.OK.code()) {
|
|
|
+ goodses.add((Goods) resultMap.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return goodses;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物料转 goods 信息
|
|
|
+ *
|
|
|
+ * @param product
|
|
|
+ * @param detail
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private ResultMap productsConvertGoods(Product product, ProductDetail detail, String storeName, String storeid, String currency, UASBatchPutOnProperty property) {
|
|
|
+ Goods g = new Goods();
|
|
|
+ g.setProductid(product.getId());
|
|
|
+ g.setUnit(product.getUnit());
|
|
|
+ g.setImg(product.getCmpImg());
|
|
|
+ g.setUuid(product.getCmpUuId());
|
|
|
+ g.setCode(product.getPcmpcode());
|
|
|
+ g.setBrandNameCn(product.getPbrand());
|
|
|
+ g.setBrandid(product.getPbrandid());
|
|
|
+ g.setBranduuid(product.getPbranduuid());
|
|
|
+ g.setBrandNameEn(product.getPbranden());
|
|
|
+ g.setKindNameCn(product.getKind());
|
|
|
+ g.setKindUuid(product.getKindid());
|
|
|
+ g.setCurrencyName(currency);
|
|
|
+ g.setStoreName(storeName);
|
|
|
+ g.setStoreid(storeid);
|
|
|
+ g.setMaxDelivery(property.getMaxDelivery());
|
|
|
+ g.setMinDelivery(property.getMinDelivery());
|
|
|
+ g.setProdNum(product.getProdNum());
|
|
|
+ g.setTag(StringConstant.INIT_TAG);
|
|
|
+ g.setPackaging(detail.getPackaging() == null ? product.getPackaging(): detail.getPackaging());
|
|
|
+ if (g.getPackaging() == null) {
|
|
|
+ g.setPackaging(StringConstant.DEFAULTPACKAGING);
|
|
|
+ }
|
|
|
+ g.setProduceDate(detail.getProduceDate() == null ? product.getProduceDate() : detail.getProduceDate());
|
|
|
+ if (g.getProduceDate() == null) {
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String format = formatter.format(new Date());
|
|
|
+ g.setProduceDate(format);
|
|
|
+ }
|
|
|
+ g.setBreakUp(Boolean.FALSE);
|
|
|
+ g.setReserve(detail.getReserve());
|
|
|
+ g.setMinPackQty(detail.getMinPackQty() == null ? product.getMinPackQty() : detail.getMinPackQty());
|
|
|
+ g.setMinBuyQty(detail.getMinBuyQty());
|
|
|
+ if (g.getMinPackQty() == null && g.getMinBuyQty() == null) {
|
|
|
+ return new ResultMap(CodeType.NOT_COMPLETE_INFO, "上架必填信息缺失");
|
|
|
+ } else {
|
|
|
+ if (g.getMinBuyQty() == null || g.getMinPackQty() == null) {
|
|
|
+ Double d = g.getMinBuyQty() == null ? g.getMinPackQty() : g.getMinBuyQty();
|
|
|
+ g.setMinBuyQty(d);
|
|
|
+ g.setMinPackQty(d);
|
|
|
+ }
|
|
|
+ double div = NumberUtil.div(g.getMinBuyQty(), g.getMinPackQty());
|
|
|
+ if (NumberUtil.compare(div, DoubleConstant.zero) != 0) {
|
|
|
+ g.setMinBuyQty(NumberUtil.sub(g.getMinBuyQty(), div));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ double price = NumberUtil.mul(detail.getPrice(), property.getFluctuateRate());
|
|
|
+ price = NumberUtil.fractionNumCeil(price, IntegerConstant.PRICE_FRACTION);
|
|
|
+ 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);
|
|
|
+ } else {
|
|
|
+ price1.setUSDPrice(price);
|
|
|
+ }
|
|
|
+ list.add(price1);
|
|
|
+ g.setPrices(list);
|
|
|
+ return new ResultMap(CodeType.OK.code(), "成功", g);
|
|
|
+ }
|
|
|
}
|
|
|
|