|
|
@@ -5,8 +5,6 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import com.alibaba.fastjson.parser.Feature;
|
|
|
-import com.uas.platform.b2c.advertise.ad.service.RecommendProductService;
|
|
|
-import com.uas.platform.b2c.common.account.dao.UserDao;
|
|
|
import com.uas.platform.b2c.common.account.model.Enterprise;
|
|
|
import com.uas.platform.b2c.common.account.service.EnterpriseService;
|
|
|
import com.uas.platform.b2c.common.base.dao.CommonDao;
|
|
|
@@ -19,26 +17,27 @@ 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.support.log.UsageBufferedLogger;
|
|
|
import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
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;
|
|
|
import com.uas.platform.b2c.prod.commodity.constant.PublicProductUrl;
|
|
|
import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
|
|
|
+import com.uas.platform.b2c.prod.commodity.dao.CommodityInOutboundDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.GoodsHistoryDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.MatchModelDao;
|
|
|
-import com.uas.platform.b2c.prod.commodity.dao.PCBDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ProductDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ProductDetailDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ProductMatchResultDao;
|
|
|
-import com.uas.platform.b2c.prod.commodity.dao.ProductModifyHistoryDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ProductPersonDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ProductPrivateDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ProductReplaceDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ProductStoreStatusDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.V_ProductPersonDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.V_ProductPrivateDao;
|
|
|
+import com.uas.platform.b2c.prod.commodity.model.CommodityInOutbound;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.GoodsHistory;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.GoodsQtyPrice;
|
|
|
@@ -58,11 +57,11 @@ import com.uas.platform.b2c.prod.commodity.model.V_ProductPerson;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
|
|
|
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.InOutboundDetailService;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.ProductAttachService;
|
|
|
import com.uas.platform.b2c.prod.commodity.service.ProductPrivateService;
|
|
|
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.InOutBoundType;
|
|
|
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;
|
|
|
@@ -72,7 +71,6 @@ import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
|
|
|
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.dao.KindInfoDao;
|
|
|
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;
|
|
|
@@ -81,17 +79,16 @@ 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.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;
|
|
|
import com.uas.platform.b2c.trade.util.BoundedExecutor;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
import com.uas.platform.core.model.Constant;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.PageParams;
|
|
|
@@ -99,10 +96,11 @@ 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 javassist.NotFoundException;
|
|
|
import org.apache.commons.beanutils.ConvertUtils;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
-import org.apache.log4j.Logger;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
@@ -123,7 +121,6 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
-import java.lang.reflect.Field;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
@@ -138,19 +135,19 @@ import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
-import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
|
- * Created by wangyc on 2017/5/26.
|
|
|
+ * 物料服务
|
|
|
+ * @author wangyc
|
|
|
+ * @date 2017/5/26
|
|
|
*/
|
|
|
@Service
|
|
|
public class ProductServiceImpl implements ProductService {
|
|
|
|
|
|
- private final Logger logger = Logger.getLogger(getClass());
|
|
|
-
|
|
|
@Autowired
|
|
|
private ProductDao productDao;
|
|
|
|
|
|
@@ -181,30 +178,18 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private ProductPrivateDao productPrivateDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ProductModifyHistoryDao productModifyHistoryDao;
|
|
|
-
|
|
|
@Autowired
|
|
|
private GoodsHistoryService goodsHistoryService;
|
|
|
|
|
|
@Autowired
|
|
|
private GoodsHistoryDao goodsHistoryDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private RecommendProductService recommendProductService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CartService cartService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private GoodsBrowsingHistoryDao goodsBrowsingHistoryDao;
|
|
|
|
|
|
@Autowired
|
|
|
private OrderDetailService orderDetailService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private OrderService orderService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ProductDetailDao productDetailDao;
|
|
|
|
|
|
@@ -250,26 +235,25 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Autowired
|
|
|
private ProductReplaceDao productReplaceDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private KindInfoDao kindInfoDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PCBDao pcbDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private UserDao userDao;
|
|
|
-
|
|
|
/**
|
|
|
* 控制任务提交速度的线程池
|
|
|
*/
|
|
|
private final BoundedExecutor executor;
|
|
|
|
|
|
+ /**
|
|
|
+ * 系统操作日志
|
|
|
+ */
|
|
|
+ private static final UsageBufferedLogger LOGGER = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private SearchService searchService;
|
|
|
|
|
|
@Autowired
|
|
|
private ProductAttachService productAttachService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommodityInOutboundDao commodityInOutboundDao;
|
|
|
+
|
|
|
@Value("#{sys.productServiceIp}")
|
|
|
private String productServiceIp;
|
|
|
|
|
|
@@ -278,9 +262,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
|
|
|
private final CommonDao commonDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private InOutboundDetailService inOutboundDetailService;
|
|
|
-
|
|
|
@Autowired
|
|
|
public ProductServiceImpl(CommonDao commonDao) {
|
|
|
this.commonDao = commonDao;
|
|
|
@@ -288,8 +269,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
executor = new BoundedExecutor(executorService, 1600);
|
|
|
}
|
|
|
|
|
|
- private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
|
|
|
-
|
|
|
@Override
|
|
|
public Page<V_ProductPrivate> getAllProducts(final PageInfo page, String keyword, String type, Long userUU) {
|
|
|
Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
@@ -298,7 +277,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
SPage<Long> ids = searchService.getProducts(enUU, keyword, page.getPageNumber(), page.getPageSize(), type);
|
|
|
if (ids == null || CollectionUtils.isEmpty(ids.getContent())) {
|
|
|
- return new PageImpl<V_ProductPrivate>(new ArrayList<>(), page, 0);
|
|
|
+ return new PageImpl<>(new ArrayList<>(), page, 0);
|
|
|
}
|
|
|
List<Long> idList = ids.getContent();
|
|
|
List<V_ProductPrivate> productList = v_productPrivateDao.findAll(idList);
|
|
|
@@ -340,7 +319,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return new PageImpl<V_ProductPrivate>(productList, page, ids.getTotalElement());
|
|
|
+ return new PageImpl<>(productList, page, ids.getTotalElement());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -352,12 +331,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (StringUtils.isEmpty(type)) {
|
|
|
type = "nStandard";
|
|
|
}
|
|
|
- page.filter("b2cEnabled", (short) 1);
|
|
|
- if (type.contains("standard")) {
|
|
|
- page.filter("standard", (short)1);
|
|
|
- } else if (type.contains("nStandard")) {
|
|
|
- page.filter("standard", (short)0);
|
|
|
- } else if (type.contains("all")) {
|
|
|
+ page.filter("b2cEnabled", IntegerConstant.YES_SHORT);
|
|
|
+ if (type.contains(ProductConstant.STANDARD)) {
|
|
|
+ page.filter("standard", IntegerConstant.YES_SHORT);
|
|
|
+ } else if (type.contains(ProductConstant.NSTANDARD)) {
|
|
|
+ page.filter("standard", IntegerConstant.NO_SHORT);
|
|
|
+ } else if (type.contains(ProductConstant.ALL)) {
|
|
|
page.sorting("createTime", Sort.Direction.DESC);
|
|
|
}
|
|
|
|
|
|
@@ -418,7 +397,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
product.setProductReplaceList(productReplaces);
|
|
|
}
|
|
|
}
|
|
|
- return new PageImpl<V_ProductPerson>(productList, page, productPage.getTotalElements());
|
|
|
+ return new PageImpl<>(productList, page, productPage.getTotalElements());
|
|
|
} else {
|
|
|
return productPage;
|
|
|
}
|
|
|
@@ -469,11 +448,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
for (Long prId : prIds) {
|
|
|
List<ProductPerson> p = productPersonDao.findByProductIdAndUserUU(prId,useruu);
|
|
|
if (CollectionUtils.isEmpty(p)) {
|
|
|
- ProductPerson productPerson = new ProductPerson();
|
|
|
- productPerson.setUserUU(useruu);
|
|
|
- productPerson.setEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- productPerson.setProductId(prId);
|
|
|
- productPerson.setTime(new Date());
|
|
|
+ ProductPerson productPerson = new ProductPerson(useruu, SystemSession.getUser().getEnterprise().getUu(), prId);
|
|
|
productPersonDao.save(productPerson);
|
|
|
count++;
|
|
|
}
|
|
|
@@ -513,13 +488,13 @@ public class ProductServiceImpl implements ProductService {
|
|
|
page.setPageNumber(1);
|
|
|
page.setPageSize(10);
|
|
|
|
|
|
- List<V_ProductPrivate> products = new ArrayList<>();
|
|
|
+ List<V_ProductPrivate> products;
|
|
|
page.filter("enUU", SystemSession.getUser().getEnterprise().getUu());
|
|
|
page.filter("b2cEnabled", com.uas.platform.b2c.prod.commodity.constant.IntegerConstant.YES_INT);
|
|
|
page.sorting(Sort.Direction.DESC, "standard", "id");
|
|
|
- if (type.contains("standard")) {
|
|
|
+ if (type.contains(ProductConstant.STANDARD)) {
|
|
|
page.filter("standard", IntegerConstant.YES_SHORT);
|
|
|
- } else if (type.contains("nStandard")) {
|
|
|
+ } else if (type.contains(ProductConstant.NSTANDARD)) {
|
|
|
page.filter("standard", IntegerConstant.NO_SHORT);
|
|
|
}
|
|
|
if (StringUtils.hasText(keyword)) {
|
|
|
@@ -580,18 +555,15 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
|
|
|
List<ProductPerson> productPersonList = productPersonDao.findByProductIdAndUserUU(id,SystemSession.getUser().getUserUU());
|
|
|
if (!CollectionUtils.isEmpty(productPersonList)) {
|
|
|
-// Map<String,Object> requestMap = new HashMap<>();
|
|
|
-// requestMap.put("userUU",productPersonList.get(0).getUserUU());
|
|
|
-// requestMap.put("productId",productPersonList.get(0).getProductId());
|
|
|
-// String res = restTemplate.postForEntity( productServiceIp+"/product/assign/delete", null, String.class, requestMap).getBody();
|
|
|
Long ppid = productPersonList.get(0).getId();
|
|
|
productPersonDao.delete(ppid);
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
Product product = productDao.findOne(id);
|
|
|
- if (product == null)
|
|
|
+ if (product == null) {
|
|
|
throw new IllegalOperatorException("选择的产品不存在,请重新选择");
|
|
|
+ }
|
|
|
//查看是否存在正常未取消的订单
|
|
|
List<Goods> goodses = goodsDao.findByProductId(product.getId());
|
|
|
Boolean isExistOrder = false;
|
|
|
@@ -648,8 +620,8 @@ public class ProductServiceImpl implements ProductService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ResultMap deleteBatch(String type, Integer isPerson) {
|
|
|
- Integer standard = null;
|
|
|
- List<ProductPerson> personList = new ArrayList<>();
|
|
|
+ Integer standard;
|
|
|
+ List<ProductPerson> personList;
|
|
|
Integer fail = 0;
|
|
|
Integer success = 0;
|
|
|
Integer isHave = 0;
|
|
|
@@ -703,7 +675,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
Set<ProductMatchResult> productMatchResultSet = product.getMatchresults();
|
|
|
productMatchResultDao.delete(productMatchResultSet);
|
|
|
goodsService.deleteGoods(goodses);
|
|
|
- //productDao.delete(product.getId());
|
|
|
ProductPrivate productPrivate = productPrivateService.findByPrId(product.getId());
|
|
|
if (null == productPrivate) {
|
|
|
productPrivate = new ProductPrivate();
|
|
|
@@ -753,14 +724,17 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Override
|
|
|
public Product match(Long id) {
|
|
|
Product product = productDao.findOne(id);
|
|
|
- if (product == null)
|
|
|
+ if (product == null) {
|
|
|
throw new IllegalOperatorException("所选产品不存在");
|
|
|
- if (product.getCmpCode() == null)
|
|
|
+ }
|
|
|
+ if (product.getCmpCode() == null) {
|
|
|
throw new IllegalOperatorException("该产品尚无产品型号,无法匹配");
|
|
|
- if (product.getBrand() == null)
|
|
|
+ }
|
|
|
+ if (product.getBrand() == null) {
|
|
|
throw new IllegalOperatorException("该产品尚无品牌信息,无法匹配");
|
|
|
+ }
|
|
|
|
|
|
- Long brandId = null;
|
|
|
+ Long brandId;
|
|
|
List<Brand> brands = brandDao.findByUpperNameEn(product.getBrand());
|
|
|
if (CollectionUtils.isEmpty(brands)) {
|
|
|
brands = brandDao.findByUpperNameCn(product.getBrand());
|
|
|
@@ -774,8 +748,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
|
|
|
List<Component> components = componentDao.findByCodeAndBrandid(product.getCmpCode(), brandId);
|
|
|
- if (CollectionUtils.isEmpty(components))
|
|
|
+ if (CollectionUtils.isEmpty(components)) {
|
|
|
throw new IllegalOperatorException("匹配失败,商城暂无该型号信息,可前往“器件申请”,提出申请");
|
|
|
+ }
|
|
|
product.setCmpUuId(components.get(0).getUuid());
|
|
|
product.setPbrand(brands.get(0).getNameCn());
|
|
|
product.setPbranden(brands.get(0).getNameEn());
|
|
|
@@ -815,60 +790,39 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Override
|
|
|
public ResultMap matchall(String matchtype) {
|
|
|
Map<String, Integer> map = new HashMap<>();
|
|
|
- boolean flag = true;
|
|
|
- ProductStoreStatus status = productStoreStatusDao.findByEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- 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);
|
|
|
- }
|
|
|
+ ResultMap resultMap = validateProductStatus(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ if (CodeType.NOT_PERMIT.equals(resultMap.getCode())) {
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ ProductStoreStatus status = (ProductStoreStatus)resultMap.getData();
|
|
|
+ /**
|
|
|
+ * 目前 测试没有这个存储过程,暂时注释掉这个代码
|
|
|
+ */
|
|
|
+ //String result = productDao.upateResultByEnuuForB2C(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ String result = "0";
|
|
|
+ if (StringUtils.isEmpty(result)) {
|
|
|
+ map.put("size", 0);
|
|
|
+ map.put("redundance", 0);
|
|
|
} else {
|
|
|
- ProductStoreStatus stroestatus = new ProductStoreStatus();
|
|
|
- stroestatus.setDate(new Date());
|
|
|
- stroestatus.setEnuu(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- stroestatus.setUseruu(SystemSession.getUser().getUserUU());
|
|
|
- stroestatus.setStatus(Status.RUNNING.value());
|
|
|
- status = productStoreStatusDao.save(stroestatus);
|
|
|
- }
|
|
|
- Integer num = null;
|
|
|
- if (flag) {
|
|
|
- /**
|
|
|
- * 目前 测试没有这个存储过程,暂时注释掉这个代码
|
|
|
- */
|
|
|
- //String result = productDao.upateResultByEnuuForB2C(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- String result = "0";
|
|
|
- if (StringUtils.isEmpty(result)) {
|
|
|
- map.put("size", 0);
|
|
|
- map.put("redundance", 0);
|
|
|
- } else {
|
|
|
- String[] split = result.split("-");
|
|
|
- map.put("size", Integer.valueOf(split[0]));
|
|
|
-// map.put("redundance", Integer.valueOf(split[1]));
|
|
|
- }
|
|
|
- Integer fail = productDao.getCountByEnuuAndStatus(SystemSession.getUser().getEnterprise().getUu(), (short)0);
|
|
|
- map.put("fail", fail);
|
|
|
- status.setStatus(Status.FINISH.value());
|
|
|
- productStoreStatusDao.save(status);
|
|
|
+ String[] split = result.split("-");
|
|
|
+ map.put("size", Integer.valueOf(split[0]));
|
|
|
}
|
|
|
+ Integer fail = productDao.getCountByEnuuAndStatus(SystemSession.getUser().getEnterprise().getUu(), (short)0);
|
|
|
+ map.put("fail", fail);
|
|
|
+ status.setStatus(Status.FINISH.value());
|
|
|
+ productStoreStatusDao.save(status);
|
|
|
return ResultMap.success(map);
|
|
|
}
|
|
|
|
|
|
private ResultMap validateProductStatus(Long enUU) {
|
|
|
ProductStoreStatus status = productStoreStatusDao.findByEnuu(enUU);
|
|
|
+ Integer maxInterval = 600000;
|
|
|
if (status != null) {
|
|
|
// 有人正在操作这张单据,不能进行操作
|
|
|
if (status.getStatus().equals(Status.RUNNING.value())) {
|
|
|
Date date = new Date();
|
|
|
long l = date.getTime() - status.getDate().getTime();
|
|
|
- if (l > 600000) {
|
|
|
+ if (l > maxInterval) {
|
|
|
status.setStatus(Status.FINISH.value());
|
|
|
} else {
|
|
|
return new ResultMap(CodeType.NOT_PERMIT, "当前有人正在进行匹配操作,无法进行匹配");
|
|
|
@@ -904,12 +858,30 @@ public class ProductServiceImpl implements ProductService {
|
|
|
ProductStoreStatus status = (ProductStoreStatus) statusResult.getData();
|
|
|
|
|
|
int total = productDao.getCountByEnuuAndStatusAndEnabled(enUU, ShortConstant.NO_SHORT, IntegerConstant.YES_SHORT);
|
|
|
- int success = 0;
|
|
|
- int fail = 0;
|
|
|
+ int success;
|
|
|
+ int fail;
|
|
|
|
|
|
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>() {
|
|
|
+ success = matchSuccess(formatSql);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 匹配成功数量
|
|
|
+ *
|
|
|
+ * @return 成功数量
|
|
|
+ */
|
|
|
+ private int matchSuccess(String formatSql) {
|
|
|
+ return jdbcTemplate.execute(new StatementCallback<Integer>() {
|
|
|
@Override
|
|
|
public Integer doInStatement(Statement statement) throws SQLException, DataAccessException {
|
|
|
statement.execute(formatSql);
|
|
|
@@ -921,15 +893,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -949,23 +912,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
String batch = createNumberService.getTimeNumber("product$match", 8);
|
|
|
// 保存要匹配的id数据
|
|
|
createMatchModel(idList, batch);
|
|
|
- int success = 0;
|
|
|
- int fail = 0;
|
|
|
+ int success;
|
|
|
+ int fail;
|
|
|
|
|
|
String sql = "/*#mycat:db_type=master*/ call PRODUCT_MATCHES_SELECT_V1(%s, %s, %s, @out); select @out";
|
|
|
final String formatSql = String.format(sql, batch, 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;
|
|
|
- }
|
|
|
- });
|
|
|
+ success = matchSuccess(formatSql);
|
|
|
fail = idList.size() - success;
|
|
|
|
|
|
status.setStatus(Status.FINISH.value());
|
|
|
@@ -1194,7 +1146,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
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;
|
|
|
+ List<Goods> addList;
|
|
|
for (Goods goods : oldList) {
|
|
|
List<Goods> goodsList = goodsDao.findRepeatGoodsInProductId(productId, goods.getProduceDate(),
|
|
|
goods.getPackaging(), goods.getMinPackQty(), goods.getMinBuyQty(), goods.getMaxDelivery(),
|
|
|
@@ -1236,25 +1188,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 更新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
|
|
|
@@ -1291,7 +1224,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* @param json
|
|
|
* @return
|
|
|
*/
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
@Override
|
|
|
public ResultMap updateMatch(String json) {
|
|
|
if(StringUtils.isEmpty(json)) {
|
|
|
@@ -1384,7 +1317,8 @@ public class ProductServiceImpl implements ProductService {
|
|
|
ProductDetail productDetail = productDetailDao.findByProductId(id);
|
|
|
if (productDetail != null) {
|
|
|
Double b2cReserve = 0d;
|
|
|
- if (product.getCmpUuId() != null) {// 获取当前商城已上架数量(含锁库存)
|
|
|
+ // 获取当前商城已上架数量(含锁库存)
|
|
|
+ if (product.getCmpUuId() != null) {
|
|
|
b2cReserve = goodsDao.getSumReserveByEnUUAndUuidAndStatus(SystemSession.getUser().getEnterprise().getUu(), product.getCmpUuId(), Status.AVAILABLE.value());
|
|
|
Double lockReserve = orderDetailDao.getSumReserveBySupEnUuAndUuidAndStatus(SystemSession.getUser().getEnterprise().getUu(), product.getCmpUuId(), Status.TOBEPAID.value());
|
|
|
b2cReserve = (b2cReserve == null ? 0d : b2cReserve) + (lockReserve == null ? 0d :lockReserve);
|
|
|
@@ -1430,22 +1364,28 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Override
|
|
|
public ResultMap validitonStandard(JSONObject jsonObject) {
|
|
|
Component component = (Component)jsonObject.get("component");
|
|
|
- if (component == null || component.getCode() == null)
|
|
|
+ if (component == null || component.getCode() == null) {
|
|
|
throw new IllegalOperatorException("请填写器件原厂型号");
|
|
|
+ }
|
|
|
Brand brand = (Brand)jsonObject.get("brand");
|
|
|
- if (brand == null || brand.getNameEn() == null)
|
|
|
+ if (brand == null || brand.getNameEn() == null) {
|
|
|
throw new IllegalOperatorException("请填写品牌英文名");
|
|
|
+ }
|
|
|
List<Brand> brands = brandDao.findByNameEn(brand.getNameEn());
|
|
|
- if (CollectionUtils.isEmpty(brands))
|
|
|
+ if (CollectionUtils.isEmpty(brands)) {
|
|
|
throw new IllegalOperatorException(("商城不存在:" + brand.getNameEn() + " 品牌,请选择商城品牌或申请该品牌"));
|
|
|
+ }
|
|
|
List<Component> componentMatched = componentDao.findByCodeAndBrandid(component.getCode(), brands.get(0).getId());
|
|
|
- if (CollectionUtils.isEmpty(componentMatched)) {// 提交申请为非标准器件则转成器件申请
|
|
|
+ // 提交申请为非标准器件则转成器件申请
|
|
|
+ if (CollectionUtils.isEmpty(componentMatched)) {
|
|
|
Kind kind = (Kind)jsonObject.get("kind");
|
|
|
- if (kind == null || kind.getId() == null)
|
|
|
+ if (kind == null || kind.getId() == null) {
|
|
|
throw new IllegalOperatorException("请选择商城物料名称(类目)");
|
|
|
+ }
|
|
|
String attach = jsonObject.getString("attach");
|
|
|
- if (attach == null)
|
|
|
+ if (attach == null) {
|
|
|
throw new IllegalOperatorException("请上传规格书");
|
|
|
+ }
|
|
|
ComponentSubmit submit = new ComponentSubmit();
|
|
|
submit.setAttach(attach);
|
|
|
submit.setBrandid(brands.get(0).getId());
|
|
|
@@ -1466,11 +1406,13 @@ public class ProductServiceImpl implements ProductService {
|
|
|
@Override
|
|
|
public ProductDetail saveDetail(Long productId, Goods goods) {
|
|
|
Product product = productDao.findOne(productId);
|
|
|
- if (product == null)
|
|
|
+ if (product == null) {
|
|
|
throw new IllegalOperatorException("此物料信息不存在,请重新确认");
|
|
|
+ }
|
|
|
ProductDetail productDetail = productDetailDao.findByProductId(productId);
|
|
|
- if (productDetail == null)
|
|
|
+ if (productDetail == null) {
|
|
|
productDetail = new ProductDetail();
|
|
|
+ }
|
|
|
|
|
|
productDetail.setBreakUp(goods.getBreakUp());
|
|
|
productDetail.setProduceDate(goods.getProduceDate());
|
|
|
@@ -1484,8 +1426,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
productDetail.setMinPackQty(goods.getMinPackQty());
|
|
|
productDetail.setPackaging(goods.getPackaging());
|
|
|
|
|
|
- if (enterpriseService.getCurrencyByRegisterAddress().getData() == null)
|
|
|
+ if (enterpriseService.getCurrencyByRegisterAddress().getData() == null) {
|
|
|
throw new IllegalOperatorException("注册地址为空,无法确认币别信息,请前往-优软云补充注册地址信息");
|
|
|
+ }
|
|
|
String currency = enterpriseService.getCurrencyByRegisterAddress().getData().toString();
|
|
|
List<GoodsQtyPrice> qtyPrice = FastjsonUtils.fromJsonArray(goods.getQtyPrice(), GoodsQtyPrice.class);
|
|
|
if (!CollectionUtils.isEmpty(qtyPrice)) {
|
|
|
@@ -1560,7 +1503,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
Long uu = SystemSession.getUser().getEnterprise().getUu();
|
|
|
ResultMap registerAddress = enterpriseService.getCurrencyByRegisterAddress();
|
|
|
- String currency = null;
|
|
|
+ String currency;
|
|
|
Set<String> uuids = new HashSet<>();
|
|
|
if (registerAddress.getCode() != CodeType.OK.code()) {
|
|
|
currency = StringConstant.RMB;
|
|
|
@@ -1568,7 +1511,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
currency = registerAddress.getData().toString();
|
|
|
}
|
|
|
StoreIn storeIn = storeInService.findByEnUU(uu);
|
|
|
- String storeName = null, storeid = null;
|
|
|
+ String storeName, storeid;
|
|
|
if (storeIn == null || storeIn.getStatus() != StoreStatus.OPENED) {
|
|
|
storeName = sysConf.getEnName();
|
|
|
storeid = sysConf.getStoreid();
|
|
|
@@ -1580,7 +1523,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (property == null) {
|
|
|
return new ResultMap(CodeType.NOT_COMPLETE_INFO.code(), "请先设置上架参数", null);
|
|
|
}
|
|
|
- String sql = null;
|
|
|
+ String sql;
|
|
|
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 p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled, 0) = 1 and p.pr_id in (:ids);";
|
|
|
@@ -1743,52 +1686,15 @@ public class ProductServiceImpl implements ProductService {
|
|
|
*/
|
|
|
@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;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 修改非标物料的品牌、物料名称、型号、规格、规格书等信息
|
|
|
*
|
|
|
@@ -1796,7 +1702,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
* @param attachUrl 规格书的地址
|
|
|
* @return the string
|
|
|
*/
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
@Override
|
|
|
public ResultMap updateProduct(String json, String attachUrl) {
|
|
|
if (StringUtils.isEmpty(json)) {
|
|
|
@@ -1826,7 +1732,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
} else {
|
|
|
persistProduct.setSpec((String) specResultMap.getData());
|
|
|
}
|
|
|
- if (productPrivate.getStandard() == IntegerConstant.NO_SHORT || StringUtils.isEmpty(productPrivate.getCmpUuId())) {
|
|
|
+ if (Objects.equals(productPrivate.getStandard(), IntegerConstant.NO_SHORT) || StringUtils.isEmpty(productPrivate.getCmpUuId())) {
|
|
|
Component component = findBybrNameAndcmpCode(productPrivate.getPbranden(), productPrivate.getPcmpcode());
|
|
|
if (component != null) {
|
|
|
//更新物料信息
|
|
|
@@ -2080,7 +1986,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(ids)) {
|
|
|
List<ProductPrivate> productPrivates = productPrivateDao.findByPrIds(ids);
|
|
|
- boolean isExist = false;
|
|
|
+ boolean isExist;
|
|
|
List<ProductPrivate> productPrivatelist = new ArrayList<>();
|
|
|
for (Long id : ids) {
|
|
|
isExist = false;
|
|
|
@@ -2113,8 +2019,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
} catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return ResultMap.success("");
|
|
|
} else {
|
|
|
return ResultMap.success("");
|
|
|
@@ -2134,11 +2038,11 @@ public class ProductServiceImpl implements ProductService {
|
|
|
SPage<Long> ids = searchService.getProducts(null, keyword, params.getPage(), params.getCount(), null);
|
|
|
PageInfo info = new PageInfo(params);
|
|
|
if (null == ids) {
|
|
|
- return new PageImpl<V_ProductPrivate>(Collections.emptyList(), info, 0);
|
|
|
+ return new PageImpl<>(Collections.emptyList(), info, 0);
|
|
|
}
|
|
|
List<Long> idList = ids.getContent();
|
|
|
List<V_ProductPrivate> productList = v_productPrivateDao.findAll(idList);
|
|
|
- return new PageImpl<V_ProductPrivate>(productList, info, ids.getTotalElement());
|
|
|
+ return new PageImpl<>(productList, info, ids.getTotalElement());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -2200,26 +2104,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据物料编号找物料
|
|
|
- *
|
|
|
- * @param prodNum
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Product findProductByProdNum(String prodNum) {
|
|
|
- if (StringUtils.isEmpty(prodNum)) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- List<Product> products = productDao.findByProdNum(prodNum);
|
|
|
- if (CollectionUtils.isEmpty(products)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- return products.get(0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 批量保存,通过jdbctemplate
|
|
|
*
|
|
|
@@ -2309,7 +2193,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
List<Product> products = productDao.findAll(prIds);
|
|
|
List<Product> freshProducts = new ArrayList<>();
|
|
|
- InOutboundDetail detail = null;
|
|
|
+ InOutboundDetail detail;
|
|
|
for (Product product : products) {
|
|
|
for (ReleaseProductByBatch productByBatch : reList) {
|
|
|
if (!productByBatch.getReleaseCode().equals(ReleaseStatus.failure.value()) &&
|
|
|
@@ -2331,7 +2215,7 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (StringUtils.isEmpty(product.getSpec()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
|
|
|
product.setSpec(productByBatch.getSpec());
|
|
|
}
|
|
|
- if ((ignoreImport == IntegerConstant.NO_SHORT) || (NumberUtil.compare(product.getErpReserve(), productByBatch.getReserve()) != 0)) {
|
|
|
+ if ((Objects.equals(ignoreImport, IntegerConstant.NO_SHORT)) || (NumberUtil.compare(product.getErpReserve(), productByBatch.getReserve()) != 0)) {
|
|
|
Double qty = NumberUtil.sub(productByBatch.getReserve(), product.getErpReserve());
|
|
|
if (NumberUtil.compare(qty, DoubleConstant.zero) != 0) {
|
|
|
//做出入库记录
|
|
|
@@ -2486,4 +2370,218 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 卖家中心添加单个物料录入
|
|
|
+ *
|
|
|
+ * @param jsonObject 前端数据封装
|
|
|
+ * @return ResultMap
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap editOne(JSONObject jsonObject) {
|
|
|
+ // 物料信息
|
|
|
+ Product product = (Product)jsonObject.get("product");
|
|
|
+ if (null == product) {
|
|
|
+ return ResultMap.error(new IllegalOperatorException("物料信息不能为空"));
|
|
|
+ }
|
|
|
+ // 库存信息
|
|
|
+ Goods goods = (Goods)jsonObject.get("goods");
|
|
|
+ if (null == goods) {
|
|
|
+ return ResultMap.error(new IllegalOperatorException("库存信息不能为空"));
|
|
|
+ }
|
|
|
+ // PCB
|
|
|
+ Integer isPcb = (Integer)jsonObject.get("isPcb");
|
|
|
+ Long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ Long userUU = SystemSession.getUser().getUserUU();
|
|
|
+ product.setPbrand(product.getBrand());
|
|
|
+ product.setPbranden(product.getBrand());
|
|
|
+ product.setPcmpcode(product.getCmpCode());
|
|
|
+ List<Product> existProducts = productDao.findProductByPcmpcodeAndPbrandenAndEnUU(product.getCmpCode(), product.getBrand(), enUU);
|
|
|
+ // PCB产品做标准判断处理
|
|
|
+ if (null != isPcb && Objects.equals(IntegerConstant.YES_SHORT, isPcb)) {
|
|
|
+ // 判断传入的数据是否是标准的
|
|
|
+ ResultMap resultMap = checkCriterion(product);
|
|
|
+ if (!Objects.equals(CodeType.OK.code(), resultMap.getCode())) {
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Product productInfo;
|
|
|
+ CommodityInOutbound inOutbound = null;
|
|
|
+ // 物料存在,更新
|
|
|
+ if (CollectionUtils.isNotEmpty(existProducts)) {
|
|
|
+ productInfo = existProducts.get(0);
|
|
|
+ // 用户填写库存量是需要做对应的出入库。如果新填写的库存数大于原库存数,做入库。否则做出库。
|
|
|
+ inOutbound = recordInventory(product, existProducts.get(0));
|
|
|
+ BeanUtils.copyProperties(product, productInfo, Product.class);
|
|
|
+ } else {
|
|
|
+ // 物料不存在,新增操作
|
|
|
+ productInfo = product;
|
|
|
+ }
|
|
|
+ // 最小包装数默认为1
|
|
|
+ Double minPackQty = productInfo.getMinPackQty() == null ? DoubleConstant.minReserve : productInfo.getMinPackQty();
|
|
|
+ productInfo.setMinPackQty(minPackQty);
|
|
|
+
|
|
|
+ // 最小起订量默认为最小包装数
|
|
|
+ Double minBuyQty = productInfo.getMinOrder() == null ? productInfo.getMinPackQty() : productInfo.getMinOrder();
|
|
|
+ productInfo.setMinOrder(minBuyQty);
|
|
|
+ // 设置库存信息
|
|
|
+ assignmentGoods(goods, productInfo);
|
|
|
+ productInfo = productDao.save(productInfo);
|
|
|
+ // 保存出入库信息
|
|
|
+ if (null != inOutbound) {
|
|
|
+ inOutbound = commodityInOutboundDao.save(inOutbound);
|
|
|
+ LOGGER.log("出入库历史", "卖家中心单个物料上传进行入库操作", inOutbound.getType(), "", inOutbound.getId());
|
|
|
+ }
|
|
|
+ // 添加到个人物料库
|
|
|
+ bindToPerson(productInfo, userUU, enUU);
|
|
|
+ return ResultMap.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录出入库信息
|
|
|
+ * 如果新填写的库存数大于原库存数,做入库。否则做出库。
|
|
|
+ *
|
|
|
+ * @param product 前台传入的物料数据
|
|
|
+ * @param existProduct 数据库存在的物料信息
|
|
|
+ */
|
|
|
+ private CommodityInOutbound recordInventory(Product product, Product existProduct) {
|
|
|
+ // 入库
|
|
|
+ String type;
|
|
|
+ CommodityInOutbound inOutbound;
|
|
|
+ if (product.getErpReserve() > existProduct.getErpReserve()) {
|
|
|
+ type = InOutBoundType.OTHER_INBOUND;
|
|
|
+ inOutbound = new CommodityInOutbound(type);
|
|
|
+ goodsInventory(product.getErpReserve(), type, existProduct.getId());
|
|
|
+ } else {
|
|
|
+ // 出库
|
|
|
+ type = InOutBoundType.OTHER_OUTBOUND;
|
|
|
+ inOutbound = new CommodityInOutbound(InOutBoundType.OTHER_OUTBOUND);
|
|
|
+ goodsInventory(product.getErpReserve(), type, existProduct.getId());
|
|
|
+ }
|
|
|
+ InOutboundDetail inOutboundDetail = new InOutboundDetail(product);
|
|
|
+ Set<InOutboundDetail> detailSet = new HashSet<>();
|
|
|
+ detailSet.add(inOutboundDetail);
|
|
|
+ inOutbound.setInOutboundDetails(detailSet);
|
|
|
+ return inOutbound;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置库存出入库
|
|
|
+ * GOODS有对应的productId,根据出库时从goods的id最小的开始减,减了之后可能需要修改状态。
|
|
|
+ * 入库时,将新加的库存数加到id值最大的Goods中。
|
|
|
+ *
|
|
|
+ * @param erpReserve 本次传入的库存
|
|
|
+ * @param type 出入库类型
|
|
|
+ * @param productId 物料id
|
|
|
+ */
|
|
|
+ private void goodsInventory(Double erpReserve, String type, Long productId) {
|
|
|
+ // 按goodsId倒序
|
|
|
+ List<Goods> goodsList = goodsDao.findByProductId(productId);
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsList)) {
|
|
|
+ // 入库
|
|
|
+ if (InOutBoundType.OTHER_INBOUND.equals(type)) {
|
|
|
+ final Double[] existReserve = {0D};
|
|
|
+ goodsList.forEach(goods -> existReserve[0] += goods.getReserve() != null ? goods.getReserve() : 0D);
|
|
|
+ Double addQty = erpReserve - existReserve[0];
|
|
|
+ Goods goods = goodsList.get(0);
|
|
|
+ Double reserve = goods.getReserve() != null ? goods.getReserve() : 0D + addQty;
|
|
|
+ goods.setReserve(reserve);
|
|
|
+ goodsDao.save(goods);
|
|
|
+ LOGGER.log("上架商品库存操作", "卖家中心单个物料上传进行入库操作", "增加库存: " + addQty, goods.getCode(), goods.getId());
|
|
|
+ } else if (InOutBoundType.OTHER_OUTBOUND.equals(type)) {
|
|
|
+ // 出库
|
|
|
+ int index = goodsList.size() - 1;
|
|
|
+ Double subQty = 0D;
|
|
|
+ for (int i = index; i >= 0; i --) {
|
|
|
+ Double existQty = goodsList.get(i).getReserve() == null ? 0D : goodsList.get(i).getReserve();
|
|
|
+ if (i == index) {
|
|
|
+ subQty = erpReserve - existQty;
|
|
|
+ } else {
|
|
|
+ subQty -= subQty - existQty;
|
|
|
+ }
|
|
|
+ // 如果当前库存减去已存在的库存大于0,继续减去后面的库存数据
|
|
|
+ Goods goods = goodsList.get(i);
|
|
|
+ if (subQty >= 0) {
|
|
|
+ goods.setReserve(0D);
|
|
|
+ goods = goodsDao.save(goods);
|
|
|
+ } else {
|
|
|
+ goods.setReserve(Math.abs(subQty));
|
|
|
+ goods = goodsDao.save(goods);
|
|
|
+ }
|
|
|
+ LOGGER.log("上架商品库存操作", "卖家中心单个物料上传进行出库操作", existQty + "->" + goods.getReserve(), goods.getCode(), goods.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否标准物料
|
|
|
+ *
|
|
|
+ * @param product 物料信息
|
|
|
+ * @return ResultMap
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultMap checkCriterion(Product product) {
|
|
|
+ List<Brand> brands = brandDao.findByName(product.getBrand());
|
|
|
+ // 先判断标准品牌信息
|
|
|
+ if (CollectionUtils.isEmpty(brands)) {
|
|
|
+ return ResultMap.error(new NotFoundException("品牌为非标准品牌"));
|
|
|
+ }
|
|
|
+ // 判断标准器件信息
|
|
|
+ List<Component> components = componentDao.findByBrandidAndCode(brands.get(0).getId(), product.getCmpCode());
|
|
|
+ if (CollectionUtils.isEmpty(components)) {
|
|
|
+ return ResultMap.error(new NotFoundException("器件为非标准器件"));
|
|
|
+ }
|
|
|
+ return ResultMap.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绑定到个人物料库
|
|
|
+ *
|
|
|
+ * @param productInfo 物料信息
|
|
|
+ * @param userUU 用户UU
|
|
|
+ * @param enUU 企业UU
|
|
|
+ */
|
|
|
+ private void bindToPerson(Product productInfo, Long userUU, Long enUU) {
|
|
|
+ List<ProductPerson> productPersonList = productPersonDao.findByProductIdAndUserUU(productInfo.getId(), userUU);
|
|
|
+ if (CollectionUtils.isEmpty(productPersonList)) {
|
|
|
+ ProductPerson productPerson = new ProductPerson(userUU, enUU, productInfo.getId());
|
|
|
+ productPerson = productPersonDao.save(productPerson);
|
|
|
+ LOGGER.log("个人物料", "新增个人物料", "通过卖家中心单个物料上传绑定个人物料", productPerson.getProduct().getProdNum(), productPerson.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置库存信息
|
|
|
+ *
|
|
|
+ * @param goods 库存
|
|
|
+ * @param productInfo 物料信息
|
|
|
+ */
|
|
|
+ private void assignmentGoods(Goods goods, Product productInfo) {
|
|
|
+ goods = Goods.productConvertGoods(goods, productInfo);
|
|
|
+ goodsService.setGoodsDefault(goods);
|
|
|
+ boolean autoPublish = goods.getAutoPublish() == null ? true : goods.getAutoPublish();
|
|
|
+ goods.setAutoPublish(autoPublish);
|
|
|
+ final Double minBuyQty = goods.getMinBuyQty();
|
|
|
+ if (CollectionUtils.isNotEmpty(goods.getPrices())) {
|
|
|
+ goods.getPrices().forEach(subPrice -> {
|
|
|
+ // 分段数量不能超过最大数量
|
|
|
+ Double endQty = NumberUtil.compare(subPrice.getEnd(), DoubleConstant.maxReserve) == 1 ? DoubleConstant.maxReserve : subPrice.getEnd();
|
|
|
+ subPrice.setEnd(endQty);
|
|
|
+
|
|
|
+ // 起始数量不能大于最小订购数
|
|
|
+ Double startQty = NumberUtil.compare(minBuyQty, subPrice.getStart()) == 1 ? subPrice.getStart() : minBuyQty;
|
|
|
+ subPrice.setStart(startQty);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ goods.setQtyPrice(JSON.toJSONString(goods.getPrices()));
|
|
|
+ StoreIn storeIn = storeInService.findByEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ if (storeIn != null && storeIn.getStatus() == StoreStatus.OPENED) {
|
|
|
+ goods.setStoreid(storeIn.getUuid());
|
|
|
+ goods.setStoreName(storeIn.getStoreName());
|
|
|
+ }
|
|
|
+ goods = goodsDao.save(goods);
|
|
|
+ LOGGER.log("上架商品", "新增上架商品", "通过卖家中心单个物料上传新增上架商品", goods.getCode(), goods.getId());
|
|
|
+ }
|
|
|
}
|