InfoController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. package com.caimei.modules.info.web;
  2. import com.caimei.modules.info.dao.InfoDao;
  3. import com.caimei.modules.info.entity.CmRelated;
  4. import com.caimei.modules.info.entity.Info;
  5. import com.caimei.modules.info.entity.InfoType;
  6. import com.caimei.modules.info.service.CmInfoDocSynService;
  7. import com.caimei.modules.info.service.CmRelatedService;
  8. import com.caimei.modules.info.service.InfoService;
  9. import com.caimei.modules.info.service.InfoTypeService;
  10. import com.caimei.modules.opensearch.CoreServiceUitls;
  11. import com.caimei.modules.opensearch.GenerateUtils;
  12. import com.caimei.modules.product.dao.KeywordFrequencyDao;
  13. import com.caimei.modules.product.entity.SearchFrequencyVo;
  14. import com.caimei.redis.RedisService;
  15. import com.google.common.collect.Maps;
  16. import com.thinkgem.jeesite.common.config.Global;
  17. import com.thinkgem.jeesite.common.persistence.Page;
  18. import com.thinkgem.jeesite.common.utils.StringUtils;
  19. import com.thinkgem.jeesite.common.web.BaseController;
  20. import org.apache.commons.collections.CollectionUtils;
  21. import org.apache.shiro.authz.annotation.RequiresPermissions;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Controller;
  24. import org.springframework.ui.Model;
  25. import org.springframework.web.bind.annotation.ModelAttribute;
  26. import org.springframework.web.bind.annotation.RequestMapping;
  27. import org.springframework.web.bind.annotation.RequestParam;
  28. import org.springframework.web.bind.annotation.ResponseBody;
  29. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  30. import javax.annotation.Resource;
  31. import javax.servlet.http.HttpServletRequest;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.util.*;
  34. /**
  35. * 信息列表Controller
  36. *
  37. * @author LG
  38. * @version 2016-06-27
  39. */
  40. @Controller
  41. @RequestMapping(value = "${adminPath}/info/info")
  42. public class InfoController extends BaseController {
  43. @Autowired
  44. private InfoService infoService;
  45. @Autowired
  46. private CmRelatedService cmRelatedService;
  47. @Autowired
  48. private InfoTypeService infoTypeService;
  49. @Autowired
  50. CmInfoDocSynService cmInfoDocSynService;
  51. @Autowired
  52. private CoreServiceUitls coreServiceUitls;
  53. @Autowired
  54. private RedisService redisService;
  55. @Resource
  56. private GenerateUtils generateUtils;
  57. @Autowired
  58. private InfoDao infoDao;
  59. @Autowired
  60. private KeywordFrequencyDao keywordFrequencyDao;
  61. @ModelAttribute
  62. public Info get(@RequestParam(required = false) String id) {
  63. Info entity = null;
  64. if (StringUtils.isNotBlank(id)) {
  65. entity = infoService.get(id);
  66. }
  67. if (entity == null) {
  68. entity = new Info();
  69. }
  70. return entity;
  71. }
  72. @RequiresPermissions("info:info:view")
  73. @RequestMapping(value = {"list", ""})
  74. public String list(Info info, HttpServletRequest request, HttpServletResponse response, Model model) {
  75. if (null != info.getStartPubDate() && !"".equals(info.getStartPubDate()) && !info.getStartPubDate().endsWith("00:00:00")) {
  76. model.addAttribute("startConfirmTime", info.getStartPubDate());
  77. info.setStartPubDate(info.getStartPubDate().trim() + " 00:00:00");
  78. }
  79. if (null != info.getEndPubDate() && !"".equals(info.getEndPubDate()) && !info.getEndPubDate().endsWith("23:59:59")) {
  80. model.addAttribute("endConfirmTime", info.getEndPubDate());
  81. info.setEndPubDate(info.getEndPubDate().trim() + " 23:59:59");
  82. }
  83. Page<Info> page = infoService.findPage(new Page<Info>(request, response), info);
  84. List<Info> list = page.getList();
  85. if (CollectionUtils.isNotEmpty(list)) {
  86. String admin2Server = Global.getConfig("admin2Server");//获取admin2文件服务器地址
  87. for (Info info2 : list) {
  88. String image = info2.getGuidanceImage();
  89. if (StringUtils.isNotBlank(image) && !image.contains("http:") && !image.contains("https:")) {//不以http开头的
  90. info2.setGuidanceImage(admin2Server + "/uploadFile/infoImage/" + image);
  91. }
  92. }
  93. }
  94. InfoType infoType = new InfoType();
  95. infoType.setType("1");
  96. infoType.setEnabledStatus("1");
  97. List<InfoType> typeList = infoTypeService.findList(infoType);
  98. List<Info> topList = infoService.findTopList();
  99. model.addAttribute("topLength", topList.size());
  100. model.addAttribute("typeList", typeList);
  101. model.addAttribute("page", page);
  102. if (null != info.getPublishSource() && 2 == info.getPublishSource()) {
  103. return "modules/info/shopInfoList";
  104. } else {
  105. return "modules/info/infoList";
  106. }
  107. }
  108. @RequiresPermissions("info:info:view")
  109. @RequestMapping(value = "list1")
  110. public String list1(Info info, HttpServletRequest request, HttpServletResponse response, Model model) {
  111. info.setEnabledStatus("1");
  112. Page<Info> page = infoService.findPage(new Page<Info>(request, response), info);
  113. /*List<Info> list = page.getList();
  114. if(CollectionUtils.isNotEmpty(list)){
  115. String admin2Server = Global.getConfig("admin2Server");//获取admin2文件服务器地址
  116. for (Info info2 : list) {
  117. String image = info2.getGuidanceImage();
  118. if(StringUtils.isNotBlank(image) && !image.contains("http:") && !image.contains("https:")){//不以http开头的
  119. info2.setGuidanceImage(admin2Server+"/uploadFile/infoImage/"+image);
  120. }
  121. }
  122. }
  123. List<InfoType> typeList = infoTypeService.findList(new InfoType());
  124. model.addAttribute("typeList", typeList);*/
  125. model.addAttribute("page", page);
  126. return "modules/info/infoList1";
  127. }
  128. @RequiresPermissions("info:info:view")
  129. @RequestMapping(value = "form")
  130. public String form(Info info, String ltype, Model model) {
  131. if (StringUtils.isBlank(info.getId())) {
  132. info.setRecommendStatus("0");
  133. info.setEnabledStatus("1");
  134. info.setPubdate(new Date());
  135. }
  136. InfoType infoType = new InfoType();
  137. List<InfoType> typeList = infoTypeService.findList(infoType);
  138. //先从reids中获取keyword值,不存在时在查询数据库
  139. List<SearchFrequencyVo> searchFrequencyVos = new ArrayList<>();
  140. searchFrequencyVos = keywordFrequencyDao.getKeywordList();
  141. // 敏感词
  142. String sensitiveWords = infoDao.getSensitiveWords(3);
  143. model.addAttribute("typeList", typeList);
  144. model.addAttribute("info", info);
  145. model.addAttribute("ltype", ltype);
  146. model.addAttribute("sensitiveWords", sensitiveWords);
  147. model.addAttribute("SearchFrequencyVo", searchFrequencyVos);
  148. return "modules/info/infoForm";
  149. }
  150. @RequiresPermissions("info:info:view")
  151. @RequestMapping(value = "relatedForm")
  152. public String relatedForm(Info info, String ltype, Model model) {
  153. CmRelated cmRelated = new CmRelated();
  154. cmRelated.setAuthorId(info.getId());
  155. cmRelated.setType("1");
  156. info.setCmRelatedList(cmRelatedService.getCmRelatedList(cmRelated));
  157. model.addAttribute("info", info);
  158. model.addAttribute("ltype", ltype);
  159. return "modules/info/infoRelatedForm";
  160. }
  161. /**
  162. * 精选推荐,文章数据
  163. */
  164. @RequestMapping(value = "infoSelectedPage")
  165. public String infoSelectedList(CmRelated cmRelated, Model model, HttpServletRequest request, HttpServletResponse response) {
  166. cmRelated.setType("2");
  167. Page<CmRelated> page = cmRelatedService.findPage(new Page<CmRelated>(request, response), cmRelated);
  168. InfoType infoType = new InfoType();
  169. infoType.setType("1");
  170. infoType.setEnabledStatus("1");
  171. List<InfoType> typeList = infoTypeService.findList(infoType);
  172. model.addAttribute("typeList", typeList);
  173. model.addAttribute("page", page);
  174. return "modules/info/infoSelectedList";
  175. }
  176. /**
  177. * 选择文章,文章数据
  178. */
  179. @RequestMapping(value = "findInfoPage")
  180. public String findInfoPage(Info info, Model model, HttpServletRequest request, HttpServletResponse response) {
  181. info.setOnlineStatus(2);
  182. Page<Info> page = infoService.findPage(new Page<Info>(request, response), info);
  183. InfoType infoType = new InfoType();
  184. infoType.setType("1");
  185. infoType.setEnabledStatus("1");
  186. List<InfoType> typeList = infoTypeService.findList(infoType);
  187. model.addAttribute("typeList", typeList);
  188. model.addAttribute("page", page);
  189. return "modules/info/addInfoForm";
  190. }
  191. /**
  192. * 添加精选文章文章数据
  193. */
  194. @RequestMapping(value = "addSelectedInfos")
  195. @ResponseBody
  196. public Map<String, Object> addSelectedInfos(String infoIds) {
  197. for (String relatedId : infoIds.split(",")) {
  198. CmRelated cmRelated = new CmRelated();
  199. cmRelated.setRelatedId(relatedId);
  200. cmRelated.setType("2");
  201. cmRelated.setSort(0);
  202. cmRelated.setDelFlag("0");
  203. cmRelated.setCreateTime(new Date());
  204. cmRelatedService.addCmRelated(cmRelated);
  205. }
  206. HashMap<String, Object> map = new HashMap<>(2);
  207. map.put("success", true);
  208. map.put("info", "添加文章成功");
  209. return map;
  210. }
  211. /**
  212. * 添加文章数据
  213. */
  214. @RequestMapping(value = "addInfos")
  215. @ResponseBody
  216. public Map<String, Object> addInfos(String infoIds) {
  217. Info info = new Info();
  218. info.setId("IN=" + infoIds);
  219. info.setEnabledStatus("1");
  220. List<Info> infoList = infoService.getInfoList(info);
  221. HashMap<String, Object> map = new HashMap<>(2);
  222. map.put("infoList", infoList);
  223. map.put("success", true);
  224. map.put("info", "添加文章成功");
  225. return map;
  226. }
  227. @RequestMapping(value = "relatedSave")
  228. public String relatedSave(Info info, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
  229. Info byInfo = new Info();
  230. byInfo.setId(info.getId());
  231. byInfo.setAutoStatus(info.getAutoStatus());
  232. infoService.updateInfo(byInfo);
  233. if ("1".equals(info.getAutoStatus())) {
  234. cmRelatedService.delCmRelatedByAuthorId("1", info.getId());
  235. info.getCmRelatedList().forEach(cmRelated -> {
  236. cmRelated.setType("1");
  237. cmRelated.setDelFlag("0");
  238. cmRelated.setCreateTime(new Date());
  239. cmRelatedService.addCmRelated(cmRelated);
  240. });
  241. }
  242. addMessage(redirectAttributes, "保存信息成功");
  243. // 更新索引
  244. coreServiceUitls.updateArticleIndex(Integer.valueOf(info.getId()));
  245. return "redirect:" + Global.getAdminPath() + "/info/info/list?repage&publishSource=" + info.getPublishSource();
  246. }
  247. @RequestMapping(value = "infoSelectedListSave")
  248. public String infoSelectedListSave(Info info, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
  249. info.getCmRelatedList().forEach(cmRelated -> {
  250. cmRelatedService.updateCmRelated(cmRelated);
  251. });
  252. addMessage(redirectAttributes, "更新排序成功");
  253. return "redirect:" + Global.getAdminPath() + "/info/info/infoSelectedPage";
  254. }
  255. @RequiresPermissions("info:info:edit")
  256. @RequestMapping(value = "save")
  257. public String save(Info info, Model model, String ltype, RedirectAttributes redirectAttributes, HttpServletRequest request) {
  258. if (!beanValidator(model, info)) {
  259. return form(info, ltype, model);
  260. }
  261. String content = info.getInfoContent();
  262. int stringLengthByUtf8 = com.caimei.utils.StringUtils.getStringLengthByUtf8(content);
  263. logger.info("信息内容字数" + stringLengthByUtf8);
  264. logger.info("原始传入信息:" + content);
  265. //富文本数量超过text保存最大数
  266. if (stringLengthByUtf8 > 300000) {
  267. List<String> list = new ArrayList<String>();
  268. list.add(0, "信息内容编辑框输入字数超过30万,当前字数:" + stringLengthByUtf8);
  269. addMessage(model, list.toArray(new String[]{}));
  270. return form(info, ltype, model);
  271. }
  272. //新增时才设置随机值
  273. if (null == info.getId() || "".equals(info.getId())) {
  274. if (0 == info.getBasePv() || "0".equals(info.getBasePv().toString())) {
  275. Random random = new Random();
  276. info.setBasePv((long) (random.nextInt(191) + 10));
  277. }
  278. }
  279. boolean flag = false;
  280. if (StringUtils.isBlank(info.getId())) {
  281. flag = true;
  282. }
  283. // 保存成功返回info.id
  284. infoService.save(info, request);
  285. addMessage(redirectAttributes, "保存信息成功");
  286. // 更新索引
  287. coreServiceUitls.updateArticleIndex(Integer.valueOf(info.getId()));
  288. if (flag) {
  289. // 新增文章 百度链接实时推送
  290. generateUtils.pushBaiduLink("https://www.caimei365.com/info/detail-" + info.getId() + "-1.html");
  291. }
  292. if (StringUtils.equals("1", ltype)) {
  293. return "redirect:" + Global.getAdminPath() + "/info/infoLabel/list";
  294. }
  295. info.setPublishSource(null == info.getPublishSource() ? 1 : info.getPublishSource());
  296. return "redirect:" + Global.getAdminPath() + "/info/info/list?repage&publishSource=" + info.getPublishSource();
  297. }
  298. @RequiresPermissions("info:info:delete")
  299. @RequestMapping(value = "delete")
  300. public String delete(Info info, RedirectAttributes redirectAttributes) {
  301. infoService.delete(info);
  302. if (info.getTopPosition() != null && !StringUtils.equals("", info.getTopPosition())) {
  303. //清除置顶,将后面置顶位的数据往前移
  304. infoService.moveTopList(info);
  305. // 重新生成静态首页
  306. generateUtils.generateHome();
  307. }
  308. addMessage(redirectAttributes, "删除信息成功");
  309. // 删除索引
  310. coreServiceUitls.deleteArticleIndex(Integer.valueOf(info.getId()));
  311. return "redirect:" + Global.getAdminPath() + "/info/info/?repage&publishSource=1";
  312. }
  313. @RequiresPermissions("info:info:delete")
  314. @RequestMapping(value = "delInfoSelected")
  315. public String delete(CmRelated cmRelated, RedirectAttributes redirectAttributes) {
  316. cmRelatedService.delCmRelatedById(cmRelated.getId());
  317. addMessage(redirectAttributes, "删除文章成功");
  318. return "redirect:" + Global.getAdminPath() + "/info/info/infoSelectedPage";
  319. }
  320. /**
  321. * 批量修改启用、停用状态
  322. *
  323. * @param ids
  324. * @param request
  325. * @param response
  326. * @return
  327. */
  328. @RequiresPermissions("info:info:edit")
  329. @ResponseBody
  330. @RequestMapping(value = "updateStatus")
  331. public Map<String, Object> updateStatus(String status, String[] ids, String type, HttpServletRequest request, HttpServletResponse response) {
  332. Map<String, Object> map = Maps.newLinkedHashMap();
  333. try {
  334. if (StringUtils.equals("enabledStatus", type)) {
  335. infoService.updateEnabledStatusByIds(status, ids);
  336. } else if (StringUtils.equals("recommendStatus", type)) {
  337. infoService.updateRecommendStatusByIds(status, ids);
  338. }
  339. map.put("success", true);
  340. map.put("msg", "修改成功");
  341. for (String id : ids) {
  342. // 更新索引
  343. coreServiceUitls.updateArticleIndex(Integer.valueOf(id));
  344. Info info = infoService.get(id);
  345. Boolean topFlag = (info.getTopPosition() != null && !StringUtils.equals("", info.getTopPosition())) ? true : false;
  346. if (topFlag) {
  347. // 重新生成静态首页
  348. generateUtils.generateHome();
  349. }
  350. }
  351. } catch (Exception e) {
  352. logger.debug(e.toString(), e);
  353. map.put("success", false);
  354. map.put("msg", "修改失败");
  355. }
  356. return map;
  357. }
  358. @RequestMapping(value = "updateTopPosition")
  359. @ResponseBody
  360. public Map<String, Object> updateTopPosition(Integer topPosition, String id, String type) {
  361. Map<String, Object> map = Maps.newLinkedHashMap();
  362. try {
  363. Info info = infoService.get(id);
  364. Boolean topFlag = (info.getTopPosition() != null && !StringUtils.equals("", info.getTopPosition())) ? true : false;
  365. String oldTopPosition = info.getTopPosition();
  366. if (StringUtils.equals("setTopPosition", type)) {
  367. //更新被替换掉置顶的文章
  368. Info oldInfo = new Info();
  369. oldInfo.setTopPosition(topPosition.toString());
  370. List<Info> replacedInfoList = infoService.findList(oldInfo);
  371. replacedInfoList.forEach(replacedInfo -> {
  372. replacedInfo.setTopPosition(null);
  373. infoService.update(replacedInfo);
  374. });
  375. //新的置顶直播
  376. info.setTopPosition(topPosition.toString());
  377. map.put("msg", "置顶成功");
  378. } else if (StringUtils.equals("clearTopPosition", type)) {
  379. //清除置顶,将后面置顶位的数据往前移
  380. infoService.moveTopList(info);
  381. //清除置顶位
  382. info.setTopPosition(null);
  383. map.put("msg", "清除成功");
  384. }
  385. infoService.update(info);
  386. //如果新直播原本也是置顶直播,需要把新直播后面的直播往前挪(新直播更新后再一起挪)
  387. if (StringUtils.equals("setTopPosition", type) && topFlag) {
  388. Info oldInfo = new Info();
  389. oldInfo.setTopPosition(oldTopPosition);
  390. infoService.moveTopList(oldInfo);
  391. }
  392. // 重新生成静态首页
  393. generateUtils.generateHome();
  394. map.put("success", true);
  395. } catch (Exception e) {
  396. logger.debug(e.toString(), e);
  397. map.put("success", false);
  398. map.put("msg", "修改失败");
  399. }
  400. return map;
  401. }
  402. @RequestMapping(value = {"infoList_multiselect"})
  403. public String infoPageMulti(Info info, HttpServletRequest request, HttpServletResponse response, Model model) {
  404. info.setEnabledStatus("1");
  405. Page<Info> page = infoService.findPage(new Page<Info>(request, response), info);
  406. model.addAttribute("page", page);
  407. return "modules/info/infoList_multiselect";
  408. }
  409. @RequestMapping(value = "check")
  410. public String checkInfo(Info info, Model model) {
  411. model.addAttribute("info", info);
  412. return "modules/info/checkInfoPage";
  413. }
  414. @RequestMapping(value = "toAuditPage")
  415. public String toAuditPage(Info info, Model model) {
  416. if (StringUtils.isBlank(info.getId())) {
  417. info.setRecommendStatus("0");
  418. info.setEnabledStatus("1");
  419. info.setPubdate(new Date());
  420. }
  421. InfoType infoType = new InfoType();
  422. List<InfoType> typeList = infoTypeService.findList(infoType);
  423. model.addAttribute("typeList", typeList);
  424. model.addAttribute("info", info);
  425. // 敏感词
  426. String sensitiveWords = infoDao.getSensitiveWords(3);
  427. model.addAttribute("sensitiveWords", sensitiveWords);
  428. return "modules/info/auditInfoPage";
  429. }
  430. @RequestMapping(value = "auditInfo")
  431. @ResponseBody
  432. public Boolean auditInfo(Info info) {
  433. infoService.auditInfo(info);
  434. return true;
  435. }
  436. @RequestMapping(value = "offline")
  437. @ResponseBody
  438. public Boolean offline(Integer id) {
  439. infoService.offlineInfo(id);
  440. return true;
  441. }
  442. }