123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- package com.caimei.modules.info.web;
- import com.caimei.modules.info.dao.InfoDao;
- import com.caimei.modules.info.entity.CmRelated;
- import com.caimei.modules.info.entity.Info;
- import com.caimei.modules.info.entity.InfoType;
- import com.caimei.modules.info.service.CmInfoDocSynService;
- import com.caimei.modules.info.service.CmRelatedService;
- import com.caimei.modules.info.service.InfoService;
- import com.caimei.modules.info.service.InfoTypeService;
- import com.caimei.modules.opensearch.CoreServiceUitls;
- import com.caimei.modules.opensearch.GenerateUtils;
- import com.caimei.modules.product.dao.KeywordFrequencyDao;
- import com.caimei.modules.product.entity.SearchFrequencyVo;
- import com.caimei.redis.RedisService;
- import com.google.common.collect.Maps;
- import com.thinkgem.jeesite.common.config.Global;
- import com.thinkgem.jeesite.common.persistence.Page;
- import com.thinkgem.jeesite.common.utils.StringUtils;
- import com.thinkgem.jeesite.common.web.BaseController;
- import org.apache.commons.collections.CollectionUtils;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.mvc.support.RedirectAttributes;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.util.*;
- /**
- * 信息列表Controller
- *
- * @author LG
- * @version 2016-06-27
- */
- @Controller
- @RequestMapping(value = "${adminPath}/info/info")
- public class InfoController extends BaseController {
- @Autowired
- private InfoService infoService;
- @Autowired
- private CmRelatedService cmRelatedService;
- @Autowired
- private InfoTypeService infoTypeService;
- @Autowired
- CmInfoDocSynService cmInfoDocSynService;
- @Autowired
- private CoreServiceUitls coreServiceUitls;
- @Autowired
- private RedisService redisService;
- @Resource
- private GenerateUtils generateUtils;
- @Autowired
- private InfoDao infoDao;
- @Autowired
- private KeywordFrequencyDao keywordFrequencyDao;
- @ModelAttribute
- public Info get(@RequestParam(required = false) String id) {
- Info entity = null;
- if (StringUtils.isNotBlank(id)) {
- entity = infoService.get(id);
- }
- if (entity == null) {
- entity = new Info();
- }
- return entity;
- }
- @RequiresPermissions("info:info:view")
- @RequestMapping(value = {"list", ""})
- public String list(Info info, HttpServletRequest request, HttpServletResponse response, Model model) {
- if (null != info.getStartPubDate() && !"".equals(info.getStartPubDate()) && !info.getStartPubDate().endsWith("00:00:00")) {
- model.addAttribute("startConfirmTime", info.getStartPubDate());
- info.setStartPubDate(info.getStartPubDate().trim() + " 00:00:00");
- }
- if (null != info.getEndPubDate() && !"".equals(info.getEndPubDate()) && !info.getEndPubDate().endsWith("23:59:59")) {
- model.addAttribute("endConfirmTime", info.getEndPubDate());
- info.setEndPubDate(info.getEndPubDate().trim() + " 23:59:59");
- }
- Page<Info> page = infoService.findPage(new Page<Info>(request, response), info);
- List<Info> list = page.getList();
- if (CollectionUtils.isNotEmpty(list)) {
- String admin2Server = Global.getConfig("admin2Server");//获取admin2文件服务器地址
- for (Info info2 : list) {
- String image = info2.getGuidanceImage();
- if (StringUtils.isNotBlank(image) && !image.contains("http:") && !image.contains("https:")) {//不以http开头的
- info2.setGuidanceImage(admin2Server + "/uploadFile/infoImage/" + image);
- }
- }
- }
- InfoType infoType = new InfoType();
- infoType.setType("1");
- infoType.setEnabledStatus("1");
- List<InfoType> typeList = infoTypeService.findList(infoType);
- List<Info> topList = infoService.findTopList();
- model.addAttribute("topLength", topList.size());
- model.addAttribute("typeList", typeList);
- model.addAttribute("page", page);
- if (null != info.getPublishSource() && 2 == info.getPublishSource()) {
- return "modules/info/shopInfoList";
- } else {
- return "modules/info/infoList";
- }
- }
- @RequiresPermissions("info:info:view")
- @RequestMapping(value = "list1")
- public String list1(Info info, HttpServletRequest request, HttpServletResponse response, Model model) {
- info.setEnabledStatus("1");
- Page<Info> page = infoService.findPage(new Page<Info>(request, response), info);
- /*List<Info> list = page.getList();
- if(CollectionUtils.isNotEmpty(list)){
- String admin2Server = Global.getConfig("admin2Server");//获取admin2文件服务器地址
- for (Info info2 : list) {
- String image = info2.getGuidanceImage();
- if(StringUtils.isNotBlank(image) && !image.contains("http:") && !image.contains("https:")){//不以http开头的
- info2.setGuidanceImage(admin2Server+"/uploadFile/infoImage/"+image);
- }
- }
- }
- List<InfoType> typeList = infoTypeService.findList(new InfoType());
- model.addAttribute("typeList", typeList);*/
- model.addAttribute("page", page);
- return "modules/info/infoList1";
- }
- @RequiresPermissions("info:info:view")
- @RequestMapping(value = "form")
- public String form(Info info, String ltype, Model model) {
- if (StringUtils.isBlank(info.getId())) {
- info.setRecommendStatus("0");
- info.setEnabledStatus("1");
- info.setPubdate(new Date());
- }
- InfoType infoType = new InfoType();
- List<InfoType> typeList = infoTypeService.findList(infoType);
- //先从reids中获取keyword值,不存在时在查询数据库
- List<SearchFrequencyVo> searchFrequencyVos = new ArrayList<>();
- searchFrequencyVos = keywordFrequencyDao.getKeywordList();
- // 敏感词
- String sensitiveWords = infoDao.getSensitiveWords(3);
- model.addAttribute("typeList", typeList);
- model.addAttribute("info", info);
- model.addAttribute("ltype", ltype);
- model.addAttribute("sensitiveWords", sensitiveWords);
- model.addAttribute("SearchFrequencyVo", searchFrequencyVos);
- return "modules/info/infoForm";
- }
- @RequiresPermissions("info:info:view")
- @RequestMapping(value = "relatedForm")
- public String relatedForm(Info info, String ltype, Model model) {
- CmRelated cmRelated = new CmRelated();
- cmRelated.setAuthorId(info.getId());
- cmRelated.setType("1");
- info.setCmRelatedList(cmRelatedService.getCmRelatedList(cmRelated));
- model.addAttribute("info", info);
- model.addAttribute("ltype", ltype);
- return "modules/info/infoRelatedForm";
- }
- /**
- * 精选推荐,文章数据
- */
- @RequestMapping(value = "infoSelectedPage")
- public String infoSelectedList(CmRelated cmRelated, Model model, HttpServletRequest request, HttpServletResponse response) {
- cmRelated.setType("2");
- Page<CmRelated> page = cmRelatedService.findPage(new Page<CmRelated>(request, response), cmRelated);
- InfoType infoType = new InfoType();
- infoType.setType("1");
- infoType.setEnabledStatus("1");
- List<InfoType> typeList = infoTypeService.findList(infoType);
- model.addAttribute("typeList", typeList);
- model.addAttribute("page", page);
- return "modules/info/infoSelectedList";
- }
- /**
- * 选择文章,文章数据
- */
- @RequestMapping(value = "findInfoPage")
- public String findInfoPage(Info info, Model model, HttpServletRequest request, HttpServletResponse response) {
- info.setOnlineStatus(2);
- Page<Info> page = infoService.findPage(new Page<Info>(request, response), info);
- InfoType infoType = new InfoType();
- infoType.setType("1");
- infoType.setEnabledStatus("1");
- List<InfoType> typeList = infoTypeService.findList(infoType);
- model.addAttribute("typeList", typeList);
- model.addAttribute("page", page);
- return "modules/info/addInfoForm";
- }
- /**
- * 添加精选文章文章数据
- */
- @RequestMapping(value = "addSelectedInfos")
- @ResponseBody
- public Map<String, Object> addSelectedInfos(String infoIds) {
- for (String relatedId : infoIds.split(",")) {
- CmRelated cmRelated = new CmRelated();
- cmRelated.setRelatedId(relatedId);
- cmRelated.setType("2");
- cmRelated.setSort(0);
- cmRelated.setDelFlag("0");
- cmRelated.setCreateTime(new Date());
- cmRelatedService.addCmRelated(cmRelated);
- }
- HashMap<String, Object> map = new HashMap<>(2);
- map.put("success", true);
- map.put("info", "添加文章成功");
- return map;
- }
- /**
- * 添加文章数据
- */
- @RequestMapping(value = "addInfos")
- @ResponseBody
- public Map<String, Object> addInfos(String infoIds) {
- Info info = new Info();
- info.setId("IN=" + infoIds);
- info.setEnabledStatus("1");
- List<Info> infoList = infoService.getInfoList(info);
- HashMap<String, Object> map = new HashMap<>(2);
- map.put("infoList", infoList);
- map.put("success", true);
- map.put("info", "添加文章成功");
- return map;
- }
- @RequestMapping(value = "relatedSave")
- public String relatedSave(Info info, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
- Info byInfo = new Info();
- byInfo.setId(info.getId());
- byInfo.setAutoStatus(info.getAutoStatus());
- infoService.updateInfo(byInfo);
- if ("1".equals(info.getAutoStatus())) {
- cmRelatedService.delCmRelatedByAuthorId("1", info.getId());
- info.getCmRelatedList().forEach(cmRelated -> {
- cmRelated.setType("1");
- cmRelated.setDelFlag("0");
- cmRelated.setCreateTime(new Date());
- cmRelatedService.addCmRelated(cmRelated);
- });
- }
- addMessage(redirectAttributes, "保存信息成功");
- // 更新索引
- coreServiceUitls.updateArticleIndex(Integer.valueOf(info.getId()));
- return "redirect:" + Global.getAdminPath() + "/info/info/list?repage&publishSource=" + info.getPublishSource();
- }
- @RequestMapping(value = "infoSelectedListSave")
- public String infoSelectedListSave(Info info, Model model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
- info.getCmRelatedList().forEach(cmRelated -> {
- cmRelatedService.updateCmRelated(cmRelated);
- });
- addMessage(redirectAttributes, "更新排序成功");
- return "redirect:" + Global.getAdminPath() + "/info/info/infoSelectedPage";
- }
- @RequiresPermissions("info:info:edit")
- @RequestMapping(value = "save")
- public String save(Info info, Model model, String ltype, RedirectAttributes redirectAttributes, HttpServletRequest request) {
- if (!beanValidator(model, info)) {
- return form(info, ltype, model);
- }
- String content = info.getInfoContent();
- int stringLengthByUtf8 = com.caimei.utils.StringUtils.getStringLengthByUtf8(content);
- logger.info("信息内容字数" + stringLengthByUtf8);
- logger.info("原始传入信息:" + content);
- //富文本数量超过text保存最大数
- if (stringLengthByUtf8 > 300000) {
- List<String> list = new ArrayList<String>();
- list.add(0, "信息内容编辑框输入字数超过30万,当前字数:" + stringLengthByUtf8);
- addMessage(model, list.toArray(new String[]{}));
- return form(info, ltype, model);
- }
- //新增时才设置随机值
- if (null == info.getId() || "".equals(info.getId())) {
- if (0 == info.getBasePv() || "0".equals(info.getBasePv().toString())) {
- Random random = new Random();
- info.setBasePv((long) (random.nextInt(191) + 10));
- }
- }
- boolean flag = false;
- if (StringUtils.isBlank(info.getId())) {
- flag = true;
- }
- // 保存成功返回info.id
- infoService.save(info, request);
- addMessage(redirectAttributes, "保存信息成功");
- // 更新索引
- coreServiceUitls.updateArticleIndex(Integer.valueOf(info.getId()));
- if (flag) {
- // 新增文章 百度链接实时推送
- generateUtils.pushBaiduLink("https://www.caimei365.com/info/detail-" + info.getId() + "-1.html");
- }
- if (StringUtils.equals("1", ltype)) {
- return "redirect:" + Global.getAdminPath() + "/info/infoLabel/list";
- }
- info.setPublishSource(null == info.getPublishSource() ? 1 : info.getPublishSource());
- return "redirect:" + Global.getAdminPath() + "/info/info/list?repage&publishSource=" + info.getPublishSource();
- }
- @RequiresPermissions("info:info:delete")
- @RequestMapping(value = "delete")
- public String delete(Info info, RedirectAttributes redirectAttributes) {
- infoService.delete(info);
- if (info.getTopPosition() != null && !StringUtils.equals("", info.getTopPosition())) {
- //清除置顶,将后面置顶位的数据往前移
- infoService.moveTopList(info);
- // 重新生成静态首页
- generateUtils.generateHome();
- }
- addMessage(redirectAttributes, "删除信息成功");
- // 删除索引
- coreServiceUitls.deleteArticleIndex(Integer.valueOf(info.getId()));
- return "redirect:" + Global.getAdminPath() + "/info/info/?repage&publishSource=1";
- }
- @RequiresPermissions("info:info:delete")
- @RequestMapping(value = "delInfoSelected")
- public String delete(CmRelated cmRelated, RedirectAttributes redirectAttributes) {
- cmRelatedService.delCmRelatedById(cmRelated.getId());
- addMessage(redirectAttributes, "删除文章成功");
- return "redirect:" + Global.getAdminPath() + "/info/info/infoSelectedPage";
- }
- /**
- * 批量修改启用、停用状态
- *
- * @param ids
- * @param request
- * @param response
- * @return
- */
- @RequiresPermissions("info:info:edit")
- @ResponseBody
- @RequestMapping(value = "updateStatus")
- public Map<String, Object> updateStatus(String status, String[] ids, String type, HttpServletRequest request, HttpServletResponse response) {
- Map<String, Object> map = Maps.newLinkedHashMap();
- try {
- if (StringUtils.equals("enabledStatus", type)) {
- infoService.updateEnabledStatusByIds(status, ids);
- } else if (StringUtils.equals("recommendStatus", type)) {
- infoService.updateRecommendStatusByIds(status, ids);
- }
- map.put("success", true);
- map.put("msg", "修改成功");
- for (String id : ids) {
- // 更新索引
- coreServiceUitls.updateArticleIndex(Integer.valueOf(id));
- Info info = infoService.get(id);
- Boolean topFlag = (info.getTopPosition() != null && !StringUtils.equals("", info.getTopPosition())) ? true : false;
- if (topFlag) {
- // 重新生成静态首页
- generateUtils.generateHome();
- }
- }
- } catch (Exception e) {
- logger.debug(e.toString(), e);
- map.put("success", false);
- map.put("msg", "修改失败");
- }
- return map;
- }
- @RequestMapping(value = "updateTopPosition")
- @ResponseBody
- public Map<String, Object> updateTopPosition(Integer topPosition, String id, String type) {
- Map<String, Object> map = Maps.newLinkedHashMap();
- try {
- Info info = infoService.get(id);
- Boolean topFlag = (info.getTopPosition() != null && !StringUtils.equals("", info.getTopPosition())) ? true : false;
- String oldTopPosition = info.getTopPosition();
- if (StringUtils.equals("setTopPosition", type)) {
- //更新被替换掉置顶的文章
- Info oldInfo = new Info();
- oldInfo.setTopPosition(topPosition.toString());
- List<Info> replacedInfoList = infoService.findList(oldInfo);
- replacedInfoList.forEach(replacedInfo -> {
- replacedInfo.setTopPosition(null);
- infoService.update(replacedInfo);
- });
- //新的置顶直播
- info.setTopPosition(topPosition.toString());
- map.put("msg", "置顶成功");
- } else if (StringUtils.equals("clearTopPosition", type)) {
- //清除置顶,将后面置顶位的数据往前移
- infoService.moveTopList(info);
- //清除置顶位
- info.setTopPosition(null);
- map.put("msg", "清除成功");
- }
- infoService.update(info);
- //如果新直播原本也是置顶直播,需要把新直播后面的直播往前挪(新直播更新后再一起挪)
- if (StringUtils.equals("setTopPosition", type) && topFlag) {
- Info oldInfo = new Info();
- oldInfo.setTopPosition(oldTopPosition);
- infoService.moveTopList(oldInfo);
- }
- // 重新生成静态首页
- generateUtils.generateHome();
- map.put("success", true);
- } catch (Exception e) {
- logger.debug(e.toString(), e);
- map.put("success", false);
- map.put("msg", "修改失败");
- }
- return map;
- }
- @RequestMapping(value = {"infoList_multiselect"})
- public String infoPageMulti(Info info, HttpServletRequest request, HttpServletResponse response, Model model) {
- info.setEnabledStatus("1");
- Page<Info> page = infoService.findPage(new Page<Info>(request, response), info);
- model.addAttribute("page", page);
- return "modules/info/infoList_multiselect";
- }
- @RequestMapping(value = "check")
- public String checkInfo(Info info, Model model) {
- model.addAttribute("info", info);
- return "modules/info/checkInfoPage";
- }
- @RequestMapping(value = "toAuditPage")
- public String toAuditPage(Info info, Model model) {
- if (StringUtils.isBlank(info.getId())) {
- info.setRecommendStatus("0");
- info.setEnabledStatus("1");
- info.setPubdate(new Date());
- }
- InfoType infoType = new InfoType();
- List<InfoType> typeList = infoTypeService.findList(infoType);
- model.addAttribute("typeList", typeList);
- model.addAttribute("info", info);
- // 敏感词
- String sensitiveWords = infoDao.getSensitiveWords(3);
- model.addAttribute("sensitiveWords", sensitiveWords);
- return "modules/info/auditInfoPage";
- }
- @RequestMapping(value = "auditInfo")
- @ResponseBody
- public Boolean auditInfo(Info info) {
- infoService.auditInfo(info);
- return true;
- }
- @RequestMapping(value = "offline")
- @ResponseBody
- public Boolean offline(Integer id) {
- infoService.offlineInfo(id);
- return true;
- }
- }
|