MyProfileController.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.ruoyi.app.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.ruoyi.app.annotation.LoginAppUser;
  4. import com.ruoyi.app.controller.base.AppBaseController;
  5. import com.ruoyi.app.domain.TbAppUser;
  6. import com.ruoyi.app.domain.TbMyProfile;
  7. import com.ruoyi.app.domain.vo.AppMemberVo;
  8. import com.ruoyi.app.service.ITbMyProfileService;
  9. import com.ruoyi.common.core.domain.AjaxResult;
  10. import com.ruoyi.common.utils.StringUtils;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiImplicitParam;
  13. import io.swagger.annotations.ApiOperation;
  14. import lombok.RequiredArgsConstructor;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.web.bind.annotation.*;
  17. import java.util.Date;
  18. import java.util.List;
  19. /**
  20. * 个人详情
  21. *
  22. * @author Alex
  23. * @date 2020-10-11
  24. */
  25. @Api(value = "个人详情",tags = "个人详情")
  26. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  27. @RestController
  28. @RequestMapping("/app/profile" )
  29. public class MyProfileController extends AppBaseController {
  30. private final ITbMyProfileService profileService;
  31. @ApiOperation("个人详情列表")
  32. @ApiImplicitParam(name = "appUserId", value = "会员ID",paramType="Long")
  33. @GetMapping("/list")
  34. public AjaxResult list(Long appUserId) {
  35. if (appUserId == null){
  36. return AjaxResult.error("参数为空");
  37. }
  38. List<TbMyProfile> profileList = profileService.list(new LambdaQueryWrapper<TbMyProfile>()
  39. .eq(TbMyProfile::getAppUserId, appUserId)
  40. );
  41. return AjaxResult.success(profileList);
  42. }
  43. @ApiOperation("添加/修改个人详情")
  44. @PostMapping("/saveOrUpdate")
  45. public AjaxResult saveOrUpdate(@RequestBody TbMyProfile profile) {
  46. if (StringUtils.isBlank(profile.getTitle()) || StringUtils.isBlank(profile.getCotents())) {
  47. return AjaxResult.error("标题或内容不能为空");
  48. }
  49. if (profile.getAppUserId() == null) {
  50. return AjaxResult.error("参数异常");
  51. }
  52. AppMemberVo user = getLoginUser().getUser();
  53. Date date = new Date();
  54. //新增
  55. if (profile.getId() == null) {
  56. profile.setCreateBy(user.getUserId());
  57. profile.setCreateTime(date);
  58. return toAjax(profileService.save(profile) ? 1 : 0);
  59. } else {
  60. // 修改
  61. profile.setUpdateBy(user.getUserId());
  62. profile.setUpdateTime(date);
  63. return toAjax(profileService.updateById(profile) ? 1 : 0);
  64. }
  65. }
  66. @ApiOperation("获取个人详情")
  67. @ApiImplicitParam(name = "id", value = "主键id",paramType="Long")
  68. @GetMapping("/get")
  69. public AjaxResult get(Long id){
  70. if (id == null){
  71. return AjaxResult.error("id不能为空");
  72. }
  73. return AjaxResult.success(profileService.getById(id));
  74. }
  75. @ApiOperation("删除个人详情")
  76. @ApiImplicitParam(name = "id", value = "主键id",paramType="Long")
  77. @GetMapping("/del")
  78. public AjaxResult del(Long id) {
  79. if (id == null){
  80. return AjaxResult.error("id不能为空");
  81. }
  82. return toAjax(profileService.removeById(id) ? 1 : 0);
  83. }
  84. }