功能管理相关管理
This commit is contained in:
parent
76066aa2dd
commit
603cd9d0e8
@ -1,10 +1,13 @@
|
||||
package club.joylink.rtss.controller.permission2;
|
||||
|
||||
import club.joylink.rtss.services.permission.SystemAbilityService;
|
||||
import club.joylink.rtss.vo.LoginUserInfoVO;
|
||||
import club.joylink.rtss.vo.client.PageVO;
|
||||
import club.joylink.rtss.vo.permission.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 面向权限的系统功能管理接口V2
|
||||
@ -13,56 +16,57 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/permission/system/ability")
|
||||
public class SystemAbilityController {
|
||||
|
||||
@Autowired
|
||||
private SystemAbilityService abilityService;
|
||||
/**
|
||||
* 添加权限功能
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public AddAbilityRspVo addAbility(@RequestBody AddAbilityReqVo req){
|
||||
return null;
|
||||
@PostMapping("/basic")
|
||||
public void addAbility(@RequestBody BasicSystemAbilityVo req, @RequestAttribute LoginUserInfoVO userInfoVO){
|
||||
this.abilityService.saveOrUpdateBasicAbility(req,userInfoVO);
|
||||
}
|
||||
/**
|
||||
* 修改权限功能的名称和描述
|
||||
*/
|
||||
@PutMapping("/basic")
|
||||
public void updateAbilityBasic(@RequestBody UpdateAbilityBasicReqVo req){
|
||||
|
||||
public void updateAbilityBasic(@RequestBody BasicSystemAbilityVo req,@RequestAttribute LoginUserInfoVO userInfoVO){
|
||||
this.abilityService.saveOrUpdateBasicAbility(req,userInfoVO);
|
||||
}
|
||||
/**
|
||||
* 修改权限功能的类型和关联的具体功能
|
||||
*/
|
||||
@PutMapping("/function")
|
||||
public void updateAbilityTypeAndFunc(@RequestBody UpdateAbilityFunctionReqVo req){
|
||||
|
||||
this.abilityService.updateTypeAndFunc(req);
|
||||
}
|
||||
/**
|
||||
* 设置权限功能的状态
|
||||
*/
|
||||
@PutMapping("/status")
|
||||
/* @PutMapping("/status")
|
||||
public void updateAbilityStatus(@RequestBody UpdateAbilityStatusReqVo req){
|
||||
|
||||
}
|
||||
}*/
|
||||
/**
|
||||
* 删除权限功能,注意对于已经启用的不能删除
|
||||
* @return 返回成功删除的权限功能的id列表
|
||||
*/
|
||||
@DeleteMapping
|
||||
public List<String> deleteAbilities(@RequestBody DeleteAbilitiesReqVo req){
|
||||
return null;
|
||||
public void deleteAbilities(@RequestBody DeleteAbilitiesReqVo req){
|
||||
this.abilityService.remove(req);
|
||||
}
|
||||
/**
|
||||
* 根据权限功能的id查询完整信息
|
||||
*/
|
||||
@GetMapping("/{abilityId}")
|
||||
public SystemAbilityRspVo findById(@PathVariable("abilityId") Long abilityId){
|
||||
return null;
|
||||
return this.abilityService.findVO(abilityId);
|
||||
}
|
||||
/**
|
||||
* 分页查询权限功能的基本信息
|
||||
*/
|
||||
@PostMapping("/find/basic/page")
|
||||
public PageVO<FindAbilityBasicRspVo>findByPage(FindAbilityBasicByPageReqVo req){
|
||||
return null;
|
||||
public PageVO<SystemAbilityRspVo>findByPage(FindAbilityBasicByPageReqVo req){
|
||||
return this.abilityService.findByPage(req);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,121 @@
|
||||
package club.joylink.rtss.services.permission;
|
||||
|
||||
import club.joylink.rtss.dao.permission.SystemAbilityDAO;
|
||||
import club.joylink.rtss.entity.permission.SystemAbility;
|
||||
import club.joylink.rtss.entity.permission.SystemAbilityExample;
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.vo.LoginUserInfoVO;
|
||||
import club.joylink.rtss.vo.client.PageVO;
|
||||
import club.joylink.rtss.vo.permission.*;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static club.joylink.rtss.vo.permission.SystemAbilityStatus.Editing;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SystemAbilityService {
|
||||
@Resource
|
||||
private SystemAbilityDAO systemAbilityDAO;
|
||||
|
||||
public SystemAbility findById(Long id){
|
||||
SystemAbility dbSa = this.systemAbilityDAO.selectByPrimaryKey(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(dbSa),"没有找到对应的权限数据");
|
||||
return dbSa;
|
||||
}
|
||||
|
||||
private void checkSameName(String name){
|
||||
SystemAbilityExample example = new SystemAbilityExample();
|
||||
SystemAbilityExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo(name);
|
||||
Long counts = this.systemAbilityDAO.countByExample(example);
|
||||
BusinessExceptionAssertEnum.NAME_REPEAT.assertTrue(counts > 0L,"重复的权限名称");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加修改功能的基础数据
|
||||
* @param vo
|
||||
* @param userInfoVO
|
||||
*/
|
||||
public void saveOrUpdateBasicAbility(BasicSystemAbilityVo vo, LoginUserInfoVO userInfoVO){
|
||||
SystemAbility tmpSa = vo.toSystemAbility();
|
||||
tmpSa.setCreatorId(userInfoVO.getAccountVO().getId());
|
||||
tmpSa.setCreateTime(LocalDateTime.now());
|
||||
tmpSa.setUpdateTime(LocalDateTime.now());
|
||||
if(Objects.nonNull(vo.getId())){
|
||||
SystemAbility dbSa = this.findById(vo.getId());
|
||||
if(Objects.equals(false,Objects.equals(vo.getName(),dbSa.getName()))){
|
||||
this.checkSameName(vo.getName());
|
||||
}
|
||||
tmpSa.setCreateTime(dbSa.getCreateTime());
|
||||
tmpSa.setUpdateTime(LocalDateTime.now());
|
||||
this.systemAbilityDAO.updateByPrimaryKeySelective(tmpSa);
|
||||
}else{
|
||||
this.checkSameName(vo.getName());
|
||||
tmpSa.setStatus(Editing.name());
|
||||
this.systemAbilityDAO.insert(tmpSa);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新类型及对应的类型id
|
||||
* @param vo
|
||||
*/
|
||||
public void updateTypeAndFunc(UpdateAbilityFunctionReqVo vo){
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(vo.getId()),"数据id不能为空");
|
||||
SystemAbility dbSA = this.findById(vo.getId());
|
||||
dbSA.setType(vo.getType().name());
|
||||
dbSA.setAbilityId(vo.getFunctionId());
|
||||
dbSA.setUpdateTime(LocalDateTime.now());
|
||||
this.systemAbilityDAO.updateByPrimaryKeySelective(dbSA);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param reqVo
|
||||
*/
|
||||
public void remove(DeleteAbilitiesReqVo reqVo){
|
||||
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(CollectionUtils.isEmpty(reqVo.getIds()),"删除数据的id不能为空");
|
||||
SystemAbilityExample example = new SystemAbilityExample();
|
||||
SystemAbilityExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andIdIn(reqVo.getIds());
|
||||
this.systemAbilityDAO.deleteByExample(example);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找对应的数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public SystemAbilityRspVo findVO(Long id){
|
||||
SystemAbility sa = this.findById(id);
|
||||
return SystemAbilityRspVo.toVO(sa);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param filterVO
|
||||
* @return
|
||||
*/
|
||||
public PageVO<SystemAbilityRspVo> findByPage(FindAbilityBasicByPageReqVo filterVO){
|
||||
PageHelper.startPage(filterVO.getPageNum(),filterVO.getPageSize());
|
||||
SystemAbilityExample example = new SystemAbilityExample();
|
||||
SystemAbilityExample.Criteria criteria = example.createCriteria();
|
||||
example.setOrderByClause(" id desc ");
|
||||
if(Objects.equals(false,filterVO.getDesc())){
|
||||
example.setOrderByClause(" id asc ");
|
||||
}
|
||||
Page<SystemAbility> page = (Page<SystemAbility>) this.systemAbilityDAO.selectByExample(example);
|
||||
List<SystemAbilityRspVo> questionVOS = SystemAbilityRspVo.convert2VOList(page.getResult());
|
||||
return PageVO.convert(page, questionVOS);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package club.joylink.rtss.vo.permission;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 添加权限功能请求
|
||||
*/
|
||||
@Data
|
||||
public class AddAbilityReqVo {
|
||||
/**
|
||||
* 权限功能名称
|
||||
*/
|
||||
@NotNull
|
||||
private String name;
|
||||
/**
|
||||
* 权限功能描述
|
||||
*/
|
||||
private String des;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package club.joylink.rtss.vo.permission;
|
||||
|
||||
import club.joylink.rtss.entity.permission.SystemAbility;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 添加权限功能请求
|
||||
*/
|
||||
@Data
|
||||
public class BasicSystemAbilityVo {
|
||||
private Long id;
|
||||
/**
|
||||
* 权限功能名称
|
||||
*/
|
||||
@NotNull
|
||||
private String name;
|
||||
/**
|
||||
* 权限功能描述
|
||||
*/
|
||||
private String des;
|
||||
|
||||
public SystemAbility toSystemAbility(){
|
||||
SystemAbility sa = new SystemAbility();
|
||||
sa.setId(this.id);
|
||||
sa.setName(this.name);
|
||||
sa.setDes(this.des);
|
||||
return sa;
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package club.joylink.rtss.vo.permission;
|
||||
|
||||
import club.joylink.rtss.entity.permission.SystemAbility;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SystemAbilityRspVo {
|
||||
@ -50,4 +53,26 @@ public class SystemAbilityRspVo {
|
||||
* 跟新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
public static SystemAbilityRspVo toVO(SystemAbility sa){
|
||||
SystemAbilityRspVo vo = new SystemAbilityRspVo();
|
||||
vo.setId(sa.getId());
|
||||
vo.setType(SystemAbilityType.valueOf(sa.getType()));
|
||||
vo.setAbilityId(sa.getAbilityId());
|
||||
vo.setName(sa.getName());
|
||||
vo.setDes(sa.getDes());
|
||||
vo.setStatus(SystemAbilityStatus.valueOf(sa.getStatus()));
|
||||
vo.setCreatorId(sa.getCreatorId());
|
||||
vo.setCreateTime(sa.getCreateTime());
|
||||
vo.setUpdateTime(sa.getUpdateTime());
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static List<SystemAbilityRspVo> convert2VOList(List<SystemAbility> list){
|
||||
List<SystemAbilityRspVo> voList = Lists.newArrayList();
|
||||
for (SystemAbility sa : list) {
|
||||
voList.add(toVO(sa));
|
||||
}
|
||||
return voList;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user