发表于: 2017-10-23 22:55:16

1 559


今天完成的事情:

1.完成版本管理接口:

代码逻辑比较简单,修改版本信息首先进行非空判断,判断os以及版本号,后面更新版本号时需要高于之前的版本,具体代码如下

/**
* 修改版本信息
* @param request
* @param response
* @param model
* @param article
* @return
*/
@RequestMapping(value = "/a/u/version", method = RequestMethod.PUT)
public String updateVersionInfo(HttpServletRequest request, HttpServletResponse response, ModelMap model,
                       Article article){
log.info("updateVersionInfo   begin");
  if(StringUtil.isEmpty(article.getImg())){
log.info("os info is empty and it's illeal");
     model.addAttribute("code", -1000);
     return "/common/success";
  }
String os = article.getImg().toLowerCase();
  if(StringUtil.isEmpty(article.getTitle())){
log.info("version number is empty and it's illeal");
     model.addAttribute("code", -1000);
     return "/common/success";
  }
/**
   * 安卓版本需要url非空
   */
  if(ANDROID.equals(os)){
log.info("it's android os");
     if(StringUtil.isEmpty(article.getUrl())){
log.info("it's android os and url is empty and it's illegal");
        model.addAttribute("code", -1000);
        return "/common/success";
     }
}
log.info("updateVersionInfo   update article : " + article);
  try {
Article currentArticle = articleService.getObjectById(article.getId());
     Integer result = article.getTitle().compareTo(currentArticle.getTitle());
     if (result < 0){
log.info("version number is lower than old one and it's illegal");
        model.addAttribute("code", -1015);
        return "/common/success";
     } else if (result == 0) {
log.info("version number has not changed and we need update");
        articleService.update(article);
        model.addAttribute("code", 0);
     } else {
log.info("version number has been higer and we need insert the new one and the old one will be keeped");
        article.setId(null);
        articleService.insert(article);
        model.addAttribute("code", 0);
     }
} catch (Throwable t) {
log.error("VersionManager error...", t);
     model.addAttribute("code", -1);
  }
log.info("updateVersionInfo   end");
  return "/common/success";
}

/**
* 版本更新列表
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = "/a/u/version", method = RequestMethod.GET)
public String getVersionInfo(HttpServletRequest request, HttpServletResponse response, ModelMap model){

Map<String, Object> androidParam = DynamicUtil.getVersionListParam(ANDROID, Article.ARTICLE_TYPE_4);
  log.info("getVersionInfo   androidParam :" + androidParam);
  Map<String, Object> iosParam = DynamicUtil.getVersionListParam(IOS, Article.ARTICLE_TYPE_4);
  log.info("getVersionInfo   iosParam :" + iosParam);


  try {
List<Long> androidIdList = articleService.getIdsByDynamicCondition(Article.class, androidParam, 0, Integer.MAX_VALUE);
     log.info("getVersionInfo   androidIdList :" + androidIdList);
     List<Long> iosIdList = articleService.getIdsByDynamicCondition(Article.class, iosParam, 0, Integer.MAX_VALUE);
     log.info("getVersionInfo   iosIdList :" + iosIdList);
     List<Article> androidList = articleService.getObjectsByIds(androidIdList);
     log.info("getVersionInfo   androidList :" + androidList);
     List<Article> iosList = articleService.getObjectsByIds(iosIdList);
     log.info("getVersionInfo   iosList :" + iosList);
     Article android = androidList.get(0);
     log.info("getVersionInfo   android :" + android);
     Article ios = iosList.get(0);
          log.info("getVersionInfo   ios :" + ios);

     List<Article> list = new ArrayList<Article>();
     list.add(android);
     list.add(ios);
     model.addAttribute("code", 0);
     model.addAttribute("list", list);
  } catch (Throwable t) {
log.error("VersionManager error...", t);
     model.addAttribute("code", -1);
  }

return "/playboy-pub-service/article/json/versionListJson";
}

/**
* 发布或取消发布
*
* @param request
* @param response
* @param model
* @param
* @param aid
* @return
* @throws Exception
*/
@RequestMapping(value = "/a/u/article/{aid}/status", method = RequestMethod.POST)
public String updateArticleJson(HttpServletRequest request, HttpServletResponse response, ModelMap model,
                       @PathVariable Long aid) throws Exception {
if (aid == null) {
model.addAttribute("code", -1000);
     log.info("put article error aid is null");
     return "common/success";
  }
Article article = articleService.getObjectById(aid);
  Integer status = article.getStatus();
  log.info("update article status : article id ,status = " + aid + " , " + status);

  try {

Manager manager = (Manager) request.getAttribute("manager");
     Long userId = manager.getId();
     article.setUpdateBy(userId);
     log.info("article is  " + article);
     if (Article.Status_Unpublished.equals(status)) {
log.info("change strtus4");
        Long time = System.currentTimeMillis();
        article.setStatus(Article.Status_Published);// 取消发布
        article.setPublishat(time);
     } else {
log.info("change strtus5");

        article.setStatus(Article.Status_Unpublished);// 发布内容

     }
articleService.update(article);
     model.addAttribute("code", 0);

  } catch (Throwable t) {
t.printStackTrace();
     log.error(t.getMessage());
     log.error("update article error,id is  " + aid);
     model.addAttribute("code", -1);

  }

return "common/success";
}

明天计划的事情:完成投资详情接口

遇到的问题:无

收获:以上


返回列表 返回列表
评论

    分享到