ContentAction.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package net.mingsoft.cms.action;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import net.mingsoft.base.entity.ResultData;
  6. import org.springframework.validation.BindingResult;
  7. import org.apache.shiro.authz.annotation.RequiresPermissions;
  8. import org.springframework.ui.ModelMap;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.web.bind.annotation.ModelAttribute;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.ResponseBody;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.RequestBody;
  17. import net.mingsoft.cms.biz.IContentBiz;
  18. import net.mingsoft.cms.entity.ContentEntity;
  19. import net.mingsoft.base.entity.BaseEntity;
  20. import net.mingsoft.basic.util.BasicUtil;
  21. import net.mingsoft.basic.util.StringUtil;
  22. import net.mingsoft.basic.bean.EUListBean;
  23. import net.mingsoft.basic.annotation.LogAnn;
  24. import net.mingsoft.basic.constant.e.BusinessTypeEnum;
  25. import io.swagger.annotations.Api;
  26. import io.swagger.annotations.ApiImplicitParam;
  27. import io.swagger.annotations.ApiImplicitParams;
  28. import io.swagger.annotations.ApiOperation;
  29. import springfox.documentation.annotations.ApiIgnore;
  30. /**
  31. * 文章管理控制层
  32. * @author 铭飞开发团队
  33. * 创建日期:2019-11-28 15:12:32<br/>
  34. * 历史修订:<br/>
  35. */
  36. @Api(value = "文章接口")
  37. @Controller("cmsContentAction")
  38. @RequestMapping("/${ms.manager.path}/cms/content")
  39. public class ContentAction extends BaseAction{
  40. /**
  41. * 注入文章业务层
  42. */
  43. @Autowired
  44. private IContentBiz contentBiz;
  45. /**
  46. * 返回主界面index
  47. */
  48. @GetMapping("/index")
  49. public String index(HttpServletResponse response,HttpServletRequest request){
  50. return "/cms/content/index";
  51. }
  52. /**
  53. * 返回主界面main
  54. */
  55. @GetMapping("/main")
  56. public String main(HttpServletResponse response,HttpServletRequest request){
  57. return "/cms/content/main";
  58. }
  59. /**
  60. * 查询文章列表
  61. * @param content 文章实体
  62. */
  63. @ApiOperation(value = "查询文章列表接口")
  64. @ApiImplicitParams({
  65. @ApiImplicitParam(name = "contentTitle", value = "文章标题", required =false,paramType="query"),
  66. @ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
  67. @ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
  68. @ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
  69. @ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
  70. @ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
  71. @ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =false,paramType="query"),
  72. @ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
  73. @ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
  74. @ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
  75. @ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
  76. @ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
  77. @ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
  78. @ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
  79. @ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
  80. @ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
  81. @ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
  82. @ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
  83. @ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
  84. @ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
  85. })
  86. @RequestMapping("/list")
  87. @ResponseBody
  88. public ResultData list(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
  89. content.setAppId(BasicUtil.getAppId());
  90. BasicUtil.startPage();
  91. List contentList = contentBiz.query(content);
  92. return ResultData.build().success(new EUListBean(contentList,(int)BasicUtil.endPage(contentList).getTotal()));
  93. }
  94. /**
  95. * 返回编辑界面content_form
  96. */
  97. @GetMapping("/form")
  98. public String form(@ModelAttribute ContentEntity content,HttpServletResponse response,HttpServletRequest request,ModelMap model){
  99. if(content.getId()!=null){
  100. BaseEntity contentEntity = contentBiz.getEntity(Integer.parseInt(content.getId()));
  101. model.addAttribute("contentEntity",contentEntity);
  102. }
  103. return "/cms/content/form";
  104. }
  105. /**
  106. * 获取文章
  107. * @param content 文章实体
  108. */
  109. @ApiOperation(value = "获取文章列表接口")
  110. @ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
  111. @GetMapping("/get")
  112. @ResponseBody
  113. public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
  114. if(content.getId()==null) {
  115. return ResultData.build().error();
  116. }
  117. content.setAppId(BasicUtil.getAppId());
  118. ContentEntity _content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
  119. return ResultData.build().success(_content);
  120. }
  121. @ApiOperation(value = "保存文章列表接口")
  122. @ApiImplicitParams({
  123. @ApiImplicitParam(name = "contentTitle", value = "文章标题", required =true,paramType="query"),
  124. @ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
  125. @ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
  126. @ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
  127. @ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
  128. @ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
  129. @ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =true,paramType="query"),
  130. @ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
  131. @ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
  132. @ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
  133. @ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
  134. @ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
  135. @ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
  136. @ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
  137. @ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
  138. @ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
  139. @ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
  140. @ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
  141. @ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
  142. @ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
  143. })
  144. /**
  145. * 保存文章
  146. * @param content 文章实体
  147. */
  148. @PostMapping("/save")
  149. @ResponseBody
  150. @LogAnn(title = "保存文章", businessType = BusinessTypeEnum.INSERT)
  151. @RequiresPermissions("cms:content:save")
  152. public ResultData save(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response, HttpServletRequest request) {
  153. //验证文章标题的值是否合法
  154. if(StringUtil.isBlank(content.getContentTitle())){
  155. return ResultData.build().error(getResString("err.empty", this.getResString("content.title")));
  156. }
  157. if(!StringUtil.checkLength(content.getContentTitle()+"", 0, 200)){
  158. return ResultData.build().error(getResString("err.length", this.getResString("content.title"), "0", "200"));
  159. }
  160. if(!StringUtil.checkLength(content.getContentAuthor()+"", 0, 200)){
  161. return ResultData.build().error(getResString("err.length", this.getResString("content.author"), "0", "200"));
  162. }
  163. if(!StringUtil.checkLength(content.getContentSource()+"", 0, 200)){
  164. return ResultData.build().error(getResString("err.length", this.getResString("content.source"), "0", "200"));
  165. }
  166. //验证发布时间的值是否合法
  167. if(StringUtil.isBlank(content.getContentDatetime())){
  168. return ResultData.build().error(getResString("err.empty", this.getResString("content.datetime")));
  169. }
  170. if(!StringUtil.checkLength(content.getContentUrl()+"", 0, 200)){
  171. return ResultData.build().error(getResString("err.length", this.getResString("content.url"), "0", "200"));
  172. }
  173. content.setAppId(BasicUtil.getAppId());
  174. contentBiz.saveEntity(content);
  175. return ResultData.build().success(content);
  176. }
  177. /**
  178. * @param content 文章实体
  179. */
  180. @ApiOperation(value = "批量删除文章列表接口")
  181. @PostMapping("/delete")
  182. @ResponseBody
  183. @LogAnn(title = "删除文章", businessType = BusinessTypeEnum.DELETE)
  184. @RequiresPermissions("cms:content:del")
  185. public ResultData delete(@RequestBody List<ContentEntity> contents,HttpServletResponse response, HttpServletRequest request) {
  186. int[] ids = new int[contents.size()];
  187. for(int i = 0;i<contents.size();i++){
  188. ids[i] =Integer.parseInt(contents.get(i).getId()) ;
  189. }
  190. contentBiz.delete(ids);
  191. return ResultData.build().success();
  192. }
  193. /**
  194. * 更新文章列表
  195. * @param content 文章实体
  196. */
  197. @ApiOperation(value = "更新文章列表接口")
  198. @ApiImplicitParams({
  199. @ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query"),
  200. @ApiImplicitParam(name = "contentTitle", value = "文章标题", required =true,paramType="query"),
  201. @ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
  202. @ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
  203. @ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
  204. @ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
  205. @ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
  206. @ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =true,paramType="query"),
  207. @ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
  208. @ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
  209. @ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
  210. @ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
  211. @ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
  212. @ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
  213. @ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
  214. @ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
  215. @ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
  216. @ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
  217. @ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
  218. @ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
  219. @ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
  220. })
  221. @PostMapping("/update")
  222. @ResponseBody
  223. @LogAnn(title = "更新文章", businessType = BusinessTypeEnum.UPDATE)
  224. @RequiresPermissions("cms:content:update")
  225. public ResultData update(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response,
  226. HttpServletRequest request) {
  227. //验证文章标题的值是否合法
  228. if(StringUtil.isBlank(content.getContentTitle())){
  229. return ResultData.build().error(getResString("err.empty", this.getResString("content.title")));
  230. }
  231. if(!StringUtil.checkLength(content.getContentTitle()+"", 0, 200)){
  232. return ResultData.build().error(getResString("err.length", this.getResString("content.title"), "0", "200"));
  233. }
  234. if(!StringUtil.checkLength(content.getContentAuthor()+"", 0, 200)){
  235. return ResultData.build().error(getResString("err.length", this.getResString("content.author"), "0", "200"));
  236. }
  237. if(!StringUtil.checkLength(content.getContentSource()+"", 0, 200)){
  238. return ResultData.build().error(getResString("err.length", this.getResString("content.source"), "0", "200"));
  239. }
  240. //验证发布时间的值是否合法
  241. if(StringUtil.isBlank(content.getContentDatetime())){
  242. return ResultData.build().error(getResString("err.empty", this.getResString("content.datetime")));
  243. }
  244. if(!StringUtil.checkLength(content.getContentUrl()+"", 0, 200)){
  245. return ResultData.build().error(getResString("err.length", this.getResString("content.url"), "0", "200"));
  246. }
  247. content.setAppId(BasicUtil.getAppId());
  248. contentBiz.updateEntity(content);
  249. return ResultData.build().success(content);
  250. }
  251. }