mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
Hellohao图床6-12更新
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package cn.hellohao;
|
||||
|
||||
import cn.hellohao.pojo.Imgreview;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.service.ImgreviewService;
|
||||
import cn.hellohao.utils.ImageReview;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JianHuangThread extends Thread {
|
||||
|
||||
private Keys key;
|
||||
private Map hashMap;
|
||||
private ImgreviewService imgreviewService;
|
||||
private User user;
|
||||
|
||||
public JianHuangThread(ImgreviewService imgreviewService, Keys keys, User user, Map<String, Integer> hashMap) {
|
||||
this.key = keys;
|
||||
this.user = user;
|
||||
this.imgreviewService = imgreviewService;
|
||||
this.hashMap = hashMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
|
||||
if (user != null) {
|
||||
ImageReview.imgJB(hashMap, key.getRequestAddress() + "/", key, imgreview);
|
||||
} else {
|
||||
ImageReview.imgJB(hashMap, key.getRequestAddress() + "/", key, imgreview);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
public class TbedApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TbedApplication.class, args);
|
||||
|
||||
}
|
||||
/**
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TbedApplication.class, args);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传配置
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
|
||||
@@ -1,146 +1,374 @@
|
||||
package cn.hellohao.controller;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.pojo.*;
|
||||
import cn.hellohao.pojo.vo.PageResultBean;
|
||||
import cn.hellohao.service.ImgService;
|
||||
import cn.hellohao.service.KeysService;
|
||||
import cn.hellohao.service.UserService;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.service.impl.ImgServiceImpl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admin")
|
||||
public class AdminController {
|
||||
|
||||
@Autowired
|
||||
private ImgService imgService;
|
||||
@Autowired
|
||||
private KeysService keysService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private ImgService imgService;
|
||||
@Autowired
|
||||
private KeysService keysService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private ImgreviewService imgreviewService;
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
@Autowired
|
||||
private EmailConfigService emailConfigService;
|
||||
|
||||
// 进入后台页面
|
||||
@RequestMapping(value = "/admin.do")
|
||||
public String goadmin(HttpSession session, Model model, HttpServletRequest request) {
|
||||
Integer storageType1 = (Integer) session.getAttribute("storageType");
|
||||
Integer storageType = keysService.selectKeysType();
|
||||
Keys key = keysService.selectKeys(storageType);
|
||||
User u = (User) session.getAttribute("user");
|
||||
if(u.getLevel()>1) {
|
||||
model.addAttribute("counts", imgService.counts(null));
|
||||
model.addAttribute("getUserTotal", userService.getUserTotal());
|
||||
}else {
|
||||
model.addAttribute("counts", imgService.countimg(u.getId()));
|
||||
}
|
||||
model.addAttribute("username", u.getUsername());
|
||||
model.addAttribute("level", u.getLevel());
|
||||
model.addAttribute("email", u.getEmail());
|
||||
model.addAttribute("loginid", 100);
|
||||
//key信息
|
||||
model.addAttribute("AccessKey", key.getAccessKey());
|
||||
model.addAttribute("AccessSecret", key.getAccessSecret());
|
||||
model.addAttribute("Endpoint", key.getEndpoint());
|
||||
model.addAttribute("Bucketname", key.getBucketname());
|
||||
model.addAttribute("RequestAddress", key.getRequestAddress());
|
||||
model.addAttribute("StorageType", storageType);
|
||||
model.addAttribute("text_foot", "<li><a href=\"http://www.hellohao.cn/\" target=\"_blank\">Hellohao ©</a></li><li>切勿上传违反中华人民共和国互联网法律条约资源</li>");
|
||||
if (u.getLevel() > 1) {
|
||||
model.addAttribute("htgl",
|
||||
"<input id=\"isadmin\" onclick=\"openLoginModal();\" class=\"btn btn-default\" type=\"button\" value=\"后台管理\">");
|
||||
}
|
||||
return "admin/table";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/selecttable.do")
|
||||
@ResponseBody
|
||||
public PageResultBean<Images> selectByFy(HttpSession session, Integer pageNum, Integer pageSize) {
|
||||
User u = (User) session.getAttribute("user");
|
||||
// 使用Pagehelper传入当前页数和页面显示条数会自动为我们的select语句加上limit查询
|
||||
// 从他的下一条sql开始分页
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Images> images = null;
|
||||
if(u.getLevel()>1){ //根据用户等级查询管理员查询所有的信息
|
||||
images = imgService.selectimg(null);// 这是我们的sql
|
||||
}else{
|
||||
images = imgService.selectimg(u.getId());// 这是我们的sql
|
||||
}
|
||||
// 使用pageInfo包装查询
|
||||
PageInfo<Images> rolePageInfo = new PageInfo<>(images);//
|
||||
return new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
|
||||
}
|
||||
|
||||
@PostMapping("/updatekey.do")
|
||||
@ResponseBody
|
||||
public String updatekey(Keys key) {
|
||||
Integer ret = keysService.updateKey(key);
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.add(ret);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
@PostMapping("/deleimg.do")
|
||||
@ResponseBody
|
||||
public String deleimg(HttpSession session,Integer id) {
|
||||
Integer storageType = (Integer) session.getAttribute("storageType");
|
||||
Images images = imgService.selectByPrimaryKey(id);
|
||||
Keys key = keysService.selectKeys(storageType);
|
||||
ImgServiceImpl de = new ImgServiceImpl();
|
||||
de.delect(key, images.getImgname());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Integer ret = imgService.deleimg(id);
|
||||
jsonArray.add(ret);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
//修改资料
|
||||
@PostMapping("/change.do")
|
||||
@ResponseBody
|
||||
public String change(HttpSession session,User user) {
|
||||
System.out.println(user.getUsername());
|
||||
Integer count = userService.checkUsername(user.getUsername());
|
||||
User u = (User) session.getAttribute("user");
|
||||
user.setEmail(u.getEmail());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
if(count==0) {
|
||||
Integer ret = userService.change(user);
|
||||
jsonArray.add(ret);
|
||||
if(u.getEmail()!=null&&u.getPassword()!=null) {
|
||||
session.removeAttribute("user");
|
||||
//刷新view
|
||||
session.invalidate();
|
||||
}
|
||||
|
||||
}else {
|
||||
jsonArray.add("-1");
|
||||
}
|
||||
// -1 用户名重复
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/goadmin")
|
||||
public String goadmin1(HttpSession session, Model model, HttpServletRequest request) {
|
||||
User user = (User) session.getAttribute("user");
|
||||
if (user.getLevel() == 1) {
|
||||
model.addAttribute("level", "普通用户");
|
||||
} else if (user.getLevel() == 2) {
|
||||
model.addAttribute("level", "管理员");
|
||||
} else {
|
||||
model.addAttribute("level", "未 知");
|
||||
}
|
||||
model.addAttribute("levels", user.getLevel());
|
||||
model.addAttribute("username", user.getUsername());
|
||||
return "admin/index";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/images/{id}")
|
||||
@ResponseBody
|
||||
public Images selectByFy(@PathVariable("id") Integer id) {
|
||||
return imgService.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
// 进入后台页面
|
||||
@RequestMapping(value = "/admin")
|
||||
public String goadmin(HttpSession session, Model model, HttpServletRequest request) {
|
||||
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
|
||||
Keys key = keysService.selectKeys(config.getSourcekey());
|
||||
User u = (User) session.getAttribute("user");
|
||||
Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
|
||||
// if (u.getLevel() > 1) {
|
||||
// //管理员
|
||||
// model.addAttribute("counts", imgService.counts(null));
|
||||
// } else {
|
||||
// //个人用户
|
||||
// //model.addAttribute("counts", imgService.countimg(u.getId()));//这个是根据用户id查询他的图片数
|
||||
//
|
||||
// }
|
||||
model.addAttribute("usercount", imgService.countimg(u.getId()));//这个是根据用户id查询他的图片数
|
||||
model.addAttribute("counts", imgService.counts(null) + 1000);//总数
|
||||
model.addAttribute("getUserTotal", userService.getUserTotal() + 100);
|
||||
model.addAttribute("imgreviewcount", imgreview.getCount());
|
||||
model.addAttribute("username", u.getUsername());
|
||||
model.addAttribute("level", u.getLevel());
|
||||
model.addAttribute("email", u.getEmail());
|
||||
model.addAttribute("loginid", 100);
|
||||
model.addAttribute("source", key.getStorageType());
|
||||
|
||||
//key信息
|
||||
// model.addAttribute("AccessKey", key.getAccessKey());
|
||||
// model.addAttribute("AccessSecret", key.getAccessSecret());
|
||||
// model.addAttribute("Endpoint", key.getEndpoint());
|
||||
// model.addAttribute("Bucketname", key.getBucketname());
|
||||
// model.addAttribute("RequestAddress", key.getRequestAddress());
|
||||
// model.addAttribute("StorageType", storageType);
|
||||
// if (u.getLevel() > 1) {
|
||||
//// model.addAttribute("htgl",
|
||||
//// "<a href=\"#home\" onclick=\"showRegisterForm();\" data-toggle=\"tab\">系统配置</a>");
|
||||
////
|
||||
//// }
|
||||
return "admin/table";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/selecttable")
|
||||
@ResponseBody
|
||||
public PageResultBean<Images> selectByFy(HttpSession session, Integer pageNum, Integer pageSize, Integer selecttype) {
|
||||
User u = (User) session.getAttribute("user");
|
||||
// 使用Pagehelper传入当前页数和页面显示条数会自动为我们的select语句加上limit查询
|
||||
// 从他的下一条sql开始分页
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Images> images = null;
|
||||
if (u.getLevel() > 1) { //根据用户等级查询管理员查询所有的信息
|
||||
if (selecttype == 1) {
|
||||
images = imgService.selectimg(null);// 这是我们的sql
|
||||
} else {
|
||||
images = imgService.selectimg(u.getId());// 这是我们的sql
|
||||
}
|
||||
} else {
|
||||
images = imgService.selectimg(u.getId());// 这是我们的sql
|
||||
}
|
||||
// 使用pageInfo包装查询
|
||||
PageInfo<Images> rolePageInfo = new PageInfo<>(images);//
|
||||
return new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
|
||||
}
|
||||
|
||||
//获取用户信息列表
|
||||
@RequestMapping(value = "/selectusertable")
|
||||
@ResponseBody
|
||||
public PageResultBean<User> selectByFy1(HttpSession session, Integer pageNum, Integer pageSize) {
|
||||
User u = (User) session.getAttribute("user");
|
||||
// 使用Pagehelper传入当前页数和页面显示条数会自动为我们的select语句加上limit查询
|
||||
// 从他的下一条sql开始分页
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<User> users = null;
|
||||
if (u.getLevel() > 1) { //根据用户等级查询管理员查询所有的信息
|
||||
users = userService.getuserlist();// 这是我们的sql
|
||||
// 使用pageInfo包装查询
|
||||
PageInfo<User> rolePageInfo = new PageInfo<>(users);//
|
||||
return new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//返回对象存储界面
|
||||
@RequestMapping(value = "/root/touser")
|
||||
public String touser() {
|
||||
return "admin/user";
|
||||
}
|
||||
|
||||
//获取用户信息列表
|
||||
@RequestMapping(value = "/selectusertable2")
|
||||
@ResponseBody
|
||||
public Map<String, Object> selectByFy12(HttpSession session, @RequestParam(required = false, defaultValue = "1") int page,
|
||||
@RequestParam(required = false) int limit) {
|
||||
User u = (User) session.getAttribute("user");
|
||||
// 使用Pagehelper传入当前页数和页面显示条数会自动为我们的select语句加上limit查询
|
||||
// 从他的下一条sql开始分页
|
||||
PageHelper.startPage(page, limit);
|
||||
List<User> users = null;
|
||||
if (u.getLevel() > 1) { //根据用户等级查询管理员查询所有的信息
|
||||
users = userService.getuserlist();// 这是我们的sql
|
||||
// 使用pageInfo包装查询
|
||||
PageInfo<User> rolePageInfo = new PageInfo<>(users);//
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("code", 0);
|
||||
map.put("msg", "");
|
||||
map.put("count", rolePageInfo.getTotal());
|
||||
map.put("data", rolePageInfo.getList());
|
||||
return map;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//返回对象存储界面
|
||||
@RequestMapping(value = "/root/tostorage")
|
||||
public String tostorage(HttpSession session, Model model, HttpServletRequest request) {
|
||||
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
|
||||
Keys key = keysService.selectKeys(config.getSourcekey());
|
||||
//key信息
|
||||
model.addAttribute("AccessKey", key.getAccessKey());
|
||||
model.addAttribute("AccessSecret", key.getAccessSecret());
|
||||
model.addAttribute("Endpoint", key.getEndpoint());
|
||||
model.addAttribute("Bucketname", key.getBucketname());
|
||||
model.addAttribute("RequestAddress", key.getRequestAddress());
|
||||
model.addAttribute("StorageType", config.getSourcekey());
|
||||
return "admin/storageconfig";
|
||||
}
|
||||
|
||||
//根据下拉框选的存储源查询对应的key
|
||||
@PostMapping("/root/getkey")
|
||||
@ResponseBody
|
||||
public String getkey(Integer storageType) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Keys key = keysService.selectKeys(storageType);
|
||||
jsonArray.add(key);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
@PostMapping("/root/updatekey")
|
||||
@ResponseBody
|
||||
public String updatekey(Keys key) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Config config = new Config();
|
||||
config.setSourcekey(key.getStorageType());
|
||||
Integer val = configService.setSourceype(config);
|
||||
if (val > 0) {
|
||||
Integer ret = keysService.updateKey(key);
|
||||
jsonArray.add(ret);
|
||||
} else {
|
||||
jsonArray.add(0);
|
||||
}
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
@PostMapping("/deleimg")
|
||||
@ResponseBody
|
||||
public String deleimg(HttpSession session, Integer id, Integer sourcekey) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
User u = (User) session.getAttribute("user");
|
||||
Images images = imgService.selectByPrimaryKey(id);
|
||||
Keys key = keysService.selectKeys(sourcekey);
|
||||
ImgServiceImpl de = new ImgServiceImpl();
|
||||
|
||||
if (key.getStorageType() == 1) {
|
||||
de.delect(key, images.getImgname());
|
||||
} else if (key.getStorageType() == 2) {
|
||||
de.delectOSS(key, images.getImgname());
|
||||
} else if (key.getStorageType() == 3) {
|
||||
//初始化腾讯云
|
||||
} else if (key.getStorageType() == 4) {
|
||||
//初始化七牛云
|
||||
} else {
|
||||
System.err.println("未获取到对象存储参数,删除失败。");
|
||||
}
|
||||
Integer ret = imgService.deleimg(id);
|
||||
Integer count = 0;
|
||||
if (ret > 0) {
|
||||
jsonObject.put("usercount", imgService.countimg(u.getId()));
|
||||
jsonObject.put("count", imgService.counts(null) + 1000);
|
||||
count = 1;
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
jsonObject.put("val", count);
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
//批量删除图片
|
||||
@PostMapping("/deleallimg")
|
||||
@ResponseBody
|
||||
public String deleallimg(HttpSession session, @RequestParam("ids[]") Integer[] ids) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
Integer v = 0;
|
||||
ImgServiceImpl de = new ImgServiceImpl();
|
||||
User u = (User) session.getAttribute("user");
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
Images images = imgService.selectByPrimaryKey(ids[i]);
|
||||
Keys key = keysService.selectKeys(images.getSource());
|
||||
if (key.getStorageType() == 1) {
|
||||
de.delect(key, images.getImgname());
|
||||
} else if (key.getStorageType() == 2) {
|
||||
de.delectOSS(key, images.getImgname());
|
||||
} else if (key.getStorageType() == 3) {
|
||||
//初始化腾讯云
|
||||
} else if (key.getStorageType() == 4) {
|
||||
//初始化七牛云
|
||||
} else {
|
||||
System.err.println("未获取到对象存储参数,删除失败。");
|
||||
}
|
||||
Integer ret = imgService.deleimg(ids[i]);
|
||||
if (ret < 1) {
|
||||
v = 0;
|
||||
} else {
|
||||
v = 1;
|
||||
}
|
||||
}
|
||||
jsonObject.put("usercount", imgService.countimg(u.getId()));
|
||||
jsonObject.put("count", imgService.counts(null) + 1000);
|
||||
jsonObject.put("val", v);
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
//刪除用戶
|
||||
@PostMapping("/root/deleuser")
|
||||
@ResponseBody
|
||||
public String deleuser(HttpSession session, Integer id) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Integer ret = userService.deleuser(id);
|
||||
jsonArray.add(ret);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
//进入修改密码页面
|
||||
@RequestMapping(value = "/tosetuser")
|
||||
public String tosetuser(HttpSession session, Model model, HttpServletRequest request) {
|
||||
User u = (User) session.getAttribute("user");
|
||||
//key信息
|
||||
model.addAttribute("username", u.getUsername());
|
||||
//
|
||||
return "admin/setuser";
|
||||
}
|
||||
|
||||
//修改资料
|
||||
@PostMapping("/change")
|
||||
@ResponseBody
|
||||
public String change(HttpSession session, User user) {
|
||||
//Integer count = userService.checkUsername(user.getUsername());//查询用户名是否重复
|
||||
User u = (User) session.getAttribute("user");
|
||||
user.setEmail(u.getEmail());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
//if(count==0) {
|
||||
Integer ret = userService.change(user);
|
||||
jsonArray.add(ret);
|
||||
if (u.getEmail() != null && u.getPassword() != null) {
|
||||
session.removeAttribute("user");
|
||||
//刷新view
|
||||
session.invalidate();
|
||||
}
|
||||
//}else {
|
||||
// jsonArray.add("-1");
|
||||
//}
|
||||
// -1 用户名重复
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
//跳转邮箱配置页面
|
||||
@RequestMapping(value = "/root/emailconfig")
|
||||
public String emailconfig(Model model) {
|
||||
EmailConfig emailConfig = emailConfigService.getemail();
|
||||
model.addAttribute("emailConfig",emailConfig);
|
||||
return "admin/emailconfig";
|
||||
}
|
||||
//修改邮箱验证
|
||||
@PostMapping("/root/updateemail")
|
||||
@ResponseBody
|
||||
public Integer updateemail(HttpSession session,String emails, String emailkey, String emailurl, String port, String emailname, Integer using ) {
|
||||
EmailConfig emailConfig = new EmailConfig();
|
||||
emailConfig.setEmailname(emailname);
|
||||
emailConfig.setEmails(emails);
|
||||
emailConfig.setEmailkey(emailkey);
|
||||
emailConfig.setEmailurl(emailurl);
|
||||
emailConfig.setPort(port);
|
||||
emailConfig.setUsing(using);
|
||||
Integer ret = emailConfigService.updateemail(emailConfig);
|
||||
return ret;
|
||||
}
|
||||
//跳转系统配置页面
|
||||
@RequestMapping(value = "/root/towebconfig")
|
||||
public String towebconfig(Model model) {
|
||||
Config config = configService.getSourceype();
|
||||
model.addAttribute("config",config);
|
||||
return "admin/webconfig";
|
||||
}
|
||||
//修改站点配置
|
||||
@PostMapping("/root/updateconfig")
|
||||
@ResponseBody
|
||||
public Integer updateconfig(HttpSession session, String webname,String explain, String logos,
|
||||
String footed, String links, String notice,String baidu ) {
|
||||
System.err.println(links);
|
||||
Config config = new Config();
|
||||
config.setWebname(webname);
|
||||
config.setExplain(explain);
|
||||
config.setLogos(logos);
|
||||
config.setFooted(footed);
|
||||
config.setLinks(links);
|
||||
config.setNotice(notice);
|
||||
config.setBaidu(baidu);
|
||||
Integer ret = configService.setSourceype(config);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/images/{id}")
|
||||
@ResponseBody
|
||||
public Images selectByFy(@PathVariable("id") Integer id) {
|
||||
return imgService.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.hellohao.controller;
|
||||
|
||||
import cn.hellohao.pojo.Imgreview;
|
||||
import cn.hellohao.service.ImgreviewService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admin")
|
||||
public class ImageReviewController {
|
||||
|
||||
@Autowired
|
||||
private ImgreviewService imgreviewService;
|
||||
|
||||
|
||||
@RequestMapping(value = "/root/ImageReview")
|
||||
public String ForwardImageReview(Model model) {
|
||||
//查询百度鉴黄的key
|
||||
Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
|
||||
model.addAttribute("appid", imgreview.getAppId());
|
||||
model.addAttribute("apikey", imgreview.getApiKey());
|
||||
model.addAttribute("secretkey", imgreview.getSecretKey());
|
||||
model.addAttribute("using", imgreview.getUsing());
|
||||
|
||||
return "admin/imageIdentify";
|
||||
}
|
||||
|
||||
//鉴黄功能开关
|
||||
@RequestMapping(value = "/root/ImgreviewSwitch")
|
||||
@ResponseBody
|
||||
public String ImgreviewSwitch(String appId, String apiKey, String secretKey, Integer using) {
|
||||
Imgreview imgreview = new Imgreview();
|
||||
imgreview.setId(1);//目前就一种鉴黄功能所以设死了
|
||||
//if(using!=null&&using.equals("")){
|
||||
imgreview.setUsing(using);
|
||||
imgreview.setAppId(appId);
|
||||
imgreview.setApiKey(apiKey);
|
||||
imgreview.setSecretKey(secretKey);
|
||||
Integer ret = imgreviewService.updateByPrimaryKeySelective(imgreview);
|
||||
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,158 +1,191 @@
|
||||
package cn.hellohao.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import cn.hellohao.pojo.*;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.service.impl.OSSImageupload;
|
||||
import cn.hellohao.utils.Sentence;
|
||||
import cn.hellohao.utils.SetText;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.service.KeysService;
|
||||
import cn.hellohao.service.UserService;
|
||||
import cn.hellohao.service.impl.NOSImageupload;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
|
||||
@Controller
|
||||
public class UpdateImgController {
|
||||
@Autowired
|
||||
private NOSImageupload nOSImageupload;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private KeysService keysService;
|
||||
|
||||
|
||||
public static String getSubString(String text, String left, String right) {
|
||||
String result = "";
|
||||
int zLen;
|
||||
if (left == null || left.isEmpty()) {
|
||||
zLen = 0;
|
||||
} else {
|
||||
zLen = text.indexOf(left);
|
||||
if (zLen > -1) {
|
||||
zLen += left.length();
|
||||
} else {
|
||||
zLen = 0;
|
||||
}
|
||||
}
|
||||
int yLen = text.indexOf(right, zLen);
|
||||
if (yLen < 0 || right == null || right.isEmpty()) {
|
||||
yLen = text.length();
|
||||
}
|
||||
result = text.substring(zLen, yLen);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping({"/","/index.do"})
|
||||
public String indexImg(Model model,HttpServletRequest request,HttpSession httpSession){
|
||||
Integer storageType = keysService.selectKeysType();
|
||||
System.out.println("类型=========="+storageType);
|
||||
Keys key = keysService.selectKeys(storageType);
|
||||
nOSImageupload.Initialize(key);
|
||||
//查询哪种对象存储
|
||||
httpSession.setAttribute("storageType", storageType);
|
||||
|
||||
model.addAttribute("text_foot", "<li><a href=\"http://www.hellohao.cn/\" target=\"_blank\">Hellohao ©</a></li><li>切勿上传违反中华人民共和国互联网法律条约资源</li>");
|
||||
User u = (User) httpSession.getAttribute("user");
|
||||
String email = (String) httpSession.getAttribute("email");
|
||||
String pass = (String) httpSession.getAttribute("pass");
|
||||
if(email!=null && pass!=null) {
|
||||
//登陆成功
|
||||
Integer ret = userService.login(u.getEmail(), u.getPassword());
|
||||
if(ret>0) {
|
||||
User user = userService.getUsers(u.getEmail());
|
||||
model.addAttribute("username",user.getUsername());
|
||||
model.addAttribute("level",user.getLevel());
|
||||
model.addAttribute("loginid",100);
|
||||
model.addAttribute("imgcount",3);
|
||||
model.addAttribute("fileSize",5120);
|
||||
|
||||
}else {
|
||||
model.addAttribute("loginid",-1);
|
||||
model.addAttribute("imgcount",1);
|
||||
}
|
||||
}else {
|
||||
model.addAttribute("loginid",-2);
|
||||
model.addAttribute("imgcount",1);
|
||||
model.addAttribute("imgcount",1);
|
||||
model.addAttribute("fileSize",3072);
|
||||
|
||||
}
|
||||
@Autowired
|
||||
private NOSImageupload nOSImageupload;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private KeysService keysService;
|
||||
@Autowired
|
||||
private NoticeService noticeService;
|
||||
@Autowired
|
||||
private OSSImageupload ossImageupload;
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
|
||||
@RequestMapping({"/", "/index"})
|
||||
public String indexImg(Model model, HttpServletRequest request, HttpSession httpSession) throws Exception {
|
||||
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
|
||||
Keys key = keysService.selectKeys(config.getSourcekey());//然后根据类型再查询key
|
||||
if(key.getStorageType()==1){
|
||||
nOSImageupload.Initialize(key);//实例化网易
|
||||
System.out.println("NOS初始化成功。");
|
||||
}else if (key.getStorageType()==2){
|
||||
OSSImageupload.Initialize(key);
|
||||
System.out.println("OSS初始化成功。");
|
||||
}else if(key.getStorageType()==3){
|
||||
//初始化腾讯云
|
||||
}else if(key.getStorageType()==4){
|
||||
//初始化七牛云
|
||||
}else{
|
||||
System.err.println("未获取到对象存储参数,初始化失败。");
|
||||
}
|
||||
|
||||
User u = (User) httpSession.getAttribute("user");
|
||||
String email = (String) httpSession.getAttribute("email");
|
||||
if (email != null) {
|
||||
//登陆成功
|
||||
Integer ret = userService.login(u.getEmail(), u.getPassword());
|
||||
if (ret > 0) {
|
||||
User user = userService.getUsers(u.getEmail());
|
||||
model.addAttribute("username", user.getUsername());
|
||||
model.addAttribute("level", user.getLevel());
|
||||
model.addAttribute("loginid", 100);
|
||||
model.addAttribute("imgcount", 3);
|
||||
model.addAttribute("fileSize", 5120);
|
||||
|
||||
} else {
|
||||
model.addAttribute("loginid", -1);
|
||||
model.addAttribute("imgcount", 1);
|
||||
}
|
||||
} else {
|
||||
model.addAttribute("loginid", -2);
|
||||
model.addAttribute("imgcount", 1);
|
||||
model.addAttribute("fileSize", 3072);
|
||||
|
||||
}
|
||||
model.addAttribute("config", config);
|
||||
|
||||
// AipContentCensor client = ImageReview.Initialize();
|
||||
// String url = "https://hellohao.nos-eastchina1.126.net/Hellohao/huangse.png";
|
||||
// JSONObject res = client.antiPorn(url);
|
||||
// res = client.imageCensorUserDefined(url, EImgType.URL, null);
|
||||
// System.out.println(res.toString());
|
||||
|
||||
//
|
||||
// CronTrigger cron = (CronTrigger) scheduler.getTrigger(cronTrigger.getKey());
|
||||
// String currentCron = cron.getCronExpression();// 当前Trigger使用的
|
||||
// System.err.println("当前trigger使用的-"+currentCron);
|
||||
//
|
||||
// //修改每隔?秒执行任务
|
||||
// CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 09 07 * * ?");
|
||||
//
|
||||
// // 按新的cronExpression表达式重新构建trigger
|
||||
// cron = cron.getTriggerBuilder().withIdentity(cronTrigger.getKey())
|
||||
// .withSchedule(scheduleBuilder).build();
|
||||
//
|
||||
// scheduler.rescheduleJob(cronTrigger.getKey(),cron);
|
||||
|
||||
return "index";
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value="/upimg.do")
|
||||
|
||||
@RequestMapping(value = "/upimg")
|
||||
@ResponseBody
|
||||
public String exit(HttpServletRequest request,HttpServletResponse response,HttpSession session
|
||||
,@RequestParam(value = "file", required = false) MultipartFile[] file,String filename) throws Exception{
|
||||
long stime = System.currentTimeMillis();
|
||||
User u = (User) session.getAttribute("user");
|
||||
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Map<String, MultipartFile> map = new HashMap<>();
|
||||
for (MultipartFile multipartFile : file) {
|
||||
//获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
String lastname = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
if (!multipartFile.isEmpty()) { //判断文件是否为空
|
||||
map.put(lastname, multipartFile);
|
||||
//multipartFile.getOriginalFilename(); //文件名
|
||||
//multipartFile.getSize(); //文件大小
|
||||
}
|
||||
public String upimg(HttpServletRequest request, HttpServletResponse response, HttpSession session
|
||||
, @RequestParam(value = "file", required = false) MultipartFile[] file) throws Exception {
|
||||
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
|
||||
Keys key = keysService.selectKeys(config.getSourcekey());
|
||||
long stime = System.currentTimeMillis();
|
||||
User u = (User) session.getAttribute("user");
|
||||
String username = "tourist";
|
||||
if (u != null) {
|
||||
username = u.getUsername();
|
||||
}
|
||||
Map<String, Integer> m =nOSImageupload.Imageupload(map);
|
||||
Images img = new Images();
|
||||
// for (String string : m) {
|
||||
// jsonArray.add(string);
|
||||
// System.out.println("文件名字:==="+string);
|
||||
// if(userid!=null) {
|
||||
// //img.setImgname(imgname);//图片名字
|
||||
// img.setImgurl(string);//图片链接
|
||||
// img.setUserid(userid);//用户id
|
||||
// userService.insertimg(img);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
for (Map.Entry<String, Integer> entry : m.entrySet()) {
|
||||
jsonArray.add(entry.getKey());
|
||||
if(u!=null) {
|
||||
//img.setImgname(imgname);//图片名字
|
||||
|
||||
img.setImgurl(entry.getKey());//图片链接
|
||||
img.setUserid(u.getId());//用户id
|
||||
img.setSizes((entry.getValue())/1024);
|
||||
img.setImgname(getSubString(entry.getKey(), "hellohao.nos-eastchina1.126.net/", ""));
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
System.out.println("上传图片所用时长:"+String.valueOf(etime-stime)+"ms");
|
||||
}
|
||||
}
|
||||
|
||||
return jsonArray.toString();
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Map<String, MultipartFile> map = new HashMap<>();
|
||||
for (MultipartFile multipartFile : file) {
|
||||
// 获取ImageReader对象的迭代器
|
||||
//获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
String lastname = fileName.substring(fileName.lastIndexOf(".") + 1);//获取文件后缀
|
||||
if (!multipartFile.isEmpty()) { //判断文件是否为空
|
||||
map.put(lastname, multipartFile);
|
||||
//multipartFile.getOriginalFilename(); //文件名
|
||||
//multipartFile.getSize(); //文件大小
|
||||
}
|
||||
}
|
||||
Map<String, Integer> m = null;
|
||||
|
||||
if(key.getStorageType()==1){
|
||||
m = nOSImageupload.Imageupload(map, username);
|
||||
}else if (key.getStorageType()==2){
|
||||
m = ossImageupload.ImageuploadOSS(map, username);
|
||||
}else if(key.getStorageType()==3){
|
||||
//初始化腾讯云
|
||||
}else if(key.getStorageType()==4){
|
||||
//初始化七牛云
|
||||
}else{
|
||||
System.err.println("未获取到对象存储参数,上传失败。");
|
||||
}
|
||||
|
||||
Images img = new Images();
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = new Date();
|
||||
String times = df.format(new Date());
|
||||
System.out.println("上传图片的时间是:"+times);
|
||||
for (Map.Entry<String, Integer> entry : m.entrySet()) {
|
||||
jsonArray.add(entry.getKey());
|
||||
img.setImgurl(entry.getKey());//图片链接
|
||||
img.setUpdatetime(times);
|
||||
img.setSource(key.getStorageType());
|
||||
if (u == null) {
|
||||
img.setUserid(0);//用户id
|
||||
} else {
|
||||
img.setUserid(u.getId());//用户id
|
||||
}
|
||||
img.setSizes((entry.getValue()) / 1024);
|
||||
img.setImgname(SetText.getSubString(entry.getKey(), key.getRequestAddress() + "/", ""));
|
||||
img.setAbnormal(0);
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
System.out.println("上传图片所用时长:" + String.valueOf(etime - stime) + "ms");
|
||||
}
|
||||
//开辟新进程鉴黄。现在已经改成定时器
|
||||
//查询鉴黄功能是否启动,1为启用
|
||||
// Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
|
||||
// if (imgreview.getUsing() == 1) {
|
||||
// //上传完成后开辟新的线程进行图片鉴黄。
|
||||
// JianHuangThread thread = new JianHuangThread(imgreviewService, key, u, m);
|
||||
// thread.start();
|
||||
// }
|
||||
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
//刪除用戶
|
||||
@RequestMapping("/sentence")
|
||||
@ResponseBody
|
||||
public String sentence(HttpSession session, Integer id) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
String text = Sentence.getURLContent();
|
||||
jsonArray.add(text);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,20 @@ package cn.hellohao.controller;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import cn.hellohao.pojo.EmailConfig;
|
||||
import cn.hellohao.service.EmailConfigService;
|
||||
import cn.hellohao.utils.SendEmail;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
@@ -17,65 +23,116 @@ import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.service.UserService;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private EmailConfigService emailConfigService;
|
||||
|
||||
@RequestMapping("/register.do")
|
||||
@ResponseBody
|
||||
public String Register(User user) {
|
||||
//取当前时间
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
||||
String birthder = df.format(new Date());// new Date()为获取当前系统时间
|
||||
user.setLevel(1);
|
||||
user.setBirthder(birthder);
|
||||
Integer ret = userService.register(user);
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.add(ret);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
@RequestMapping("/login.do")
|
||||
@ResponseBody
|
||||
public String login(HttpServletRequest request,HttpSession httpSession,String email,String password) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
Integer ret = userService.login(email, password);
|
||||
if(ret>0) {
|
||||
jsonArray.add(1);
|
||||
User user = userService.getUsers(email);
|
||||
httpSession.setAttribute("user",user);
|
||||
httpSession.setAttribute("email",user.getEmail());
|
||||
httpSession.setAttribute("pass",user.getPassword());
|
||||
|
||||
//登录成功之后把账号密码存入session
|
||||
|
||||
}else {
|
||||
jsonArray.add(0);
|
||||
}
|
||||
return jsonArray.toString();
|
||||
}
|
||||
//退出
|
||||
@RequestMapping(value="/exit.do")
|
||||
@RequestMapping("/register")
|
||||
@ResponseBody
|
||||
public String exit(Model model,HttpServletRequest request,HttpSession session){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//注销,移除session
|
||||
User user = (User) session.getAttribute("user");
|
||||
if(user.getEmail()!=null&&user.getPassword()!=null) {
|
||||
session.removeAttribute(user.getEmail());
|
||||
session.removeAttribute(user.getPassword());
|
||||
//刷新view
|
||||
session.invalidate();
|
||||
jsonObject.put("exit", 1);
|
||||
}
|
||||
|
||||
return jsonObject.toString();
|
||||
public String Register(User user) {
|
||||
//取当前时间
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
EmailConfig emailConfig = emailConfigService.getemail();
|
||||
Integer countusername = userService.countusername(user.getUsername());
|
||||
Integer countmail = userService.countmail(user.getEmail());
|
||||
if (countusername == 0 && countmail == 0) {
|
||||
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
||||
String birthder = df.format(new Date());// new Date()为获取当前系统时间
|
||||
user.setLevel(1);
|
||||
user.setUid(uid);
|
||||
user.setBirthder(birthder);
|
||||
//查询是否启用了邮箱验证。
|
||||
EmailConfig emailConfig1 = emailConfigService.getemail();
|
||||
Integer type = 0;
|
||||
if(emailConfig1.getUsing()==1){
|
||||
user.setIsok(0);
|
||||
//初始化邮箱
|
||||
MimeMessage message = SendEmail.Emails(emailConfig);
|
||||
//注册完发激活链接
|
||||
Thread thread = new Thread() {
|
||||
public void run() {
|
||||
Integer a = SendEmail.sendEmail(message, user.getUsername(), uid, user.getEmail(),emailConfig);
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
}else{
|
||||
//直接注册
|
||||
user.setIsok(1);
|
||||
type = 2;
|
||||
}
|
||||
Integer ret = userService.register(user);
|
||||
jsonObject.put("ret",ret);
|
||||
jsonObject.put("zctype",type);
|
||||
} else {
|
||||
jsonObject.put("ret",-2);
|
||||
}
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
@RequestMapping("/login.do")
|
||||
@ResponseBody
|
||||
public String login(HttpServletRequest request, HttpSession httpSession, String email, String password) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
Integer ret = userService.login(email, password);
|
||||
if (ret > 0) {
|
||||
User user = userService.getUsers(email);
|
||||
if (user.getIsok() == 1) {
|
||||
httpSession.setAttribute("user", user);
|
||||
httpSession.setAttribute("email", user.getEmail());
|
||||
httpSession.setAttribute("pass", user.getPassword());
|
||||
jsonArray.add(1);
|
||||
} else {
|
||||
jsonArray.add(-1);
|
||||
}
|
||||
//登录成功之后把账号密码存入session
|
||||
} else {
|
||||
jsonArray.add(0);
|
||||
}
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
//退出
|
||||
@RequestMapping(value = "/exit.do")
|
||||
@ResponseBody
|
||||
public String exit(Model model, HttpServletRequest request, HttpSession session) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//注销,移除session
|
||||
User user = (User) session.getAttribute("user");
|
||||
if (user.getEmail() != null && user.getPassword() != null) {
|
||||
session.removeAttribute(user.getEmail());
|
||||
session.removeAttribute(user.getPassword());
|
||||
//刷新view
|
||||
session.invalidate();
|
||||
jsonObject.put("exit", 1);
|
||||
}
|
||||
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
//邮箱激活
|
||||
@RequestMapping(value = "/activation.do", method = RequestMethod.GET)
|
||||
public String activation(Model model, HttpServletRequest request, HttpSession session, String activation, String username) {
|
||||
System.out.println("激活方法进去了");
|
||||
Integer ret = 0;
|
||||
User user = userService.getUsersMail(activation);
|
||||
if (user != null && user.getIsok() == 0) {
|
||||
Integer setisok = userService.uiduser(activation);
|
||||
model.addAttribute("setisok", ret);
|
||||
model.addAttribute("username", username);
|
||||
return "isok";
|
||||
} else {
|
||||
return "redirect:/index.do";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package cn.hellohao.dao;
|
||||
|
||||
import cn.hellohao.pojo.Config;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Mapper
|
||||
public interface ConfigMapper {
|
||||
Config getSourceype();
|
||||
Integer setSourceype(Config config);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.hellohao.dao;
|
||||
|
||||
import cn.hellohao.pojo.EmailConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface EmailConfigMapper {
|
||||
EmailConfig getemail();
|
||||
Integer updateemail(EmailConfig emailConfig);
|
||||
}
|
||||
@@ -10,9 +10,20 @@ import cn.hellohao.pojo.Images;
|
||||
@Mapper
|
||||
public interface ImgMapper {
|
||||
|
||||
List<Images> selectimg(@Param("userid") Integer userid);
|
||||
Integer countimg(@Param("userid") Integer userid);
|
||||
Integer deleimg(@Param("id") Integer id);
|
||||
Images selectByPrimaryKey(@Param("id") Integer id);
|
||||
Integer counts(@Param("userid") Integer userid);
|
||||
List<Images> selectimg(@Param("userid") Integer userid);
|
||||
|
||||
Integer countimg(@Param("userid") Integer userid);
|
||||
|
||||
Integer deleimg(@Param("id") Integer id);
|
||||
|
||||
Images selectByPrimaryKey(@Param("id") Integer id);
|
||||
|
||||
Integer counts(@Param("userid") Integer userid);
|
||||
|
||||
Integer setabnormal(@Param("imgname") String imgname);
|
||||
|
||||
Integer deleimgname(@Param("imgname") String imgname);
|
||||
Integer deleall(@Param("id") Integer id);
|
||||
|
||||
List<Images> gettimeimg(@Param("time") String time);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.hellohao.dao;
|
||||
|
||||
import cn.hellohao.pojo.Imgreview;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ImgreviewMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(Imgreview record);
|
||||
|
||||
int insertSelective(Imgreview record);
|
||||
|
||||
Imgreview selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(Imgreview record);
|
||||
|
||||
int updateByPrimaryKey(Imgreview record);
|
||||
}
|
||||
@@ -7,11 +7,9 @@ import cn.hellohao.pojo.Keys;
|
||||
|
||||
@Mapper
|
||||
public interface KeysMapper {
|
||||
//查询密钥
|
||||
Keys selectKeys(@Param("storageType") Integer storageType);
|
||||
//查询key类型
|
||||
Integer selectKeysType();
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
//查询密钥
|
||||
Keys selectKeys(@Param("storageType") Integer storageType);
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.hellohao.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface NoticeMapper {
|
||||
|
||||
String getNotice();
|
||||
}
|
||||
@@ -6,19 +6,42 @@ import org.apache.ibatis.annotations.Param;
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
//注册
|
||||
Integer register(User user);
|
||||
//登录
|
||||
Integer login(@Param("email") String email,@Param("password") String password);
|
||||
//获取用户信息
|
||||
User getUsers(@Param("email") String email);
|
||||
//插入图片
|
||||
Integer insertimg(Images img);
|
||||
//修改资料
|
||||
Integer change(User user);
|
||||
//检查用户名是否重复
|
||||
Integer checkUsername(@Param("username") String username);
|
||||
Integer getUserTotal();
|
||||
//注册
|
||||
Integer register(User user);
|
||||
|
||||
//登录
|
||||
Integer login(@Param("email") String email, @Param("password") String password);
|
||||
|
||||
//获取用户信息
|
||||
User getUsers(@Param("email") String email);
|
||||
|
||||
//插入图片
|
||||
Integer insertimg(Images img);
|
||||
|
||||
//修改资料
|
||||
Integer change(User user);
|
||||
|
||||
//检查用户名是否重复
|
||||
Integer checkUsername(@Param("username") String username);
|
||||
|
||||
Integer getUserTotal();
|
||||
|
||||
List<User> getuserlist();
|
||||
|
||||
//刪除用戶
|
||||
Integer deleuser(@Param("id") Integer id);
|
||||
|
||||
//查询用户名或者邮箱是否存在
|
||||
Integer countusername(@Param("username") String username);
|
||||
|
||||
Integer countmail(@Param("email") String email);
|
||||
|
||||
Integer uiduser(@Param("uid") String uid);
|
||||
|
||||
User getUsersMail(@Param("uid") String uid);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import cn.hellohao.pojo.User;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@@ -13,34 +14,46 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
|
||||
@Component
|
||||
public class InterceptorConfig implements HandlerInterceptor{
|
||||
//private static final Logger log = LoggerFactory.getLogger(InterceptorConfig.class);
|
||||
|
||||
/**
|
||||
public class InterceptorConfig implements HandlerInterceptor {
|
||||
//private static final Logger log = LoggerFactory.getLogger(InterceptorConfig.class);
|
||||
|
||||
/**
|
||||
* 进入controller层之前拦截请求
|
||||
*/
|
||||
//这个方法是在访问接口之前执行的,我们只需要在这里写验证登陆状态的业务逻辑,就可以在用户调用指定接口之前验证登陆状态了
|
||||
*/
|
||||
//这个方法是在访问接口之前执行的,我们只需要在这里写验证登陆状态的业务逻辑,就可以在用户调用指定接口之前验证登陆状态了
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
//设置不缓存
|
||||
// response.setHeader("Cache-Control","no-cache");
|
||||
// response.setHeader("Pragma","no-cache");
|
||||
// response.setDateHeader("Expires",0);
|
||||
//每一个项目对于登陆的实现逻辑都有所区别,我这里使用最简单的Session提取User来验证登陆。
|
||||
HttpSession session = request.getSession();
|
||||
//这里的User是登陆时放入session的
|
||||
String email = (String) session.getAttribute("email");
|
||||
User user = (User) session.getAttribute("user");
|
||||
String email = null;
|
||||
Integer level = 0;
|
||||
if (user != null) {
|
||||
email = user.getEmail();
|
||||
level = user.getLevel();
|
||||
}
|
||||
// String email = (String) session.getAttribute("email");
|
||||
//如果session中没有user,表示没登陆
|
||||
if (email == null){
|
||||
if (email == null) {
|
||||
//这个方法返回false表示忽略当前请求,如果一个用户调用了需要登陆才能使用的接口,如果他没有登陆这里会直接忽略掉
|
||||
//当然你可以利用response给用户返回一些提示信息,告诉他没登陆
|
||||
System.out.println("没有登录权限");
|
||||
request.getRequestDispatcher("/index.do").forward(request,response);
|
||||
System.out.println("没有登录权限");
|
||||
request.getRequestDispatcher("/index").forward(request, response);
|
||||
return false;
|
||||
}else {
|
||||
System.out.println("进入成功");
|
||||
} else {
|
||||
|
||||
//System.out.println("进入成功");
|
||||
return true; //如果session里有user,表示该用户已经登陆,放行,用户即可继续调用自己需要的接口
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
|
||||
}
|
||||
|
||||
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package cn.hellohao.interceptor;
|
||||
|
||||
import cn.hellohao.pojo.User;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
|
||||
@Component
|
||||
public class InterceptorConfigTwo implements HandlerInterceptor {
|
||||
//private static final Logger log = LoggerFactory.getLogger(InterceptorConfig.class);
|
||||
|
||||
/**
|
||||
* 进入controller层之前拦截请求
|
||||
*/
|
||||
//这个方法是在访问接口之前执行的,我们只需要在这里写验证登陆状态的业务逻辑,就可以在用户调用指定接口之前验证登陆状态了
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
//设置不缓存
|
||||
// response.setHeader("Cache-Control","no-cache");
|
||||
// response.setHeader("Pragma","no-cache");
|
||||
// response.setDateHeader("Expires",0);
|
||||
//每一个项目对于登陆的实现逻辑都有所区别,我这里使用最简单的Session提取User来验证登陆。
|
||||
HttpSession session = request.getSession();
|
||||
//这里的User是登陆时放入session的
|
||||
User user = (User) session.getAttribute("user");
|
||||
String email = null;
|
||||
Integer level = 0;
|
||||
if (user != null) {
|
||||
email = user.getEmail();
|
||||
level = user.getLevel();
|
||||
}
|
||||
// String email = (String) session.getAttribute("email");
|
||||
//如果session中没有user,表示没登陆
|
||||
if (email == null) {
|
||||
//这个方法返回false表示忽略当前请求,如果一个用户调用了需要登陆才能使用的接口,如果他没有登陆这里会直接忽略掉
|
||||
//当然你可以利用response给用户返回一些提示信息,告诉他没登陆
|
||||
System.out.println("没有登录权限");
|
||||
request.getRequestDispatcher("/index").forward(request, response);
|
||||
return false;
|
||||
} else {
|
||||
if (level == 2) {
|
||||
System.out.println("进入成功");
|
||||
return true; //如果session里有user,表示该用户已经登陆,放行,用户即可继续调用自己需要的接口
|
||||
} else {
|
||||
request.getRequestDispatcher("/admin/admin").forward(request, response);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
|
||||
}
|
||||
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,29 +6,34 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class WebAppConfig implements WebMvcConfigurer {
|
||||
public class WebAppConfig implements WebMvcConfigurer {
|
||||
|
||||
|
||||
@Autowired
|
||||
private InterceptorConfig interceptorConfig;
|
||||
|
||||
|
||||
// 这个方法是用来配置静态资源的,比如html,js,css,等等
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
}
|
||||
|
||||
// 这个方法用来注册拦截器,我们自己写好的拦截器需要通过这里添加注册才能生效
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
||||
// addPathPatterns("/**") 表示拦截所有的请求,
|
||||
// excludePathPatterns("/login", "/register") 表示除了登陆与注册之外,因为登陆注册不需要登陆也可以访问
|
||||
//registry.addInterceptor(interceptorConfig).addPathPatterns("admin/**").excludePathPatterns("/login", "/register");
|
||||
registry.addInterceptor(interceptorConfig).addPathPatterns("/admin/**");
|
||||
@Autowired
|
||||
private InterceptorConfigTwo interceptorConfigTwo;
|
||||
|
||||
|
||||
}
|
||||
// 这个方法是用来配置静态资源的,比如html,js,css,等等
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
}
|
||||
|
||||
// 这个方法用来注册拦截器,我们自己写好的拦截器需要通过这里添加注册才能生效
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// addPathPatterns("/**") 表示拦截所有的请求,
|
||||
// excludePathPatterns("/login", "/register") 表示除了登陆与注册之外,因为登陆注册不需要登陆也可以访问
|
||||
//registry.addInterceptor(interceptorConfig).addPathPatterns("admin/**").excludePathPatterns("/login", "/register");
|
||||
registry.addInterceptor(interceptorConfig).addPathPatterns("/admin/**");
|
||||
registry.addInterceptor(interceptorConfigTwo).addPathPatterns("/admin/root/**");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class Config {
|
||||
private Integer id;
|
||||
private Integer sourcekey;
|
||||
private Integer emails;
|
||||
private String webname;
|
||||
private String explain;
|
||||
private String logos;
|
||||
private String footed;
|
||||
private String links;
|
||||
private String notice;
|
||||
private String baidu;
|
||||
|
||||
public Config() {
|
||||
}
|
||||
|
||||
public Config(Integer id, Integer sourcekey, Integer emails, String webname, String explain, String logos, String footed, String links, String notice, String baidu) {
|
||||
this.id = id;
|
||||
this.sourcekey = sourcekey;
|
||||
this.emails = emails;
|
||||
this.webname = webname;
|
||||
this.explain = explain;
|
||||
this.logos = logos;
|
||||
this.footed = footed;
|
||||
this.links = links;
|
||||
this.notice = notice;
|
||||
this.baidu = baidu;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getSourcekey() {
|
||||
return sourcekey;
|
||||
}
|
||||
|
||||
public void setSourcekey(Integer sourcekey) {
|
||||
this.sourcekey = sourcekey;
|
||||
}
|
||||
|
||||
public Integer getEmails() {
|
||||
return emails;
|
||||
}
|
||||
|
||||
public void setEmails(Integer emails) {
|
||||
this.emails = emails;
|
||||
}
|
||||
|
||||
public String getWebname() {
|
||||
return webname;
|
||||
}
|
||||
|
||||
public void setWebname(String webname) {
|
||||
this.webname = webname;
|
||||
}
|
||||
|
||||
public String getExplain() {
|
||||
return explain;
|
||||
}
|
||||
|
||||
public void setExplain(String explain) {
|
||||
this.explain = explain;
|
||||
}
|
||||
|
||||
public String getLogos() {
|
||||
return logos;
|
||||
}
|
||||
|
||||
public void setLogos(String logos) {
|
||||
this.logos = logos;
|
||||
}
|
||||
|
||||
public String getFooted() {
|
||||
return footed;
|
||||
}
|
||||
|
||||
public void setFooted(String footed) {
|
||||
this.footed = footed;
|
||||
}
|
||||
|
||||
public String getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public void setLinks(String links) {
|
||||
this.links = links;
|
||||
}
|
||||
|
||||
public String getNotice() {
|
||||
return notice;
|
||||
}
|
||||
|
||||
public void setNotice(String notice) {
|
||||
this.notice = notice;
|
||||
}
|
||||
|
||||
public String getBaidu() {
|
||||
return baidu;
|
||||
}
|
||||
|
||||
public void setBaidu(String baidu) {
|
||||
this.baidu = baidu;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class EmailConfig {
|
||||
private Integer id ;
|
||||
private String emails;
|
||||
private String emailkey;
|
||||
private String emailurl;
|
||||
private String port;
|
||||
private String emailname;
|
||||
private Integer using ;
|
||||
|
||||
public EmailConfig() {
|
||||
}
|
||||
|
||||
public EmailConfig(Integer id, String emails, String emailkey, String emailurl, String port, String emailname, Integer using) {
|
||||
this.id = id;
|
||||
this.emails = emails;
|
||||
this.emailkey = emailkey;
|
||||
this.emailurl = emailurl;
|
||||
this.port = port;
|
||||
this.emailname = emailname;
|
||||
this.using = using;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmails() {
|
||||
return emails;
|
||||
}
|
||||
|
||||
public void setEmails(String emails) {
|
||||
this.emails = emails;
|
||||
}
|
||||
|
||||
public String getEmailkey() {
|
||||
return emailkey;
|
||||
}
|
||||
|
||||
public void setEmailkey(String emailkey) {
|
||||
this.emailkey = emailkey;
|
||||
}
|
||||
|
||||
public String getEmailurl() {
|
||||
return emailurl;
|
||||
}
|
||||
|
||||
public void setEmailurl(String emailurl) {
|
||||
this.emailurl = emailurl;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getEmailname() {
|
||||
return emailname;
|
||||
}
|
||||
|
||||
public void setEmailname(String emailname) {
|
||||
this.emailname = emailname;
|
||||
}
|
||||
|
||||
public Integer getUsing() {
|
||||
return using;
|
||||
}
|
||||
|
||||
public void setUsing(Integer using) {
|
||||
this.using = using;
|
||||
}
|
||||
}
|
||||
@@ -1,111 +1,127 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public class Images {
|
||||
// 默认的时间字符串格式
|
||||
|
||||
//id, imgname, imgurl, userid
|
||||
private Integer id;
|
||||
private String imgname;
|
||||
private String imgurl;
|
||||
private Integer userid;
|
||||
private Integer sizes=0;
|
||||
private Date updatetime;
|
||||
private Integer storageType;
|
||||
|
||||
|
||||
public Images() {
|
||||
super();
|
||||
}
|
||||
|
||||
//id, imgname, imgurl, userid
|
||||
private Integer id;
|
||||
private String imgname;
|
||||
private String imgurl;
|
||||
private Integer userid;
|
||||
private Integer sizes = 0;
|
||||
private Integer abnormal;
|
||||
private Integer source;
|
||||
private String updatetime;
|
||||
private String username;
|
||||
private Integer storageType;
|
||||
|
||||
|
||||
public Images(Integer id, String imgname, String imgurl, Integer userid, Integer sizes, Date updatetime,
|
||||
Integer storageType) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.imgname = imgname;
|
||||
this.imgurl = imgurl;
|
||||
this.userid = userid;
|
||||
this.sizes = sizes;
|
||||
this.updatetime = updatetime;
|
||||
this.storageType = storageType;
|
||||
}
|
||||
public Images() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Images(Integer id, String imgname, String imgurl, Integer userid, Integer sizes, Integer abnormal, Integer source, String updatetime, String username, Integer storageType) {
|
||||
this.id = id;
|
||||
this.imgname = imgname;
|
||||
this.imgurl = imgurl;
|
||||
this.userid = userid;
|
||||
this.sizes = sizes;
|
||||
this.abnormal = abnormal;
|
||||
this.source = source;
|
||||
this.updatetime = updatetime;
|
||||
this.username = username;
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getImgname() {
|
||||
return imgname;
|
||||
}
|
||||
|
||||
public void setImgname(String imgname) {
|
||||
this.imgname = imgname;
|
||||
}
|
||||
|
||||
public String getImgname() {
|
||||
return imgname;
|
||||
}
|
||||
public String getImgurl() {
|
||||
return imgurl;
|
||||
}
|
||||
|
||||
public void setImgurl(String imgurl) {
|
||||
this.imgurl = imgurl;
|
||||
}
|
||||
|
||||
public void setImgname(String imgname) {
|
||||
this.imgname = imgname;
|
||||
}
|
||||
public Integer getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(Integer userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getImgurl() {
|
||||
return imgurl;
|
||||
}
|
||||
public Integer getSizes() {
|
||||
return sizes;
|
||||
}
|
||||
|
||||
public void setSizes(Integer sizes) {
|
||||
this.sizes = sizes;
|
||||
}
|
||||
|
||||
public void setImgurl(String imgurl) {
|
||||
this.imgurl = imgurl;
|
||||
}
|
||||
public Integer getAbnormal() {
|
||||
return abnormal;
|
||||
}
|
||||
|
||||
public void setAbnormal(Integer abnormal) {
|
||||
this.abnormal = abnormal;
|
||||
}
|
||||
|
||||
public Integer getUserid() {
|
||||
return userid;
|
||||
}
|
||||
public Integer getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(Integer source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public void setUserid(Integer userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
public String getUpdatetime() {
|
||||
return updatetime;
|
||||
}
|
||||
|
||||
public void setUpdatetime(String updatetime) {
|
||||
this.updatetime = updatetime;
|
||||
}
|
||||
|
||||
public Integer getSizes() {
|
||||
return sizes;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setSizes(Integer sizes) {
|
||||
this.sizes = sizes;
|
||||
}
|
||||
public Integer getStorageType() {
|
||||
return storageType;
|
||||
}
|
||||
|
||||
public void setStorageType(Integer storageType) {
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
public Date getUpdatetime() {
|
||||
return updatetime;
|
||||
}
|
||||
|
||||
|
||||
public void setUpdatetime(Date updatetime) {
|
||||
this.updatetime = updatetime;
|
||||
}
|
||||
|
||||
|
||||
public Integer getStorageType() {
|
||||
|
||||
return storageType;
|
||||
}
|
||||
|
||||
|
||||
public void setStorageType(Integer storageType) {
|
||||
this.storageType = storageType;
|
||||
}
|
||||
}
|
||||
@Mapper
|
||||
public static interface ConfigMapper {
|
||||
Config getSourceype();
|
||||
Integer setSourceype(@Param("sourcekey") Integer sourcekey);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class Imgreview {
|
||||
private Integer id;
|
||||
|
||||
private String appId;
|
||||
|
||||
private String apiKey;
|
||||
|
||||
private String secretKey;
|
||||
|
||||
private Integer using;
|
||||
|
||||
private Integer count;
|
||||
|
||||
public Imgreview() {
|
||||
}
|
||||
|
||||
public Imgreview(Integer id, String appId, String apiKey, String secretKey, Integer using, Integer count) {
|
||||
this.id = id;
|
||||
this.appId = appId;
|
||||
this.apiKey = apiKey;
|
||||
this.secretKey = secretKey;
|
||||
this.using = using;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public Integer getUsing() {
|
||||
return using;
|
||||
}
|
||||
|
||||
public void setUsing(Integer using) {
|
||||
this.using = using;
|
||||
}
|
||||
|
||||
public Integer getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
@@ -1,85 +1,85 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class Keys {
|
||||
private Integer id;
|
||||
private String AccessKey;
|
||||
private String AccessSecret;
|
||||
private String Endpoint;
|
||||
private String Bucketname;
|
||||
private String RequestAddress;
|
||||
private Integer storageType;
|
||||
|
||||
public Keys() {
|
||||
super();
|
||||
}
|
||||
private Integer id;
|
||||
private String AccessKey;
|
||||
private String AccessSecret;
|
||||
private String Endpoint;
|
||||
private String Bucketname;
|
||||
private String RequestAddress;
|
||||
private Integer storageType;
|
||||
|
||||
public Keys(Integer id, String accessKey, String accessSecret, String endpoint, String bucketname,
|
||||
String requestAddress, Integer storageType) {
|
||||
super();
|
||||
this.id = id;
|
||||
AccessKey = accessKey;
|
||||
AccessSecret = accessSecret;
|
||||
Endpoint = endpoint;
|
||||
Bucketname = bucketname;
|
||||
RequestAddress = requestAddress;
|
||||
this.storageType = storageType;
|
||||
}
|
||||
public Keys() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public Keys(Integer id, String accessKey, String accessSecret, String endpoint, String bucketname,
|
||||
String requestAddress, Integer storageType) {
|
||||
super();
|
||||
this.id = id;
|
||||
AccessKey = accessKey;
|
||||
AccessSecret = accessSecret;
|
||||
Endpoint = endpoint;
|
||||
Bucketname = bucketname;
|
||||
RequestAddress = requestAddress;
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
return AccessKey;
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
AccessKey = accessKey;
|
||||
}
|
||||
public String getAccessKey() {
|
||||
return AccessKey;
|
||||
}
|
||||
|
||||
public String getAccessSecret() {
|
||||
return AccessSecret;
|
||||
}
|
||||
public void setAccessKey(String accessKey) {
|
||||
AccessKey = accessKey;
|
||||
}
|
||||
|
||||
public void setAccessSecret(String accessSecret) {
|
||||
AccessSecret = accessSecret;
|
||||
}
|
||||
public String getAccessSecret() {
|
||||
return AccessSecret;
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
return Endpoint;
|
||||
}
|
||||
public void setAccessSecret(String accessSecret) {
|
||||
AccessSecret = accessSecret;
|
||||
}
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
Endpoint = endpoint;
|
||||
}
|
||||
public String getEndpoint() {
|
||||
return Endpoint;
|
||||
}
|
||||
|
||||
public String getBucketname() {
|
||||
return Bucketname;
|
||||
}
|
||||
public void setEndpoint(String endpoint) {
|
||||
Endpoint = endpoint;
|
||||
}
|
||||
|
||||
public void setBucketname(String bucketname) {
|
||||
Bucketname = bucketname;
|
||||
}
|
||||
public String getBucketname() {
|
||||
return Bucketname;
|
||||
}
|
||||
|
||||
public String getRequestAddress() {
|
||||
return RequestAddress;
|
||||
}
|
||||
public void setBucketname(String bucketname) {
|
||||
Bucketname = bucketname;
|
||||
}
|
||||
|
||||
public void setRequestAddress(String requestAddress) {
|
||||
RequestAddress = requestAddress;
|
||||
}
|
||||
public String getRequestAddress() {
|
||||
return RequestAddress;
|
||||
}
|
||||
|
||||
public Integer getStorageType() {
|
||||
return storageType;
|
||||
}
|
||||
public void setRequestAddress(String requestAddress) {
|
||||
RequestAddress = requestAddress;
|
||||
}
|
||||
|
||||
public void setStorageType(Integer storageType) {
|
||||
this.storageType = storageType;
|
||||
}
|
||||
public Integer getStorageType() {
|
||||
return storageType;
|
||||
}
|
||||
|
||||
public void setStorageType(Integer storageType) {
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class Notice {
|
||||
private Integer id;
|
||||
private String text;
|
||||
|
||||
|
||||
public Notice() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public Notice(Integer id, String text, String password, String email, String birthder, Integer level,
|
||||
Integer keyId) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.text = text;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String gettext() {
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
public void settext(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,91 +1,92 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class User {
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
private String birthder;
|
||||
private Integer level;
|
||||
|
||||
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
private String birthder;
|
||||
private Integer level;
|
||||
private String uid;
|
||||
private Integer isok;
|
||||
|
||||
|
||||
public User(Integer id, String username, String password, String email, String birthder, Integer level,
|
||||
Integer keyId) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.birthder = birthder;
|
||||
this.level = level;
|
||||
}
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
|
||||
public User(Integer id, String username, String password, String email, String birthder, Integer level, String uid, Integer isok) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.birthder = birthder;
|
||||
this.level = level;
|
||||
this.uid = uid;
|
||||
this.isok = isok;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public String getBirthder() {
|
||||
return birthder;
|
||||
}
|
||||
|
||||
public void setBirthder(String birthder) {
|
||||
this.birthder = birthder;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
public Integer getIsok() {
|
||||
return isok;
|
||||
}
|
||||
|
||||
|
||||
public String getBirthder() {
|
||||
return birthder;
|
||||
}
|
||||
|
||||
|
||||
public void setBirthder(String birthder) {
|
||||
this.birthder = birthder;
|
||||
}
|
||||
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setIsok(Integer isok) {
|
||||
this.isok = isok;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.hellohao.quartz;
|
||||
|
||||
import org.quartz.Trigger;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
|
||||
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
|
||||
/*
|
||||
* 由于springboot是无xml配置,所以此处我们采用bean注解的方式实现quartz的配置*/
|
||||
|
||||
@Configuration
|
||||
public class QuartzConfigration {
|
||||
@Bean(name = "jobDetail")
|
||||
public MethodInvokingJobDetailFactoryBean detailFactoryBean(SchedulerTask task) {
|
||||
// ScheduleTask为需要执行的任务
|
||||
MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
|
||||
/*
|
||||
* 是否并发执行
|
||||
* 例如每5s执行一次任务,但是当前任务还没有执行完,就已经过了5s了,
|
||||
* 如果此处为true,则下一个任务会bing执行,如果此处为false,则下一个任务会等待上一个任务执行完后,再开始执行
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
"0 0 12 * * ?" 每天中午12点触发
|
||||
"0 15 10 ? * *" 每天上午10:15触发
|
||||
"0 15 10 * * ?" 每天上午10:15触发
|
||||
"0 15 10 * * ? *" 每天上午10:15触发
|
||||
"0 15 10 * * ? 2005" 2005年的每天上午10:15触发
|
||||
"0 * 14 * * ?" 在每天下午2点到下午2:59期间的每1分钟触发
|
||||
"0 0/5 14 * * ?" 在每天下午2点到下午2:55期间的每5分钟触发
|
||||
"0 0/5 14,18 * * ?" 在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发
|
||||
"0 0-5 14 * * ?" 在每天下午2点到下午2:05期间的每1分钟触发
|
||||
"0 10,44 14 ? 3 WED" 每年三月的星期三的下午2:10和2:44触发
|
||||
"0 15 10 ? * MON-FRI" 周一至周五的上午10:15触发
|
||||
"0 15 10 15 * ?" 每月15日上午10:15触发
|
||||
"0 15 10 L * ?" 每月最后一日的上午10:15触发
|
||||
"0 15 10 ? * 6L" 每月的最后一个星期五上午10:15触发
|
||||
"0 15 10 ? * 6L 2002-2005" 2002年至2005年的每月的最后一个星期五上午10:15触发
|
||||
"0 15 10 ? * 6#3" 每月的第三个星期五上午10:15触发
|
||||
* */
|
||||
jobDetail.setConcurrent(true);
|
||||
|
||||
jobDetail.setName("scheduler");// 设置任务的名字
|
||||
jobDetail.setGroup("scheduler_group");// 设置任务的分组,这些属性都可以存储在数据库中,在多任务的时候使用
|
||||
|
||||
/*
|
||||
* 这两行代码表示执行task对象中的scheduleTest方法。定时执行的逻辑都在scheduleTest。
|
||||
*/
|
||||
jobDetail.setTargetObject(task);
|
||||
|
||||
jobDetail.setTargetMethod("start");
|
||||
return jobDetail;
|
||||
}
|
||||
|
||||
@Bean(name = "jobTrigger")
|
||||
public CronTriggerFactoryBean cronJobTrigger(MethodInvokingJobDetailFactoryBean jobDetail) {
|
||||
CronTriggerFactoryBean tigger = new CronTriggerFactoryBean();
|
||||
tigger.setJobDetail(jobDetail.getObject());
|
||||
tigger.setCronExpression("0 30 04 * * ?");// 表示每天七点半执行
|
||||
//tigger.setCronExpression("*/5 * * * * ?");//每五秒执行一次
|
||||
//tigger.set
|
||||
tigger.setName("myTigger");// trigger的name
|
||||
return tigger;
|
||||
|
||||
}
|
||||
|
||||
@Bean(name = "scheduler")
|
||||
public SchedulerFactoryBean schedulerFactory(Trigger cronJobTrigger) {
|
||||
SchedulerFactoryBean bean = new SchedulerFactoryBean();
|
||||
//设置是否任意一个已定义的Job会覆盖现在的Job。默认为false,即已定义的Job不会覆盖现有的Job。
|
||||
bean.setOverwriteExistingJobs(true);
|
||||
// 延时启动,应用启动5秒后 ,定时器才开始启动
|
||||
bean.setStartupDelay(5);
|
||||
// 注册定时触发器
|
||||
bean.setTriggers(cronJobTrigger);
|
||||
return bean;
|
||||
}
|
||||
//多任务时的Scheduler,动态设置Trigger。一个SchedulerFactoryBean可能会有多个Trigger
|
||||
@Bean(name = "multitaskScheduler")
|
||||
public SchedulerFactoryBean schedulerFactoryBean(){
|
||||
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
|
||||
return schedulerFactoryBean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package cn.hellohao.quartz;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Imgreview;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.service.ConfigService;
|
||||
import cn.hellohao.service.ImgreviewService;
|
||||
import cn.hellohao.service.KeysService;
|
||||
import cn.hellohao.service.impl.ImgServiceImpl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baidu.aip.contentcensor.AipContentCensor;
|
||||
import com.baidu.aip.contentcensor.EImgType;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
单任务执行,并且通过控制器的接口实现时间间隔的动态修改
|
||||
任务类
|
||||
* */
|
||||
@Configuration
|
||||
@Component
|
||||
@EnableScheduling
|
||||
public class SchedulerTask {
|
||||
|
||||
@Autowired
|
||||
private ImgServiceImpl imgService;
|
||||
@Autowired
|
||||
private ImgreviewService imgreviewService;
|
||||
@Autowired
|
||||
private KeysService keysService;
|
||||
|
||||
private static AipContentCensor client;
|
||||
|
||||
private static void Initializes(Imgreview imgreview) {
|
||||
client = new AipContentCensor(imgreview.getAppId(), imgreview.getApiKey(), imgreview.getSecretKey());
|
||||
client.setConnectionTimeoutInMillis(2000);
|
||||
client.setSocketTimeoutInMillis(60000);
|
||||
}
|
||||
|
||||
public void start() throws InterruptedException {
|
||||
|
||||
//System.out.println("活动开始!!!"+new Date());
|
||||
//查询鉴黄key
|
||||
Imgreview imgreview = imgreviewService.selectByPrimaryKey(1);
|
||||
//初始化鉴黄
|
||||
SchedulerTask.Initializes(imgreview);
|
||||
//计算出昨天的日期
|
||||
Date d = new Date();
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
String oldtime = df.format(new Date(d.getTime() - 1 * 24 * 60 * 60 * 1000));
|
||||
//服务器获取出这个时间段的值然后遍历
|
||||
List<Images> imglist= imgService.gettimeimg(oldtime);
|
||||
for (Images images : imglist) {
|
||||
|
||||
String imgurl = "http://"+images.getImgurl();
|
||||
System.err.println("正在鉴定的图片:" + imgurl);
|
||||
JSONObject res = client.antiPorn(imgurl);
|
||||
res = client.imageCensorUserDefined(imgurl, EImgType.URL, null);
|
||||
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.JSONArray data = jsonObject.getJSONArray("data");
|
||||
Integer conclusionType = jsonObject.getInteger("conclusionType");
|
||||
if (conclusionType == 2) {
|
||||
for (Object datum : data) {
|
||||
com.alibaba.fastjson.JSONObject imgdata = (com.alibaba.fastjson.JSONObject) datum;
|
||||
if (imgdata.getInteger("type") == 1) {
|
||||
//标记图片
|
||||
Integer ret = imgService.deleimgname(images.getImgname()); //删除数据库图片信息
|
||||
//Imgreview imgreview1 =imgreviewService.selectByPrimaryKey(1);
|
||||
Imgreview imgreview1 = new Imgreview();
|
||||
imgreview1.setId(1);
|
||||
Integer count = imgreview.getCount();
|
||||
System.out.println("违法图片总数:" + count);
|
||||
imgreview1.setCount(count + 1);
|
||||
imgreviewService.updateByPrimaryKeySelective(imgreview1);
|
||||
Keys key =null;
|
||||
if(images.getSource()==1){
|
||||
key = keysService.selectKeys(images.getSource());
|
||||
imgService.delect(key, images.getImgname());
|
||||
}else if (images.getSource()==2){
|
||||
key = keysService.selectKeys(images.getSource());
|
||||
imgService.delectOSS(key, images.getImgname());
|
||||
}else if(images.getSource()==3){
|
||||
//初始化腾讯云
|
||||
}else if(images.getSource()==4){
|
||||
//初始化七牛云
|
||||
}else{
|
||||
System.err.println("未获取到对象存储参数,上传失败。");
|
||||
}
|
||||
|
||||
if (ret == 1) {
|
||||
System.err.println("存在色情图片,删除成功。");
|
||||
} else {
|
||||
System.err.println("存在色情图片,删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.hellohao.quartz;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class test {
|
||||
public static void main(String[] args) {
|
||||
Date d = new Date();
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
String oldtime = df.format(new Date(d.getTime()));
|
||||
System.out.println(df.format(new Date()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.hellohao.service;
|
||||
|
||||
import cn.hellohao.pojo.Config;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface ConfigService {
|
||||
Config getSourceype();
|
||||
Integer setSourceype(Config config);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.hellohao.service;
|
||||
|
||||
import cn.hellohao.pojo.EmailConfig;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface EmailConfigService {
|
||||
EmailConfig getemail();
|
||||
Integer updateemail(EmailConfig emailConfig);
|
||||
}
|
||||
@@ -8,9 +8,21 @@ import org.apache.ibatis.annotations.Param;
|
||||
import cn.hellohao.pojo.Images;
|
||||
|
||||
public interface ImgService {
|
||||
List<Images> selectimg(Integer id);
|
||||
Integer deleimg(Integer id);
|
||||
Integer countimg(Integer userid);
|
||||
Images selectByPrimaryKey(Integer id);
|
||||
Integer counts(Integer userid);
|
||||
List<Images> selectimg(Integer id);
|
||||
|
||||
Integer deleimg(Integer id);
|
||||
|
||||
Integer countimg(Integer userid);
|
||||
|
||||
Images selectByPrimaryKey(Integer id);
|
||||
|
||||
Integer counts(Integer userid);
|
||||
|
||||
Integer setabnormal(String imgname);
|
||||
|
||||
Integer deleimgname(String imgname);
|
||||
|
||||
Integer deleall(Integer id);
|
||||
|
||||
List<Images> gettimeimg(String time);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.hellohao.service;
|
||||
|
||||
import cn.hellohao.pojo.Imgreview;
|
||||
|
||||
public interface ImgreviewService {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
int insert(Imgreview record);
|
||||
|
||||
int insertSelective(Imgreview record);
|
||||
|
||||
Imgreview selectByPrimaryKey(Integer id);
|
||||
|
||||
int updateByPrimaryKeySelective(Imgreview record);
|
||||
|
||||
int updateByPrimaryKey(Imgreview record);
|
||||
|
||||
}
|
||||
@@ -4,11 +4,10 @@ package cn.hellohao.service;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
|
||||
public interface KeysService {
|
||||
//查询密钥
|
||||
Keys selectKeys(Integer storageType);
|
||||
//查询key类型
|
||||
Integer selectKeysType();
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
//查询密钥
|
||||
Keys selectKeys(Integer storageType);
|
||||
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package cn.hellohao.service;
|
||||
|
||||
public interface NoticeService {
|
||||
|
||||
String getNotice();
|
||||
}
|
||||
@@ -3,19 +3,39 @@ package cn.hellohao.service;
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
//注册
|
||||
Integer register(User user);
|
||||
//登录
|
||||
Integer login(String email,String password);
|
||||
//获取用户信息
|
||||
User getUsers(String email);
|
||||
//插入图片
|
||||
Integer insertimg(Images img);
|
||||
//修改资料
|
||||
Integer change(User user);
|
||||
//检查用户名是否重复
|
||||
Integer checkUsername(String username);
|
||||
|
||||
Integer getUserTotal();
|
||||
//注册
|
||||
Integer register(User user);
|
||||
|
||||
//登录
|
||||
Integer login(String email, String password);
|
||||
|
||||
//获取用户信息
|
||||
User getUsers(String email);
|
||||
|
||||
//插入图片
|
||||
Integer insertimg(Images img);
|
||||
|
||||
//修改资料
|
||||
Integer change(User user);
|
||||
|
||||
//检查用户名是否重复
|
||||
Integer checkUsername(String username);
|
||||
|
||||
Integer getUserTotal();
|
||||
|
||||
List<User> getuserlist();
|
||||
|
||||
Integer deleuser(Integer id);
|
||||
|
||||
//查询用户名或者邮箱是否存在
|
||||
Integer countusername(String username);
|
||||
|
||||
Integer countmail(String email);
|
||||
|
||||
Integer uiduser(String uid);
|
||||
|
||||
User getUsersMail(String uid);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.dao.ConfigMapper;
|
||||
import cn.hellohao.pojo.Config;
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.service.ConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ConfigServiceImpl implements ConfigService {
|
||||
@Autowired
|
||||
private ConfigMapper configMapper;
|
||||
@Override
|
||||
public Config getSourceype() {
|
||||
return configMapper.getSourceype();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer setSourceype(Config config) {
|
||||
return configMapper.setSourceype(config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.dao.EmailConfigMapper;
|
||||
import cn.hellohao.pojo.EmailConfig;
|
||||
import cn.hellohao.service.EmailConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class EmailServiceImpl implements EmailConfigService {
|
||||
@Autowired
|
||||
EmailConfigMapper emailConfigMapper;
|
||||
@Override
|
||||
public EmailConfig getemail() {
|
||||
return emailConfigMapper.getemail();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateemail(EmailConfig emailConfig) {
|
||||
return emailConfigMapper.updateemail(emailConfig);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package cn.hellohao.service.impl;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -18,69 +19,112 @@ import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.service.ImgService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class ImgServiceImpl implements ImgService {
|
||||
@Autowired
|
||||
private ImgMapper imgMapper;
|
||||
@Autowired
|
||||
//@Resource
|
||||
private ImgMapper imgMapper;
|
||||
|
||||
@Override
|
||||
public List<Images> selectimg(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.selectimg(userid);
|
||||
}
|
||||
@Override
|
||||
public List<Images> selectimg(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.selectimg(userid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleimg(Integer id) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.deleimg(id);
|
||||
}
|
||||
@Override
|
||||
public Integer deleimg(Integer id) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.deleimg(id);
|
||||
}
|
||||
|
||||
|
||||
public Images selectByPrimaryKey(Integer id) {
|
||||
return imgMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
public Images selectByPrimaryKey(Integer id) {
|
||||
return imgMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
//删除对象存储的图片文件
|
||||
public void delect(Keys key,String fileName) {
|
||||
// 初始化
|
||||
Credentials credentials = new BasicCredentials(key.getAccessKey(), key.getAccessSecret());
|
||||
NosClient nosClient = new NosClient(credentials);
|
||||
nosClient.setEndpoint(key.getEndpoint());
|
||||
// 初始化TransferManager
|
||||
TransferManager transferManager = new TransferManager(nosClient);
|
||||
//删除对象存储的图片文件
|
||||
public void delect(Keys key, String fileName) {
|
||||
// 初始化
|
||||
Credentials credentials = new BasicCredentials(key.getAccessKey(), key.getAccessSecret());
|
||||
NosClient nosClient = new NosClient(credentials);
|
||||
nosClient.setEndpoint(key.getEndpoint());
|
||||
// 初始化TransferManager
|
||||
TransferManager transferManager = new TransferManager(nosClient);
|
||||
//列举桶
|
||||
ArrayList bucketList = new ArrayList();
|
||||
String tname = "";
|
||||
for (Bucket bucket : nosClient.listBuckets()) {
|
||||
bucketList.add(bucket.getName());
|
||||
}
|
||||
for (Object object : bucketList) {
|
||||
tname = object.toString();
|
||||
//查看桶的ACL
|
||||
CannedAccessControlList acl = nosClient.getBucketAcl(object.toString());
|
||||
// bucket权限
|
||||
}
|
||||
//这种方法不能删除指定文件夹下的文件
|
||||
boolean isExist = nosClient.doesObjectExist(tname, fileName, null);
|
||||
System.out.println("文件是否存在:" + isExist);
|
||||
if (isExist) {
|
||||
nosClient.deleteObject(tname, fileName);
|
||||
}
|
||||
|
||||
//列举桶
|
||||
ArrayList bucketList = new ArrayList();
|
||||
String tname = "";
|
||||
for (Bucket bucket : nosClient.listBuckets()) {
|
||||
bucketList.add(bucket.getName());
|
||||
}
|
||||
for (Object object : bucketList) {
|
||||
System.out.println("桶名:"+object.toString());
|
||||
tname = object.toString();
|
||||
//查看桶的ACL
|
||||
CannedAccessControlList acl = nosClient.getBucketAcl(object.toString());
|
||||
// bucket权限
|
||||
System.out.println("这个桶的权限是:"+acl.toString());
|
||||
}
|
||||
//这是删除文件的方法
|
||||
boolean isExist = nosClient.doesObjectExist(tname,fileName,null);
|
||||
System.out.println("文件是否存在:"+isExist);
|
||||
|
||||
nosClient.deleteObject(tname,fileName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer counts(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.counts(userid);
|
||||
}
|
||||
//删除OSS对象存储的图片文件
|
||||
public void delectOSS(Keys key, String fileName) {
|
||||
// 初始化
|
||||
// Endpoint以杭州为例,其它Region请按实际情况填写。
|
||||
String endpoint = key.getEndpoint();
|
||||
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
||||
String accessKeyId = key.getAccessKey();
|
||||
String accessKeySecret = key.getAccessSecret();
|
||||
String bucketName = key.getBucketname();
|
||||
String objectName = fileName;
|
||||
|
||||
@Override
|
||||
public Integer countimg(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.countimg(userid);
|
||||
}
|
||||
// 创建OSSClient实例。
|
||||
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
// 删除文件。
|
||||
ossClient.deleteObject(bucketName, objectName);
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer counts(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.counts(userid);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer countimg(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.countimg(userid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer setabnormal(String imgname) {
|
||||
return imgMapper.setabnormal(imgname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleimgname(String imgname) {
|
||||
return imgMapper.deleimgname(imgname);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleall(Integer id) {
|
||||
return imgMapper.deleall(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Images> gettimeimg(String time) {
|
||||
return imgMapper.gettimeimg(time);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.dao.ImgreviewMapper;
|
||||
import cn.hellohao.pojo.Imgreview;
|
||||
import cn.hellohao.service.ImgreviewService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ImgreviewServiceImpl implements ImgreviewService {
|
||||
|
||||
@Autowired
|
||||
private ImgreviewMapper imgreviewMapper;
|
||||
|
||||
@Override
|
||||
public int deleteByPrimaryKey(Integer id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(Imgreview record) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertSelective(Imgreview record) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Imgreview selectByPrimaryKey(Integer id) {
|
||||
return imgreviewMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKeySelective(Imgreview record) {
|
||||
return imgreviewMapper.updateByPrimaryKeySelective(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateByPrimaryKey(Imgreview record) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -9,26 +9,21 @@ import cn.hellohao.service.KeysService;
|
||||
|
||||
@Service
|
||||
public class KeysServiceImpl implements KeysService {
|
||||
|
||||
@Autowired
|
||||
private KeysMapper keysMapper;
|
||||
|
||||
@Override
|
||||
public Keys selectKeys(Integer storageType) {
|
||||
// TODO Auto-generated method stub
|
||||
return keysMapper.selectKeys(storageType);
|
||||
}
|
||||
@Autowired
|
||||
private KeysMapper keysMapper;
|
||||
|
||||
@Override
|
||||
public Integer selectKeysType() {
|
||||
// TODO Auto-generated method stub
|
||||
return keysMapper.selectKeysType();
|
||||
}
|
||||
@Override
|
||||
public Keys selectKeys(Integer storageType) {
|
||||
// TODO Auto-generated method stub
|
||||
return keysMapper.selectKeys(storageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateKey(Keys key) {
|
||||
// TODO Auto-generated method stub
|
||||
return keysMapper.updateKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateKey(Keys key) {
|
||||
// TODO Auto-generated method stub
|
||||
return keysMapper.updateKey(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import cn.hellohao.pojo.Keys;
|
||||
|
||||
@Service
|
||||
public class NOSImageupload {
|
||||
//直接读取properties文件的值
|
||||
//直接读取properties文件的值
|
||||
// @Value("${AccessKey}")
|
||||
// private String AccessKey;
|
||||
// @Value("${AccessSecret}")
|
||||
@@ -36,60 +36,68 @@ public class NOSImageupload {
|
||||
// private String Bucketname;
|
||||
// @Value("${RequestAddress}")
|
||||
// private String RequestAddress;
|
||||
static String BarrelName;
|
||||
static NosClient nosClient;
|
||||
static Keys key;
|
||||
static String BarrelName;
|
||||
static NosClient nosClient;
|
||||
static Keys key;
|
||||
|
||||
public Map<String, Integer> Imageupload(Map<String, MultipartFile> fileMap) throws Exception {
|
||||
// 要上传文件的路径
|
||||
Map<String, Integer> ImgUrl = new HashMap<>();
|
||||
for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
//System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
|
||||
File file = changeFile(entry.getValue());
|
||||
try {
|
||||
nosClient.putObject(BarrelName, uuid + "." + entry.getKey(), file);
|
||||
ImgUrl.put(key.getRequestAddress() + "/" + uuid + "." + entry.getKey(), (int) (entry.getValue().getSize()));
|
||||
} catch (Exception e) {
|
||||
System.out.println("上传报错==" + e.getMessage());
|
||||
}
|
||||
}
|
||||
return ImgUrl;
|
||||
}
|
||||
public Map<String, Integer> Imageupload(Map<String, MultipartFile> fileMap, String username) throws Exception {
|
||||
// String Catalog = "";//默认游客目录
|
||||
// if(username.equals("tourist")){
|
||||
// Catalog = "tourist";
|
||||
// }else{
|
||||
// Catalog = username;
|
||||
// }
|
||||
// 要上传文件的路径
|
||||
File file = null;
|
||||
Map<String, Integer> ImgUrl = new HashMap<>();
|
||||
for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,5);//生成一个没有-的uuid,然后取前5位
|
||||
java.text.DateFormat format1 = new java.text.SimpleDateFormat("MMddhhmmss");
|
||||
String times = format1.format(new Date());
|
||||
file = changeFile(entry.getValue());
|
||||
try {
|
||||
nosClient.putObject(BarrelName, username + "/" + uuid+times + "." + entry.getKey(), file);
|
||||
ImgUrl.put(key.getRequestAddress() + "/" + username + "/" + uuid+times + "." + entry.getKey(), (int) (entry.getValue().getSize()));
|
||||
} catch (Exception e) {
|
||||
System.out.println("上传报错:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
return ImgUrl;
|
||||
}
|
||||
|
||||
// 转换文件方法
|
||||
private File changeFile(MultipartFile multipartFile) throws Exception {
|
||||
// 获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
// 获取文件后缀
|
||||
String prefix = fileName.substring(fileName.lastIndexOf("."));
|
||||
// todo 修改临时文件文件名
|
||||
File file = File.createTempFile(fileName, prefix);
|
||||
// MultipartFile to File
|
||||
multipartFile.transferTo(file);
|
||||
return file;
|
||||
}
|
||||
// 转换文件方法
|
||||
private File changeFile(MultipartFile multipartFile) throws Exception {
|
||||
// 获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
// 获取文件后缀
|
||||
String prefix = fileName.substring(fileName.lastIndexOf("."));
|
||||
// todo 修改临时文件文件名
|
||||
File file = File.createTempFile(fileName, prefix);
|
||||
// MultipartFile to File
|
||||
multipartFile.transferTo(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
//初始化对象存储
|
||||
public static void Initialize(Keys k){
|
||||
// 初始化
|
||||
Credentials credentials = new BasicCredentials(k.getAccessKey(), k.getAccessSecret());
|
||||
nosClient = new NosClient(credentials);
|
||||
nosClient.setEndpoint(k.getEndpoint());
|
||||
// 初始化TransferManager
|
||||
TransferManager transferManager = new TransferManager(nosClient);
|
||||
// 列举桶
|
||||
ArrayList bucketList = new ArrayList();
|
||||
for (Bucket bucket : nosClient.listBuckets()) {
|
||||
bucketList.add(bucket.getName());
|
||||
}
|
||||
for (Object object : bucketList) {
|
||||
if (object.toString().equals(k.getBucketname())) {
|
||||
BarrelName = object.toString();
|
||||
}
|
||||
}
|
||||
key = k;
|
||||
}
|
||||
//初始化网易NOS对象存储
|
||||
public static void Initialize(Keys k) {
|
||||
// 初始化
|
||||
Credentials credentials = new BasicCredentials(k.getAccessKey(), k.getAccessSecret());
|
||||
nosClient = new NosClient(credentials);
|
||||
nosClient.setEndpoint(k.getEndpoint());
|
||||
// 初始化TransferManager
|
||||
TransferManager transferManager = new TransferManager(nosClient);
|
||||
// 列举桶
|
||||
ArrayList bucketList = new ArrayList();
|
||||
for (Bucket bucket : nosClient.listBuckets()) {
|
||||
bucketList.add(bucket.getName());
|
||||
}
|
||||
for (Object object : bucketList) {
|
||||
if (object.toString().equals(k.getBucketname())) {
|
||||
BarrelName = object.toString();
|
||||
}
|
||||
}
|
||||
key = k;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.dao.NoticeMapper;
|
||||
import cn.hellohao.service.NoticeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class NoticeServiceImpl implements NoticeService {
|
||||
|
||||
@Autowired
|
||||
private NoticeMapper noticeMapper;
|
||||
|
||||
@Override
|
||||
public String getNotice() {
|
||||
return noticeMapper.getNotice();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
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 OSSImageupload {
|
||||
static String BarrelName;
|
||||
static OSSClient ossClient;
|
||||
static Keys key;
|
||||
|
||||
public Map<String, Integer> ImageuploadOSS(Map<String, MultipartFile> fileMap, String username) throws Exception {
|
||||
// 要上传文件的路径
|
||||
File file = null;
|
||||
Map<String, Integer> ImgUrl = new HashMap<>();
|
||||
//设置Header
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
meta.setHeader("Content-Disposition", "inline");
|
||||
for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,5);//生成一个没有-的uuid,然后取前5位
|
||||
java.text.DateFormat format1 = new java.text.SimpleDateFormat("MMddhhmmss");
|
||||
String times = format1.format(new Date());
|
||||
file = changeFile(entry.getValue());
|
||||
|
||||
String head = "";
|
||||
if(entry.getKey().equals("jpg")||entry.getKey().equals("jpeg")){
|
||||
head = "image/jpeg";
|
||||
}else if(entry.getKey().equals("png")){
|
||||
head = "image/png";
|
||||
}else if(entry.getKey().equals("bmp")){
|
||||
head = "image/bmp";
|
||||
}else if(entry.getKey().equals("gif")){
|
||||
head = "image/gif";
|
||||
}else{
|
||||
System.err.println("位置格式文件,无法定义header头。");
|
||||
}
|
||||
meta.setHeader("Content-Type", head);//image/jpeg
|
||||
// 上传文件流。
|
||||
ossClient.putObject(key.getBucketname(), username + "/" + uuid+times + "." + entry.getKey(),file,meta);
|
||||
// 关闭OSSClient。
|
||||
//ossClient.shutdown();
|
||||
ImgUrl.put(key.getRequestAddress() + "/" + username + "/" + uuid+times + "." + entry.getKey(), (int) (entry.getValue().getSize()));
|
||||
|
||||
}
|
||||
return ImgUrl;
|
||||
}
|
||||
|
||||
// 转换文件方法
|
||||
private File changeFile(MultipartFile multipartFile) throws Exception {
|
||||
// 获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
// 获取文件后缀
|
||||
String prefix = fileName.substring(fileName.lastIndexOf("."));
|
||||
// todo 修改临时文件文件名
|
||||
File file = File.createTempFile(fileName, prefix);
|
||||
// MultipartFile to File
|
||||
multipartFile.transferTo(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
//初始化网易NOS对象存储
|
||||
public static void Initialize(Keys k) {
|
||||
// 初始化
|
||||
// Endpoint以杭州为例,其它Region请按实际情况填写。
|
||||
String endpoint = "http://oss-cn-beijing.aliyuncs.com";
|
||||
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
||||
String accessKeyId = "LTAI0Yd6Li0VxrUF";
|
||||
String accessKeySecret = "F2ZuDMq0IYefvVDKyfJLpRNzXldci9";
|
||||
String bucketName = "hellohao";
|
||||
// 创建OSSClient实例。
|
||||
ossClient = new OSSClient(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
|
||||
key = k;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -7,53 +7,84 @@ import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.service.UserService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public Integer register(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
return userMapper.register(user);
|
||||
}
|
||||
@Override
|
||||
public Integer register(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@Override
|
||||
public Integer login(String email, String password) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.login(email, password);
|
||||
}
|
||||
return userMapper.register(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUsers(String email) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.getUsers(email);
|
||||
}
|
||||
@Override
|
||||
public Integer login(String email, String password) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.login(email, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer insertimg(Images img) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.insertimg(img);
|
||||
}
|
||||
@Override
|
||||
public User getUsers(String email) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.getUsers(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer change(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.change(user);
|
||||
}
|
||||
@Override
|
||||
public Integer insertimg(Images img) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.insertimg(img);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer checkUsername(String username) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.checkUsername(username);
|
||||
}
|
||||
@Override
|
||||
public Integer change(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.change(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getUserTotal() {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.getUserTotal();
|
||||
}
|
||||
@Override
|
||||
public Integer checkUsername(String username) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.checkUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getUserTotal() {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.getUserTotal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleuser(Integer id) {
|
||||
return userMapper.deleuser(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countusername(String username) {
|
||||
return userMapper.countusername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countmail(String email) {
|
||||
return userMapper.countmail(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> getuserlist() {
|
||||
return userMapper.getuserlist();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer uiduser(String uid) {
|
||||
return userMapper.uiduser(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUsersMail(String uid) {
|
||||
return userMapper.getUsersMail(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.hellohao.test;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class MyAuthenticator extends Authenticator {
|
||||
/*在使用Authenticator这个抽象类时,我们必须采用继承该抽象类的方式,并且该继承类必须具
|
||||
* 有返回PasswordAuthentication对象(用于存储认证时要用到的用户名、密码)getPasswordAuthentication()
|
||||
* 方法。并且要在Session中进行注册,使Session能够了解在认证时该使用哪个类。
|
||||
* */
|
||||
public static void main(String[] args) throws Exception {
|
||||
//获取本机的ip地址和域名
|
||||
InetAddress ia = InetAddress.getLocalHost();
|
||||
System.out.println(ia.toString());
|
||||
System.out.println(ia.getHostName());//域名 127
|
||||
System.out.println(ia.getHostAddress());//ip地址 192.168.201.254
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
package cn.hellohao.test;␍␍import com.alibaba.fastjson.JSONObject;␍␍import java.io.BufferedReader;␍import java.io.IOException;␍import java.io.InputStreamReader;␍import java.net.MalformedURLException;␍import java.net.URL;␍import java.net.URLConnection;␍import java.util.*;␍␍/** ␍ * ␍ * 于第一种方式相比,优势 1>当启动和去取消任务时可以控制 2>第一次执行任务时可以指定你想要的delay时间 ␍ * ␍ * 在实现时,Timer类可以调度任务,TimerTask则是通过在run()方法里实现具体任务。 Timer实例可以调度多任务,它是线程安全的。 ␍ * 当Timer的构造器被调用时,它创建了一个线程,这个线程可以用来调度任务。 下面是代码: ␍ * ␍ * @author GT ␍ * ␍ */ ␍public class Task2 {␍ public static void main(String[] args) {␍␍ TimerTask task = new TimerTask() {␍ Map<String, Integer> map = new HashMap<String, Integer>();␍ @Override␍ public void run() {␍ // task to run goes here ␍ //System.out.println("Hello !!!");␍ String url = "http://ip.360.cn/IPShare/info";␍ String json = loadJSON(url);␍ //System.out.println(json);␍␍ JSONObject pa=JSONObject.parseObject(json);␍ //System.out.println(pa.getString("ip"));␍ map.put(pa.getString("ip"),5);␍ List<Map.Entry<Object, Object>> li = getKeyBySameValue(map);␍ Integer count = 0;␍ for (int i = 0;i<li.size();i++){␍ System.out.println(li.get(i).getKey());␍ Integer a = Integer.parseInt(String.valueOf(li.get(i).getKey()));␍ count = count+a;␍ if (count>30){␍ System.out.println("您已经被限制!");␍ }␍␍ }␍ }␍ }; ␍ Timer timer = new Timer(); ␍ long delay = 0; ␍ long intevalPeriod = 5 * 1000;␍ // schedules the task to be run in an interval ␍ timer.scheduleAtFixedRate(task, delay, intevalPeriod); ␍ } // end of main␍␍␍ //获取本机ip␍ public static String loadJSON(String url) {␍ StringBuilder json = new StringBuilder();␍ try {␍ URL oracle = new URL(url);␍ URLConnection yc = oracle.openConnection();␍ BufferedReader in = new BufferedReader(new InputStreamReader(␍ yc.getInputStream(),"utf-8"));//防止乱码␍ String inputLine = null;␍ while ((inputLine = in.readLine()) != null) {␍ json.append(inputLine);␍ }␍ in.close();␍ } catch (MalformedURLException e) {␍ e.printStackTrace();␍ } catch (IOException e) {␍ e.printStackTrace();␍ }␍ return json.toString();␍ }␍␍␍ public static List<Map.Entry<Object, Object>> getKeyBySameValue(Map map){␍ Map values = new HashMap();␍ List list;␍ Iterator iterator = map.keySet().iterator();␍ while (iterator.hasNext()) {␍ Object key = iterator.next();␍ Object value = map.get(key);␍ if (map.containsValue(value)) {␍ if (values.containsKey(value)) {␍ list = (List) values.get(value);␍ } else {␍ list = new ArrayList();␍ }␍ list.add(key);␍ values.put(value, list);␍ }␍ }␍ iterator = values.keySet().iterator();␍ Map<Object,Object> newMap = new HashMap<>();␍ while (iterator.hasNext()) {␍ Object value = iterator.next();␍ List result = (List) values.get(value);␍ if (result.size() > 1) {␍ System.out.println("value :" + value + " -> keys:"␍ + result.toString());␍ }␍ newMap.put(value,result.toString());␍ }␍ List<Map.Entry<Object, Object>> returnList = new ArrayList<>(newMap.entrySet());␍ return returnList;␍ }␍␍␍␍}
|
||||
package cn.hellohao.test;␍␍import com.alibaba.fastjson.JSONObject;␍␍import java.io.BufferedReader;␍import java.io.IOException;␍import java.io.InputStreamReader;␍import java.net.MalformedURLException;␍import java.net.URL;␍import java.net.URLConnection;␍import java.util.*;␍␍/**␍ * 于第一种方式相比,优势 1>当启动和去取消任务时可以控制 2>第一次执行任务时可以指定你想要的delay时间␍ * <p>␍ * 在实现时,Timer类可以调度任务,TimerTask则是通过在run()方法里实现具体任务。 Timer实例可以调度多任务,它是线程安全的。␍ * 当Timer的构造器被调用时,它创建了一个线程,这个线程可以用来调度任务。 下面是代码:␍ *␍ * @author GT␍ */␍public class Task2 {␍ public static void main(String[] args) {␍␍ TimerTask task = new TimerTask() {␍ Map<String, Integer> map = new HashMap<String, Integer>();␍␍ @Override␍ public void run() {␍ // task to run goes here ␍ //System.out.println("Hello !!!");␍ String url = "http://ip.360.cn/IPShare/info";␍ String json = loadJSON(url);␍ //System.out.println(json);␍␍ JSONObject pa = JSONObject.parseObject(json);␍ //System.out.println(pa.getString("ip"));␍ map.put(pa.getString("ip"), 5);␍ List<Map.Entry<Object, Object>> li = getKeyBySameValue(map);␍ Integer count = 0;␍ for (int i = 0; i < li.size(); i++) {␍ System.out.println(li.get(i).getKey());␍ Integer a = Integer.parseInt(String.valueOf(li.get(i).getKey()));␍ count = count + a;␍ if (count > 30) {␍ System.out.println("您已经被限制!");␍ }␍␍ }␍ }␍ };␍ Timer timer = new Timer();␍ long delay = 0;␍ long intevalPeriod = 5 * 1000;␍ // schedules the task to be run in an interval ␍ timer.scheduleAtFixedRate(task, delay, intevalPeriod);␍ } // end of main␍␍␍ //获取本机ip␍ public static String loadJSON(String url) {␍ StringBuilder json = new StringBuilder();␍ try {␍ URL oracle = new URL(url);␍ URLConnection yc = oracle.openConnection();␍ BufferedReader in = new BufferedReader(new InputStreamReader(␍ yc.getInputStream(), "utf-8"));//防止乱码␍ String inputLine = null;␍ while ((inputLine = in.readLine()) != null) {␍ json.append(inputLine);␍ }␍ in.close();␍ } catch (MalformedURLException e) {␍ e.printStackTrace();␍ } catch (IOException e) {␍ e.printStackTrace();␍ }␍ return json.toString();␍ }␍␍␍ public static List<Map.Entry<Object, Object>> getKeyBySameValue(Map map) {␍ Map values = new HashMap();␍ List list;␍ Iterator iterator = map.keySet().iterator();␍ while (iterator.hasNext()) {␍ Object key = iterator.next();␍ Object value = map.get(key);␍ if (map.containsValue(value)) {␍ if (values.containsKey(value)) {␍ list = (List) values.get(value);␍ } else {␍ list = new ArrayList();␍ }␍ list.add(key);␍ values.put(value, list);␍ }␍ }␍ iterator = values.keySet().iterator();␍ Map<Object, Object> newMap = new HashMap<>();␍ while (iterator.hasNext()) {␍ Object value = iterator.next();␍ List result = (List) values.get(value);␍ if (result.size() > 1) {␍ System.out.println("value :" + value + " -> keys:"␍ + result.toString());␍ }␍ newMap.put(value, result.toString());␍ }␍ List<Map.Entry<Object, Object>> returnList = new ArrayList<>(newMap.entrySet());␍ return returnList;␍ }␍␍␍}
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.hellohao.test;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.common.utils.BinaryUtil;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
|
||||
public class alioss {
|
||||
//上传文件
|
||||
public static void shangchuan() throws Exception{
|
||||
// Endpoint以杭州为例,其它Region请按实际情况填写。
|
||||
String endpoint = "http://oss-cn-beijing.aliyuncs.com";
|
||||
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
||||
String accessKeyId = "LTAI0Yd6Li0VxrUF";
|
||||
String accessKeySecret = "F2ZuDMq0IYefvVDKyfJLpRNzXldci9";
|
||||
String bucketName = "hellohao";
|
||||
//String objectName = "hellohao.png";
|
||||
//设置Header
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
meta.setHeader("Content-Type", "image/jpeg");//image/jpeg
|
||||
meta.setHeader("Content-Disposition", "inline");
|
||||
|
||||
// 创建OSSClient实例。
|
||||
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
// 上传文件流。
|
||||
InputStream inputStream = new FileInputStream("D:\\桌面\\资料\\TouXiang.png");
|
||||
//ossClient.putObject(bucketName, "test/TouXiang.png", inputStream,meta);
|
||||
ossClient.deleteObject(bucketName, "test/TouXiang.png");
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
alioss.shangchuan();
|
||||
//image/jpeg
|
||||
}
|
||||
|
||||
|
||||
public void settou(){
|
||||
|
||||
// Endpoint以杭州为例,其它Region请按实际情况填写。
|
||||
String endpoint = "http://oss-cn-beijing.aliyuncs.com";
|
||||
// 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
||||
String accessKeyId = "LTAI0Yd6Li0VxrUF";
|
||||
String accessKeySecret = "F2ZuDMq0IYefvVDKyfJLpRNzXldci9";
|
||||
|
||||
//String content = "hellohao";
|
||||
|
||||
// 创建上传文件的元信息,可以通过文件元信息设置HTTP header。
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
|
||||
//String md5 = BinaryUtil.toBase64String(BinaryUtil.calculateMd5(content.getBytes()));
|
||||
// 开启文件内容MD5校验。开启后OSS会把您提供的MD5与文件的MD5比较,不一致则抛出异常。
|
||||
//meta.setContentMD5(md5);
|
||||
// 指定上传的内容类型。内容类型决定浏览器将以什么形式、什么编码读取文件。如果没有指定则根据文件的扩展名生成,如果没有扩展名则为默认值application/octet-stream。
|
||||
meta.setContentType("text/plain");
|
||||
// 设置内容被下载时的名称。
|
||||
meta.setContentDisposition("attachment; filename=\"DownloadFilename\"");
|
||||
// 设置上传文件的长度。如超过此长度,则会被截断,为设置的长度。如不足,则为上传文件的实际长度。
|
||||
//meta.setContentLength(content.length());
|
||||
// 设置内容被下载时网页的缓存行为。
|
||||
meta.setCacheControl("Download Action");
|
||||
// 设置缓存过期时间,格式是格林威治时间(GMT)。
|
||||
//meta.setExpirationTime(DateUtil.parseIso8601Date("2022-10-12T00:00:00.000Z"));
|
||||
// 设置内容被下载时的编码格式。
|
||||
meta.setContentEncoding("utf-8");
|
||||
// 设置header。
|
||||
meta.setHeader("<yourHeader>", "<yourHeaderValue>");
|
||||
// 创建OSSClient实例。
|
||||
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
// 上传文件。
|
||||
//ossClient.putObject("<yourBucketName>", "<yourObjectName>", new ByteArrayInputStream(content.getBytes()), meta);
|
||||
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
package cn.hellohao.test;␍␍import java.io.IOException;␍import java.util.Scanner;␍␍public class asdf {␍ public static void main(String[] args) {␍// TODO Auto-generated method stub␍ try {long start = System.currentTimeMillis();Process process = Runtime.getRuntime().exec(new String[] {"wmic","cpu","get","ProcessorId"});process.getOutputStream().close();Scanner sc = new Scanner(process.getInputStream());String property = sc.next();String serial = sc.next();System.out.println(property +":"+ serial);System.out.println("time:"+ (System.currentTimeMillis() - start));␍ } catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();␍ }␍ }␍␍␍}␍
|
||||
package cn.hellohao.test;␍␍import java.io.*;␍import java.net.HttpURLConnection;␍import java.net.MalformedURLException;␍import java.net.URL;␍␍/**␍ * @program: email-demo␍ * @description:␍ * @author: smallsoup␍ * @create: 2019-01-27 16:44␍ **/␍␍public class asdf {␍ public static void main(String[] a) {␍ try {␍ URL url = new URL("https://v1.hitokoto.cn/");␍ BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));␍ //BufferedWriter writer=new BufferedWriter(new FileWriter("index.html"));␍ String str = "";␍ String line;␍ while ((line = reader.readLine()) != null) {␍␍ str = line;␍ System.out.println(str);␍ }␍ reader.close();␍ //writer.close();␍ } catch (MalformedURLException e) {␍ e.printStackTrace();␍ } catch (IOException e) {␍ e.printStackTrace();␍ }␍␍ }␍}␍
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.hellohao.test;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class geshihuashijian {
|
||||
|
||||
//盐,用于混交md5
|
||||
private static final String slat = "&%5123***&&%%$$#@";
|
||||
|
||||
public static String getMD5(String str) {
|
||||
String base = str +"/"+slat;
|
||||
String md5 = DigestUtils.md5DigestAsHex(base.getBytes());
|
||||
return md5;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Date d = new Date();
|
||||
System.out.println(DateFormat.getDateInstance().format(d));
|
||||
String uid = UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,5);
|
||||
java.text.DateFormat format1 = new java.text.SimpleDateFormat("MMddhhmmss");
|
||||
String s = format1.format(new Date());
|
||||
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
System.out.println(uid+s);
|
||||
System.out.println("两天前的日期:" + df.format(new Date(d.getTime() - 2 * 24 * 60 * 60 * 1000)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package cn.hellohao.test;
|
||||
|
||||
import com.baidu.aip.contentcensor.AipContentCensor;
|
||||
import com.baidu.aip.contentcensor.EImgType;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class imgsh {
|
||||
//设置APPID/AK/SK
|
||||
private static final String APP_ID = "15434135";
|
||||
private static final String API_KEY = "yDdHaeMf0FfFAxupXFkoxoPG";
|
||||
private static final String SECRET_KEY = "QGRXTy8QNDMr0dWuWS6bj7rNcwtEddKe";
|
||||
|
||||
private imgsh() {
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private static AipContentCensor client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);
|
||||
|
||||
public static AipContentCensor getConn() {
|
||||
client.setConnectionTimeoutInMillis(2000);
|
||||
client.setSocketTimeoutInMillis(60000);
|
||||
return client;
|
||||
}
|
||||
|
||||
private static AipContentCensor chushihua() {
|
||||
// 初始化一个AipImageCensor
|
||||
AipContentCensor client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);
|
||||
//AipImageCensor client = new AipImageCensor(APP_ID, API_KEY, SECRET_KEY);
|
||||
|
||||
// 可选:设置网络连接参数
|
||||
client.setConnectionTimeoutInMillis(2000);
|
||||
client.setSocketTimeoutInMillis(60000);
|
||||
|
||||
// 可选:设置代理服务器地址, http和socket二选一,或者均不设置
|
||||
//client.setHttpProxy("proxy_host", proxy_port); // 设置http代理
|
||||
//client.setSocketProxy("proxy_host", proxy_port); // 设置socket代理
|
||||
|
||||
// 可选:设置log4j日志输出格式,若不设置,则使用默认配置
|
||||
// 也可以直接通过jvm启动参数设置此环境变量
|
||||
//System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");
|
||||
|
||||
// // 调用接口
|
||||
// String path = "test.jpg";
|
||||
// JSONObject res = client.antiPorn(path);
|
||||
// System.out.println(res.toString(2));
|
||||
return client;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
AipContentCensor client = chushihua();
|
||||
sample(client);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void sample(AipContentCensor client) {
|
||||
// // 参数为本地图片路径
|
||||
// String path = "test.jpg";
|
||||
// JSONObject response = client.imageCensorUserDefined(path, EImgType.FILE, null);
|
||||
// System.out.println(response.toString());
|
||||
|
||||
// 参数为url
|
||||
//String url = "https://hellohao.nos-eastchina1.126.net/BlogImg/%E8%BF%99%E6%98%AF%E6%B5%8B%E8%AF%95%E6%96%87%E4%BB%B6%E5%A4%B9/huang.png";
|
||||
String url = "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4225605092,1601815977&fm=26&gp=0.jpg";
|
||||
JSONObject res = client.antiPorn(url);
|
||||
res = client.imageCensorUserDefined(url, EImgType.URL, null);
|
||||
System.out.println(res.toString());
|
||||
|
||||
// // 参数为本地图片文件二进制数组
|
||||
// byte[] file = readImageFile(imagePath);
|
||||
// response = client.imageCensorUserDefined(file, null);
|
||||
// System.out.println(response.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.hellohao.test;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class jsontest {
|
||||
public static void main(String[] args) {
|
||||
String str = "[{\"conclusion\":\"不合规\",\"log_id\":15574879277703875,\"data\":[{\"msg\":\"存在色情内容\",\"probability\":1,\"type\":1}],\"conclusionType\":2}]\n";
|
||||
|
||||
JSONArray jsonArray = JSON.parseArray(str);
|
||||
for (Object o : jsonArray) {
|
||||
JSONObject jsonObject = (JSONObject) o;
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
for (Object datum : data) {
|
||||
JSONObject aaa = (JSONObject) datum;
|
||||
System.out.println(aaa.getString("msg"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import cn.hellohao.pojo.Imgreview;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.service.ImgreviewService;
|
||||
import cn.hellohao.service.impl.ImgServiceImpl;
|
||||
import cn.hellohao.service.impl.ImgreviewServiceImpl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baidu.aip.contentcensor.AipContentCensor;
|
||||
import com.baidu.aip.contentcensor.EImgType;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class ImageReview {
|
||||
|
||||
//设置APPID/AK/SK
|
||||
// private static final String APP_ID = "15434135";
|
||||
// private static final String API_KEY = "yDdHaeMf0FfFAxupXFkoxoPG";
|
||||
// private static final String SECRET_KEY = "QGRXTy8QNDMr0dWuWS6bj7rNcwtEddKe";
|
||||
private static AipContentCensor client;
|
||||
|
||||
private ImageReview() {
|
||||
}
|
||||
|
||||
|
||||
private static void Initializes(Imgreview imgreview) {
|
||||
client = new AipContentCensor(imgreview.getAppId(), imgreview.getApiKey(), imgreview.getSecretKey());
|
||||
client.setConnectionTimeoutInMillis(2000);
|
||||
client.setSocketTimeoutInMillis(60000);
|
||||
}
|
||||
|
||||
//开始调用鉴黄。
|
||||
public static void imgJB(Map<String, Integer> imgmap, String requestAddress, Keys key, Imgreview imgreview) {
|
||||
ImgServiceImpl imgService = SpringContextHolder.getBean(ImgServiceImpl.class);
|
||||
ImgreviewServiceImpl imgreviewService = SpringContextHolder.getBean(ImgreviewServiceImpl.class);
|
||||
ImageReview.Initializes(imgreview);
|
||||
//遍历map,获取里边的key(图片地址)
|
||||
for (Map.Entry<String, Integer> entry : imgmap.entrySet()) {
|
||||
System.out.println("正在鉴定的图片:" + entry.getKey());
|
||||
JSONObject res = client.antiPorn(entry.getKey());
|
||||
res = client.imageCensorUserDefined("http://" + entry.getKey(), EImgType.URL, null);
|
||||
|
||||
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.JSONArray data = jsonObject.getJSONArray("data");
|
||||
Integer conclusionType = jsonObject.getInteger("conclusionType");
|
||||
if (conclusionType == 2) {
|
||||
for (Object datum : data) {
|
||||
com.alibaba.fastjson.JSONObject imgdata = (com.alibaba.fastjson.JSONObject) datum;
|
||||
if (imgdata.getInteger("type") == 1) {
|
||||
//标记图片
|
||||
String imgname = SetText.getSubString(entry.getKey(), requestAddress, "");
|
||||
Integer ret = imgService.deleimgname(imgname); //删除数据库图片信息
|
||||
//Imgreview imgreview1 =imgreviewService.selectByPrimaryKey(1);
|
||||
Imgreview imgreview1 = new Imgreview();
|
||||
imgreview1.setId(1);
|
||||
Integer count = imgreview.getCount();
|
||||
System.out.println("总数:" + count);
|
||||
imgreview1.setCount(count + 1);
|
||||
imgreviewService.updateByPrimaryKeySelective(imgreview1);
|
||||
|
||||
if(key.getStorageType()==1){
|
||||
imgService.delect(key, imgname);
|
||||
}else if (key.getStorageType()==2){
|
||||
imgService.delectOSS(key, imgname);
|
||||
}else if(key.getStorageType()==3){
|
||||
//初始化腾讯云
|
||||
}else if(key.getStorageType()==4){
|
||||
//初始化七牛云
|
||||
}else{
|
||||
System.err.println("未获取到对象存储参数,上传失败。");
|
||||
}
|
||||
|
||||
if (ret == 1) {
|
||||
System.out.println("存在色情图片,删除成功。");
|
||||
} else {
|
||||
System.out.println("存在色情图片,删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import cn.hellohao.pojo.EmailConfig;
|
||||
import cn.hellohao.service.EmailConfigService;
|
||||
import cn.hellohao.test.asdf;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.mail.*;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
public class SendEmail {
|
||||
// 发件人 账号和密码
|
||||
// private static String MY_EMAIL_NAME = "Hellohao图床";
|
||||
// private static String MY_EMAIL_ACCOUNT = "helloshihao@163.com";
|
||||
// private static String MY_EMAIL_PASSWORD = "hellohao950504";// 密码,是你自己的设置的授权码
|
||||
// // SMTP服务器(这里用的163 SMTP服务器)
|
||||
// public static String MEAIL_163_SMTP_HOST = "smtp.163.com";
|
||||
// public static String SMTP_163_PORT = "25";// 端口号,这个是163使用到的;QQ的应该是465或者875
|
||||
|
||||
public static MimeMessage Emails(EmailConfig emailConfig) {
|
||||
Properties p = new Properties();
|
||||
p.setProperty("mail.smtp.host", emailConfig.getEmailurl());
|
||||
p.setProperty("mail.smtp.port", emailConfig.getPort());
|
||||
p.setProperty("mail.smtp.socketFactory.port", emailConfig.getPort());
|
||||
p.setProperty("mail.smtp.auth", "true");
|
||||
p.setProperty("mail.smtp.socketFactory.class", "SSL_FACTORY");
|
||||
|
||||
Session session = Session.getInstance(p, new Authenticator() {
|
||||
// 设置认证账户信息
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(emailConfig.getEmails(), emailConfig.getEmailkey());
|
||||
}
|
||||
});
|
||||
session.setDebug(true);
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
System.err.println("邮件初始化完成");
|
||||
return message;
|
||||
}
|
||||
|
||||
public static Integer sendEmail(MimeMessage message, String username, String Url, String email,EmailConfig emailConfig) {
|
||||
String body = "<!DOCTYPE html>\n" +
|
||||
"<html>\n" +
|
||||
" <head>\n" +
|
||||
" <style type=\"text/css\">*{margin:0;padding:0;box-sizing:border-box}a{color:inherit;text-decoration:none;background-color:transparent}li{list-style:none}.clearfix:after{content:'';display:table;clear:both}body{font-size:14px;color:#494949;overflow:auto}.wrap{position:relative;min-height:580px}.wrap-bg circle,.wrap-bg rect{stroke-width:0;-ms-transform:rotate(30deg) scale(1.1);transform:rotate(30deg) scale(1.1);-ms-transform-origin:center;transform-origin:center}.main{position:absolute;top:50%;left:50%;z-index:2;width:970px;background:#effbff;-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);box-shadow:0 0 50px rgba(0,0,0,.1)}.header-tabs{width:100%;height:55px;padding:0 30px;background:linear-gradient(45deg,#4c75e9,#2c7ce3);overflow:hidden}.header-tabs .tab{float:left;height:40px;width:200px;padding:0 18px;margin-top:15px;border-radius:10px 10px 0 0;background:#fbfdff;line-height:40px;color:#113c73}.header-tabs .tab:after{content:'';display:table;clear:both}.header-tabs .tab span{float:left}.header-tabs .tab i{position:relative;float:right;width:11px;height:11px;margin-top:14px;cursor:pointer;-ms-transform:rotate(45deg);transform:rotate(45deg)}.header-tabs .tab i:before{content:'';position:absolute;top:5px;left:0;display:block;width:100%;height:1px;background:#113c73}.header-tabs .tab i:after{content:'';position:absolute;left:5px;top:0;display:block;width:1px;height:100%;background:#113c73}.header-tabs .tab-add{position:relative;float:left;width:28px;height:28px;margin:20px 0 0 15px;border-radius:50%;background:#a9cdf7}.header-tabs .tab-add:before{content:'';position:absolute;top:13px;left:9px;display:block;width:10px;height:2px;background:#113c73}.header-tabs .tab-add:after{content:'';position:absolute;left:13px;top:9px;display:block;width:2px;height:10px;background:#113c73}.header-tabs .tabs-tool{float:right;height:100%}.header-tabs .tabs-tool a{position:relative;float:left;width:14px;height:100%;margin:0 15px}.header-tabs .tabs-tool .btn-min:before{content:'';position:absolute;top:27px;left:0;width:100%;height:1px;background:#113c73}.header-tabs .tabs-tool .btn-max:before{content:'';position:absolute;top:20px;left:0;width:14px;height:14px;border:1px solid #113c73;box-sizing:border-box}.header-tabs .tabs-tool .btn-close{width:15px;-ms-transform:rotate(45deg);transform:rotate(45deg)}.header-tabs .tabs-tool .btn-close:before{content:'';position:absolute;top:27px;left:0;display:block;width:15px;height:1px;background:#113c73}.header-tabs .tabs-tool .btn-close:after{content:'';position:absolute;left:7px;top:20px;display:block;width:1px;height:15px;background:#113c73}.header-url{width:100%;height:54px;padding:10px 20px 10px 15px;background:#f2f2f2}.header-url a{float:left;height:100%;margin:0 9px;overflow:hidden}.header-url a svg{margin-top:9px}.header-url a .arrow{fill:none;stroke:#494949;stroke-width:2px;stroke-linecap:round;stroke-linejoin:round}.header-url .btn-next .arrow{-ms-transform-origin:center;transform-origin:center;-ms-transform:rotate(180deg);transform:rotate(180deg);stroke:#d4d5d6}.header-url .btn-refresh path{fill:none;stroke:#494949;stroke-width:2px;stroke-linecap:round;stroke-linejoin:round;-ms-transform-origin:center;transform-origin:center;-ms-transform:rotate(40deg);transform:rotate(40deg)}.header-url .btn-refresh polyline{fill:#494949;-ms-transform-origin:center;transform-origin:center;-ms-transform:rotate(40deg);transform:rotate(40deg)}.header-url input[type=text]{height:100%;width:820px;margin-left:6px;padding:0 1em;border:1px solid #a9a9a9;border-radius:4px;background:#fff}.main-content{height:470px;border:1px solid #c4dce5;background:#f4fcff}.main-content h5{padding:110px 0;font-weight:400;text-align:center}.main-content h5 span{position:relative;display:inline-block;font-size:60px;color:#2c7ce3}.main-content h5 span:before{content:'';position:absolute;top:48px;left:-36px;display:block;width:14px;height:14px;border-radius:50%;background:linear-gradient(45deg,#ded9ff,#2c7ce3);opacity:.2}.main-content h5 span:after{content:'';position:absolute;top:32px;left:-80px;display:block;width:20px;height:20px;border-radius:50%;background:linear-gradient(45deg,#ded9ff,#2c7ce3);opacity:.2}.main-content h5 span i:before{content:'';position:absolute;top:32px;right:-72px;display:block;width:14px;height:14px;border-radius:50%;background:linear-gradient(45deg,#ded9ff,#2c7ce3);opacity:.2}.main-content h5 span i:after{content:'';position:absolute;top:48px;right:-40px;display:block;width:20px;height:20px;border-radius:50%;background:linear-gradient(45deg,#ded9ff,#2c7ce3);opacity:.2}.main-content p{font-size:26px;text-align:center}</style>\n" +
|
||||
" </head>\n" +
|
||||
" <body>\n" +
|
||||
" <div class=\"wrap\">\n" +
|
||||
" <div class=\"main\">\n" +
|
||||
" <header>\n" +
|
||||
" <div class=\"header-tabs clearfix\">\n" +
|
||||
" <a href=\"javascript: void(0);\" class=\"tab\"><span>账号激活</span> <i></i> </a>\n" +
|
||||
" <a href=\"javascript: void(0);\" class=\"tab-add\"></a>\n" +
|
||||
" <div class=\"tabs-tool\">\n" +
|
||||
" <a href=\"javascript: void(0);\" class=\"btn-min\"></a> \n" +
|
||||
" <a href=\"javascript: void(0);\" class=\"btn-max\"></a> \n" +
|
||||
" <a href=\"javascript: void(0);\" class=\"btn-close\"></a>\n" +
|
||||
" </div>\n" +
|
||||
" </div>\n" +
|
||||
" </header>\n" +
|
||||
" <div class=\"main-content\">\n" +
|
||||
" <h5><span>您正在注册Hellohao图床<i></i></span></h5>\n" +
|
||||
" <p>点击 <a href='http://tc.hellohao.cn/user/activation.do?activation=" + Url + "&username=" + username + "' ><u> 激活链接 </u></a> 进行账号激活</p>\n" +
|
||||
" </div>\n" +
|
||||
" </div>\n" +
|
||||
" </div>\n" +
|
||||
" <script async=\"\" src=\"//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script> \n" +
|
||||
" <!-- yedomains --> \n" +
|
||||
" <ins class=\"adsbygoogle\" style=\"display:block\" data-ad-client=\"ca-pub-2629805781865389\" data-ad-slot=\"1129638672\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"></ins> \n" +
|
||||
" <script>\n" +
|
||||
"(adsbygoogle = window.adsbygoogle || []).push({});\n" +
|
||||
"</script> \n" +
|
||||
" </body>\n" +
|
||||
"</html>";
|
||||
try {
|
||||
// 发件人
|
||||
message.setFrom(new InternetAddress(emailConfig.getEmails(), emailConfig.getEmailname(), "UTF-8"));
|
||||
// 收件人和抄送人
|
||||
message.setRecipients(Message.RecipientType.TO, email);
|
||||
// 内容(这个内容还不能乱写,有可能会被SMTP拒绝掉;多试几次吧)
|
||||
message.setSubject(emailConfig.getEmailname()+"账号激活");//标题
|
||||
message.setContent(body, "text/html;charset=UTF-8");//内容
|
||||
message.setSentDate(new Date());
|
||||
message.saveChanges();
|
||||
System.out.println("准备发送");
|
||||
Transport.send(message);
|
||||
return 1;
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class Sentence {
|
||||
|
||||
/**
|
||||
* 根据URL请求json数据
|
||||
*
|
||||
* @return //parm:请求的url链接 返回的是json字符串
|
||||
*/
|
||||
public static String getURLContent() {
|
||||
String str = "";
|
||||
try {
|
||||
URL url = new URL("https://v1.hitokoto.cn/");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
//BufferedWriter writer=new BufferedWriter(new FileWriter("index.html"));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
str += line;
|
||||
//System.out.println(str);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
//writer.close();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
public class SetText {
|
||||
public static String getSubString(String text, String left, String right) {
|
||||
String result = "";
|
||||
int zLen;
|
||||
if (left == null || left.isEmpty()) {
|
||||
zLen = 0;
|
||||
} else {
|
||||
zLen = text.indexOf(left);
|
||||
if (zLen > -1) {
|
||||
zLen += left.length();
|
||||
} else {
|
||||
zLen = 0;
|
||||
}
|
||||
}
|
||||
int yLen = text.indexOf(right, zLen);
|
||||
if (yLen < 0 || right == null || right.isEmpty()) {
|
||||
yLen = text.length();
|
||||
}
|
||||
result = text.substring(zLen, yLen);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.hellohao.utils;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Spring的ApplicationContext的持有者,可以用静态方法的方式获取spring容器中的bean
|
||||
*
|
||||
* @author yj
|
||||
* @date 2018年5月27日 下午6:32:11
|
||||
*/
|
||||
@Component
|
||||
public class SpringContextHolder implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
SpringContextHolder.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
assertApplicationContext();
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getBean(String beanName) {
|
||||
assertApplicationContext();
|
||||
return (T) applicationContext.getBean(beanName);
|
||||
}
|
||||
|
||||
public static <T> T getBean(Class<T> requiredType) {
|
||||
assertApplicationContext();
|
||||
return applicationContext.getBean(requiredType);
|
||||
}
|
||||
|
||||
private static void assertApplicationContext() {
|
||||
if (SpringContextHolder.applicationContext == null) {
|
||||
throw new RuntimeException("applicaitonContext属性为null,请检查是否注入了SpringContextHolder!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user