187 lines
4.7 KiB
Plaintext
187 lines
4.7 KiB
Plaintext
package com.bonus.sys.controller;
|
|
|
|
import java.util.List;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import com.bonus.sys.AjaxRes;
|
|
import com.bonus.sys.BaseController;
|
|
import com.bonus.sys.GlobalConst;
|
|
import com.bonus.sys.Page;
|
|
import com.bonus.sys.beans.NewRoleBean;
|
|
import com.bonus.sys.beans.ZNode;
|
|
import com.bonus.sys.service.NewRoleService;
|
|
|
|
@Controller
|
|
@RequestMapping("/backstage/newRole/")
|
|
public class NewRoleController extends BaseController<NewRoleBean> {
|
|
|
|
@Autowired
|
|
private NewRoleService service;
|
|
|
|
@RequestMapping("list")
|
|
public String index(Model model) {
|
|
return "/sys/newRole";
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "findAll")
|
|
@ResponseBody
|
|
public AjaxRes findAll() {
|
|
AjaxRes ar = getAjaxRes();
|
|
try {
|
|
List<ZNode> list = service.getNewRoleInfo();
|
|
if (list != null) {
|
|
for (ZNode bean : list) {
|
|
bean.setIcon(getRequest().getContextPath()
|
|
+ "/static/css/sys/images/user_group.gif");
|
|
}
|
|
}
|
|
ar.setSucceed(list);
|
|
} catch (Exception e) {
|
|
logger.error(e.toString(), e);
|
|
ar.setFailMsg(GlobalConst.DATA_FAIL);
|
|
}
|
|
return ar;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* @Author 姜山
|
|
* @Date 2019-08-15
|
|
* @function 获取角色列表
|
|
* @param o
|
|
* @return
|
|
*/
|
|
@RequestMapping(value = "findByPage", method = RequestMethod.POST)
|
|
public String findByPage(@RequestBody Page<NewRoleBean> page, NewRoleBean o,Model model) {
|
|
try {
|
|
o = page.getObj();
|
|
|
|
page = service.findByPage(o, page);
|
|
model.addAttribute("page", page);
|
|
}catch(Exception e) {
|
|
System.out.println("角色列表获取错误!");
|
|
e.printStackTrace();
|
|
}
|
|
return "/sys/newRoleList";
|
|
}
|
|
|
|
|
|
/**
|
|
* @Author 姜山
|
|
* @Date 2019-08-16
|
|
* @function 前往新增角色页面
|
|
* @param o
|
|
* @return
|
|
*/
|
|
@RequestMapping("toAddRole")
|
|
public String toAddActivity(NewRoleBean o,Model model) {
|
|
return "/sys/newRoleAdd";
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @Author 姜山
|
|
* @Date 2019-08-16
|
|
* @function 新增角色
|
|
* @param o
|
|
* @return
|
|
*/
|
|
@RequestMapping(value = "add", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public synchronized AjaxRes addRole(@RequestBody NewRoleBean o,HttpServletRequest request){
|
|
AjaxRes ar = getAjaxRes();
|
|
int res = 0;
|
|
try {
|
|
res = service.insertBean(o);
|
|
if( res == 1 ){
|
|
ar.setRes(GlobalConst.SUCCEED);
|
|
ar.setResMsg("添加成功!");
|
|
}else{
|
|
ar.setRes(GlobalConst.FAIL);
|
|
ar.setResMsg("添加名称重复,请更换名称!");
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
logger.error(e.toString(), e);
|
|
ar.setResMsg("添加失败!");
|
|
|
|
}
|
|
return ar;
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "del", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public AjaxRes del(@RequestBody NewRoleBean o) {
|
|
AjaxRes ar = getAjaxRes();
|
|
int res = 0 ;
|
|
try {
|
|
res = service.deleteBean(o);
|
|
if(res == 1){
|
|
ar.setRes(GlobalConst.SUCCEED);
|
|
ar.setResMsg("删除成功!");
|
|
}else{
|
|
ar.setResMsg("已添加采购明细无法删除!");
|
|
}
|
|
} catch (Exception e) {
|
|
logger.error(e.toString(), e);
|
|
ar.setResMsg("删除失败!");
|
|
}
|
|
return ar;
|
|
}
|
|
|
|
/**
|
|
* @Author 姜山
|
|
* @Date 2019-08-18
|
|
* @function 前往添加页面
|
|
* @param o
|
|
* @return
|
|
*/
|
|
@RequestMapping("toRoleInfo")
|
|
public String toAddActivity(NewRoleBean o,Model model,HttpServletRequest request) {
|
|
o = service.getRoleInfoById(o);
|
|
model.addAttribute("role", o);
|
|
return "/sys/newRoleAdd";
|
|
}
|
|
|
|
/**
|
|
* @Author 姜山
|
|
* @Date 2019-08-18
|
|
* @function 修改信息
|
|
* @param o
|
|
* @return
|
|
*/
|
|
@RequestMapping(value = "update", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public AjaxRes updateRole(@RequestBody NewRoleBean o,HttpServletRequest request){
|
|
AjaxRes ar = getAjaxRes();
|
|
try {
|
|
int result = service.updateBean(o);
|
|
if(result == 1) {
|
|
ar.setRes(GlobalConst.SUCCEED);
|
|
ar.setResMsg("修改成功!");
|
|
}else {
|
|
ar.setResMsg("修改失败!");
|
|
}
|
|
} catch (Exception e) {
|
|
logger.error(e.toString(), e);
|
|
ar.setResMsg("修改失败!");
|
|
}
|
|
return ar;
|
|
}
|
|
}
|