Commit cdc584440858046437e897f1d6f838714ec518d3

Authored by 陈杰
1 parent a191d3cf
Exists in master

1

src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java
... ... @@ -432,6 +432,14 @@ public class ChannelController {
432 432 return result;
433 433 }
434 434  
  435 + @RequestMapping(value = "openAddress",method = RequestMethod.GET)
  436 + @ApiOperation(value = "开启配送,或者关闭配送")
  437 + public BaseDto openAddress(int id){
  438 + ChannelProduct channelProduct = channelProductService.getDetail(id);
  439 + channelProductService.updateProductOpenAddress(channelProduct.getOpenAddress()==1?0:1,id);
  440 + return new BaseDto();
  441 + }
  442 +
435 443 @RequestMapping(value = "GetDiscountPackage",method = RequestMethod.GET)
436 444 @ApiOperation(value = "获取商品详情")
437 445 public BaseDto<DiscountPackage> GetDiscountPackage(int id){
... ... @@ -589,6 +597,7 @@ public class ChannelController {
589 597 object.put("score_id",0);
590 598 object.put("channelId",order.getChannelId());
591 599 object.put("agentId",order.getAgentId());
  600 + object.put("address",order.getAddress());
592 601 JSONObject jsonObject = HttpClientUtils.httpPostJson(domain+"/University/GetAddOrderDetail",object.toJSONString());
593 602 String data = jsonObject.getString("data");
594 603 result.setData(JSON.parseObject(data,new TypeReference<List<Order>>(){}));
... ...
src/main/java/com/sincere/wechatbusiness/controller/CodeController.java 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +//package com.sincere.wechatbusiness.controller;
  2 +//
  3 +//import com.alibaba.fastjson.JSONObject;
  4 +//import com.sincere.wechatbusiness.utils.HttpClientUtils;
  5 +//import org.springframework.web.bind.annotation.RestController;
  6 +//
  7 +//import java.io.*;
  8 +//import java.net.HttpURLConnection;
  9 +//import java.net.URL;
  10 +//
  11 +//@RestController
  12 +//public class CodeController {
  13 +//
  14 +// private static String appId = "wxd055a716238e1bd7";
  15 +// private static String secret = "c6912d34732b65116b8b4e9d5f8a81a5";
  16 +//
  17 +// public static void main(String[] args){
  18 +// String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret;
  19 +// JSONObject object = HttpClientUtils.httpGet(url) ;
  20 +// String token = object.get("access_token").toString();
  21 +// try {
  22 +// URL imgUrl = new URL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token);
  23 +// HttpURLConnection httpURLConnection = (HttpURLConnection) imgUrl.openConnection();
  24 +// httpURLConnection.setRequestMethod("POST");// 提交模式
  25 +// // conn.setConnectTimeout(10000);//连接超时 单位毫秒
  26 +// // conn.setReadTimeout(2000);//读取超时 单位毫秒
  27 +// // 发送POST请求必须设置如下两行
  28 +// httpURLConnection.setDoOutput(true);
  29 +// httpURLConnection.setDoInput(true);
  30 +// // 获取URLConnection对象对应的输出流
  31 +// PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
  32 +// // 发送请求参数
  33 +// JSONObject paramJson = new JSONObject();
  34 +// paramJson.put("scene", "channel=2");
  35 +// paramJson.put("page", "pages/index/index");
  36 +// paramJson.put("width", 430);
  37 +// paramJson.put("auto_color", true);
  38 +// printWriter.write(paramJson.toString());
  39 +// // flush输出流的缓冲
  40 +// printWriter.flush();
  41 +// //开始获取数据
  42 +// BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream());
  43 +// OutputStream os = new FileOutputStream(new File("C:\\Users\\chen\\Desktop\\abc.png"));
  44 +// int len;
  45 +// byte[] arr = new byte[1024];
  46 +// while ((len = bis.read(arr)) != -1)
  47 +// {
  48 +// os.write(arr, 0, len);
  49 +// os.flush();
  50 +// }
  51 +// os.close();
  52 +// }
  53 +// catch (Exception e)
  54 +// {
  55 +// e.printStackTrace();
  56 +// }
  57 +// }
  58 +//}
... ...
src/main/java/com/sincere/wechatbusiness/controller/TestController.java 0 → 100644
... ... @@ -0,0 +1,107 @@
  1 +//package com.sincere.wechatbusiness.controller;
  2 +//
  3 +//import com.sincere.wechatbusiness.dto.BaseDto;
  4 +//import com.sincere.wechatbusiness.mapper.ChannelMapper;
  5 +//import com.sincere.wechatbusiness.model.Banner;
  6 +//import com.sincere.wechatbusiness.model.BannerNext;
  7 +//import com.sincere.wechatbusiness.model.ChannelProduct;
  8 +//import com.sincere.wechatbusiness.service.BannerService;
  9 +//import com.sincere.wechatbusiness.service.ChannelProductService;
  10 +//import com.sincere.wechatbusiness.service.ChannelService;
  11 +//import org.apache.commons.lang3.StringUtils;
  12 +//import org.springframework.beans.factory.annotation.Autowired;
  13 +//import org.springframework.web.bind.annotation.RequestMapping;
  14 +//import org.springframework.web.bind.annotation.RequestMethod;
  15 +//import org.springframework.web.bind.annotation.RestController;
  16 +//
  17 +//import java.io.BufferedReader;
  18 +//import java.io.FileReader;
  19 +//import java.io.IOException;
  20 +//import java.util.List;
  21 +//
  22 +//@RestController
  23 +//public class TestController {
  24 +//
  25 +// @Autowired
  26 +// ChannelService channelService ;
  27 +//
  28 +// @Autowired
  29 +// ChannelProductService channelProductService ;
  30 +//
  31 +// @Autowired
  32 +// BannerService bannerService ;
  33 +//
  34 +// @Autowired
  35 +// ChannelMapper channelMapper ;
  36 +//
  37 +//
  38 +// public static void main(String[] args){
  39 +// try {
  40 +// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt");
  41 +// BufferedReader bf = new BufferedReader(fr);
  42 +// String str;
  43 +// // 按行读取字符串
  44 +// while ((str = bf.readLine()) != null) {
  45 +// String[] message = str.split("=");
  46 +// System.out.println(message[0]+"="+ message[1] +"="+ java.net.URLEncoder.encode(message[2], "UTF-8"));
  47 +// }
  48 +// bf.close();
  49 +// fr.close();
  50 +// } catch (IOException e) {
  51 +// e.printStackTrace();
  52 +// }
  53 +// }
  54 +//
  55 +// @RequestMapping(value = "copy",method = RequestMethod.GET)
  56 +// public BaseDto copyChannel(){
  57 +// int sourceId = 1025 ;
  58 +// ChannelProduct channelProduct = channelProductService.getList(sourceId).get(0);
  59 +// List<Banner> banners = bannerService.getList(sourceId);
  60 +// List<BannerNext> bannerNexts = bannerService.getBannerNextList(sourceId);
  61 +//
  62 +// try {
  63 +// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt");
  64 +// BufferedReader bf = new BufferedReader(fr);
  65 +// String str;
  66 +// // 按行读取字符串
  67 +// while ((str = bf.readLine()) != null) {
  68 +// int channelId = 0;
  69 +// try{
  70 +// channelId = channelMapper.getByName(str.trim() + "团购").getId();
  71 +// }catch (Exception e){
  72 +// System.out.println(str);
  73 +// e.printStackTrace();
  74 +// }
  75 +// int channelProductId = 0 ;
  76 +// List<ChannelProduct> products = channelProductService.getList(channelId);
  77 +// for(ChannelProduct product : products){
  78 +// channelProductId = product.getId();
  79 +// product.setTitle(channelProduct.getTitle());
  80 +// product.setCaption(channelProduct.getCaption());
  81 +// product.setChannelPrice(channelProduct.getChannelPrice());
  82 +// channelProductService.update(product);
  83 +// }
  84 +//
  85 +// bannerService.deleteChannelBanner(channelId);
  86 +// bannerService.deleteChannelBannerNext(channelId);
  87 +// for(Banner banner : banners){
  88 +// banner.setChannelId(channelId);
  89 +// if(StringUtils.isNotBlank(banner.getLinkUrl())){
  90 +// banner.setLinkUrl("http://market.myjxt.com/wap/index.html#/CommodityDetail?id="+channelProductId+"&productId=1");
  91 +// }
  92 +// bannerService.copy(banner);
  93 +// }
  94 +// for(BannerNext bannerNext : bannerNexts){
  95 +// bannerNext.setChannelId(channelId);
  96 +// bannerService.copyBannerNext(bannerNext);
  97 +// }
  98 +// }
  99 +// bf.close();
  100 +// fr.close();
  101 +// } catch (IOException e) {
  102 +// e.printStackTrace();
  103 +// }
  104 +//
  105 +// return new BaseDto();
  106 +// }
  107 +//}
... ...
src/main/java/com/sincere/wechatbusiness/controller/TokenController.java 0 → 100644
... ... @@ -0,0 +1,91 @@
  1 +package com.sincere.wechatbusiness.controller;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.sincere.wechatbusiness.model.AccessToken;
  5 +import com.sincere.wechatbusiness.model.Token;
  6 +import com.sincere.wechatbusiness.service.ChannelService;
  7 +import io.swagger.annotations.ApiOperation;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.web.bind.annotation.RequestMapping;
  10 +import org.springframework.web.bind.annotation.RequestMethod;
  11 +import org.springframework.web.bind.annotation.RestController;
  12 +
  13 +import java.io.IOException;
  14 +import java.io.InputStream;
  15 +import java.net.HttpURLConnection;
  16 +import java.net.MalformedURLException;
  17 +import java.net.URL;
  18 +import java.util.Calendar;
  19 +import java.util.Date;
  20 +
  21 +@RestController
  22 +public class TokenController {
  23 +
  24 + @Autowired
  25 + ChannelService channelService ;
  26 +
  27 + @ApiOperation(value = "获取分享token")
  28 + @RequestMapping(value = "getToken",method = RequestMethod.GET)
  29 + public String getToken(){
  30 + AccessToken accessToken=channelService.getAccessToken();
  31 + Token token=new Token();
  32 + if(accessToken!=null) {
  33 + Calendar dateOne=Calendar.getInstance();
  34 + Calendar dateTwo=Calendar.getInstance();
  35 + dateOne.setTime(new Date());
  36 + dateTwo.setTime(accessToken.getCreateTime());
  37 + long timeOne=dateOne.getTimeInMillis();
  38 + long timeTwo=dateTwo.getTimeInMillis();
  39 + long minute=(timeOne-timeTwo)/(1000*60);
  40 +
  41 + if(minute<60) token.setAccess_token(accessToken.getAccessToken());
  42 + else{
  43 + token=getAccessToken("wx6078ff3f67524996","8a0465b8ad0f000f568f48853e2818c8");
  44 + accessToken.setAccessToken(token.getAccess_token());
  45 + channelService.insertAccessToken(accessToken);
  46 + }
  47 + }
  48 + else {
  49 + token=getAccessToken("wx6078ff3f67524996","8a0465b8ad0f000f568f48853e2818c8");
  50 + accessToken=new AccessToken();
  51 + accessToken.setAccessToken(token.getAccess_token());
  52 + channelService.insertAccessToken(accessToken);
  53 + }
  54 + return accessToken.getAccessToken() ;
  55 + }
  56 +
  57 + public Token getAccessToken(String appID, String appScret) {
  58 + Token token = new Token();
  59 + String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret="
  60 + + appScret;
  61 + try {
  62 + URL getUrl=new URL(url);
  63 + HttpURLConnection http=(HttpURLConnection)getUrl.openConnection();
  64 + http.setRequestMethod("GET");
  65 + http.setRequestProperty("Content-Type",
  66 + "application/x-www-form-urlencoded");
  67 + http.setDoOutput(true);
  68 + http.setDoInput(true);
  69 +
  70 +
  71 + http.connect();
  72 + InputStream is = http.getInputStream();
  73 + int size = is.available();
  74 + byte[] b = new byte[size];
  75 + is.read(b);
  76 +
  77 + String message = new String(b, "UTF-8");
  78 + JSONObject json = JSONObject.parseObject(message);
  79 +
  80 +
  81 + token.setAccess_token(json.getString("access_token"));
  82 + token.setExpires_in(new Integer(json.getString("expires_in")));
  83 + } catch (MalformedURLException e) {
  84 + e.printStackTrace();
  85 + } catch (IOException e) {
  86 + e.printStackTrace();
  87 + }
  88 + return token;
  89 + }
  90 +
  91 +}
... ...
src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java
... ... @@ -8,6 +8,8 @@ import java.util.List;
8 8  
9 9 public interface ChannelMapper {
10 10  
  11 + Channel getByName(String name);
  12 +
11 13 List<Channel> getListByTemplate(int templateId);
12 14  
13 15 List<Channel> getList(Channel channel);
... ...
src/main/java/com/sincere/wechatbusiness/mapper/ChannelProductMapper.java
1 1 package com.sincere.wechatbusiness.mapper;
2 2  
3 3 import com.sincere.wechatbusiness.model.ChannelProduct;
  4 +import org.apache.ibatis.annotations.Param;
4 5  
5 6 import java.util.List;
6 7  
... ... @@ -16,4 +17,6 @@ public interface ChannelProductMapper {
16 17 ChannelProduct getDetail(int id);
17 18  
18 19 int updateChannelProductMsg(ChannelProduct channelProduct);
  20 +
  21 + int updateProductOpenAddress(@Param("openAddress") int openAddress , @Param("id") int id);
19 22 }
... ...
src/main/java/com/sincere/wechatbusiness/model/ChannelProduct.java
... ... @@ -32,6 +32,16 @@ public class ChannelProduct {
32 32 private String channelRequire ;
33 33 private String channelExplain ;
34 34  
  35 + private int openAddress ;
  36 +
  37 + public int getOpenAddress() {
  38 + return openAddress;
  39 + }
  40 +
  41 + public void setOpenAddress(int openAddress) {
  42 + this.openAddress = openAddress;
  43 + }
  44 +
35 45 public String getChannelTitle() {
36 46 return channelTitle;
37 47 }
... ...
src/main/java/com/sincere/wechatbusiness/service/ChannelProductService.java
1 1 package com.sincere.wechatbusiness.service;
2 2  
3 3 import com.sincere.wechatbusiness.model.ChannelProduct;
  4 +import org.apache.ibatis.annotations.Param;
4 5  
5 6 import java.util.List;
6 7  
... ... @@ -16,4 +17,6 @@ public interface ChannelProductService {
16 17 ChannelProduct getDetail(int id);
17 18  
18 19 int updateChannelProductMsg(ChannelProduct channelProduct);
  20 +
  21 + int updateProductOpenAddress(int openAddress ,int id);
19 22 }
... ...
src/main/java/com/sincere/wechatbusiness/service/impl/ChannelProductServiceImpl.java
... ... @@ -32,4 +32,9 @@ public class ChannelProductServiceImpl implements ChannelProductService {
32 32 public int updateChannelProductMsg(ChannelProduct channelProduct) {
33 33 return channelProductMapper.updateChannelProductMsg(channelProduct);
34 34 }
  35 +
  36 + @Override
  37 + public int updateProductOpenAddress(int openAddress, int id) {
  38 + return channelProductMapper.updateProductOpenAddress(openAddress,id);
  39 + }
35 40 }
... ...
src/main/resources/mapper/BannerMapper.xml
... ... @@ -43,7 +43,7 @@
43 43 update banner set state=0 where id = #{id}
44 44 </update>
45 45  
46   - <update id="deleteChannelBanner" parameterType="java.lang.Integer">
47   - update banner set state=0 where channelId = #{channelId}
48   - </update>
  46 + <delete id="deleteChannelBanner" parameterType="java.lang.Integer">
  47 + delete banner where channelId = #{channelId}
  48 + </delete>
49 49 </mapper>
50 50 \ No newline at end of file
... ...
src/main/resources/mapper/ChannelMapper.xml
... ... @@ -16,6 +16,10 @@
16 16 <result column="city_code" jdbcType="VARCHAR" property="cityCode" />
17 17 </resultMap>
18 18  
  19 + <select id="getByName" parameterType="java.lang.String" resultMap="ChannelMap">
  20 + select * from channel where name = #{name} and state = 1
  21 + </select>
  22 +
19 23 <resultMap id="AreaMap" type="com.sincere.wechatbusiness.model.Area">
20 24 <result column="value" jdbcType="VARCHAR" property="value" />
21 25 <result column="label" jdbcType="VARCHAR" property="label" />
... ...
src/main/resources/mapper/ChannelProductMapper.xml
... ... @@ -19,7 +19,7 @@
19 19 <result column="channel_require" jdbcType="VARCHAR" property="channelRequire" />
20 20 <result column="channel_explain" jdbcType="VARCHAR" property="channelExplain" />
21 21 <result column="title" jdbcType="VARCHAR" property="title" />
22   -
  22 + <result column="open_address" jdbcType="INTEGER" property="openAddress"/>
23 23 </resultMap>
24 24  
25 25 <select id="getList" parameterType="java.lang.Integer" resultMap="ChannelProductMap">
... ... @@ -61,6 +61,10 @@
61 61 where id = #{id}
62 62 </update>
63 63  
  64 + <update id="updateProductOpenAddress">
  65 + update channel_product set open_address=#{openAddress} where id=#{id}
  66 + </update>
  67 +
64 68 <update id="deleteChannelProduct" parameterType="java.lang.Integer">
65 69 update channel_product set state=0 where channelId=#{id}
66 70 </update>
... ...