UserZdController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.ruoyi.web.controller;
  2. import java.math.BigDecimal;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.stream.Collectors;
  6. import javax.servlet.http.HttpServletResponse;
  7. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  8. import com.ruoyi.common.utils.SecurityUtils;
  9. import io.swagger.annotations.ApiOperation;
  10. import org.springframework.security.access.prepost.PreAuthorize;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.GetMapping;
  13. import org.springframework.web.bind.annotation.PostMapping;
  14. import org.springframework.web.bind.annotation.PutMapping;
  15. import org.springframework.web.bind.annotation.DeleteMapping;
  16. import org.springframework.web.bind.annotation.PathVariable;
  17. import org.springframework.web.bind.annotation.RequestBody;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import com.ruoyi.common.annotation.Log;
  21. import com.ruoyi.common.core.controller.BaseController;
  22. import com.ruoyi.common.core.domain.AjaxResult;
  23. import com.ruoyi.common.enums.BusinessType;
  24. import com.ruoyi.web.domain.UserZd;
  25. import com.ruoyi.web.service.IUserZdService;
  26. import com.ruoyi.common.utils.poi.ExcelUtil;
  27. import com.ruoyi.common.core.page.TableDataInfo;
  28. /**
  29. * 用户信息-账单Controller
  30. *
  31. * @author shenzx
  32. * @date 2025-09-01
  33. */
  34. @RestController
  35. @RequestMapping("/user/zd")
  36. public class UserZdController extends BaseController
  37. {
  38. private IUserZdService userZdService;
  39. @Autowired
  40. public void setUserZdService(IUserZdService userZdService) {
  41. this.userZdService = userZdService;
  42. }
  43. @GetMapping("balance")
  44. @ApiOperation("余额")
  45. public AjaxResult balance(){
  46. QueryWrapper<UserZd> qw = new QueryWrapper<>();
  47. qw.lambda().eq(UserZd::getUserId, SecurityUtils.getUserId());
  48. List<UserZd> list = userZdService.list(qw);
  49. if (list.isEmpty()) return success(BigDecimal.ZERO);
  50. BigDecimal reduce = list.stream().filter(v -> "1".equals(v.getStatus())).map(UserZd::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
  51. return success(reduce);
  52. }
  53. /**
  54. * 查询用户信息-账单列表
  55. */
  56. @GetMapping("/list")
  57. public TableDataInfo list(UserZd userZd)
  58. {
  59. startPage();
  60. QueryWrapper<UserZd> queryWrapper = new QueryWrapper<>();
  61. queryWrapper.setEntity(userZd);
  62. List<UserZd> userZdList = userZdService.list(queryWrapper);
  63. return getDataTable(userZdList);
  64. }
  65. /**
  66. * 导出用户信息-账单列表
  67. */
  68. @Log(title = "用户信息-账单", businessType = BusinessType.EXPORT)
  69. @PostMapping("/export")
  70. public void export(HttpServletResponse response, UserZd userZd)
  71. {
  72. QueryWrapper<UserZd> queryWrapper = new QueryWrapper<>();
  73. queryWrapper.setEntity(userZd);
  74. List<UserZd> list = userZdService.list(queryWrapper);
  75. ExcelUtil<UserZd> util = new ExcelUtil<>(UserZd.class);
  76. util.exportExcel(response, list, "用户信息-账单数据");
  77. }
  78. /**
  79. * 获取用户信息-账单详细信息
  80. */
  81. @GetMapping(value = "/{id}")
  82. public AjaxResult getInfo(@PathVariable("id") Long id)
  83. {
  84. return success(userZdService.getById(id));
  85. }
  86. /**
  87. * 新增用户信息-账单
  88. */
  89. @Log(title = "用户信息-账单", businessType = BusinessType.INSERT)
  90. @PostMapping
  91. public AjaxResult add(@RequestBody UserZd userZd)
  92. {
  93. userZdService.save(userZd);
  94. return success(userZd);
  95. }
  96. /**
  97. * 修改用户信息-账单
  98. */
  99. @Log(title = "用户信息-账单", businessType = BusinessType.UPDATE)
  100. @PutMapping
  101. public AjaxResult edit(@RequestBody UserZd userZd)
  102. {
  103. userZdService.updateById(userZd);
  104. return success(userZd);
  105. }
  106. /**
  107. * 删除用户信息-账单
  108. */
  109. @Log(title = "用户信息-账单", businessType = BusinessType.DELETE)
  110. @DeleteMapping("/{ids}")
  111. public AjaxResult remove(@PathVariable Long[] ids)
  112. {
  113. return toAjax(userZdService.removeByIds(Arrays.asList(ids)));
  114. }
  115. }