|
@@ -0,0 +1,700 @@
|
|
|
+package com.uas.cloud.mall.commodity.service.impl;
|
|
|
+
|
|
|
+import com.uas.cloud.commons.domain.Enterprise;
|
|
|
+import com.uas.cloud.commons.domain.PageInfo;
|
|
|
+import com.uas.cloud.commons.exception.IllegalOperatorException;
|
|
|
+import com.uas.cloud.commons.support.SystemSession;
|
|
|
+import com.uas.cloud.mall.commodity.domain.Commodity;
|
|
|
+import com.uas.cloud.mall.commodity.domain.CommodityQtyPrice;
|
|
|
+import com.uas.cloud.mall.commodity.domain.ReleaseProductByBatch;
|
|
|
+import com.uas.cloud.mall.commodity.repository.CommonDao;
|
|
|
+import com.uas.cloud.mall.commodity.repository.CommodityDao;
|
|
|
+import com.uas.cloud.mall.commodity.repository.ReleaseProductByBatchDao;
|
|
|
+import com.uas.cloud.mall.commodity.service.CommodityService;
|
|
|
+import com.uas.cloud.mall.commodity.service.CreateNumberService;
|
|
|
+import com.uas.cloud.mall.commodity.service.ReleaseProductByBatchService;
|
|
|
+import com.uas.cloud.mall.commodity.service.ShopComponentService;
|
|
|
+import com.uas.cloud.mall.commodity.statusAndType.ReleaseStatus;
|
|
|
+import com.uas.cloud.mall.commodity.statusAndType.Type;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+
|
|
|
+ * Created by John on 2017/3/2.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchService {
|
|
|
+
|
|
|
+ private final ReleaseProductByBatchDao releaseProductByBatchDao;
|
|
|
+
|
|
|
+ private final CommodityService goodsService;
|
|
|
+
|
|
|
+ private final CreateNumberService createNumberService;
|
|
|
+
|
|
|
+ private final CommodityDao goodsDao;
|
|
|
+
|
|
|
+ private final CommonDao commonDao;
|
|
|
+
|
|
|
+ private final ShopComponentService shopComponentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public ReleaseProductByBatchServiceImpl(ReleaseProductByBatchDao releaseProductByBatchDao, CommodityService goodsService, CreateNumberService createNumberService, CommodityDao goodsDao, CommonDao commonDao, ShopComponentService shopComponentService) {
|
|
|
+ this.releaseProductByBatchDao = releaseProductByBatchDao;
|
|
|
+ this.goodsService = goodsService;
|
|
|
+ this.createNumberService = createNumberService;
|
|
|
+ this.goodsDao = goodsDao;
|
|
|
+ this.commonDao = commonDao;
|
|
|
+ this.shopComponentService = shopComponentService;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 导入excel发布商品(大量)
|
|
|
+ *
|
|
|
+ * @author hejq
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ModelMap releaseByWorkbook(Workbook workbook) {
|
|
|
+ ModelMap modelMap = new ModelMap();
|
|
|
+ List<ReleaseProductByBatch> releaseProductByBatchs = new ArrayList<ReleaseProductByBatch>();
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ int colNum = sheet.getRow(0).getPhysicalNumberOfCells();
|
|
|
+ if(colNum != 23) {
|
|
|
+ throw new IllegalOperatorException("您上传的信息列信息不正确,请与模板的列做比较");
|
|
|
+ }
|
|
|
+ Row headerRow = sheet.getRow(0);
|
|
|
+ String batch = createNumberService.getTimeNumber("product$goods", 8, rowNum);
|
|
|
+ int total = 0;
|
|
|
+ if (headerRow != null) {
|
|
|
+ Cell cellHead = headerRow.getCell(0);
|
|
|
+ Object readWorkBookCell = readWorkBookCell(cellHead, Cell.CELL_TYPE_STRING, 0, 0);
|
|
|
+ Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
|
|
+ Matcher m = p.matcher(readWorkBookCell.toString());
|
|
|
+ String str = m.replaceAll("");
|
|
|
+ if(StringUtils.isEmpty(str) || !("中文产品品牌".equals(str))) {
|
|
|
+ throw new IllegalOperatorException("上传的文件信息第一列的表头为空,或第一列的表头名称不为中文产品品牌");
|
|
|
+ }
|
|
|
+ for (int r = 1; r <= rowNum; r++) {
|
|
|
+ Row row = sheet.getRow(r);
|
|
|
+
|
|
|
+ total++;
|
|
|
+ if (row != null && row.getCell(1) != null && row.getCell(1).getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ ReleaseProductByBatch releaseProductByBatch = new ReleaseProductByBatch(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)) {
|
|
|
+ continue;
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.setBrandNameEn(String.valueOf(cellValue));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object brandNameCnCellValue = readWorkBookCell(row.getCell(0), Cell.CELL_TYPE_STRING, r, 0);
|
|
|
+ if("示例优软商城品牌1".equals(brandNameCnCellValue) || "示例优软商城品牌2".equals(brandNameCnCellValue)) {
|
|
|
+ continue;
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.setBrandNameCn(String.valueOf(brandNameCnCellValue));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object codeCellValue = readWorkBookCell(row.getCell(2), Cell.CELL_TYPE_STRING, r, 2);
|
|
|
+ if(StringUtils.isEmpty(codeCellValue) || "B2C1".equals(brandNameCnCellValue) || "B2C2".equals(brandNameCnCellValue)) {
|
|
|
+ continue;
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.setCode(codeCellValue.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object originialCellValue = readWorkBookCell(row.getCell(3), Cell.CELL_TYPE_STRING, r, 3);
|
|
|
+ if (StringUtils.isEmpty(originialCellValue)
|
|
|
+ || ((!"现货".equals(originialCellValue)) && (!"呆滞库存".equals(originialCellValue)))) {
|
|
|
+ releaseProductByBatch.addErrmsg("4:库存类型为空,或者没有选择现货或者呆滞库存");
|
|
|
+ } else {
|
|
|
+ if ("现货".equals(originialCellValue)) {
|
|
|
+ releaseProductByBatch.setOriginal(Type.Goods_Original_Code.value());
|
|
|
+ } else if ("呆滞库存".equals(originialCellValue)) {
|
|
|
+ releaseProductByBatch.setOriginal(Type.Goods_Inaction_Stock.value());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Double reserve = null;
|
|
|
+ Object reserveCellValue = readWorkBookCell(row.getCell(4), Cell.CELL_TYPE_NUMERIC, r, 4);
|
|
|
+ if (reserveCellValue == null || Double.valueOf(reserveCellValue.toString()).doubleValue() <= 0) {
|
|
|
+ releaseProductByBatch.addErrmsg("5:发布数量为空或者小于等于0");
|
|
|
+ } else {
|
|
|
+ reserve = Double.valueOf(reserveCellValue.toString());
|
|
|
+ int compareTo = reserve.compareTo(99999999d);
|
|
|
+ if(compareTo > 0) {
|
|
|
+ releaseProductByBatch.addErrmsg("5:发布数量大于了我们设置的最大值99999999");
|
|
|
+ }
|
|
|
+ releaseProductByBatch.setReserve(reserve);
|
|
|
+ }
|
|
|
+
|
|
|
+ Double sample = null;
|
|
|
+ Object sampleObj = readWorkBookCell(row.getCell(5), Cell.CELL_TYPE_NUMERIC, r, 5);
|
|
|
+ if (sampleObj != null) {
|
|
|
+ sample = Double.valueOf(sampleObj.toString());
|
|
|
+ if (sample <= 0) {
|
|
|
+
|
|
|
+ releaseProductByBatch.setSampleqty((double) 0);
|
|
|
+ } else {
|
|
|
+ releaseProductByBatch.setSampleqty(sample);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ releaseProductByBatch.setMinPackage((double) 0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object minBuyCellValue = readWorkBookCell(row.getCell(6), Cell.CELL_TYPE_NUMERIC, r, 6);
|
|
|
+ if (minBuyCellValue != null) {
|
|
|
+ Double minBuy = Double.valueOf(minBuyCellValue.toString());
|
|
|
+ if (minBuy <= 0) {
|
|
|
+
|
|
|
+ releaseProductByBatch.addErrmsg("6:最小起订量的数量不能是负数");
|
|
|
+ } else {
|
|
|
+ Double rel_reserve = releaseProductByBatch.getReserve() == null ? 0 : releaseProductByBatch.getReserve();
|
|
|
+ int relVal = minBuy.compareTo(rel_reserve);
|
|
|
+ if(relVal > 0) {
|
|
|
+ releaseProductByBatch.setErrmsg("6:最小起订量的数量不能大于库存的数量");
|
|
|
+ }
|
|
|
+ releaseProductByBatch.setMinBuyQty(minBuy);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.addErrmsg("6:最小起订量的数量不可以为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object minPackQtyCellValue = readWorkBookCell(row.getCell(7), Cell.CELL_TYPE_NUMERIC, r, 7);
|
|
|
+ if (minPackQtyCellValue != null) {
|
|
|
+ Double minPackQty = Double.valueOf(minPackQtyCellValue.toString());
|
|
|
+ if (minPackQty <= 0) {
|
|
|
+
|
|
|
+ releaseProductByBatch.addErrmsg("7:最小包装量的数量不能是负数");
|
|
|
+ } else {
|
|
|
+ releaseProductByBatch.setMinPackage(minPackQty);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ releaseProductByBatch.addErrmsg("7:最小包装量不可以为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Object rmbPriceMinPackQtyCellValue = readWorkBookCell(row.getCell(8), Cell.CELL_TYPE_NUMERIC, r, 8);
|
|
|
+ if (rmbPriceMinPackQtyCellValue != null) {
|
|
|
+ Double rmbPrice = Double.valueOf(rmbPriceMinPackQtyCellValue.toString());
|
|
|
+ releaseProductByBatch.setRmbMinPackPrice(rmbPrice);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object usdPriceMinPackQtyCellValue = readWorkBookCell(row.getCell(9), Cell.CELL_TYPE_NUMERIC, r, 9);
|
|
|
+ if (usdPriceMinPackQtyCellValue != null) {
|
|
|
+ Double usdPrice = Double.valueOf(usdPriceMinPackQtyCellValue.toString());
|
|
|
+ releaseProductByBatch.setUsdMinPackPrice(usdPrice);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ comfirmCurrency(releaseProductByBatch);
|
|
|
+
|
|
|
+
|
|
|
+ Object produceDateCellValue = readWorkBookCell(row.getCell(10), Integer.MAX_VALUE, r, 10);
|
|
|
+ if (produceDateCellValue == null) {
|
|
|
+ releaseProductByBatch.addErrmsg("10:产品生产日期不可以为空");
|
|
|
+ } else {
|
|
|
+ Date produceDate = (Date) produceDateCellValue;
|
|
|
+ int compareTo = produceDate.compareTo(new Date());
|
|
|
+ if(compareTo > 0) {
|
|
|
+ releaseProductByBatch.addErrmsg("10:产品生产日期不能早于今天");
|
|
|
+ }
|
|
|
+ releaseProductByBatch.setProductDate((Date)produceDateCellValue);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(releaseProductByBatch.getCurrency() != null && releaseProductByBatch.getCurrency().contains("RMB")) {
|
|
|
+ Object deliveryCellValue = readWorkBookCell(row.getCell(11), Cell.CELL_TYPE_STRING, r, 11);
|
|
|
+ setDemDeliveryTime(releaseProductByBatch, deliveryCellValue);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(releaseProductByBatch.getCurrency() != null && releaseProductByBatch.getCurrency().contains("USD")) {
|
|
|
+ Object deliveryhkCellValue = readWorkBookCell(row.getCell(12), Cell.CELL_TYPE_STRING, r, 12);
|
|
|
+ setHKDeliveryTime(releaseProductByBatch ,deliveryhkCellValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (releaseProductByBatch.getDeliveryDemTime() == null
|
|
|
+ && releaseProductByBatch.getDeliveryHKTime() == null) {
|
|
|
+ releaseProductByBatch.addErrmsg("11-12:大陆交期和香港交期至少填一种");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<CommodityQtyPrice> prices = new ArrayList<CommodityQtyPrice>();
|
|
|
+ Double[] priceMaxMinPrice = {Double.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE, Double.MIN_VALUE};
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
+
|
|
|
+ readSectionPrice(row.getCell(13 + 3 * i), row.getCell(14 + 3 * i), row.getCell(15 + 3 * i),
|
|
|
+ prices, releaseProductByBatch, r, (13 + 3 * i), priceMaxMinPrice);
|
|
|
+ }
|
|
|
+
|
|
|
+ setSectionPrice(releaseProductByBatch, prices, priceMaxMinPrice);
|
|
|
+
|
|
|
+
|
|
|
+ setMinMaxPrices(releaseProductByBatch, priceMaxMinPrice);
|
|
|
+
|
|
|
+
|
|
|
+ Object remarkCellValue = readWorkBookCell(row.getCell(22), Cell.CELL_TYPE_STRING, r, 21);
|
|
|
+ if (!StringUtils.isEmpty(remarkCellValue)) {
|
|
|
+ String remark = remarkCellValue.toString();
|
|
|
+ releaseProductByBatch.setRemark(remark);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ releaseProductByBatch.setPublisherName(SystemSession.getUser().getUserName());
|
|
|
+ releaseProductByBatch.setPublisherTel(SystemSession.getUser().getUserTel());
|
|
|
+ releaseProductByBatch.setPublisherUu(SystemSession.getUser().getUserUU());
|
|
|
+
|
|
|
+ releaseProductByBatch.setUnit("PCS");
|
|
|
+ releaseProductByBatch.setCreateDate(new Date());
|
|
|
+ releaseProductByBatchs.add(releaseProductByBatch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ commonDao.save(releaseProductByBatchs, ReleaseProductByBatch.class);
|
|
|
+ Long userUU = SystemSession.getUser().getUserUU();
|
|
|
+ releaseProductByBatchDao.callValidProcedure(userUU, batch);
|
|
|
+ Integer failure = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.failure.value());
|
|
|
+ Integer success = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.success.value());
|
|
|
+ modelMap.put("total", total);
|
|
|
+ modelMap.put("success", success);
|
|
|
+ modelMap.put("failure", failure);
|
|
|
+ modelMap.put("filter", total - failure - success);
|
|
|
+ modelMap.put("batch", batch);
|
|
|
+ return modelMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置当前的最小和最大价格
|
|
|
+ * @param releaseProductByBatch
|
|
|
+ * @param priceMaxMinPrice
|
|
|
+ */
|
|
|
+ private void setMinMaxPrices(ReleaseProductByBatch releaseProductByBatch, Double[] priceMaxMinPrice) {
|
|
|
+ if(!priceMaxMinPrice[0].equals(Double.MAX_VALUE)) {
|
|
|
+ releaseProductByBatch.setMinPriceRMB(priceMaxMinPrice[0]);
|
|
|
+ }
|
|
|
+ if(!priceMaxMinPrice[1].equals(Double.MIN_VALUE)) {
|
|
|
+ releaseProductByBatch.setMaxPriceRMB(priceMaxMinPrice[1]);
|
|
|
+ }
|
|
|
+ if(!priceMaxMinPrice[2].equals(Double.MAX_VALUE)) {
|
|
|
+ releaseProductByBatch.setMinPriceUSD(priceMaxMinPrice[2]);
|
|
|
+ }
|
|
|
+ if(!priceMaxMinPrice[3].equals(Double.MIN_VALUE)) {
|
|
|
+ releaseProductByBatch.setMaxPriceUSD(priceMaxMinPrice[3]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置分段价格
|
|
|
+ * @param releaseProductByBatch
|
|
|
+ */
|
|
|
+ private void setSectionPrice(ReleaseProductByBatch releaseProductByBatch, List<CommodityQtyPrice> prices, Double[] priceMaxMinPrice) {
|
|
|
+ if (!CollectionUtils.isEmpty(prices)) {
|
|
|
+ double start = -1;
|
|
|
+ for (int j = 0; j < prices.size(); j++) {
|
|
|
+ CommodityQtyPrice price = prices.get(j);
|
|
|
+ if(j == 0) {
|
|
|
+ int val = price.getStart().compareTo(releaseProductByBatch.getMinBuyQty());
|
|
|
+ if(val != 0) {
|
|
|
+ releaseProductByBatch.addErrmsg("13:第一个分段数量的起始值与最小起订量不相等");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (start < price.getStart()) {
|
|
|
+ start = price.getStart();
|
|
|
+ } else {
|
|
|
+ releaseProductByBatch.addErrmsg("13:分段数量起始值存在后一个分段的开始值小于前一个分段的开始值");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (j < prices.size() - 1) {
|
|
|
+ price.setEnd(prices.get(j + 1).getStart() - 1);
|
|
|
+ }
|
|
|
+ if (j == prices.size() - 1) {
|
|
|
+ price.setEnd(releaseProductByBatch.getReserve());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ CommodityQtyPrice qtyPrice = new CommodityQtyPrice();
|
|
|
+ qtyPrice.setStart(releaseProductByBatch.getMinBuyQty());
|
|
|
+ Double rmbMinPackPrice = releaseProductByBatch.getRmbMinPackPrice();
|
|
|
+ if (rmbMinPackPrice != null) {
|
|
|
+ qtyPrice.setrMBPrice(rmbMinPackPrice);
|
|
|
+ priceMaxMinPrice[0] = rmbMinPackPrice;
|
|
|
+ priceMaxMinPrice[1] = rmbMinPackPrice;
|
|
|
+ }
|
|
|
+ Double usdMinPackPrice = releaseProductByBatch.getUsdMinPackPrice();
|
|
|
+ if (usdMinPackPrice != null) {
|
|
|
+ qtyPrice.setuSDPrice(usdMinPackPrice);
|
|
|
+ priceMaxMinPrice[2] = usdMinPackPrice;
|
|
|
+ priceMaxMinPrice[3] = usdMinPackPrice;
|
|
|
+ }
|
|
|
+ qtyPrice.setEnd(releaseProductByBatch.getReserve());
|
|
|
+ prices.add(qtyPrice);
|
|
|
+ }
|
|
|
+ releaseProductByBatch.setPrices(prices);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置内地的交货周期
|
|
|
+ * @param releaseProductByBatch
|
|
|
+ * @param deliveryCellValue
|
|
|
+ */
|
|
|
+ private void setDemDeliveryTime(ReleaseProductByBatch releaseProductByBatch, Object deliveryCellValue) {
|
|
|
+ if (!StringUtils.isEmpty(deliveryCellValue)) {
|
|
|
+ Short[] delivers = splitDeliveryString(deliveryCellValue.toString());
|
|
|
+ if (delivers != null) {
|
|
|
+ releaseProductByBatch.setMindeliveryDemTime(delivers[0]);
|
|
|
+ releaseProductByBatch.setMaxdeliveryDemTime(delivers[1]);
|
|
|
+
|
|
|
+ releaseProductByBatch.setDeliveryDemTime(delivers[1]);
|
|
|
+
|
|
|
+ Short maxdeliveryDemTime = releaseProductByBatch.getMaxdeliveryDemTime();
|
|
|
+ int compareTo = maxdeliveryDemTime.compareTo((short)30);
|
|
|
+ if(compareTo > 0) {
|
|
|
+ releaseProductByBatch.setErrmsg("11:大陆交期的最大值超过了30天");
|
|
|
+ }
|
|
|
+
|
|
|
+ Short mindeliveryDemTime = releaseProductByBatch.getMindeliveryDemTime();
|
|
|
+ int compareTo2 = mindeliveryDemTime.compareTo((short)0);
|
|
|
+ if(compareTo2 < 0) {
|
|
|
+ releaseProductByBatch.setErrmsg("11:大陆交期的最小值小于1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 设置香港的交货周期
|
|
|
+ * @param releaseProductByBatch
|
|
|
+ * @param deliveryhkCellValue
|
|
|
+ */
|
|
|
+ private void setHKDeliveryTime(ReleaseProductByBatch releaseProductByBatch, Object deliveryhkCellValue) {
|
|
|
+ if (!StringUtils.isEmpty(deliveryhkCellValue)) {
|
|
|
+ Short[] deliverys = splitDeliveryString(deliveryhkCellValue.toString());
|
|
|
+ if (deliverys != null) {
|
|
|
+ releaseProductByBatch.setMindeliveryHKTime(deliverys[0]);
|
|
|
+ releaseProductByBatch.setMaxdeliveryHKTime(deliverys[1]);
|
|
|
+ releaseProductByBatch.setDeliveryHKTime(deliverys[1]);
|
|
|
+
|
|
|
+ Short maxdeliveryHKTime = releaseProductByBatch.getMaxdeliveryHKTime();
|
|
|
+ int compareTo = maxdeliveryHKTime.compareTo((short)30);
|
|
|
+ if(compareTo > 0) {
|
|
|
+ releaseProductByBatch.setErrmsg("12:香港交期的最大值超过了30天");
|
|
|
+ }
|
|
|
+
|
|
|
+ Short mindeliveryHKTime = releaseProductByBatch.getMindeliveryHKTime();
|
|
|
+ int compareTo2 = mindeliveryHKTime.compareTo((short)0);
|
|
|
+ if(compareTo2 < 1) {
|
|
|
+ releaseProductByBatch.setErrmsg("12:香港交期的最小值小于1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 根据价格确认币别
|
|
|
+ * @param releaseProductByBatch
|
|
|
+ */
|
|
|
+ private void comfirmCurrency(ReleaseProductByBatch releaseProductByBatch) {
|
|
|
+
|
|
|
+ Double rmbMinPackPrice = releaseProductByBatch.getRmbMinPackPrice();
|
|
|
+ Double usdMinPackPrice = releaseProductByBatch.getUsdMinPackPrice();
|
|
|
+ if (rmbMinPackPrice == null && usdMinPackPrice == null) {
|
|
|
+ releaseProductByBatch.addErrmsg("8-9:最小包单价至少填一种价格");
|
|
|
+ } else if (rmbMinPackPrice != null && usdMinPackPrice == null) {
|
|
|
+ releaseProductByBatch.setCurrency("RMB");
|
|
|
+ releaseProductByBatch.setRmbTaxRate(0.17d);
|
|
|
+ } else if (rmbMinPackPrice == null && usdMinPackPrice != null) {
|
|
|
+ releaseProductByBatch.setCurrency("USD");
|
|
|
+ releaseProductByBatch.setUsdTaxRate(0d);
|
|
|
+ } else {
|
|
|
+ releaseProductByBatch.setCurrency("RMB-USD");
|
|
|
+ releaseProductByBatch.setRmbTaxRate(0.17d);
|
|
|
+ releaseProductByBatch.setUsdTaxRate(0d);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 创建时间 :2016年12月11日 下午2:02:16
|
|
|
+ *
|
|
|
+ * @author yujia
|
|
|
+ * @param cell
|
|
|
+ * @param cellType
|
|
|
+ * @throws @Description:
|
|
|
+ * 传入单元格,类型,返回值
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private Object readWorkBookCell(Cell cell, int cellType, int r, int n) {
|
|
|
+ Object obj = null;
|
|
|
+ try {
|
|
|
+ if (cell != null && cell.getCellType() != Cell.CELL_TYPE_BLANK) {
|
|
|
+ switch (cellType) {
|
|
|
+ case Cell.CELL_TYPE_STRING:
|
|
|
+ cell.setCellType(Cell.CELL_TYPE_STRING);
|
|
|
+ String str = cell.getStringCellValue().trim();
|
|
|
+ if(str.indexOf("\u00A0")>0){
|
|
|
+ str= str.replaceAll("\u00A0", "");
|
|
|
+ }
|
|
|
+ obj = str.trim();
|
|
|
+ break;
|
|
|
+ case Cell.CELL_TYPE_NUMERIC:
|
|
|
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
|
|
|
+ obj = cell.getNumericCellValue();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
|
|
+ String productTime = cell.getStringCellValue();
|
|
|
+ Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
|
|
+ Matcher m = p.matcher(productTime);
|
|
|
+ String time = m.replaceAll("");
|
|
|
+ if(time.indexOf("\u00A0")>0){
|
|
|
+ time= time.replaceAll("\u00A0", "");
|
|
|
+ }
|
|
|
+ DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+ obj = format1.parse(time);
|
|
|
+ }else if (HSSFDateUtil.isCellDateFormatted(cell)) {
|
|
|
+ obj = cell.getDateCellValue();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ throw new IllegalOperatorException("读取表格中"+r+"行"+ (n+1)+ "列的内容错误,有可能是该单元格的格式不正确");
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 创建时间 :2016年12月11日 下午2:02:47
|
|
|
+ *
|
|
|
+ * @author yujia
|
|
|
+ * @return
|
|
|
+ * @return Short[]
|
|
|
+ * @throws @Description:
|
|
|
+ * 大陆交货和香港交货的
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private Short[] splitDeliveryString(String delivery) {
|
|
|
+ Short[] shorts = null;
|
|
|
+ if (!StringUtils.isEmpty(delivery)) {
|
|
|
+ shorts = new Short[2];
|
|
|
+ String[] deliverys = delivery.split("~");
|
|
|
+ if (deliverys.length == 1) {
|
|
|
+ try {
|
|
|
+ shorts[0] = Short.valueOf(deliverys[0].trim());
|
|
|
+ shorts[1] = Short.valueOf(deliverys[0].trim());
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ shorts[0] = Short.valueOf(deliverys[0]);
|
|
|
+ shorts[1] = Short.valueOf(deliverys[1]);
|
|
|
+ Arrays.sort(shorts);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return shorts;
|
|
|
+ }
|
|
|
+
|
|
|
+ * 创建时间 :2016年12月12日 下午4:46:21
|
|
|
+ *
|
|
|
+ * @author yujia
|
|
|
+ * @param cellQty
|
|
|
+ * @param cellPriceRMB
|
|
|
+ * @param cellPriceUSD
|
|
|
+ * @param prices
|
|
|
+ * @param releaseProductByBatch
|
|
|
+ * @return void
|
|
|
+ * @throws @Description:
|
|
|
+ * 获取每一个分段的的数量
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private void readSectionPrice(Cell cellQty, Cell cellPriceRMB, Cell cellPriceUSD, List<CommodityQtyPrice> prices,
|
|
|
+ ReleaseProductByBatch releaseProductByBatch, int r, int num, Double[] priceMaxMinPrice) {
|
|
|
+
|
|
|
+ Object startQtyCellValue = readWorkBookCell(cellQty, Cell.CELL_TYPE_NUMERIC, r, num);
|
|
|
+ if (startQtyCellValue != null) {
|
|
|
+ Double start = Double.valueOf(startQtyCellValue.toString());
|
|
|
+ CommodityQtyPrice qtyPrice = new CommodityQtyPrice();
|
|
|
+
|
|
|
+ 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_NUMERIC, r, num+1);
|
|
|
+ if (pricermbReadWorkBookCellValue != null) {
|
|
|
+ pricermb = Double.valueOf(pricermbReadWorkBookCellValue.toString());
|
|
|
+ }
|
|
|
+ if (pricermb != null && pricermb > 0.0) {
|
|
|
+ qtyPrice.setrMBPrice(pricermb);
|
|
|
+ BigDecimal priceNum = new BigDecimal(pricermb);
|
|
|
+ BigDecimal taxNum = new BigDecimal(releaseProductByBatch.getRmbTaxRate() + 1);
|
|
|
+ qtyPrice.setrMBNTPrice(priceNum.divide(taxNum, 6, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ if(priceMaxMinPrice[0] > pricermb) {
|
|
|
+ priceMaxMinPrice[0] = pricermb;
|
|
|
+ }
|
|
|
+ if(priceMaxMinPrice[1] < pricermb) {
|
|
|
+ priceMaxMinPrice[1] = pricermb;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(currency != null && currency.contains("USD")) {
|
|
|
+
|
|
|
+ Double priceusd = null;
|
|
|
+ Object priceusdReadWorkBookCellValue = readWorkBookCell(cellPriceUSD, Cell.CELL_TYPE_NUMERIC, r, num+2);
|
|
|
+ if (priceusdReadWorkBookCellValue != null) {
|
|
|
+ priceusd = Double.valueOf(priceusdReadWorkBookCellValue.toString());
|
|
|
+ }
|
|
|
+ if (priceusd != null && priceusd > 0) {
|
|
|
+ qtyPrice.setuSDPrice(priceusd);
|
|
|
+ qtyPrice.setuSDNTPrice(priceusd);
|
|
|
+ if(priceMaxMinPrice[2] > priceusd) {
|
|
|
+ priceMaxMinPrice[2] = priceusd;
|
|
|
+ }
|
|
|
+ if(priceMaxMinPrice[3] < priceusd) {
|
|
|
+ priceMaxMinPrice[3] = priceusd;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Set<String> publishByBatch(String batch) {
|
|
|
+ Enterprise enterprise = SystemSession.getUser().getEnterprise();
|
|
|
+ releaseProductByBatchDao.callPublishByBatch(enterprise.getUu(), enterprise.getEnName(), batch);
|
|
|
+ List<Commodity> goodsList = goodsDao.findByBatchid(batch);
|
|
|
+ Set<String> uuids = new HashSet<String>();
|
|
|
+ for (Commodity goods : goodsList) {
|
|
|
+ uuids.add(goods.getUuid());
|
|
|
+ goodsService.saveOrUpdatePriceInfos(goods, "NORMAL");
|
|
|
+ }
|
|
|
+ shopComponentService.saveShopComponent(goodsList);
|
|
|
+ return uuids;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 获取这次上架批次有误的信息
|
|
|
+ * @param batch
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ReleaseProductByBatch> findFailureReleaseProductByBatchByBatch(String batch) {
|
|
|
+ return releaseProductByBatchDao.findByPublisherUuAndRelbatchidAndReleaseCode(SystemSession.getUser().getUserUU(), batch, ReleaseStatus.failure.value());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通过id删除产品信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ if (releaseProductByBatchDao.exists(id)) {
|
|
|
+ releaseProductByBatchDao.delete(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通过ids删除产品信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void delete(List<Long> ids) {
|
|
|
+ for (int i = 0; i < ids.size(); i++) {
|
|
|
+ if (releaseProductByBatchDao.exists(ids.get(i))) {
|
|
|
+ releaseProductByBatchDao.delete(ids.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通过uu查询所有信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ReleaseProductByBatch> findByPublisheruu(Long publisheruu) {
|
|
|
+ List<ReleaseProductByBatch> releaseProductByBatchs = releaseProductByBatchDao.findByPublisherUu(publisheruu);
|
|
|
+ return releaseProductByBatchs;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ReleaseProductByBatch> getPageReleaseProductByBatch(final PageInfo info, String batch) {
|
|
|
+ info.filter("relbatchid", batch);
|
|
|
+ info.filter("releaseCode", ReleaseStatus.success.value());
|
|
|
+ return releaseProductByBatchDao.findAll(new Specification<ReleaseProductByBatch>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<ReleaseProductByBatch> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ query.where(info.getPredicates(root, query, cb));
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }, info);
|
|
|
+ }
|
|
|
+}
|