|
|
@ -27,9 +27,8 @@ package com.yxt.supervise.portal.biz.gdinventory; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.map.MapUtil; |
|
|
|
import cn.hutool.core.text.csv.*; |
|
|
|
import cn.hutool.poi.excel.ExcelReader; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
|
import cn.hutool.poi.excel.sax.handler.RowHandler; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
@ -38,7 +37,6 @@ import com.yxt.common.core.result.FileUploadResult; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.supervise.portal.biz.storeindex.StoreIndexService; |
|
|
|
import com.yxt.supervise.portal.extexcel.CsvTool; |
|
|
|
import com.yxt.supervise.portal.extexcel.ExcelTool; |
|
|
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -46,7 +44,6 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.util.*; |
|
|
@ -74,6 +71,10 @@ public class GdInventoryService extends ServiceImpl<GdInventoryMapper, GdInvento |
|
|
|
private StoreIndexService storeIndexService; |
|
|
|
@Autowired |
|
|
|
private FileUploadComponent fileUploadComponent; |
|
|
|
@Autowired |
|
|
|
private GdInventoryLogService gdInventoryLogService; |
|
|
|
@Autowired |
|
|
|
private GdInventoryLogErrService gdInventoryLogErrService; |
|
|
|
|
|
|
|
public void doCheck() { |
|
|
|
|
|
|
@ -278,20 +279,22 @@ public class GdInventoryService extends ServiceImpl<GdInventoryMapper, GdInvento |
|
|
|
|
|
|
|
public void importFromXlsx(String filePath) { |
|
|
|
long millis = System.currentTimeMillis(); |
|
|
|
ExcelUtil.readBySax(filePath, 0, createRowHandler()); |
|
|
|
GdInventoryLog gdlog = new GdInventoryLog(filePath); |
|
|
|
ExcelUtil.readBySax(filePath, 0, createRowHandler(gdlog)); |
|
|
|
System.out.println("用时:" + (System.currentTimeMillis() - millis)); |
|
|
|
} |
|
|
|
|
|
|
|
private RowHandler createRowHandler() { |
|
|
|
private RowHandler createRowHandler(GdInventoryLog gdlog) { |
|
|
|
return new RowHandler() { |
|
|
|
|
|
|
|
private List<GdInventoryOk> toInsertList = new ArrayList<>(); |
|
|
|
private int x = 0, y = 0; |
|
|
|
private List<GdInventoryLogErr> errList = new ArrayList<>(); |
|
|
|
private int x = 0, y = 0, errnum = 0; |
|
|
|
private int num = 0; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handle(int i, long l, List<Object> r) { |
|
|
|
if (l > 0) { |
|
|
|
public void handle(int sheetIndex, long rowIndex, List<Object> r) { |
|
|
|
if (rowIndex > 0) { |
|
|
|
String prodCode = "" + r.get(3); |
|
|
|
String warehouseCode = "" + r.get(1); |
|
|
|
|
|
|
@ -309,9 +312,21 @@ public class GdInventoryService extends ServiceImpl<GdInventoryMapper, GdInvento |
|
|
|
map.put("prodValue", r.get(8)); // 商品货值
|
|
|
|
map.put("suppliderName", r.get(9)); // 供应商
|
|
|
|
map.put("datadate", r.get(10)); // 数据日期
|
|
|
|
BeanUtil.fillBeanWithMap(map, ok, true); |
|
|
|
|
|
|
|
toInsertList.add(ok); |
|
|
|
try { |
|
|
|
BeanUtil.fillBeanWithMap(map, ok, true); |
|
|
|
toInsertList.add(ok); |
|
|
|
y++; |
|
|
|
} catch (Exception e) { |
|
|
|
errnum++; |
|
|
|
GdInventoryLogErr gile = new GdInventoryLogErr(); |
|
|
|
gile.setRowNum(x + 1); |
|
|
|
gile.setErrInfo(e.getMessage()); |
|
|
|
gile.setFileFullPath(gdlog.getFileFullPath()); |
|
|
|
gile.setRowContent(JSONUtil.toJsonStr(r)); |
|
|
|
errList.add(gile); |
|
|
|
} |
|
|
|
|
|
|
|
if (999 == num) { |
|
|
|
gdInventoryOkService.saveBatch(toInsertList); |
|
|
|
num = 0; |
|
|
@ -319,10 +334,9 @@ public class GdInventoryService extends ServiceImpl<GdInventoryMapper, GdInvento |
|
|
|
} else { |
|
|
|
num++; |
|
|
|
} |
|
|
|
y++; |
|
|
|
} |
|
|
|
x++; |
|
|
|
System.out.println(",X:" + x + ",Y:" + y); |
|
|
|
// System.out.println(",X:" + x + ",Y:" + y);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -336,20 +350,33 @@ public class GdInventoryService extends ServiceImpl<GdInventoryMapper, GdInvento |
|
|
|
if (toInsertList != null && !toInsertList.isEmpty()) { |
|
|
|
gdInventoryOkService.saveBatch(toInsertList); |
|
|
|
} |
|
|
|
if (errList != null && !errList.isEmpty()) { |
|
|
|
gdInventoryLogErrService.saveBatch(errList); |
|
|
|
} |
|
|
|
|
|
|
|
gdlog.setAllNum(x); |
|
|
|
gdlog.setValidNum(y); |
|
|
|
gdlog.setErrRowNum(errnum); |
|
|
|
RowHandler.super.doAfterAllAnalysed(); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean importAndCount(MultipartFile file) { |
|
|
|
public ResultBean<GdInventoryLog> uploadAndResetData(MultipartFile file) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
|
|
|
|
ResultBean<FileUploadResult> fub = fileUploadComponent.uploadFile(file, "kcxxcx"); |
|
|
|
String filePath = fub.getData().getFilePath(); |
|
|
|
String fp = fileUploadComponent.getUploadPath() + filePath; |
|
|
|
|
|
|
|
long millis = System.currentTimeMillis(); |
|
|
|
ExcelUtil.read07BySax(fp, -1, createRowHandler()); |
|
|
|
System.out.println("用时:" + (System.currentTimeMillis() - millis)); |
|
|
|
return ResultBean.fireSuccess(); |
|
|
|
gdInventoryOkService.clearData(); |
|
|
|
GdInventoryLog gdlog = new GdInventoryLog(fp); |
|
|
|
ExcelUtil.read07BySax(fp, -1, createRowHandler(gdlog)); |
|
|
|
// System.out.println("用时:" + (System.currentTimeMillis() - millis));
|
|
|
|
gdlog.setDurations(System.currentTimeMillis() - millis); |
|
|
|
gdInventoryLogService.save(gdlog); |
|
|
|
|
|
|
|
return rb.success().setData(gdlog); |
|
|
|
} |
|
|
|
} |
|
|
|