|
|
@@ -20,10 +20,13 @@ 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.RegexConstant;
|
|
|
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.ErrorInfoConstant;
|
|
|
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.constant.UploadConstant;
|
|
|
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;
|
|
|
@@ -121,6 +124,7 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
+import java.io.*;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
@@ -139,6 +143,8 @@ import java.util.Objects;
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* 物料服务
|
|
|
@@ -245,6 +251,11 @@ public class ProductServiceImpl implements ProductService {
|
|
|
*/
|
|
|
private static final UsageBufferedLogger LOGGER = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
|
|
|
+ /**
|
|
|
+ * 验证产品型号
|
|
|
+ */
|
|
|
+ private static final Pattern codePattern = Pattern.compile(RegexConstant.LetterAndDigitAndEnglishSpecialCharacter);
|
|
|
+
|
|
|
@Autowired
|
|
|
private SearchService searchService;
|
|
|
|
|
|
@@ -2384,6 +2395,11 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (null == product) {
|
|
|
return ResultMap.error(new IllegalOperatorException("物料信息不能为空"));
|
|
|
}
|
|
|
+ // 检验物料信息
|
|
|
+ ResultMap resultMap = checkProductInfo(product);
|
|
|
+ if (Objects.equals(CodeType.ERROR.code(), resultMap.getCode())) {
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
// 库存信息
|
|
|
Goods goods = (Goods)jsonObject.get("goods");
|
|
|
if (null == goods) {
|
|
|
@@ -2400,9 +2416,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
// PCB产品做标准判断处理
|
|
|
if (null != isPcb && Objects.equals(IntegerConstant.YES_SHORT, isPcb)) {
|
|
|
// 判断传入的数据是否是标准的
|
|
|
- ResultMap resultMap = checkCriterion(product);
|
|
|
- if (!Objects.equals(CodeType.OK.code(), resultMap.getCode())) {
|
|
|
- return resultMap;
|
|
|
+ ResultMap criterionResultMap = checkCriterion(product);
|
|
|
+ if (Objects.equals(CodeType.ERROR.code(), criterionResultMap.getCode())) {
|
|
|
+ return criterionResultMap;
|
|
|
}
|
|
|
}
|
|
|
Product productInfo;
|
|
|
@@ -2437,6 +2453,86 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return ResultMap.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验传入的物料信息
|
|
|
+ *
|
|
|
+ * @param product 物料信息
|
|
|
+ * @return ResultMap
|
|
|
+ */
|
|
|
+ private ResultMap checkProductInfo(Product product) {
|
|
|
+ StringBuffer errMsg = new StringBuffer();
|
|
|
+ String GBK_CHARSET_NAME = "GBK";
|
|
|
+ String UTF_8_CHARSET_NAME = "UTF-8";
|
|
|
+ int maxBrandEnLength = 50;
|
|
|
+ int maxBrandCnLength = 25;
|
|
|
+ int maxKindLength = 20;
|
|
|
+ // 验证品牌
|
|
|
+ if (StringUtils.isEmpty(product.getBrand())) {
|
|
|
+ jointErrMsg(errMsg, ErrorInfoConstant.BRAND_EMPTY_INFO.getInfo());
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ if (product.getBrand().getBytes(GBK_CHARSET_NAME).length > maxBrandCnLength
|
|
|
+ || product.getBrand().getBytes(UTF_8_CHARSET_NAME).length > maxBrandEnLength) {
|
|
|
+ jointErrMsg(errMsg, ErrorInfoConstant.BRAND_LENGTH_INFO.getInfo());
|
|
|
+ }
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ jointErrMsg(errMsg, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 校验类目
|
|
|
+ if (StringUtils.isEmpty(product.getKind())) {
|
|
|
+ jointErrMsg(errMsg, ErrorInfoConstant.KIND_EMPTY_INFO.getInfo());
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ if (product.getKind().getBytes(GBK_CHARSET_NAME).length > maxKindLength) {
|
|
|
+ jointErrMsg(errMsg, ErrorInfoConstant.KIND_LENGTH_INFO.getInfo());
|
|
|
+ }
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ jointErrMsg(errMsg, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 验证型号
|
|
|
+ if (!StringUtils.isEmpty(product.getCmpCode())) {
|
|
|
+ String code = product.getCmpCode().trim();
|
|
|
+ Matcher matcher = codePattern.matcher(code);
|
|
|
+ if (!matcher.find()) {
|
|
|
+ jointErrMsg(errMsg, ErrorInfoConstant.CODE_PATTERN_INFO.getInfo());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (code.getBytes("GBK").length > 100) {
|
|
|
+ jointErrMsg(errMsg, ErrorInfoConstant.CODE_LENGTH_INFO.getInfo());
|
|
|
+ }
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ jointErrMsg(errMsg, e.getMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ jointErrMsg(errMsg, ErrorInfoConstant.CODE_EMPTY_INFO.getInfo());
|
|
|
+ }
|
|
|
+ // 规格处理
|
|
|
+ if (!StringUtils.isEmpty(product.getSpec())) {
|
|
|
+ String str = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutStringIgnoreEncode(product.getSpec(), UploadConstant.SPEC_MAX_BYTE);
|
|
|
+ product.setSpec(str);
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(errMsg)) {
|
|
|
+ return ResultMap.error(new IllegalOperatorException(errMsg.toString()));
|
|
|
+ }
|
|
|
+ return ResultMap.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拼接错误信息
|
|
|
+ *
|
|
|
+ * @param errMsg 错误信息
|
|
|
+ * @param info 错误信息
|
|
|
+ * @return errMsg
|
|
|
+ */
|
|
|
+ private void jointErrMsg(StringBuffer errMsg, String info) {
|
|
|
+ if (errMsg.length() > 0) {
|
|
|
+ errMsg.append(",");
|
|
|
+ }
|
|
|
+ errMsg.append(info);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 记录出入库信息
|
|
|
* 如果新填写的库存数大于原库存数,做入库。否则做出库。
|
|
|
@@ -2514,7 +2610,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 判断是否标准物料
|
|
|
*
|
|
|
@@ -2560,6 +2655,13 @@ public class ProductServiceImpl implements ProductService {
|
|
|
*/
|
|
|
private void assignmentGoods(Goods goods, Product productInfo) {
|
|
|
goods = Goods.productConvertGoods(goods, productInfo);
|
|
|
+ if (productInfo.getId() != null) {
|
|
|
+ List<Goods> goodsList = goodsDao.findByProductId(productInfo.getId());
|
|
|
+ if (CollectionUtils.isNotEmpty(goodsList)) {
|
|
|
+ goods.setId(goodsList.get(0).getId());
|
|
|
+ goods.setProductid(productInfo.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
goodsService.setGoodsDefault(goods);
|
|
|
boolean autoPublish = goods.getAutoPublish() == null ? true : goods.getAutoPublish();
|
|
|
goods.setAutoPublish(autoPublish);
|