SystemMenuServiceImpl.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.template.services.impl;
  2. import com.template.mapper.SystemMenuMapper;
  3. import com.template.model.pojo.SystemMenu;
  4. import com.template.model.result.CommonResult;
  5. import com.template.model.vo.SystemMenuVo;
  6. import com.template.services.SystemMenuService;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.cache.annotation.CacheEvict;
  10. import org.springframework.cache.annotation.Cacheable;
  11. import org.springframework.stereotype.Service;
  12. import java.util.HashMap;
  13. import java.util.List;
  14. /**
  15. * <p>
  16. * 服务实现类
  17. * </p>
  18. *
  19. * @author ceshi
  20. * @since 2023-03-30
  21. */
  22. @Service
  23. public class SystemMenuServiceImpl extends ServiceImpl<SystemMenuMapper, SystemMenu> implements SystemMenuService {
  24. @Autowired
  25. private SystemMenuMapper systemMenuMapper;
  26. /*
  27. 查询获取所有菜单
  28. * */
  29. @Override
  30. @Cacheable(value = {"getSystemMenus"})
  31. public CommonResult<List<SystemMenu>> getSystemMenus() {
  32. List<SystemMenu> result = systemMenuMapper.selectList(null);
  33. return CommonResult.ok().setResult(result);
  34. }
  35. @Override
  36. //根据参数清除名为roomThirdSetting的缓存
  37. @CacheEvict(value = "getSystemMenus")
  38. public CommonResult insertSystemMenus(SystemMenu systemMenu) {
  39. int result = systemMenuMapper.insert(systemMenu);
  40. return result > 0 ? CommonResult.ok() : CommonResult.fail();
  41. }
  42. @Override
  43. public CommonResult deleteSystemMenu(Integer userID) {
  44. int result = systemMenuMapper.deleteById(Long.valueOf(userID));
  45. return result > 0 ? CommonResult.ok() : CommonResult.fail();
  46. }
  47. @Override
  48. public CommonResult<List<SystemMenu>> getSystemMenusByParentId(Long parentId) {
  49. HashMap<String, Object> map = new HashMap<>();
  50. // 自定义要查询
  51. map.put("menu_parent_id",parentId);
  52. List<SystemMenu> result = systemMenuMapper.selectByMap(map);
  53. return CommonResult.ok().setResult(result);
  54. }
  55. @Override
  56. @CacheEvict(value = "insertPlaybackRecord", allEntries = true)//allEntries清除整个缓存区
  57. public CommonResult<Integer> insertPlaybackRecord(SystemMenu systemMenu) {
  58. Integer result = systemMenuMapper.insert(systemMenu); // 帮我们自动生成id
  59. return CommonResult.ok().setResult(result);// 发现,id会自动回填
  60. }
  61. @Override
  62. @Cacheable("insertPlaybackRecord")
  63. public CommonResult<List<SystemMenu>> getPlaybackRecords() {
  64. List<SystemMenu> result = systemMenuMapper.selectList(null);
  65. return CommonResult.ok().setResult(result);
  66. }
  67. @Override
  68. public CommonResult<List<SystemMenuVo>> getPlaybackRecordBySql() {
  69. List<SystemMenuVo> result = systemMenuMapper.querySystemMenuAll();
  70. return CommonResult.ok().setResult(result);
  71. }
  72. }