package cn.ksource.web.controller.message; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import cn.ksource.core.page.PageInfo; import cn.ksource.core.util.ConvertUtil; import cn.ksource.core.util.JsonUtil; import cn.ksource.core.web.SysInfo; import cn.ksource.core.web.WebUtil; import cn.ksource.web.entity.message.CmsNews; import cn.ksource.web.facade.colunm.ColunmFacade; import cn.ksource.web.facade.message.MessageFacade; import cn.ksource.web.service.file.FileService; @Controller @RequestMapping("/business/pages/cms/message/") public class MessageController { @Resource(name="messageFacade") private MessageFacade messageFacade; @Resource(name="colunmFacade") private ColunmFacade colunmFacade; @Resource(name="fileService") private FileService fileService; /** * 展示栏目管理列表 * @param request * @param response * @return */ @RequestMapping("/messageList.html") public ModelAndView messageList(HttpServletRequest request,HttpServletResponse response){ ModelAndView view=new ModelAndView("/page/message/messageList"); //String categoryId = request.getParameter("categoryId"); String categoryId = "11"; boolean isShowAddButton = messageFacade.isShowAddButton(categoryId); view.addObject("categoryId", categoryId); view.addObject("isShowAddButton", isShowAddButton); return view; } /** * 展示栏目管理列表 * @param request * @param response * @return */ @RequestMapping("/messageData.html") public ModelAndView messageData(HttpServletRequest request,PageInfo pageInfo){ ModelAndView view=new ModelAndView("/page/message/messageData"); String categoryId = request.getParameter("categoryId"); PageInfo info = messageFacade.querymessageData(pageInfo,categoryId); view.addObject("messages", info); return view; } /** * 展示栏目管理列表总数量 */ @RequestMapping("messageCount.html") public void messageCount(HttpServletRequest request,HttpServletResponse response) { String categoryId = request.getParameter("categoryId"); int count = messageFacade.querymessageCount(categoryId); WebUtil.write(response, String.valueOf(count)); } @RequestMapping("/addMessage.html") public ModelAndView addMessage(HttpServletRequest request, HttpServletResponse response){ ModelAndView modelAndView = new ModelAndView("/page/message/addMessage"); String categoryId = request.getParameter("categoryId"); //通过分类id查询分类信息 Map colunm = colunmFacade.queryColunmById(categoryId); modelAndView.addObject("colunm",colunm); modelAndView.addObject("categoryId",categoryId); return modelAndView; } @RequestMapping("addMessageSubmit.html") public ModelAndView addMessageSubmit(HttpServletRequest request, HttpServletResponse response,CmsNews cmsNews){ String summary = request.getParameter("summary"); String content = request.getParameter("content"); cmsNews.setContent(content); cmsNews.setSummary(summary); //通过分类id查询分类信息 boolean b = messageFacade.save(cmsNews,request); return WebUtil.sysInfoPage(request, "操作成功!", "window.top.hideDialog('0');window.top.query();", SysInfo.Success,""); } /** * 跳转到修改信息界面 * @param request * @param response * @return */ @RequestMapping("/updateMessage.html") public ModelAndView updateMessage(HttpServletRequest request, HttpServletResponse response){ ModelAndView modelAndView = new ModelAndView("/page/message/updateMessage"); String categoryId = request.getParameter("categoryId"); String messageId = request.getParameter("id"); //通过分类id查询分类信息 Map colunm = colunmFacade.queryColunmById(categoryId); //通过信息id查询信息 Map message = messageFacade.queryMessageById(messageId); //查询图片信息 List images = fileService.getFileListByType(messageId, "1"); //查询附件信息 List files = fileService.getFileList(messageId); message.put("images", images); message.put("files", files); modelAndView.addObject("colunm",colunm); modelAndView.addObject("msg", message); return modelAndView; } @RequestMapping("updateMessageSubmit.html") public ModelAndView updateMessageSubmit(HttpServletRequest request, HttpServletResponse response,CmsNews cmsNews){ String summary = request.getParameter("summary"); String content = request.getParameter("content"); cmsNews.setContent(content); cmsNews.setSummary(summary); System.out.println("show_num"+cmsNews.getShow_num()); //通过分类id查询分类信息 boolean b = messageFacade.updateMessage(cmsNews,request); // return WebUtil.sysInfoPage(request, "操作成功!", // "window.top.hideDialog('0');window.top.query();", // SysInfo.Success,""); if(b) { return WebUtil.sysInfoPage(request,"操作成功!", "window.top.hideDialog('0');window.top.query();", SysInfo.Success,""); } else { return WebUtil.sysInfoPage(request,"操作失败,上传文件大小最大为100M", "window.top.query();", SysInfo.Error,""); } } /** * 删除信息 */ @RequestMapping("deleteMessage.html") public void deleteMessage(HttpServletRequest request,HttpServletResponse response) { String id = request.getParameter("id"); messageFacade.deleteMessage(id); WebUtil.write(response, "0"); }; @RequestMapping("classify.html") public ModelAndView classify() { ModelAndView modelAndView = new ModelAndView("/page/message/left"); List menuList = messageFacade.queryMeunListById(); modelAndView.addObject("menuList", menuList); return modelAndView; } @RequestMapping("index.html") public ModelAndView messagelist(HttpServletRequest request) { ModelAndView modelAndView = new ModelAndView("/page/message/index"); String categoryId = request.getParameter("categoryId"); //判断是否需要展示添加按钮 //如果此分类是列表展示,则显示添加按钮,如果此分类是单信息,则查询该分类下有无数据,如果有一条数据,则不显示添加按钮,如果无数据,则显示添加按钮 boolean isShowAddButton = messageFacade.isShowAddButton(categoryId); //查询该分类详细信息 Map map = colunmFacade.queryColunmById(categoryId); modelAndView.addObject("shenpi",map.get("SHENPI")); modelAndView.addObject("isShowAddButton",isShowAddButton); modelAndView.addObject("categoryId",categoryId); return modelAndView; } /** * 获取表格数据(json形式) */ @RequestMapping("listJson.html") public void listJson(HttpServletRequest request,HttpServletResponse response) { int page = ConvertUtil.obj2Int(request.getParameter("page")); int pageSize = ConvertUtil.obj2Int(request.getParameter("rows")); String categoryId = request.getParameter("categoryId"); Map resultMap = messageFacade.queryMessageListJson(categoryId,page,pageSize); WebUtil.write(response, JsonUtil.map2Json(resultMap)); } @RequestMapping("/add.html") public ModelAndView add(HttpServletRequest request, HttpServletResponse response){ ModelAndView modelAndView = new ModelAndView("/page/message/add"); String categoryId = request.getParameter("categoryId"); //通过分类id查询分类信息 Map colunm = colunmFacade.queryColunmById(categoryId); modelAndView.addObject("colunm",colunm); return modelAndView; } @RequestMapping("save.html") public ModelAndView save(HttpServletRequest request, HttpServletResponse response,CmsNews cmsNews){ String main_people = request.getParameter("main_people"); String main_people_name = request.getParameter("main_people_TEXT"); String shoot_name = request.getParameter("shoot_id_TEXT"); cmsNews.setMainPeopleId(main_people); cmsNews.setMainPeopleName(main_people_name); cmsNews.setShoot_name(shoot_name); //通过分类id查询分类信息 boolean b = messageFacade.save(cmsNews,request); if(b) { return WebUtil.goSysInfoPage(request,"操作成功!", "window.top.setReload();;window.top.closeDialog(0);", SysInfo.Success); } else { return WebUtil.goSysInfoPage(request,"操作失败,上传文件大小最大为100M", "window.top.getDomID().contentWindow.reloadDataGrid('dg',{});", SysInfo.Error); } } }