|
|
@ -26,15 +26,29 @@ |
|
|
|
package com.yxt.supervise.portal.biz.gdinstorage; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import cn.hutool.poi.excel.ExcelReader; |
|
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
|
import cn.hutool.poi.excel.sax.handler.RowHandler; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.yxt.common.base.config.component.FileUploadComponent; |
|
|
|
import com.yxt.common.core.result.FileUploadResult; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.supervise.portal.biz.gdinventory.GdInventoryLog; |
|
|
|
import com.yxt.supervise.portal.biz.gdinventory.GdInventoryLogErr; |
|
|
|
import com.yxt.supervise.portal.biz.gdinventory.GdInventoryOk; |
|
|
|
import com.yxt.supervise.portal.biz.gdoutstorage.GdOutstorageGd; |
|
|
|
import com.yxt.supervise.portal.biz.supplierindex.SupplierIndexService; |
|
|
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* Project: yxt_supervise <br/> |
|
|
@ -52,8 +66,14 @@ import java.util.List; |
|
|
|
@Service |
|
|
|
public class GdInstorageService extends ServiceImpl<GdInstorageMapper, GdInstorage> { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FileUploadComponent fileUploadComponent; |
|
|
|
@Autowired |
|
|
|
private GdInstorageGdService gdInstorageGdService; |
|
|
|
@Autowired |
|
|
|
private GdInstorageLogService gdInstorageLogService; |
|
|
|
@Autowired |
|
|
|
private SupplierIndexService supplierIndexService; |
|
|
|
|
|
|
|
public void doimp(String filePath) { |
|
|
|
long millis = System.currentTimeMillis(); |
|
|
@ -107,4 +127,83 @@ public class GdInstorageService extends ServiceImpl<GdInstorageMapper, GdInstora |
|
|
|
gd.setColv21("" + r.get(22)); // 进项税率
|
|
|
|
return gd; |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<GdInstorageLog> uploadAndInsert(MultipartFile file) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
|
|
|
|
ResultBean<FileUploadResult> fub = fileUploadComponent.uploadFile(file, "rkmxb"); |
|
|
|
String filePath = fub.getData().getFilePath(); |
|
|
|
String fp = fileUploadComponent.getUploadPath() + filePath; |
|
|
|
|
|
|
|
long millis = System.currentTimeMillis(); |
|
|
|
GdInstorageLog gdlog = new GdInstorageLog(fp); |
|
|
|
ExcelUtil.read07BySax(fp, -1, createRowHandler(gdlog)); |
|
|
|
// System.out.println("用时:" + (System.currentTimeMillis() - millis));
|
|
|
|
gdlog.setDurations(System.currentTimeMillis() - millis); |
|
|
|
gdInstorageLogService.save(gdlog); |
|
|
|
|
|
|
|
return rb.success().setData(gdlog); |
|
|
|
} |
|
|
|
|
|
|
|
private RowHandler createRowHandler(GdInstorageLog gdlog) { |
|
|
|
return new RowHandler() { |
|
|
|
|
|
|
|
List<GdInstorageGd> toInsertListGd = new ArrayList<>(); |
|
|
|
List<GdInstorage> toInsertList = new ArrayList<>(); |
|
|
|
private List<GdInstorageLogErr> errList = new ArrayList<>(); |
|
|
|
private int x = 0, y = 0, errnum = 0; |
|
|
|
private String odate = null; |
|
|
|
|
|
|
|
private String readOrderDate(String orderdate) { |
|
|
|
if (StrUtil.isBlank(orderdate)) |
|
|
|
return ""; |
|
|
|
return orderdate.substring(0, 10); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void handle(int sheetIndex, long rowIndex, List<Object> r) { |
|
|
|
if (rowIndex > 0) { |
|
|
|
String warehouseCode = "" + r.get(1); |
|
|
|
GdInstorageGd gd = rowToEntity(r); |
|
|
|
|
|
|
|
if (StrUtil.isBlank(odate)) { |
|
|
|
odate = readOrderDate(gd.getCold3()); |
|
|
|
} |
|
|
|
gd.setOrderDate(odate); |
|
|
|
|
|
|
|
String unifiedCode = supplierIndexService.unifiedCode(gd.getColex()); |
|
|
|
if (StrUtil.isBlank(unifiedCode)) { |
|
|
|
gd.setSupplierCodeUnified(gd.getColex()); |
|
|
|
} else { |
|
|
|
gd.setSupplierCodeUnified(unifiedCode); |
|
|
|
} |
|
|
|
|
|
|
|
toInsertListGd.add(gd); |
|
|
|
if ("112".equals(warehouseCode.trim())) { |
|
|
|
GdInstorage gi = new GdInstorage(); |
|
|
|
BeanUtil.copyProperties(gd, gi); |
|
|
|
toInsertList.add(gi); |
|
|
|
y++; |
|
|
|
} |
|
|
|
x++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void doAfterAllAnalysed() { |
|
|
|
if (toInsertListGd != null && !toInsertListGd.isEmpty()) { |
|
|
|
gdInstorageGdService.saveBatch(toInsertListGd); |
|
|
|
} |
|
|
|
if (toInsertList != null && !toInsertList.isEmpty()) { |
|
|
|
GdInstorageService.this.saveBatch(toInsertList); |
|
|
|
} |
|
|
|
|
|
|
|
gdlog.setAllNum(x); |
|
|
|
gdlog.setValidNum(y); |
|
|
|
gdlog.setErrRowNum(errnum); |
|
|
|
RowHandler.super.doAfterAllAnalysed(); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|