From d09b5c265696e6c998575f0aea9d9629e0893718 Mon Sep 17 00:00:00 2001 From: hello-hao <923453645@qq.com> Date: Mon, 21 Feb 2022 18:45:41 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=E4=BF=AE=E5=A4=8D=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E7=9B=B8=E5=86=8C=E6=98=BE=E7=A4=BA=E6=89=80=E6=9C=89=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=9A=84=E9=94=99=E8=AF=AF=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E5=83=8F=E7=AD=9B=E9=80=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86=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/AdminController.java | 21 +++---- .../hellohao/controller/IndexController.java | 60 +++++++++++++------ .../hellohao/service/impl/UploadServicel.java | 12 ++-- .../java/cn/hellohao/utils/ImgUrlUtil.java | 6 +- src/main/resources/mapper/ImgMapper.xml | 36 +++++++---- .../resources/mapper/UploadConfigMapper.xml | 5 +- 6 files changed, 90 insertions(+), 50 deletions(-) diff --git a/src/main/java/cn/hellohao/controller/AdminController.java b/src/main/java/cn/hellohao/controller/AdminController.java index 12113bf..2d19a67 100644 --- a/src/main/java/cn/hellohao/controller/AdminController.java +++ b/src/main/java/cn/hellohao/controller/AdminController.java @@ -276,12 +276,12 @@ public class AdminController { JSONObject jsonObj = JSONObject.parseObject(data); Integer pageNum = jsonObj.getInteger("pageNum"); Integer pageSize = jsonObj.getInteger("pageSize"); - String username = jsonObj.getString("username"); Integer source = jsonObj.getInteger("source"); String starttime = jsonObj.getString("starttime"); String stoptime = jsonObj.getString("stoptime"); + String selectUserType = jsonObj.getString("selectUserType");//me/all + String username = jsonObj.getString("username"); Integer selecttype = jsonObj.getInteger("selecttype"); - String classifuids = jsonObj.getString("classifuids"); boolean violation = jsonObj.getBoolean("violation"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if(starttime!=null){ @@ -307,17 +307,18 @@ public class AdminController { if(violation){ img.setViolation("true"); } - img.setUsername(username); - img.setSource(source); - img.setSelecttype(selecttype); img.setStarttime(starttime); img.setStoptime(stoptime); - if(classifuids!=null){ - String[] calssif = classifuids.split(","); - img.setClassifuidlist(calssif); - } if(subject.hasRole("admin")){ - img.setUserid(null); + img.setSource(source); + if(selectUserType.equals("me")){ + img.setUserid(user.getId()); + img.setUsername(null); + img.setSelecttype(null); + }else{ + img.setUsername(username); + img.setSelecttype(selecttype); + } }else{ //普通用户 img.setUserid(user.getId()); diff --git a/src/main/java/cn/hellohao/controller/IndexController.java b/src/main/java/cn/hellohao/controller/IndexController.java index f70816a..30a2a21 100644 --- a/src/main/java/cn/hellohao/controller/IndexController.java +++ b/src/main/java/cn/hellohao/controller/IndexController.java @@ -88,34 +88,56 @@ public class IndexController { @PostMapping(value = "/upload")//upimg new @ResponseBody public Msg upimg(HttpServletRequest request,HttpSession httpSession - , @RequestParam(value = "file", required = false) MultipartFile multipartFile,Integer day, - @RequestParam(value = "classifications", defaultValue = "" ) String classifications) { - final JSONArray jsonArray = new JSONArray(); - if(!classifications.equals("")){ - String[] calssif = classifications.split(","); - for (int i = 0; i < calssif.length; i++) { - jsonArray.add(calssif[i]); - } - } - return uploadServicel.uploadForLoc(request,multipartFile,day,null,jsonArray); + , @RequestParam(value = "file", required = false) MultipartFile multipartFile,Integer day) { + return uploadServicel.uploadForLoc(request,multipartFile,day,null); } - //根据网络图片url上传 @PostMapping(value = "/uploadForUrl") //new @ResponseBody public Msg upurlimg(HttpServletRequest request,@RequestParam(value = "data", defaultValue = "") String data) { JSONObject jsonObj = JSONObject.parseObject(data); - final JSONArray jsonArray = new JSONArray(); Integer setday = jsonObj.getInteger("day"); String imgUrl = jsonObj.getString("imgUrl"); - String selectTreeListStr = jsonObj.getString("classifications"); - if(null != selectTreeListStr){ - String[] calssif = selectTreeListStr.split(","); - for (int i = 0; i < calssif.length; i++) { - jsonArray.add(calssif[i]); + String[] URLArr = imgUrl.split("\n"); + + Subject subject = SecurityUtils.getSubject(); + User user = (User) subject.getPrincipal(); + UploadConfig updateConfig = uploadConfigService.getUpdateConfig(); + int syscounts = 0; + if(null==user){ + syscounts = updateConfig.getImgcounttourists(); + }else{ + syscounts = updateConfig.getImgcountuser(); + } + Msg retMsg = new Msg(); + JSONObject jsonObject = new JSONObject(); + JSONArray retArray = new JSONArray(); + int errcounts = 0; + int excess = 0; + for (int i = 0; i < URLArr.length; i++) { + int temp = i+1; + if(syscounts>=temp){ + Msg msg = uploadServicel.uploadForLoc(request, null, setday, URLArr[i]); + if(!msg.getCode().equals("200")){ + //失败的个数 + errcounts++; + }else{ + retArray.add(msg); + } + }else{ + //超额的个数 + excess++; } } - return uploadServicel.uploadForLoc(request,null,setday,imgUrl,jsonArray); + //共传过来的数量 + jsonObject.put("counts",URLArr.length); + //上传失败的个数 + jsonObject.put("errcounts",errcounts); + //超过系统定义值 不上传的数量 + jsonObject.put("excess",excess); + jsonObject.put("urls",retArray); + retMsg.setData(jsonObject); + return retMsg; } @RequestMapping(value = "/getUploadInfo")//new @@ -136,6 +158,8 @@ public class IndexController { }else{ jsonObject.put("filesize",Integer.valueOf(updateConfig.getFilesizeuser())/1024); jsonObject.put("imgcount",updateConfig.getImgcountuser()); + jsonObject.put("uploadSwitch",updateConfig.getUserclose()); + jsonObject.put("uploadInfo","系统暂时关闭了用户上传功能"); } }catch (Exception e){ e.printStackTrace(); diff --git a/src/main/java/cn/hellohao/service/impl/UploadServicel.java b/src/main/java/cn/hellohao/service/impl/UploadServicel.java index 1920dae..dda05c5 100644 --- a/src/main/java/cn/hellohao/service/impl/UploadServicel.java +++ b/src/main/java/cn/hellohao/service/impl/UploadServicel.java @@ -52,7 +52,7 @@ public class UploadServicel { public Msg uploadForLoc(HttpServletRequest request, - MultipartFile multipartFile, Integer setday, String imgUrl, JSONArray selectTreeList) { + MultipartFile multipartFile, Integer setday, String imgUrl) { Msg msg = new Msg(); try{ JSONObject jsonObject = new JSONObject(); @@ -220,10 +220,10 @@ public class UploadServicel { //先判断是不是有效链接 // final boolean valid = ImgUrlUtil.isValid(imgurl); if(true){ - Long imgsize = null; + Long imgsize = 0L; try { - imgsize = ImgUrlUtil.getFileLength(imgurl); - if(imgsize>0){ +// imgsize = ImgUrlUtil.getFileLength(imgurl); + if(imgsize==0){ // String uuid= UUID.randomUUID().toString().replace("-", ""); String ShortUID = SetText.getShortUuid(); String savePath = request.getSession().getServletContext().getRealPath("/")+File.separator+"hellohaotmp"+File.separator; @@ -245,7 +245,7 @@ public class UploadServicel { msg.setCode("500"); msg.setInfo("获取资源失败"); } - } catch (IOException e) { + } catch (Exception e) { msg.setCode("500"); msg.setInfo("获取资源失败"); } @@ -253,10 +253,10 @@ public class UploadServicel { msg.setCode("500"); msg.setInfo("该链接无效"); } + return msg; } - public static Group group; //上传用户或游客的所属分组 public static Long memory;//上传用户或者游客的分配容量 memory public static Long TotleMemory;//用户或者游客下可使用的总容量 //maxsize diff --git a/src/main/java/cn/hellohao/utils/ImgUrlUtil.java b/src/main/java/cn/hellohao/utils/ImgUrlUtil.java index 45add0b..9ea9918 100644 --- a/src/main/java/cn/hellohao/utils/ImgUrlUtil.java +++ b/src/main/java/cn/hellohao/utils/ImgUrlUtil.java @@ -90,12 +90,11 @@ public class ImgUrlUtil { * @param savePath * @throws IOException */ - public static Map downLoadFromUrl(String urlStr, String fileName, String savePath){ + public static Map downLoadFromUrl(String urlStr,String fileName,String savePath){ Map resmap = new HashMap<>(); Map map = checkURLStatusCode(urlStr); - if(map.get("Check").equals("false")){ -// StatusCode + if(map.size()==0 || map.get("Check").equals("false")){ resmap.put("res",false); resmap.put("StatusCode",map.get("StatusCode")); return resmap; @@ -135,6 +134,7 @@ public class ImgUrlUtil { f.renameTo(new File(imgPath)); resmap.put("res",true); resmap.put("imgPath",imgPath); + resmap.put("imgsize",new File(imgPath).length()); }else{ new File(saveDir+File.separator+fileName).delete(); resmap.put("res",false); diff --git a/src/main/resources/mapper/ImgMapper.xml b/src/main/resources/mapper/ImgMapper.xml index de1e9e3..a0fd8c2 100644 --- a/src/main/resources/mapper/ImgMapper.xml +++ b/src/main/resources/mapper/ImgMapper.xml @@ -37,20 +37,32 @@ and a.updatetime <= #{stoptime} - - - - - and - a.userid not in (#{userid}) - - - and - a.userid = #{userid} - - + + and + a.violation !="" + + + and + a.userid = #{userid} + + + + + + and + a.userid in ( SELECT id from `user` where username LIKE '%${username}%') + + + and + a.userid not in ( SELECT id from `user` where username LIKE '%${username}%') + + + + + + order by a.id desc diff --git a/src/main/resources/mapper/UploadConfigMapper.xml b/src/main/resources/mapper/UploadConfigMapper.xml index d0ee838..a0f702d 100644 --- a/src/main/resources/mapper/UploadConfigMapper.xml +++ b/src/main/resources/mapper/UploadConfigMapper.xml @@ -40,7 +40,10 @@ `usermemory` = #{usermemory}, - `blacklist` = #{blacklist} + `blacklist` = #{blacklist}, + + + `userclose` = #{userclose}