From 261c4e04caf7728016a662ebc8dc1dc19bd2c227 Mon Sep 17 00:00:00 2001 From: 陈杰 <504987307@qq.com> Date: Tue, 28 Jul 2020 10:42:56 +0800 Subject: [PATCH] 动态码 --- src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java | 42 +++++++++++++++++++++++++++++++----------- src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java | 3 +++ src/main/java/com/sincere/wechatbusiness/service/ChannelService.java | 2 ++ src/main/java/com/sincere/wechatbusiness/service/impl/ChannelServiceImpl.java | 9 +++++++++ src/main/resources/mapper/ChannelMapper.xml | 17 +++++++++++++++++ 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java b/src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java index 13351eb..1e97227 100644 --- a/src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java +++ b/src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java @@ -17,9 +17,14 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import javax.imageio.ImageIO; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.awt.image.BufferedImage; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; +import java.net.URLEncoder; @RestController @RequestMapping("reportVoluntary") @@ -142,19 +147,28 @@ public class ReportVoluntaryController { @ApiOperation("获取小程序动态码") @RequestMapping(value = "/downloadSmallRoutine" , method = RequestMethod.GET) - public BaseDto downloadSmallRoutine(int channelId){ - BaseDto result = new BaseDto(); + public void downloadSmallRoutine(int channelId, HttpServletResponse response){ Channel channel = channelService.getDetail(channelId); if(StringUtils.isBlank(channel.getReportRoutineUrl())){ createRoutine(channelId); - String prefix = domain.replaceAll("51314","51315"); - String url = prefix+"smallRoutine\\"+channelId+".png" ; + String url = "https://market.myjxt.com:51315/smallRoutine/"+channelId+".png" ; channel.setReportRoutineUrl(url); channelService.updateRoutine(channelId,url); } - result.setData(channel.getReportRoutineUrl()); - return result ; - + try{ + String fileUrl = channel.getReportRoutineUrl().replace("https://market.myjxt.com:51315/smallRoutine/","c:\\report\\img\\smallRoutine\\"); + response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(channel.getName()+"动态码.jpg", "utf-8")); + InputStream in = new FileInputStream(fileUrl); + OutputStream out = response.getOutputStream(); + byte [] by = new byte[1024]; + int i = 0; + while((i=in.read(by))!=-1) { + out.write(by,0,i); + } + in.close(); + }catch (Exception e){ + e.printStackTrace(); + } } public void createRoutine(int channelId){ @@ -183,7 +197,7 @@ public class ReportVoluntaryController { printWriter.flush(); //开始获取数据 BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream()); - OutputStream os = new FileOutputStream(new File("D:\\report\\img\\smallRoutine\\"+channelId+".png")); + OutputStream os = new FileOutputStream(new File("C:\\report\\img\\smallRoutine\\"+channelId+".png")); int len; byte[] arr = new byte[1024]; while ((len = bis.read(arr)) != -1) @@ -192,13 +206,19 @@ public class ReportVoluntaryController { os.flush(); } os.close(); - } - catch (Exception e) - { + }catch (Exception e) { e.printStackTrace(); } } + @ApiOperation("获取渠道商列表") + @RequestMapping(value = "/getChannelList" , method = RequestMethod.GET) + public BaseDto getChannelList(String name , int page , int pageSize ){ + BaseDto result = new BaseDto(); + result.setData(channelService.getReportChannel(page,pageSize,name)); + return result ; + } + @ApiOperation("获取渠道商推广的用户") @RequestMapping(value = "/getUserList" , method = RequestMethod.GET) public JSONObject getUserList(int channelId , int page , int pageSize){ diff --git a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java index ac217dc..96aaa86 100644 --- a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java +++ b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java @@ -8,6 +8,9 @@ import java.util.List; public interface ChannelMapper { + List getReportChannel(@Param("name") String name); + int getReportChannelCount(@Param("name") String name); + Channel getByName(String name); List getListByTemplate(int templateId); diff --git a/src/main/java/com/sincere/wechatbusiness/service/ChannelService.java b/src/main/java/com/sincere/wechatbusiness/service/ChannelService.java index 8b62045..2482494 100644 --- a/src/main/java/com/sincere/wechatbusiness/service/ChannelService.java +++ b/src/main/java/com/sincere/wechatbusiness/service/ChannelService.java @@ -7,6 +7,8 @@ import java.util.List; public interface ChannelService { + Page getReportChannel(int page , int pageSize , String name); + List getListByTemplate(int templateId); Page getList(Channel channel, int page, int pageSize); diff --git a/src/main/java/com/sincere/wechatbusiness/service/impl/ChannelServiceImpl.java b/src/main/java/com/sincere/wechatbusiness/service/impl/ChannelServiceImpl.java index a72f06c..c9b01e3 100644 --- a/src/main/java/com/sincere/wechatbusiness/service/impl/ChannelServiceImpl.java +++ b/src/main/java/com/sincere/wechatbusiness/service/impl/ChannelServiceImpl.java @@ -16,6 +16,15 @@ public class ChannelServiceImpl implements ChannelService { ChannelMapper channelMapper; @Override + public Page getReportChannel(int page, int pageSize, String name) { + Page result=new Page<>(page,pageSize); + PageHelper.startPage(page,pageSize); + result.setList(channelMapper.getReportChannel(name)); + result.setCount(channelMapper.getReportChannelCount(name)); + return result; + } + + @Override public List getListByTemplate(int templateId) { return channelMapper.getListByTemplate(templateId); } diff --git a/src/main/resources/mapper/ChannelMapper.xml b/src/main/resources/mapper/ChannelMapper.xml index 256a40c..c77b268 100644 --- a/src/main/resources/mapper/ChannelMapper.xml +++ b/src/main/resources/mapper/ChannelMapper.xml @@ -15,8 +15,25 @@ + + + + + -- libgit2 0.21.0