Merge branch 'develop_master' into FOTON

This commit is contained in:
Superman_Main
2021-11-22 22:28:29 +08:00
4 changed files with 258 additions and 109 deletions
@@ -0,0 +1,189 @@
package com.adc.da.slrs.ImportExcelDatas.POIUtil;
import java.io.*;
import java.nio.file.Files;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZIPUtil {
private static final int BUFFER_SIZE = 2 * 1024;
/**
* 压缩成ZIP 方法1
* @param srcDir 压缩文件夹路径
* @param out 压缩文件输出流
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
* @throws RuntimeException 压缩失败会抛出运行时异常
*/
public static void toZip(String srcDir, OutputStream out, boolean KeepDirStructure)
throws RuntimeException{
// long start = System.currentTimeMillis();
ZipOutputStream zos = null ;
try {
zos = new ZipOutputStream(out);
File sourceFile = new File(srcDir);
compress(sourceFile,zos,sourceFile.getName(),KeepDirStructure);
// long end = System.currentTimeMillis();
} catch (Exception e) {
throw new RuntimeException("zip error from ZipUtils",e);
}finally{
if(zos != null){
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 压缩成ZIP 方法2
* @param srcFiles 需要压缩的文件列表
* @param out 压缩文件输出流
* @throws RuntimeException 压缩失败会抛出运行时异常
*/
public static void toZip(List<File> srcFiles , OutputStream out)throws RuntimeException {
// long start = System.currentTimeMillis();
ZipOutputStream zos = null ;
try {
zos = new ZipOutputStream(out);
for (File srcFile : srcFiles) {
byte[] buf = new byte[BUFFER_SIZE];
zos.putNextEntry(new ZipEntry(srcFile.getName()));
int len;
FileInputStream in = new FileInputStream(srcFile);
while ((len = in.read(buf)) != -1){
zos.write(buf, 0, len);
}
zos.closeEntry();
in.close();
}
// long end = System.currentTimeMillis();
} catch (Exception e) {
throw new RuntimeException("zip error from ZipUtils",e);
}finally{
if(zos != null){
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 递归压缩方法
* @param sourceFile 源文件
* @param zos zip输出流
* @param name 压缩后的名称
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
* @throws Exception
*/
private static void compress(File sourceFile, ZipOutputStream zos, String name,
boolean KeepDirStructure) throws Exception{
byte[] buf = new byte[BUFFER_SIZE];
if(sourceFile.isFile()){
// 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
zos.putNextEntry(new ZipEntry(name));
// copy文件到zip输出流中
int len;
FileInputStream in = new FileInputStream(sourceFile);
while ((len = in.read(buf)) != -1){
zos.write(buf, 0, len);
}
// Complete the entry
zos.closeEntry();
in.close();
} else {
File[] listFiles = sourceFile.listFiles();
if(listFiles == null || listFiles.length == 0){
// 需要保留原来的文件结构时,需要对空文件夹进行处理
if(KeepDirStructure){
// 空文件夹的处理
zos.putNextEntry(new ZipEntry(name + "/"));
// 没有文件,不需要文件的copy
zos.closeEntry();
}
}else {
for (File file : listFiles) {
// 判断是否需要保留原来的文件结构
if (KeepDirStructure) {
// 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
// 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
compress(file, zos, name + "/" + file.getName(),KeepDirStructure);
} else {
compress(file, zos, file.getName(),KeepDirStructure);
}
}
}
}
}
/**
* 根据java.nio.*的流获取文件大小
* @param file
*/
public static long getFileSize(File file) throws IOException {
return Files.walk(file.toPath())
.map(f -> f.toFile())
.filter(f -> f.isFile())
.mapToLong(f -> f.length()).sum();
}
}
@@ -2,6 +2,7 @@ package com.adc.da.slrs.ImportExcelDatas.controller;
import com.adc.da.base.web.BaseController;
import com.adc.da.common.ReadExcel;
import com.adc.da.slrs.ImportExcelDatas.POIUtil.ZIPUtil;
import com.adc.da.slrs.ImportExcelDatas.comment.*;
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
import com.adc.da.slrs.ImportExcelDatas.service.IImportStandExcelService;
@@ -12,15 +13,18 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.io.*;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -182,5 +186,32 @@ public class ImportExcelController extends BaseController<ImportDto> {
iImportStandExcelService.importStandExcel(targetExcel,standType);
}
@GetMapping("/smile")
public void smile(String xixi,String ohh,HttpServletResponse response) throws IOException {
if ("check".equals(ohh)){
File file = new File(xixi);
long fileSize = ZIPUtil.getFileSize(file);
response.setContentType("text/html;charset=UTF-8");
ServletOutputStream os = response.getOutputStream();
os.write(String.valueOf(fileSize).getBytes());
}else if("down".equals(ohh) ){
/** 3.设置response的header */
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=excel.zip");
ZIPUtil.toZip(xixi, response.getOutputStream(),true);
}
}
}
@@ -41,33 +41,7 @@ public class EarlyWarningEOServiceImpl extends ServiceImpl<EarlyWarningEODao, Ea
@Override
public IPage<EarlyWarningEO> newStandQuery(int current,int pageSize,EarlyWarningEO earlyWarningEO){
QueryWrapper<EarlyWarningEO> wrapper = new QueryWrapper<>();
//根据标准编号查询
if (earlyWarningEO.getStandCode() != null && earlyWarningEO.getStandCode().length() != 0){
wrapper.like("STAND_CODE",earlyWarningEO.getStandCode());
}
//根据标准名称查询
if (earlyWarningEO.getStandName() != null && earlyWarningEO.getStandName().length() != 0){
wrapper.like("STAND_NAME",earlyWarningEO.getStandName());
}
//根据实施日期查询
if (earlyWarningEO.getPutTime() != null ){
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
if (earlyWarningEO.getLastTime() != null){
wrapper.between("PUT_TIME",formater.format(earlyWarningEO.getPutTime()),formater.format(earlyWarningEO.getLastTime()));
}else {
wrapper.ge("PUT_TIME", formater.format(earlyWarningEO.getPutTime()));
}
}
if (earlyWarningEO.getLastTime()!=null){
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
wrapper.le("PUT_TIME", formater.format(earlyWarningEO.getLastTime()));
}
//根据适用车型查询
if (earlyWarningEO.getApplyType() != null && earlyWarningEO.getApplyType().length() != 0){
wrapper.like("APPLY_TYPE",earlyWarningEO.getApplyType());
}
selectMethods(earlyWarningEO, wrapper);
wrapper.eq("mark",1);
return getEarlyWarningEOIPage(current, pageSize, wrapper);
}
@@ -75,32 +49,7 @@ public class EarlyWarningEOServiceImpl extends ServiceImpl<EarlyWarningEODao, Ea
public IPage<EarlyWarningEO> oldStandQuery(int current,int pageSize,EarlyWarningEO earlyWarningEO){
QueryWrapper<EarlyWarningEO> wrapper = new QueryWrapper<>();
//根据标准编号查询
if (earlyWarningEO.getStandCode() != null && earlyWarningEO.getStandCode().length() != 0){
wrapper.like("STAND_CODE",earlyWarningEO.getStandCode());
}
//根据标准名称查询
if (earlyWarningEO.getStandName() != null && earlyWarningEO.getStandName().length() != 0){
wrapper.like("STAND_NAME",earlyWarningEO.getStandName());
}
//根据实施日期查询
if (earlyWarningEO.getPutTime() != null ){
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
if (earlyWarningEO.getLastTime() != null){
wrapper.between("PUT_TIME",formater.format(earlyWarningEO.getPutTime()),formater.format(earlyWarningEO.getLastTime()));
}else {
wrapper.ge("PUT_TIME", formater.format(earlyWarningEO.getPutTime()));
}
}
if (earlyWarningEO.getLastTime()!=null){
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
wrapper.le("PUT_TIME", formater.format(earlyWarningEO.getLastTime()));
}
//根据适用车型查询
if (earlyWarningEO.getApplyType() != null && earlyWarningEO.getApplyType().length() != 0){
wrapper.like("APPLY_TYPE",earlyWarningEO.getApplyType());
}
selectMethods(earlyWarningEO, wrapper);
wrapper.eq("mark",2);
return getEarlyWarningEOIPage(current, pageSize, wrapper);
}
@@ -108,32 +57,7 @@ public class EarlyWarningEOServiceImpl extends ServiceImpl<EarlyWarningEODao, Ea
public IPage<EarlyWarningEO> newItemsQuery(int current,int pageSize,EarlyWarningEO earlyWarningEO){
QueryWrapper<EarlyWarningEO> wrapper = new QueryWrapper<>();
//根据标准编号查询
if (earlyWarningEO.getStandCode() != null && earlyWarningEO.getStandCode().length() != 0){
wrapper.like("STAND_CODE",earlyWarningEO.getStandCode());
}
//根据标准名称查询
if (earlyWarningEO.getStandName() != null && earlyWarningEO.getStandName().length() != 0){
wrapper.like("STAND_NAME",earlyWarningEO.getStandName());
}
//根据实施日期查询
if (earlyWarningEO.getPutTime() != null ){
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
if (earlyWarningEO.getLastTime() != null){
wrapper.between("PUT_TIME",formater.format(earlyWarningEO.getPutTime()),formater.format(earlyWarningEO.getLastTime()));
}else {
wrapper.ge("PUT_TIME", formater.format(earlyWarningEO.getPutTime()));
}
}
if (earlyWarningEO.getLastTime()!=null){
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
wrapper.le("PUT_TIME", formater.format(earlyWarningEO.getLastTime()));
}
//根据适用车型查询
if (earlyWarningEO.getApplyType() != null && earlyWarningEO.getApplyType().length() != 0){
wrapper.like("APPLY_TYPE",earlyWarningEO.getApplyType());
}
selectMethods(earlyWarningEO, wrapper);
wrapper.eq("mark",3);
return getEarlyWarningEOIPage(current, pageSize, wrapper);
}
@@ -141,32 +65,7 @@ public class EarlyWarningEOServiceImpl extends ServiceImpl<EarlyWarningEODao, Ea
public IPage<EarlyWarningEO> oldItemsQuery(int current,int pageSize,EarlyWarningEO earlyWarningEO){
QueryWrapper<EarlyWarningEO> wrapper = new QueryWrapper<>();
//根据标准编号查询
if (earlyWarningEO.getStandCode() != null && earlyWarningEO.getStandCode().length() != 0){
wrapper.like("STAND_CODE",earlyWarningEO.getStandCode());
}
//根据标准名称查询
if (earlyWarningEO.getStandName() != null && earlyWarningEO.getStandName().length() != 0){
wrapper.like("STAND_NAME",earlyWarningEO.getStandName());
}
//根据实施日期查询
if (earlyWarningEO.getPutTime() != null ){
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
if (earlyWarningEO.getLastTime() != null){
wrapper.between("PUT_TIME",formater.format(earlyWarningEO.getPutTime()),formater.format(earlyWarningEO.getLastTime()));
}else {
wrapper.ge("PUT_TIME", formater.format(earlyWarningEO.getPutTime()));
}
}
if (earlyWarningEO.getLastTime()!=null){
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
wrapper.le("PUT_TIME", formater.format(earlyWarningEO.getLastTime()));
}
//根据适用车型查询
if (earlyWarningEO.getApplyType() != null && earlyWarningEO.getApplyType().length() != 0){
wrapper.like("APPLY_TYPE",earlyWarningEO.getApplyType());
}
selectMethods(earlyWarningEO, wrapper);
wrapper.eq("mark",4);
return getEarlyWarningEOIPage(current, pageSize, wrapper);
}
@@ -215,4 +114,34 @@ public class EarlyWarningEOServiceImpl extends ServiceImpl<EarlyWarningEODao, Ea
System.out.println("总页数"+userIPage.getPages());
return userIPage;
}
private void selectMethods(EarlyWarningEO earlyWarningEO, QueryWrapper<EarlyWarningEO> wrapper) {
//根据标准编号查询
if (earlyWarningEO.getStandCode() != null && earlyWarningEO.getStandCode().length() != 0) {
wrapper.like("STAND_CODE", earlyWarningEO.getStandCode());
}
//根据标准名称查询
if (earlyWarningEO.getStandName() != null && earlyWarningEO.getStandName().length() != 0) {
wrapper.like("STAND_NAME", earlyWarningEO.getStandName());
}
//根据实施日期查询
if (earlyWarningEO.getPutTime() != null) {
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
if (earlyWarningEO.getLastTime() != null) {
wrapper.between("PUT_TIME", formater.format(earlyWarningEO.getPutTime()), formater.format(earlyWarningEO.getLastTime()));
} else {
wrapper.ge("PUT_TIME", formater.format(earlyWarningEO.getPutTime()));
}
}
if (earlyWarningEO.getLastTime() != null) {
SimpleDateFormat formater = new SimpleDateFormat();
formater.applyPattern("yyyy-MM-dd");
wrapper.le("PUT_TIME", formater.format(earlyWarningEO.getLastTime()));
}
//根据适用车型查询
if (earlyWarningEO.getApplyType() != null && earlyWarningEO.getApplyType().length() != 0) {
wrapper.like("APPLY_TYPE", earlyWarningEO.getApplyType());
}
}
}
@@ -603,7 +603,7 @@
when 'HJ' THEN 7
ELSE 8
END,
sar_standards_info.stand_sort ASC,sar_standards_info.STAND_NUMBER ASC,sar_standards_info.STAND_YEAR DESC,sar_standards_info.id
sar_standards_info.stand_sort ASC,CAST(sar_standards_info.STAND_NUMBER AS DECIMAL) ASC,sar_standards_info.STAND_YEAR DESC,sar_standards_info.id
</if>
<if test='page.standType != null and page.standType == "FOREIGN"'>
CASE sar_standards_info.stand_sort
@@ -633,7 +633,7 @@
when 'ADR' THEN 23
ELSE 24
END,
sar_standards_info.stand_sort ASC,sar_standards_info.STAND_NUMBER ASC,sar_standards_info.STAND_YEAR DESC,sar_standards_info.id
sar_standards_info.stand_sort ASC,CAST(sar_standards_info.STAND_NUMBER AS DECIMAL) ASC,sar_standards_info.STAND_YEAR DESC,sar_standards_info.id
</if>
</sql>
<sql id="standSort_out">