From 8542ca2afc6dde4d4a4589d0c0f3a3bca19f071b Mon Sep 17 00:00:00 2001 From: hello-hao <923453645@qq.com> Date: Fri, 15 Apr 2022 19:14:15 +0800 Subject: [PATCH] =?UTF-8?q?:art:=E5=AE=8C=E5=96=84=E6=96=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hellohao/controller/AlbumController.java | 76 ++++++++++++++++++- .../java/cn/hellohao/dao/AlbumMapper.java | 2 + .../cn/hellohao/service/AlbumService.java | 2 + .../service/impl/AlbumServiceImpl.java | 7 ++ .../hellohao/service/impl/UploadServicel.java | 11 +-- src/main/resources/mapper/AlbumMapper.xml | 13 ++++ 6 files changed, 104 insertions(+), 7 deletions(-) diff --git a/src/main/java/cn/hellohao/controller/AlbumController.java b/src/main/java/cn/hellohao/controller/AlbumController.java index c5b2b37..f6adb40 100644 --- a/src/main/java/cn/hellohao/controller/AlbumController.java +++ b/src/main/java/cn/hellohao/controller/AlbumController.java @@ -108,8 +108,21 @@ public class AlbumController { try{ JSONObject jsonObject = JSONObject.parseObject(data); String key = jsonObject.getString("key"); + Subject subject = SecurityUtils.getSubject(); + User user = (User) subject.getPrincipal(); + Album album = new Album(); + album.setAlbumkey(key); + if(subject.hasRole("admin")){ + album.setUserid(null); + }else{ + album.setUserid(user.getId()); + } + JSONObject jsonObj = new JSONObject(); + Album album1 = albumServiceImpl.selectAlbum(album); List imagesList = imgAndAlbumService.selectImgForAlbumkey(key); - msg.setData(imagesList); + jsonObj.put("album",album1); + jsonObj.put("imagesList",imagesList); + msg.setData(jsonObj); }catch (Exception e){ e.printStackTrace(); msg.setCode("500"); @@ -155,7 +168,7 @@ public class AlbumController { } Subject subject = SecurityUtils.getSubject(); User u = (User) subject.getPrincipal(); - String uuid = "TOALBUM"+ UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,5)+"N"; + String uuid = "TOALBUM"+ UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,7)+"N"; SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Album album = new Album(); album.setAlbumtitle(albumtitle); @@ -192,6 +205,65 @@ public class AlbumController { } + @PostMapping("/admin/UpdateForAlbum")//new + @ResponseBody + public Msg UpdateForAlbum(@RequestParam(value = "data", defaultValue = "") String data){ + data = StringEscapeUtils.unescapeHtml4(data); + Msg msg = new Msg(); + try { + JSONObject jsonObject = JSONObject.parseObject(data); + String albumkey = jsonObject.getString("albumkey"); + String albumtitle = jsonObject.getString("albumtitle"); + String password = jsonObject.getString("password"); + JSONArray jsonArray = JSONArray.parseArray(jsonObject.getString("albumlist")); + if(null!=password){ +// String regex = "^[a-z0-9A-Z\u4e00-\u9fa5]+$"; +// return str.matches(regex); + 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(); + Album album = new Album(); + album.setAlbumtitle(albumtitle); + album.setPassword(password); + album.setAlbumkey(albumkey); + + albumServiceImpl.updateAlbum(album); + imgAndAlbumService.deleteImgAndAlbumForKey(albumkey); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject img = jsonArray.getJSONObject(i); + ImgAndAlbum imgAndAlbum = new ImgAndAlbum(); + imgAndAlbum.setImgname(img.getString("imgurl")); + imgAndAlbum.setAlbumkey(albumkey); + imgAndAlbum.setNotes(img.getString("notes")); + albumServiceImpl.addAlbumForImgAndAlbumMapper(imgAndAlbum); + } + final JSONObject json = new JSONObject(); + json.put("url",albumkey); + json.put("title",albumtitle); + json.put("password",password); + msg.setCode("200"); + msg.setInfo("画廊修改成功"); + msg.setData(json); + }catch (Exception e){ + e.printStackTrace(); + msg.setCode("500"); + msg.setInfo("修改画廊失败"); + } + return msg; + } + + @PostMapping("/checkPass")//new @ResponseBody public Msg checkPass(@RequestParam(value = "data", defaultValue = "") String data) { diff --git a/src/main/java/cn/hellohao/dao/AlbumMapper.java b/src/main/java/cn/hellohao/dao/AlbumMapper.java index 3dd173b..963020b 100644 --- a/src/main/java/cn/hellohao/dao/AlbumMapper.java +++ b/src/main/java/cn/hellohao/dao/AlbumMapper.java @@ -23,4 +23,6 @@ public interface AlbumMapper { List selectAlbumURLList(Album album); Integer selectAlbumCount(@Param("userid") Integer userid); + + Integer updateAlbum(Album album); } diff --git a/src/main/java/cn/hellohao/service/AlbumService.java b/src/main/java/cn/hellohao/service/AlbumService.java index 00ae97a..5d2fb59 100644 --- a/src/main/java/cn/hellohao/service/AlbumService.java +++ b/src/main/java/cn/hellohao/service/AlbumService.java @@ -26,4 +26,6 @@ public interface AlbumService { List selectAlbumURLList(Album album); Integer selectAlbumCount(Integer userid); + + Integer updateAlbum(Album album); } diff --git a/src/main/java/cn/hellohao/service/impl/AlbumServiceImpl.java b/src/main/java/cn/hellohao/service/impl/AlbumServiceImpl.java index d194666..aa68de6 100644 --- a/src/main/java/cn/hellohao/service/impl/AlbumServiceImpl.java +++ b/src/main/java/cn/hellohao/service/impl/AlbumServiceImpl.java @@ -84,6 +84,11 @@ public class AlbumServiceImpl implements AlbumService { return albumMapper.selectAlbumCount(userid); } + @Override + public Integer updateAlbum(Album album) { + return albumMapper.updateAlbum(album); + } + @Transactional public Integer delete(String albumkey) { Integer ret1 = albumMapper.deleteAlbum(albumkey); @@ -108,4 +113,6 @@ public class AlbumServiceImpl implements AlbumService { } return ret1; } + + } diff --git a/src/main/java/cn/hellohao/service/impl/UploadServicel.java b/src/main/java/cn/hellohao/service/impl/UploadServicel.java index cc358fb..c10fdbc 100644 --- a/src/main/java/cn/hellohao/service/impl/UploadServicel.java +++ b/src/main/java/cn/hellohao/service/impl/UploadServicel.java @@ -257,11 +257,11 @@ public class UploadServicel { return msg; } - public static Group group; //上传用户或游客的所属分组 - public static Long memory;//上传用户或者游客的分配容量 memory - public static Long TotleMemory;//用户或者游客下可使用的总容量 //maxsize - public static Long UsedTotleMemory;//用户或者游客已经用掉的总容量 //usermemory - public static String updatePath="tourist"; + private static Group group; //上传用户或游客的所属分组 + private static Long memory;//上传用户或者游客的分配容量 memory + private static Long TotleMemory;//用户或者游客下可使用的总容量 //maxsize + private static Long UsedTotleMemory;//用户或者游客已经用掉的总容量 //usermemory + private static String updatePath="tourist"; //判断用户 或 游客 当前上传图片的一系列校验 private Msg updateImgCheck(User user, UploadConfig uploadConfig){ @@ -276,6 +276,7 @@ public class UploadServicel { msg.setInfo("系统已禁用游客上传"); return msg; } + updatePath="tourist"; group = GetCurrentSource.GetSource(null); memory = Long.valueOf(uploadConfig.getVisitormemory());//单位 B 游客设置总量 TotleMemory = Long.valueOf(uploadConfig.getFilesizetourists());//单位 B 游客单文件大小 diff --git a/src/main/resources/mapper/AlbumMapper.xml b/src/main/resources/mapper/AlbumMapper.xml index b644e49..f22ad30 100644 --- a/src/main/resources/mapper/AlbumMapper.xml +++ b/src/main/resources/mapper/AlbumMapper.xml @@ -63,5 +63,18 @@ + + UPDATE `album` + + + albumtitle = #{albumtitle}, + + + password = #{password}, + + + WHERE + albumkey = #{albumkey} + \ No newline at end of file