:art:完善部分新功能

This commit is contained in:
hello-hao
2022-11-21 19:03:58 +08:00
parent b978f33aba
commit 2ee49dcae2
15 changed files with 525 additions and 467 deletions
@@ -500,8 +500,10 @@ public class AdminController {
JSONObject jsonObj = JSONObject.parseObject(data);
String uuid = jsonObj.getString("uuid");
JSONObject jsonObject = new JSONObject();
MyProgress myProgress =
JSON.parseObject(iRedisService.getValue(uuid).toString(), MyProgress.class);
MyProgress myProgress = null;
try{
myProgress = JSON.parseObject(iRedisService.getValue(uuid).toString(), MyProgress.class);
}catch (Exception e){ }
if (null == myProgress) {
jsonObject.put("succ", myProgress.getDelSuccessCount());
jsonObject.put("errorlist", new ArrayList<String>());
@@ -2,11 +2,9 @@ package cn.hellohao.controller;
import cn.hellohao.pojo.Msg;
import cn.hellohao.service.impl.ClientService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
@@ -17,18 +15,30 @@ import javax.servlet.http.HttpServletRequest;
* @date 2019-07-18 17:22
*/
@RestController
@RequestMapping("/api")
public class ClientController {
@Autowired
private ClientService clientService;
@Autowired private ClientService clientService;
@PostMapping(value = "/uploadbymail")
@ResponseBody
public Msg uploadbymail(HttpServletRequest request, @RequestParam("file") MultipartFile file, String mail, String pass) {
Msg resultBean = clientService.uploadImg(request, file, mail, pass);
public Msg uploadbymail(
HttpServletRequest request,
@RequestParam(value = "file") MultipartFile file,
@RequestParam(value = "mail", defaultValue = "") String mail,
@RequestParam(value = "pass", defaultValue = "") String pass,
@RequestParam(value = "days", defaultValue = "0") String days) {
if (file == null
|| StringUtils.isBlank(mail)
|| StringUtils.isBlank(pass)) {
Msg msg = new Msg();
msg.setCode("400");
msg.setInfo("相关参数不能为空");
return msg;
}
Msg resultBean =
clientService.uploadImg(
request, file, mail, pass, Integer.valueOf(days.toString()));
return resultBean;
}
}
@@ -1,11 +1,9 @@
package cn.hellohao.dao;
import cn.hellohao.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.User;
import java.util.List;
@Mapper
@@ -14,7 +12,6 @@ public interface UserMapper {
Integer login(@Param("email") String email, @Param("password") String password,@Param("uid") String uid);
User getUsers(User user);
User loginByToken (@Param("token") String token);
Integer insertimg(Images img);
Integer change(User user);
Integer changeUser(User user);
Integer checkUsername(@Param("username") String username);
@@ -1,6 +1,5 @@
package cn.hellohao.service;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.User;
import org.springframework.stereotype.Service;
@@ -16,8 +15,6 @@ public interface UserService {
User getUsers(User user);
Integer insertimg(Images img);
Integer change(User user);
Integer changeUser(User user);
@@ -3,42 +3,43 @@ package cn.hellohao.service.impl;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.utils.*;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.exception.CosClientException;
import com.qcloud.cos.exception.CosServiceException;
import com.qcloud.cos.model.*;
import com.qcloud.cos.model.ListObjectsRequest;
import com.qcloud.cos.model.ObjectListing;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.*;
import java.util.Map;
@Service
public class COSImageupload {
static COSClient cosClient;
static Keys key;
public ReturnImage ImageuploadCOS(Map<String, File> fileMap, String username,Integer keyID) {
public ReturnImage ImageuploadCOS(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
Map<ReturnImage, Integer> ImgUrl = new HashMap<>();
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
file = entry.getValue();
try {
String bucketName = key.getBucketname();
String userkey =username + "/" + ShortUID + "." + entry.getKey();
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, userkey, file);
String userkey = username + "/" + ShortUIDName + "." + prefix;
PutObjectRequest putObjectRequest =
new PutObjectRequest(bucketName, userkey, file);
PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
returnImage.setImgname(userkey);
returnImage.setImgurl(key.getRequestAddress() + "/" + userkey);
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
} catch (CosServiceException serverException) {
returnImage.setCode("400");
serverException.printStackTrace();
@@ -47,41 +48,42 @@ public class COSImageupload {
clientException.printStackTrace();
}
}
}catch(Exception e){
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
return returnImage;
}
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getEndpoint()!=null
&& k.getBucketname()!=null && k.getRequestAddress()!=null ) {
if (!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getEndpoint().equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("")) {
String secretId = k.getAccessKey();
String secretKey = k.getAccessSecret();
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
Region region = new Region(k.getEndpoint());
ClientConfig clientConfig = new ClientConfig(region);
COSClient cos = new COSClient(cred, clientConfig);
ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.setBucketName(k.getBucketname());
listObjectsRequest.setDelimiter("/");
listObjectsRequest.setMaxKeys(1);
ObjectListing objectListing = null;
try {
objectListing = cos.listObjects(listObjectsRequest);
ret = 1;
cosClient = cos;
key = k;
} catch (Exception e) {
System.out.println("COS Object Is null");
ret = -1;
}
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
String secretId = k.getAccessKey();
String secretKey = k.getAccessSecret();
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
Region region = new Region(k.getEndpoint());
ClientConfig clientConfig = new ClientConfig(region);
COSClient cos = new COSClient(cred, clientConfig);
ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.setBucketName(k.getBucketname());
listObjectsRequest.setDelimiter("/");
listObjectsRequest.setMaxKeys(1);
ObjectListing objectListing = null;
try {
objectListing = cos.listObjects(listObjectsRequest);
ret = 1;
cosClient = cos;
key = k;
} catch (Exception e) {
System.out.println("COS Object Is null");
ret = -1;
}
return ret;
}
@@ -94,10 +96,6 @@ public class COSImageupload {
e.printStackTrace();
b = false;
}
return b ;
return b;
}
}
@@ -2,6 +2,7 @@ package cn.hellohao.service.impl;
import cn.hellohao.dao.*;
import cn.hellohao.pojo.*;
import cn.hellohao.service.ImgTempService;
import cn.hellohao.service.SysConfigService;
import cn.hellohao.utils.*;
import com.alibaba.fastjson.JSON;
@@ -12,6 +13,7 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
@@ -26,29 +28,23 @@ import java.util.*;
@Service
public class ClientService {
@Autowired
private SysConfigService sysConfigService;
@Autowired
private UserMapper userMapper;
@Autowired
private KeysMapper keysMapper;
@Autowired
private ConfigMapper configMapper;
@Autowired
private UploadConfigMapper uploadConfigMapper;
@Autowired
private ImgMapper imgMapper;
@Autowired
ImgreviewMapper imgreviewMapper;
@Autowired private SysConfigService sysConfigService;
@Autowired private UserMapper userMapper;
@Autowired private KeysMapper keysMapper;
@Autowired private UploadConfigMapper uploadConfigMapper;
@Autowired private ImgMapper imgMapper;
@Autowired private ImgreviewMapper imgreviewMapper;
@Autowired private ImgTempService imgTempService;
@Autowired private KeysServiceImpl keysService;
public Msg uploadImg(HttpServletRequest request, MultipartFile multipartFile, String email, String pass ){
public Msg uploadImg(
HttpServletRequest request, MultipartFile multipartFile, String email, String pass,Integer setday) {
Msg msg = new Msg();
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Integer sourceKeyId = 0;
FileInputStream fis = null;
String md5key = null;
Integer setday = 0;
JSONObject jsonObject = new JSONObject();
String userip = GetIPS.getIpAddr(request);
UploadConfig uploadConfig = uploadConfigMapper.getUpdateConfig();
@@ -119,56 +115,96 @@ public class ClientService {
}
}
}
if(Integer.valueOf(sysConfigService.getstate().getCheckduplicate())==1) {
// if (Integer.valueOf(sysConfigService.getstate().getCheckduplicate()) == 1) {
// Images imaOBJ = new Images();
// imaOBJ.setMd5key(md5key);
// imaOBJ.setUserid(u.getId());
// if (imgMapper.md5Count(imaOBJ) > 0) {
// List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
// jsonObject.put("url", images.get(0).getImgurl());
// jsonObject.put("name", file.getName());
// jsonObject.put("size", images.get(0).getSizes());
// msg.setData(jsonObject);
// return msg;
// }
// }
Images imgObj = new Images();
String imgnameEd = null;
Map<Map<String, String>, File> map = new HashMap<>();
if (file.exists()) {
Map<String, String> m1 = new HashMap<>();
String shortUuid_y = SetText.getShortUuid();
m1.put("prefix", prefix);
m1.put("name", shortUuid_y);
map.put(m1, file);
imgnameEd = updatePath + "/" + shortUuid_y + "." + prefix;
imgObj.setImgname(imgnameEd);
if (key.getStorageType().equals(5)) {
imgObj.setImgurl(key.getRequestAddress() + "/ota/" + imgnameEd);
} else {
imgObj.setImgurl(key.getRequestAddress() + "/" + imgnameEd);
}
imgObj.setSizes(Long.toString(file.length()));
}
imgObj.setUpdatetime(df.format(new Date()));
imgObj.setSource(key.getId());
imgObj.setUserid(u == null ? 0 : u.getId());
if (setday == 1 || setday == 3 || setday == 7 || setday == 30) {
imgObj.setImgtype(1);
ImgTemp imgDataExp = new ImgTemp();
imgDataExp.setDeltime(UploadServicel.plusDay(setday));
imgDataExp.setImguid(imguid);
imgTempService.insertImgExp(imgDataExp);
} else {
imgObj.setImgtype(0);
}
imgObj.setAbnormal(userip);
imgObj.setMd5key(md5key);
imgObj.setImguid(imguid);
imgObj.setFormat(fileMiME.getData().toString());
Integer insertRet = imgMapper.insertImgData(imgObj);
if (insertRet == 0) {
Images imaOBJ = new Images();
imaOBJ.setMd5key(md5key);
imaOBJ.setUserid(u.getId());
if (imgMapper.md5Count(imaOBJ) > 0) {
List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
imaOBJ.setUserid(u == null ? 0 : u.getId());
List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
if (images.size() > 0) {
jsonObject.put("url", images.get(0).getImgurl());
// Keys imgFromKey = keysService.selectKeys(images.get(0).getSource());
// if (imgFromKey.getStorageType().equals(5)) {
// jsonObject.put(
// "url",
// imgFromKey.getRequestAddress()
// + "/ota/"
// + images.get(0).getImgname());
// } else {
// jsonObject.put("url", images.get(0).getImgurl());
// }
jsonObject.put("name", file.getName());
jsonObject.put("size", images.get(0).getSizes());
msg.setData(jsonObject);
return msg;
} else {
msg.setInfo("未获取到指定图像");
msg.setCode("110501");
return msg;
}
}
Map<String, File> map = new HashMap<>();
if (file.exists()) {
map.put(prefix, file);
}
long stime = System.currentTimeMillis();
Map<ReturnImage, Integer> m = null;
ReturnImage returnImage = GetSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
Images img = new Images();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ReturnImage returnImage =
GetSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
if (returnImage.getCode().equals("200")) {
String imgurl = returnImage.getImgurl();
Long imgsize = returnImage.getImgSize();
String imgname = returnImage.getImgname();
img.setImgurl(imgurl);
img.setUpdatetime(df.format(new Date()));
img.setSource(key.getId());
img.setUserid(u == null ? 0 : u.getId());
img.setSizes(imgsize.toString());
if (uploadConfig.getUrltype() == 2) {
img.setImgname(imgname);
} else {
img.setImgname(SetText.getSubString(imgname, key.getRequestAddress() + "/", ""));
}
img.setImgtype(setday > 0 ? 1 : 0);
img.setAbnormal(userip);
img.setMd5key(md5key);
img.setImguid(imguid);
img.setFormat(fileMiME.getData().toString());
userMapper.insertimg(img);
long etime = System.currentTimeMillis();
Print.Normal("上传图片所用总时长:" + String.valueOf(etime - stime) + "ms");
jsonObject.put("url", img.getImgurl());
jsonObject.put("name", imgname);
jsonObject.put("size", img.getSizes());
new Thread(() -> {
LegalImageCheck(img);
}).start();
jsonObject.put("url", imgObj.getImgurl());
jsonObject.put("name", imgObj.getImgname());
jsonObject.put("size", imgObj.getSizes());
new Thread(
() -> {
LegalImageCheck(imgObj);
})
.start();
} else {
msg.setCode("5001");
msg.setInfo("上传服务内部错误");
@@ -177,53 +213,55 @@ public class ClientService {
file.delete();
msg.setData(jsonObject);
return msg;
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
msg.setCode("5001");
msg.setInfo("Error for server:500");
return msg;
}
}
public static Group group;
public static Long memory;
public static Long TotleMemory;
public static Long UsedTotleMemory;
public static String updatePath = "tourist";
public static Group group; //上传用户或游客的所属分组
public static Long memory;//上传用户或者游客的分配容量 memory
public static Long TotleMemory;//用户或者游客下可使用的总容量 //maxsize
public static Long UsedTotleMemory;//用户或者游客已经用掉的总容量 //usermemory
public static String updatePath="tourist";
//判断用户 或 游客 当前上传图片的一系列校验
private Msg updateImgCheck(User user, UploadConfig uploadConfig){
final Msg msg = new Msg();
private Msg updateImgCheck(User user, UploadConfig uploadConfig) {
Msg msg = new Msg();
java.text.DateFormat dateFormat = null;
try {
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
if (user == null) {
//用户没有登陆,值判断游客能不能上传即可
if(uploadConfig.getIsupdate()!=1){
if (uploadConfig.getIsupdate() != 1) {
msg.setCode("1000");
msg.setInfo("系统已禁用游客上传");
return msg;
}
group = GetCurrentSource.GetSource(null);
memory = Long.valueOf(uploadConfig.getVisitormemory());//单位 B 游客设置总量
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists());//单位 B 游客单文件大小
UsedTotleMemory = imgMapper.getusermemory(0)==null?0L : imgMapper.getusermemory(0);//单位 B
memory = Long.valueOf(uploadConfig.getVisitormemory()); // 单位 B 游客设置总量
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists()); // 单位 B 游客单文件大小
UsedTotleMemory =
imgMapper.getusermemory(0) == null
? 0L
: imgMapper.getusermemory(0); // 单位 B
} else {
//判断用户能不能上传
if(uploadConfig.getUserclose()!=1){
// 判断用户能不能上传
if (uploadConfig.getUserclose() != 1) {
msg.setCode("1001");
msg.setInfo("系统已禁用上传功能");
return msg;
}
updatePath = user.getUsername();
group= GetCurrentSource.GetSource(user.getId());
memory = Long.valueOf(user.getMemory());//单位 B
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser());//单位 B
UsedTotleMemory = imgMapper.getusermemory(user.getId())==null?0L:imgMapper.getusermemory(user.getId());//单位 B
group = GetCurrentSource.GetSource(user.getId());
memory = Long.valueOf(user.getMemory()); // 单位 B
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser()); // 单位 B
UsedTotleMemory =
imgMapper.getusermemory(user.getId()) == null
? 0L
: imgMapper.getusermemory(user.getId()); // 单位 B
}
//判断上传的图片目录结构类型
// 判断上传的图片目录结构类型
if (uploadConfig.getUrltype() == 2) {
updatePath = dateFormat.format(new Date());
}
@@ -235,9 +273,8 @@ public class ClientService {
return msg;
}
//图片鉴黄
private synchronized void LegalImageCheck(Images images){
System.out.println("非法图像鉴别进程启动");
// 图片鉴黄
private synchronized void LegalImageCheck(Images images) {
Imgreview imgreview = null;
try {
imgreview = imgreviewMapper.selectByusing(1);
@@ -245,23 +282,33 @@ public class ClientService {
Print.warning("获取鉴别程序的时候发生错误");
e.printStackTrace();
}
LegalImageCheckForBaiDu(imgreview,images);
if(imgreview==null){
System.out.println("没有找到可用的图像鉴别进程");
}else{
LegalImageCheckForBaiDu(imgreview, images);
}
}
private void LegalImageCheckForBaiDu(Imgreview imgreview,Images images){
if(imgreview.getUsing()==1){
private void LegalImageCheckForBaiDu(Imgreview imgreview, Images images) {
if (imgreview.getUsing() == 1) {
try {
AipContentCensor client = new AipContentCensor(imgreview.getAppId(), imgreview.getApiKey(), imgreview.getSecretKey());
AipContentCensor client =
new AipContentCensor(
imgreview.getAppId(),
imgreview.getApiKey(),
imgreview.getSecretKey());
client.setConnectionTimeoutInMillis(5000);
client.setSocketTimeoutInMillis(30000);
org.json.JSONObject res = client.antiPorn(images.getImgurl());
res = client.imageCensorUserDefined(images.getImgurl(), EImgType.URL, null);
com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray("[" + res.toString() + "]");
com.alibaba.fastjson.JSONArray jsonArray =
JSON.parseArray("[" + res.toString() + "]");
for (Object o : jsonArray) {
JSONObject jsonObject = (JSONObject) o;
com.alibaba.fastjson.JSONArray data = jsonObject.getJSONArray("data");
Integer conclusionType = jsonObject.getInteger("conclusionType");
if(conclusionType!=null){
if (conclusionType != null) {
if (conclusionType == 2) {
for (Object datum : data) {
JSONObject imgdata = (JSONObject) datum;
@@ -283,14 +330,10 @@ public class ClientService {
}
}
}catch (Exception e){
} catch (Exception e) {
System.out.println("图像鉴黄线程执行过程中出现异常");
e.printStackTrace();
}
}
}
}
@@ -5,22 +5,23 @@ import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.utils.FTPUtils;
import cn.hellohao.utils.Print;
import cn.hellohao.utils.SetText;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Service
public class FTPImageupload {
static Keys key;
public ReturnImage ImageuploadFTP(Map<String, File> fileMap, String username,Integer keyID) {
public ReturnImage ImageuploadFTP(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
String[] host = key.getEndpoint().split("\\:");
String h = host[0];
@@ -28,27 +29,28 @@ public class FTPImageupload {
FTPUtils ftps = new FTPUtils(h, p, key.getAccessKey(), key.getAccessSecret());
boolean flag = ftps.open();
File file = null;
Map<ReturnImage, Integer> ImgUrl = new HashMap<>();
ftps.mkDir(File.separator+username);
ftps.mkDir(File.separator + username);
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String prefix = entry.getKey().get("prefix");
String ShortUIDName = entry.getKey().get("name");
file = entry.getValue();
String userkey =username + "/"+ ShortUID + "." + entry.getKey();
String userkey = username + "/" + ShortUIDName + "." + prefix;
if (flag) {
boolean isUpload = ftps.upload(file, "/" + userkey, "");
if(isUpload){
returnImage.setImgname(userkey);
returnImage.setImgurl(key.getRequestAddress() + "/"+ userkey);
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
}else{
returnImage.setCode("500");
if (isUpload) {
} else {
returnImage.setCode("400");
}
} else {
returnImage.setCode("400");
}
Print.Normal("要上传的文件路径:/"+userkey);
Print.Normal("要上传的文件路径:/" + userkey);
}
}catch (Exception e){
returnImage.setCode("200");
} catch (Exception e) {
e.printStackTrace();
returnImage.setCode("500");
}
@@ -57,55 +59,57 @@ public class FTPImageupload {
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getEndpoint()!=null && k.getRequestAddress()!=null ) {
if(!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getEndpoint().equals("") && !k.getRequestAddress().equals("") ) {
FTPClient ftp = new FTPClient();
ftp.setConnectTimeout(0);
int flag = k.getEndpoint().indexOf(":");
if(flag>0){
String[] host = k.getEndpoint().split("\\:");
String h = host[0];
Integer p = Integer.parseInt(host[1]);
try {
if(!ftp.isConnected()){
ftp.connect(h,p);
}
ftp.login(k.getAccessKey(), k.getAccessSecret());
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
System.out.println("FTP Object Is null");
ftp.disconnect();
return -1;
}
ret = 1;
key = k;
} catch (IOException e) {
System.out.println("FTP Object Is null");
return -1;
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
FTPClient ftp = new FTPClient();
ftp.setConnectTimeout(0);
int flag = k.getEndpoint().indexOf(":");
if (flag > 0) {
String[] host = k.getEndpoint().split("\\:");
String h = host[0];
Integer p = Integer.parseInt(host[1]);
try {
if (!ftp.isConnected()) {
ftp.connect(h, p);
}
ftp.login(k.getAccessKey(), k.getAccessSecret());
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
System.out.println("FTP Object Is null");
ftp.disconnect();
return -1;
}
ret = 1;
key = k;
} catch (IOException e) {
System.out.println("FTP Object Is null");
return -1;
}
}
return ret;
}
public static void fuzhi(String p1,String p2){
String a=p1;
try{
File afile=new File(a);
File bfile=new File(p2);//定义一个复制后的文件路径
public static void copyFile(String p1, String p2) {
String a = p1;
try {
File afile = new File(a);
File bfile = new File(p2); // 定义一个复制后的文件路径
bfile.createNewFile();
FileInputStream c=new FileInputStream(afile);
FileOutputStream d=new FileOutputStream(bfile);
byte[] date=new byte[512];
int i=0;
while((i=c.read(date))>0){
FileInputStream c = new FileInputStream(afile);
FileOutputStream d = new FileOutputStream(bfile);
byte[] date = new byte[512];
int i = 0;
while ((i = c.read(date)) > 0) {
d.write(date);
}
c.close();
d.close();
System.out.println("文件复制成功");}
catch(IOException e){
System.out.println("文件复制成功");
} catch (IOException e) {
e.printStackTrace();
}
}
@@ -116,7 +120,6 @@ public class FTPImageupload {
String[] host = key.getEndpoint().split("\\:");
String h = host[0];
Integer p = Integer.parseInt(host[1]);
//创建FTP客户端,所有的操作都基于FTPClinet
FTPUtils ftps = new FTPUtils(h, p, key.getAccessKey(), key.getAccessSecret());
ftps.open();
b = ftps.deleteFile(images.getImgname());
@@ -126,6 +129,4 @@ public class FTPImageupload {
}
return b;
}
}
@@ -1,13 +1,8 @@
package cn.hellohao.service.impl;
import cn.hellohao.config.GlobalConstant;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.pojo.UploadConfig;
import cn.hellohao.utils.*;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
@@ -18,14 +13,11 @@ import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.util.Auth;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Service
public class KODOImageupload {
@@ -33,7 +25,8 @@ public class KODOImageupload {
static BucketManager bucketManager;
static Keys key;
public ReturnImage ImageuploadKODO(Map<Map<String, String>, File> fileMap, String username, Integer keyID){
public ReturnImage ImageuploadKODO(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
Configuration cfg;
if (key.getEndpoint().equals("1")) {
@@ -83,40 +76,46 @@ public class KODOImageupload {
public static Integer Initialize(Keys k) {
int ret = -1;
if (k.getEndpoint() != null && k.getAccessSecret() != null && k.getEndpoint() != null
&& k.getBucketname() != null && k.getRequestAddress() != null) {
if (!k.getEndpoint().equals("") && !k.getAccessSecret() .equals("") && !k.getEndpoint() .equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress() .equals("")) {
Configuration cfg;
if (k.getEndpoint().equals("1")) {
cfg = new Configuration(Zone.zone0());
} else if (k.getEndpoint().equals("2")) {
cfg = new Configuration(Zone.zone1());
} else if (k.getEndpoint().equals("3")) {
cfg = new Configuration(Zone.zone2());
} else if (k.getEndpoint().equals("4")) {
cfg = new Configuration(Zone.zoneNa0());
} else {
cfg = new Configuration(Zone.zoneAs0());
}
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(k.getAccessKey(), k.getAccessSecret());
String upToken = auth.uploadToken(k.getBucketname(),null,7200,null);//auth.uploadToken(k.getBucketname());
BucketManager bmObj = new BucketManager(auth, cfg);
BucketManager.FileListIterator fileListIterator = null;
try {
fileListIterator = bmObj.createFileListIterator(k.getBucketname(), "", 1, "/");
FileInfo[] items = fileListIterator.next();
if(items!=null){
ret = 1;
bucketManager = bmObj;
key = k;
}
}catch (Exception e){
System.out.println("KODO Object Is null");
ret = -1;
}
if (org.apache.commons.lang3.StringUtils.isBlank(k.getAccessKey())
|| org.apache.commons.lang3.StringUtils.isBlank(k.getAccessSecret())
|| org.apache.commons.lang3.StringUtils.isBlank(k.getEndpoint())
|| org.apache.commons.lang3.StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
Configuration cfg;
if (k.getEndpoint().equals("1")) {
cfg = new Configuration(Zone.zone0());
} else if (k.getEndpoint().equals("2")) {
cfg = new Configuration(Zone.zone1());
} else if (k.getEndpoint().equals("3")) {
cfg = new Configuration(Zone.zone2());
} else if (k.getEndpoint().equals("4")) {
cfg = new Configuration(Zone.zoneNa0());
} else {
cfg = new Configuration(Zone.zoneAs0());
}
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(k.getAccessKey(), k.getAccessSecret());
String upToken =
auth.uploadToken(
k.getBucketname(),
null,
7200,
null); // auth.uploadToken(k.getBucketname());
BucketManager bmObj = new BucketManager(auth, cfg);
BucketManager.FileListIterator fileListIterator = null;
try {
fileListIterator = bmObj.createFileListIterator(k.getBucketname(), "", 1, "/");
FileInfo[] items = fileListIterator.next();
if (items != null) {
ret = 1;
bucketManager = bmObj;
key = k;
}
} catch (Exception e) {
System.out.println("KODO Object Is null");
ret = -1;
}
return ret;
}
@@ -130,6 +129,4 @@ public class KODOImageupload {
}
return b;
}
}
@@ -4,14 +4,13 @@ import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.Msg;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.utils.SetText;
import cn.hellohao.utils.TypeDict;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.ObjectListing;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.File;
@@ -22,7 +21,8 @@ public class OSSImageupload {
static OSS ossClient;
static Keys key;
public ReturnImage ImageuploadOSS(Map<Map<String, String>, File> fileMap, String username,Integer keyID){
public ReturnImage ImageuploadOSS(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
ObjectMetadata meta = new ObjectMetadata();
@@ -53,27 +53,31 @@ public class OSSImageupload {
public static Integer Initialize(Keys k) {
int ret = -1;
ObjectListing objectListing = null;
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getAccessKey()!=null && k.getEndpoint()!=null
&& k.getBucketname()!=null && k.getRequestAddress()!=null ) {
if(!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getAccessKey().equals("") && !k.getEndpoint().equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("") ) {
OSS ossObj = new OSSClientBuilder().build(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
try {
objectListing = ossObj.listObjects(k.getBucketname());
ret=1;
ossClient = ossObj;
key = k;
} catch (Exception e) {
System.out.println("OSS Object Is null");
ret = -1;
}
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())) {
return -1;
}
OSS ossObj =
new OSSClientBuilder()
.build(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
try {
objectListing = ossObj.listObjects(k.getBucketname());
ret = 1;
ossClient = ossObj;
key = k;
} catch (Exception e) {
System.out.println("OSS Object Is null");
ret = -1;
}
return ret;
}
public boolean delOSS(Integer keyID, Images images){
boolean b =true;
public boolean delOSS(Integer keyID, Images images) {
boolean b = true;
try {
ossClient.deleteObject(key.getBucketname(), images.getImgname());
} catch (Exception e) {
@@ -82,6 +86,4 @@ public class OSSImageupload {
}
return b;
}
}
@@ -9,6 +9,7 @@ import cn.hellohao.utils.TypeDict;
import com.UpYun;
import com.aliyun.oss.model.ObjectMetadata;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.List;
import java.util.Map;
@@ -18,47 +19,64 @@ public class UFileImageupload {
static UpYun uFile;
static Keys key;
public ReturnImage ImageuploadUFile(Map<String, File> fileMap, String username,Integer keyID) {
/*
* 废弃方法待补位
* */
public ReturnImage ImageuploadUFile(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
ObjectMetadata meta = new ObjectMetadata();
meta.setHeader("Content-Disposition", "inline");
try {
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
String ShortUID = SetText.getShortUuid();
file = entry.getValue();
Msg fileMiME = TypeDict.FileMiME(file);
meta.setHeader("content-type", fileMiME.getData().toString());
uFile.setContentMD5(UpYun.md5(file));
boolean result = uFile.writeFile(username + "/" + ShortUID + "." + entry.getKey(), file, true);
if(result){
boolean result =
uFile.writeFile(
username + "/" + ShortUID + "." + entry.getKey(), file, true);
if (result) {
returnImage.setImgname(username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgurl(key.getRequestAddress() + "/" +username + "/" + ShortUID + "." + entry.getKey());
returnImage.setImgurl(
key.getRequestAddress()
+ "/"
+ username
+ "/"
+ ShortUID
+ "."
+ entry.getKey());
returnImage.setImgSize(entry.getValue().length());
returnImage.setCode("200");
}else{
} else {
returnImage.setCode("400");
System.err.println("上传失败");
}
}
}catch(Exception e){
} catch (Exception e) {
returnImage.setCode("500");
}
returnImage.setCode("500");
return returnImage;
}
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getAccessSecret()!=null && k.getAccessKey()!=null
&& k.getBucketname()!=null && k.getRequestAddress()!=null ) {
if(!k.getAccessSecret().equals("") && !k.getAccessKey().equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("") ) {
if (k.getAccessSecret() != null
&& k.getAccessKey() != null
&& k.getBucketname() != null
&& k.getRequestAddress() != null) {
if (!k.getAccessSecret().equals("")
&& !k.getAccessKey().equals("")
&& !k.getBucketname().equals("")
&& !k.getRequestAddress().equals("")) {
UpYun ufObj = new UpYun(k.getBucketname(), k.getAccessKey(), k.getAccessSecret());
List<UpYun.FolderItem> items = null;
try {
items = ufObj.readDir("/",null);
items = ufObj.readDir("/", null);
ret = 1;
uFile = ufObj;
key = k;
@@ -81,5 +99,4 @@ public class UFileImageupload {
}
return b;
}
}
@@ -4,11 +4,12 @@ import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.Msg;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.utils.SetText;
import cn.hellohao.utils.TypeDict;
import com.UpYun;
import com.aliyun.oss.model.ObjectMetadata;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.List;
import java.util.Map;
@@ -18,7 +19,8 @@ public class USSImageupload {
static UpYun upyun;
static Keys key;
public ReturnImage ImageuploadUSS(Map<Map<String, String>, File> fileMap, String username,Integer keyID) {
public ReturnImage ImageuploadUSS(
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
ReturnImage returnImage = new ReturnImage();
File file = null;
ObjectMetadata meta = new ObjectMetadata();
@@ -46,30 +48,30 @@ public class USSImageupload {
returnImage.setCode("500");
}
return returnImage;
}
//初始化
// 初始化
public static Integer Initialize(Keys k) {
int ret = -1;
if(k.getStorageType()!=null && k.getAccessKey() != null && k.getAccessSecret() != null && k.getBucketname() != null
&& k.getRequestAddress() !=null ) {
if(!k.getStorageType().equals("") && !k.getAccessKey().equals("") && !k.getAccessSecret().equals("") && !k.getBucketname().equals("")
&& !k.getRequestAddress().equals("") ) {
// 初始化
// 创建UpYun实例。
UpYun upObj= new UpYun(k.getBucketname(), k.getAccessKey(), k.getAccessSecret());
List<UpYun.FolderItem> items = null;
try {
items = upObj.readDir("/",null);
ret = 1;
upyun = upObj;
key = k;
} catch (Exception e) {
System.out.println("USS Object Is null");
ret = -1;
}
}
if (StringUtils.isBlank(k.getAccessKey())
|| StringUtils.isBlank(k.getKeyname())
|| StringUtils.isBlank(k.getAccessSecret())
|| StringUtils.isBlank(k.getEndpoint())
|| StringUtils.isBlank(k.getBucketname())
|| StringUtils.isBlank(k.getRequestAddress())
|| k.getStorageType() == null) {
return -1;
}
UpYun upObj = new UpYun(k.getBucketname(), k.getAccessKey(), k.getAccessSecret());
List<UpYun.FolderItem> items = null;
try {
items = upObj.readDir("/", null);
ret = 1;
upyun = upObj;
key = k;
} catch (Exception e) {
System.out.println("USS Object Is null");
ret = -1;
}
return ret;
}
@@ -80,10 +82,8 @@ public class USSImageupload {
boolean result = upyun.deleteFile(images.getImgname(), null);
} catch (Exception e) {
e.printStackTrace();
b=false;
b = false;
}
return b;
}
}
@@ -3,7 +3,6 @@ package cn.hellohao.service.impl;
import cn.hellohao.dao.*;
import cn.hellohao.pojo.*;
import cn.hellohao.service.ImgTempService;
import cn.hellohao.service.SysConfigService;
import cn.hellohao.utils.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@@ -27,57 +26,49 @@ import java.util.*;
* @version 1.0
* @date 2020/1/9 15:46
*/
@Service
public class UploadServicel {
@Autowired
ConfigMapper configMapper;
@Autowired
SysConfigService sysConfigService;
@Autowired
UploadConfigMapper uploadConfigMapper;
@Autowired
KeysMapper keysMapper;
@Autowired
ImgMapper imgMapper;
@Autowired
UserMapper userMapper;
@Autowired
ImgreviewMapper imgreviewMapper;
@Autowired
ImgTempService imgTempService;
@Autowired private UploadConfigMapper uploadConfigMapper;
@Autowired private KeysMapper keysMapper;
@Autowired private ImgMapper imgMapper;
@Autowired private UserMapper userMapper;
@Autowired private ImgreviewMapper imgreviewMapper;
@Autowired private ImgTempService imgTempService;
@Autowired private KeysServiceImpl keysService;
public Msg uploadForLoc(HttpServletRequest request,
MultipartFile multipartFile, Integer setday, String imgUrl) {
public Msg uploadForLoc(
HttpServletRequest request,
MultipartFile multipartFile,
Integer setday,
String imgUrl) {
Msg msg = new Msg();
try{
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
JSONObject jsonObject = new JSONObject();
UploadConfig uploadConfig = uploadConfigMapper.getUpdateConfig();
String userip = GetIPS.getIpAddr(request);
Subject subject = SecurityUtils.getSubject();
User u = (User) subject.getPrincipal();
if(null!=u){
u = userMapper.getUsers(u);
if (null != u) {
u = userMapper.getUsers(u);
}
Integer sourceKeyId = 0;
String md5key = null;
FileInputStream fis = null;
File file =null;
if(imgUrl==null){
File file = null;
if (imgUrl == null) {
file = SetFiles.changeFile_new(multipartFile);
}else{
} else {
Msg imgData = uploadForURL(request, imgUrl);
if(imgData.getCode().equals("200")){
if (imgData.getCode().equals("200")) {
file = new File((String) imgData.getData());
}else{
} else {
return imgData;
}
}
String imguid = UUID.randomUUID().toString().replace("-", "");
Msg msg1 = updateImgCheck(u,uploadConfig);
if(!msg1.getCode().equals("300")){
Msg msg1 = updateImgCheck(u, uploadConfig);
if (!msg1.getCode().equals("300")) {
return msg1;
}
sourceKeyId = group.getKeyid();
@@ -85,12 +76,12 @@ public class UploadServicel {
Long tmp = (memory == -1 ? -2 : UsedTotleMemory);
if (tmp >= memory) {
msg.setCode("4005");
msg.setInfo(u==null?"游客空间已用尽":"您的可用空间不足");
msg.setInfo(u == null ? "游客空间已用尽" : "您的可用空间不足");
return msg;
}
if (file.length() > TotleMemory) {
System.err.println("文件大小:"+file.length());
System.err.println("最大限制:"+TotleMemory);
System.err.println("文件大小:" + file.length());
System.err.println("最大限制:" + TotleMemory);
msg.setCode("4006");
msg.setInfo("图像超出系统限制大小");
return msg;
@@ -103,29 +94,29 @@ public class UploadServicel {
System.out.println("未获取到图片的MD5,成成UUID");
}
Msg fileMiME = TypeDict.FileMiME(file);
if(!fileMiME.getCode().equals("200")) {
if (!fileMiME.getCode().equals("200")) {
msg.setCode("4000");
msg.setInfo(fileMiME.getInfo());
return msg;
}
if(md5key==null || md5key.equals("")){
if (md5key == null || md5key.equals("")) {
md5key = UUID.randomUUID().toString().replace("-", "");
}
// if(Integer.valueOf(sysConfigService.getstate().getCheckduplicate())==1){
// Images imaOBJ = new Images();
// imaOBJ.setMd5key(md5key);
// imaOBJ.setUserid(u==null?0:u.getId());
// if(imgMapper.md5Count(imaOBJ)>0){
// List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
// jsonObject.put("url", images.get(0).getImgurl());
// jsonObject.put("name",file.getName());
// jsonObject.put("imguid",images.get(0).getImguid());
// msg.setData(jsonObject);
// return msg;
// }
// }
String prefix = file.getName().substring(file.getName().lastIndexOf(".")+1);
//判断黑名单
// if(Integer.valueOf(sysConfigService.getstate().getCheckduplicate())==1){
// Images imaOBJ = new Images();
// imaOBJ.setMd5key(md5key);
// imaOBJ.setUserid(u==null?0:u.getId());
// if(imgMapper.md5Count(imaOBJ)>0){
// List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
// jsonObject.put("url", images.get(0).getImgurl());
// jsonObject.put("name",file.getName());
// jsonObject.put("imguid",images.get(0).getImguid());
// msg.setData(jsonObject);
// return msg;
// }
// }
String prefix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
// 判断黑名单
if (uploadConfig.getBlacklist() != null) {
String[] iparr = uploadConfig.getBlacklist().split(";");
for (String s : iparr) {
@@ -138,63 +129,60 @@ public class UploadServicel {
}
}
// 先存数据库
final Images imgObj = new Images();
Images imgObj = new Images();
String imgnameEd = null;
final Map<Map<String, String>, File> map = new HashMap<>();
Map<Map<String, String>, File> map = new HashMap<>();
if (file.exists()) {
Map<String, String> m1 = new HashMap<>();
String shortUuid_y = SetText.getShortUuid();
m1.put("prefix", prefix);
m1.put("name", shortUuid_y);
map.put(m1, file);
// map.put(prefix, file);
imgnameEd = updatePath + "/" + shortUuid_y + "." + prefix;
imgObj.setImgname(imgnameEd);
if(key.getStorageType().equals(5)){
if (key.getStorageType().equals(5)) {
imgObj.setImgurl(key.getRequestAddress() + "/ota/" + imgnameEd);
}else {
} else {
imgObj.setImgurl(key.getRequestAddress() + "/" + imgnameEd);
}
imgObj.setSizes(Long.toString(file.length()));
}
imgObj.setUpdatetime(df.format(new Date()));
imgObj.setSource(key.getId());
imgObj.setUserid(u == null ? 0 : u.getId());
if(setday == 1 || setday == 3 || setday == 7 || setday == 30){
if (setday == 1 || setday == 3 || setday == 7 || setday == 30) {
imgObj.setImgtype(1);
ImgTemp imgDataExp = new ImgTemp();
imgDataExp.setDeltime(plusDay(setday));
imgDataExp.setImguid(imguid);
imgTempService.insertImgExp(imgDataExp);
}else{
} else {
imgObj.setImgtype(0);
}
imgObj.setAbnormal(userip);
imgObj.setMd5key(md5key);
imgObj.setImguid(imguid);
imgObj.setFormat(fileMiME.getData().toString());
userMapper.insertimg(imgObj);
final Integer insertRet = imgMapper.insertImgData(imgObj);
Integer insertRet = imgMapper.insertImgData(imgObj);
if (insertRet == 0) {
Images imaOBJ = new Images();
imaOBJ.setMd5key(md5key);
imaOBJ.setUserid(u == null ? 0 : u.getId());
List<Images> images = imgMapper.selectImgUrlByMD5(md5key);
if (images.size() > 0) {
Keys imgFromKey = keysService.selectKeys(images.get(0).getSource());
if(imgFromKey.getStorageType().equals(5)){
jsonObject.put("url",imgFromKey.getRequestAddress() + "/ota/"+ images.get(0).getImgname());
}else{
jsonObject.put("url", images.get(0).getImgurl());
}
jsonObject.put("url", images.get(0).getImgurl());
// Keys imgFromKey = keysService.selectKeys(images.get(0).getSource());
// if (imgFromKey.getStorageType().equals(5)) {
// jsonObject.put(
// "url",
// imgFromKey.getRequestAddress()
// + "/ota/"
// + images.get(0).getImgname());
// } else {
// jsonObject.put("url", images.get(0).getImgurl());
// }
jsonObject.put("name", file.getName());
jsonObject.put("imguid", images.get(0).getImguid());
System.err.println("已经有啦,哈哈哈哈哈啊哈!!!!!!!!");
System.err.println(jsonObject.toJSONString());
msg.setData(jsonObject);
return msg;
} else {
@@ -204,18 +192,20 @@ public class UploadServicel {
}
}
long stime = System.currentTimeMillis();
Map<ReturnImage, Integer> m = null;
ReturnImage returnImage = GetSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
if(returnImage.getCode().equals("200")){
ReturnImage returnImage =
GetSource.storageSource(key.getStorageType(), map, updatePath, key.getId());
if (returnImage.getCode().equals("200")) {
long etime = System.currentTimeMillis();
Print.Normal("上传图片所用总时长:" + String.valueOf(etime - stime) + "ms");
jsonObject.put("url", img.getImgurl());
jsonObject.put("name", imgname);
jsonObject.put("imguid",img.getImguid());
new Thread(()->{LegalImageCheck(img);}).start();
}else{
jsonObject.put("url", imgObj.getImgurl());
jsonObject.put("name", imgObj.getImgname());
jsonObject.put("imguid", imgObj.getImguid());
new Thread(
() -> {
LegalImageCheck(imgObj);
})
.start();
} else {
msg.setCode("5001");
msg.setInfo("上传服务内部错误");
return msg;
@@ -223,37 +213,40 @@ public class UploadServicel {
file.delete();
msg.setData(jsonObject);
return msg;
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
msg.setInfo("上传时发生了一些错误");
msg.setCode("110500");
return msg;
}
}
public static Msg uploadForURL(HttpServletRequest request, String imgurl){
final Msg msg = new Msg();
if(true){
public static Msg uploadForURL(HttpServletRequest request, String imgurl) {
Msg msg = new Msg();
if (true) {
Long imgsize = 0L;
try {
if(imgsize==0){
if (imgsize == 0) {
String ShortUID = SetText.getShortUuid();
String savePath = request.getSession().getServletContext().getRealPath("/")+File.separator+"hellohaotmp"+File.separator;
Map<String ,Object> bl =ImgUrlUtil.downLoadFromUrl (imgurl, ShortUID, savePath);
if((Boolean) bl.get("res")==true){
String savePath =
request.getSession().getServletContext().getRealPath("/")
+ File.separator
+ "hellohaotmp"
+ File.separator;
Map<String, Object> bl = ImgUrlUtil.downLoadFromUrl(imgurl, ShortUID, savePath);
if ((Boolean) bl.get("res") == true) {
msg.setCode("200");
msg.setData(bl.get("imgPath"));
return msg;
}else{
if(bl.get("StatusCode").equals("110403")){
} else {
if (bl.get("StatusCode").equals("110403")) {
msg.setInfo("该链接非图像文件,无法上传");
}else{
} else {
msg.setInfo("该链接暂时无法上传");
}
msg.setCode("500");
}
}else{
} else {
msg.setCode("500");
msg.setInfo("获取资源失败");
}
@@ -261,7 +254,7 @@ public class UploadServicel {
msg.setCode("500");
msg.setInfo("获取资源失败");
}
}else{
} else {
msg.setCode("500");
msg.setInfo("该链接无效");
}
@@ -269,40 +262,46 @@ public class UploadServicel {
return msg;
}
private static Group group; //上传用户或游客的所属分组
private static Long memory;//上传用户或者游客的分配容量 memory
private static Long TotleMemory;//用户或者游客下可使用的总容量 //maxsize
private static Long UsedTotleMemory;//用户或者游客已经用掉的总容量 //usermemory
private static String updatePath="tourist";
private static Group group; // 上传用户或游客的所属分组
private static Long memory; // 上传用户或者游客的分配容量 memory
private static Long TotleMemory; // 用户或者游客下可使用的总容量 //maxsize
private static Long UsedTotleMemory; // 用户或者游客已经用掉的总容量 //usermemory
private static String updatePath = "tourist";
//判断用户 或 游客 当前上传图片的一系列校验
private Msg updateImgCheck(User user, UploadConfig uploadConfig){
final Msg msg = new Msg();
// 判断用户 或 游客 当前上传图片的一系列校验
private Msg updateImgCheck(User user, UploadConfig uploadConfig) {
Msg msg = new Msg();
java.text.DateFormat dateFormat = null;
try {
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
if (user == null) {
if(uploadConfig.getIsupdate()!=1){
if (uploadConfig.getIsupdate() != 1) {
msg.setCode("1000");
msg.setInfo("系统已禁用游客上传");
return msg;
}
updatePath="tourist";
updatePath = "tourist";
group = GetCurrentSource.GetSource(null);
memory = Long.valueOf(uploadConfig.getVisitormemory());//单位 B 游客设置总量
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists());//单位 B 游客单文件大小
UsedTotleMemory = imgMapper.getusermemory(0)==null?0L : imgMapper.getusermemory(0);//单位 B
memory = Long.valueOf(uploadConfig.getVisitormemory()); // 单位 B 游客设置总量
TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists()); // 单位 B 游客单文件大小
UsedTotleMemory =
imgMapper.getusermemory(0) == null
? 0L
: imgMapper.getusermemory(0); // 单位 B
} else {
if(uploadConfig.getUserclose()!=1){
if (uploadConfig.getUserclose() != 1) {
msg.setCode("1001");
msg.setInfo("系统已禁用上传功能");
return msg;
}
updatePath = user.getUsername();
group= GetCurrentSource.GetSource(user.getId());
memory = Long.valueOf(user.getMemory());//单位 B *1024*1024
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser());//单位 B
UsedTotleMemory = imgMapper.getusermemory(user.getId())==null?0L:imgMapper.getusermemory(user.getId());//单位 B
group = GetCurrentSource.GetSource(user.getId());
memory = Long.valueOf(user.getMemory()); // 单位 B *1024*1024
TotleMemory = Long.valueOf(uploadConfig.getFilesizeuser()); // 单位 B
UsedTotleMemory =
imgMapper.getusermemory(user.getId()) == null
? 0L
: imgMapper.getusermemory(user.getId()); // 单位 B
}
if (uploadConfig.getUrltype() == 2) {
updatePath = dateFormat.format(new Date());
@@ -315,7 +314,7 @@ public class UploadServicel {
return msg;
}
private synchronized void LegalImageCheck(Images images){
private synchronized void LegalImageCheck(Images images) {
System.out.println("非法图像鉴别进程启动");
Imgreview imgreview = null;
try {
@@ -324,31 +323,37 @@ public class UploadServicel {
Print.warning("获取鉴别程序的时候发生错误");
e.printStackTrace();
}
if(null != imgreview){
LegalImageCheckForBaiDu(imgreview,images);
if (null != imgreview) {
LegalImageCheckForBaiDu(imgreview, images);
}
}
private void LegalImageCheckForBaiDu(Imgreview imgreview,Images images){
private void LegalImageCheckForBaiDu(Imgreview imgreview, Images images) {
System.out.println("非法图像鉴别进程启动-BaiDu");
if(imgreview.getUsing()==1){
if (imgreview.getUsing() == 1) {
try {
AipContentCensor client = new AipContentCensor(imgreview.getAppId(), imgreview.getApiKey(), imgreview.getSecretKey());
AipContentCensor client =
new AipContentCensor(
imgreview.getAppId(),
imgreview.getApiKey(),
imgreview.getSecretKey());
client.setConnectionTimeoutInMillis(5000);
client.setSocketTimeoutInMillis(30000);
org.json.JSONObject res = client.antiPorn(images.getImgurl());
res = client.imageCensorUserDefined(images.getImgurl(), EImgType.URL, null);
System.err.println("返回的鉴黄json:"+res.toString());
com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray("[" + res.toString() + "]");
System.err.println("返回的鉴黄json:" + res.toString());
com.alibaba.fastjson.JSONArray jsonArray =
JSON.parseArray("[" + res.toString() + "]");
for (Object o : jsonArray) {
com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject) o;
com.alibaba.fastjson.JSONObject jsonObject =
(com.alibaba.fastjson.JSONObject) o;
com.alibaba.fastjson.JSONArray data = jsonObject.getJSONArray("data");
Integer conclusionType = jsonObject.getInteger("conclusionType");
if(conclusionType!=null){
if (conclusionType != null) {
if (conclusionType == 2) {
for (Object datum : data) {
com.alibaba.fastjson.JSONObject imgdata = (com.alibaba.fastjson.JSONObject) datum;
com.alibaba.fastjson.JSONObject imgdata =
(com.alibaba.fastjson.JSONObject) datum;
if (imgdata.getInteger("type") == 1) {
Images img = new Images();
img.setImgname(images.getImgname());
@@ -367,29 +372,25 @@ public class UploadServicel {
}
}
}catch (Exception e){
} catch (Exception e) {
System.out.println("图像鉴黄线程执行过程中出现异常");
e.printStackTrace();
}
}
}
//计算时间
public static String plusDay(int setday){
// 计算时间
public static String plusDay(int setday) {
Date d = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currdate = format.format(d);
System.out.println("现在的日期是:" + currdate);
Calendar ca = Calendar.getInstance();
ca.setTime(d);
ca.add(Calendar.DATE, setday);// num为增加的天数,可以改变的
ca.add(Calendar.DATE, setday); // num为增加的天数,可以改变的
d = ca.getTime();
String enddate = format.format(d);
System.out.println("到期的日期:" + enddate);
return enddate;
}
}
@@ -3,7 +3,6 @@ package cn.hellohao.service.impl;
import cn.hellohao.dao.CodeMapper;
import cn.hellohao.dao.UserMapper;
import cn.hellohao.exception.CodeException;
import cn.hellohao.pojo.Images;
import cn.hellohao.pojo.User;
import cn.hellohao.service.UserService;
import cn.hellohao.utils.Print;
@@ -42,11 +41,6 @@ public class UserServiceImpl implements UserService {
return userMapper.getUsers(user);
}
@Override
public Integer insertimg(Images img) {
// TODO Auto-generated method stub
return userMapper.insertimg(img);
}
@Override
public Integer change(User user) {
+3 -4
View File
@@ -110,10 +110,9 @@
null violation,
#{idname} idname
) temp_t
where not exists (
select md5key from imgdata img_t where temp_t.md5key = img_t.md5key
) and (select (select checkduplicate from sysconfig where id =1)=1)
where
IF((select (select checkduplicate from sysconfig where id =1)=1),
not exists (select md5key from imgdata img_t where temp_t.md5key = img_t.md5key),true)
</insert>
+4 -4
View File
@@ -116,10 +116,10 @@
</select>
<!-- 插入图片信息 -->
<insert id="insertimg" parameterType="cn.hellohao.pojo.Images">
INSERT INTO imgdata (id, imgname, imgurl, userid, updatetime,sizes,abnormal,source,imgtype,md5key,imguid,format,about,violation)
VALUES (NULL, #{imgname}, #{imgurl}, #{userid}, #{updatetime},#{sizes},#{abnormal},#{source},#{imgtype},#{md5key},#{imguid},#{format},#{about},null)
</insert>
<!-- <insert id="insertimg" parameterType="cn.hellohao.pojo.Images">-->
<!-- INSERT INTO imgdata (id, imgname, imgurl, userid, updatetime,sizes,abnormal,source,imgtype,md5key,imguid,format,about,violation)-->
<!-- VALUES (NULL, #{imgname}, #{imgurl}, #{userid}, #{updatetime},#{sizes},#{abnormal},#{source},#{imgtype},#{md5key},#{imguid},#{format},#{about},null)-->
<!-- </insert>-->
<!-- 修改资料 -->
<update id="change" parameterType="cn.hellohao.pojo.User">