package com.ruoyi.app.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.app.annotation.LoginAppUser; import com.ruoyi.app.controller.base.AppBaseController; import com.ruoyi.app.domain.TbAppUser; import com.ruoyi.app.domain.TbMyProfile; import com.ruoyi.app.domain.vo.AppMemberVo; import com.ruoyi.app.service.ITbMyProfileService; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.StringUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.List; /** * 个人详情 * * @author Alex * @date 2020-10-11 */ @Api(value = "个人详情",tags = "个人详情") @RequiredArgsConstructor(onConstructor_ = @Autowired) @RestController @RequestMapping("/app/profile" ) public class MyProfileController extends AppBaseController { private final ITbMyProfileService profileService; @ApiOperation("个人详情列表") @ApiImplicitParam(name = "appUserId", value = "会员ID",paramType="Long") @GetMapping("/list") public AjaxResult list(Long appUserId) { if (appUserId == null){ return AjaxResult.error("参数为空"); } List profileList = profileService.list(new LambdaQueryWrapper() .eq(TbMyProfile::getAppUserId, appUserId) ); return AjaxResult.success(profileList); } @ApiOperation("添加/修改个人详情") @PostMapping("/saveOrUpdate") public AjaxResult saveOrUpdate(@RequestBody TbMyProfile profile) { if (StringUtils.isBlank(profile.getTitle()) || StringUtils.isBlank(profile.getCotents())) { return AjaxResult.error("标题或内容不能为空"); } if (profile.getAppUserId() == null) { return AjaxResult.error("参数异常"); } AppMemberVo user = getLoginUser().getUser(); Date date = new Date(); //新增 if (profile.getId() == null) { profile.setCreateBy(user.getUserId()); profile.setCreateTime(date); return toAjax(profileService.save(profile) ? 1 : 0); } else { // 修改 profile.setUpdateBy(user.getUserId()); profile.setUpdateTime(date); return toAjax(profileService.updateById(profile) ? 1 : 0); } } @ApiOperation("获取个人详情") @ApiImplicitParam(name = "id", value = "主键id",paramType="Long") @GetMapping("/get") public AjaxResult get(Long id){ if (id == null){ return AjaxResult.error("id不能为空"); } return AjaxResult.success(profileService.getById(id)); } @ApiOperation("删除个人详情") @ApiImplicitParam(name = "id", value = "主键id",paramType="Long") @GetMapping("/del") public AjaxResult del(Long id) { if (id == null){ return AjaxResult.error("id不能为空"); } return toAjax(profileService.removeById(id) ? 1 : 0); } }