From 60823a014f19d3b50057433e04752565cb66c75d Mon Sep 17 00:00:00 2001 From: shuzheng <469741414@qq.com> Date: Sat, 18 Mar 2017 18:53:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90=E4=B8=93=E9=A2=98=E5=92=8C?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/manage/CmsMenuController.java | 132 ++++++++++++++++++ .../controller/manage/CmsTopicController.java | 132 ++++++++++++++++++ 2 files changed, 264 insertions(+) create mode 100644 zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsMenuController.java create mode 100644 zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsTopicController.java diff --git a/zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsMenuController.java b/zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsMenuController.java new file mode 100644 index 00000000..c9c3dccf --- /dev/null +++ b/zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsMenuController.java @@ -0,0 +1,132 @@ +package com.zheng.cms.admin.controller.manage; + +import com.baidu.unbiz.fluentvalidator.ComplexResult; +import com.baidu.unbiz.fluentvalidator.FluentValidator; +import com.baidu.unbiz.fluentvalidator.ResultCollectors; +import com.zheng.cms.common.constant.CmsResult; +import com.zheng.cms.common.constant.CmsResultConstant; +import com.zheng.cms.dao.model.CmsMenu; +import com.zheng.cms.dao.model.CmsMenuExample; +import com.zheng.cms.rpc.api.CmsMenuService; +import com.zheng.common.base.BaseController; +import com.zheng.common.validator.LengthValidator; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang.StringUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 菜单控制器 + * Created by shuzheng on 2017/3/18. + */ +@Controller +@Api(value = "菜单管理", description = "菜单管理") +@RequestMapping("/manage/menu") +public class CmsMenuController extends BaseController { + + private static Logger _log = LoggerFactory.getLogger(CmsMenuController.class); + + @Autowired + private CmsMenuService cmsMenuService; + + @ApiOperation(value = "评论首页") + @RequiresPermissions("cms:menu:read") + @RequestMapping(value = "/index", method = RequestMethod.GET) + public String index() { + return "/manage/menu/index"; + } + + @ApiOperation(value = "评论列表") + @RequiresPermissions("cms:menu:read") + @RequestMapping(value = "/list", method = RequestMethod.GET) + @ResponseBody + public Object list( + @RequestParam(required = false, defaultValue = "0", value = "offset") int offset, + @RequestParam(required = false, defaultValue = "10", value = "limit") int limit, + @RequestParam(required = false, value = "sort") String sort, + @RequestParam(required = false, value = "order") String order) { + CmsMenuExample cmsMenuExample = new CmsMenuExample(); + cmsMenuExample.setOffset(offset); + cmsMenuExample.setLimit(limit); + if (!StringUtils.isBlank(sort) && !StringUtils.isBlank(order)) { + cmsMenuExample.setOrderByClause(sort + " " + order); + } + List rows = cmsMenuService.selectByExample(cmsMenuExample); + long total = cmsMenuService.countByExample(cmsMenuExample); + Map result = new HashMap<>(); + result.put("rows", rows); + result.put("total", total); + return result; + } + + @ApiOperation(value = "新增菜单") + @RequiresPermissions("cms:menu:create") + @RequestMapping(value = "/create", method = RequestMethod.GET) + public String create() { + return "/manage/menu/create"; + } + + @ApiOperation(value = "新增菜单") + @RequiresPermissions("cms:menu:create") + @RequestMapping(value = "/create", method = RequestMethod.POST) + @ResponseBody + public Object create(CmsMenu cmsMenu) { + ComplexResult result = FluentValidator.checkAll() + .on(cmsMenu.getName(), new LengthValidator(1, 20, "名称")) + .doValidate() + .result(ResultCollectors.toComplex()); + if (!result.isSuccess()) { + return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors()); + } + long time = System.currentTimeMillis(); + cmsMenu.setOrders(time); + int count = cmsMenuService.insertSelective(cmsMenu); + return new CmsResult(CmsResultConstant.SUCCESS, count); + } + + @ApiOperation(value = "删除菜单") + @RequiresPermissions("cms:menu:delete") + @RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET) + @ResponseBody + public Object delete(@PathVariable("ids") String ids) { + int count = cmsMenuService.deleteByPrimaryKeys(ids); + return new CmsResult(CmsResultConstant.SUCCESS, count); + } + + @ApiOperation(value = "修改菜单") + @RequiresPermissions("cms:menu:update") + @RequestMapping(value = "/update/{id}", method = RequestMethod.GET) + public String update(@PathVariable("id") int id, ModelMap modelMap) { + CmsMenu menu = cmsMenuService.selectByPrimaryKey(id); + modelMap.put("menu", menu); + return "/manage/menu/update"; + } + + @ApiOperation(value = "修改菜单") + @RequiresPermissions("cms:menu:update") + @RequestMapping(value = "/update/{id}", method = RequestMethod.POST) + @ResponseBody + public Object update(@PathVariable("id") int id, CmsMenu cmsMenu) { + ComplexResult result = FluentValidator.checkAll() + .on(cmsMenu.getName(), new LengthValidator(1, 20, "名称")) + .doValidate() + .result(ResultCollectors.toComplex()); + if (!result.isSuccess()) { + return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors()); + } + cmsMenu.setMenuId(id); + int count = cmsMenuService.updateByPrimaryKeySelective(cmsMenu); + return new CmsResult(CmsResultConstant.SUCCESS, count); + } + +} \ No newline at end of file diff --git a/zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsTopicController.java b/zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsTopicController.java new file mode 100644 index 00000000..256a581c --- /dev/null +++ b/zheng-cms/zheng-cms-admin/src/main/java/com/zheng/cms/admin/controller/manage/CmsTopicController.java @@ -0,0 +1,132 @@ +package com.zheng.cms.admin.controller.manage; + +import com.baidu.unbiz.fluentvalidator.ComplexResult; +import com.baidu.unbiz.fluentvalidator.FluentValidator; +import com.baidu.unbiz.fluentvalidator.ResultCollectors; +import com.zheng.cms.common.constant.CmsResult; +import com.zheng.cms.common.constant.CmsResultConstant; +import com.zheng.cms.dao.model.CmsTopic; +import com.zheng.cms.dao.model.CmsTopicExample; +import com.zheng.cms.rpc.api.CmsTopicService; +import com.zheng.common.base.BaseController; +import com.zheng.common.validator.LengthValidator; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang.StringUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 专题控制器 + * Created by shuzheng on 2017/3/18. + */ +@Controller +@Api(value = "专题管理", description = "专题管理") +@RequestMapping("/manage/topic") +public class CmsTopicController extends BaseController { + + private static Logger _log = LoggerFactory.getLogger(CmsTopicController.class); + + @Autowired + private CmsTopicService cmsTopicService; + + @ApiOperation(value = "评论首页") + @RequiresPermissions("cms:topic:read") + @RequestMapping(value = "/index", method = RequestMethod.GET) + public String index() { + return "/manage/topic/index"; + } + + @ApiOperation(value = "评论列表") + @RequiresPermissions("cms:topic:read") + @RequestMapping(value = "/list", method = RequestMethod.GET) + @ResponseBody + public Object list( + @RequestParam(required = false, defaultValue = "0", value = "offset") int offset, + @RequestParam(required = false, defaultValue = "10", value = "limit") int limit, + @RequestParam(required = false, value = "sort") String sort, + @RequestParam(required = false, value = "order") String order) { + CmsTopicExample cmsTopicExample = new CmsTopicExample(); + cmsTopicExample.setOffset(offset); + cmsTopicExample.setLimit(limit); + if (!StringUtils.isBlank(sort) && !StringUtils.isBlank(order)) { + cmsTopicExample.setOrderByClause(sort + " " + order); + } + List rows = cmsTopicService.selectByExample(cmsTopicExample); + long total = cmsTopicService.countByExample(cmsTopicExample); + Map result = new HashMap<>(); + result.put("rows", rows); + result.put("total", total); + return result; + } + + @ApiOperation(value = "新增专题") + @RequiresPermissions("cms:topic:create") + @RequestMapping(value = "/create", method = RequestMethod.GET) + public String create() { + return "/manage/topic/create"; + } + + @ApiOperation(value = "新增专题") + @RequiresPermissions("cms:topic:create") + @RequestMapping(value = "/create", method = RequestMethod.POST) + @ResponseBody + public Object create(CmsTopic cmsTopic) { + ComplexResult result = FluentValidator.checkAll() + .on(cmsTopic.getTitle(), new LengthValidator(1, 100, "标题")) + .doValidate() + .result(ResultCollectors.toComplex()); + if (!result.isSuccess()) { + return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors()); + } + long time = System.currentTimeMillis(); + cmsTopic.setCtime(time); + int count = cmsTopicService.insertSelective(cmsTopic); + return new CmsResult(CmsResultConstant.SUCCESS, count); + } + + @ApiOperation(value = "删除专题") + @RequiresPermissions("cms:topic:delete") + @RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET) + @ResponseBody + public Object delete(@PathVariable("ids") String ids) { + int count = cmsTopicService.deleteByPrimaryKeys(ids); + return new CmsResult(CmsResultConstant.SUCCESS, count); + } + + @ApiOperation(value = "修改专题") + @RequiresPermissions("cms:topic:update") + @RequestMapping(value = "/update/{id}", method = RequestMethod.GET) + public String update(@PathVariable("id") int id, ModelMap modelMap) { + CmsTopic topic = cmsTopicService.selectByPrimaryKey(id); + modelMap.put("topic", topic); + return "/manage/topic/update"; + } + + @ApiOperation(value = "修改专题") + @RequiresPermissions("cms:topic:update") + @RequestMapping(value = "/update/{id}", method = RequestMethod.POST) + @ResponseBody + public Object update(@PathVariable("id") int id, CmsTopic cmsTopic) { + ComplexResult result = FluentValidator.checkAll() + .on(cmsTopic.getTitle(), new LengthValidator(1, 100, "标题")) + .doValidate() + .result(ResultCollectors.toComplex()); + if (!result.isSuccess()) { + return new CmsResult(CmsResultConstant.INVALID_LENGTH, result.getErrors()); + } + cmsTopic.setTopicId(id); + int count = cmsTopicService.updateByPrimaryKeySelective(cmsTopic); + return new CmsResult(CmsResultConstant.SUCCESS, count); + } + +} \ No newline at end of file