汎用バックグラウンド管理システム(5)-ロールインタフェース、実装、コントローラ、
14798 ワード
1.ロールインタフェース
2.ロールインタフェース実装
3.ロールコントローラ
package com.sundablog.service.backend.system.upms.role;
import java.util.List;
import com.sundablog.pojo.AdminRole;
import com.sundablog.pojo.AdminRolePermission;
import com.sundablog.result.LayUiResult;
/**
*
* @ClassName: RoleService
* @Description:
* @author:
* @date: 2018 3 14 6:55:15
*
* @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
*/
public interface RoleService {
/**
*
* @Title: addRole
* @Description:
* @param: @param adminRole
* @param: @return
* @return: int
* @throws
*/
int addRole(AdminRole adminRole);
/**
*
* @Title: updataRole
* @Description:
* @param: @param adminRole
* @param: @return
* @return: int
* @throws
*/
int updataRole(AdminRole adminRole);
/**
*
* @Title: delectRoleByRoleId
* @Description:
* @param: @param roleId
* @param: @return
* @return: int
* @throws
*/
int delectRoleByRoleId(int roleId);
/**
* RoleId
* @Title: selectRoleByRoleId
* @Description: RoleId
* @param: @param roleId
* @param: @return
* @return: AdminRole
* @throws
*/
AdminRole selectRoleByRoleId(int roleId);
/**
*
* @Title: findPagingQuery
* @Description:
* @param: @param page
* @param: @param limit
* @param: @return
* @return: LayUiResult
* @throws
*/
LayUiResult findPagingQuery(int page,int limit);
/**
*
* @Title: selectRole
* @Description: TODO( )
* @param: @return
* @return: List
* @throws
*/
List selectRole();
/**
* id
* @Title: selectRolePermissionByRoleId
* @Description: id
* @param: @param roleId
* @param: @return
* @return: List
* @throws
*/
List selectRolePermissionByRoleId(int roleId);
/**
* ID id
* @Title: addRolePermission
* @Description: ID id
* @param: @param roleId
* @param: @param permissionId
* @param: @return
* @return: int
* @throws
*/
int addRolePermission(int roleId,String permissionId);
}
2.ロールインタフェース実装
package com.sundablog.service.impl.backend.system.upms.role;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sundablog.mapper.AdminRoleMapper;
import com.sundablog.mapper.AdminRolePermissionMapper;
import com.sundablog.pojo.AdminRole;
import com.sundablog.pojo.AdminRoleExample;
import com.sundablog.pojo.AdminRolePermission;
import com.sundablog.pojo.AdminRolePermissionExample;
import com.sundablog.pojo.AdminRolePermissionExample.Criteria;
import com.sundablog.result.LayUiResult;
import com.sundablog.service.backend.system.upms.role.RoleService;
import cn.hutool.core.util.StrUtil;
/**
*
* @ClassName: RoleServiceImpl
* @Description:TODO( )
* @author:
* @date: 2018 3 14 7:02:07
*
* @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
*/
@Service
public class RoleServiceImpl implements RoleService {
@Autowired
private AdminRoleMapper adminRoleMapper;
@Autowired
private AdminRolePermissionMapper adminRolePermissionMapper;
/**
*
* Title: addRole
* Description:
* @param adminRole
* @return
* @see com.sundablog.service.backend.system.upms.role.RoleService#addRole(com.sundablog.pojo.AdminRole)
*/
@Override
public int addRole(AdminRole adminRole) {
int i = adminRoleMapper.insertSelective(adminRole);
return i;
}
/**
*
* Title: updataRole
* Description:
* @param adminRole
* @return
* @see com.sundablog.service.backend.system.upms.role.RoleService#updataRole(com.sundablog.pojo.AdminRole)
*/
@Override
public int updataRole(AdminRole adminRole) {
int i = adminRoleMapper.updateByPrimaryKeySelective(adminRole);
return i;
}
/**
*
* Title: delectRoleByRoleId
* Description:
* @param roleId
* @return
* @see com.sundablog.service.backend.system.upms.role.RoleService#delectRoleByRoleId(int)
*/
@Override
public int delectRoleByRoleId(int roleId) {
int i = adminRoleMapper.deleteByPrimaryKey(roleId);
if (i > 0) {
AdminRolePermissionExample example = new AdminRolePermissionExample();
Criteria criteria = example.createCriteria();
criteria.andRoleIdEqualTo(roleId);
int j = adminRolePermissionMapper.deleteByExample(example);
if (j > 0) {
return j;
} else {
return 0;
}
} else {
return 0;
}
}
/**
* id
* Title: selectRoleByRoleId
* Description:
* @param roleId
* @return
* @see com.sundablog.service.backend.system.upms.role.RoleService#selectRoleByRoleId(int)
*/
@Override
public AdminRole selectRoleByRoleId(int roleId) {
AdminRole adminRole = adminRoleMapper.selectByPrimaryKey(roleId);
return adminRole;
}
/**
*
* Title: findPagingQuery
* Description:
* @param page
* @param limit
* @return
* @see com.sundablog.service.backend.system.upms.role.RoleService#findPagingQuery(int, int)
*/
@Override
public LayUiResult findPagingQuery(int page, int limit) {
PageHelper.startPage(page, limit);
AdminRoleExample example = new AdminRoleExample();
List list = adminRoleMapper.selectByExample(example);
PageInfo pageInfo = new PageInfo<>(list);
LayUiResult layUiResult = new LayUiResult();
layUiResult.setCode(0);
layUiResult.setMsg("");
layUiResult.setCount(pageInfo.getTotal());
layUiResult.setData(list);
return layUiResult;
}
/**
* id
* Title: selectRolePermissionByRoleId
* Description:
* @param roleId
* @return
* @see com.sundablog.service.backend.system.upms.role.RoleService#selectRolePermissionByRoleId(int)
*/
@Override
public List selectRolePermissionByRoleId(int roleId) {
AdminRolePermissionExample example = new AdminRolePermissionExample();
Criteria criteria = example.createCriteria();
criteria.andRoleIdEqualTo(roleId);
List list = adminRolePermissionMapper.selectByExample(example);
return list;
}
/**
* ID id
* Title: addRolePermission
* Description:
* @param roleId
* @param permissionId
* @return
* @see com.sundablog.service.backend.system.upms.role.RoleService#addRolePermission(int, java.lang.String)
*/
@Override
public int addRolePermission(int roleId, String permissionId) {
//
AdminRolePermissionExample example = new AdminRolePermissionExample();
Criteria criteria = example.createCriteria();
criteria.andRoleIdEqualTo(roleId);
int i = adminRolePermissionMapper.deleteByExample(example);
//
List list = StrUtil.split(permissionId, ',');
try {
for (String string : list) {
AdminRolePermission adminRolePermission = new AdminRolePermission();
adminRolePermission.setRoleId(roleId);
adminRolePermission.setPermissionId(Integer.valueOf(string));
adminRolePermissionMapper.insert(adminRolePermission);
}
return 1;
} catch (Exception e) {
return 0;
}
}
/**
*
* Title: selectRole
* Description:
* @return
* @see com.sundablog.service.backend.system.upms.role.RoleService#selectRole()
*/
@Override
public List selectRole() {
AdminRoleExample example = new AdminRoleExample();
List list = adminRoleMapper.selectByExample(example);
return list;
}
}
3.ロールコントローラ
package com.sundablog.controller.backend.system.upms.role;
import java.util.Date;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.databind.deser.Deserializers.Base;
import com.sundablog.pojo.AdminRole;
import com.sundablog.pojo.AdminRolePermission;
import com.sundablog.result.BaseResult;
import com.sundablog.result.LayUiResult;
import com.sundablog.service.backend.system.upms.role.RoleService;
import cn.hutool.setting.Setting;
/**
*
* @ClassName: RoleController
* @Description:
* @author:
* @date: 2018 3 14 7:10:26
*
* @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
*/
@Controller
@RequestMapping("/backend/system/upms/role")
public class RoleController {
@Autowired
private RoleService roleService;
/**
*
* @Title: index
* @Description:
* @param: @return
* @return: String
* @throws
*/
@RequiresPermissions("backend_system_upms_role_index")
@RequestMapping("/index")
public String index() {
return "backend/system/upms/role/index";
}
/**
*
* @Title: addIndex
* @Description:
* @param: @return
* @return: String
* @throws
*/
@RequiresPermissions("backend_system_upms_role_add")
@RequestMapping("/add")
public String addIndex() {
return "backend/system/upms/role/add";
}
/**
*
* @Title: settingIndex
* @Description: TODO( )
* @param: @return
* @return: String
* @throws
*/
@RequiresPermissions("backend_system_upms_role_setting")
@RequestMapping("/setting")
public String settingIndex() {
return "backend/system/upms/role/setting";
}
/**
*
* @Title: delectRole
* @Description:
* @param: @param roleId
* @param: @return
* @return: BaseResult
* @throws
*/
@RequiresPermissions("backend_system_upms_role_delectRole")
@RequestMapping("/delectRole")
@ResponseBody
public BaseResult delectRole(int roleId) {
int i = roleService.delectRoleByRoleId(roleId);
if (i > 0) {
return BaseResult.build(200, BaseResult.delectSuccess);
} else {
return BaseResult.build(201, BaseResult.delectFail);
}
}
/**
*
* @Title: findPagingQuery
* @Description:
* @param: @param page
* @param: @param limit
* @param: @return
* @return: LayUiResult
* @throws
*/
@RequestMapping("/findPagingQuery")
@ResponseBody
public LayUiResult findPagingQuery(@RequestParam(value="page", defaultValue="1") int page,@RequestParam(value="limit", defaultValue="10") int limit) {
LayUiResult result = roleService.findPagingQuery(page, limit);
return result;
}
/**
*
* @Title: selectRole
* @Description:
* @param: @return
* @return: BaseResult
* @throws
*/
@RequestMapping("/selectRole")
@ResponseBody
public BaseResult selectRole() {
List list = roleService.selectRole();
return BaseResult.build(200, "", list);
}
/**
*
* @Title: addRole
* @Description:
* @param: @param adminRole
* @param: @return
* @return: BaseResult
* @throws
*/
@RequestMapping("/addRole")
@ResponseBody
public BaseResult addRole(AdminRole adminRole) {
adminRole.setCtime(new Date());
int i = roleService.addRole(adminRole);
if (i > 0) {
return BaseResult.build(200, BaseResult.addSuccess);
} else {
return BaseResult.build(209, BaseResult.addFail);
}
}
/**
* id
* @Title: selectRolePermissionByRoleId
* @Description: id
* @param: @param roleId
* @param: @return
* @return: BaseResult
* @throws
*/
@RequestMapping("/selectRolePermissionByRoleId")
@ResponseBody
public BaseResult selectRolePermissionByRoleId(int roleId) {
List list = roleService.selectRolePermissionByRoleId(roleId);
return BaseResult.build(200, "", list);
}
/**
* ID id
* @Title: addRolePermission
* @Description: TODO( )
* @param: @param roleId
* @param: @param permissionId
* @param: @return
* @return: BaseResult
* @throws
*/
@RequestMapping("/addRolePermission")
@ResponseBody
public BaseResult addRolePermission(int roleId,String permissionId) {
int i = roleService.addRolePermission(roleId, permissionId);
if (i > 0) {
return BaseResult.build(200, BaseResult.addSuccess);
} else {
return BaseResult.build(209, BaseResult.addFail);
}
}
}