Bläddra i källkod

pcb调整产品导入

wangyc 7 år sedan
förälder
incheckning
19f7a47ecf

+ 2 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/constant/ErrorInfoConstant.java

@@ -37,6 +37,8 @@ public enum  ErrorInfoConstant {
     BRAND_EMPTY_INFO("英文/中文品牌名称不能为空"),
     KIND_EMPTY_INFO("类目(产品名称)不能为空"),
     KIND_LENGTH_INFO("类目(产品名称)不能超过20个字符"),
+    // PCB模块使用
+    KIND_UNSTANDARD("类目(产品名称)不是商城标准类目"),
     BREAK_UP_INFO("请选择可拆卖情况是或否"),
     RESERVE_NUMBER_INFO("库存须填写小于10亿的正整数"),
     PRODUCE_DATE_INFO("生产日期不能为空"),

+ 25 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/constant/UploadConstant.java

@@ -121,6 +121,26 @@ public final class UploadConstant {
      */
     public static final int CUSTOM_LABEL = 17;
 
+    /**
+     * 尺寸(pcb)
+     */
+    public static final int SIZE = 18;
+
+    /**
+     * 颜色(pcb)
+     */
+    public static final int COLOR = 19;
+
+    /**
+     * 铜厚(pcb)
+     */
+    public static final int THICK_COPPER = 20;
+
+    /**
+     * 厚度(pcb)
+     */
+    public static final int THICK = 21;
+
     /**
      * 导入表的最大列数
      */
@@ -155,4 +175,9 @@ public final class UploadConstant {
      * 规格的最大长度
      */
     public static final int SPEC_MAX_BYTE = 50;
+
+    /**
+     * PCB一级类目id
+     */
+    public static final long PCB_PARENTID = 3825L;
 }

+ 100 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java

@@ -286,6 +286,30 @@ public class ReleaseProductByBatch implements Serializable {
 	@Column(name = "rel_selfmindeliverystr")
 	private String selfMinDeliveryStr;
 
+	/**
+	 * 尺寸(pcb)
+	 */
+	@Column(name = "rel_size")
+	private String size;
+
+	/**
+	 * 颜色(pcb)
+	 */
+	@Column(name = "rel_color")
+	private String color;
+
+	/**
+	 * 铜厚(pcb)
+	 */
+	@Column(name = "rel_thickcopper")
+	private String thickCopper;
+
+	/**
+	 * 厚度(pcb)
+	 */
+	@Column(name = "rel_thick")
+	private String thick;
+
 //	/**
 //	 * 商城最长交期
 //	 */
@@ -778,6 +802,50 @@ public class ReleaseProductByBatch implements Serializable {
 
 	}
 
+	public void setSizeByExcel(Object value) {
+		String str = StringUtilB2C.getStr(value);
+		try {
+			if (!StringUtilB2C.isEmpty(str) && str.getBytes("GBK").length <= 256) {
+				setSize(str);
+			}
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e + "指定字符集不支持");
+		}
+	}
+
+	public void setColorByExcel(Object value) {
+		String str = StringUtilB2C.getStr(value);
+		try {
+			if (!StringUtilB2C.isEmpty(str) && str.getBytes("GBK").length <= 256) {
+				setColor(str);
+			}
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e + "指定字符集不支持");
+		}
+	}
+
+	public void setThickCopperByExcel(Object value) {
+		String str = StringUtilB2C.getStr(value);
+		try {
+			if (!StringUtilB2C.isEmpty(str) && str.getBytes("GBK").length <= 256) {
+				setThickCopper(str);
+			}
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e + "指定字符集不支持");
+		}
+	}
+
+	public void setThickByExcel(Object value) {
+		String str = StringUtilB2C.getStr(value);
+		try {
+			if (!StringUtilB2C.isEmpty(str) && str.getBytes("GBK").length <= 256) {
+				setThick(str);
+			}
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e + "指定字符集不支持");
+		}
+	}
+
 	@Override
 	public int hashCode() {
 		int result = (brandNameEn == null ? 0 : brandNameEn.hashCode());
@@ -1693,4 +1761,36 @@ public class ReleaseProductByBatch implements Serializable {
 		this.spec = spec;
 		return this;
 	}
+
+	public String getSize() {
+		return size;
+	}
+
+	public void setSize(String size) {
+		this.size = size;
+	}
+
+	public String getColor() {
+		return color;
+	}
+
+	public void setColor(String color) {
+		this.color = color;
+	}
+
+	public String getThickCopper() {
+		return thickCopper;
+	}
+
+	public void setThickCopper(String thickCopper) {
+		this.thickCopper = thickCopper;
+	}
+
+	public String getThick() {
+		return thick;
+	}
+
+	public void setThick(String thick) {
+		this.thick = thick;
+	}
 }

+ 32 - 4
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ReleaseProductByBatchServiceImpl.java

@@ -36,6 +36,7 @@ import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
 import com.uas.platform.b2c.prod.commodity.util.SheetUtil;
 import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
 import com.uas.platform.b2c.prod.product.kind.dao.KindInfoDao;
+import com.uas.platform.b2c.prod.product.kind.model.KindInfo;
 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;
@@ -184,7 +185,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		int blankNum = 0;
 		if (headerRow != null) {
 			// 验证模板是否为商城模板
-			validateTemplate(headerRow, colNum, currency, isAPerson);
+			validateTemplate(headerRow, colNum, currency, isAPerson, isPcb);
 			for (int r = 2; r <= rowNum; r++) {
 				Row row = sheet.getRow(r);
 				// 英文品牌名称
@@ -696,8 +697,9 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * @param headerRow 首行
 	 * @param colNum	总列
 	 * @param currency	币别
+	 * @param isPcb 是否pcb模块
 	 */
-	private void validateTemplate(Row headerRow, int colNum, String currency, boolean isAPerson) {
+	private void validateTemplate(Row headerRow, int colNum, String currency, boolean isAPerson, boolean isPcb) {
 		if (isAPerson) {
 			if (colNum == UploadConstant.MAX_TOTAL_COLUMN_PERSON) {
 				Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN_PERSON - 1);
@@ -719,8 +721,8 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
 			}
 		} else {
-			if (colNum == UploadConstant.MAX_TOTAL_COLUMN) {
-				Cell errorCell = headerRow.getCell(UploadConstant.MAX_TOTAL_COLUMN - 1);
+			if (colNum == (isPcb ? UploadConstant.MAX_TOTAL_COLUMN_PCB : UploadConstant.MAX_TOTAL_COLUMN)) {
+				Cell errorCell = headerRow.getCell(isPcb ? UploadConstant.MAX_TOTAL_COLUMN_PCB - 1 : UploadConstant.MAX_TOTAL_COLUMN - 1);
 				Object errorCellObj = readWorkBookCell(errorCell, Cell.CELL_TYPE_STRING, 0, 0);
 				String errorHead = StringUtilB2C.replaceLineBreak(String.valueOf(errorCellObj));
 				if (StringUtils.isEmpty(errorHead) || !("错误提示".equals(errorHead))) {
@@ -982,6 +984,12 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		aProduct.setKindByExcel(kindValue);
 		// pcb模块判断类目是否为商城标准pcb类目
 		if (isPcb && !StringUtils.isEmpty(aProduct.getKindName())) {
+			KindInfo kindInfo = kindInfoDao.findByNameCn(aProduct.getKindName());
+			if (kindInfo != null && kindInfo.getId() != null && (kindInfoDao.existsChildByParentId(UploadConstant.PCB_PARENTID, kindInfo.getId()) > 0)) {
+				aProduct.setKindUuid(kindInfo.getId());
+			} else {
+				aProduct.setErrmsg(ErrorInfoConstant.KIND_UNSTANDARD.getInfo());
+			}
 		}
 
 		Object codeValue = readWorkBookCell(row.getCell(UploadConstant.PRODUCT_CODE), Cell.CELL_TYPE_STRING,
@@ -1053,6 +1061,26 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			if (aProduct.getCode() != null && aProduct.getBrandNameEn() != null && aProduct.getTag() != null) {
 				resetTag(aProduct);
 			}
+
+			// 如果是pcb模块,解析尺寸、颜色、铜厚、厚度
+			if (isPcb) {
+				Object sizeValue = readWorkBookCell(row.getCell(UploadConstant.SIZE), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.SIZE);
+				aProduct.setSizeByExcel(sizeValue);
+
+				Object colorValue = readWorkBookCell(row.getCell(UploadConstant.COLOR), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.COLOR);
+				aProduct.setColorByExcel(colorValue);
+
+				Object thickCopperValue = readWorkBookCell(row.getCell(UploadConstant.THICK_COPPER), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.THICK_COPPER);
+				aProduct.setThickCopperByExcel(thickCopperValue);
+
+				Object thickValue = readWorkBookCell(row.getCell(UploadConstant.THICK), Cell.CELL_TYPE_STRING,
+					rowNum, UploadConstant.THICK);
+				aProduct.setThickByExcel(thickValue);
+			}
+
 		} else {
 			Object packageMethodValue = readWorkBookCell(row.getCell(UploadConstant.SPECIFICATION), Cell.CELL_TYPE_STRING,
 					rowNum, UploadConstant.SPECIFICATION);

+ 15 - 0
src/main/java/com/uas/platform/b2c/prod/product/kind/dao/KindInfoDao.java

@@ -49,4 +49,19 @@ public interface KindInfoDao extends JpaSpecificationExecutor<KindInfo>, JpaRepo
 	@Query("select k from KindInfo k where k.parentid = :parentid")
 	public List<KindInfo> findByParentid(@Param("parentid")Long parentid);
 
+	/**
+	 * 判断该子类目是否存在于该类目的所有子类目中
+	 * @param parentId 父类目
+	 * @param childId 子类目
+	 * @return
+	 */
+	@Query(nativeQuery = true, value = "select find_in_set(:childId, findLeafKind(:parentId))")
+	public Integer existsChildByParentId(@Param("parentid") Long parentId, @Param("childId") Long childId);
+
+	/**
+	 * 通过类目名获取类目信息
+	 * @param name
+	 * @return
+	 */
+	public KindInfo findByNameCn(String name);
 }