优化商品导出excel的功能

This commit is contained in:
神话
2022-05-03 11:11:03 +08:00
parent e7faf6e621
commit cdadbf937c
4 changed files with 82 additions and 118 deletions

View File

@@ -3,18 +3,17 @@ package com.jsh.erp.service.material;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.materialExtend.MaterialExtendService;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.service.depotItem.DepotItemService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.materialCategory.MaterialCategoryService;
import com.jsh.erp.service.materialExtend.MaterialExtendService;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.service.unit.UnitService;
import com.jsh.erp.service.user.UserService;
@@ -22,12 +21,14 @@ import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ExcelUtils;
import com.jsh.erp.utils.StringUtil;
import jxl.Sheet;
import jxl.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@@ -125,23 +126,7 @@ public class MaterialService {
enableSerialNumber, enableBatchNumber, remark, idList, mpList, offset, rows);
if (null != list) {
for (MaterialVo4Unit m : list) {
//扩展信息
String materialOther = "";
for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("制造商")) {
materialOther = materialOther + ((m.getMfrs() == null || m.getMfrs().equals("")) ? "" : "(" + m.getMfrs() + ")");
}
if (mpArr[i].equals("自定义1")) {
materialOther = materialOther + ((m.getOtherField1() == null || m.getOtherField1().equals("")) ? "" : "(" + m.getOtherField1() + ")");
}
if (mpArr[i].equals("自定义2")) {
materialOther = materialOther + ((m.getOtherField2() == null || m.getOtherField2().equals("")) ? "" : "(" + m.getOtherField2() + ")");
}
if (mpArr[i].equals("自定义3")) {
materialOther = materialOther + ((m.getOtherField3() == null || m.getOtherField3().equals("")) ? "" : "(" + m.getOtherField3() + ")");
}
}
m.setMaterialOther(materialOther);
m.setMaterialOther(getMaterialOtherByParam(mpArr, m));
m.setStock(depotItemService.getStockByParam(null,m.getId(),null,null));
resList.add(m);
}
@@ -468,9 +453,20 @@ public class MaterialService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public BaseResponseInfo importExcel(Sheet src, HttpServletRequest request) throws Exception {
public BaseResponseInfo importExcel(MultipartFile file, HttpServletRequest request) throws Exception {
BaseResponseInfo info = new BaseResponseInfo();
try {
//文件扩展名只能为xls
String fileName = file.getOriginalFilename();
if(StringUtil.isNotEmpty(fileName)) {
String fileExt = fileName.substring(fileName.indexOf(".")+1);
if(!"xls".equals(fileExt)) {
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXTENSION_ERROR_CODE,
ExceptionConstants.MATERIAL_EXTENSION_ERROR_MSG);
}
}
Workbook workbook = Workbook.getWorkbook(file.getInputStream());
Sheet src = workbook.getSheet(0);
List<Depot> depotList= depotService.getDepot();
int depotCount = depotList.size();
List<MaterialWithInitStock> mList = new ArrayList<>();
@@ -946,6 +942,31 @@ public class MaterialService {
return materialMapperEx.getTotalStockAndPrice(depotList, idList, materialParam);
}
/**
* 构造扩展信息
* @param mpArr
* @param m
* @return
*/
public String getMaterialOtherByParam(String[] mpArr, MaterialVo4Unit m) {
String materialOther = "";
for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("制造商")) {
materialOther = materialOther + ((m.getMfrs() == null || m.getMfrs().equals("")) ? "" : "(" + m.getMfrs() + ")");
}
if (mpArr[i].equals("自定义1")) {
materialOther = materialOther + ((m.getOtherField1() == null || m.getOtherField1().equals("")) ? "" : "(" + m.getOtherField1() + ")");
}
if (mpArr[i].equals("自定义2")) {
materialOther = materialOther + ((m.getOtherField2() == null || m.getOtherField2().equals("")) ? "" : "(" + m.getOtherField2() + ")");
}
if (mpArr[i].equals("自定义3")) {
materialOther = materialOther + ((m.getOtherField3() == null || m.getOtherField3().equals("")) ? "" : "(" + m.getOtherField3() + ")");
}
}
return materialOther;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchSetMaterialCurrentStock(String ids) throws Exception {
int res = 0;

View File

@@ -529,7 +529,7 @@ public class SupplierService {
} else {
//会员
String[] names = {"名称", "联系人", "手机号码", "联系电话", "电子邮箱", "预付款", "备注", "状态"};
String title = "信息报表";
String title = "信息内容";
List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) {
for (Supplier s : dataList) {
@@ -561,7 +561,7 @@ public class SupplierService {
}
String[] names = {"名称", "联系人", "手机号码", "联系电话", "电子邮箱", "传真", beginNeedStr,
allNeedStr, "纳税人识别号", "税率(%)", "开户行", "账号", "地址", "备注", "状态"};
String title = "信息报表";
String title = "信息内容";
List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) {
for (Supplier s : dataList) {