From 1392d130e555d4b1e34b34bc2110ddde7676c324 Mon Sep 17 00:00:00 2001 From: zxt@theyeasy.com Date: Wed, 27 Dec 2017 15:10:15 +0800 Subject: [PATCH] 查询单个商品 --- src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java | 36 +++++++++++++++++++++++------------- src/com/w1hd/zzhnc/controller/pc/GoodsController.java | 3 ++- src/com/w1hd/zzhnc/controller/pc/HomeController.java | 3 ++- src/com/w1hd/zzhnc/controller/pc/PcWxController.java | 11 ++++++----- src/com/w1hd/zzhnc/controller/pc/PrizeController.java | 4 ++-- src/com/w1hd/zzhnc/controller/pc/ReportController.java | 33 +++++++++++++++++---------------- src/com/w1hd/zzhnc/controller/pc/SellerController.java | 7 ++++--- src/com/w1hd/zzhnc/controller/pc/UploadController.java | 408 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/com/w1hd/zzhnc/service/GoodsService.java | 17 +++++++++++------ src/com/w1hd/zzhnc/util/SpringFTPUtil.java | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 465 insertions(+), 249 deletions(-) create mode 100644 src/com/w1hd/zzhnc/util/SpringFTPUtil.java diff --git a/src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java b/src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java index bbb0ad7..b29ae00 100644 --- a/src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java +++ b/src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @@ -12,19 +13,19 @@ import com.w1hd.zzhnc.service.AutoreplyService; import com.w1hd.zzhnc.vo.Vo_msg; @Controller -@RequestMapping("/autoreply") +@RequestMapping(value = "/autoreply") public class AutoreplyController extends BaseController { @Autowired AutoreplyService replyService; - @RequestMapping(value="/autoresponse",method=RequestMethod.GET) + @RequestMapping(value = "/autoresponse", method = RequestMethod.GET) public ModelAndView autoreplyIndex() { ModelAndView mv = new ModelAndView("/pc/autoresponse/autoresponse"); return mv; } - @RequestMapping("/autoresponseEdit") + @RequestMapping(value = "/autoresponseEdit", method = RequestMethod.GET) public ModelAndView autoresponseEdit(Integer id) { ModelAndView mv = new ModelAndView("/pc/autoresponse/autoresponseEdit"); mv.addObject("id", id); @@ -33,7 +34,7 @@ public class AutoreplyController extends BaseController { } // 自动回复列表 - @RequestMapping(value = "/getAutoreplyList") + @RequestMapping(value = "/getAutoreplyList", method = RequestMethod.GET) @ResponseBody public Object autoreplyList(Integer page, String keyword, Boolean isRedirectStaff, Integer projectId) { @@ -41,10 +42,14 @@ public class AutoreplyController extends BaseController { } // 添加关键字 - @RequestMapping(value = "/addAutoreply") + @RequestMapping(value = "/addAutoreply", method = RequestMethod.POST) @ResponseBody - public Object addautoreply(String keywords, boolean isRedirectStaff, String content, Integer projectId, - String projectName, Integer sort) { + public Object addautoreply(@RequestParam(value = "keywords", required = false) String keywords, + @RequestParam(value = "keywords", required = true) boolean isRedirectStaff, + @RequestParam(value = "content", required = true) String content, + @RequestParam(value = "projectId", required = false, defaultValue = "1") Integer projectId, + @RequestParam(value = "projectName", required = false, defaultValue = "默认") String projectName, + @RequestParam(value = "sort", required = false, defaultValue = "0") Integer sort) { String result = replyService.addAutoReply(keywords, isRedirectStaff, content, projectId, projectName, sort); if (result.equals("ok")) { return new Vo_msg(0, "添加成功"); @@ -54,10 +59,15 @@ public class AutoreplyController extends BaseController { } // 修改关键字 - @RequestMapping(value = "/updateAutoreply") + @RequestMapping(value = "/updateAutoreply", method = RequestMethod.POST) @ResponseBody - public Object updateautoreply(Integer id, String keywords, boolean isRedirectStaff, String content, - Integer projectId, String projectName, Integer sort) { + public Object updateautoreply(@RequestParam(value = "id", required = true) Integer id, + @RequestParam(value = "keywords", required = true) String keywords, + @RequestParam(value = "content", required = true) String content, + @RequestParam(value = "isRedirectStaff", required = false, defaultValue = "false") boolean isRedirectStaff, + @RequestParam(value = "projectId", required = false, defaultValue = "0") Integer projectId, + @RequestParam(value = "projectName", required = false, defaultValue = "default") String projectName, + @RequestParam(value = "sort", required = false, defaultValue = "0") Integer sort) { String result = replyService.updateAutoReply(id, keywords, isRedirectStaff, content, projectId, projectName, sort); if (result.equals("ok")) { @@ -68,7 +78,7 @@ public class AutoreplyController extends BaseController { } // 删除关键字 - @RequestMapping(value = "/deleteAutoreply") + @RequestMapping(value = "/deleteAutoreply", method = RequestMethod.POST) @ResponseBody public Object deleteautoreply(Integer id) { String result = replyService.deleteAutoReply(id); @@ -80,7 +90,7 @@ public class AutoreplyController extends BaseController { } // 获取 - @RequestMapping(value = "/getAutoReply") + @RequestMapping(value = "/getAutoReply", method = RequestMethod.GET) @ResponseBody public Object getAutoReply(Integer id) { Autoreply reply = replyService.getAutoReply(id); @@ -91,7 +101,7 @@ public class AutoreplyController extends BaseController { } } - @RequestMapping(value = "/publish") + @RequestMapping(value = "/publish", method = RequestMethod.GET) @ResponseBody public Object publish() { replyService.init(true); diff --git a/src/com/w1hd/zzhnc/controller/pc/GoodsController.java b/src/com/w1hd/zzhnc/controller/pc/GoodsController.java index 2dbd3dd..51e4ed4 100644 --- a/src/com/w1hd/zzhnc/controller/pc/GoodsController.java +++ b/src/com/w1hd/zzhnc/controller/pc/GoodsController.java @@ -42,10 +42,11 @@ public class GoodsController { @ResponseBody @RequestMapping(value="/search",method=RequestMethod.GET) public Object search(@RequestParam(value="key",required=false) String key, + @RequestParam(value="id",required=false,defaultValue = "0")Integer id, @RequestParam(value="sellerId",required=false,defaultValue = "0")Integer sellerId, @RequestParam(value="page",required=false,defaultValue = "1")Integer page, @RequestParam(value="size",required=false,defaultValue = "10")Integer size) { - return new Vo_msg(0,goodsService.seacrh(key,sellerId,page,size)); + return new Vo_msg(0,goodsService.seacrh(id,key,sellerId,page,size)); } } diff --git a/src/com/w1hd/zzhnc/controller/pc/HomeController.java b/src/com/w1hd/zzhnc/controller/pc/HomeController.java index 41744d6..d41c226 100644 --- a/src/com/w1hd/zzhnc/controller/pc/HomeController.java +++ b/src/com/w1hd/zzhnc/controller/pc/HomeController.java @@ -3,13 +3,14 @@ package com.w1hd.zzhnc.controller.pc; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; @Controller @RequestMapping("/home") public class HomeController extends BaseController { - @RequestMapping("/index") + @RequestMapping(value="/index",method=RequestMethod.GET) public ModelAndView Index() { ModelAndView mv = new ModelAndView("/pc/index"); return mv; diff --git a/src/com/w1hd/zzhnc/controller/pc/PcWxController.java b/src/com/w1hd/zzhnc/controller/pc/PcWxController.java index ac59024..708c45c 100644 --- a/src/com/w1hd/zzhnc/controller/pc/PcWxController.java +++ b/src/com/w1hd/zzhnc/controller/pc/PcWxController.java @@ -3,6 +3,7 @@ package com.w1hd.zzhnc.controller.pc; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import org.theyeasy.weixin.service.WxOpenService; @@ -24,7 +25,7 @@ public class PcWxController { SysWxauthorizeService sysWxauthorizeService; - @RequestMapping("/wxmanage") + @RequestMapping(value="/wxmanage",method=RequestMethod.GET) public ModelAndView wxManage() { ModelAndView mv = new ModelAndView("/pc/wx/wxmanage"); @@ -43,7 +44,7 @@ public class PcWxController { } /*显示已授权的公众号*/ - @RequestMapping("/getwx") + @RequestMapping(value="/getwx",method=RequestMethod.GET) public @ResponseBody Vo_msg getWx() { SysWxauthorize sysWxauthorize = sysWxauthorizeService.getAuthorizerOnlyOne(); @@ -51,7 +52,7 @@ public class PcWxController { } /*判断模板消息是否存在,有长ID表存公众号添加过对应的模板消息*/ - @RequestMapping("/getTemplate") + @RequestMapping(value="/getTemplate",method=RequestMethod.GET) public @ResponseBody Vo_msg getTemplateLongId(String template_id_short) { return new Vo_msg(0,"",WxMpUtil.getTemplateLongId(template_id_short)); @@ -59,7 +60,7 @@ public class PcWxController { /*添加模板消息*/ - @RequestMapping("/addTemplate") + @RequestMapping(value="/addTemplate",method=RequestMethod.POST) public @ResponseBody Vo_msg addTemplate(String template_id_short) { String msg = WxMpUtil.addTemplate(template_id_short); @@ -67,7 +68,7 @@ public class PcWxController { } /*测试发送模板消息*/ - @RequestMapping("/testSendTemplate") + @RequestMapping(value="/testSendTemplate",method=RequestMethod.GET) public @ResponseBody String testSendTemplate(String mpOpenid) { String result = WxMpUtil.SendTemplate_Vanker(mpOpenid, "你好,请问东莞万科的楼盘平均价格多少?首付会很高吗?月供5000以内的有没有?在线等,请尽快答复!", "admin", "无", "2017-10-28 21:33:31", "mini.weiyisz.com/wx/chatListView?salesId=1"); diff --git a/src/com/w1hd/zzhnc/controller/pc/PrizeController.java b/src/com/w1hd/zzhnc/controller/pc/PrizeController.java index dc1c920..fbe5a27 100644 --- a/src/com/w1hd/zzhnc/controller/pc/PrizeController.java +++ b/src/com/w1hd/zzhnc/controller/pc/PrizeController.java @@ -23,7 +23,7 @@ public class PrizeController { @Autowired PrizeService prizeService; - @RequestMapping("/prizeList") + @RequestMapping(value = "/prizeList", method = RequestMethod.GET) public ModelAndView prizeList() { return new ModelAndView("/pc/prize/prizeList"); } @@ -56,7 +56,7 @@ public class PrizeController { return new Vo_msg(0, result); } - @RequestMapping("/edit") + @RequestMapping(value = "/edit", method = RequestMethod.POST) @ResponseBody public Object edit(Integer id, String name, Integer num) { Prize p = new Prize(); diff --git a/src/com/w1hd/zzhnc/controller/pc/ReportController.java b/src/com/w1hd/zzhnc/controller/pc/ReportController.java index 5c8c45e..9b63742 100644 --- a/src/com/w1hd/zzhnc/controller/pc/ReportController.java +++ b/src/com/w1hd/zzhnc/controller/pc/ReportController.java @@ -3,6 +3,7 @@ package com.w1hd.zzhnc.controller.pc; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @@ -20,79 +21,79 @@ public class ReportController extends BaseController { @Autowired FansService fansService; - @RequestMapping("/goods") + @RequestMapping(value = "/goods", method = RequestMethod.GET) public ModelAndView goods() { ModelAndView mv = new ModelAndView("/pc/report/goods"); return mv; } - @RequestMapping("/prize") + + @RequestMapping(value = "/prize", method = RequestMethod.GET) public ModelAndView prize() { ModelAndView mv = new ModelAndView("/pc/report/prize"); return mv; } - - @RequestMapping("/chatrecord") + + @RequestMapping(value = "/chatrecord", method = RequestMethod.GET) public ModelAndView chatrecord() { ModelAndView mv = new ModelAndView("/pc/report/chatrecord"); return mv; } - - @RequestMapping("/chatrecordCopy") + + @RequestMapping(value = "/chatrecordCopy", method = RequestMethod.GET) public ModelAndView chatrecord2(String fansname) { ModelAndView mv = new ModelAndView("/pc/report/chatrecord_copy"); mv.addObject("fansname", fansname); return mv; } - - @RequestMapping("/chatlog") + + @RequestMapping(value = "/chatlog", method = RequestMethod.GET) public ModelAndView chatlog() { ModelAndView mv = new ModelAndView("/pc/report/chatlog"); return mv; } - @RequestMapping("/fans") + @RequestMapping(value = "/fans", method = RequestMethod.GET) public ModelAndView fans() { ModelAndView mv = new ModelAndView("/pc/report/fans"); return mv; } - @RequestMapping("/posterrecord") + @RequestMapping(value = "/posterrecord", method = RequestMethod.GET) public ModelAndView posterrecord() { ModelAndView mv = new ModelAndView("/pc/report/posterrecord"); return mv; } - @RequestMapping("/salereport") + @RequestMapping(value = "/salereport", method = RequestMethod.GET) public ModelAndView salereport() { ModelAndView mv = new ModelAndView("/pc/report/salereport"); return mv; } - @RequestMapping("/callreport") + @RequestMapping(value = "/callreport", method = RequestMethod.GET) public ModelAndView wanxereport() { ModelAndView mv = new ModelAndView("/pc/report/callreport"); return mv; } - @RequestMapping("/remarksreport") + @RequestMapping(value = "/remarksreport", method = RequestMethod.GET) public ModelAndView remarksreport() { ModelAndView mv = new ModelAndView("/pc/report/remarksreport"); return mv; } - @RequestMapping("/winningrecord") + @RequestMapping(value = "/winningrecord", method = RequestMethod.GET) public ModelAndView winningrecord() { ModelAndView mv = new ModelAndView("/pc/report/winningrecord"); return mv; } // 聊天记录列表 - @RequestMapping(value = "/getChatLogList") + @RequestMapping(value = "/getChatLogList", method = RequestMethod.GET) @ResponseBody public Object getChatLogList(Integer page, Integer replytype, String date1, String date2, String keyword) { return new Vo_msg(0, chatlogService.getChatLogList(page, replytype, date1, date2, keyword)); } - } \ No newline at end of file diff --git a/src/com/w1hd/zzhnc/controller/pc/SellerController.java b/src/com/w1hd/zzhnc/controller/pc/SellerController.java index ba36a49..073df4e 100644 --- a/src/com/w1hd/zzhnc/controller/pc/SellerController.java +++ b/src/com/w1hd/zzhnc/controller/pc/SellerController.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; @@ -21,20 +22,20 @@ public class SellerController { @Autowired SellerService sellerService; - @RequestMapping("/sellerList") + @RequestMapping(value="/sellerList",method=RequestMethod.GET) public ModelAndView sellerList() { return new ModelAndView("/pc/seller/sellerList"); } @ResponseBody - @RequestMapping("/update") + @RequestMapping(value="/update",method=RequestMethod.POST) public Object update(@RequestBody Seller s) { boolean b = sellerService.update(s); return new Vo_msg(0, true); } @ResponseBody - @RequestMapping("/search") + @RequestMapping(value="/search",method=RequestMethod.GET) public Object search(@RequestParam(value = "key", required = false) String key, @RequestParam(value = "sellerId", required = false, defaultValue = "0") Integer sellerId, @RequestParam(value = "page", required = false, defaultValue = "1") Integer page, diff --git a/src/com/w1hd/zzhnc/controller/pc/UploadController.java b/src/com/w1hd/zzhnc/controller/pc/UploadController.java index 5afa02c..22aadf4 100644 --- a/src/com/w1hd/zzhnc/controller/pc/UploadController.java +++ b/src/com/w1hd/zzhnc/controller/pc/UploadController.java @@ -37,223 +37,227 @@ import com.w1hd.zzhnc.vo.Vo_msg; @RequestMapping("/upload") public class UploadController extends BaseController { - /** - * 上传图片 - * - * @param request - * @return - * @throws IOException - */ - @RequestMapping(value = "/UploadImg", method = RequestMethod.POST) - public @ResponseBody Object UploadImg(HttpServletRequest request, MultipartFile file) throws IOException { - if (file == null || file.isEmpty()) - return new Vo_msg(-1, "上传文件不能为空"); - String returnPath = ""; // 需要返回的图片相对路径 + /** + * 上传图片 + * + * @param request + * @return + * @throws IOException + */ - String realPath = request.getSession().getServletContext().getRealPath("/WEB-INF/res/upload"); - String imageType = "posttemplet"; - File path = new File(""); - String fileName = file.getOriginalFilename(); - String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); - System.out.println("fileExt:" + fileExt); - SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); - String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt; - try { - // 判断文件夹是否存在。如果不存在则创建文件夹 - String ctxPath = realPath + "/" + imageType; - File filepath = new File(ctxPath); - if (!filepath.exists()) { - filepath.mkdirs(); - } - BufferedImage bi = null; - path = new File(ctxPath + "/" + newFileName); - System.out.println("path=" + path); - BufferedImage src = ImageIO.read(file.getInputStream()); - int src_width = src.getWidth(); - int src_height = src.getHeight(); + @RequestMapping(value = "/UploadImg", method = RequestMethod.POST) + public @ResponseBody Object UploadImg(HttpServletRequest request, MultipartFile file) throws IOException { - int angel = getRotateAngleForPhoto(file.getInputStream()); - if (angel != 0) { - /* - * BufferedImage src = ImageIO.read(file.getInputStream()); int src_width = src.getWidth(null); int - * src_height = src.getHeight(null); - */ - Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension(src_width, src_height)), angel); - bi = new BufferedImage(rect_des.width, rect_des.height, BufferedImage.TYPE_INT_RGB); - Graphics2D g2 = bi.createGraphics(); - g2.translate((rect_des.width - src_width) / 2, (rect_des.height - src_height) / 2); - g2.rotate(Math.toRadians(angel), src_width / 2, src_height / 2); - g2.drawImage(src, null, null); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - ImageIO.write(bi, fileExt, os); - FileCopyUtils.copy(os.toByteArray(), path); // 把图片复制到本地 - os.close(); - } else { - FileCopyUtils.copy(file.getBytes(), path); // 把图片复制到本地 - } - // 图片压缩 - if (src_width != 640) { - int height = (src_height * 640) / src_width; - System.out.println("scaleheight:" + height); - com.w1hd.zzhnc.util.ImageUtil.scale2(ctxPath + "/" + newFileName, ctxPath + "/" + newFileName, - height, 640, false); + if (true) { + return com.w1hd.zzhnc.util.SpringFTPUtil.upload(file.getInputStream(), file.getOriginalFilename(), "zzhnc", + 0, 0, 1.0f); - } - returnPath = "/zzhnc/res/upload/" + imageType + "/" + newFileName; - System.out.println(returnPath); + } + if (file == null || file.isEmpty()) + return new Vo_msg(-1, "上传文件不能为空"); + String returnPath = ""; // 需要返回的图片相对路径 - /* } */ - } catch (Exception e) { - e.printStackTrace(); - return new Vo_msg(-1, "上传失败,数据异常"); - } - System.out.println("图片path=" + path); - return new Vo_msg(0, returnPath); - } + String realPath = request.getSession().getServletContext().getRealPath("/WEB-INF/res/upload"); + String imageType = "posttemplet"; + File path = new File(""); + String fileName = file.getOriginalFilename(); + String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); + System.out.println("fileExt:" + fileExt); + SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); + String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt; + try { + // 判断文件夹是否存在。如果不存在则创建文件夹 + String ctxPath = realPath + "/" + imageType; + File filepath = new File(ctxPath); + if (!filepath.exists()) { + filepath.mkdirs(); + } + BufferedImage bi = null; + path = new File(ctxPath + "/" + newFileName); + System.out.println("path=" + path); + BufferedImage src = ImageIO.read(file.getInputStream()); + int src_width = src.getWidth(); + int src_height = src.getHeight(); - /** - * 图片翻转时,计算图片翻转到正常显示需旋转角度 - */ - public int getRotateAngleForPhoto(InputStream stream) { + int angel = getRotateAngleForPhoto(file.getInputStream()); + if (angel != 0) { + /* + * BufferedImage src = ImageIO.read(file.getInputStream()); int src_width = + * src.getWidth(null); int src_height = src.getHeight(null); + */ + Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension(src_width, src_height)), angel); + bi = new BufferedImage(rect_des.width, rect_des.height, BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = bi.createGraphics(); + g2.translate((rect_des.width - src_width) / 2, (rect_des.height - src_height) / 2); + g2.rotate(Math.toRadians(angel), src_width / 2, src_height / 2); + g2.drawImage(src, null, null); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageIO.write(bi, fileExt, os); + FileCopyUtils.copy(os.toByteArray(), path); // 把图片复制到本地 + os.close(); + } else { + FileCopyUtils.copy(file.getBytes(), path); // 把图片复制到本地 + } + // 图片压缩 + if (src_width != 640) { + int height = (src_height * 640) / src_width; + System.out.println("scaleheight:" + height); + com.w1hd.zzhnc.util.ImageUtil.scale2(ctxPath + "/" + newFileName, ctxPath + "/" + newFileName, height, + 640, false); - int angel = 0; - Metadata metadata; + } + returnPath = "/zzhnc/res/upload/" + imageType + "/" + newFileName; + System.out.println(returnPath); - try { - metadata = JpegMetadataReader.readMetadata(stream); - Directory directory = metadata.getDirectory(ExifDirectory.class); - if (directory.containsTag(ExifDirectory.TAG_ORIENTATION)) { - // Exif信息中方向 - int orientation = directory.getInt(ExifDirectory.TAG_ORIENTATION); - // 原图片的方向信息 - if (6 == orientation) { - // 6旋转90 - angel = 90; - } else if (3 == orientation) { - // 3旋转180 - angel = 180; - } else if (8 == orientation) { - // 8旋转90 - angel = 270; - } - } - } catch (JpegProcessingException e) { - } catch (MetadataException e) { - } - return angel; - } + /* } */ + } catch (Exception e) { + e.printStackTrace(); + return new Vo_msg(-1, "上传失败,数据异常"); + } + System.out.println("图片path=" + path); + return new Vo_msg(0, returnPath); + } - /** - * 计算旋转参数 - */ - public static Rectangle CalcRotatedSize(Rectangle src, int angel) { - // if angel is greater than 90 degree,we need to do some conversion. - if (angel > 90) { - if (angel / 9 % 2 == 1) { - int temp = src.height; - src.height = src.width; - src.width = temp; - } - angel = angel % 90; - } + /** + * 图片翻转时,计算图片翻转到正常显示需旋转角度 + */ + public int getRotateAngleForPhoto(InputStream stream) { - double r = Math.sqrt(src.height * src.height + src.width * src.width) / 2; - double len = 2 * Math.sin(Math.toRadians(angel) / 2) * r; - double angel_alpha = (Math.PI - Math.toRadians(angel)) / 2; - double angel_dalta_width = Math.atan((double) src.height / src.width); - double angel_dalta_height = Math.atan((double) src.width / src.height); + int angel = 0; + Metadata metadata; - int len_dalta_width = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_width)); - int len_dalta_height = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_height)); - int des_width = src.width + len_dalta_width * 2; - int des_height = src.height + len_dalta_height * 2; - return new java.awt.Rectangle(new Dimension(des_width, des_height)); - } + try { + metadata = JpegMetadataReader.readMetadata(stream); + Directory directory = metadata.getDirectory(ExifDirectory.class); + if (directory.containsTag(ExifDirectory.TAG_ORIENTATION)) { + // Exif信息中方向 + int orientation = directory.getInt(ExifDirectory.TAG_ORIENTATION); + // 原图片的方向信息 + if (6 == orientation) { + // 6旋转90 + angel = 90; + } else if (3 == orientation) { + // 3旋转180 + angel = 180; + } else if (8 == orientation) { + // 8旋转90 + angel = 270; + } + } + } catch (JpegProcessingException e) { + } catch (MetadataException e) { + } + return angel; + } - + /** + * 计算旋转参数 + */ + public static Rectangle CalcRotatedSize(Rectangle src, int angel) { + // if angel is greater than 90 degree,we need to do some conversion. + if (angel > 90) { + if (angel / 9 % 2 == 1) { + int temp = src.height; + src.height = src.width; + src.width = temp; + } + angel = angel % 90; + } - /** - * 上传图片 - * - * @param request - * @return - * @throws IOException - */ - @RequestMapping(value = "/NewUploadImg", method = RequestMethod.POST) - public @ResponseBody Object NewUploadImg(HttpServletRequest request) throws IOException { - + double r = Math.sqrt(src.height * src.height + src.width * src.width) / 2; + double len = 2 * Math.sin(Math.toRadians(angel) / 2) * r; + double angel_alpha = (Math.PI - Math.toRadians(angel)) / 2; + double angel_dalta_width = Math.atan((double) src.height / src.width); + double angel_dalta_height = Math.atan((double) src.width / src.height); - String returnPath = ""; // 需要返回的图片相对路径 - MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; - Map fileMap = multipartRequest.getFileMap(); - String realPath = request.getSession().getServletContext().getRealPath("/WEB-INF/res/upload"); - System.out.println(CommonUtil.getTime()); - String uploadType = null; - String imageType = "UE"; - File path = new File(""); - for (Map.Entry entity : fileMap.entrySet()) { - MultipartFile mf = entity.getValue(); - String fileName = mf.getOriginalFilename(); - String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); - uploadType = request.getParameter("uploadType"); // 判断是单个上传还是批量上传 - String newFileName = ""; - // 抽奖人名单 - if ("employees".equals(imageType)) { - boolean b = fileName.contains(".jpg"); - if (!b) { - return "上传文件扩展名是不允许的扩展名。只允许jpg格式。!"; - } - newFileName = fileName; - } else { - SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); - newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt; - } - try { - // 判断文件夹是否存在。如果不存在则创建文件夹 - String ctxPath = realPath + "/" + imageType; - File file = new File(ctxPath); - if (!file.exists()) { - file.mkdirs(); - } - BufferedImage bi = null; - path = new File(ctxPath + "/" + newFileName); - System.out.println("path=" + path); - int angel = getRotateAngleForPhoto(mf.getInputStream()); - if (angel != 0) { - BufferedImage src = ImageIO.read(mf.getInputStream()); - int src_width = src.getWidth(null); - int src_height = src.getHeight(null); - Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension(src_width, src_height)), angel); + int len_dalta_width = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_width)); + int len_dalta_height = (int) (len * Math.cos(Math.PI - angel_alpha - angel_dalta_height)); + int des_width = src.width + len_dalta_width * 2; + int des_height = src.height + len_dalta_height * 2; + return new java.awt.Rectangle(new Dimension(des_width, des_height)); + } - bi = new BufferedImage(rect_des.width, rect_des.height, BufferedImage.TYPE_INT_RGB); - Graphics2D g2 = bi.createGraphics(); - g2.translate((rect_des.width - src_width) / 2, (rect_des.height - src_height) / 2); - g2.rotate(Math.toRadians(angel), src_width / 2, src_height / 2); + /** + * 上传图片 + * + * @param request + * @return + * @throws IOException + */ + @RequestMapping(value = "/NewUploadImg", method = RequestMethod.POST) + public @ResponseBody Object NewUploadImg(HttpServletRequest request) throws IOException { - g2.drawImage(src, null, null); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - ImageIO.write(bi, fileExt, os); - FileCopyUtils.copy(os.toByteArray(), path); // 把图片复制到本地 - os.close(); - } else { - FileCopyUtils.copy(mf.getBytes(), path); // 把图片复制到本地 - } - - returnPath = "http://mini.weiyisz.com/zzhnc/res/upload/" + imageType + "/" + newFileName; - System.out.println(returnPath); - /* } */ - } catch (Exception e) { - e.printStackTrace(); - return ""; - } - } + String returnPath = ""; // 需要返回的图片相对路径 + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map fileMap = multipartRequest.getFileMap(); + String realPath = request.getSession().getServletContext().getRealPath("/WEB-INF/res/upload"); + System.out.println(CommonUtil.getTime()); + String uploadType = null; + String imageType = "UE"; + File path = new File(""); + for (Map.Entry entity : fileMap.entrySet()) { + MultipartFile mf = entity.getValue(); + String fileName = mf.getOriginalFilename(); + String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); + uploadType = request.getParameter("uploadType"); // 判断是单个上传还是批量上传 + String newFileName = ""; + // 抽奖人名单 + if ("employees".equals(imageType)) { + boolean b = fileName.contains(".jpg"); + if (!b) { + return "上传文件扩展名是不允许的扩展名。只允许jpg格式。!"; + } + newFileName = fileName; + } else { + SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); + newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt; + } + try { + // 判断文件夹是否存在。如果不存在则创建文件夹 + String ctxPath = realPath + "/" + imageType; + File file = new File(ctxPath); + if (!file.exists()) { + file.mkdirs(); + } + BufferedImage bi = null; + path = new File(ctxPath + "/" + newFileName); + System.out.println("path=" + path); + int angel = getRotateAngleForPhoto(mf.getInputStream()); + if (angel != 0) { + BufferedImage src = ImageIO.read(mf.getInputStream()); + int src_width = src.getWidth(null); + int src_height = src.getHeight(null); + Rectangle rect_des = CalcRotatedSize(new Rectangle(new Dimension(src_width, src_height)), angel); - // if (uploadType != null) { // 批量上传 - String result = "{\"name\":\"\", \"originalName\": \"\", \"size\":\"1000\", \"state\": \"SUCCESS\", \"type\": \"\", \"url\": \"" - + returnPath + "\"}"; - result = result.replaceAll("\\\\", "\\\\"); - return result; - - } + bi = new BufferedImage(rect_des.width, rect_des.height, BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = bi.createGraphics(); + g2.translate((rect_des.width - src_width) / 2, (rect_des.height - src_height) / 2); + g2.rotate(Math.toRadians(angel), src_width / 2, src_height / 2); + + g2.drawImage(src, null, null); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + ImageIO.write(bi, fileExt, os); + FileCopyUtils.copy(os.toByteArray(), path); // 把图片复制到本地 + os.close(); + } else { + FileCopyUtils.copy(mf.getBytes(), path); // 把图片复制到本地 + } + + returnPath = "http://mini.weiyisz.com/zzhnc/res/upload/" + imageType + "/" + newFileName; + System.out.println(returnPath); + /* } */ + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + + // if (uploadType != null) { // 批量上传 + String result = "{\"name\":\"\", \"originalName\": \"\", \"size\":\"1000\", \"state\": \"SUCCESS\", \"type\": \"\", \"url\": \"" + + returnPath + "\"}"; + result = result.replaceAll("\\\\", "\\\\"); + return result; + + } } diff --git a/src/com/w1hd/zzhnc/service/GoodsService.java b/src/com/w1hd/zzhnc/service/GoodsService.java index 8bac5bf..a2980a8 100644 --- a/src/com/w1hd/zzhnc/service/GoodsService.java +++ b/src/com/w1hd/zzhnc/service/GoodsService.java @@ -39,15 +39,20 @@ public class GoodsService { return goods; } - public PageResults seacrh(String key, Integer sellerId, Integer page, Integer size) { + public PageResults seacrh(Integer id, String key, Integer sellerId, Integer page, Integer size) { Example ex = new Example(Goods.class); Criteria c = ex.createCriteria(); - if (!Strings.isNullOrEmpty(key)) { - c.andCondition(" (description like \"%" + key + "%\" or name like \"%" + key + "%\")"); - } - if (sellerId != null && sellerId > 0) { - c.andEqualTo("sellerId", sellerId); + if (id != null && id > 0) { + c.andEqualTo("id", id); + } else { + if (!Strings.isNullOrEmpty(key)) { + c.andCondition(" (description like \"%" + key + "%\" or name like \"%" + key + "%\")"); + } + if (sellerId != null && sellerId > 0) { + c.andEqualTo("sellerId", sellerId); + } } + c.andEqualTo("deleted", false); RowBounds row = new RowBounds(page, size); List list = goodsDao.selectByExampleAndRowBounds(ex, row); diff --git a/src/com/w1hd/zzhnc/util/SpringFTPUtil.java b/src/com/w1hd/zzhnc/util/SpringFTPUtil.java new file mode 100644 index 0000000..fa894b5 --- /dev/null +++ b/src/com/w1hd/zzhnc/util/SpringFTPUtil.java @@ -0,0 +1,192 @@ +package com.w1hd.zzhnc.util; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.mime.MultipartEntity; +import org.apache.http.entity.mime.content.InputStreamBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.integration.file.remote.session.CachingSessionFactory; +import org.springframework.integration.file.remote.session.Session; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; + +/** + * spring ftp工具类 + */ +public class SpringFTPUtil { + + private final static Logger logger = LoggerFactory.getLogger(SpringFTPUtil.class); + + /** + * 图片上传封装类,上传图片名称使用imgfile名称 + * + * @param ftpChannel + * @param imgfile + * @param ftpServerPath + * @return + * @throws UnsupportedEncodingException + */ + public static boolean ftpUpload(MessageChannel ftpChannel, File imgfile, String ftpServerPath) + throws UnsupportedEncodingException { + if (StringUtils.isNotBlank(ftpServerPath) && ftpServerPath.startsWith("/")) { + ftpServerPath = StringUtils.substringAfter(ftpServerPath, "/"); + } + Message message = MessageBuilder.withPayload(imgfile) + .setHeader("remote_dir", new String(ftpServerPath.getBytes(Charset.forName("UTF-8")), "ISO-8859-1")) + .setHeader("remote_filename", + new String(imgfile.getName().getBytes(Charset.forName("UTF-8")), "ISO-8859-1")) + .build(); + return ftpChannel.send(message); + } + + /** + * 图片上传封装类 + * + * @param uploadFileMap + * @param ftpServerPath + * @return + * @throws UnsupportedEncodingException + */ + public static Map ftpUpload(MessageChannel ftpChannel, Map uploadFileMap, + String ftpServerPath) throws UnsupportedEncodingException { + if (StringUtils.isNotBlank(ftpServerPath) && ftpServerPath.startsWith("/")) + ftpServerPath = StringUtils.substringAfter(ftpServerPath, "/"); + Message message = null; + Map failFileMap = new HashMap(); + boolean result = true; + for (String uploadFileStr : uploadFileMap.keySet()) { + message = MessageBuilder.withPayload(uploadFileMap.get(uploadFileStr)) + .setHeader("remote_dir", ftpServerPath) + .setHeader("remote_filename", new String(uploadFileStr.getBytes("UTF-8"), "ISO-8859-1")).build(); + result = ftpChannel.send(message); + if (!result) { + failFileMap.put(uploadFileStr, uploadFileMap.get(uploadFileStr)); + } + } + return failFileMap; + } + + /** + * 图片上传封装类,上传图片名称使用ftpfilename名称(重命名) + * + * @param ftpChannel + * @param imgfile + * @param ftpfilename + * @param ftpServerPath + * @return + * @throws UnsupportedEncodingException + */ + public static boolean ftpUpload(MessageChannel ftpChannel, File imgfile, String ftpfilename, String ftpServerPath) + throws UnsupportedEncodingException { + if (StringUtils.isNotBlank(ftpServerPath) && ftpServerPath.startsWith("/")) { + ftpServerPath = StringUtils.substringAfter(ftpServerPath, "/"); + } + Message message = MessageBuilder.withPayload(imgfile) + .setHeader("remote_dir", new String(ftpServerPath.getBytes(Charset.forName("UTF-8")), "ISO-8859-1")) + .setHeader("remote_filename", new String(ftpfilename.getBytes(Charset.forName("UTF-8")), "ISO-8859-1")) + .build(); + return ftpChannel.send(message); + } + + /** + * 图片上传封装类,上传图片名称使用ftpfilename名称(重命名) + * + * @param ftpChannel + * @param fileInputStream + * @param ftpfilename + * @param ftpServerPath + * @return + * @throws Exception + */ + public static boolean ftpUpload(MessageChannel ftpChannel, InputStream fileInputStream, String ftpfilename, + String ftpServerPath) throws Exception { + if (StringUtils.isNotBlank(ftpServerPath) && ftpServerPath.startsWith("/")) { + ftpServerPath = StringUtils.substringAfter(ftpServerPath, "/"); + } + Message message = null; + try { + message = MessageBuilder.withPayload(IOUtils.toByteArray(fileInputStream)) + .setHeader("remote_dir", new String(ftpServerPath.getBytes(Charset.forName("UTF-8")), "ISO-8859-1")) + .setHeader("remote_filename", + new String(ftpfilename.getBytes(Charset.forName("UTF-8")), "ISO-8859-1")) + .build(); + } catch (IOException e) { + logger.error("ftp上传图片产生异常", e); + throw new Exception(e); + } finally { + IOUtils.closeQuietly(fileInputStream); + } + try { + return ftpChannel.send(message); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + private static final String[] extensionPermit = {"jpg", "png", "gif", "jpeg" }; + + public static Object upload(InputStream fileInputStream, String fileName, String merchantId, Integer height, + Integer width, Float scale) { + String fdfsPath = ""; + try { + String url = "http://120.76.158.63:8081/wykj/resource/imgUpload"; + String extension = FilenameUtils.getExtension(fileName); + if (!ArrayUtils.contains(extensionPermit, extension)) { + url = "http://120.76.158.63:8081/wykj/resource/fileUpload"; + } + HttpClient httpclient = new DefaultHttpClient(); + HttpPost httppost = new HttpPost(url); + String name = fileName; + MultipartEntity reqEntity = new MultipartEntity(); + InputStreamBody inputStreamBody = new InputStreamBody(fileInputStream, name); + StringBody fileNam = new StringBody(name); + StringBody dateFlag = new StringBody(DateUtil.getCurrentDateTime3Str()); + StringBody metrialsType = new StringBody("25"); + StringBody ip = new StringBody("0.0.0.1"); + + reqEntity.addPart("fileName", fileNam); + reqEntity.addPart("dateFlag", dateFlag); + reqEntity.addPart("metrialsType", metrialsType); + reqEntity.addPart("file", inputStreamBody); + reqEntity.addPart("height", new StringBody(String.valueOf(height))); + reqEntity.addPart("merchantId", new StringBody(merchantId)); + reqEntity.addPart("width", new StringBody(String.valueOf(width))); + reqEntity.addPart("scale", new StringBody(String.valueOf(scale))); + httppost.setEntity(reqEntity); + HttpResponse response = httpclient.execute(httppost); + int statusCode = response.getStatusLine().getStatusCode(); + + if (statusCode == HttpStatus.SC_OK) { + + System.out.println("服务器正常响应....."); + HttpEntity resEntity = response.getEntity(); + return EntityUtils.toString(resEntity); + + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} -- libgit2 0.24.0