package com.yeshi.fanli.controller.client.v1;
|
|
import java.io.PrintWriter;
|
import java.io.UnsupportedEncodingException;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.yeshi.utils.JsonUtil;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.yeshi.fanli.entity.accept.AcceptData;
|
import com.yeshi.fanli.entity.bus.help.AppPageNotification;
|
import com.yeshi.fanli.service.inter.help.AppPageNotificationService;
|
import com.yeshi.fanli.service.manger.AppUpdateManager;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.VersionUtil;
|
|
@Controller
|
@RequestMapping("api/v1/help")
|
public class HelpController {
|
|
@Resource
|
private AppPageNotificationService appPageNotificationService;
|
|
@Resource
|
private AppUpdateManager appUpdateManager;
|
|
/**
|
* 获取app页面的通知
|
*
|
* @param acceptData
|
* @param type
|
* @param out
|
*/
|
@RequestMapping(value = "getAppPageNotification")
|
public void getAppPageNotification(AcceptData acceptData, String type, PrintWriter out) {
|
if (StringUtil.isNullOrEmpty(type)) {
|
out.print(JsonUtil.loadFalseResult(1, "请上传类型"));
|
return;
|
}
|
|
String platform = acceptData.getPlatform();
|
String version = acceptData.getVersion();
|
|
AppPageNotification ap = appPageNotificationService.getValidNotificationByTypeCache(type, platform,
|
Integer.parseInt(version));
|
if ("home".equalsIgnoreCase(type) && VersionUtil.smallerThan_1_5_1(platform, version) && ap != null) {
|
AppPageNotification no = new AppPageNotification();
|
no.setContentUrl("");
|
no.setMd5("111111111111111111");
|
no.setPageName(ap.getPageName());
|
no.setShow(true);
|
no.setType(ap.getType());
|
no.setUpdateTime(ap.getUpdateTime());
|
no.setCanClose(false);
|
no.setContent(String.format("尊敬的用户,为更加准确高效的为你返利、省钱,请升级到%s最新版本", Constant.getAppName(platform, version)));
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
out.print(JsonUtil.loadTrueResult(gson.toJson(no)));
|
return;
|
}
|
|
// 没有通知
|
if (ap == null || !ap.getShow()) {
|
out.print(JsonUtil.loadFalseResult(2, "无通知"));
|
} else {// 有通知
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
out.print(JsonUtil.loadTrueResult(gson.toJson(ap)));
|
}
|
}
|
|
@RequestMapping(value = "updateApp")
|
public void updateApp(AcceptData acceptData, PrintWriter out) {
|
if (Constant.IS_TEST)
|
acceptData.setVersion("20");
|
String result = appUpdateManager.getUpdateInfoCache(acceptData);
|
try {
|
out.print(new String(result.getBytes("ISO-8859-1"), "UTF-8"));
|
} catch (UnsupportedEncodingException e) {
|
out.print(result);
|
}
|
}
|
|
}
|