diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/MaterialService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/MaterialService.java index 87fd0457..34ed6105 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/MaterialService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/MaterialService.java @@ -513,28 +513,28 @@ public class MaterialService { } String[] names = StringUtil.listToStringArray(nameList); String title = "商品信息"; - List objects = new ArrayList<>(); + List objects = new ArrayList<>(); if (null != dataList) { for (MaterialVo4Unit m : dataList) { - String[] objs = new String[names.length]; + Object[] objs = new Object[names.length]; objs[0] = m.getName(); objs[1] = m.getStandard(); objs[2] = m.getModel(); objs[3] = m.getColor(); objs[4] = m.getBrand(); objs[5] = m.getCategoryName(); - objs[6] = m.getWeight() == null ? "" : m.getWeight().setScale(3, BigDecimal.ROUND_HALF_UP).toString(); - objs[7] = m.getExpiryNum() == null ? "" : m.getExpiryNum().toString(); + objs[6] = m.getWeight() == null ? "" : m.getWeight().setScale(3, BigDecimal.ROUND_HALF_UP); + objs[7] = m.getExpiryNum() == null ? "" : m.getExpiryNum(); objs[8] = m.getCommodityUnit(); objs[9] = otherMaterialMap.get(m.getId()) == null ? "" : otherMaterialMap.get(m.getId()).getCommodityUnit(); objs[10] = m.getmBarCode(); objs[11] = otherMaterialMap.get(m.getId()) == null ? "" : otherMaterialMap.get(m.getId()).getBarCode(); - objs[12] = m.getRatio() == null ? "" : m.getRatio().toString(); + objs[12] = m.getRatio() == null ? "" : m.getRatio(); objs[13] = m.getSku(); - objs[14] = m.getPurchaseDecimal() == null ? "" : m.getPurchaseDecimal().setScale(3, BigDecimal.ROUND_HALF_UP).toString(); - objs[15] = m.getCommodityDecimal() == null ? "" : m.getCommodityDecimal().setScale(3, BigDecimal.ROUND_HALF_UP).toString(); - objs[16] = m.getWholesaleDecimal() == null ? "" : m.getWholesaleDecimal().setScale(3, BigDecimal.ROUND_HALF_UP).toString(); - objs[17] = m.getLowDecimal() == null ? "" : m.getLowDecimal().setScale(3, BigDecimal.ROUND_HALF_UP).toString(); + objs[14] = m.getPurchaseDecimal() == null ? "" : m.getPurchaseDecimal().setScale(3, BigDecimal.ROUND_HALF_UP); + objs[15] = m.getCommodityDecimal() == null ? "" : m.getCommodityDecimal().setScale(3, BigDecimal.ROUND_HALF_UP); + objs[16] = m.getWholesaleDecimal() == null ? "" : m.getWholesaleDecimal().setScale(3, BigDecimal.ROUND_HALF_UP); + objs[17] = m.getLowDecimal() == null ? "" : m.getLowDecimal().setScale(3, BigDecimal.ROUND_HALF_UP); objs[18] = m.getEnabled() ? "1" : "0"; objs[19] = m.getEnableSerialNumber(); objs[20] = m.getEnableBatchNumber(); @@ -548,7 +548,7 @@ public class MaterialService { int i = 27; 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(); + objs[i] = number == null ? BigDecimal.ZERO : number.setScale(2, BigDecimal.ROUND_HALF_UP); i++; } objects.add(objs); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/SupplierService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/SupplierService.java index 4466c6ac..055c9ec6 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/SupplierService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/SupplierService.java @@ -559,10 +559,10 @@ public class SupplierService { //会员 String[] names = {"会员卡号*", "联系人", "手机号码", "联系电话", "电子邮箱", "备注", "排序", "状态*"}; String title = "信息内容"; - List objects = new ArrayList(); + List objects = new ArrayList<>(); if (null != dataList) { for (Supplier s : dataList) { - String[] objs = new String[names.length]; + Object[] objs = new Object[names.length]; objs[0] = s.getSupplier(); objs[1] = s.getContacts(); objs[2] = s.getTelephone(); @@ -588,10 +588,10 @@ public class SupplierService { String[] names = {"名称*", "联系人", "手机号码", "联系电话", "电子邮箱", "传真", beginNeedStr, "纳税人识别号", "税率(%)", "开户行", "账号", "地址", "备注", "排序", "状态*"}; String title = "信息内容"; - List objects = new ArrayList(); + List objects = new ArrayList<>(); if (null != dataList) { for (Supplier s : dataList) { - String[] objs = new String[names.length]; + Object[] objs = new Object[names.length]; objs[0] = s.getSupplier(); objs[1] = s.getContacts(); objs[2] = s.getTelephone(); @@ -599,12 +599,12 @@ public class SupplierService { objs[4] = s.getEmail(); objs[5] = s.getFax(); if(("客户").equals(s.getType())) { - objs[6] = s.getBeginNeedGet() == null? "" : s.getBeginNeedGet().setScale(2,BigDecimal.ROUND_HALF_UP).toString(); + objs[6] = s.getBeginNeedGet() == null? "" : s.getBeginNeedGet().setScale(2,BigDecimal.ROUND_HALF_UP); } else if(("供应商").equals(s.getType())) { - objs[6] = s.getBeginNeedPay() == null? "" : s.getBeginNeedPay().setScale(2,BigDecimal.ROUND_HALF_UP).toString(); + objs[6] = s.getBeginNeedPay() == null? "" : s.getBeginNeedPay().setScale(2,BigDecimal.ROUND_HALF_UP); } objs[7] = s.getTaxNum(); - objs[8] = s.getTaxRate() == null? "" : s.getTaxRate().setScale(2,BigDecimal.ROUND_HALF_UP).toString(); + objs[8] = s.getTaxRate() == null? "" : s.getTaxRate().setScale(2,BigDecimal.ROUND_HALF_UP); objs[9] = s.getBankName(); objs[10] = s.getAccountNumber(); objs[11] = s.getAddress(); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/SystemConfigService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/SystemConfigService.java index 852fb85f..3bfe86c8 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/SystemConfigService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/SystemConfigService.java @@ -648,14 +648,14 @@ public class SystemConfigService { public void exportExcelByParam(String title, String head, String tip, JSONArray arr, HttpServletResponse response) throws Exception { List nameList = StringUtil.strToStringList(head); String[] names = StringUtil.listToStringArray(nameList); - List objects = new ArrayList<>(); + List objects = new ArrayList<>(); if (null != arr) { for (Object object: arr) { List list = (List) object; - String[] objs = new String[names.length]; + Object[] objs = new Object[names.length]; for (int i = 0; i < list.size(); i++) { if(null != list.get(i)) { - objs[i] = list.get(i).toString(); + objs[i] = list.get(i); } } objects.add(objs); 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 961fed7a..2a3ab971 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 @@ -1,7 +1,7 @@ package com.jsh.erp.utils; import java.io.*; -import java.text.SimpleDateFormat; +import java.math.BigDecimal; import java.util.*; import jxl.*; @@ -110,8 +110,9 @@ public class ExcelUtils { * @return * @throws Exception */ + public static File exportObjectsOneSheet(String fileName, String tip, - String[] names, String title, List objects) throws Exception { + String[] names, String title, List objects) throws Exception { File excelFile = new File("/opt/"+ fileName); WritableWorkbook wtwb = Workbook.createWorkbook(excelFile); WritableSheet sheet = wtwb.createSheet(title, 0); @@ -157,9 +158,16 @@ public class ExcelUtils { // 其余行依次写入数据 int rowNum = 2; for (int j = 0; j < objects.size(); j++) { - String[] obj = objects.get(j); + Object[] obj = objects.get(j); for (int h = 0; h < obj.length; h++) { - sheet.addCell(new Label(h, rowNum, obj[h], format)); + if(obj[h] instanceof String) { + sheet.addCell(new Label(h, rowNum, obj[h].toString(), format)); + } else if(obj[h] instanceof BigDecimal || obj[h] instanceof Double || obj[h] instanceof Integer || obj[h] instanceof Long) { + sheet.addCell(new jxl.write.Number(h, rowNum, Double.parseDouble(obj[h].toString()), format)); + } else { + String cont = obj[h]!=null?obj[h].toString():""; + sheet.addCell(new Label(h, rowNum, cont, format)); + } } rowNum = rowNum + 1; }