|
|
@@ -1,11 +1,14 @@
|
|
|
package com.uas.platform.b2c.prod.commodity.service.impl;
|
|
|
|
|
|
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;
|
|
|
import com.uas.platform.b2c.core.config.SysConf;
|
|
|
import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
import com.uas.platform.b2c.core.utils.NumberUtil;
|
|
|
import com.uas.platform.b2c.core.utils.RegexConstant;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
|
|
|
+import com.uas.platform.b2c.prod.commodity.constant.ShortConstant;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.dao.ReleaseProductByBatchDao;
|
|
|
import com.uas.platform.b2c.prod.commodity.model.Goods;
|
|
|
@@ -18,12 +21,12 @@ import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
|
|
|
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.StringConstant.Currency;
|
|
|
import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
import com.uas.platform.core.model.PageInfo;
|
|
|
import com.uas.platform.core.model.ReleaseStatus;
|
|
|
import com.uas.platform.core.model.Type;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.commons.lang.ArrayUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -45,6 +48,7 @@ import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import static com.uas.platform.b2c.core.utils.NumberUtil.fractionNumCeil;
|
|
|
+import static java.util.Collections.emptyList;
|
|
|
|
|
|
@Service
|
|
|
public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchService {
|
|
|
@@ -70,6 +74,9 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
@Autowired
|
|
|
private SysConf SysConf;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EnterpriseService enterpriseService;
|
|
|
+
|
|
|
@Override
|
|
|
public ReleaseProductByBatch save(ReleaseProductByBatch releaseProductByBatch) {
|
|
|
return releaseProductByBatch;
|
|
|
@@ -81,32 +88,20 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
* @author hejq
|
|
|
*/
|
|
|
@Override
|
|
|
- public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale) {
|
|
|
+ public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale, String currency) {
|
|
|
ModelMap modelMap = new ModelMap();
|
|
|
List<ReleaseProductByBatch> releaseProductByBatchs = new ArrayList<ReleaseProductByBatch>();
|
|
|
Pattern codePattern = Pattern.compile(RegexConstant.EnglishAnDigitAndSpecialCharacter);
|
|
|
-
|
|
|
Pattern chineseAndEnglishPattern = Pattern.compile(RegexConstant.chineseAndEnglish);
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
- if(colNum != 26) {
|
|
|
+ if(colNum != 21) {
|
|
|
throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
}
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
|
|
|
- String storeid = null, storeName = null;
|
|
|
- if(selfSale) {
|
|
|
- StoreIn storeIn = storeInService.findByEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- if(storeIn == null || storeIn.getStatus() != StoreStatus.OPENED) {
|
|
|
- throw new IllegalOperatorException("您还没有开店铺,不能选择店铺自营。");
|
|
|
- }else {
|
|
|
- storeid = storeIn.getUuid();
|
|
|
- storeName = storeIn.getStoreName();
|
|
|
- }
|
|
|
- }else {
|
|
|
- storeid = SysConf.getStoreid();
|
|
|
- storeName = SysConf.getEnName();
|
|
|
- }
|
|
|
+ StoreIn storeIn = getStoreInfo(selfSale);
|
|
|
+ String storeid = storeIn.getUuid(), storeName = storeIn.getStoreName();
|
|
|
Row headerRow = sheet.getRow(0);
|
|
|
int total = 0;
|
|
|
if (headerRow != null) {
|
|
|
@@ -129,7 +124,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
releaseProductByBatch.setRelbatchid(batch);
|
|
|
Cell cell = row.getCell(1);
|
|
|
Object cellValue = readWorkBookCell(cell, Cell.CELL_TYPE_STRING, r, 1);
|
|
|
- if(StringUtils.isEmpty(cellValue) || "UAS1".equals(cellValue) || "UAS2".equals(cellValue)) {
|
|
|
+ if(StringUtils.isEmpty(cellValue)) {
|
|
|
continue;
|
|
|
}else {
|
|
|
releaseProductByBatch.setBrandNameEn(String.valueOf(cellValue));
|
|
|
@@ -137,7 +132,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
|
|
|
// 中文品牌名
|
|
|
Object brandNameCnCellValue = readWorkBookCell(row.getCell(0), Cell.CELL_TYPE_STRING, r, 0);
|
|
|
- if("示例优软商城品牌1".equals(brandNameCnCellValue) || "示例优软商城品牌2".equals(brandNameCnCellValue)) {
|
|
|
+ if(StringUtils.isEmpty(brandNameCnCellValue)) {
|
|
|
continue;
|
|
|
}else {
|
|
|
releaseProductByBatch.setBrandNameCn(String.valueOf(brandNameCnCellValue));
|
|
|
@@ -145,7 +140,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
|
|
|
// 产品型号
|
|
|
Object codeCellValue = readWorkBookCell(row.getCell(2), Cell.CELL_TYPE_STRING, r, 2);
|
|
|
- if(StringUtils.isEmpty(codeCellValue) || "B2C1".equals(brandNameCnCellValue) || "B2C2".equals(brandNameCnCellValue)) {
|
|
|
+ if(StringUtils.isEmpty(codeCellValue)) {
|
|
|
continue;
|
|
|
}else {
|
|
|
String code = codeCellValue.toString();
|
|
|
@@ -156,11 +151,20 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 可拆卖
|
|
|
+ Object breakUpCellValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING, r, 3);
|
|
|
+ releaseProductByBatch.setBreakUpStr(String.valueOf(breakUpCellValue));
|
|
|
+ if (!StringUtils.isEmpty(breakUpCellValue)&&(ReleaseConstant.YES.equals(breakUpCellValue.toString()))) {
|
|
|
+ releaseProductByBatch.setBreakUp(Boolean.TRUE);
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.setBreakUp(Boolean.FALSE);
|
|
|
+ }
|
|
|
+
|
|
|
// 库存类型
|
|
|
- Object originialCellValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING, r, 3);
|
|
|
+ Object originialCellValue = readWorkBookCell(row.getCell(4), Cell.CELL_TYPE_STRING, r, 4);
|
|
|
if (StringUtils.isEmpty(originialCellValue)
|
|
|
|| ((!"现货".equals(originialCellValue)) && (!"呆滞库存".equals(originialCellValue)))) {
|
|
|
- releaseProductByBatch.addErrmsg("4:库存类型为空,或者没有选择现货或者呆滞库存");
|
|
|
+ releaseProductByBatch.addErrmsg("5:库存类型为空,或者没有选择现货或者呆滞库存");
|
|
|
} else {
|
|
|
if ("现货".equals(originialCellValue)) {
|
|
|
releaseProductByBatch.setOriginal(Type.Goods_Original_Code.value());
|
|
|
@@ -171,40 +175,44 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
|
|
|
// 发布库存量
|
|
|
Double reserve = null;
|
|
|
- Object reserveCellValue = readWorkBookCell(row.getCell(4), Cell.CELL_TYPE_STRING, r, 4);
|
|
|
+ Object reserveCellValue = readWorkBookCell(row.getCell(5), Cell.CELL_TYPE_STRING, r, 5);
|
|
|
if (reserveCellValue == null || !isNumber(reserveCellValue.toString())) {
|
|
|
- releaseProductByBatch.addErrmsg("5:发布数量为空或者不是数字");
|
|
|
+ releaseProductByBatch.addErrmsg("6:发布数量为空或者不是数字");
|
|
|
} else {
|
|
|
reserve = Double.valueOf(reserveCellValue.toString());
|
|
|
int compareTo = reserve.compareTo(99999999d);
|
|
|
if(compareTo > 0) {
|
|
|
- releaseProductByBatch.addErrmsg("5:发布数量大于了我们设置的最大值99999999");
|
|
|
+ releaseProductByBatch.addErrmsg("6:发布数量大于了我们设置的最大值99999999");
|
|
|
}else if(NumberUtil.compare(reserve, 0.0) < 1) {
|
|
|
- releaseProductByBatch.addErrmsg("5:发布数量必须大于0");
|
|
|
+ releaseProductByBatch.addErrmsg("6:发布数量必须大于0");
|
|
|
}
|
|
|
releaseProductByBatch.setReserve(reserve);
|
|
|
}
|
|
|
|
|
|
+ // 生产日期
|
|
|
+ Object produceDateCellValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_STRING, r, 6);
|
|
|
+ if (produceDateCellValue == null) {
|
|
|
+ releaseProductByBatch.addErrmsg("7:产品生产日期不可以为空");
|
|
|
+ } else {
|
|
|
+ releaseProductByBatch.setProductDate(String.valueOf(produceDateCellValue));
|
|
|
+ }
|
|
|
+
|
|
|
//包装方式
|
|
|
String packaging = null;
|
|
|
- Object packagingCellValue = readWorkBookCell(row.getCell(5), Cell.CELL_TYPE_STRING, r, 5);
|
|
|
+ Object packagingCellValue = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING, r, 7);
|
|
|
if (packagingCellValue == null || StringUtils.isEmpty(packagingCellValue.toString())) {
|
|
|
- releaseProductByBatch.addErrmsg("6:包装方式不能为空");
|
|
|
+ releaseProductByBatch.addErrmsg("8:包装方式不能为空");
|
|
|
} else {
|
|
|
packaging = packagingCellValue.toString();
|
|
|
releaseProductByBatch.setPackaging(packaging);
|
|
|
Matcher matcher = chineseAndEnglishPattern.matcher(packaging);
|
|
|
if(!matcher.find()) {
|
|
|
- releaseProductByBatch.addErrmsg("6:包装方式仅限中文或英文");
|
|
|
+ releaseProductByBatch.addErrmsg("8:包装方式仅限中文或英文");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //封装方式
|
|
|
- Object encapsulationCellValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_STRING, r, 6);
|
|
|
- releaseProductByBatch.setEncapsulation(String.valueOf(encapsulationCellValue));
|
|
|
-
|
|
|
Double sample = null;
|
|
|
- Object sampleObj = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_STRING, r, 7);
|
|
|
+ Object sampleObj = readWorkBookCell(row.getCell(8), Cell.CELL_TYPE_STRING, r, 8);
|
|
|
if ((sampleObj != null)&&(isNumber(sampleObj.toString()))) {
|
|
|
sample = Double.valueOf(sampleObj.toString());
|
|
|
if (sample <= 0) {
|
|
|
@@ -217,168 +225,73 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
// 这个是没有输入数据默认为null
|
|
|
releaseProductByBatch.setMinPackage((double) 0);
|
|
|
}
|
|
|
+
|
|
|
+ //封装方式
|
|
|
+ Object encapsulationCellValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_STRING, r, 6);
|
|
|
+ releaseProductByBatch.setEncapsulation(String.valueOf(encapsulationCellValue));
|
|
|
|
|
|
// 最小起订量
|
|
|
- Object minBuyCellValue = readWorkBookCell(row.getCell(8), Cell.CELL_TYPE_STRING, r, 8);
|
|
|
+ Object minBuyCellValue = readWorkBookCell(row.getCell(9), Cell.CELL_TYPE_STRING, r, 9);
|
|
|
if ((minBuyCellValue != null)&&(isNumber(minBuyCellValue.toString()))) {
|
|
|
Double minBuy = Double.valueOf(minBuyCellValue.toString());
|
|
|
if (minBuy <= 0) {
|
|
|
// 输入负数
|
|
|
- releaseProductByBatch.addErrmsg("9:最小起订量的数量不能是负数");
|
|
|
+ releaseProductByBatch.addErrmsg("10:最小起订量的数量不能是负数");
|
|
|
} else {
|
|
|
Double rel_reserve = releaseProductByBatch.getReserve() == null ? 0 : releaseProductByBatch.getReserve();
|
|
|
int relVal = minBuy.compareTo(rel_reserve);
|
|
|
if(relVal > 0) {
|
|
|
- releaseProductByBatch.addErrmsg("9:最小起订量的数量不能大于库存的数量");
|
|
|
+ releaseProductByBatch.addErrmsg("10:最小起订量的数量不能大于库存的数量");
|
|
|
}
|
|
|
releaseProductByBatch.setMinBuyQty(minBuy);
|
|
|
}
|
|
|
}else {
|
|
|
- releaseProductByBatch.addErrmsg("9:最小起订量的数量不可以为空且只能是数字");
|
|
|
+ releaseProductByBatch.addErrmsg("10:最小起订量的数量不可以为空且只能是数字");
|
|
|
}
|
|
|
|
|
|
// 最小包装量
|
|
|
- Object minPackQtyCellValue = readWorkBookCell(row.getCell(9), Cell.CELL_TYPE_STRING, r, 9);
|
|
|
+ Object minPackQtyCellValue = readWorkBookCell(row.getCell(10), Cell.CELL_TYPE_STRING, r, 10);
|
|
|
if ((minPackQtyCellValue != null)&&(isNumber(minPackQtyCellValue.toString()))) {
|
|
|
Double minPackQty = Double.valueOf(minPackQtyCellValue.toString());
|
|
|
if (minPackQty <= 0) {
|
|
|
// 输入负数
|
|
|
- releaseProductByBatch.addErrmsg("10:最小包装量的数量不能是负数");
|
|
|
+ releaseProductByBatch.addErrmsg("11:最小包装量的数量不能是负数");
|
|
|
} else {
|
|
|
releaseProductByBatch.setMinPackage(minPackQty);
|
|
|
}
|
|
|
}else {
|
|
|
- releaseProductByBatch.addErrmsg("10:最小包装量不可以为空且只能是数字");
|
|
|
- }
|
|
|
-
|
|
|
- // 可拆卖
|
|
|
- Object breakUpCellValue = readWorkBookCell(row.getCell(10), Cell.CELL_TYPE_STRING, r, 10);
|
|
|
- releaseProductByBatch.setBreakUpStr(String.valueOf(breakUpCellValue));
|
|
|
- if (!StringUtils.isEmpty(breakUpCellValue)&&(ReleaseConstant.YES.equals(breakUpCellValue.toString()))) {
|
|
|
- releaseProductByBatch.setBreakUp(Boolean.TRUE);
|
|
|
- }else {
|
|
|
- releaseProductByBatch.setBreakUp(Boolean.FALSE);
|
|
|
- }
|
|
|
-
|
|
|
- // 最小包单价(人民币)
|
|
|
- Object rmbPriceMinPackQtyCellValue = readWorkBookCell(row.getCell(11), Cell.CELL_TYPE_STRING, r, 11);
|
|
|
- if ((rmbPriceMinPackQtyCellValue != null)&&(isNumber(rmbPriceMinPackQtyCellValue.toString()))) {
|
|
|
- Double rmbPrice = Double.valueOf(rmbPriceMinPackQtyCellValue.toString());
|
|
|
- rmbPrice = fractionNumCeil(rmbPrice, 6);
|
|
|
- releaseProductByBatch.setRmbMinPackPrice(rmbPrice);
|
|
|
- }
|
|
|
-
|
|
|
- // 最小包单价(美元)
|
|
|
- Object usdPriceMinPackQtyCellValue = readWorkBookCell(row.getCell(12), Cell.CELL_TYPE_STRING, r, 12);
|
|
|
- if ((usdPriceMinPackQtyCellValue != null)&&(isNumber(usdPriceMinPackQtyCellValue.toString()))) {
|
|
|
- Double usdPrice = Double.valueOf(usdPriceMinPackQtyCellValue.toString());
|
|
|
- usdPrice = fractionNumCeil(usdPrice, 6);
|
|
|
- releaseProductByBatch.setUsdMinPackPrice(usdPrice);
|
|
|
+ releaseProductByBatch.addErrmsg("11:最小包装量不可以为空且只能是数字");
|
|
|
}
|
|
|
|
|
|
// 确认币别
|
|
|
- Double rmbMinPackPrice = releaseProductByBatch.getRmbMinPackPrice();
|
|
|
- Double usdMinPackPrice = releaseProductByBatch.getUsdMinPackPrice();
|
|
|
- if (rmbMinPackPrice == null && usdMinPackPrice == null) {
|
|
|
- releaseProductByBatch.addErrmsg("12-13:最小包单价至少填一种价格");
|
|
|
- } else if (rmbMinPackPrice != null && usdMinPackPrice == null) {
|
|
|
- releaseProductByBatch.setCurrency("RMB");
|
|
|
- releaseProductByBatch.setRmbTaxRate(0.17d);
|
|
|
- } else if (rmbMinPackPrice == null && usdMinPackPrice != null) {
|
|
|
+ if(Currency.USD.equals(currency)) {
|
|
|
releaseProductByBatch.setCurrency("USD");
|
|
|
releaseProductByBatch.setUsdTaxRate(0d);
|
|
|
- } else {
|
|
|
- releaseProductByBatch.setCurrency("RMB-USD");
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.setCurrency("RMB");
|
|
|
releaseProductByBatch.setRmbTaxRate(0.17d);
|
|
|
- releaseProductByBatch.setUsdTaxRate(0d);
|
|
|
- }
|
|
|
-
|
|
|
- // 生产日期
|
|
|
- Object produceDateCellValue = readWorkBookCell(row.getCell(13), Cell.CELL_TYPE_STRING, r, 13);
|
|
|
- if (produceDateCellValue == null) {
|
|
|
- releaseProductByBatch.addErrmsg("14:产品生产日期不可以为空");
|
|
|
- } else {
|
|
|
- releaseProductByBatch.setProductDate(String.valueOf(produceDateCellValue));
|
|
|
- }
|
|
|
-
|
|
|
- //交期时间
|
|
|
-// if(releaseProductByBatch.getCurrency() != null) {
|
|
|
-// Object deliveryCellValue = readWorkBookCell(row.getCell(13), Cell.CELL_TYPE_STRING, r, 13);
|
|
|
-// if (!StringUtils.isEmpty(deliveryCellValue)) {
|
|
|
-// Short[] delivers = splitDeliveryString(deliveryCellValue.toString());
|
|
|
-// if (delivers != null) {
|
|
|
-// releaseProductByBatch.setB2cMinDelivery(delivers[0]);
|
|
|
-// releaseProductByBatch.setB2cMaxDelivery(delivers[1]);
|
|
|
-//
|
|
|
-// Boolean aBoolean = deliveryTimeBetween(releaseProductByBatch.getB2cMaxDelivery(), (short) 0, (short) 9);
|
|
|
-// if(!aBoolean) {
|
|
|
-// releaseProductByBatch.addErrmsg("14:交期的不在(0,9]天");
|
|
|
-// }
|
|
|
-// Boolean bBoolean = deliveryTimeBetween(releaseProductByBatch.getB2cMinDelivery(), (short) 0, (short) 9);
|
|
|
-// if(!bBoolean) {
|
|
|
-// releaseProductByBatch.addErrmsg("14:交期的不在(0,9]天");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- // 大陆交期
|
|
|
- if(releaseProductByBatch.getCurrency() != null && releaseProductByBatch.getCurrency().contains("RMB")) {
|
|
|
- Object deliveryCellValue = readWorkBookCell(row.getCell(14), Cell.CELL_TYPE_STRING, r, 14);
|
|
|
- if (!StringUtils.isEmpty(deliveryCellValue)) {
|
|
|
- Short[] delivers = splitDeliveryString(deliveryCellValue.toString());
|
|
|
- if (!ArrayUtils.isEmpty(delivers)&&(delivers[0] !=null)&&(delivers[1] !=null)) {
|
|
|
- releaseProductByBatch.setDeliveryDemMinTime(delivers[0]);
|
|
|
- releaseProductByBatch.setDeliveryDemMaxTime(delivers[1]);
|
|
|
- Boolean aBoolean = deliveryTimeBetween(releaseProductByBatch.getDeliveryDemMaxTime(), (short) 0, (short) 9);
|
|
|
- if(!aBoolean) {
|
|
|
- releaseProductByBatch.addErrmsg("15:大陆交期的不在(0,9]天");
|
|
|
- }
|
|
|
- Boolean bBoolean = deliveryTimeBetween(releaseProductByBatch.getDeliveryDemMinTime(), (short) 0, (short) 9);
|
|
|
- if(!bBoolean) {
|
|
|
- releaseProductByBatch.addErrmsg("15:大陆交期的不在(0,9]天");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- // 香港交期
|
|
|
- if(releaseProductByBatch.getCurrency() != null && releaseProductByBatch.getCurrency().contains("USD")) {
|
|
|
- Object deliveryhkCellValue = readWorkBookCell(row.getCell(15), Cell.CELL_TYPE_STRING, r, 15);
|
|
|
- if (!StringUtils.isEmpty(deliveryhkCellValue)) {
|
|
|
- Short[] deliverys = splitDeliveryString(deliveryhkCellValue.toString());
|
|
|
- if (!ArrayUtils.isEmpty(deliverys)&&(deliverys[0] !=null)&&(deliverys[1] !=null)) {
|
|
|
- releaseProductByBatch.setDeliveryHKMinTime(deliverys[0]);
|
|
|
- releaseProductByBatch.setDeliveryHKMaxTime(deliverys[1]);
|
|
|
-
|
|
|
- Boolean aBoolean = deliveryTimeBetween(releaseProductByBatch.getDeliveryHKMinTime(), (short) 0, (short) 9);
|
|
|
- if(!aBoolean) {
|
|
|
- releaseProductByBatch.addErrmsg("16:香港交期的不在(0,9]天");
|
|
|
- }
|
|
|
- Boolean bBoolean = deliveryTimeBetween(releaseProductByBatch.getDeliveryHKMaxTime(), (short) 0, (short) 9);
|
|
|
- if(!bBoolean) {
|
|
|
- releaseProductByBatch.addErrmsg("16:香港交期的不在(0,9]天");
|
|
|
- }
|
|
|
- }
|
|
|
+ // 最小包单价
|
|
|
+ Object priceMinPackQtyCellValue = readWorkBookCell(row.getCell(11), Cell.CELL_TYPE_STRING, r, 11);
|
|
|
+ if ((priceMinPackQtyCellValue != null)&&(isNumber(priceMinPackQtyCellValue.toString()))) {
|
|
|
+ Double price = Double.valueOf(priceMinPackQtyCellValue.toString());
|
|
|
+ price = fractionNumCeil(price, 6);
|
|
|
+ if(Currency.USD.equals(currency)) {
|
|
|
+ releaseProductByBatch.setUsdMinPackPrice(price);
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.setRmbMinPackPrice(price);
|
|
|
}
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.addErrmsg("最小包单价信息为空");
|
|
|
}
|
|
|
|
|
|
- if("RMB-USD".equals(releaseProductByBatch.getCurrency())) {
|
|
|
- if(releaseProductByBatch.getDeliveryDemMaxTime() == null || releaseProductByBatch.getDeliveryHKMaxTime() == null) {
|
|
|
- releaseProductByBatch.addErrmsg("15-16:您上架的币别是人民币和美金,所以香港和大陆的交期都需要填写,且格式必须是5~5");
|
|
|
- }
|
|
|
- }else if("RMB".equals(releaseProductByBatch.getCurrency())) {
|
|
|
- if(releaseProductByBatch.getDeliveryDemMaxTime() == null) {
|
|
|
- releaseProductByBatch.addErrmsg("15-16:您上架的币别是人民币,所以大陆交期需要填写,且格式必须是5~5");
|
|
|
- }
|
|
|
- }else if("USD".equals(releaseProductByBatch.getCurrency())) {
|
|
|
- if(releaseProductByBatch.getDeliveryHKMaxTime() == null) {
|
|
|
- releaseProductByBatch.addErrmsg("15-16:您上架的币别是美金,所以香港交期需要填写,且格式必须是5~5");
|
|
|
- }
|
|
|
+ Object deliveryMinCellValue = readWorkBookCell(row.getCell(12), Cell.CELL_TYPE_STRING, r, 12);
|
|
|
+ Object deliveryMaxCellValue = readWorkBookCell(row.getCell(13), Cell.CELL_TYPE_STRING, r, 13);
|
|
|
+ if(StringUtils.isEmpty(deliveryMinCellValue) && StringUtils.isEmpty(deliveryMaxCellValue)) {
|
|
|
+ releaseProductByBatch.addErrmsg("13-14:存在交期的信息为空");
|
|
|
}else {
|
|
|
- if(releaseProductByBatch.getDeliveryDemMaxTime() == null && releaseProductByBatch.getDeliveryHKMaxTime() == null) {
|
|
|
- releaseProductByBatch.addErrmsg("15-16:您必须要填写一个类型的交期,且格式必须是5~5");
|
|
|
- }
|
|
|
+ setDeliveryTime(releaseProductByBatch, deliveryMinCellValue, deliveryMaxCellValue);
|
|
|
}
|
|
|
|
|
|
// 分段数量
|
|
|
@@ -386,39 +299,23 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
Double[] priceMaxMinPrice = {Double.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE, Double.MIN_VALUE}; //最小人民币价格,最大人民币价格,最小美金价格,最大美金价格
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
// 起始量必须等于最小起定量
|
|
|
- readSectionPrice(row.getCell(16 + 3 * i), row.getCell(17 + 3 * i), row.getCell(18 + 3 * i),
|
|
|
- prices, releaseProductByBatch, r, (16 + 3 * i), priceMaxMinPrice);
|
|
|
+ readSectionPrice(row.getCell(14 + 2 * i), row.getCell(15 + 2 * i),
|
|
|
+ prices, releaseProductByBatch, r, (14 + 2 * i), priceMaxMinPrice);
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(prices)) {
|
|
|
- double start = -1;
|
|
|
- for (int j = 0; j < prices.size(); j++) {
|
|
|
- GoodsQtyPrice price = prices.get(j);
|
|
|
- if(j == 0) {
|
|
|
- int val = price.getStart().compareTo(releaseProductByBatch.getMinBuyQty());
|
|
|
- if(val != 0) {
|
|
|
- releaseProductByBatch.addErrmsg("17:第一个分段数量的起始值与最小起订量不相等");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 判断输入的后一个分段是否大于前一个分段
|
|
|
- if (start < price.getStart()) {
|
|
|
- start = price.getStart();
|
|
|
- } else {
|
|
|
- releaseProductByBatch.addErrmsg("17:分段数量起始值存在后一个分段的开始值小于前一个分段的开始值");
|
|
|
- }
|
|
|
-
|
|
|
- if (j < prices.size() - 1) {
|
|
|
- price.setEnd(prices.get(j + 1).getStart() - 1);
|
|
|
- }
|
|
|
- if (j == prices.size() - 1) {
|
|
|
- price.setEnd(reserve);
|
|
|
- }
|
|
|
- }
|
|
|
+ setPricesQty(prices, releaseProductByBatch);
|
|
|
} else {
|
|
|
// 如果未填分段价格,默认为最小包装量价格
|
|
|
GoodsQtyPrice qtyPrice = new GoodsQtyPrice();
|
|
|
qtyPrice.setStart(releaseProductByBatch.getMinBuyQty());
|
|
|
- if (rmbMinPackPrice != null) {
|
|
|
+ if(Currency.USD.equals(releaseProductByBatch.getCurrency())) {
|
|
|
+ Double usdMinPackPrice = releaseProductByBatch.getUsdMinPackPrice();
|
|
|
+ qtyPrice.setUSDPrice(usdMinPackPrice);
|
|
|
+ qtyPrice.setUSDNTPrice(usdMinPackPrice);
|
|
|
+ priceMaxMinPrice[2] = usdMinPackPrice;
|
|
|
+ priceMaxMinPrice[3] = usdMinPackPrice;
|
|
|
+ }else {
|
|
|
+ Double rmbMinPackPrice = releaseProductByBatch.getRmbMinPackPrice();
|
|
|
qtyPrice.setRMBPrice(rmbMinPackPrice);
|
|
|
BigDecimal priceNum = new BigDecimal(rmbMinPackPrice);
|
|
|
BigDecimal taxNum = new BigDecimal(releaseProductByBatch.getRmbTaxRate() + 1);
|
|
|
@@ -426,12 +323,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
priceMaxMinPrice[0] = rmbMinPackPrice;
|
|
|
priceMaxMinPrice[1] = rmbMinPackPrice;
|
|
|
}
|
|
|
- if (usdMinPackPrice != null) {
|
|
|
- qtyPrice.setUSDPrice(usdMinPackPrice);
|
|
|
- qtyPrice.setUSDNTPrice(usdMinPackPrice);
|
|
|
- priceMaxMinPrice[2] = usdMinPackPrice;
|
|
|
- priceMaxMinPrice[3] = usdMinPackPrice;
|
|
|
- }
|
|
|
qtyPrice.setEnd(reserve);
|
|
|
prices.add(qtyPrice);
|
|
|
}
|
|
|
@@ -450,7 +341,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
}
|
|
|
|
|
|
// 备注
|
|
|
- Object remarkCellValue = readWorkBookCell(row.getCell(25), Cell.CELL_TYPE_STRING, r, 25);
|
|
|
+ Object remarkCellValue = readWorkBookCell(row.getCell(20), Cell.CELL_TYPE_STRING, r, 20);
|
|
|
if (!StringUtils.isEmpty(remarkCellValue)) {
|
|
|
String remark = remarkCellValue.toString();
|
|
|
releaseProductByBatch.setRemark(remark);
|
|
|
@@ -485,6 +376,56 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
return modelMap;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 分析分段的价格
|
|
|
+ */
|
|
|
+ private void setPricesQty(List<GoodsQtyPrice> prices, ReleaseProductByBatch productByBatch) {
|
|
|
+ double end = -1;
|
|
|
+ GoodsQtyPrice[] array = new GoodsQtyPrice[prices.size()];
|
|
|
+ prices.toArray(array);
|
|
|
+ Arrays.sort(array, new Comparator<GoodsQtyPrice>() {
|
|
|
+ @Override
|
|
|
+ public int compare(GoodsQtyPrice o1, GoodsQtyPrice o2) {
|
|
|
+ return NumberUtil.compare(o1.getEnd(), o2.getEnd());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<GoodsQtyPrice> priceList = Collections.<GoodsQtyPrice>emptyList();
|
|
|
+ for (int j = 0; j < priceList.size(); j++) {
|
|
|
+ GoodsQtyPrice price = priceList.get(j);
|
|
|
+ if(NumberUtil.compare(end, -1d) == 0) {
|
|
|
+ if(NumberUtil.compare(price.getEnd(), productByBatch.getMinBuyQty()) > 0) {
|
|
|
+ price.setStart(productByBatch.getMinBuyQty());
|
|
|
+ end = price.getEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (j < prices.size() - 1) {
|
|
|
+ price.setEnd(prices.get(j - 1).getStart() - 1);
|
|
|
+ }
|
|
|
+ if (j == prices.size() - 1) {
|
|
|
+ price.setEnd(DoubleConstant.maxReserve);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取店铺的信息
|
|
|
+ * @param selfSale
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private StoreIn getStoreInfo(Boolean selfSale) {
|
|
|
+ StoreIn storeIn = null;
|
|
|
+ if(selfSale) {
|
|
|
+ storeIn = storeInService.findByEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ if((storeIn == null) || (storeIn.getStatus() != StoreStatus.OPENED)) {
|
|
|
+ throw new IllegalOperatorException("您的公司还为开店,不能选择自营");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ storeIn = storeInService.findByUuid(SysConf.getStoreid());
|
|
|
+ }
|
|
|
+ return storeIn;
|
|
|
+ }
|
|
|
+
|
|
|
private Boolean isNumber(String str) {
|
|
|
Pattern numberPattern = Pattern.compile(RegexConstant.NumberData);
|
|
|
Matcher matcher = numberPattern.matcher(str);
|
|
|
@@ -495,6 +436,44 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置交期的信息
|
|
|
+ */
|
|
|
+ private void setDeliveryTime(ReleaseProductByBatch releaseProductByBatch, Object minDelivery, Object maxDelivery) {
|
|
|
+ minDelivery = minDelivery == null ? maxDelivery : minDelivery;
|
|
|
+ maxDelivery = maxDelivery == null ? minDelivery : maxDelivery;
|
|
|
+ Pattern intMinP = Pattern.compile(RegexConstant.Integer);
|
|
|
+ Matcher intMinM = intMinP.matcher(minDelivery.toString());
|
|
|
+ Short min = null, max = null;
|
|
|
+ if(intMinM.find()) {
|
|
|
+ String g = intMinM.group();
|
|
|
+ min = Short.valueOf(g);
|
|
|
+ }
|
|
|
+ Pattern intMaxP = Pattern.compile(RegexConstant.Integer);
|
|
|
+ Matcher intMaxM = intMaxP.matcher(maxDelivery.toString());
|
|
|
+ if(intMaxM.find()) {
|
|
|
+ String g = intMaxM.group();
|
|
|
+ max = Short.valueOf(g);
|
|
|
+ }
|
|
|
+ if((min != null) || (max != null)) {
|
|
|
+ min = min == null ? max : min;
|
|
|
+ max = max == null ? min : max;
|
|
|
+ if(min.shortValue() > ShortConstant.maxDelivery || min.shortValue() < 0 || max.shortValue() > Short.MAX_VALUE || max.shortValue() < 0){
|
|
|
+ releaseProductByBatch.addErrmsg("13-14:交期的信息必须为正整数并且小于" + ShortConstant.maxDelivery);
|
|
|
+ }else {
|
|
|
+ if(min.shortValue() > max.shortValue()) {
|
|
|
+ Short delivery = max;
|
|
|
+ max = min;
|
|
|
+ min = delivery;
|
|
|
+ }
|
|
|
+ releaseProductByBatch.setSelfMinDelivery(min);
|
|
|
+ releaseProductByBatch.setSelfMaxDelivery(max);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.addErrmsg("13-14:交期的信息必须为正整数并且小于" + ShortConstant.maxDelivery);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建时间 :2016年12月11日 下午2:02:16
|
|
|
*
|
|
|
@@ -619,85 +598,48 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
|
|
|
* 获取每一个分段的的数量
|
|
|
*
|
|
|
*/
|
|
|
- private void readSectionPrice(Cell cellQty, Cell cellPriceRMB, Cell cellPriceUSD, List<GoodsQtyPrice> prices,
|
|
|
+ private void readSectionPrice(Cell cellQty, Cell cellPrice, List<GoodsQtyPrice> prices,
|
|
|
ReleaseProductByBatch releaseProductByBatch, int r, int num, Double[] priceMaxMinPrice) {
|
|
|
// 先跟据币别判断对应的价格是否有空值
|
|
|
- Object startQtyCellValue = readWorkBookCell(cellQty, Cell.CELL_TYPE_STRING, r, num);
|
|
|
- if ((startQtyCellValue != null)&&(isNumber(startQtyCellValue.toString()))) {
|
|
|
- Double start = Double.valueOf(startQtyCellValue.toString());
|
|
|
+ Object endQtyCellValue = readWorkBookCell(cellQty, Cell.CELL_TYPE_STRING, r, num);
|
|
|
+ if ((endQtyCellValue != null)&&(isNumber(endQtyCellValue.toString()))) {
|
|
|
+ Double end = Double.valueOf(endQtyCellValue.toString());
|
|
|
GoodsQtyPrice qtyPrice = new GoodsQtyPrice();
|
|
|
// 分段数量start不得大于库存量
|
|
|
- if (start > releaseProductByBatch.getReserve() || start <= 0) {
|
|
|
- releaseProductByBatch.addErrmsg("11: 分段数量存在起始值大于库存量或者开始数量小于0");
|
|
|
- }
|
|
|
- qtyPrice.setStart(start);
|
|
|
-
|
|
|
- String currency = releaseProductByBatch.getCurrency();
|
|
|
-
|
|
|
- // 人民币价格
|
|
|
- if(currency != null && currency.contains("RMB")) {
|
|
|
- Double pricermb = null;
|
|
|
- Object pricermbReadWorkBookCellValue = readWorkBookCell(cellPriceRMB, Cell.CELL_TYPE_STRING, r, num+1);
|
|
|
- if ((pricermbReadWorkBookCellValue != null)&&(isNumber(pricermbReadWorkBookCellValue.toString()))) {
|
|
|
- pricermb = Double.valueOf(pricermbReadWorkBookCellValue.toString());
|
|
|
- }
|
|
|
- if (pricermb != null && pricermb > 0.0) {
|
|
|
- pricermb = fractionNumCeil(pricermb, 6);
|
|
|
- qtyPrice.setRMBPrice(pricermb);
|
|
|
- BigDecimal taxNum = new BigDecimal(releaseProductByBatch.getRmbTaxRate() + 1);
|
|
|
- qtyPrice.setRMBNTPrice(new BigDecimal(pricermb).divide(taxNum, 6, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
- if(priceMaxMinPrice[0] > pricermb) {
|
|
|
- priceMaxMinPrice[0] = pricermb;
|
|
|
- }
|
|
|
- if(priceMaxMinPrice[1] < pricermb) {
|
|
|
- priceMaxMinPrice[1] = pricermb;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (end > releaseProductByBatch.getReserve() || end <= 0) {
|
|
|
+ releaseProductByBatch.addErrmsg(num + ": 分段数量存在结束值大于库存量或者结束值小于0");
|
|
|
}
|
|
|
+ qtyPrice.setEnd(end);
|
|
|
|
|
|
- if(currency != null && currency.contains("USD")) {
|
|
|
- // 美金价格
|
|
|
- Double priceusd = null;
|
|
|
- Object priceusdReadWorkBookCellValue = readWorkBookCell(cellPriceUSD, Cell.CELL_TYPE_STRING, r, num+2);
|
|
|
- if ((priceusdReadWorkBookCellValue != null)&&(isNumber(priceusdReadWorkBookCellValue.toString()))) {
|
|
|
- priceusd = Double.valueOf(priceusdReadWorkBookCellValue.toString());
|
|
|
- }
|
|
|
- if (priceusd != null && priceusd > 0) {
|
|
|
- priceusd = fractionNumCeil(priceusd, 6);
|
|
|
- qtyPrice.setUSDPrice(priceusd);
|
|
|
- qtyPrice.setUSDNTPrice(priceusd);
|
|
|
- if(priceMaxMinPrice[2] > priceusd) {
|
|
|
- priceMaxMinPrice[2] = priceusd;
|
|
|
+ Double price = null;
|
|
|
+ Object priceCellValue = readWorkBookCell(cellPrice, Cell.CELL_TYPE_STRING, r, num + 1);
|
|
|
+ if ((priceCellValue != null)&&(isNumber(priceCellValue.toString()))) {
|
|
|
+ price = Double.valueOf(priceCellValue.toString());
|
|
|
+ }
|
|
|
+ if (price != null && price > 0.0) {
|
|
|
+ price = fractionNumCeil(price, 6);
|
|
|
+ if(Currency.USD.equals(releaseProductByBatch.getCurrency())) {
|
|
|
+ qtyPrice.setUSDPrice(price);
|
|
|
+ qtyPrice.setUSDNTPrice(price);
|
|
|
+ if(priceMaxMinPrice[2] > price) {
|
|
|
+ priceMaxMinPrice[2] = price;
|
|
|
+ }
|
|
|
+ if(priceMaxMinPrice[3] < price) {
|
|
|
+ priceMaxMinPrice[3] = price;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ qtyPrice.setRMBPrice(price);
|
|
|
+ BigDecimal taxNum = new BigDecimal(releaseProductByBatch.getRmbTaxRate() + 1);
|
|
|
+ qtyPrice.setRMBNTPrice(new BigDecimal(price).divide(taxNum, 6, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ if(priceMaxMinPrice[0] > price) {
|
|
|
+ priceMaxMinPrice[0] = price;
|
|
|
}
|
|
|
- if(priceMaxMinPrice[3] < priceusd) {
|
|
|
- priceMaxMinPrice[3] = priceusd;
|
|
|
+ if(priceMaxMinPrice[1] < price) {
|
|
|
+ priceMaxMinPrice[1] = price;
|
|
|
}
|
|
|
}
|
|
|
+ prices.add(qtyPrice);
|
|
|
}
|
|
|
-
|
|
|
- // 验证信息的一致性
|
|
|
- Double rmbPrice = qtyPrice.getRMBPrice();
|
|
|
- Double usdPrice = qtyPrice.getUSDPrice();
|
|
|
-
|
|
|
- boolean isUnit = true;
|
|
|
- if ("RMB".equalsIgnoreCase(currency)) {
|
|
|
- if (rmbPrice == null) {
|
|
|
- isUnit = false;
|
|
|
- }
|
|
|
- } else if ("RMB-USD".equalsIgnoreCase(currency)) {
|
|
|
- if (rmbPrice == null || usdPrice == null) {
|
|
|
- isUnit = false;
|
|
|
- }
|
|
|
- } else if ("USD".equalsIgnoreCase(currency)) {
|
|
|
- if (usdPrice == null) {
|
|
|
- isUnit = false;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!isUnit) {
|
|
|
- releaseProductByBatch.addErrmsg("11: 前后的价格信息不一致,例如最小包单价填了人民币和美金,后面的分段只填了人民币");
|
|
|
- }
|
|
|
-
|
|
|
- prices.add(qtyPrice);
|
|
|
}
|
|
|
}
|
|
|
|