Commit 7417f5ee authored by hanfeng's avatar hanfeng

Merge branch 'master_activity-hf' into base-modify

parents 141313ed c9cfe1d6
...@@ -8,16 +8,16 @@ package com.xxfc.platform.summit.model; ...@@ -8,16 +8,16 @@ package com.xxfc.platform.summit.model;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.Data;
/** /**
* 封装 access_token * 封装 access_token
*/ */
@Data
public class AccessToken implements Serializable { public class AccessToken implements Serializable {
private static final long serialVersionUID = -822464425433824314L; private static final long serialVersionUID = -822464425433824314L;
...@@ -41,8 +41,11 @@ public class AccessToken implements Serializable { ...@@ -41,8 +41,11 @@ public class AccessToken implements Serializable {
expires_in = temp.getInteger("expires_in"); expires_in = temp.getInteger("expires_in");
if (expires_in != null) if (expires_in != null){
expiredTime = System.currentTimeMillis() + ((expires_in -5) * 1000); expiredTime = System.currentTimeMillis() + ((expires_in -5) * 1000);
System.out.println("----expiredTime==="+expiredTime);
}
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
...@@ -69,17 +72,6 @@ public class AccessToken implements Serializable { ...@@ -69,17 +72,6 @@ public class AccessToken implements Serializable {
return access_token != null; return access_token != null;
} }
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
public void setExpires_in(Integer expires_in) {
this.expires_in = expires_in;
}
public void setExpiredTime(Long expiredTime) {
this.expiredTime = expiredTime;
}
public void setJson(String json) { public void setJson(String json) {
this.json = json; this.json = json;
...@@ -90,13 +82,6 @@ public class AccessToken implements Serializable { ...@@ -90,13 +82,6 @@ public class AccessToken implements Serializable {
return number == null ? null : number.intValue(); return number == null ? null : number.intValue();
} }
public String getAccessToken() {
return access_token;
}
public Integer getExpiresIn() {
return expires_in;
}
} }
package com.xxfc.platform.summit.pojo;
public enum SummitStatus {
ENROLL("报名中",1),IN_PROGRESS("进行中",2),End("已结束",3);
private String msg;
private Integer code;
SummitStatus(String msg, Integer code) {
this.msg = msg;
this.code = code;
}
public String getMsg() {
return msg;
}
public Integer getCode() {
return code;
}
}
...@@ -7,6 +7,7 @@ import com.xxfc.platform.summit.entity.Activity; ...@@ -7,6 +7,7 @@ import com.xxfc.platform.summit.entity.Activity;
import com.xxfc.platform.summit.mapper.ActivityMapper; import com.xxfc.platform.summit.mapper.ActivityMapper;
import com.xxfc.platform.summit.pojo.AccessType; import com.xxfc.platform.summit.pojo.AccessType;
import com.xxfc.platform.summit.pojo.ActivityQuery; import com.xxfc.platform.summit.pojo.ActivityQuery;
import com.xxfc.platform.summit.pojo.SummitStatus;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -40,10 +41,23 @@ public class ActivityBiz extends BaseBiz<ActivityMapper, Activity> { ...@@ -40,10 +41,23 @@ public class ActivityBiz extends BaseBiz<ActivityMapper, Activity> {
criteria.andLike("title", String.format("%%%s%%", query.getTitle().trim())); criteria.andLike("title", String.format("%%%s%%", query.getTitle().trim()));
} }
if (query.getStartTime() != null) { if (query.getStartTime() != null) {
criteria.andLike("startTime", query.getStartTime()/(1000*60*60)+"%"); criteria.andLike("startTime", query.getStartTime() / (1000 * 60 * 60) + "%");
} }
if (query.getStatus() != null) { if (query.getStatus() != null) {
criteria.andEqualTo("status", query.getStatus()); criteria.andEqualTo("status", query.getStatus());
switch (query.getStatus()) {
case 1:
criteria.orLessThan("startTime", System.currentTimeMillis());
break;
case 2:
criteria.orBetween("startTime", System.currentTimeMillis(),"endTime");
break;
case 3:
criteria.orGreaterThan("endTime", System.currentTimeMillis());
break;
default:
throw new IllegalStateException("Unexpected value: " + query.getStatus());
}
} }
if (query.getType() != null && AccessType.PUBLIC.getCode().equals(query.getType())) { if (query.getType() != null && AccessType.PUBLIC.getCode().equals(query.getType())) {
......
...@@ -17,10 +17,8 @@ import org.apache.commons.lang3.StringUtils; ...@@ -17,10 +17,8 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
...@@ -33,7 +31,6 @@ import javax.servlet.http.HttpSession; ...@@ -33,7 +31,6 @@ import javax.servlet.http.HttpSession;
public class WeixinController { public class WeixinController {
public static final String WECHAT_AUTOLOGIN_CALLBACKURL_KEY = "callback"; public static final String WECHAT_AUTOLOGIN_CALLBACKURL_KEY = "callback";
public static final String WECHAT_REDIS_KEY = "key";
@Autowired @Autowired
WeixinService weixinService; WeixinService weixinService;
...@@ -55,15 +52,16 @@ public class WeixinController { ...@@ -55,15 +52,16 @@ public class WeixinController {
@RequestMapping(value ="/app/unauth/wxLogin",method = RequestMethod.GET) @RequestMapping(value ="/app/unauth/wxLogin",method = RequestMethod.GET)
@IgnoreUserToken @IgnoreUserToken
public String index(@RequestParam(value = "redirec_url")String redirec_url, public String index(@RequestParam(value = "redirec_url",defaultValue = "")String redirec_url,
@RequestParam(value = "key")String key){ @RequestParam(value = "key",defaultValue = "")String key){
log.info("-----微信wxLogin---redirec_url=="+redirec_url); log.info("-----微信wxLogin---redirec_url=="+redirec_url+"-----key===="+key);
if (StringUtils.isBlank(redirec_url)){ if (StringUtils.isBlank(redirec_url)||StringUtils.isBlank(key)){
redirec_url=""; redirec_url="";
} }
try { try {
String encrypt_curr_url = Base64.encode(redirec_url.getBytes("utf-8")); String encrypt_curr_url = Base64.encode(redirec_url.getBytes("utf-8"));
redirec_url=url+"?" + WECHAT_AUTOLOGIN_CALLBACKURL_KEY+ "=" + encrypt_curr_url+"&"+WECHAT_REDIS_KEY+"="+key; encrypt_curr_url+=","+key;
redirec_url=url+"?" + WECHAT_AUTOLOGIN_CALLBACKURL_KEY+ "=" + encrypt_curr_url;
String oauth_api=weixinService.getAuthorize(redirec_url); String oauth_api=weixinService.getAuthorize(redirec_url);
return String.format("redirect:"+oauth_api); return String.format("redirect:"+oauth_api);
}catch (Exception e){ }catch (Exception e){
...@@ -80,17 +78,22 @@ public class WeixinController { ...@@ -80,17 +78,22 @@ public class WeixinController {
* @return * @return
*/ */
@GetMapping(value = "/app/unauth/userInfo") @GetMapping(value = "/app/unauth/userInfo")
public String getUserInformation(String code, String callback,String key, HttpServletRequest request) { public String getUserInformation(String code, String callback, HttpServletRequest request) {
log.info("-----微信回调userInfo---code=="+code+"----redirec_url==="+callback+"---key==="+key); log.info("-----微信回调userInfo---code=="+code+"----redirec_url==="+callback);
try { try {
String [] params=callback.split(",");
String key=params[1];
callback=params[0];
userBiz.authUser(code,key,request); userBiz.authUser(code,key,request);
callback =new String(Base64.decode(callback), "utf-8"); callback =new String(Base64.decode(callback), "utf-8");
log.info("callback===" + callback); log.info("callback===" + callback);
return String.format("redirect:"+callback);
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
log.info("网络异常===" + e.getMessage()); log.info("网络异常===" + e.getMessage());
return String.format("网络异常");
} }
return String.format("redirect:"+callback);
} }
/** /**
...@@ -99,7 +102,7 @@ public class WeixinController { ...@@ -99,7 +102,7 @@ public class WeixinController {
* @return * @return
*/ */
@GetMapping(value = "/app/unauth/share") @GetMapping(value = "/app/unauth/share")
public ObjectRestResponse share(@RequestParam("url") String url) { public @ResponseBody ObjectRestResponse share(@RequestParam("url") String url) {
log.info("-----微信分享share---url=="+url); log.info("-----微信分享share---url=="+url);
try { try {
return ObjectRestResponse.succ(wXjsService.getShareData(url)); return ObjectRestResponse.succ(wXjsService.getShareData(url));
......
...@@ -59,17 +59,17 @@ public class WeChatH5LoginInterceptor extends HandlerInterceptorAdapter { ...@@ -59,17 +59,17 @@ public class WeChatH5LoginInterceptor extends HandlerInterceptorAdapter {
return true; return true;
} }
String redisKey=redisInfo(request); String redisKey=redisInfo(request);
Map<String,Object> result=new HashMap<>(); JSONObject result=new JSONObject();
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
if (StringUtils.isNotBlank(redisKey)){ if (StringUtils.isNotBlank(redisKey)){
json.put("key",redisKey); json.put("key",redisKey);
} }
json.put("url","https://dev.dfangche.com/api/summit/auth/app/unauth/wxLogin?redirec_url=https://dev.dfangche.com/h5/appHtml/view/wxh5/index.html"); json.put("url","https://dev.dfangche.com/api/summit/auth/app/unauth/wxLogin");
result.put("data",json); result.put("data",json);
result.put("status",1001); result.put("status",1001);
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
response.setContentType("application/json; charset=utf-8"); response.setContentType("application/json; charset=utf-8");
response.getWriter().write(result.toString()); response.getWriter().append(result.toString());
return false; return false;
} }
return true; return true;
...@@ -89,15 +89,17 @@ public class WeChatH5LoginInterceptor extends HandlerInterceptorAdapter { ...@@ -89,15 +89,17 @@ public class WeChatH5LoginInterceptor extends HandlerInterceptorAdapter {
{ {
e.printStackTrace(); e.printStackTrace();
} }
String redisLockKey=null; String key=null;
if (StringUtils.isNotBlank(jb)){ if (StringUtils.isNotBlank(jb)){
redisLockKey= RedisKey.CONSTANT_CODE_PREFIX + UUID.randomUUID(); key= UUID.randomUUID()+"";
Boolean suc = summbitRedisTemplate.opsForValue().setIfAbsent(redisLockKey, jb); String redisLockKey= RedisKey.CONSTANT_CODE_PREFIX +key;
log.info("-----jb====="+jb.toString());
Boolean suc = summbitRedisTemplate.opsForValue().setIfAbsent(redisLockKey, jb.toString());
if (suc) { if (suc) {
summbitRedisTemplate.expire(redisLockKey, 5, TimeUnit.MINUTES);//5分钟内过期 summbitRedisTemplate.expire(redisLockKey, 5, TimeUnit.MINUTES);//5分钟内过期
} }
} }
return redisLockKey; return key;
} }
......
...@@ -58,9 +58,11 @@ public class AccessTokenService { ...@@ -58,9 +58,11 @@ public class AccessTokenService {
{ {
JSONObject obj = JSONObject.parseObject(accessTokenRedis).getJSONObject(wy_appid); JSONObject obj = JSONObject.parseObject(accessTokenRedis).getJSONObject(wy_appid);
AccessToken accessToken = new AccessToken(obj.getString("json"),obj.getString("accessToken"),obj.getInteger("expiresIn")); AccessToken accessToken = new AccessToken(obj.getString("json"),obj.getString("accessToken"),obj.getInteger("expiresIn"));
if(accessToken.isAvailable()) if(accessToken.isAvailable()){
return accessToken; return accessToken;
} }
summbitRedisTemplate.delete(wy_appid);
}
refreshAccessToken(); refreshAccessToken();
accessTokenRedis = summbitRedisTemplate.opsForValue().get(wy_appid) == null ? "" : summbitRedisTemplate.opsForValue().get(wy_appid).toString(); accessTokenRedis = summbitRedisTemplate.opsForValue().get(wy_appid) == null ? "" : summbitRedisTemplate.opsForValue().get(wy_appid).toString();
...@@ -94,11 +96,10 @@ public class AccessTokenService { ...@@ -94,11 +96,10 @@ public class AccessTokenService {
String json = HttpRequestUtil.httpGet(url+"&appid="+wy_appid+"&secret="+wy_secret); String json = HttpRequestUtil.httpGet(url+"&appid="+wy_appid+"&secret="+wy_secret);
log.info("---json===="+json); log.info("---json===="+json);
result = new AccessToken(json); result = new AccessToken(json);
log.info("---result===="+result.toString());
if (result.isAvailable()) if (result.isAvailable())
break; break;
} }
// 三次请求如果仍然返回了不可用的 access token 仍然 put 进去,便于上层通过 AccessToken 中的属性判断底层的情况 // 三次请求如果仍然返回了不可用的 access token 仍然 put 进去,便于上层通过 AccessToken 中的属性判断底层的情况
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put(wy_appid, result); obj.put(wy_appid, result);
......
...@@ -76,7 +76,7 @@ public class JsTicketService { ...@@ -76,7 +76,7 @@ public class JsTicketService {
{ {
JSONObject objTemp = new JSONObject(); JSONObject objTemp = new JSONObject();
objTemp = JSONObject.parseObject(jsTicketRedis).getJSONObject(key); objTemp = JSONObject.parseObject(jsTicketRedis).getJSONObject(key);
jsTicket.setExpiredTime(objTemp.getLong("expiresIn")); jsTicket.setExpiredTime(objTemp.getLong("expiredTime"));
jsTicket.setTicket(objTemp.getString("ticket")); jsTicket.setTicket(objTemp.getString("ticket"));
jsTicket.setExpires_in(objTemp.getInteger("expiresIn")); jsTicket.setExpires_in(objTemp.getInteger("expiresIn"));
...@@ -85,6 +85,7 @@ public class JsTicketService { ...@@ -85,6 +85,7 @@ public class JsTicketService {
//(JsTicket) JSON.parseObject(redisUtil.get(key)).get(key); //(JsTicket) JSON.parseObject(redisUtil.get(key)).get(key);
if(!jsTicket.isAvailable()) if(!jsTicket.isAvailable())
{ {
log.info("---jsTicket----失效");
// https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=wx_card // https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=wx_card
String json = HttpRequestUtil.httpGet(apiUrl+"access_token="+ tokenService.getAccessTokenStr()+"&type="+jsApiType.name()); String json = HttpRequestUtil.httpGet(apiUrl+"access_token="+ tokenService.getAccessTokenStr()+"&type="+jsApiType.name());
log.info("---json===="+json); log.info("---json===="+json);
...@@ -92,6 +93,7 @@ public class JsTicketService { ...@@ -92,6 +93,7 @@ public class JsTicketService {
/*Element element = new Element(SystemConfig.WINXIN_AppID, jsTicket); /*Element element = new Element(SystemConfig.WINXIN_AppID, jsTicket);
ehcache.put(element);*/ ehcache.put(element);*/
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
summbitRedisTemplate.delete(key);
Boolean suc=summbitRedisTemplate.opsForValue().setIfAbsent(key, obj.toJSONString()); Boolean suc=summbitRedisTemplate.opsForValue().setIfAbsent(key, obj.toJSONString());
if (suc) { if (suc) {
summbitRedisTemplate.expire(wy_appid, jsTicket.getExpiresIn(), TimeUnit.MINUTES); summbitRedisTemplate.expire(wy_appid, jsTicket.getExpiresIn(), TimeUnit.MINUTES);
......
...@@ -98,4 +98,9 @@ public class RedisKey { ...@@ -98,4 +98,9 @@ public class RedisKey {
public static final String CACHE_DICTIONARY_ALL =CACHE_DICTIONARY_PREFIX + "all:"; public static final String CACHE_DICTIONARY_ALL =CACHE_DICTIONARY_PREFIX + "all:";
public static final String CACHE_DICTIONARY_ALL_MAP =CACHE_DICTIONARY_ALL + "map:"; public static final String CACHE_DICTIONARY_ALL_MAP =CACHE_DICTIONARY_ALL + "map:";
public static final String ILLEGAL_VEHICLE_ENQUIRIES ="cache:violation"; public static final String ILLEGAL_VEHICLE_ENQUIRIES ="cache:violation";
/**
* 服务器上传压缩包文件序号
*/
public static final String UPLOAD_ZIP_NO_PREFIX ="upload:zip:no:";
} }
...@@ -183,9 +183,9 @@ public class UploadController{ ...@@ -183,9 +183,9 @@ public class UploadController{
@PostMapping(value="/app/unauth/pictureZip") @PostMapping(value="/app/unauth/pictureZip")
public ObjectRestResponse pictureZip( public ObjectRestResponse pictureZip(
@RequestBody MultipartFile file, @RequestParam("file")MultipartFile file,
@RequestBody String password) throws Exception { @RequestParam(value = "prefix",defaultValue = "summit")String prefix) throws Exception {
return uploadZipService.uploadPictureZip(file,password); return uploadZipService.uploadPictureZip(file,prefix);
} }
} }
...@@ -7,5 +7,5 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -7,5 +7,5 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
public interface UploadZipService { public interface UploadZipService {
ObjectRestResponse uploadPictureZip(MultipartFile file, String password) throws IOException; ObjectRestResponse uploadPictureZip(MultipartFile file, String prefix) throws IOException;
} }
package com.xxfc.platform.universal.service.impl; package com.xxfc.platform.universal.service.impl;
import com.alibaba.druid.sql.visitor.functions.If;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode; import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.xxfc.platform.universal.constant.RedisKey;
import com.xxfc.platform.universal.constant.enumerate.FileTypeEnum; import com.xxfc.platform.universal.constant.enumerate.FileTypeEnum;
import com.xxfc.platform.universal.service.UploadZipService; import com.xxfc.platform.universal.service.UploadZipService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.*; import java.io.*;
import java.nio.charset.Charset;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
...@@ -22,60 +29,74 @@ public class UploadZipServiceImpl implements UploadZipService { ...@@ -22,60 +29,74 @@ public class UploadZipServiceImpl implements UploadZipService {
@Value("${universal.uploadPath}") @Value("${universal.uploadPath}")
private String uploadPath ; private String uploadPath ;
@Value("${universal.url}") @Value("${universal.url}")
private String xx_url ; private String xx_url ;
@Value("${photo.format}")
private static final String APK_SUFFIX=".apk"; private String PHOTO_FORMAT=".png/.jpg/.git/.bmp";
private static final String APK_NAME="xxfc.apk"; @Autowired
private static final String JPG=".jpg"; RedisTemplate redisTemplate;
private static final String PNG=".png";
@Override @Override
public ObjectRestResponse uploadPictureZip(MultipartFile file, String password) throws IOException { public ObjectRestResponse uploadPictureZip(MultipartFile uFile, String prefix) throws IOException {
if (Objects.isNull(file)) { if (Objects.isNull(uFile)) {
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"请上传压缩文件!"); return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"请上传压缩文件!");
} }
String fileContentType = uFile.getContentType();
String fileContentType = file.getContentType();
//将压缩包保存在指定路径 //将压缩包保存在指定路径
String packFilePath = uploadPath + File.separator + file.getName(); String packFilePath = uploadPath + File.separator + uFile.getName();
if (FileTypeEnum.FILE_TYPE_ZIP.type.equals(fileContentType)||FileTypeEnum.FILE_TYPE_X_ZIP.type.equals(fileContentType)) { if (FileTypeEnum.FILE_TYPE_ZIP.type.equals(fileContentType)||FileTypeEnum.FILE_TYPE_X_ZIP.type.equals(fileContentType)) {
//zip解压缩处理 //zip解压缩处理
packFilePath += FileTypeEnum.FILE_TYPE_ZIP.fileStufix; packFilePath += FileTypeEnum.FILE_TYPE_ZIP.fileStufix;
} else { } else {
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"上传的压缩包格式不正确,仅支持zip压缩文件!"); return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"上传的压缩包格式不正确,仅支持zip压缩文件!");
} }
File fi = new File(packFilePath); File file = new File(packFilePath);
try { try {
file.transferTo(fi); //保存压缩包
FileOutputStream os = new FileOutputStream(file);
IOUtil.copy(uFile.getInputStream(),os);
os.close();
} catch (IOException e) { } catch (IOException e) {
log.error("zip file save to " + uploadPath + " error", e.getMessage(), e); log.error("zip file save to " + uploadPath + " error", e.getMessage(), e);
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"保存压缩文件到:" + uploadPath + " 失败!"); return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE,"保存压缩文件到:" + uploadPath + " 失败!");
} }
//zip压缩包 //zip压缩包解压
return unPackZip(fi, password, uploadPath); return unPackZip(file, prefix);
} }
public ObjectRestResponse unPackZip(File file, String password, String destPath) throws IOException { public ObjectRestResponse<String> unPackZip(File file, String prefix) throws IOException {
ZipFile zipFile = new ZipFile(file); ZipFile zipFile = new ZipFile(file, Charset.forName("GBK"));
Enumeration<? extends ZipEntry> entries = zipFile.entries(); Enumeration<? extends ZipEntry> entries = zipFile.entries();
long millis = System.currentTimeMillis();
String dirPathToday = prefix+ File.separator + millis;
String redisNoKey = RedisKey.UPLOAD_FILE_NO_PREFIX +millis;
StringBuffer result = new StringBuffer();
Integer index = 0;
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement(); ZipEntry entry = entries.nextElement();
if (entry.isDirectory()) { if (entry.isDirectory() && index++ == 0) {
destPath =destPath+File.separator+ entry.getName(); File dir = new File(uploadPath+dirPathToday);
File dir = new File(destPath);
dir.mkdir(); dir.mkdir();
}else { } else if (!entry.isDirectory()) {
File targetFile = new File(destPath+File.separator+entry.getName());
if (targetFile.getParentFile().exists()){
Long no = redisTemplate.opsForValue().increment(redisNoKey);
if(no.equals(1l)){
redisTemplate.expire(redisNoKey,1, TimeUnit.DAYS);
} }
String name = entry.getName();
String format = name.substring(name.lastIndexOf("."));
if (PHOTO_FORMAT.contains(format)) {
String realFileRelPath = dirPathToday + File.separator + no +format;
File targetFile = new File(uploadPath+realFileRelPath);
FileUtils.copyInputStreamToFile(zipFile.getInputStream(entry),targetFile);
realFileRelPath=xx_url+ SystemConfig.XXMP_URL+realFileRelPath;
result.append(realFileRelPath+",");
} }
} }
}
return null; return ObjectRestResponse.succ(result.substring(0, result.length()-1));
} }
} }
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