Commit 261c4e04caf7728016a662ebc8dc1dc19bd2c227
1 parent
bbcd213f
Exists in
master
动态码
Showing
5 changed files
with
62 additions
and
11 deletions
Show diff stats
src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java
@@ -17,9 +17,14 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -17,9 +17,14 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
17 | import org.springframework.web.bind.annotation.RequestMethod; | 17 | import org.springframework.web.bind.annotation.RequestMethod; |
18 | import org.springframework.web.bind.annotation.RestController; | 18 | import org.springframework.web.bind.annotation.RestController; |
19 | 19 | ||
20 | +import javax.imageio.ImageIO; | ||
21 | +import javax.servlet.ServletOutputStream; | ||
22 | +import javax.servlet.http.HttpServletResponse; | ||
23 | +import java.awt.image.BufferedImage; | ||
20 | import java.io.*; | 24 | import java.io.*; |
21 | import java.net.HttpURLConnection; | 25 | import java.net.HttpURLConnection; |
22 | import java.net.URL; | 26 | import java.net.URL; |
27 | +import java.net.URLEncoder; | ||
23 | 28 | ||
24 | @RestController | 29 | @RestController |
25 | @RequestMapping("reportVoluntary") | 30 | @RequestMapping("reportVoluntary") |
@@ -142,19 +147,28 @@ public class ReportVoluntaryController { | @@ -142,19 +147,28 @@ public class ReportVoluntaryController { | ||
142 | 147 | ||
143 | @ApiOperation("获取小程序动态码") | 148 | @ApiOperation("获取小程序动态码") |
144 | @RequestMapping(value = "/downloadSmallRoutine" , method = RequestMethod.GET) | 149 | @RequestMapping(value = "/downloadSmallRoutine" , method = RequestMethod.GET) |
145 | - public BaseDto downloadSmallRoutine(int channelId){ | ||
146 | - BaseDto result = new BaseDto(); | 150 | + public void downloadSmallRoutine(int channelId, HttpServletResponse response){ |
147 | Channel channel = channelService.getDetail(channelId); | 151 | Channel channel = channelService.getDetail(channelId); |
148 | if(StringUtils.isBlank(channel.getReportRoutineUrl())){ | 152 | if(StringUtils.isBlank(channel.getReportRoutineUrl())){ |
149 | createRoutine(channelId); | 153 | createRoutine(channelId); |
150 | - String prefix = domain.replaceAll("51314","51315"); | ||
151 | - String url = prefix+"smallRoutine\\"+channelId+".png" ; | 154 | + String url = "https://market.myjxt.com:51315/smallRoutine/"+channelId+".png" ; |
152 | channel.setReportRoutineUrl(url); | 155 | channel.setReportRoutineUrl(url); |
153 | channelService.updateRoutine(channelId,url); | 156 | channelService.updateRoutine(channelId,url); |
154 | } | 157 | } |
155 | - result.setData(channel.getReportRoutineUrl()); | ||
156 | - return result ; | ||
157 | - | 158 | + try{ |
159 | + String fileUrl = channel.getReportRoutineUrl().replace("https://market.myjxt.com:51315/smallRoutine/","c:\\report\\img\\smallRoutine\\"); | ||
160 | + response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(channel.getName()+"动态码.jpg", "utf-8")); | ||
161 | + InputStream in = new FileInputStream(fileUrl); | ||
162 | + OutputStream out = response.getOutputStream(); | ||
163 | + byte [] by = new byte[1024]; | ||
164 | + int i = 0; | ||
165 | + while((i=in.read(by))!=-1) { | ||
166 | + out.write(by,0,i); | ||
167 | + } | ||
168 | + in.close(); | ||
169 | + }catch (Exception e){ | ||
170 | + e.printStackTrace(); | ||
171 | + } | ||
158 | } | 172 | } |
159 | 173 | ||
160 | public void createRoutine(int channelId){ | 174 | public void createRoutine(int channelId){ |
@@ -183,7 +197,7 @@ public class ReportVoluntaryController { | @@ -183,7 +197,7 @@ public class ReportVoluntaryController { | ||
183 | printWriter.flush(); | 197 | printWriter.flush(); |
184 | //开始获取数据 | 198 | //开始获取数据 |
185 | BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream()); | 199 | BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream()); |
186 | - OutputStream os = new FileOutputStream(new File("D:\report\img\smallRoutine\"+channelId+".png")); | 200 | + OutputStream os = new FileOutputStream(new File("C:\report\img\smallRoutine\"+channelId+".png")); |
187 | int len; | 201 | int len; |
188 | byte[] arr = new byte[1024]; | 202 | byte[] arr = new byte[1024]; |
189 | while ((len = bis.read(arr)) != -1) | 203 | while ((len = bis.read(arr)) != -1) |
@@ -192,13 +206,19 @@ public class ReportVoluntaryController { | @@ -192,13 +206,19 @@ public class ReportVoluntaryController { | ||
192 | os.flush(); | 206 | os.flush(); |
193 | } | 207 | } |
194 | os.close(); | 208 | os.close(); |
195 | - } | ||
196 | - catch (Exception e) | ||
197 | - { | 209 | + }catch (Exception e) { |
198 | e.printStackTrace(); | 210 | e.printStackTrace(); |
199 | } | 211 | } |
200 | } | 212 | } |
201 | 213 | ||
214 | + @ApiOperation("获取渠道商列表") | ||
215 | + @RequestMapping(value = "/getChannelList" , method = RequestMethod.GET) | ||
216 | + public BaseDto getChannelList(String name , int page , int pageSize ){ | ||
217 | + BaseDto result = new BaseDto(); | ||
218 | + result.setData(channelService.getReportChannel(page,pageSize,name)); | ||
219 | + return result ; | ||
220 | + } | ||
221 | + | ||
202 | @ApiOperation("获取渠道商推广的用户") | 222 | @ApiOperation("获取渠道商推广的用户") |
203 | @RequestMapping(value = "/getUserList" , method = RequestMethod.GET) | 223 | @RequestMapping(value = "/getUserList" , method = RequestMethod.GET) |
204 | public JSONObject getUserList(int channelId , int page , int pageSize){ | 224 | public JSONObject getUserList(int channelId , int page , int pageSize){ |
src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java
@@ -8,6 +8,9 @@ import java.util.List; | @@ -8,6 +8,9 @@ import java.util.List; | ||
8 | 8 | ||
9 | public interface ChannelMapper { | 9 | public interface ChannelMapper { |
10 | 10 | ||
11 | + List<Channel> getReportChannel(@Param("name") String name); | ||
12 | + int getReportChannelCount(@Param("name") String name); | ||
13 | + | ||
11 | Channel getByName(String name); | 14 | Channel getByName(String name); |
12 | 15 | ||
13 | List<Channel> getListByTemplate(int templateId); | 16 | List<Channel> getListByTemplate(int templateId); |
src/main/java/com/sincere/wechatbusiness/service/ChannelService.java
@@ -7,6 +7,8 @@ import java.util.List; | @@ -7,6 +7,8 @@ import java.util.List; | ||
7 | 7 | ||
8 | public interface ChannelService { | 8 | public interface ChannelService { |
9 | 9 | ||
10 | + Page<Channel> getReportChannel(int page , int pageSize , String name); | ||
11 | + | ||
10 | List<Channel> getListByTemplate(int templateId); | 12 | List<Channel> getListByTemplate(int templateId); |
11 | 13 | ||
12 | Page<Channel> getList(Channel channel, int page, int pageSize); | 14 | Page<Channel> getList(Channel channel, int page, int pageSize); |
src/main/java/com/sincere/wechatbusiness/service/impl/ChannelServiceImpl.java
@@ -16,6 +16,15 @@ public class ChannelServiceImpl implements ChannelService { | @@ -16,6 +16,15 @@ public class ChannelServiceImpl implements ChannelService { | ||
16 | ChannelMapper channelMapper; | 16 | ChannelMapper channelMapper; |
17 | 17 | ||
18 | @Override | 18 | @Override |
19 | + public Page<Channel> getReportChannel(int page, int pageSize, String name) { | ||
20 | + Page<Channel> result=new Page<>(page,pageSize); | ||
21 | + PageHelper.startPage(page,pageSize); | ||
22 | + result.setList(channelMapper.getReportChannel(name)); | ||
23 | + result.setCount(channelMapper.getReportChannelCount(name)); | ||
24 | + return result; | ||
25 | + } | ||
26 | + | ||
27 | + @Override | ||
19 | public List<Channel> getListByTemplate(int templateId) { | 28 | public List<Channel> getListByTemplate(int templateId) { |
20 | return channelMapper.getListByTemplate(templateId); | 29 | return channelMapper.getListByTemplate(templateId); |
21 | } | 30 | } |
src/main/resources/mapper/ChannelMapper.xml
@@ -15,8 +15,25 @@ | @@ -15,8 +15,25 @@ | ||
15 | <result column="province_code" jdbcType="VARCHAR" property="provinceCode" /> | 15 | <result column="province_code" jdbcType="VARCHAR" property="provinceCode" /> |
16 | <result column="city_code" jdbcType="VARCHAR" property="cityCode" /> | 16 | <result column="city_code" jdbcType="VARCHAR" property="cityCode" /> |
17 | <result column="report_routine_url" jdbcType="VARCHAR" property="reportRoutineUrl" /> | 17 | <result column="report_routine_url" jdbcType="VARCHAR" property="reportRoutineUrl" /> |
18 | + <result column="register" property="register" /> | ||
18 | </resultMap> | 19 | </resultMap> |
19 | 20 | ||
21 | + <select id="getReportChannel" resultMap="ChannelMap"> | ||
22 | + select * , (select count(*) from report_voluntary.dbo.users as users where users.channelId = channel.id) as register | ||
23 | + from channel where state = 1 | ||
24 | + <if test="name != null and name != ''"> | ||
25 | + and name like '%${name}%' | ||
26 | + </if> | ||
27 | + </select> | ||
28 | + | ||
29 | + <select id="getReportChannelCount" resultType="java.lang.Integer"> | ||
30 | + select count(*) | ||
31 | + from channel where state = 1 | ||
32 | + <if test="name != null and name != ''"> | ||
33 | + and name like '%${name}%' | ||
34 | + </if> | ||
35 | + </select> | ||
36 | + | ||
20 | <select id="getByName" parameterType="java.lang.String" resultMap="ChannelMap"> | 37 | <select id="getByName" parameterType="java.lang.String" resultMap="ChannelMap"> |
21 | select * from channel where name = #{name} and state = 1 | 38 | select * from channel where name = #{name} and state = 1 |
22 | </select> | 39 | </select> |