mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
重构版功能实现
This commit is contained in:
@@ -2,14 +2,12 @@ package cn.hellohao.controller;
|
||||
|
||||
import cn.hellohao.pojo.*;
|
||||
import cn.hellohao.service.*;
|
||||
import cn.hellohao.service.impl.AlbumServiceI;
|
||||
import cn.hellohao.service.impl.ImgAndAlbumServiceImpl;
|
||||
import cn.hellohao.utils.GetCurrentSource;
|
||||
import cn.hellohao.utils.Print;
|
||||
import cn.hellohao.service.impl.AlbumServiceImpl;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,7 +27,7 @@ import java.util.*;
|
||||
@Controller
|
||||
public class AlbumController {
|
||||
@Autowired
|
||||
AlbumServiceI albumServiceI;
|
||||
AlbumServiceImpl albumServiceImpl;
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
@Autowired
|
||||
@@ -60,7 +58,7 @@ public class AlbumController {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Album> albums = null;
|
||||
try {
|
||||
albums = albumServiceI.selectAlbumURLList(album);
|
||||
albums = albumServiceImpl.selectAlbumURLList(album);
|
||||
PageInfo<Album> rolePageInfo = new PageInfo<>(albums);
|
||||
map.put("code", 200);
|
||||
map.put("info", "");
|
||||
@@ -86,13 +84,13 @@ public class AlbumController {
|
||||
JSONArray albumkeyList = jsonObject.getJSONArray("albumkeyList");
|
||||
for (int i = 0; i < albumkeyList.size(); i++) {
|
||||
if(subject.hasRole("admin")){
|
||||
albumServiceI.deleteAlbum(albumkeyList.getString(i));
|
||||
albumServiceImpl.deleteAlbum(albumkeyList.getString(i));
|
||||
}else{
|
||||
Album album = new Album();
|
||||
album.setAlbumkey(albumkeyList.getString(i));
|
||||
final Album alb = albumServiceI.selectAlbum(album);
|
||||
final Album alb = albumServiceImpl.selectAlbum(album);
|
||||
if(alb.getUserid()==user.getId()){
|
||||
albumServiceI.deleteAlbum(albumkeyList.getString(i));
|
||||
albumServiceImpl.deleteAlbum(albumkeyList.getString(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,21 +104,45 @@ public class AlbumController {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/SaveForAlbum")
|
||||
@PostMapping("/getAlbumImgList") //new
|
||||
@ResponseBody
|
||||
public Msg SaveForAlbum(HttpSession session,@RequestParam("imgarr[]") String[] imgarr, @RequestParam("aboutarr[]") String[] aboutarr,
|
||||
String albumtitle, String password){
|
||||
public Msg getAlbumImgList(@RequestParam("data") String data) {
|
||||
Msg msg = new Msg();
|
||||
User u = (User) session.getAttribute("user");
|
||||
String uuid = "TOALBUM"+ UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,5)+"N";
|
||||
Integer ret =0;
|
||||
Integer temp = 0;
|
||||
Integer temp2 = 0;
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
|
||||
for (int i = 0; i < imgarr.length; i++) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
JSONArray jsonArray = jsonObject.getJSONArray("imguidlist");
|
||||
JSONArray json = albumServiceImpl.getAlbumList(jsonArray);
|
||||
msg.setData(json);
|
||||
return msg;
|
||||
}
|
||||
|
||||
@PostMapping("/SaveForAlbum")//new
|
||||
@ResponseBody
|
||||
public Msg SaveForAlbum(@RequestParam(value = "data", defaultValue = "") String data){
|
||||
data = StringEscapeUtils.unescapeHtml4(data);
|
||||
Msg msg = new Msg();
|
||||
try {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
String albumtitle = jsonObject.getString("albumtitle");
|
||||
String password = jsonObject.getString("password");
|
||||
JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("albumlist"));
|
||||
if(null!=password){
|
||||
password = password.replace(" ", "");
|
||||
if(password.replace(" ", "").equals("") || password.length()<3){
|
||||
msg.setCode("110403");
|
||||
msg.setInfo("密码长度不得小于三位有效字符");
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
if(albumtitle==null || jsonArray.size()==0){
|
||||
msg.setCode("110404");
|
||||
msg.setInfo("标题和图片参数不能为空");
|
||||
return msg;
|
||||
}
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
User u = (User) subject.getPrincipal();
|
||||
String uuid = "TOALBUM"+ UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,5)+"N";
|
||||
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Album album = new Album();
|
||||
ImgAndAlbum imgAndAlbum = new ImgAndAlbum();
|
||||
album.setAlbumtitle(albumtitle);
|
||||
album.setCreatedate(df.format(new Date()));
|
||||
album.setPassword(password);
|
||||
@@ -130,48 +152,42 @@ public class AlbumController {
|
||||
}else{
|
||||
album.setUserid(u.getId());
|
||||
}
|
||||
String imgurl = "";
|
||||
Integer sourcekey = 0;
|
||||
UploadConfig updateConfig = uploadConfigService.getUpdateConfig();
|
||||
if(updateConfig.getUrltype()==2){
|
||||
imgurl = imgarr[i];
|
||||
}else{
|
||||
if (u == null) {
|
||||
//sourcekey = GetCurrentSource.GetSource(null);
|
||||
imgurl="tourist/"+imgarr[i];
|
||||
} else {
|
||||
//sourcekey = GetCurrentSource.GetSource(u.getId());
|
||||
imgurl=u.getUsername()+"/"+imgarr[i];
|
||||
}
|
||||
albumServiceImpl.addAlbum(album);
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject img = jsonArray.getJSONObject(i);
|
||||
ImgAndAlbum imgAndAlbum = new ImgAndAlbum();
|
||||
imgAndAlbum.setImgname(img.getString("imgurl"));
|
||||
imgAndAlbum.setAlbumkey(uuid);
|
||||
imgAndAlbum.setNotes(img.getString("notes"));
|
||||
albumServiceImpl.addAlbumForImgAndAlbumMapper(imgAndAlbum);
|
||||
}
|
||||
|
||||
imgAndAlbum.setImgname(imgarr[i]);
|
||||
imgAndAlbum.setAlbumkey(uuid);
|
||||
imgAndAlbum.setNotes(aboutarr[i]);
|
||||
if(temp==0){
|
||||
temp2 = albumServiceI.addAlbum(album);
|
||||
temp = 1;
|
||||
}
|
||||
if(temp2>0){
|
||||
ret = albumServiceI.addAlbumForImgAndAlbumMapper(imgAndAlbum);
|
||||
}
|
||||
}
|
||||
if(ret>0){
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("url",uuid);
|
||||
json.put("title",albumtitle);
|
||||
json.put("password",password);
|
||||
msg.setCode("200");
|
||||
msg.setInfo("成功创建画廊链接:");
|
||||
msg.setData(configService.getSourceype().getDomain()+"/"+uuid);
|
||||
}else{
|
||||
msg.setInfo("成功创建画廊链接");
|
||||
msg.setData(json);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
msg.setCode("500");
|
||||
msg.setInfo("创建画廊链接失败:");
|
||||
msg.setInfo("创建画廊链接失败");
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping("/TOALBUM{key}N")
|
||||
public String selectByFy(@PathVariable("key") String key, Model model) {
|
||||
Album album = new Album();
|
||||
album.setAlbumkey("TOALBUM"+key+"N");
|
||||
Album a = albumServiceI.selectAlbum(album);
|
||||
Album a = albumServiceImpl.selectAlbum(album);
|
||||
Config config = configService.getSourceype();
|
||||
model.addAttribute("webname",config.getWebname());
|
||||
model.addAttribute("domain",config.getDomain());
|
||||
@@ -196,7 +212,7 @@ public class AlbumController {
|
||||
Msg msg = new Msg();
|
||||
Album album = new Album();
|
||||
album.setAlbumkey(albumkey);
|
||||
Album a = albumServiceI.selectAlbum(album);
|
||||
Album a = albumServiceImpl.selectAlbum(album);
|
||||
if(a==null){
|
||||
msg.setCode("404");
|
||||
msg.setInfo("画廊地址不存在");
|
||||
|
||||
Reference in New Issue
Block a user