ArticleAction.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /**
  2. The MIT License (MIT) * Copyright (c) 2016 铭飞科技(mingsoft.net)
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. * this software and associated documentation files (the "Software"), to deal in
  5. * the Software without restriction, including without limitation the rights to
  6. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  7. * the Software, and to permit persons to whom the Software is furnished to do so,
  8. * subject to the following conditions:
  9. * The above copyright notice and this permission notice shall be included in all
  10. * copies or substantial portions of the Software.
  11. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  13. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  14. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  15. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. */
  18. package net.mingsoft.cms.action;
  19. import java.io.File;
  20. import java.sql.Timestamp;
  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import org.apache.commons.lang3.StringUtils;
  29. import org.apache.shiro.authz.annotation.RequiresPermissions;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.beans.factory.annotation.Value;
  32. import org.springframework.stereotype.Controller;
  33. import org.springframework.ui.ModelMap;
  34. import org.springframework.web.bind.annotation.ModelAttribute;
  35. import org.springframework.web.bind.annotation.PathVariable;
  36. import org.springframework.web.bind.annotation.RequestBody;
  37. import org.springframework.web.bind.annotation.RequestMapping;
  38. import com.alibaba.fastjson.JSONArray;
  39. import net.mingsoft.base.entity.BaseEntity;
  40. import net.mingsoft.base.filter.DateValueFilter;
  41. import net.mingsoft.base.filter.DoubleValueFilter;
  42. import net.mingsoft.basic.action.BaseAction;
  43. import net.mingsoft.basic.bean.EUListBean;
  44. import net.mingsoft.basic.biz.IColumnBiz;
  45. import net.mingsoft.basic.entity.ColumnEntity;
  46. import net.mingsoft.basic.util.ArrysUtil;
  47. import net.mingsoft.basic.util.BasicUtil;
  48. import net.mingsoft.basic.util.FileUtil;
  49. import net.mingsoft.basic.util.StringUtil;
  50. import net.mingsoft.cms.biz.IArticleBiz;
  51. import net.mingsoft.cms.constant.ModelCode;
  52. import net.mingsoft.cms.constant.e.ColumnTypeEnum;
  53. import net.mingsoft.cms.entity.ArticleEntity;
  54. import net.mingsoft.mdiy.biz.IContentModelBiz;
  55. import net.mingsoft.mdiy.biz.IContentModelFieldBiz;
  56. import net.mingsoft.mdiy.entity.ContentModelEntity;
  57. import net.mingsoft.mdiy.entity.ContentModelFieldEntity;
  58. import net.mingsoft.mdiy.util.DictUtil;
  59. import net.mingsoft.mdiy.util.ParserUtil;
  60. /**
  61. * @ClassName: ArticleAction
  62. * @Description:TODO 文章管理
  63. * @author: 铭飞开发团队
  64. * @date: 2018年1月31日 下午2:51:39
  65. *
  66. * @Copyright: 2018 www.mingsoft.net Inc. All rights reserved.
  67. */
  68. @Controller
  69. @RequestMapping("/${ms.manager.path}/cms/article")
  70. public class ArticleAction extends BaseAction {
  71. /**
  72. * 上传路径
  73. */
  74. @Value("${ms.upload.path}")
  75. private String uploadFloderPath;
  76. /**
  77. * 业务层的注入
  78. */
  79. @Autowired
  80. private IColumnBiz columnBiz;
  81. /**
  82. * 文章管理业务处理层
  83. */
  84. @Autowired
  85. private IArticleBiz articleBiz;
  86. /**
  87. * 字段管理业务层
  88. */
  89. @Autowired
  90. private IContentModelFieldBiz fieldBiz;
  91. /**
  92. * 内容管理业务层
  93. */
  94. @Autowired
  95. private IContentModelBiz contentBiz;
  96. /**
  97. * 判断是否为checkbox类型
  98. */
  99. private static final int checkBox = 11;
  100. /**
  101. * 加载页面显示所有文章信息
  102. *
  103. * @param request
  104. * @return 返回文章页面显示地址
  105. */
  106. @SuppressWarnings("static-access")
  107. @RequestMapping("/index")
  108. public String index(HttpServletRequest request, ModelMap mode, HttpServletResponse response) {
  109. // 获取站点id
  110. int appId = BasicUtil.getAppId();
  111. List<ColumnEntity> list = columnBiz.queryAll(appId, this.getModelCodeId(request, ModelCode.CMS_COLUMN));
  112. request.setAttribute("listColumn", JSONArray.toJSONString(list));
  113. // 返回路径
  114. return "/cms/article/index"; // 这里表示显示/manager/cms/article/article_list.ftl
  115. }
  116. /**
  117. * 返回一个文章列表框架和一些基础数据
  118. * @param article
  119. * @param request
  120. * @param mode
  121. * @param response
  122. * @param categoryId
  123. * @return 返回一个文章列表界面
  124. */
  125. @RequestMapping("/{categoryId}/main")
  126. public String main(@ModelAttribute ArticleEntity article, HttpServletRequest request, ModelMap mode,
  127. HttpServletResponse response, @PathVariable int categoryId) {
  128. String articleType = request.getParameter("articleType");
  129. String isParent = BasicUtil.getString("isParent", "false");
  130. mode.addAttribute("isParent", isParent);
  131. //使用糊涂工具排序使全部属性排在第一个
  132. mode.addAttribute("articleTypeList", DictUtil.list("文章属性"));
  133. mode.addAttribute("articleType", articleType);
  134. mode.addAttribute("categoryId", categoryId);
  135. //返回文章页面显示地址
  136. return "/cms/article/article_main";
  137. }
  138. /**
  139. * 加载页面显示所有文章信息
  140. *
  141. * @param request
  142. * @return 返回文章页面显示数据
  143. */
  144. @RequestMapping("/{categoryId}/list")
  145. public void list(@ModelAttribute ArticleEntity article, HttpServletRequest request, ModelMap mode,
  146. HttpServletResponse response, @PathVariable int categoryId) {
  147. int[] basicCategoryIds = null;
  148. String articleType = article.getArticleType();
  149. if(StringUtils.isEmpty(articleType)){
  150. articleType = BasicUtil.getString("articleTypeStr");
  151. }
  152. if(!StringUtils.isEmpty(articleType) && articleType.equals("a")){
  153. articleType = null;
  154. }
  155. if(categoryId > 0){
  156. basicCategoryIds = columnBiz.queryChildrenCategoryIds(categoryId, BasicUtil.getAppId(),
  157. BasicUtil.getModelCodeId(ModelCode.CMS_COLUMN));
  158. }
  159. int appId = BasicUtil.getAppId();
  160. BasicUtil.startPage();
  161. article.setBasicDisplay(-1);
  162. //查询文章列表
  163. List<ArticleEntity> articleList = articleBiz.query(appId, basicCategoryIds, articleType, null, null, true, null, null, article);
  164. EUListBean _list = new EUListBean(articleList, (int) BasicUtil.endPage(articleList).getTotal());
  165. //将数据以json数据的形式返回
  166. this.outJson(response, net.mingsoft.base.util.JSONArray.toJSONString(_list, new DoubleValueFilter(),new DateValueFilter("yyyy-MM-dd")));
  167. }
  168. /**
  169. * 添加文章页面
  170. *
  171. * @return 保存文章的页面地址
  172. */
  173. @SuppressWarnings("static-access")
  174. @RequestMapping("/add")
  175. public String add(ModelMap mode, HttpServletRequest request) {
  176. int categoryId = BasicUtil.getInt("categoryId", 0);
  177. String categoryTitle = request.getParameter("categoryTitle");
  178. // 文章属性
  179. mode.addAttribute("articleType", DictUtil.list("文章属性"));
  180. // 站点ID
  181. int appId = BasicUtil.getAppId();
  182. List<ColumnEntity> list = columnBiz.queryAll(appId, this.getModelCodeId(request, ModelCode.CMS_COLUMN));
  183. mode.addAttribute("appId", appId);
  184. mode.addAttribute("listColumn", JSONArray.toJSONString(list));
  185. boolean isEditCategory = false; // 新增,不是单篇
  186. int columnType=1;//新增,不是单篇
  187. if(categoryId != 0){
  188. // 获取栏目id
  189. ColumnEntity column = (ColumnEntity) columnBiz.getEntity(categoryId);
  190. columnType = column.getColumnType();
  191. // 判断栏目是否为"",如果是"",就重新赋值
  192. if (StringUtils.isBlank(categoryTitle)) {
  193. categoryTitle = column.getCategoryTitle();
  194. }
  195. // 判断栏目是否是单篇
  196. if (column != null && column.getColumnType() == ColumnTypeEnum.COLUMN_TYPE_COVER.toInt()) {
  197. isEditCategory = true; // 是单页
  198. columnType = column.getColumnType();;
  199. }
  200. }
  201. mode.addAttribute("categoryTitle", categoryTitle);
  202. mode.addAttribute("isEditCategory", isEditCategory); // 新增状态
  203. mode.addAttribute("columnType", columnType);
  204. mode.addAttribute("categoryId", categoryId);
  205. mode.addAttribute("articleImagesUrl", uploadFloderPath+net.mingsoft.base.constant.Const.SEPARATOR
  206. +BasicUtil.getAppId()+net.mingsoft.base.constant.Const.SEPARATOR);
  207. // 添加一个空的article实体
  208. ArticleEntity article = new ArticleEntity();
  209. mode.addAttribute("article", article);
  210. mode.addAttribute("action", "save");
  211. // 返回路径
  212. return "/cms/article/article_form"; // 这里表示显示/manager/cms/article/article_save.ftl
  213. }
  214. /**
  215. * 获取表单信息进行保存
  216. *
  217. * @param article
  218. * 文章对象
  219. */
  220. @RequestMapping("/save")
  221. @RequiresPermissions("article:save")
  222. public void save(@ModelAttribute ArticleEntity article, HttpServletRequest request, HttpServletResponse response) {
  223. // 获取站点id
  224. int appId = BasicUtil.getAppId();
  225. // 验证文章,文章自由排序,栏目id
  226. if (!validateForm(article, response)) {
  227. this.outJson(response, ModelCode.CMS_ARTICLE, false);
  228. }
  229. article.setBasicUpdateTime(new Timestamp(System.currentTimeMillis()));
  230. // 文章类型
  231. String langtyp[] = request.getParameterValues("articleType");
  232. if (langtyp != null) {
  233. StringBuffer sb = new StringBuffer();
  234. for (int j = 0; j < langtyp.length; j++) {
  235. sb.append(langtyp[j] + ",");
  236. }
  237. }
  238. String checkboxType = BasicUtil.getString("checkboxType");
  239. //如果选择一个属性不做排序操作
  240. if(!StringUtils.isEmpty(checkboxType) && checkboxType.length()>2){
  241. // 文章类型排序
  242. article.setArticleType(ArrysUtil.sort(checkboxType, ",")+",");
  243. }else{
  244. article.setArticleType(checkboxType);
  245. }
  246. ColumnEntity column = (ColumnEntity) columnBiz.getEntity(article.getBasicCategoryId());
  247. article.setColumn(column);
  248. // 添加文章所属的站点id
  249. article.setArticleWebId(appId);
  250. // 绑定模块编号
  251. article.setBasicModelId(BasicUtil.getInt("modelId"));
  252. // 保存文章实体
  253. articleBiz.saveBasic(article);
  254. if (column.getColumnType() == ColumnTypeEnum.COLUMN_TYPE_LIST.toInt()) {// 列表
  255. article.setArticleUrl(column.getColumnPath() + File.separator + article.getBasicId() + ParserUtil.HTML_SUFFIX);
  256. } else if (column.getColumnType() == ColumnTypeEnum.COLUMN_TYPE_COVER.toInt()) {// 单篇
  257. article.setArticleUrl(column.getColumnPath() + File.separator + ParserUtil.INDEX+ParserUtil.HTML_SUFFIX);
  258. }
  259. articleBiz.updateBasic(article);
  260. // 判断栏目是否存在新增字段
  261. if (column.getColumnContentModelId() != 0) {
  262. // 保存所有的字段信息
  263. List<ContentModelFieldEntity> listField = fieldBiz.queryListByCmid(column.getColumnContentModelId());
  264. // 获取内容模型实体
  265. ContentModelEntity contentModel = (ContentModelEntity) contentBiz
  266. .getEntity(column.getColumnContentModelId());
  267. if (contentModel != null) {
  268. // 保存新增字段的信息
  269. Map<String, Object> param = this.checkField(listField, request, article.getBasicId());
  270. fieldBiz.insertBySQL(contentModel.getCmTableName(), param);
  271. }
  272. }
  273. //
  274. if (article.getColumn().getColumnType() == ColumnTypeEnum.COLUMN_TYPE_COVER.toInt()) {
  275. this.outJson(response, ModelCode.CMS_ARTICLE, true, "" + article.getColumn().getCategoryId(), article.getBasicId());
  276. } else {
  277. this.outJson(response, ModelCode.CMS_ARTICLE, true, article.getColumn().getCategoryId()+"", "");
  278. }
  279. }
  280. /**
  281. * 验证表单
  282. *
  283. * @param article
  284. * @param response
  285. * @return 返回Boolean类型 true:通过,false:有错
  286. */
  287. public boolean validateForm(ArticleEntity article, HttpServletResponse response) {
  288. // 对表单数据进行再次验证
  289. // 验证文章标题是否为空
  290. if (StringUtils.isBlank(article.getBasicTitle())) {
  291. this.outJson(response, ModelCode.CMS_ARTICLE, false,
  292. getResString("err.empty", this.getResString("basicTitle")));
  293. return false;
  294. }
  295. // 验证文章所属是否为0
  296. if (article.getBasicCategoryId() == 0) {
  297. this.outJson(response, ModelCode.CMS_ARTICLE, false,
  298. getResString("err.empty", this.getResString("basicCategoryId")));
  299. return false;
  300. }
  301. // 验证文章标题长度,若超过定义长度则截取
  302. if (!StringUtil.checkLength(article.getBasicTitle(), 1, 300)) {
  303. this.outJson(response, ModelCode.CMS_ARTICLE, false,
  304. getResString("err.length", this.getResString("basicTitle"), "1", "300"));
  305. return false;
  306. }
  307. // 验证文章来源长度,若超过定义长度则截取
  308. if (!StringUtils.isBlank(article.getArticleSource())
  309. && !StringUtil.checkLength(article.getArticleSource(), 1, 300)) {
  310. this.outJson(response, ModelCode.CMS_ARTICLE, false,
  311. getResString("err.length", this.getResString("articleSource"), "1", "300"));
  312. return false;
  313. }
  314. // 验证文章作者长度,若超过定义长度则截取
  315. if (!StringUtils.isBlank(article.getArticleAuthor())
  316. && !StringUtil.checkLength(article.getArticleAuthor(), 1, 12)) {
  317. this.outJson(response, ModelCode.CMS_ARTICLE, false,
  318. getResString("err.length", this.getResString("articleAuthor"), "1", "12"));
  319. return false;
  320. }
  321. // 验证文章描述长度,若超过定义长度则截取
  322. if (!StringUtils.isBlank(article.getBasicDescription())
  323. && !StringUtil.checkLength(article.getBasicDescription(), 1, 400)) {
  324. this.outJson(response, ModelCode.CMS_ARTICLE, false,
  325. getResString("err.length", this.getResString("basicDescription"), "1", "400"));
  326. return false;
  327. }
  328. // 验证文章关键字长度,若超过定义长度则截取
  329. if (!StringUtils.isBlank(article.getArticleKeyword())
  330. && !StringUtil.checkLength(article.getArticleKeyword(), 1, 155)) {
  331. this.outJson(response, ModelCode.CMS_ARTICLE, false,
  332. getResString("err.length", this.getResString("articleKeyword"), "1", "155"));
  333. return false;
  334. }
  335. return true;
  336. }
  337. /**
  338. * 更新文章
  339. *
  340. * @param basicId
  341. * 文章id
  342. * @param article
  343. * 文章实体
  344. * @param request
  345. * @param response
  346. */
  347. @RequestMapping("/{basicId}/update")
  348. @RequiresPermissions("article:update")
  349. public void update(@PathVariable int basicId, @ModelAttribute ArticleEntity article, HttpServletRequest request,
  350. HttpServletResponse response) {
  351. // 获取站点id
  352. int appId = BasicUtil.getAppId();
  353. article.setBasicUpdateTime(new Timestamp(System.currentTimeMillis()));
  354. // 文章类型
  355. String checkboxType = BasicUtil.getString("checkboxType");
  356. //如果选择一个属性不做排序操作
  357. if(!StringUtils.isEmpty(checkboxType) && checkboxType.length()>2){
  358. // 文章类型排序
  359. article.setArticleType(ArrysUtil.sort(checkboxType, ",")+",");
  360. }else{
  361. article.setArticleType(checkboxType);
  362. }
  363. // 获取更改前的文章实体
  364. ArticleEntity oldArticle = (ArticleEntity) articleBiz.getEntity(basicId);
  365. // 获取栏目实体
  366. ColumnEntity column = (ColumnEntity) columnBiz.getEntity(article.getBasicCategoryId());
  367. if (oldArticle != null) {
  368. // 获取更改前的文章所属栏目实体
  369. ColumnEntity oldColumn = (ColumnEntity) columnBiz.getEntity(oldArticle.getBasicCategoryId());
  370. // 通过表单类型id判断是否更改了表单类型,如果更改则先删除记录
  371. if (oldColumn.getColumnContentModelId() != column.getColumnContentModelId()) {
  372. // 获取旧的内容模型id
  373. ContentModelEntity contentModel = (ContentModelEntity) contentBiz
  374. .getEntity(oldColumn.getColumnContentModelId());
  375. // 删除旧的内容模型中保存的值
  376. Map<String, Integer> wheres = new HashMap<String, Integer>();
  377. wheres.put("basicId", article.getBasicId());
  378. if (contentModel != null) {
  379. fieldBiz.deleteBySQL(contentModel.getCmTableName(), wheres);
  380. }
  381. // 判断栏目是否存在新增字段
  382. if (column.getColumnContentModelId() != 0) {
  383. // 保存所有的字段信息
  384. List<ContentModelFieldEntity> listField = fieldBiz.queryListByCmid(column.getColumnContentModelId());
  385. ContentModelEntity newContentModel = (ContentModelEntity) contentBiz
  386. .getEntity(column.getColumnContentModelId());
  387. if (newContentModel != null) {
  388. Map<String, Object> param = this.checkField(listField, request, article.getBasicId());
  389. fieldBiz.insertBySQL(newContentModel.getCmTableName(), param);
  390. }
  391. }
  392. }
  393. }
  394. //判断是否修改了所属栏目
  395. if(oldArticle.getBasicCategoryId()!=article.getBasicCategoryId()){
  396. //拼接栏目路径和文章编号及文件后缀
  397. article.setArticleUrl(column.getColumnPath() + File.separator + article.getBasicId() + ParserUtil.HTML_SUFFIX);
  398. }
  399. // 添加文章所属的站点id
  400. article.setArticleWebId(appId);
  401. // 设置文章所属的栏目实体
  402. article.setColumn(column);
  403. article.setBasicUpdateTime(new Date());
  404. String articleType = request.getParameter("articleTypeJson");
  405. articleBiz.updateBasic(article);
  406. // 判断该文章是否存在新增字段
  407. if (column.getColumnContentModelId() != 0) {
  408. // 保存所有的字段信息
  409. List<ContentModelFieldEntity> listField = fieldBiz.queryListByCmid(column.getColumnContentModelId());
  410. // // update中的where条件
  411. Map<String, Integer> where = new HashMap<String, Integer>();
  412. // 压入默认的basicId字段
  413. where.put("basicId", article.getBasicId());
  414. // 遍历字段的信息
  415. Map<String, Object> param = this.checkField(listField, request, article.getBasicId());
  416. ContentModelEntity contentModel = (ContentModelEntity) contentBiz
  417. .getEntity(column.getColumnContentModelId());
  418. if (contentModel != null) {
  419. // 遍历所有的字段实体,得到字段名列表信息
  420. List<String> listFieldName = new ArrayList<String>();
  421. listFieldName.add("basicId");
  422. // 查询新增字段的信息
  423. List fieldLists = fieldBiz.queryBySQL(contentModel.getCmTableName(), listFieldName, where);
  424. // 判断新增字段表中是否存在该文章,不存在则保存,否则更新
  425. if (fieldLists == null || fieldLists.size() == 0) {
  426. fieldBiz.insertBySQL(contentModel.getCmTableName(), param);
  427. } else {
  428. fieldBiz.updateBySQL(contentModel.getCmTableName(), param, where);
  429. }
  430. }
  431. }
  432. switch (column.getColumnType()) {
  433. case ColumnEntity.COLUMN_TYPE_COVER:
  434. this.outJson(response, ModelCode.CMS_ARTICLE, true, column.getCategoryId() + "", "");
  435. break;
  436. case ColumnEntity.COLUMN_TYPE_LIST:
  437. this.outJson(response, ModelCode.CMS_ARTICLE, true, column.getCategoryId() + "",
  438. this.redirectBack(request, false));
  439. }
  440. }
  441. /**
  442. * 显示更新内容
  443. *
  444. * @param request
  445. * @return 修改文章的页面地址
  446. */
  447. @RequestMapping("/{id}/edit")
  448. public String edit(@PathVariable int id, ModelMap model, HttpServletRequest request) {
  449. // 如果_categoryId大于0表示是编辑封面栏目,应该先查询分类下面的唯一一篇文章
  450. String categoryTitle = request.getParameter("categoryTitle");
  451. // 板块id
  452. int categoryId = BasicUtil.getInt("categoryId", 0);
  453. ArticleEntity articleEntity = null;
  454. int appId = BasicUtil.getAppId();
  455. model.addAttribute("appId", appId);
  456. model.addAttribute("articleImagesUrl", "/upload/"+BasicUtil.getAppId()+"/");
  457. model.addAttribute("action", "update");
  458. if (categoryId > 0) { // 分类获取文章
  459. articleEntity = articleBiz.getByCategoryId(categoryId);
  460. ColumnEntity column = articleEntity.getColumn();
  461. int columnType = column.getColumnType();
  462. model.addAttribute("article", articleEntity);
  463. // 文章属性
  464. model.addAttribute("articleType", DictUtil.list("文章属性"));
  465. model.addAttribute("categoryTitle", categoryTitle);
  466. model.addAttribute("categoryId", categoryId);// 编辑封面
  467. model.addAttribute("isEditCategory", true);// 编辑封面
  468. model.addAttribute("columnType", columnType);
  469. return "/cms/article/article_form";
  470. } else if (id > 0) { // 文章id获取
  471. // 允许编辑文章时更改分类
  472. List<ColumnEntity> list = columnBiz.queryAll(appId, this.getModelCodeId(request, ModelCode.CMS_COLUMN));
  473. @SuppressWarnings("static-access")
  474. String listJsonString = JSONArray.toJSONString(list);
  475. request.setAttribute("listColumn", listJsonString);
  476. // 文章属性
  477. model.addAttribute("articleType", DictUtil.list("文章属性"));
  478. articleEntity = (ArticleEntity) articleBiz.getEntity(id);
  479. model.addAttribute("article", articleEntity);
  480. // 判断是否是封面类型的栏目,如果是封面类型的栏目有些信息需要屏蔽,例如分类
  481. ColumnEntity column = articleEntity.getColumn();
  482. int columnType = column.getColumnType();
  483. if (column.getColumnType() == ColumnEntity.ColumnTypeEnum.COLUMN_TYPE_COVER.toInt()) {
  484. model.addAttribute("categoryTitle", categoryTitle);
  485. model.addAttribute("categoryId", column.getCategoryId());// 编辑封面
  486. model.addAttribute("isEditCategory", true);// 编辑封面
  487. } else {
  488. model.addAttribute("categoryTitle", articleEntity.getColumn().getCategoryTitle());
  489. model.addAttribute("isEditCategory", false);// 编辑文章
  490. }
  491. model.addAttribute("columnType", columnType);
  492. model.addAttribute("categoryId", column.getCategoryId());// 编辑封面
  493. return "/cms/article/article_form";
  494. } else {// 非法
  495. // return "/cms/article/article_form");
  496. return this.redirectBack(request, true);
  497. }
  498. }
  499. /**
  500. * 删除文章
  501. *
  502. * @param request
  503. * @param response
  504. * @return
  505. */
  506. @RequestMapping("/delete")
  507. @RequiresPermissions("article:del")
  508. public void delete(@RequestBody List<ArticleEntity> articles, HttpServletRequest request, HttpServletResponse response) {
  509. int appId = BasicUtil.getAppId();
  510. int[] ids = new int[articles.size()];
  511. //循环获取id数据
  512. for(int i=0;i<articles.size();i++){
  513. ids[i] = articles.get(i).getArticleID();
  514. }
  515. if (ids.length == 0 || ids == null) {
  516. this.outJson(response, ModelCode.CMS_ARTICLE, false, "", this.redirectBack(request, false));
  517. return;
  518. }
  519. // 删除多个帖子
  520. articleBiz.deleteBasic(ids);
  521. FileUtil.del(articles);
  522. this.outJson(response, ModelCode.CMS_ARTICLE, true, "", this.redirectBack(request, false));
  523. }
  524. /**
  525. * 遍历出所有文章新增字段的信息
  526. *
  527. * @param listField
  528. * :字段列表
  529. * @param request
  530. * @param articleId
  531. * 文章id
  532. * @return 字段信息
  533. */
  534. private Map checkField(List<ContentModelFieldEntity> listField, HttpServletRequest request, int articleId) {
  535. Map<String, Object> mapParams = new HashMap();
  536. // 压入默认的basicId字段
  537. mapParams.put("basicId", articleId);
  538. // 遍历字段名
  539. for (int i = 0; i < listField.size(); i++) {
  540. ContentModelFieldEntity field = (ContentModelFieldEntity) listField.get(i);
  541. String fieldName = field.getFieldFieldName();
  542. // 判断字段类型是否为checkbox类型
  543. if (field.getFieldType() == checkBox) {
  544. String langtyp[] = request.getParameterValues(field.getFieldFieldName());
  545. if (langtyp != null) {
  546. StringBuffer sb = new StringBuffer();
  547. for (int j = 0; j < langtyp.length; j++) {
  548. sb.append(langtyp[j] + ",");
  549. }
  550. mapParams.put(field.getFieldFieldName(), sb.toString());
  551. } else {
  552. mapParams.put(field.getFieldFieldName(), langtyp);
  553. }
  554. } else {
  555. if (StringUtils.isBlank(request.getParameter(field.getFieldFieldName()))) {
  556. mapParams.put(field.getFieldFieldName(), null);
  557. } else {
  558. mapParams.put(field.getFieldFieldName(), request.getParameter(field.getFieldFieldName()));
  559. }
  560. }
  561. }
  562. return mapParams;
  563. }
  564. /**
  565. * 查询单页栏目是否绑定了文章
  566. *
  567. * @param article
  568. * 文章对象
  569. */
  570. @RequestMapping("/{id}/queryColumnArticle")
  571. public void queryColumnArticle(@PathVariable int id, HttpServletResponse response) {
  572. List articls = articleBiz.queryListByColumnId(id);
  573. if (articls == null || articls.size() == 0) {
  574. this.outJson(response, ModelCode.CMS_ARTICLE, true, null);
  575. } else {
  576. this.outJson(response, ModelCode.CMS_ARTICLE, false, null);
  577. }
  578. }
  579. }