喻健
2018-11-13 6feaf1324e207ebee22d0e263a8f32061b8374bf
推送迁移
2个文件已修改
153 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushRecordAdminController.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java
@@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.yeshi.fanli.exception.PushException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.push.PushRecordService;
@@ -16,6 +17,7 @@
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;
@@ -149,4 +151,111 @@
    }
    /**
     * 商品推送  -(新后台)
     *
     * @param uId
     *            -用户ID 可为空
     * @param url
     *            -商品链接
     * @param title
     *            -推送标题
     * @param content
     *            -推送内容
     * @param out
     * @throws Exception
     */
    @RequestMapping(value = "newPushGoodsAll")
    public void newPushGoodsAll(String callback, 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)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("提取商品ID失败"));
            return;
        }
        JSONObject json = IOSPushFactory.createGoodsPush(Long.parseLong(auctionId), title, content);
        if (json.toString().getBytes().length > 256) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
            return;
        }
        try {
            pushService.pushGoods(uid, url, title, content);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("推送失败"));
            e.printStackTrace();
        }
    }
    /**
     * 网页推送 -(新后台)
     *
     * @param url
     * @param title
     * @param content
     * @param out
     * @throws Exception
     */
    @RequestMapping(value = "newPushUrlAll")
    public void newPushUrlAll(String callback, String url, String title, String content, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请填写链接,标题与内容"));
            return;
        }
        JSONObject json = IOSPushFactory.createURLPush(HttpUtil.getShortLink(url), title, content);
        if (json.toString().getBytes().length > 256) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("标题或内容过长,请删减后再试"));
            return;
        }
        try {
            pushService.pushUrl(null, url, title, content);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
        } catch (PushException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("推送失败"));
            e.printStackTrace();
        }
    }
    /**
     *
     * 方法说明: 站内信推送 -(新后台)
     *
     * @param uId
     * @param title
     * @param content
     * @throws Exception
     */
    @RequestMapping(value = "newPushFanZNX")
    public void newPushFanZNX(String callback, Long uid, String title, String content, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请填写标题与内容"));
            return;
        }
        try {
            pushService.pushZNX(uid, title, content);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("推送成功"));
        } catch (PushException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("推送失败"));
            e.printStackTrace();
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/controller/admin/PushRecordAdminController.java
@@ -13,6 +13,7 @@
import com.yeshi.fanli.service.inter.push.PushRecordService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import org.yeshi.utils.JsonUtil;
import net.sf.json.JSONObject;
@@ -36,4 +37,47 @@
        out.print(JsonUtil.loadTrueResult(data));
    }
    
    /**
     * 推荐记录 -(新后台)
     * @param callback
     * @param key
     * @param type
     * @param pageIndex
     * @param out
     */
    @RequestMapping(value = "getNewPushRecordList")
    public void getNewPushRecordList(String callback, String key, Integer type, Integer pageIndex, PrintWriter out){
        try {
            if (pageIndex == null || pageIndex < 0){
                pageIndex = 1;
            }
            if (type == null) {
                type = 0;
            }
            List<PushRecord> list = pushRecordService.getPushRecordList(key, type, pageIndex);
            if (list == null || list.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无更多数据"));
                return;
            }
            int count = pushRecordService.getCount(key, type, pageIndex);
            PageEntity pe = new PageEntity(pageIndex, Constant.PAGE_SIZE, count);
            JSONObject data = new JSONObject();
            data.put("pe", pe);
            data.put("result_list", list);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
            e.printStackTrace();
        }
    }
}