package com.matrix.system.shopXcx.api.action; import com.matrix.core.pojo.AjaxResult; import com.matrix.system.shopXcx.bean.*; import com.matrix.system.shopXcx.dao.ShopArticleDao; import com.matrix.system.shopXcx.dao.ShopArticleTypeDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.*; /** * @description 文章 * @author jiangyouyao * @date 2019-06-11 10:15 */ @CrossOrigin(origins = "*", maxAge = 3600) @Controller @RequestMapping(value = "wxapi/Article") public class WxArticleAction { @Autowired private ShopArticleTypeDao articleTypeDao; @Autowired private ShopArticleDao articleDao; /** * 查询常见问题文章类型接口 * @param * @return */ @PostMapping("/findArticleType") @ResponseBody public AjaxResult getArticleByTypeCode() { List shopArticleTypes = articleTypeDao.selectByTypeCode(); AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, shopArticleTypes, shopArticleTypes.size()); return result; } /** * 根据类型code查询类型文章 * @param * @return */ @PostMapping("/findArticleByArtypeCode/{artypeCode}") @ResponseBody public AjaxResult getArticleByArtypeCode(@PathVariable("artypeCode") String artypeCode) { List shopArticles = articleDao.selectArticleByArtypeCode(artypeCode); AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, shopArticles); return result; } /** * 根据标题和类型查询文章接口 * @param * @return */ @PostMapping("/findArticleByTitleAndType") @ResponseBody public AjaxResult findArticleByTitleAndType(@RequestBody ShopArticle shopArticle) { List shopArticles = articleDao.findArticleByTitleAndType(shopArticle); AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, shopArticles); return result; } /** * 根据ID查询文章 * @param * @return */ @PostMapping("/findArticById/{artId}") @ResponseBody public AjaxResult getArticleByArtypeId(@PathVariable("artId") Integer artId) { ShopArticle shopArticles = articleDao.selectById(artId); if(null != shopArticles){ Integer artVisitstimes = shopArticles.getArtVisitstimes(); Map modifyMap = new HashMap<>(); if(null == artVisitstimes){ modifyMap.put("artVisitstimes", 1); }else{ modifyMap.put("artVisitstimes", artVisitstimes+1); } modifyMap.put("artId", artId); articleDao.updateByMap(modifyMap); } AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, Collections.singletonList(shopArticles)); return result; } /** * 查询常见问题类型文章 * @param * @return */ @PostMapping("/findArticle") @ResponseBody public AjaxResult getArticle() { List shopArticles = articleDao.selectArticle(); AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, shopArticles, shopArticles.size()); return result; } }