Commit 84d85755 authored by jiaorz's avatar jiaorz

Merge remote-tracking branch 'origin/base-modify' into base-modify

parents 5e32b907 887f28a7
...@@ -60,6 +60,18 @@ ...@@ -60,6 +60,18 @@
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
</dependency> </dependency>
<!--zip4j依赖,解压zip压缩-->
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
<!--解压rar压缩-->
<dependency>
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<version>0.7</version>
</dependency>
</dependencies> </dependencies>
......
package com.xxfc.platform.universal.constant.enumerate;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public enum FileTypeEnum {
FILE_TYPE_ZIP("application/zip", ".zip"),
FILE_TYPE_RAR("application/octet-stream", ".rar");
public String type;
public String fileStufix;
public static String getFileStufix(String type) {
for (FileTypeEnum orderTypeEnum : FileTypeEnum.values()) {
if (orderTypeEnum.type.equals(type)) {
return orderTypeEnum.fileStufix;
}
}
return null;
}
}
package com.xxfc.platform.universal.utils;
import com.github.junrar.Archive;
import com.github.junrar.rarfile.FileHeader;
import lombok.extern.slf4j.Slf4j;
import net.lingala.zip4j.core.ZipFile;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* 解压rar/zip工具类
*/
@Slf4j
public class UnPackeUtil {
/**
* zip文件解压
*
* @param destPath 解压文件路径
* @param zipFile 压缩文件
* @param password 解压密码(如果有)
*/
public static void unPackZip(File zipFile, String password, String destPath) {
try {
ZipFile zip = new ZipFile(zipFile);
/*zip4j默认用GBK编码去解压,这里设置编码为GBK的*/
zip.setFileNameCharset("GBK");
log.info("begin unpack zip file....");
zip.extractAll(destPath);
// 如果解压需要密码
if (zip.isEncrypted()) {
zip.setPassword(password);
}
} catch (Exception e) {
log.error("unPack zip file to " + destPath + " fail ....", e.getMessage(), e);
}
}
/**
* rar文件解压(不支持有密码的压缩包)
*
* @param rarFile rar压缩包
* @param destPath 解压保存路径
*/
public static void unPackRar(File rarFile, String destPath) {
try (Archive archive = new Archive(rarFile)) {
if (null != archive) {
FileHeader fileHeader = archive.nextFileHeader();
File file = null;
while (null != fileHeader) {
// 防止文件名中文乱码问题的处理
String fileName = fileHeader.getFileNameW().isEmpty() ? fileHeader.getFileNameString() : fileHeader.getFileNameW();
if (fileHeader.isDirectory()) {
//是文件夹
file = new File(destPath + File.separator + fileName);
file.mkdirs();
} else {
//不是文件夹
file = new File(destPath + File.separator + fileName.trim());
if (!file.exists()) {
if (!file.getParentFile().exists()) {
// 相对路径可能多级,可能需要创建父目录.
file.getParentFile().mkdirs();
}
file.createNewFile();
}
FileOutputStream os = new FileOutputStream(file);
archive.extractFile(fileHeader, os);
os.close();
}
fileHeader = archive.nextFileHeader();
}
}
} catch (Exception e) {
log.error("unpack rar file fail....", e.getMessage(), e);
}
}
}
\ No newline at end of file
...@@ -13,9 +13,9 @@ public class CommonConfig { ...@@ -13,9 +13,9 @@ public class CommonConfig {
public MultipartConfigElement multipartConfigElement() { public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory(); MultipartConfigFactory factory = new MultipartConfigFactory();
// 单个数据大小 // 单个数据大小
factory.setMaxFileSize("10240KB"); // KB,MB factory.setMaxFileSize("102400KB"); // KB,MB
/// 总上传数据大小 /// 总上传数据大小
factory.setMaxRequestSize("102400KB"); factory.setMaxRequestSize("502400KB");
return factory.createMultipartConfig(); return factory.createMultipartConfig();
} }
} }
\ No newline at end of file
...@@ -2,9 +2,11 @@ package com.xxfc.platform.universal.controller; ...@@ -2,9 +2,11 @@ package com.xxfc.platform.universal.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken; import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.result.JsonResultUtil; import com.github.wxiaoqi.security.common.util.result.JsonResultUtil;
import com.xxfc.platform.universal.dto.ImgDTO; import com.xxfc.platform.universal.dto.ImgDTO;
import com.xxfc.platform.universal.dto.UploadImgDTO; import com.xxfc.platform.universal.dto.UploadImgDTO;
import com.xxfc.platform.universal.service.FileUploadService;
import com.xxfc.platform.universal.service.UploadService; import com.xxfc.platform.universal.service.UploadService;
import com.xxfc.platform.universal.utils.ImgBase64Util; import com.xxfc.platform.universal.utils.ImgBase64Util;
import com.xxfc.platform.universal.utils.PublicMsg; import com.xxfc.platform.universal.utils.PublicMsg;
...@@ -38,6 +40,8 @@ public class UploadController{ ...@@ -38,6 +40,8 @@ public class UploadController{
@Autowired @Autowired
UploadService uploadService; UploadService uploadService;
@Autowired
FileUploadService fileUploadService;
private static Integer MAX_DRIVING_LICENSE_SIZE = 10 * 1024 * 1024;//10M private static Integer MAX_DRIVING_LICENSE_SIZE = 10 * 1024 * 1024;//10M
...@@ -158,5 +162,12 @@ public class UploadController{ ...@@ -158,5 +162,12 @@ public class UploadController{
ueditor.setTitle(upfile.getOriginalFilename()); ueditor.setTitle(upfile.getOriginalFilename());
return ueditor; return ueditor;
} }
@RequestMapping(value="/app/unauth/zip", method = RequestMethod.POST)
public ObjectRestResponse zip(
@RequestParam("file")MultipartFile upfile,
@RequestParam(value = "prefix",defaultValue = "renovate")String prefix) throws Exception {
return fileUploadService.handlerUpload(upfile,null,prefix);
}
} }
package com.xxfc.platform.universal.service;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import org.springframework.web.multipart.MultipartFile;
public interface FileUploadService {
public ObjectRestResponse handlerUpload(MultipartFile zipFile,String password,String prefix)throws Exception;
}
...@@ -23,7 +23,7 @@ import java.util.UUID; ...@@ -23,7 +23,7 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Service @Service
public class UploadService { public class UploadService {
public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd"); public static final DateTimeFormatter DEFAULT_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
@Value("${universal.baseUploadPath}") @Value("${universal.baseUploadPath}")
......
package com.xxfc.platform.universal.service.impl;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.xxfc.platform.universal.constant.enumerate.FileTypeEnum;
import com.xxfc.platform.universal.service.FileUploadService;
import com.xxfc.platform.universal.utils.UnPackeUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
@Service
@Slf4j
public class FileUploadServiceImpl implements FileUploadService {
@Value("${universal.uploadPath}")
private String uploadPath ;
@Value("${universal.url}")
private String xx_url ;
@Override
public ObjectRestResponse handlerUpload(MultipartFile zipFile,String password,String prefix)throws Exception {
if (null == zipFile) {
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"请上传压缩文件!");
}
boolean isZipPack = true;
String fileContentType = zipFile.getContentType();
//将压缩包保存在指定路径
String packFilePath = uploadPath + File.separator + zipFile.getName();
if (FileTypeEnum.FILE_TYPE_ZIP.type.equals(fileContentType)) {
//zip解压缩处理
packFilePath += FileTypeEnum.FILE_TYPE_ZIP.fileStufix;
} else if (FileTypeEnum.FILE_TYPE_RAR.type.equals(fileContentType)) {
//rar解压缩处理
packFilePath += FileTypeEnum.FILE_TYPE_RAR.fileStufix;
isZipPack = false;
} else {
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"上传的压缩包格式不正确,仅支持rar和zip压缩文件!");
}
File file = new File(packFilePath);
try {
zipFile.transferTo(file);
} catch (IOException e) {
log.error("zip file save to " + uploadPath + " error", e.getMessage(), e);
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"保存压缩文件到:" + uploadPath + " 失败!");
}
if (isZipPack) {
//zip压缩包
UnPackeUtil.unPackZip(file, password, uploadPath);
} else {
//rar压缩包
UnPackeUtil.unPackRar(file, uploadPath);
}
String path=readZipFile(packFilePath);
if (StringUtils.isNotBlank(path)){
path=xx_url+"/"+prefix+"/"+path;
return ObjectRestResponse.succ(path);
}else {
return ObjectRestResponse.createDefaultFail();
}
}
public static String readZipFile(String file) throws Exception {
ZipFile zf = new ZipFile(file);
InputStream in = new BufferedInputStream(new FileInputStream(file));
ZipInputStream zin = new ZipInputStream(in);
ZipEntry ze;
String path=null;
while ((ze = zin.getNextEntry()) != null) {
if (ze.isDirectory()) {
} else {
path= ze.getName();
}
}
zin.closeEntry();
return path;
}
}
...@@ -1334,4 +1334,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> { ...@@ -1334,4 +1334,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> {
return list; return list;
} }
public List<String> findExistVehicleIds() {
return mapper.findExistVehicleIds();
}
} }
...@@ -29,6 +29,7 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo ...@@ -29,6 +29,7 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo
public static final DateTimeFormatter YEARMONTH_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM"); public static final DateTimeFormatter YEARMONTH_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM");
public static final Integer DEL_BATCH_SIZE = 1000; public static final Integer DEL_BATCH_SIZE = 1000;
public static final Integer COPY_BATCH_SIZE = 100; public static final Integer COPY_BATCH_SIZE = 100;
public static final int MONTH_INTERVAL=2;
@Autowired @Autowired
private RedisTemplate customRedisTemplate; private RedisTemplate customRedisTemplate;
...@@ -127,4 +128,7 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo ...@@ -127,4 +128,7 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo
mapper.createTbIfNotExists(tbName); mapper.createTbIfNotExists(tbName);
} }
public void InsertBatch(List<VehicleBookInfo> bookInfos) {
mapper.insertBatch(bookInfos);
}
} }
package com.xxfc.platform.vehicle.config;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* xxl-job config
*
* @author xuxueli 2017-04-28
*/
@Slf4j
@Configuration
public class XxlJobConfig {
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.executor.appname}")
private String appName;
@Value("${xxl.job.executor.ip}")
private String ip;
@Value("${xxl.job.executor.port}")
private int port;
@Value("${xxl.job.accessToken}")
private String accessToken;
@Value("${xxl.job.executor.logpath}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays}")
private int logRetentionDays;
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobSpringExecutor xxlJobExecutor() {
log.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppName(appName);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
/**
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
*
* 1、引入依赖:
* <dependency>
* <groupId>org.springframework.cloud</groupId>
* <artifactId>spring-cloud-commons</artifactId>
* <version>${version}</version>
* </dependency>
*
* 2、配置文件,或者容器启动变量
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
*
* 3、获取IP
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
*/
}
\ No newline at end of file
package com.xxfc.platform.vehicle.jobhandler;
import com.xxfc.platform.vehicle.biz.VehicleBiz;
import com.xxfc.platform.vehicle.biz.VehicleBookInfoBiz;
import com.xxfc.platform.vehicle.entity.VehicleBookInfo;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/8/1 11:28
*/
@JobHandler(value = "vehicle_job_handler")
@Component("vehicle_job_handler")
public class VehicleJobHandler extends IJobHandler {
@Autowired
private VehicleBiz vehicleBiz;
@Autowired
private VehicleBookInfoBiz vehicleBookInfoBiz;
@Override
public ReturnT<String> execute(String s) throws Exception {
try {
List<String> existVehicleIds = vehicleBiz.findExistVehicleIds();
LocalDate date = LocalDate.now();
int year = date.getYear();
int nowMonth = date.getMonthValue();
int month = nowMonth + VehicleBookInfoBiz.MONTH_INTERVAL > 12 ? (VehicleBookInfoBiz.MONTH_INTERVAL + nowMonth) - 12 : nowMonth + VehicleBookInfoBiz.MONTH_INTERVAL;
year = month > nowMonth ? year : year + 1;
String yearAndMonth = String.format("%d-%d", year, month);
if (CollectionUtils.isNotEmpty(existVehicleIds)) {
List<VehicleBookInfo> bookInfos = existVehicleIds.stream().map(vehicleId -> {
VehicleBookInfo vehicleBookInfo = new VehicleBookInfo();
vehicleBookInfo.setVehicle(vehicleId);
vehicleBookInfo.setYearMonth(yearAndMonth);
return vehicleBookInfo;
}).collect(Collectors.toList());
vehicleBookInfoBiz.InsertBatch(bookInfos);
}
ReturnT returnT = new ReturnT();
returnT.setCode(100);
returnT.setMsg("成功");
return returnT;
} catch (Exception ex) {
XxlJobLogger.log(ex);
return FAIL;
}
}
}
package com.xxfc.platform.vehicle.mapper; package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.VehicleBookInfo; import com.xxfc.platform.vehicle.entity.VehicleBookInfo;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
import java.util.List; import java.util.List;
...@@ -43,4 +44,5 @@ public interface VehicleBookInfoMapper extends Mapper<VehicleBookInfo> { ...@@ -43,4 +44,5 @@ public interface VehicleBookInfoMapper extends Mapper<VehicleBookInfo> {
public Integer del4YearMoth(Map<String, Object> params); public Integer del4YearMoth(Map<String, Object> params);
void insertBatch(@Param("vbfs") List<VehicleBookInfo> bookInfos);
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package com.xxfc.platform.vehicle.mapper; ...@@ -3,6 +3,7 @@ package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.Vehicle; import com.xxfc.platform.vehicle.entity.Vehicle;
import com.xxfc.platform.vehicle.pojo.*; import com.xxfc.platform.vehicle.pojo.*;
import com.xxfc.platform.vehicle.pojo.dto.VehiclePlanDto; import com.xxfc.platform.vehicle.pojo.dto.VehiclePlanDto;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
...@@ -46,5 +47,6 @@ public interface VehicleMapper extends Mapper<Vehicle> { ...@@ -46,5 +47,6 @@ public interface VehicleMapper extends Mapper<Vehicle> {
int upMileageByIdAndStatus(@Param("vehicleId") String vehicleId, @Param("status") Integer status, int upMileageByIdAndStatus(@Param("vehicleId") String vehicleId, @Param("status") Integer status,
@Param("lastStatus") Integer lastStatus,@Param("mileage") Integer mileage); @Param("lastStatus") Integer lastStatus,@Param("mileage") Integer mileage);
@Select("select `id` from `vehicle` where `is_del`=0")
List<String> findExistVehicleIds();
} }
\ No newline at end of file
...@@ -87,5 +87,10 @@ ...@@ -87,5 +87,10 @@
</insert> </insert>
<insert id="insertBatch">
INSERT IGNORE INTO vehicle_book_info(`vehicle`,`year_month`,`booked_date`)VALUES
<foreach collection="vbfs" item="vbf" separator=",">
(#{vbf.vehicle} ,#{vbf.yearMonth} ,0)
</foreach>
</insert>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment