From 18140dea12e4354b961d742a03dbd3c378472991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Thu, 20 Apr 2023 00:49:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=8C=89=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E7=9A=84=E6=A0=BC=E5=BC=8F=E6=8E=92=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jshERP-boot/pom.xml | 5 - .../erp/controller/MaterialController.java | 6 - .../mappers/MaterialInitialStockMapperEx.java | 2 + .../erp/service/material/MaterialService.java | 134 +++++++----------- .../java/com/jsh/erp/utils/ExcelUtils.java | 10 +- .../src/main/resources/application.properties | 6 +- .../MaterialInitialStockMapperEx.xml | 5 + 7 files changed, 68 insertions(+), 100 deletions(-) diff --git a/jshERP-boot/pom.xml b/jshERP-boot/pom.xml index dbc3df739..a28c25b44 100644 --- a/jshERP-boot/pom.xml +++ b/jshERP-boot/pom.xml @@ -63,11 +63,6 @@ jxl 2.6.12 - - com.alibaba - easyexcel - 3.2.1 - org.projectlombok diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java index 2f5126474..d379d19a0 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java @@ -1,6 +1,5 @@ package com.jsh.erp.controller; -import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jsh.erp.datasource.entities.MaterialVo4Unit; @@ -8,25 +7,20 @@ import com.jsh.erp.datasource.entities.Unit; import com.jsh.erp.service.depot.DepotService; import com.jsh.erp.service.depotItem.DepotItemService; import com.jsh.erp.service.material.MaterialService; -import com.jsh.erp.service.redis.RedisService; import com.jsh.erp.service.unit.UnitService; import com.jsh.erp.utils.BaseResponseInfo; import com.jsh.erp.utils.ErpInfo; -import com.jsh.erp.utils.ExcelUtils; import com.jsh.erp.utils.StringUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.InputStream; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialInitialStockMapperEx.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialInitialStockMapperEx.java index 41868c63f..76ff7c90a 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialInitialStockMapperEx.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialInitialStockMapperEx.java @@ -11,4 +11,6 @@ public interface MaterialInitialStockMapperEx { int batchInsert(List list); + List getListExceptZero(); + } \ No newline at end of file diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java index 87958112c..ce4d1389a 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java @@ -1,6 +1,5 @@ package com.jsh.erp.service.material; -import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -36,7 +35,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; -import java.io.InputStream; import java.math.BigDecimal; import java.util.*; @@ -79,15 +77,6 @@ public class MaterialService { @Resource private MaterialExtendService materialExtendService; - @Value("${server.tomcat.basedir}") - private String basedir; - - @Value("${template.path}") - private String templatePath; - - @Value("${export.mode}") - private Integer exportMode; - public Material getMaterial(long id)throws Exception { Material result=null; try{ @@ -475,10 +464,6 @@ public class MaterialService { public void exportExcel(String categoryId, String materialParam, String color, String weight, String expiryNum, String enabled, String enableSerialNumber, String enableBatchNumber, String remark, String mpList, HttpServletResponse response)throws Exception { - String[] mpArr = new String[]{}; - if(StringUtil.isNotEmpty(mpList)){ - mpArr= mpList.split(","); - } List idList = new ArrayList<>(); if(StringUtil.isNotEmpty(categoryId)){ idList = getListByParentId(Long.parseLong(categoryId)); @@ -492,74 +477,61 @@ public class MaterialService { for(MaterialExtend me: otherDataList) { otherMaterialMap.put(me.getMaterialId(), me); } - if(exportMode == 0) { - String[] names = {"名称*", "规格", "型号", "颜色", "类别", "基础重量(kg)", "保质期(天)", "基本单位*", "副单位", "基本条码*", - "副条码", "比例", "采购价", "零售价", "销售价", "最低售价", "状态*", "序列号", "批号", "备注"}; - String title = "商品信息"; - List objects = new ArrayList<>(); - if (null != dataList) { - for (MaterialVo4Unit m : dataList) { - String[] objs = new String[100]; - objs[0] = m.getName(); - objs[1] = m.getStandard(); - objs[2] = m.getModel(); - objs[3] = m.getColor(); - objs[4] = m.getCategoryName(); - objs[5] = m.getWeight() == null ? "" : m.getWeight().setScale(3, BigDecimal.ROUND_HALF_UP).toString(); - objs[6] = m.getExpiryNum() == null ? "" : m.getExpiryNum().toString(); - objs[7] = m.getCommodityUnit(); - objs[8] = otherMaterialMap.get(m.getId()) == null ? "": otherMaterialMap.get(m.getId()).getCommodityUnit(); - objs[9] = m.getmBarCode(); - objs[10] = otherMaterialMap.get(m.getId()) == null ? "": otherMaterialMap.get(m.getId()).getBarCode(); - objs[11] = m.getRatio() == null ? "" : m.getRatio().toString(); - objs[12] = m.getPurchaseDecimal() == null ? "" : m.getPurchaseDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); - objs[13] = m.getCommodityDecimal() == null ? "" : m.getCommodityDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); - objs[14] = m.getWholesaleDecimal() == null ? "" : m.getWholesaleDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); - objs[15] = m.getLowDecimal() == null ? "" : m.getLowDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); - objs[16] = m.getEnabled() ? "1" : "0"; - objs[17] = m.getEnableSerialNumber(); - objs[18] = m.getEnableBatchNumber(); - objs[19] = m.getRemark(); - objects.add(objs); - } + String nameStr = "名称*,规格,型号,颜色,类别,基础重量(kg),保质期(天),基本单位*,副单位,基本条码*,副条码,比例,采购价,零售价,销售价,最低售价,状态*,序列号,批号,备注"; + List nameList = StringUtil.strToStringList(nameStr); + //仓库列表 + List depotList = depotService.getAllList(); + if (nameList != null) { + for(Depot depot: depotList) { + nameList.add(depot.getName()); } - File file = ExcelUtils.exportObjectsWithoutTitle(title, "导入时本行内容请勿删除,切记!", names, title, objects); - ExcelUtils.downloadExcel(file, file.getName(), response); - } else { - List> objects = new ArrayList<>(); - if (null != dataList) { - for (MaterialVo4Unit m : dataList) { - Map map = new HashMap<>(); - map.put(0, m.getName()); - map.put(1, m.getStandard()); - map.put(2, m.getModel()); - map.put(3, m.getColor()); - map.put(4, m.getCategoryName()); - map.put(5, m.getWeight() == null ? "" : m.getWeight().setScale(3, BigDecimal.ROUND_HALF_UP).toString()); - map.put(6, m.getExpiryNum() == null ? "" : m.getExpiryNum().toString()); - map.put(7, m.getCommodityUnit()); - map.put(8, otherMaterialMap.get(m.getId()) == null ? "": otherMaterialMap.get(m.getId()).getCommodityUnit()); - map.put(9, m.getmBarCode()); - map.put(10, otherMaterialMap.get(m.getId()) == null ? "": otherMaterialMap.get(m.getId()).getBarCode()); - map.put(11, m.getRatio() == null ? "" : m.getRatio().toString()); - map.put(12, m.getPurchaseDecimal() == null ? "" : m.getPurchaseDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString()); - map.put(13, m.getCommodityDecimal() == null ? "" : m.getCommodityDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString()); - map.put(14, m.getWholesaleDecimal() == null ? "" : m.getWholesaleDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString()); - map.put(15, m.getLowDecimal() == null ? "" : m.getLowDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString()); - map.put(16, m.getEnabled() ? "1" : "0"); - map.put(17, m.getEnableSerialNumber()); - map.put(18, m.getEnableBatchNumber()); - map.put(19, m.getRemark()); - objects.add(map); - } - } - String fileName = "商品信息.xls"; - String pathFile = basedir + File.separator + fileName; - InputStream path = ExcelUtils.getPathByFileName(templatePath, "goods_template_export.xls"); - EasyExcel.write(pathFile).withTemplate(path).sheet(0).needHead(Boolean.FALSE).doWrite(objects); - File file = new File(basedir, fileName); - ExcelUtils.downloadExcel(file, fileName, response); } + //期初库存缓存 + List misList = materialInitialStockMapperEx.getListExceptZero(); + Map misMap = new HashMap<>(); + if (misList != null) { + for (MaterialInitialStock mis : misList) { + misMap.put(mis.getMaterialId() + "_" + mis.getDepotId(), mis.getNumber()); + } + } + String[] names = StringUtil.listToStringArray(nameList); + String title = "商品信息"; + List objects = new ArrayList<>(); + if (null != dataList) { + for (MaterialVo4Unit m : dataList) { + String[] objs = new String[100]; + objs[0] = m.getName(); + objs[1] = m.getStandard(); + objs[2] = m.getModel(); + objs[3] = m.getColor(); + objs[4] = m.getCategoryName(); + objs[5] = m.getWeight() == null ? "" : m.getWeight().setScale(3, BigDecimal.ROUND_HALF_UP).toString(); + objs[6] = m.getExpiryNum() == null ? "" : m.getExpiryNum().toString(); + objs[7] = m.getCommodityUnit(); + objs[8] = otherMaterialMap.get(m.getId()) == null ? "" : otherMaterialMap.get(m.getId()).getCommodityUnit(); + objs[9] = m.getmBarCode(); + objs[10] = otherMaterialMap.get(m.getId()) == null ? "" : otherMaterialMap.get(m.getId()).getBarCode(); + objs[11] = m.getRatio() == null ? "" : m.getRatio().toString(); + objs[12] = m.getPurchaseDecimal() == null ? "" : m.getPurchaseDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); + objs[13] = m.getCommodityDecimal() == null ? "" : m.getCommodityDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); + objs[14] = m.getWholesaleDecimal() == null ? "" : m.getWholesaleDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); + objs[15] = m.getLowDecimal() == null ? "" : m.getLowDecimal().setScale(2, BigDecimal.ROUND_HALF_UP).toString(); + objs[16] = m.getEnabled() ? "1" : "0"; + objs[17] = m.getEnableSerialNumber(); + objs[18] = m.getEnableBatchNumber(); + objs[19] = m.getRemark(); + //仓库期初库存 + int i = 20; + for(Depot depot: depotList) { + BigDecimal number = misMap.get(m.getId() + "_" + depot.getId()); + objs[i] = number == null ? "0" : number.setScale(2, BigDecimal.ROUND_HALF_UP).toString(); + i++; + } + objects.add(objs); + } + } + File file = ExcelUtils.exportObjectsWithoutTitle(title, "导入时本行内容请勿删除,切记!", names, title, objects); + ExcelUtils.downloadExcel(file, file.getName(), response); } @Transactional(value = "transactionManager", rollbackFor = Exception.class) diff --git a/jshERP-boot/src/main/java/com/jsh/erp/utils/ExcelUtils.java b/jshERP-boot/src/main/java/com/jsh/erp/utils/ExcelUtils.java index 5cc47e934..512021435 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/utils/ExcelUtils.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/utils/ExcelUtils.java @@ -49,23 +49,27 @@ public class ExcelUtils { File excelFile = new File(fileName); WritableWorkbook wtwb = Workbook.createWorkbook(excelFile); WritableSheet sheet = wtwb.createSheet(title, 0); - sheet.getSettings().setDefaultColumnWidth(20); + sheet.getSettings().setDefaultColumnWidth(12); // 标题的格式 - WritableFont wfc = new WritableFont(WritableFont.ARIAL, 15, + WritableFont wfc = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); WritableCellFormat wcfFC = new WritableCellFormat(wfc); wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE); + //设置边框 + wcfFC.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN); + // 设置字体以及单元格格式 - WritableFont wfont = new WritableFont(WritableFont.createFont("楷书"), 15); + WritableFont wfont = new WritableFont(WritableFont.createFont("楷书"), 12); WritableCellFormat format = new WritableCellFormat(wfont); format.setAlignment(Alignment.LEFT); format.setVerticalAlignment(VerticalAlignment.TOP); // 第一行写入提示 sheet.addCell(new Label(0, 0, tip, wcfFC)); + // 第二行写入标题 for (int i = 0; i < names.length; i++) { sheet.addCell(new Label(i, 1, names[i], wcfFC)); diff --git a/jshERP-boot/src/main/resources/application.properties b/jshERP-boot/src/main/resources/application.properties index 706ea47ae..c8a57b747 100644 --- a/jshERP-boot/src/main/resources/application.properties +++ b/jshERP-boot/src/main/resources/application.properties @@ -30,8 +30,4 @@ file.path=/opt/jshERP/upload server.tomcat.basedir=/opt/tmp/tomcat #文件上传限制(byte) spring.servlet.multipart.max-file-size=10485760 -spring.servlet.multipart.max-request-size=10485760 -#模板路径 -template.path=/home/jshERP/jshERP-web/public/doc -#导出方式 0-不带模板(默认) 1-带模板 -export.mode=0 \ No newline at end of file +spring.servlet.multipart.max-request-size=10485760 \ No newline at end of file diff --git a/jshERP-boot/src/main/resources/mapper_xml/MaterialInitialStockMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/MaterialInitialStockMapperEx.xml index a55a6e4e7..a552505a9 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/MaterialInitialStockMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/MaterialInitialStockMapperEx.xml @@ -10,4 +10,9 @@ + + \ No newline at end of file