|
|
@ -3,9 +3,11 @@ package com.yxt.supervise.customer.biz.gdinventoryok; |
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.thread.ThreadUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelWriter; |
|
|
|
import cn.hutool.poi.excel.sax.handler.RowHandler; |
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
import com.alibaba.excel.read.builder.ExcelReaderBuilder; |
|
|
@ -20,7 +22,10 @@ import com.yxt.common.core.result.FileUploadResult; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import com.yxt.supervise.customer.api.gdinventorylog.GdInventoryLog; |
|
|
|
import com.yxt.supervise.customer.api.gdinventoryok.*; |
|
|
|
import com.yxt.supervise.customer.api.gdinventoryok.GdInventoryOk; |
|
|
|
import com.yxt.supervise.customer.api.gdinventoryok.GdInventoryOkExcelVo; |
|
|
|
import com.yxt.supervise.customer.api.gdinventoryok.GdInventoryOkQuery; |
|
|
|
import com.yxt.supervise.customer.api.gdinventoryok.GdInventoryOkVo; |
|
|
|
import com.yxt.supervise.customer.api.gdinventoryyc.GdInventoryYc; |
|
|
|
import com.yxt.supervise.customer.biz.gdinventorylog.GdInventoryLogService; |
|
|
|
import com.yxt.supervise.customer.biz.gdinventorylogerr.GdInventoryLogErrService; |
|
|
@ -28,12 +33,15 @@ import com.yxt.supervise.customer.biz.gdinventoryyc.GdInventoryYcService; |
|
|
|
import com.yxt.supervise.customer.biz.gdrescategoryprod.GdRescategoryProdService; |
|
|
|
import com.yxt.supervise.customer.biz.storeindex.StoreIndexService; |
|
|
|
import com.yxt.supervise.customer.biz.storeinfo.StoreInfoService; |
|
|
|
import com.yxt.supervise.customer.feign.report.ReportInventoryFeign; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.File; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
@ -64,6 +72,9 @@ public class GdInventoryOkService extends MybatisBaseService<GdInventoryOkMapper |
|
|
|
@Autowired |
|
|
|
private GdInventoryLogErrService gdInventoryLogErrService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ReportInventoryFeign reportInventoryFeign; |
|
|
|
|
|
|
|
public void clearData() { |
|
|
|
baseMapper.clearData(); |
|
|
|
} |
|
|
@ -141,17 +152,162 @@ public class GdInventoryOkService extends MybatisBaseService<GdInventoryOkMapper |
|
|
|
String filePath = fub.getData().getFilePath(); |
|
|
|
String fp = fileUploadComponent.getUploadPath() + filePath; |
|
|
|
|
|
|
|
long millis = System.currentTimeMillis(); |
|
|
|
// long millis = System.currentTimeMillis();
|
|
|
|
baseMapper.clearData(); |
|
|
|
gdInventoryYcService.clearData(); |
|
|
|
GdInventoryLog gdlog = new GdInventoryLog(fp); |
|
|
|
gdlog.setOrderDate("3000-01-01"); |
|
|
|
gdlog.setState(1); |
|
|
|
gdInventoryLogService.save(gdlog); |
|
|
|
|
|
|
|
ThreadUtil.execute(() -> asyncRead2Db(fp)); |
|
|
|
// ExcelUtil.read07BySax(fp, -1, createRowHandler(gdlog));
|
|
|
|
// System.out.println("用时:" + (System.currentTimeMillis() - millis));
|
|
|
|
// gdlog.setDurations(System.currentTimeMillis() - millis);
|
|
|
|
|
|
|
|
return gdlog; |
|
|
|
} |
|
|
|
|
|
|
|
private void asyncRead2Db(String fp) { |
|
|
|
|
|
|
|
GdInventoryLog gdlog = gdInventoryLogService.fetchByFileFullPath(fp); |
|
|
|
long millis = System.currentTimeMillis(); |
|
|
|
ExcelReaderBuilder read = EasyExcel.read(fp, GdInventoryOk.class, createReadListener(gdlog)); |
|
|
|
read.sheet().doRead(); |
|
|
|
// System.out.println("用时:" + (System.currentTimeMillis() - millis));
|
|
|
|
gdlog.setDurations(System.currentTimeMillis() - millis); |
|
|
|
gdInventoryLogService.save(gdlog); |
|
|
|
gdlog.setState(2); |
|
|
|
gdInventoryLogService.updateById(gdlog); |
|
|
|
|
|
|
|
return gdlog; |
|
|
|
millis = System.currentTimeMillis(); |
|
|
|
ResultBean r = reportInventoryFeign.kcReport(gdlog.getOrderDate()); |
|
|
|
gdlog.setState(3); |
|
|
|
gdlog.setRemarks(gdlog.getRemarks() + ";创建报表用时:" + (System.currentTimeMillis() - millis)); |
|
|
|
gdInventoryLogService.updateById(gdlog); |
|
|
|
gdInventoryLogService.buildExcelById(gdlog.getIdStr()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private RowHandler createRowHandler(GdInventoryLog gdlog) { |
|
|
|
return new RowHandler() { |
|
|
|
|
|
|
|
private List<GdInventoryOk> toInsertList = new ArrayList<>(); |
|
|
|
private List<GdInventoryYc> toInsertListYc = new ArrayList<>(); |
|
|
|
private int x = 0, y = 0, z = 0, errnum = 0; |
|
|
|
private int num = 0, numyc = 0; |
|
|
|
private String odate = null; |
|
|
|
|
|
|
|
private Map<String, Object> readMapFromRow(List<Object> r) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("orgCode", r.get(0));// 企业组织机构代码证
|
|
|
|
map.put("warehouseCode", "" + r.get(1));// 仓库/门店编号
|
|
|
|
map.put("warehouseName", r.get(2)); // 仓库/门店名称
|
|
|
|
map.put("prodCode", "" + r.get(7)); // 商品编码
|
|
|
|
map.put("prodBarCode", r.get(8));// 商品条码
|
|
|
|
map.put("prodName", r.get(9)); // 商品名称
|
|
|
|
map.put("warehouseType", r.get(10)); // 仓库类型
|
|
|
|
map.put("prodNum", r.get(11)); // 商品数量
|
|
|
|
map.put("prodValue", r.get(12)); // 商品货值
|
|
|
|
map.put("suppliderName", r.get(13)); // 供应商
|
|
|
|
map.put("datadate", r.get(14)); // 数据日期
|
|
|
|
|
|
|
|
|
|
|
|
map.put("typeCode", r.get(3)); // 类别编号
|
|
|
|
map.put("typeName", r.get(4)); // 类别名称
|
|
|
|
map.put("typeOne", r.get(5)); // 一级类别名称
|
|
|
|
map.put("typeTwo", r.get(6)); // 二级类别名称
|
|
|
|
|
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean checkYcProd(String typeCode) { |
|
|
|
if (StrUtil.isBlank(typeCode)) |
|
|
|
return false; |
|
|
|
if (typeCode.length() < 4) |
|
|
|
return false; |
|
|
|
String subCode = typeCode.substring(0, 4); |
|
|
|
return "0811".equals(subCode) || "0813".equals(subCode) || "0815".equals(subCode); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handle(int sheetIndex, long rowIndex, List<Object> r) { |
|
|
|
String typeCode = "" + r.get(3); |
|
|
|
if (rowIndex > 0 && StringUtils.isNotBlank(typeCode)) { |
|
|
|
String prodCode = "" + r.get(7); |
|
|
|
String warehouseCode = "" + r.get(1); |
|
|
|
|
|
|
|
if (StrUtil.isBlank(odate)) { |
|
|
|
odate = "" + r.get(14); |
|
|
|
gdlog.setOrderDate(odate); |
|
|
|
} |
|
|
|
|
|
|
|
// System.out.println(",X:" + x + ",prodCode:" + prodCode);
|
|
|
|
|
|
|
|
if (checkYcProd(typeCode)) { |
|
|
|
GdInventoryYc yc = new GdInventoryYc(); |
|
|
|
Map<String, Object> map = readMapFromRow(r); |
|
|
|
|
|
|
|
try { |
|
|
|
BeanUtil.fillBeanWithMap(map, yc, true); |
|
|
|
toInsertListYc.add(yc); |
|
|
|
z++; |
|
|
|
} catch (Exception e) { |
|
|
|
errnum++; |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
if (990 == numyc) { |
|
|
|
gdInventoryYcService.saveBatch(toInsertListYc); |
|
|
|
numyc = 0; |
|
|
|
toInsertListYc.clear(); |
|
|
|
} else { |
|
|
|
numyc++; |
|
|
|
} |
|
|
|
} else { |
|
|
|
GdInventoryOk ok = new GdInventoryOk(); |
|
|
|
Map<String, Object> map = readMapFromRow(r); |
|
|
|
|
|
|
|
try { |
|
|
|
BeanUtil.fillBeanWithMap(map, ok, true); |
|
|
|
toInsertList.add(ok); |
|
|
|
y++; |
|
|
|
} catch (Exception e) { |
|
|
|
errnum++; |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
if (990 == num) { |
|
|
|
GdInventoryOkService.this.saveBatch(toInsertList); |
|
|
|
num = 0; |
|
|
|
toInsertList.clear(); |
|
|
|
} else { |
|
|
|
num++; |
|
|
|
} |
|
|
|
} |
|
|
|
x++; |
|
|
|
// System.out.println(",X:" + x + ",Y:" + y);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handleCell(int sheetIndex, long rowIndex, int cellIndex, Object value, CellStyle xssfCellStyle) { |
|
|
|
RowHandler.super.handleCell(sheetIndex, rowIndex, cellIndex, value, xssfCellStyle); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void doAfterAllAnalysed() { |
|
|
|
if (toInsertList != null && !toInsertList.isEmpty()) { |
|
|
|
GdInventoryOkService.this.saveBatch(toInsertList); |
|
|
|
} |
|
|
|
if (toInsertListYc != null && !toInsertListYc.isEmpty()) { |
|
|
|
gdInventoryYcService.saveBatch(toInsertListYc); |
|
|
|
} |
|
|
|
|
|
|
|
gdlog.setAllNum(x); |
|
|
|
gdlog.setValidNum(y); |
|
|
|
gdlog.setErrRowNum(z); |
|
|
|
RowHandler.super.doAfterAllAnalysed(); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private ReadListener<GdInventoryOk> createReadListener(GdInventoryLog gdlog) { |
|
|
|