Administrator
2018-10-30 7bf6a0582c7c62c90ee2ed8a88654f11d0479092
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.yeshi.fanli.controller.admin;
 
import java.io.PrintWriter;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.push.PushRecordService;
import com.yeshi.fanli.service.inter.push.PushService;
import com.yeshi.fanli.service.inter.user.AccountMessageService;
import com.yeshi.fanli.service.inter.user.SystemZnxService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.IOSPushFactory;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.JsonUtil;
 
import net.sf.json.JSONObject;
 
@Controller(value = "adminPushController")
@RequestMapping("admin/new/api/v1/push")
public class PushController {
 
    public final static int GOODS = 1; // 商品推送
    public final static int URL = 2; // 网页推送
    public final static int DETAIL = 3; // 详情推送
    public final static int ZNX = 4; // 站内推送
 
    @Resource
    private PushRecordService pushRecordService;
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private SystemZnxService systemZnxService;
 
    @Resource
    private AccountMessageService accountMessageService;
 
    @Resource
    private SystemService systemService;
 
    @Resource
    private PushService pushService;
 
    /**
     * 商品推送
     * 
     * @param uId
     *            -用户ID 可为空
     * @param url
     *            -商品链接
     * @param title
     *            -推送标题
     * @param content
     *            -推送内容
     * @param out
     * @throws Exception
     */
    @RequestMapping(value = "pushGoodsAll_f", method = RequestMethod.POST)
    public void pushGoods(Long uId, String url, String title, String content, PrintWriter out) throws Exception {
        String auctionId = null;
        if (!StringUtil.isNullOrEmpty(url) && url.contains("id=")) {
            String[] sts = url.split("\\?")[1].split("&");
            for (String st : sts)
                if (st.contains("id=")) {
                    auctionId = st.replace("id=", "");
                }
        }
 
        if (StringUtil.isNullOrEmpty(auctionId)) {
            out.print(JsonUtil.loadFalseResult("提取商品ID失败"));
            return;
        }
 
        JSONObject json = IOSPushFactory.createGoodsPush(Long.parseLong(auctionId), title, content);
        if (json.toString().getBytes().length > 256) {
            out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
            return;
        }
 
        pushService.pushGoods(uId, url, title, content);
        out.print(JsonUtil.loadTrueResult("推送成功"));
    }
 
    /**
     * 网页推送
     * 
     * @param url
     * @param title
     * @param content
     * @param out
     * @throws Exception
     */
    @RequestMapping(value = "pushUrlAll_f", method = RequestMethod.POST)
    public void pushUrl(String url, String title, String content, PrintWriter out) throws Exception {
        if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
            out.print(JsonUtil.loadFalseResult("请填写链接,标题与内容"));
            return;
        }
 
        JSONObject json = IOSPushFactory.createURLPush(HttpUtil.getShortLink(url), title, content);
        if (json.toString().getBytes().length > 256) {
            out.print(JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
            return;
        }
        pushService.pushUrl(null, url, title, content);
        out.print(JsonUtil.loadTrueResult("推送成功"));
    }
 
    /**
     * 
     * 方法说明: 站内信推送
     * 
     * @author mawurui createTime 2018年3月12日 下午5:45:00
     * @param uId
     * @param title
     * @param content
     * @throws Exception
     */
    @RequestMapping(value = "pushFanZNX_f", method = RequestMethod.POST)
    public void pushSystemZnx(Long uId, String title, String content, PrintWriter out) throws Exception {
        pushService.pushZNX(uId, title, content);
        out.print(JsonUtil.loadTrueResult("推送成功"));
    }
 
    /**
     * 短链接转换
     * 
     * @param url
     * @param out
     * @throws Exception
     */
    @RequestMapping(value = "convertLink", method = RequestMethod.POST)
    public void convertLink(String url, PrintWriter out) throws Exception {
 
        String shortLink = org.yeshi.utils.HttpUtil.getShortLink(url);
 
        JSONObject jsonData = new JSONObject();
        jsonData.put("url", url);
        jsonData.put("shortLink", shortLink);
 
        out.print(JsonUtil.loadTrueResult(jsonData));
 
    }
 
}