diff --git a/src/main/java/club/joylink/rtss/controller/permission2/SystemAbilityController.java b/src/main/java/club/joylink/rtss/controller/permission2/SystemAbilityController.java index 2ca71eb68..bfadea763 100644 --- a/src/main/java/club/joylink/rtss/controller/permission2/SystemAbilityController.java +++ b/src/main/java/club/joylink/rtss/controller/permission2/SystemAbilityController.java @@ -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 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 PageVOfindByPage(FindAbilityBasicByPageReqVo req){ - return null; + public PageVOfindByPage(FindAbilityBasicByPageReqVo req){ + return this.abilityService.findByPage(req); } } diff --git a/src/main/java/club/joylink/rtss/services/permission/SystemAbilityService.java b/src/main/java/club/joylink/rtss/services/permission/SystemAbilityService.java index df7bd88fc..1c7c5191d 100644 --- a/src/main/java/club/joylink/rtss/services/permission/SystemAbilityService.java +++ b/src/main/java/club/joylink/rtss/services/permission/SystemAbilityService.java @@ -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 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 page = (Page) this.systemAbilityDAO.selectByExample(example); + List questionVOS = SystemAbilityRspVo.convert2VOList(page.getResult()); + return PageVO.convert(page, questionVOS); + } + } diff --git a/src/main/java/club/joylink/rtss/vo/permission/AddAbilityReqVo.java b/src/main/java/club/joylink/rtss/vo/permission/AddAbilityReqVo.java deleted file mode 100644 index f0adf94ea..000000000 --- a/src/main/java/club/joylink/rtss/vo/permission/AddAbilityReqVo.java +++ /dev/null @@ -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; -} diff --git a/src/main/java/club/joylink/rtss/vo/permission/BasicSystemAbilityVo.java b/src/main/java/club/joylink/rtss/vo/permission/BasicSystemAbilityVo.java new file mode 100644 index 000000000..c220d6d35 --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/permission/BasicSystemAbilityVo.java @@ -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; + } +} diff --git a/src/main/java/club/joylink/rtss/vo/permission/SystemAbilityRspVo.java b/src/main/java/club/joylink/rtss/vo/permission/SystemAbilityRspVo.java index 2b6df7163..85cd44b7d 100644 --- a/src/main/java/club/joylink/rtss/vo/permission/SystemAbilityRspVo.java +++ b/src/main/java/club/joylink/rtss/vo/permission/SystemAbilityRspVo.java @@ -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 convert2VOList(List list){ + List voList = Lists.newArrayList(); + for (SystemAbility sa : list) { + voList.add(toVO(sa)); + } + return voList; + } }