SystemMenuCommonlyUsedController.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package com.xjrsoft.module.system.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.bean.BeanUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.github.yulichang.toolkit.MPJWrappers;
  8. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  9. import com.xjrsoft.common.model.result.RT;
  10. import com.xjrsoft.common.page.ConventPage;
  11. import com.xjrsoft.common.page.PageOutput;
  12. import com.xjrsoft.common.utils.VoToColumnUtil;
  13. import com.xjrsoft.module.system.dto.AddSystemMenuCommonlyUsedDto;
  14. import com.xjrsoft.module.system.dto.SystemMenuCommonlyUsedPageDto;
  15. import com.xjrsoft.module.system.dto.UpdateSystemMenuCommonlyUsedDto;
  16. import com.xjrsoft.module.system.entity.SystemMenuCommonlyUsed;
  17. import com.xjrsoft.module.system.service.ISystemMenuCommonlyUsedService;
  18. import com.xjrsoft.module.system.vo.SystemMenuCommonlyUsedPageVo;
  19. import com.xjrsoft.module.system.vo.SystemMenuCommonlyUsedVo;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import lombok.AllArgsConstructor;
  23. import org.springframework.web.bind.annotation.DeleteMapping;
  24. import org.springframework.web.bind.annotation.GetMapping;
  25. import org.springframework.web.bind.annotation.PostMapping;
  26. import org.springframework.web.bind.annotation.PutMapping;
  27. import org.springframework.web.bind.annotation.RequestBody;
  28. import org.springframework.web.bind.annotation.RequestMapping;
  29. import org.springframework.web.bind.annotation.RequestParam;
  30. import org.springframework.web.bind.annotation.RestController;
  31. import javax.validation.Valid;
  32. import java.util.List;
  33. /**
  34. * @title: 常用功能设置
  35. * @Author brealinxx
  36. * @Date: 2024-04-18
  37. * @Version 1.0
  38. */
  39. @RestController
  40. @RequestMapping("/system" + "/systemMenuCommonlyUsed")
  41. @Api(value = "/system" + "/systemMenuCommonlyUsed",tags = "常用功能设置代码")
  42. @AllArgsConstructor
  43. public class SystemMenuCommonlyUsedController {
  44. private final ISystemMenuCommonlyUsedService systemMenuCommonlyUsedService;
  45. @GetMapping(value = "/page")
  46. @ApiOperation(value="常用功能设置列表(分页)")
  47. @SaCheckPermission("systemmenucommonlyused:detail")
  48. public RT<PageOutput<SystemMenuCommonlyUsedPageVo>> page(@Valid SystemMenuCommonlyUsedPageDto dto){
  49. LambdaQueryWrapper<SystemMenuCommonlyUsed> queryWrapper = new LambdaQueryWrapper<>();
  50. queryWrapper
  51. .orderByDesc(SystemMenuCommonlyUsed::getId)
  52. .eq(SystemMenuCommonlyUsed::getCreateUserId, StpUtil.getLoginIdAsLong())
  53. .select(SystemMenuCommonlyUsed.class,x -> VoToColumnUtil.fieldsToColumns(SystemMenuCommonlyUsedPageVo.class).contains(x.getProperty()));
  54. IPage<SystemMenuCommonlyUsed> page = systemMenuCommonlyUsedService.page(ConventPage.getPage(dto), queryWrapper);
  55. PageOutput<SystemMenuCommonlyUsedPageVo> pageOutput = ConventPage.getPageOutput(page, SystemMenuCommonlyUsedPageVo.class);
  56. return RT.ok(pageOutput);
  57. }
  58. @GetMapping(value = "/nopage")
  59. @ApiOperation(value = "常用功能设置列表(不分页)")
  60. @SaCheckPermission("systemmenucommonlyused:detail")
  61. public RT<List<SystemMenuCommonlyUsedPageVo>> noPage(@Valid SystemMenuCommonlyUsedPageDto dto) {
  62. MPJLambdaWrapper<SystemMenuCommonlyUsed> queryWrapper = MPJWrappers.<SystemMenuCommonlyUsed>lambdaJoin()
  63. .distinct()
  64. .orderByDesc(SystemMenuCommonlyUsed::getId)
  65. .select(SystemMenuCommonlyUsed.class, x -> VoToColumnUtil.fieldsToColumns(SystemMenuCommonlyUsedPageVo.class).contains(x.getProperty()))
  66. .select("t.id",SystemMenuCommonlyUsedPageVo::getId)
  67. .select("t1.icon_url",SystemMenuCommonlyUsedPageVo::getIconUrl)
  68. .select("t1.path",SystemMenuCommonlyUsedPageVo::getPath)
  69. .select("t1.remark",SystemMenuCommonlyUsedPageVo::getRemark)
  70. .select("t1.title",SystemMenuCommonlyUsedPageVo::getTitle)
  71. .eq(SystemMenuCommonlyUsed::getCreateUserId, StpUtil.getLoginIdAsLong())
  72. .leftJoin("xjr_menu t1 on t1.id = t.menu_id");
  73. List<SystemMenuCommonlyUsedPageVo> dataList = systemMenuCommonlyUsedService.selectJoinList(SystemMenuCommonlyUsedPageVo.class,queryWrapper);
  74. // List<SystemMenuCommonlyUsedPageVo> treeVoList = TreeUtil.build(dataList);
  75. return RT.ok(dataList);
  76. }
  77. @DeleteMapping
  78. @ApiOperation(value = "删除常用功能设置")
  79. @SaCheckPermission("systemmenucommonlyused:delete")
  80. public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
  81. return RT.ok(systemMenuCommonlyUsedService.removeByMenuId(ids));
  82. }
  83. @GetMapping(value = "/info")
  84. @ApiOperation(value="根据id查询常用功能设置信息")
  85. @SaCheckPermission("systemmenucommonlyused:detail")
  86. public RT<SystemMenuCommonlyUsedVo> info(@RequestParam Long id){
  87. SystemMenuCommonlyUsed systemMenuCommonlyUsed = systemMenuCommonlyUsedService.getById(id);
  88. if (systemMenuCommonlyUsed == null) {
  89. return RT.error("找不到此数据!");
  90. }
  91. return RT.ok(BeanUtil.toBean(systemMenuCommonlyUsed, SystemMenuCommonlyUsedVo.class));
  92. }
  93. @PostMapping
  94. @ApiOperation(value = "新增常用功能设置")
  95. @SaCheckPermission("systemmenucommonlyused:add")
  96. public RT<Boolean> add(@Valid @RequestBody AddSystemMenuCommonlyUsedDto dto){
  97. if(dto.getMenuId() == null){
  98. return RT.error("菜单id缺失");
  99. }
  100. SystemMenuCommonlyUsed systemMenuCommonlyUsed = BeanUtil.toBean(dto, SystemMenuCommonlyUsed.class);
  101. boolean isSuccess = systemMenuCommonlyUsedService.save(systemMenuCommonlyUsed);
  102. return RT.ok(isSuccess);
  103. }
  104. @PutMapping
  105. @ApiOperation(value = "修改常用功能设置")
  106. @SaCheckPermission("systemmenucommonlyused:edit")
  107. public RT<Boolean> update(@Valid @RequestBody UpdateSystemMenuCommonlyUsedDto dto){
  108. SystemMenuCommonlyUsed systemMenuCommonlyUsed = BeanUtil.toBean(dto, SystemMenuCommonlyUsed.class);
  109. return RT.ok(systemMenuCommonlyUsedService.updateById(systemMenuCommonlyUsed));
  110. }
  111. }