|
@@ -4,19 +4,28 @@ package com.ruoyi.app.controller;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
import com.ruoyi.app.controller.base.AppBaseController;
|
|
|
+import com.ruoyi.app.domain.TbAppUser;
|
|
|
import com.ruoyi.app.domain.TbFamily;
|
|
|
+import com.ruoyi.app.domain.TbFamilyMember;
|
|
|
import com.ruoyi.app.domain.TbMemberMiddle;
|
|
|
+import com.ruoyi.app.domain.vo.AppMemberVo;
|
|
|
+import com.ruoyi.app.service.ITbAppUserService;
|
|
|
import com.ruoyi.app.service.ITbFamilyService;
|
|
|
import com.ruoyi.app.service.ITbMemberMiddleService;
|
|
|
+import com.ruoyi.common.annotation.Log;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.enums.BusinessType;
|
|
|
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.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
* 家族管理
|
|
@@ -31,14 +40,18 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
public class FamilyController extends AppBaseController {
|
|
|
|
|
|
private final ITbFamilyService familyService;
|
|
|
+ private final ITbAppUserService appUserService;
|
|
|
+ private final ITbMemberMiddleService middleService;
|
|
|
|
|
|
/**
|
|
|
* 查询我的默认家族
|
|
|
*/
|
|
|
@ApiOperation("我的默认家族")
|
|
|
- @ApiImplicitParam(name = "memberId", value = "家族成员ID",paramType="Long")
|
|
|
@GetMapping("/myFamily")
|
|
|
- public AjaxResult myFamily(Long memberId){
|
|
|
+ public AjaxResult myFamily(){
|
|
|
+ TbAppUser user = getLoginUser().getUser();
|
|
|
+ AppMemberVo memberVo = appUserService.getAppMember(user.getId().toString(),"");
|
|
|
+ Long memberId = memberVo.getMemberId();
|
|
|
if (memberId == null) {
|
|
|
return AjaxResult.error("成员id不能为空");
|
|
|
}
|
|
@@ -47,19 +60,59 @@ public class FamilyController extends AppBaseController {
|
|
|
}
|
|
|
|
|
|
@ApiOperation("我的家族列表")
|
|
|
- @ApiImplicitParam(name = "memberId", value = "家族成员ID",paramType="Long")
|
|
|
@GetMapping("/myList")
|
|
|
- public AjaxResult myList(Long memberId){
|
|
|
+ public AjaxResult myList(){
|
|
|
+ TbAppUser user = getLoginUser().getUser();
|
|
|
+ AppMemberVo memberVo = appUserService.getAppMember(user.getId().toString(),"");
|
|
|
+ Long memberId = memberVo.getMemberId();
|
|
|
if (memberId == null) {
|
|
|
return AjaxResult.error("成员id不能为空");
|
|
|
}
|
|
|
return AjaxResult.success(familyService.selectByMemberId(memberId));
|
|
|
}
|
|
|
|
|
|
- //切换家族
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 创建家族
|
|
|
+ */
|
|
|
+ @ApiOperation("创建家族")
|
|
|
+ @PostMapping("/create")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public AjaxResult add(@RequestBody TbFamily tbFamily) {
|
|
|
+ Date date = new Date();
|
|
|
+ tbFamily.setCreateTime(date);
|
|
|
+ tbFamily.setUpdateTime(date);
|
|
|
+ if(!familyService.saveFamily(tbFamily)) {
|
|
|
+ return AjaxResult.error("创建失败");
|
|
|
+ }
|
|
|
+ // 设置添加人为管理员
|
|
|
+ TbAppUser user = getLoginUser().getUser();
|
|
|
+ AppMemberVo memberVo = appUserService.getAppMember(user.getId().toString(),"");
|
|
|
+ appUserService.saveOrUpdate(memberVo);
|
|
|
+ TbMemberMiddle middle = new TbMemberMiddle();
|
|
|
+ middle.setMemberId(memberVo.getMemberId());
|
|
|
+ middle.setFamilyId(tbFamily.getId());
|
|
|
+ middle.setAcquiesce("Y");
|
|
|
+ middle.setAdmin("Y");
|
|
|
+ middle.setStatus("2");
|
|
|
+ if(!middleService.save(middle)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return AjaxResult.error("创建失败");
|
|
|
+ }
|
|
|
+ return AjaxResult.success("创建成功");
|
|
|
+ }
|
|
|
|
|
|
- //家族树
|
|
|
+ @ApiOperation("切换家族")
|
|
|
+ @ApiImplicitParam(name = "familyId", value = "切换的家族ID",paramType="Long")
|
|
|
+ @GetMapping("/change")
|
|
|
+ public AjaxResult change(Long familyId) {
|
|
|
+ TbAppUser user = getLoginUser().getUser();
|
|
|
+ AppMemberVo memberVo = appUserService.getAppMember(user.getId().toString(),"");
|
|
|
+ Long memberId = memberVo.getMemberId();
|
|
|
+ if(familyService.change(memberId,familyId)){
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+ return AjaxResult.error("切换失败");
|
|
|
+ }
|
|
|
|
|
|
- //家族成员
|
|
|
+ // 加入家族
|
|
|
}
|