InfoController.java 20 KB

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