|
|
@@ -4,13 +4,16 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.platform.b2c.advertise.ad.service.RecommendProductService;
|
|
|
import com.uas.platform.b2c.common.account.service.EnterpriseService;
|
|
|
+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.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.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.type.ProductConstant;
|
|
|
import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
|
|
|
@@ -22,10 +25,16 @@ 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.trade.order.dao.OrderDetailDao;
|
|
|
import com.uas.platform.b2c.trade.order.model.Order;
|
|
|
+import com.uas.platform.b2c.trade.order.model.OrderDetail;
|
|
|
import com.uas.platform.b2c.trade.order.model.Purchase;
|
|
|
import com.uas.platform.b2c.trade.order.model.PurchaseDetail;
|
|
|
import com.uas.platform.b2c.trade.order.service.OrderDetailService;
|
|
|
import com.uas.platform.b2c.trade.order.service.OrderService;
|
|
|
+import com.uas.platform.b2c.trade.order.status.OrderStatus;
|
|
|
+import com.uas.platform.b2c.trade.presale.dao.CartDao;
|
|
|
+import com.uas.platform.b2c.trade.presale.dao.GoodsBrowsingHistoryDao;
|
|
|
+import com.uas.platform.b2c.trade.presale.model.Cart;
|
|
|
+import com.uas.platform.b2c.trade.presale.model.GoodsBrowsingHistory;
|
|
|
import com.uas.platform.b2c.trade.presale.service.CartService;
|
|
|
import com.uas.platform.b2c.trade.support.CodeType;
|
|
|
import com.uas.platform.b2c.trade.support.ResultMap;
|
|
|
@@ -37,6 +46,7 @@ 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;
|
|
|
@@ -45,6 +55,8 @@ 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;
|
|
|
@@ -56,6 +68,7 @@ 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;
|
|
|
@@ -91,6 +104,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private GoodsDao goodsDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CartDao cartDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ProductModifyHistoryDao productModifyHistoryDao;
|
|
|
|
|
|
@@ -109,6 +125,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private CartService cartService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GoodsBrowsingHistoryDao goodsBrowsingHistoryDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private OrderDetailService orderDetailService;
|
|
|
|
|
|
@@ -127,20 +146,30 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private EnterpriseService enterpriseService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysConf sysConf;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductMatchResultDao productMatchResultDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsService goodsService;
|
|
|
+
|
|
|
private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
|
|
|
|
|
|
@Override
|
|
|
public Page<Product> getAllProducts(final PageInfo page, String keyword, String type) {
|
|
|
- page.filter("enUU", SystemSession.getUser().getEnterprise().getUu());
|
|
|
- if(StringUtils.isEmpty(type)) {
|
|
|
- type = "all";
|
|
|
+ page.expression(PredicateUtils.eq("enUU", SystemSession.getUser().getEnterprise().getUu(), true));
|
|
|
+ if (StringUtils.isEmpty(type)) {
|
|
|
+ type = "nStandard";
|
|
|
}
|
|
|
- if(type.contains("standard")) {
|
|
|
+ if (type.contains("standard")) {
|
|
|
page.filter("standard", (short)1);
|
|
|
-// page.filter("b2cEnabled", (short) 1);
|
|
|
- }else if(type.contains("nStandard")){
|
|
|
+ page.filter("b2cEnabled", (short) 1);
|
|
|
+ } else if (type.contains("nStandard")) {
|
|
|
page.filter("standard", (short)0);
|
|
|
- }else if(type.contains("all")) {
|
|
|
+ page.filter("b2cEnabled", (short) 1);
|
|
|
+ } else if (type.contains("all")) {
|
|
|
SimpleExpression[] arr = new SimpleExpression[2];
|
|
|
arr[0] = PredicateUtils.eq("b2cEnabled", (short) 1, false);
|
|
|
arr[1] = PredicateUtils.eq("standard", (short) 1, false);
|
|
|
@@ -149,16 +178,16 @@ public class ProductServiceImpl implements ProductService {
|
|
|
page.orExpression(standard);
|
|
|
page.orExpression(logicalExpression);
|
|
|
page.sorting("standard", Sort.Direction.DESC);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if (StringUtils.hasText(keyword)) {
|
|
|
SimpleExpression code = PredicateUtils.like("prodNum", keyword, true);
|
|
|
+ SimpleExpression kind = PredicateUtils.like("kind", keyword, true);
|
|
|
SimpleExpression brandEn = PredicateUtils.like("pbranden", keyword, true);
|
|
|
SimpleExpression cmpCode = PredicateUtils.like("pcmpcode", keyword, true);
|
|
|
- SimpleExpression[] expressions2 = new SimpleExpression[]{code, brandEn, cmpCode};
|
|
|
- LogicalExpression logicalExpression2 = PredicateUtils.or(expressions2);
|
|
|
- page.expression(logicalExpression2);
|
|
|
+ SimpleExpression[] expressions4 = new SimpleExpression[]{code, kind, brandEn, cmpCode};
|
|
|
+ LogicalExpression logicalExpression4 = PredicateUtils.or(expressions4);
|
|
|
+ page.expression(logicalExpression4);
|
|
|
}
|
|
|
|
|
|
Page<Product> productPage = productDao.findAll(new Specification<Product>() {
|
|
|
@@ -182,29 +211,31 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Product> getProducts(String type, String keyword) {
|
|
|
+ public List<Goods> getProductsGoods(String type, String keyword) {
|
|
|
final PageInfo page = new PageInfo();
|
|
|
page.setPageNumber(1);
|
|
|
page.setPageSize(10);
|
|
|
|
|
|
List<Product> products = new ArrayList<Product>();
|
|
|
page.filter("enUU", SystemSession.getUser().getEnterprise().getUu());
|
|
|
- if(StringUtils.isEmpty(type)) {
|
|
|
- type = "all";
|
|
|
- }
|
|
|
- if(type.contains("standard")) {
|
|
|
- page.filter("standard", (short)1);
|
|
|
- }else if(type.contains("nStandard")){
|
|
|
- page.filter("standard", (short)0);
|
|
|
- }
|
|
|
- if(StringUtils.hasText(keyword)) {
|
|
|
- SimpleExpression code = PredicateUtils.like("kind", keyword, true);
|
|
|
- SimpleExpression brandEn = PredicateUtils.like("pbranden", keyword, true);
|
|
|
- SimpleExpression cmpCode = PredicateUtils.like("pcmpcode", keyword, true);
|
|
|
- SimpleExpression[] expressions2 = new SimpleExpression[] {code, brandEn, cmpCode};
|
|
|
- LogicalExpression logicalExpression2 = PredicateUtils.or(expressions2);
|
|
|
- page.expression(logicalExpression2);
|
|
|
- }
|
|
|
+ page.filter("b2cEnabled", com.uas.platform.b2c.prod.commodity.constant.IntegerConstant.YES_INT);
|
|
|
+ //产品部要求导出是非标和标准全部导出,先注释这条代码
|
|
|
+// if(StringUtils.isEmpty(type)) {
|
|
|
+// type = "all";
|
|
|
+// }
|
|
|
+// if(type.contains("standard")) {
|
|
|
+// page.filter("standard", (short)1);
|
|
|
+// }else if(type.contains("nStandard")){
|
|
|
+// page.filter("standard", (short)0);
|
|
|
+// }
|
|
|
+// if(StringUtils.hasText(keyword)) {
|
|
|
+// SimpleExpression code = PredicateUtils.like("kind", keyword, true);
|
|
|
+// SimpleExpression brandEn = PredicateUtils.like("pbranden", keyword, true);
|
|
|
+// SimpleExpression cmpCode = PredicateUtils.like("pcmpcode", keyword, true);
|
|
|
+// SimpleExpression[] expressions2 = new SimpleExpression[] {code, brandEn, cmpCode};
|
|
|
+// LogicalExpression logicalExpression2 = PredicateUtils.or(expressions2);
|
|
|
+// page.expression(logicalExpression2);
|
|
|
+// }
|
|
|
products = productDao.findAll(new Specification<Product>() {
|
|
|
@Override
|
|
|
public Predicate toPredicate(Root<Product> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
@@ -212,13 +243,32 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return null;
|
|
|
}
|
|
|
});
|
|
|
+ //先按照id降序排列
|
|
|
Collections.sort(products, new Comparator<Product>() {
|
|
|
@Override
|
|
|
public int compare(Product o1, Product o2) {
|
|
|
- return o2.getId().compareTo(o1.getId());
|
|
|
+ return (o2.getId().compareTo(o1.getId()));
|
|
|
}
|
|
|
});
|
|
|
- return products;
|
|
|
+ //后面按照非标与标准排列
|
|
|
+ Collections.sort(products, new Comparator<Product>() {
|
|
|
+ @Override
|
|
|
+ public int compare(Product o1, Product o2) {
|
|
|
+ return o2.getStandard().compareTo(o1.getStandard());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<Goods> goodses = new ArrayList<>();
|
|
|
+ for (Product product : products) {
|
|
|
+ System.out.println(product.getId() + " -" + product.getStandard());
|
|
|
+ List<Goods> goodses1 = goodsDao.findByProductIdOrderByGoodsId(product.getId());
|
|
|
+ if(goodses1.size() > 0) {
|
|
|
+ goodses.addAll(goodses1);
|
|
|
+ }else {
|
|
|
+ Goods g = Goods.productConvertGoods(product);
|
|
|
+ goodses.add(g);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return goodses;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -227,11 +277,38 @@ public class ProductServiceImpl implements ProductService {
|
|
|
Product product = productDao.findOne(id);
|
|
|
if (product == null)
|
|
|
throw new IllegalOperatorException("选择的产品不存在,请重新选择");
|
|
|
- try {
|
|
|
- productDao.delete(id);
|
|
|
- } catch (Exception e) {
|
|
|
- throw new IllegalOperatorException("该产品可能已经被商务平台其他单据引用,无法删除");
|
|
|
- }
|
|
|
+ //查看是否存在正常未取消的订单
|
|
|
+ List<Goods> goodses = goodsDao.findByProductId(product.getId());
|
|
|
+ Boolean isExistOrder = false;
|
|
|
+ String codes = OrderStatus.UNAVAILABLE.getCodes() + "-" + Status.TOBECONFIRMED.value();
|
|
|
+ for (Goods goods : goodses) {
|
|
|
+ List<OrderDetail> orderList = orderDetailService.findOrderDetailByBatchCode(goods.getBatchCode());
|
|
|
+ for (OrderDetail detail : orderList) {
|
|
|
+ Order order = detail.getOrder();
|
|
|
+ int status = order.getStatus() == null ? detail.getStatus() : order.getStatus();
|
|
|
+ if (codes.indexOf(String.valueOf(status)) < 0) {
|
|
|
+ // 区分是否是假单,or_orderids 不为空
|
|
|
+ if (StringUtils.isEmpty(order.getOrderids())) {
|
|
|
+ isExistOrder = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isExistOrder) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!isExistOrder) {
|
|
|
+ //删除外键关联的匹配结果列表,不然删除product失败
|
|
|
+ Set<ProductMatchResult> productMatchResultSet = product.getMatchresults();
|
|
|
+ productMatchResultDao.delete(productMatchResultSet);
|
|
|
+ goodsService.deleteGoods(goodses);
|
|
|
+ productDao.delete(id);
|
|
|
+ } else {
|
|
|
+ throw new
|
|
|
+ IllegalOperatorException("该产品中存在已下单的在售产品信息,不能删除");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -252,10 +329,44 @@ public class ProductServiceImpl implements ProductService {
|
|
|
standard = IntegerConstant.NO_SHORT;
|
|
|
}
|
|
|
List<Product> products = productDao.findProductByEnuuAndStandard(uu, standard);
|
|
|
+ Set<String> uuids = new HashSet<>();
|
|
|
for (Product product : products) {
|
|
|
try {
|
|
|
- productDao.delete(product);
|
|
|
- success++;
|
|
|
+ //查看是否存在正常未取消的订单
|
|
|
+ List<Goods> goodses = goodsDao.findByProductId(product.getId());
|
|
|
+ Boolean isExistOrder = false;
|
|
|
+ String codes = OrderStatus.UNAVAILABLE.getCodes() + "-" + Status.TOBECONFIRMED.value();
|
|
|
+ for (Goods goods : goodses) {
|
|
|
+ List<OrderDetail> orderList = orderDetailService.findOrderDetailByBatchCode(goods.getBatchCode());
|
|
|
+ for (OrderDetail detail : orderList) {
|
|
|
+ Order order = detail.getOrder();
|
|
|
+ Integer status = order.getStatus() == null ? detail.getStatus() : order.getStatus();
|
|
|
+ if(codes.indexOf(String.valueOf(status)) < 0) {
|
|
|
+ //防止虚拟单据
|
|
|
+ if (StringUtils.isEmpty(order.getOrderids())) {
|
|
|
+ isExistOrder = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(isExistOrder) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isExistOrder) {
|
|
|
+ //删除外键关联的匹配结果列表,不然删除product失败
|
|
|
+ Set<ProductMatchResult> productMatchResultSet = product.getMatchresults();
|
|
|
+ productMatchResultDao.delete(productMatchResultSet);
|
|
|
+ goodsService.deleteGoods(goodses);
|
|
|
+ productDao.delete(product.getId());
|
|
|
+ if (!StringUtils.isEmpty(product.getCmpUuId())) {
|
|
|
+ uuids.add(product.getCmpUuId());
|
|
|
+ }
|
|
|
+ success++;
|
|
|
+ }else {
|
|
|
+ fail++;
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
fail++;
|
|
|
}
|
|
|
@@ -276,6 +387,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if((products.size() != 0) && (products.size() == fail.intValue())) {
|
|
|
status = CodeType.ERROR_STATE.code();
|
|
|
}
|
|
|
+ for (String uuid : uuids) {
|
|
|
+ goodsService.updateComponentTradeInfos(uuid);
|
|
|
+ }
|
|
|
return new ResultMap(status, message);
|
|
|
}
|
|
|
|
|
|
@@ -485,6 +599,68 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 一键匹配非标产品,并带出该型号匹配的器件信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap matchNonStandardProduct(){
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ final Long uu = SystemSession.getUser().getUserUU();
|
|
|
+ final Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ ProductStoreStatus status = productStoreStatusDao.findByEnuu(enUU);
|
|
|
+ if (status != null) {
|
|
|
+ // 有人正在操作这张单据,不能进行操作
|
|
|
+ if (status.getStatus().equals(Status.RUNNING.value())) {
|
|
|
+ Date date = new Date();
|
|
|
+ long l = date.getTime() - status.getDate().getTime();
|
|
|
+ if (l > 600000) {
|
|
|
+ status.setStatus(Status.FINISH.value());
|
|
|
+ } else {
|
|
|
+ return new ResultMap(CodeType.NOT_PERMIT, "当前有人正在进行匹配操作,无法进行匹配");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ status.setStatus(Status.RUNNING.value());
|
|
|
+ status = productStoreStatusDao.save(status);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ProductStoreStatus storeStatus = new ProductStoreStatus();
|
|
|
+ storeStatus.setDate(new Date());
|
|
|
+ storeStatus.setEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ storeStatus.setUseruu(SystemSession.getUser().getUserUU());
|
|
|
+ storeStatus.setStatus(Status.RUNNING.value());
|
|
|
+ status = productStoreStatusDao.save(storeStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ int total = productDao.getCountByEnuuAndStatusAndEnabled(enUU, ShortConstant.NO_SHORT, IntegerConstant.YES_SHORT);
|
|
|
+ int success = 0;
|
|
|
+ int fail = 0;
|
|
|
+
|
|
|
+ String sql = "/*#mycat:db_type=master*/ call PRODUCT_MATCHES_V1(%s, %s, @out); select @out";
|
|
|
+ final String formatSql = String.format(sql, enUU, uu);
|
|
|
+ success = jdbcTemplate.execute(new StatementCallback<Integer>() {
|
|
|
+ @Override
|
|
|
+ public Integer doInStatement(Statement statement) throws SQLException, DataAccessException {
|
|
|
+ statement.execute(formatSql);
|
|
|
+ ResultSet rs = statement.getResultSet();
|
|
|
+ if (null != rs) {
|
|
|
+ rs.next();
|
|
|
+ return rs.getInt(1);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ fail = total - success;
|
|
|
+
|
|
|
+ status.setStatus(Status.FINISH.value());
|
|
|
+ productStoreStatusDao.save(status);
|
|
|
+ map.put("total", total);
|
|
|
+ map.put("fail", fail);
|
|
|
+ map.put("success", success);
|
|
|
+
|
|
|
+ return ResultMap.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据标准上架信息 保存对产品包装,包装数量,生产日期的修改
|
|
|
*
|
|
|
@@ -508,6 +684,263 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return product;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存匹配的信息
|
|
|
+ * @param json
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap saveMatchInfo(String json){
|
|
|
+ Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ if (StringUtils.isEmpty(json)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "传入的信息为空");
|
|
|
+ }
|
|
|
+ JSONObject object = FastjsonUtils.fromJson(json, JSONObject.class);
|
|
|
+ Long matchId = object.getLong("matchId");
|
|
|
+ Long detailId = object.getLong("detailId");
|
|
|
+ if (StringUtils.isEmpty(matchId) || StringUtils.isEmpty(detailId)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "匹配参数丢失,刷新后重新");
|
|
|
+ }
|
|
|
+ Product product = productDao.findOne(matchId);
|
|
|
+ if (product == null) {
|
|
|
+ return new ResultMap(CodeType.NOT_EXiST, "匹配产品不存在");
|
|
|
+ }
|
|
|
+ ProductMatchResult result = productMatchResultDao.findOne(detailId);
|
|
|
+ if (result == null) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "匹配结果信息丢失");
|
|
|
+ }
|
|
|
+ List<Product> standardList = productDao.findProductByPcmpcodeAndPbrandenAndEnUUAndStandard(result.getCmpcode(), result.getBranden(), enUU, IntegerConstant.YES_SHORT);
|
|
|
+ Product standardProduct = null;
|
|
|
+ if (!CollectionUtils.isEmpty(standardList)) {
|
|
|
+ standardProduct = standardList.get(0);
|
|
|
+ }
|
|
|
+ List<List<Goods>> repeatList = new ArrayList<>();
|
|
|
+ // 已有对应标准信息,需要判断在售商品是否重复
|
|
|
+ if (standardProduct != null) {
|
|
|
+ repeatList = getRepeatGoodsList(matchId, standardProduct.getId());
|
|
|
+ }
|
|
|
+ // 已有重复需要用户排除重复
|
|
|
+ if (!CollectionUtils.isEmpty(repeatList) && standardProduct != null) {
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("repeatList", repeatList);
|
|
|
+ final Product item = standardProduct;
|
|
|
+ Object brandAndCode = new Object() {
|
|
|
+ private String brandEn = item.getPbranden();
|
|
|
+ private String code = item.getPcmpcode();
|
|
|
+
|
|
|
+ public String getCode() {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+ public String getBrandEn() {
|
|
|
+ return brandEn;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ resultMap.put("brandAndCode", brandAndCode);
|
|
|
+ resultMap.put("beforeId", matchId);
|
|
|
+ resultMap.put("afterId", standardProduct.getId());
|
|
|
+ resultMap.put("resultId", result.getId());
|
|
|
+ return ResultMap.success(resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ Product afterProduct = updateProductAfterMatch(product, result);
|
|
|
+ if (standardProduct == null) {
|
|
|
+ standardProduct = afterProduct;
|
|
|
+ } else {
|
|
|
+ afterProduct.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
+ afterProduct.setBatchCount(0);
|
|
|
+ }
|
|
|
+ productDao.save(afterProduct);
|
|
|
+ updateInfoAfterTurnStandard(matchId, standardProduct);
|
|
|
+ return ResultMap.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMap updateInfoAfterChoose(Long beforeId, Long afterId, Long resultId, List<Long> idArray) {
|
|
|
+ List<GoodsHistory> goodsHistoryList = new ArrayList<>(idArray.size());
|
|
|
+ GoodsHistory goodsHist = null;
|
|
|
+ for (Long id : idArray) {
|
|
|
+ Goods goods = goodsDao.findOne(id);
|
|
|
+ goodsHist = goodsHistoryService.converTGoodsHist(goods,
|
|
|
+ GoodsHistory.OperateType.DELETE_FOR_REPEAT.getPhrase());
|
|
|
+ goodsHist.setMessage(goodsHist.getMessage() + "匹配后因为重复删除");
|
|
|
+ goodsHistoryList.add(goodsHist);
|
|
|
+ goodsDao.delete(id);
|
|
|
+ }
|
|
|
+ goodsHistoryDao.save(goodsHistoryList);
|
|
|
+ Product beforeProduct = productDao.findOne(beforeId);
|
|
|
+ beforeProduct.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
+ ProductMatchResult result = productMatchResultDao.findOne(resultId);
|
|
|
+ if (result == null) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "匹配结果信息丢失");
|
|
|
+ }
|
|
|
+ Product standardProduct = updateProductAfterMatch(beforeProduct, result);
|
|
|
+ productDao.save(standardProduct);
|
|
|
+
|
|
|
+ Product afterProduct = productDao.findOne(afterId);
|
|
|
+ updateInfoAfterTurnStandard(beforeId, afterProduct);
|
|
|
+ return ResultMap.success(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新匹配后的产品库信息
|
|
|
+ * @param product 更新的产品
|
|
|
+ * @param result 匹配的结果
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Product updateProductAfterMatch(Product product, ProductMatchResult result) {
|
|
|
+ product.setPbrand(result.getBrandcn());
|
|
|
+ product.setPbranden(result.getBranden());
|
|
|
+ product.setPbrandid(result.getBrid());
|
|
|
+ product.setPbranduuid(result.getPbranduuid());
|
|
|
+ product.setPcmpcode(result.getCmpcode());
|
|
|
+ product.setCmpUuId(result.getUuid());
|
|
|
+ product.setKind(result.getKindcn());
|
|
|
+ product.setKinden(result.getKinden());
|
|
|
+ product.setKindid(result.getKindid());
|
|
|
+ product.setStandard(1);
|
|
|
+ product.setTostandard(new Date());
|
|
|
+ if (product.getEncapsulation() == null) {
|
|
|
+ product.setEncapsulation(result.getEncapsulation());
|
|
|
+ }
|
|
|
+ product.setCmpImg(result.getImg());
|
|
|
+
|
|
|
+ return product;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 匹配标准后更新相关信息
|
|
|
+ * @param oldId 匹配前产品id
|
|
|
+ * @param product 匹配后的product
|
|
|
+ */
|
|
|
+ private void updateInfoAfterTurnStandard(Long oldId, Product product){
|
|
|
+ List<Goods> goodsList = goodsDao.findByProductId(oldId);
|
|
|
+ List<GoodsHistory> historyList = new ArrayList<>();
|
|
|
+ List<Goods> saveList = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(goodsList)) {
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ updateGoodsInfo(goods, product);
|
|
|
+ GoodsHistory goodsHist = goodsHistoryService.converTGoodsHist(goods,
|
|
|
+ GoodsHistory.OperateType.Modifying.getPhrase());
|
|
|
+ //更新购物车信息
|
|
|
+ List<Cart> cartList = cartDao.findCartByBatch(goods.getBatchCode());
|
|
|
+ updateCartsInfo(goods, cartList);
|
|
|
+ //更新浏览历史
|
|
|
+ List<GoodsBrowsingHistory> historyByBatch = goodsBrowsingHistoryDao.findGoodsBrowsingHistoryByBatch(goods.getBatchCode());
|
|
|
+ updateBrowsingHistory(goods, historyByBatch);
|
|
|
+
|
|
|
+ saveList.add(goods);
|
|
|
+ historyList.add(goodsHist);
|
|
|
+ cartDao.save(cartList);
|
|
|
+ goodsBrowsingHistoryDao.save(historyByBatch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goodsDao.save(saveList);
|
|
|
+ product.setBatchCount(product.getBatchCount() + saveList.size());
|
|
|
+ productDao.save(product);
|
|
|
+ goodsHistoryDao.save(historyList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取重复的在售商品列表
|
|
|
+ * @param oldId 原来的goods列表
|
|
|
+ * @param productId 匹配后的产品Id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<List<Goods>> getRepeatGoodsList(Long oldId, Long productId) {
|
|
|
+ List<Goods> oldList = goodsDao.findByProductId(oldId);
|
|
|
+ List<List<Goods>> resultList = new ArrayList<>();
|
|
|
+ List<Goods> addList = null;
|
|
|
+ for (Goods goods : oldList) {
|
|
|
+ List<Goods> goodsList = goodsDao.findRepeatGoodsInProductId(productId, goods.getProduceDate(),
|
|
|
+ goods.getPackaging(), goods.getMinPackQty(), goods.getMinBuyQty(), goods.getMaxDelivery(),
|
|
|
+ goods.getMinDelivery(), goods.getUnit());
|
|
|
+ if (!CollectionUtils.isEmpty(goodsList)) {
|
|
|
+ addList = new ArrayList<>();
|
|
|
+ Goods sameGoods = goodsList.get(0);
|
|
|
+ if (sameGoods.getStoreid().equals(sysConf.getStoreid())) {
|
|
|
+ sameGoods.setSelfSale("寄售");
|
|
|
+ } else {
|
|
|
+ sameGoods.setSelfSale("自营");
|
|
|
+ }
|
|
|
+ addList.add(sameGoods);
|
|
|
+
|
|
|
+ if (goods.getStoreid().equals(sysConf.getStoreid())) {
|
|
|
+ goods.setSelfSale("寄售");
|
|
|
+ } else {
|
|
|
+ goods.setSelfSale("自营");
|
|
|
+ }
|
|
|
+ addList.add(goods);
|
|
|
+ resultList.add(addList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新浏览历史信息
|
|
|
+ * @param goods
|
|
|
+ * @param historyByBatch
|
|
|
+ */
|
|
|
+ private void updateBrowsingHistory(Goods goods, List<GoodsBrowsingHistory> historyByBatch) {
|
|
|
+ for (GoodsBrowsingHistory gb : historyByBatch) {
|
|
|
+ gb.setCode(goods.getCode());
|
|
|
+ gb.setKindNameCn(goods.getKindNameCn());
|
|
|
+ gb.setBrandNameCn(goods.getBrandNameCn());
|
|
|
+ gb.setBrandNameEn(goods.getBrandNameEn());
|
|
|
+ gb.setImg(goods.getImg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新GoodsHistory信息
|
|
|
+ */
|
|
|
+ private void updateGoodsHistoryInfo(Goods goods, List<GoodsHistory> history) {
|
|
|
+ for (GoodsHistory gh : history) {
|
|
|
+ gh.setCode(goods.getCode());
|
|
|
+ gh.setUuid(goods.getUuid());
|
|
|
+ gh.setKindNameCn(goods.getKindNameCn());
|
|
|
+ gh.setImg(goods.getImg());
|
|
|
+ gh.setBranduuid(goods.getBranduuid());
|
|
|
+ gh.setKindNameCn(goods.getKindNameCn());
|
|
|
+ gh.setKindUuid(goods.getKindUuid());
|
|
|
+ gh.setBrandNameCn(goods.getBrandNameCn());
|
|
|
+ gh.setBrandNameEn(goods.getBrandNameEn());
|
|
|
+ gh.setBranduuid(goods.getBranduuid());
|
|
|
+ gh.setBrandid(goods.getBrandid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param goods
|
|
|
+ * @param cartList
|
|
|
+ */
|
|
|
+ private void updateCartsInfo(Goods goods, List<Cart> cartList) {
|
|
|
+ for (Cart cart : cartList){
|
|
|
+ cart.setCode(goods.getCode());
|
|
|
+ cart.setBrName(goods.getBrandNameEn());
|
|
|
+ cart.setKiName(goods.getKindNameCn());
|
|
|
+ cart.setImg(goods.getImg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新在售信息
|
|
|
+ */
|
|
|
+ private void updateGoodsInfo(Goods goods, Product product) {
|
|
|
+ goods.setProductid(product.getId());
|
|
|
+ goods.setProdNum(product.getProdNum());
|
|
|
+ goods.setUuid(product.getCmpUuId());
|
|
|
+ goods.setCode(product.getPcmpcode());
|
|
|
+ goods.setImg(product.getCmpImg());
|
|
|
+ goods.setKindUuid(product.getKindid());
|
|
|
+ goods.setKindNameCn(product.getKind());
|
|
|
+ goods.setBrandNameCn(product.getPbrand());
|
|
|
+ goods.setBrandNameEn(product.getPbranden());
|
|
|
+ goods.setBrandid(product.getPbrandid());
|
|
|
+ goods.setBranduuid(product.getPbranduuid());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 用户选择对应的品牌和类目,更新非标产品为标准产品
|
|
|
* @param json
|
|
|
@@ -724,5 +1157,39 @@ public class ProductServiceImpl implements ProductService {
|
|
|
|
|
|
return productDetailDao.save(productDetail);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Integer> getProductCount() {
|
|
|
+ Map<String, Integer> resultMap = new HashMap<>();
|
|
|
+ Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ if (enUU == null){
|
|
|
+ throw new IllegalOperatorException("店铺信息丢失,请刷新后重试");
|
|
|
+ }
|
|
|
+ int standard = productDao.getCountByEnuuAndStatusAndEnabled(enUU, ShortConstant.YES_SHORT, IntegerConstant.YES_SHORT);
|
|
|
+ int nStandard = productDao.getCountByEnuuAndStatusAndEnabled(enUU, ShortConstant.NO_SHORT, IntegerConstant.YES_SHORT);
|
|
|
+ resultMap.put("standard", standard);
|
|
|
+ resultMap.put("nStandard", nStandard);
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Goods> getGoodsByProductId(Long id) {
|
|
|
+ return goodsService.getGoodsByProductId(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取信息
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Product getProductById(Long id) {
|
|
|
+ if(id == null) {
|
|
|
+ return null;
|
|
|
+ }else {
|
|
|
+ return productDao.findOne(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|