浏览代码

修正 =====

linjinyu 4 年之前
父节点
当前提交
b4f2533716

+ 0 - 72
superdesk-libs-common/src/main/java/cn/superdesk/libs/common/unicrypt/MD5.java

@@ -1,72 +0,0 @@
-//package cn.superdesk.libs.common.unicrypt;
-//
-//import java.io.UnsupportedEncodingException;
-//import java.security.SignatureException;
-//
-//import org.apache.commons.codec.digest.DigestUtils;
-//
-//public class MD5 {
-//    /**
-//     * 签名字符??
-//     *
-//     * @param text          签名的字符串
-//     * @param key           密钥
-//     * @param input_charset 编码格式
-//     * @return 签名结果
-//     */
-//    public static String sign(String text, String key, String input_charset) {
-//        text = text + key;
-//        return DigestUtils.md5Hex(getContentBytes(text, input_charset));
-//    }
-//
-//    /**
-//     * 签名字符?
-//     *
-//     * @param text          签名的字符串
-//     * @param sign          签名结果
-//     * @param key           密钥
-//     * @param input_charset 编码格式
-//     * @return 签名结果
-//     */
-//    public static boolean verify(String text, String sign, String key, String input_charset) {
-//        text = text + key;
-//        String mysign = DigestUtils.md5Hex(getContentBytes(text, input_charset));
-//        if (mysign.equals(sign)) {
-//            return true;
-//        } else {
-//            return false;
-//        }
-//    }
-//
-//    /**
-//     * @param content
-//     * @param charset
-//     * @return
-//     * @throws SignatureException
-//     * @throws UnsupportedEncodingException
-//     */
-//    private static byte[] getContentBytes(String content, String charset) {
-//        if (charset == null || "".equals(charset)) {
-//            return content.getBytes();
-//        }
-//        try {
-//            return content.getBytes(charset);
-//        } catch (UnsupportedEncodingException e) {
-//            throw new RuntimeException("MD5签名过程中出现错??指定的编码集不对,您目前指定的编码集是:" + charset);
-//        }
-//    }
-//
-//    /**
-//     * 生成随机验证码
-//     *
-//     * @return
-//     */
-//    public static String createRandomVcode() {
-//        //验证码
-//        String vcode = "";
-//        for (int i = 0; i < 6; i++) {
-//            vcode = vcode + (int) (Math.random() * 9);
-//        }
-//        return vcode;
-//    }
-//}

+ 92 - 86
superdesk-libs-common2/pom.xml

@@ -1,98 +1,104 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>cn.superdesk.libs</groupId>
-		<artifactId>superdesk-libs</artifactId>
-		<version>1.3.1-SNAPSHOT</version>
-	</parent>
-	<artifactId>superdesk-libs-common2</artifactId>
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>cn.superdesk.libs</groupId>
+        <artifactId>superdesk-libs</artifactId>
+        <version>1.3.1-SNAPSHOT</version>
+    </parent>
+    <artifactId>superdesk-libs-common2</artifactId>
 
-	<dependencies>
-		<dependency>
-			<groupId>cn.superdesk.libs</groupId>
-			<artifactId>superdesk-libs-common</artifactId>
-			<version>${project.parent.version}</version>
-		</dependency>
+    <dependencies>
+        <dependency>
+            <groupId>cn.superdesk.libs</groupId>
+            <artifactId>superdesk-libs-common</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
 
-		<dependency>
-			<groupId>cn.superdesk.libs</groupId>
-			<artifactId>superdesk-libs-cache</artifactId>
-			<version>${project.parent.version}</version>
-			<optional>true</optional>
-		</dependency>
+        <dependency>
+            <groupId>cn.superdesk.libs</groupId>
+            <artifactId>superdesk-libs-cache</artifactId>
+            <version>${project.parent.version}</version>
+            <optional>true</optional>
+        </dependency>
 
-		<dependency>
-			<groupId>org.apache.poi</groupId>
-			<artifactId>poi</artifactId>
-			<version>3.15</version>
-			<optional>true</optional>
-		</dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>3.15</version>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>3.15</version>
+            <optional>true</optional>
+        </dependency>
 
-		<dependency>
-			<groupId>org.apache.poi</groupId>
-			<artifactId>poi-ooxml</artifactId>
-			<version>3.15</version>
-			<optional>true</optional>
-		</dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml-schemas</artifactId>
+            <version>3.15</version>
+            <optional>true</optional>
+        </dependency>
 
-		<dependency>
-			<groupId>org.apache.poi</groupId>
-			<artifactId>poi-ooxml-schemas</artifactId>
-			<version>3.15</version>
-			<optional>true</optional>
-		</dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.1</version>
+            <optional>true</optional>
+        </dependency>
 
-		<dependency>
-			<groupId>org.apache.commons</groupId>
-			<artifactId>commons-collections4</artifactId>
-			<version>4.1</version>
-			<optional>true</optional>
-		</dependency>
+        <dependency>
+            <groupId>org.apache.zookeeper</groupId>
+            <artifactId>zookeeper</artifactId>
+            <version>3.4.9</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>javax.jms</groupId>
+                    <artifactId>jms</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.jdmk</groupId>
+                    <artifactId>jmxtools</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.jmx</groupId>
+                    <artifactId>jmxri</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+            </exclusions>
+            <optional>true</optional>
+        </dependency>
 
-		<dependency>
-			<groupId>org.apache.zookeeper</groupId>
-			<artifactId>zookeeper</artifactId>
-			<version>3.4.9</version>
-			<exclusions>
-				<exclusion>
-					<groupId>javax.jms</groupId>
-					<artifactId>jms</artifactId>
-				</exclusion>
-				<exclusion>
-					<groupId>com.sun.jdmk</groupId>
-					<artifactId>jmxtools</artifactId>
-				</exclusion>
-				<exclusion>
-					<groupId>com.sun.jmx</groupId>
-					<artifactId>jmxri</artifactId>
-				</exclusion>
-				<exclusion>
-					<groupId>org.slf4j</groupId>
-					<artifactId>slf4j-log4j12</artifactId>
-				</exclusion>
-			</exclusions>
-			<optional>true</optional>
-		</dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.6</version>
+            <scope>test</scope>
+        </dependency>
 
-		<dependency>
-			<groupId>commons-io</groupId>
-			<artifactId>commons-io</artifactId>
-			<version>2.6</version>
-			<scope>test</scope>
-		</dependency>
+        <dependency>
+            <groupId>net.sf.json-lib</groupId>
+            <artifactId>json-lib</artifactId>
+            <version>2.4</version>
+            <classifier>jdk15</classifier><!--指定jdk版本-->
+        </dependency>
 
-	</dependencies>
+    </dependencies>
 
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-deploy-plugin</artifactId>
-				<configuration>
-					<skip>false</skip>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-deploy-plugin</artifactId>
+                <configuration>
+                    <skip>false</skip>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

+ 22 - 0
superdesk-libs-common2/src/main/java/cn/superdesk/libs/common2/excel/ExcelWriter.java

@@ -98,22 +98,31 @@ public final class ExcelWriter implements Closeable {
     public <T> boolean write(List<T> list, Class<T> clazz) {
 
         ExcelMeta excelMeta = ExcelBeanHelper.getExcelMeta(clazz);
+
         try {
+
             Sheet sheet = workbook.createSheet(this.sheetName);
             sheet.setDefaultColumnWidth(15);
+
             CellStyle titleStyle = workbook.createCellStyle();
+
             titleStyle.setAlignment(HorizontalAlignment.CENTER);
             titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
             titleStyle.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
             titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
             titleStyle.setBorderBottom(BorderStyle.THIN); //下边框
             titleStyle.setBorderLeft(BorderStyle.THIN);
+
             Font font = workbook.createFont();
+
             font.setFontName("宋体");
             font.setFontHeightInPoints((short) 13);
+
             titleStyle.setFont(font);
+
             //列值类型
             Class<?>[] cellValueTypes = new Class<?>[excelMeta.getTitleColumnNum()];
+
             //写标题
             for (int i = 1; i <= excelMeta.getTitleRowNum(); i++) {
                 Row excelRow = sheet.createRow(i - 1);
@@ -125,6 +134,7 @@ public final class ExcelWriter implements Closeable {
                     cellValueTypes[j - 1] = titleMeta.getValueType();
                 }
             }
+
             //合并表头
             //sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 8));
             //sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
@@ -133,11 +143,13 @@ public final class ExcelWriter implements Closeable {
 
             // 行数
             int rowsCount = sheet.getPhysicalNumberOfRows();
+
             //冻结表头
             //sheet.createFreezePane(0, rowsCount - 1);
 
             // 写入内容
             List<Object[]> rows = ExcelBeanHelper.beanToExcelValueArrays(list, clazz);
+
             // 列数
             //int colsCount = sheet.getRow(0).getPhysicalNumberOfCells();
             for (int i = 0; i < rows.size(); i++) {
@@ -157,14 +169,17 @@ public final class ExcelWriter implements Closeable {
                     }
                 }
             }
+
             workbook.write(outputStream);
             return true;
+
         } catch (IOException e) {
             LOG.error("流异常", e);
         } catch (Exception e) {
             LOG.error("其他异常", e);
         } finally {
         }
+
         return false;
     }
 
@@ -173,6 +188,7 @@ public final class ExcelWriter implements Closeable {
      * 合并列
      */
     private void mergeColumns(Sheet sheet, CellStyle cellStyle) {
+
         // 行数
         int rowsCount = sheet.getPhysicalNumberOfRows();
         // 列数
@@ -186,12 +202,15 @@ public final class ExcelWriter implements Closeable {
 
         for (int r = 0; r < rowsCount; r++) {
             row = sheet.getRow(r);
+
             // 重置
             colSpan = 0;
             row = sheet.getRow(r);
             for (int c = 0; c < colsCount; c++) {
+
                 cell1 = row.getCell(c);
                 cell2 = row.getCell(c + 1);
+
                 if (cell1 == null) {// 如果当前单元格是空的,跳过,继续当前行的后一个单元格查找
                     if (c == colsCount - 1) {
                         break;
@@ -199,6 +218,7 @@ public final class ExcelWriter implements Closeable {
                         continue;
                     }
                 }
+
                 if (cell2 == null) {// 说明当前行已经到最后一个单元格了
                     if (colSpan >= 1) {// 判断colSpan是否大于等于1,大于1就要合并了
                         // 合并行中连续相同的值的单元格
@@ -206,6 +226,7 @@ public final class ExcelWriter implements Closeable {
                         break;
                     }
                 }
+
                 if (cell1 != null && cell2 != null) {
                     // 如果当前单元格和下一个单元格内容相同,那么colSpan加1
                     if (cell1.getStringCellValue().equals(cell2.getStringCellValue())) {
@@ -238,6 +259,7 @@ public final class ExcelWriter implements Closeable {
         Row      row         = null;
         Cell     cell        = null;
         String[] lastRowVals = new String[excelMeta.getTitleColumnNum()];
+
         for (int r = 0; r < excelMeta.getTitleRowNum(); r++) {
             for (int c = 0; c < excelMeta.getTitleColumnNum(); c++) {
                 row = sheet.getRow(r);

+ 9 - 8
superdesk-libs-common2/src/main/java/cn/superdesk/libs/common2/uniexcel/ExcelData.java

@@ -60,8 +60,8 @@
 //                    //获得当前行的开始列
 //                    int firstCellNum = row.getFirstCellNum();
 //                    //获得当前行的列数
-//                    int      lastCellNum = row.getLastCellNum();
-//                    String[] cells       = new String[row.getLastCellNum()];
+//                    int lastCellNum = row.getLastCellNum();
+//                    String[] cells = new String[row.getLastCellNum()];
 //                    //循环当前行
 //                    for (int cellNum = firstCellNum; cellNum < lastCellNum; cellNum++) {
 //                        Cell cell = row.getCell(cellNum);
@@ -82,11 +82,13 @@
 //     * @throws IOException
 //     */
 //    public static boolean checkFile(MultipartFile file) throws IOException {
+//
 //        //判断文件是否存在
 //        if (null == file) {
 //            log.error("文件不存在!");
 //            return false;
 //        }
+//
 //        //获得文件名
 //        String fileName = file.getOriginalFilename();
 //        //判断文件是否是excel文件
@@ -173,16 +175,16 @@
 //            result = sdf.format(date);
 //        } else if (cell.getCellStyle().getDataFormat() == 58) {
 //            // 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
-//            SimpleDateFormat sdf   = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
-//            double           value = cell.getNumericCellValue();
+//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+//            double value = cell.getNumericCellValue();
 //            Date date = org.apache.poi.ss.usermodel.DateUtil
 //                    .getJavaDate(value);
 //            result = sdf.format(date);
 //        } else {
-//            double        value  = cell.getNumericCellValue();
-//            CellStyle     style  = cell.getCellStyle();
+//            double value = cell.getNumericCellValue();
+//            CellStyle style = cell.getCellStyle();
 //            DecimalFormat format = new DecimalFormat();
-//            String        temp   = style.getDataFormatString();
+//            String temp = style.getDataFormatString();
 //            // 单元格设置成常规
 //            if (temp.equals("General")) {
 //                format.applyPattern("#");
@@ -193,5 +195,4 @@
 //        return result;
 //    }
 //
-//
 //}

文件差异内容过多而无法显示
+ 566 - 448
superdesk-libs-common2/src/main/java/cn/superdesk/libs/common2/uniexcel/ExcelUtils.java