作者 shenhailong

添加 列表查询 主单号—— 工具类 +不+ - 问题

@@ -56,6 +56,42 @@ @@ -56,6 +56,42 @@
56 <version>1.18.10</version> 56 <version>1.18.10</version>
57 <scope>compile</scope> 57 <scope>compile</scope>
58 </dependency> 58 </dependency>
  59 +
  60 + <!--excel 导入所需要的包 -->
  61 + <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
  62 + <dependency>
  63 + <groupId>org.apache.poi</groupId>
  64 + <artifactId>poi</artifactId>
  65 + <version>3.6</version>
  66 + </dependency>
  67 + <dependency>
  68 + <groupId>org.apache.poi</groupId>
  69 + <artifactId>poi-ooxml</artifactId>
  70 + <version>3.17</version>
  71 + </dependency>
  72 +
  73 + <dependency>
  74 + <groupId>org.springframework</groupId>
  75 + <artifactId>spring-context</artifactId>
  76 + <version>4.2.4.RELEASE</version>
  77 + </dependency>
  78 +
  79 +
  80 +
  81 +
  82 + <dependency>
  83 + <groupId>org.springframework</groupId>
  84 + <artifactId>spring-web</artifactId>
  85 + <version>5.2.0.BUILD-SNAPSHOT</version>
  86 + <scope>compile</scope>
  87 + </dependency>
  88 + <dependency>
  89 + <groupId>org.springframework</groupId>
  90 + <artifactId>spring-web</artifactId>
  91 + <version>5.2.0.BUILD-SNAPSHOT</version>
  92 + <scope>compile</scope>
  93 + </dependency>
  94 +
59 </dependencies> 95 </dependencies>
60 96
61 <build> 97 <build>
  1 +package com.tianbo.util.ExcelUtils;
  2 +
  3 +
  4 +
  5 +import org.apache.commons.lang.StringUtils;
  6 +import org.apache.poi.hssf.usermodel.HSSFCell;
  7 +import org.apache.poi.hssf.usermodel.HSSFRow;
  8 +import org.apache.poi.hssf.usermodel.HSSFSheet;
  9 +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  10 +import org.apache.poi.ss.usermodel.Cell;
  11 +import org.apache.poi.xssf.usermodel.XSSFCell;
  12 +import org.apache.poi.xssf.usermodel.XSSFRow;
  13 +import org.apache.poi.xssf.usermodel.XSSFSheet;
  14 +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  15 +import org.springframework.web.multipart.MultipartFile;
  16 +
  17 +import java.io.InputStream;
  18 +import java.util.ArrayList;
  19 +import java.util.List;
  20 +
  21 +/**
  22 + * shenhailong
  23 + * 2020/4/27/14:29
  24 + */
  25 +public class ExcelUtils {
  26 +
  27 +
  28 +
  29 + /**
  30 + * 读取.xlsx 内容
  31 + * @param file
  32 + * @return
  33 + * @throws
  34 + */
  35 + public static List<ArrayList<String>> readXlsx (MultipartFile file) {
  36 + List<ArrayList<String>> list = new ArrayList<ArrayList<String>>();
  37 + InputStream input = null;
  38 + XSSFWorkbook wb = null;
  39 + try {
  40 + input = file.getInputStream();
  41 + //创建文档
  42 + wb = new XSSFWorkbook(input);
  43 + ArrayList<String> rowList = null;
  44 + int totoalRows = 0;//总行数
  45 + int totalCells = 0;//总列数
  46 + //读取sheet(页)
  47 + for (int sheetIndex = 0 ; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) {
  48 + XSSFSheet xssfSheet = wb.getSheetAt(sheetIndex);
  49 +
  50 + if (xssfSheet == null) {
  51 + continue;
  52 + }
  53 + totoalRows = xssfSheet.getLastRowNum();
  54 + //读取row
  55 + for (int rowIndex = 2; rowIndex <= totoalRows; rowIndex++) {
  56 + XSSFRow xssfRow = xssfSheet.getRow(rowIndex);
  57 +
  58 + if (xssfRow == null) {
  59 + continue;
  60 + }
  61 + rowList = new ArrayList<String>();
  62 + totalCells = xssfRow.getLastCellNum();
  63 +
  64 + //读取列
  65 + for (int cellIndex = 0; cellIndex < totalCells; cellIndex++) {
  66 + XSSFCell xssfCell = xssfRow.getCell(cellIndex);
  67 + if (xssfCell == null) {
  68 + rowList.add("");
  69 + } else {
  70 +// xssfCell.setCellType(Cell.CELL_TYPE_STRING);
  71 + rowList.add(String.valueOf(xssfCell.getStringCellValue()));
  72 + }
  73 + }
  74 +
  75 + list.add(rowList);
  76 +
  77 + }
  78 + }
  79 + } catch (Exception e) {
  80 + e.printStackTrace();
  81 + return null;
  82 + } finally {
  83 + try {
  84 + if ( wb != null) {
  85 + wb.close();
  86 + }
  87 + if (input != null) {
  88 + input.close();
  89 + }
  90 + } catch (Exception e) {
  91 + }
  92 + }
  93 +
  94 + return list;
  95 + }
  96 +
  97 +
  98 +
  99 + /**
  100 + * 读取 .xls内容
  101 + * @param file
  102 + * @return
  103 + * @throws
  104 + */
  105 + public static List<ArrayList<String>> readXls (MultipartFile file) {
  106 + List<ArrayList<String>> list = new ArrayList<ArrayList<String>>();
  107 +
  108 + //创建输入流
  109 + InputStream input = null;
  110 + //创建文档
  111 + HSSFWorkbook wb = null;
  112 +
  113 + try {
  114 + input = file.getInputStream();
  115 + //创建文档
  116 + wb = new HSSFWorkbook(input);
  117 +
  118 + ArrayList<String> rowList = null;
  119 + int totoalRows = 0;//总行数
  120 + int totalCells = 0;//总列数
  121 + //读取sheet(页)
  122 + for (int sheetIndex = 0 ; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) {
  123 + HSSFSheet hssfSheet = wb.getSheetAt(sheetIndex);
  124 +
  125 + if (hssfSheet == null) {
  126 + continue;
  127 + }
  128 +
  129 + totoalRows = hssfSheet.getLastRowNum();
  130 + //读取row
  131 + for (int rowIndex = 2; rowIndex <= totoalRows; rowIndex++) {
  132 + HSSFRow hssfRow = hssfSheet.getRow(rowIndex);
  133 +
  134 + if (hssfRow == null) {
  135 + continue;
  136 + }
  137 + rowList = new ArrayList<String>();
  138 + totalCells = hssfRow.getLastCellNum();
  139 +
  140 + //读取列
  141 + for (int cellIndex = 0; cellIndex < totalCells; cellIndex++) {
  142 + HSSFCell hssfCell = hssfRow.getCell(cellIndex);
  143 + if (hssfCell == null) {
  144 + rowList.add("");
  145 + } else {
  146 + hssfCell.setCellType(Cell.CELL_TYPE_STRING);
  147 + rowList.add(String.valueOf(hssfCell.getStringCellValue()));
  148 + }
  149 + }
  150 +
  151 + list.add(rowList);
  152 +
  153 + }
  154 + }
  155 + } catch (Exception e) {
  156 + e.printStackTrace();
  157 + return null;
  158 + } finally {
  159 + try {
  160 + if ( wb != null) {
  161 +// wb.close();
  162 + }
  163 + if (input != null) {
  164 + input.close();
  165 + }
  166 + } catch (Exception e) {
  167 + }
  168 + }
  169 + return list;
  170 + }
  171 +
  172 +
  173 + public static String getPostfix (String path) {
  174 + if (StringUtils.isBlank(path) || !path.contains(".")) {
  175 + return null;
  176 + }
  177 + return path.substring(path.lastIndexOf(".") + 1, path.length()).trim();
  178 + }
  179 +
  180 +}
  1 +package com.tianbo.util.WaybillUtils;
  2 +
  3 +/**
  4 + * shenhailong
  5 + * 2020/4/27/14:54
  6 + */
  7 +public class WaybillUtils {
  8 +
  9 +
  10 + // 主单添加 - 符号
  11 + public String awb(String waybill){
  12 + String awb = "";
  13 + if (waybill.contains("-")) {
  14 + awb = waybill;
  15 + } else {
  16 + String s1 = waybill;
  17 + String substring = s1.substring(0, 3);
  18 + String substring1 = s1.substring(3);
  19 + awb = substring + "-" + substring1;
  20 + }
  21 + return awb;
  22 + }
  23 +
  24 + // 判断是否符合模七校验
  25 + public boolean checkout(String waybill){
  26 +
  27 + String[] split = waybill.split("-");
  28 +
  29 + int number = Integer.parseInt(split[1]);
  30 +
  31 + int start = number/10;
  32 +
  33 + int remainder = start % 7;
  34 +
  35 + int last = number % 10;
  36 +
  37 + if (remainder!=last){
  38 + return false;
  39 + }else {
  40 + return true;
  41 + }
  42 +
  43 + }
  44 +
  45 +}