浏览代码

APP: 添加我的家族

Alex 4 年之前
父节点
当前提交
c72d5bdda3

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbAppUserController.java

@@ -170,7 +170,7 @@ public class TbAppUserController extends BaseController {
         List<Long> mIds = new ArrayList<>();
         List<Long> mIds = new ArrayList<>();
         AtomicInteger ck = new AtomicInteger(0);
         AtomicInteger ck = new AtomicInteger(0);
         list.forEach(item -> {
         list.forEach(item -> {
-            if (item.getJoins().equals("Y")) {
+            if ("Y".equals(item.getJoins())) {
                 ck.set(1);
                 ck.set(1);
                 mIds.add(item.getId());
                 mIds.add(item.getId());
             }
             }

+ 10 - 10
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbFamilyController.java

@@ -138,14 +138,14 @@ public class TbFamilyController extends BaseController {
         return toAjax(iTbFamilyService.updateById(tbFamily) ? 1 : 0);
         return toAjax(iTbFamilyService.updateById(tbFamily) ? 1 : 0);
     }
     }
 
 
-    /**
-     * 删除家族
-     */
-    @ApiOperation("删除家族")
-    @PreAuthorize("@ss.hasPermi('system:family:remove')" )
-    @Log(title = "家族" , businessType = BusinessType.DELETE)
-    @DeleteMapping("/{ids}" )
-    public AjaxResult remove(@PathVariable Long[] ids) {
-        return toAjax(iTbFamilyService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
-    }
+//    /**
+//     * 删除家族
+//     */
+//    @ApiOperation("删除家族")
+//    @PreAuthorize("@ss.hasPermi('system:family:remove')" )
+//    @Log(title = "家族" , businessType = BusinessType.DELETE)
+//    @DeleteMapping("/{ids}" )
+//    public AjaxResult remove(@PathVariable Long[] ids) {
+//        return toAjax(iTbFamilyService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+//    }
 }
 }

+ 11 - 0
ruoyi-app/src/main/java/com/ruoyi/app/config/InterceptorConfig.java

@@ -10,6 +10,7 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.web.cors.CorsConfiguration;
 import org.springframework.web.cors.CorsConfiguration;
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
 import org.springframework.web.filter.CorsFilter;
 import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -38,4 +39,14 @@ public class InterceptorConfig implements WebMvcConfigurer {
     public AuthenticationInterceptor authenticationInterceptor() {
     public AuthenticationInterceptor authenticationInterceptor() {
         return new AuthenticationInterceptor();
         return new AuthenticationInterceptor();
     }
     }
+
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        registry.addMapping("/**")
+                .allowedOrigins("*")
+                .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
+                .allowCredentials(true)
+                .maxAge(3600)
+                .allowedHeaders("*");
+    }
 }
 }

+ 42 - 0
ruoyi-app/src/main/java/com/ruoyi/app/controller/FamilyController.java

@@ -1,10 +1,20 @@
 package com.ruoyi.app.controller;
 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.controller.base.AppBaseController;
+import com.ruoyi.app.domain.TbFamily;
+import com.ruoyi.app.domain.TbMemberMiddle;
+import com.ruoyi.app.service.ITbFamilyService;
+import com.ruoyi.app.service.ITbMemberMiddleService;
+import com.ruoyi.common.core.domain.AjaxResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 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.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
@@ -20,4 +30,36 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/app/family" )
 @RequestMapping("/app/family" )
 public class FamilyController extends AppBaseController {
 public class FamilyController extends AppBaseController {
 
 
+    private final ITbFamilyService familyService;
+
+    /**
+     * 查询我的默认家族
+     */
+    @ApiOperation("我的默认家族")
+    @ApiImplicitParam(name = "memberId", value = "家族成员ID",paramType="Long")
+    @GetMapping("/myFamily")
+    public AjaxResult myFamily(Long memberId){
+        if (memberId == null) {
+            return AjaxResult.error("成员id不能为空");
+        }
+        TbFamily family = familyService.myFamily(memberId);
+        return AjaxResult.success(family);
+    }
+
+    @ApiOperation("我的家族列表")
+    @ApiImplicitParam(name = "memberId", value = "家族成员ID",paramType="Long")
+    @GetMapping("/myList")
+    public AjaxResult myList(Long memberId){
+        if (memberId == null) {
+            return AjaxResult.error("成员id不能为空");
+        }
+        return AjaxResult.success(familyService.selectByMemberId(memberId));
+    }
+
+    //切换家族
+
+
+    //家族树
+
+    //家族成员
 }
 }

+ 43 - 10
ruoyi-app/src/main/java/com/ruoyi/app/controller/MyFriendController.java

@@ -56,6 +56,7 @@ public class MyFriendController extends AppBaseController {
         return getDataTable(list);
         return getDataTable(list);
     }
     }
 
 
+
     @ApiOperation("添加好友-搜索")
     @ApiOperation("添加好友-搜索")
     @ApiImplicitParam(name = "searchValue", value = "查询条件:会员号/手机号",paramType="String")
     @ApiImplicitParam(name = "searchValue", value = "查询条件:会员号/手机号",paramType="String")
     @GetMapping("/getByMobile")
     @GetMapping("/getByMobile")
@@ -65,6 +66,8 @@ public class MyFriendController extends AppBaseController {
         }
         }
         return AjaxResult.success(userService.getAppMember(null,searchValue));
         return AjaxResult.success(userService.getAppMember(null,searchValue));
     }
     }
+
+
     @ApiOperation("根据id获取好友")
     @ApiOperation("根据id获取好友")
     @ApiImplicitParam(name = "id", value = "好友id",paramType="Long")
     @ApiImplicitParam(name = "id", value = "好友id",paramType="Long")
     @GetMapping("/getById")
     @GetMapping("/getById")
@@ -75,12 +78,16 @@ public class MyFriendController extends AppBaseController {
         return AjaxResult.success(userService.getAppMember(id.toString(),null));
         return AjaxResult.success(userService.getAppMember(id.toString(),null));
     }
     }
 
 
-    @ApiOperation("添加申请好友")
+
+    @ApiOperation("申请添加好友")
     @PostMapping("/add")
     @PostMapping("/add")
     public AjaxResult add(@RequestBody TbMyFriends friends) {
     public AjaxResult add(@RequestBody TbMyFriends friends) {
-        if (friends.getAppUserId() == null || friends.getFriendsUserId() == null) {
-            return AjaxResult.error("参数异常");
+        if (friends.getFriendsUserId() == null) {
+            return AjaxResult.error("好友id不能为空");
         }
         }
+        // 当前登录人
+        TbAppUser user = getLoginUser().getUser();
+        friends.setAppUserId(user.getId());
         // 查询是否已经存在
         // 查询是否已经存在
         TbMyFriends item = friendsService.getOne(new LambdaQueryWrapper<TbMyFriends>()
         TbMyFriends item = friendsService.getOne(new LambdaQueryWrapper<TbMyFriends>()
                 .nested(
                 .nested(
@@ -92,10 +99,9 @@ public class MyFriendController extends AppBaseController {
                         .eq(TbMyFriends::getFriendsUserId,friends.getAppUserId())
                         .eq(TbMyFriends::getFriendsUserId,friends.getAppUserId())
                 )
                 )
         );
         );
-        TbAppUser user = getLoginUser().getUser();
         // 已存在并已通过
         // 已存在并已通过
         if (item != null && item.getStatus().equals("2")) {
         if (item != null && item.getStatus().equals("2")) {
-            return AjaxResult.success();
+            return AjaxResult.success("好友已添加");
         }
         }
         friends.setStatus("1"); //申请
         friends.setStatus("1"); //申请
         friends.setCreateBy(user.getId().toString());
         friends.setCreateBy(user.getId().toString());
@@ -105,10 +111,7 @@ public class MyFriendController extends AppBaseController {
             friendsService.save(friends);
             friendsService.save(friends);
         }else{
         }else{
             // 已存在未通过
             // 已存在未通过
-            // id为空
-            if (friends.getId() == null) {
-                return AjaxResult.error("申请失败");
-            }
+            friends.setId(item.getId());
             friendsService.updateById(friends);
             friendsService.updateById(friends);
         }
         }
         return AjaxResult.success();
         return AjaxResult.success();
@@ -130,7 +133,7 @@ public class MyFriendController extends AppBaseController {
         pageSize = pageSize == null ? 10 : pageSize;
         pageSize = pageSize == null ? 10 : pageSize;
         PageHelper.startPage(pageNum, pageSize, "create_time desc");
         PageHelper.startPage(pageNum, pageSize, "create_time desc");
         List<TbMyFriends> list = friendsService.list(new LambdaQueryWrapper<TbMyFriends>()
         List<TbMyFriends> list = friendsService.list(new LambdaQueryWrapper<TbMyFriends>()
-                .eq(TbMyFriends::getAppUserId, appUserId)
+                .eq(TbMyFriends::getFriendsUserId, appUserId)
                 .and(
                 .and(
                         i -> i.eq(TbMyFriends::getStatus,"1").or()
                         i -> i.eq(TbMyFriends::getStatus,"1").or()
                         .eq(TbMyFriends::getStatus,"3")
                         .eq(TbMyFriends::getStatus,"3")
@@ -138,4 +141,34 @@ public class MyFriendController extends AppBaseController {
         );
         );
         return getDataTable(list);
         return getDataTable(list);
     }
     }
+
+
+    @ApiOperation("通过申请")
+    @ApiImplicitParam(name = "id", value = "好友id",paramType="Long")
+    @GetMapping("/pass")
+    public AjaxResult pass(Long id){
+        if (id == null) {
+            return AjaxResult.error("好友id不能为空");
+        }
+        TbAppUser user = getLoginUser().getUser();
+        TbMyFriends friends = friendsService.getByUid(id, user.getId());
+        if (friends == null) {
+            return AjaxResult.error("该用户已不存在");
+        }
+        if ("2".equals(friends.getStatus())) {
+            return AjaxResult.error("好友已添加");
+        }
+        friends.setStatus("2");
+        return toAjax(friendsService.updateById(friends) ? 1 : 0);
+    }
+
+    @ApiOperation("删除好友")
+    @ApiImplicitParam(name = "id", value = "好友id",paramType="Long")
+    @DeleteMapping("/del")
+    public AjaxResult del(Long id) {
+        if (id == null) {
+            return AjaxResult.error("id不能为空");
+        }
+        return toAjax(friendsService.removeById(id) ? 1 : 0);
+    }
 }
 }

+ 10 - 0
ruoyi-system/src/main/java/com/ruoyi/app/domain/TbMemberMiddle.java

@@ -64,4 +64,14 @@ public class TbMemberMiddle implements Serializable {
     @ApiModelProperty(value="申请状态 1申请 2同意 3拒绝")
     @ApiModelProperty(value="申请状态 1申请 2同意 3拒绝")
     @Excel(name = "申请状态")
     @Excel(name = "申请状态")
     private String status;
     private String status;
+
+    /** 是否默认  Y是  N否 */
+    @ApiModelProperty(value="是否默认  Y是  N否")
+    @Excel(name = "是否默认  Y是  N否")
+    private String acquiesce;
+
+    /** 是否族长  Y是  N否 */
+    @ApiModelProperty(value="是否族长 Y是  N否")
+    @Excel(name = "是否族长 Y是  N否")
+    private String patriarch;
 }
 }

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/app/mapper/TbFamilyMapper.java

@@ -18,5 +18,6 @@ import java.util.List;
 public interface TbFamilyMapper extends BaseMapper<TbFamily> {
 public interface TbFamilyMapper extends BaseMapper<TbFamily> {
 
 
     List<TbFamily> selectByUserId(@Param("userId") Long uid);
     List<TbFamily> selectByUserId(@Param("userId") Long uid);
+    List<TbFamily> selectByMemberId(@Param("memberId") Long mid);
     List<AppFamilyVo> pageList(@Param(Constants.WRAPPER) LambdaQueryWrapper<TbFamily> wrapper);
     List<AppFamilyVo> pageList(@Param(Constants.WRAPPER) LambdaQueryWrapper<TbFamily> wrapper);
 }
 }

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/app/service/ITbFamilyService.java

@@ -18,6 +18,9 @@ import java.util.List;
 public interface ITbFamilyService extends IService<TbFamily> {
 public interface ITbFamilyService extends IService<TbFamily> {
 
 
     List<TbFamily> selectByUserId(Long uid);
     List<TbFamily> selectByUserId(Long uid);
+    List<TbFamily> selectByMemberId(Long mid);
     List<AppFamilyVo> pageList(LambdaQueryWrapper<TbFamily> wrapper);
     List<AppFamilyVo> pageList(LambdaQueryWrapper<TbFamily> wrapper);
     boolean saveFamily(TbFamily family);
     boolean saveFamily(TbFamily family);
+    TbFamily myFamily(Long memberId);
+    boolean change(Long memberId,Long familyId);
 }
 }

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/app/service/ITbMyFriendsService.java

@@ -14,6 +14,6 @@ import java.util.List;
 public interface ITbMyFriendsService extends IService<TbMyFriends> {
 public interface ITbMyFriendsService extends IService<TbMyFriends> {
 
 
     List<TbMyFriends> pageList(TbMyFriends friends);
     List<TbMyFriends> pageList(TbMyFriends friends);
-    TbMyFriends getByUid(Long userId);
+    TbMyFriends getByUid(Long userId, Long friendId);
 
 
 }
 }

+ 47 - 0
ruoyi-system/src/main/java/com/ruoyi/app/service/impl/TbFamilyServiceImpl.java

@@ -2,7 +2,10 @@ package com.ruoyi.app.service.impl;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.app.domain.TbMemberMiddle;
 import com.ruoyi.app.domain.vo.AppFamilyVo;
 import com.ruoyi.app.domain.vo.AppFamilyVo;
+import com.ruoyi.app.service.ITbMemberMiddleService;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -25,6 +28,8 @@ public class TbFamilyServiceImpl extends ServiceImpl<TbFamilyMapper, TbFamily> i
 
 
     @Autowired
     @Autowired
     private ITbFamilyService familyService;
     private ITbFamilyService familyService;
+    @Autowired
+    private ITbMemberMiddleService middleService;
 
 
     /**
     /**
      * 根据会员id获取家族列表
      * 根据会员id获取家族列表
@@ -35,6 +40,15 @@ public class TbFamilyServiceImpl extends ServiceImpl<TbFamilyMapper, TbFamily> i
     public List<TbFamily> selectByUserId(Long uid) {
     public List<TbFamily> selectByUserId(Long uid) {
         return baseMapper.selectByUserId(uid);
         return baseMapper.selectByUserId(uid);
     }
     }
+    /**
+     * 根据成员id获取家族列表
+     * @param mid
+     * @return
+     */
+    @Override
+    public List<TbFamily> selectByMemberId(Long mid) {
+        return baseMapper.selectByMemberId(mid);
+    }
 
 
     @Override
     @Override
     public List<AppFamilyVo> pageList(LambdaQueryWrapper<TbFamily> wrapper){
     public List<AppFamilyVo> pageList(LambdaQueryWrapper<TbFamily> wrapper){
@@ -50,4 +64,37 @@ public class TbFamilyServiceImpl extends ServiceImpl<TbFamilyMapper, TbFamily> i
         }
         }
         return familyService.updateById(family);
         return familyService.updateById(family);
     }
     }
+
+    @Override
+    public TbFamily myFamily(Long memberId) {
+        TbMemberMiddle middle = middleService.getOne(new LambdaQueryWrapper<TbMemberMiddle>()
+                .eq(TbMemberMiddle::getMemberId, memberId)
+                .eq(TbMemberMiddle::getAcquiesce, "Y")
+        );
+        if (middle == null) {
+            return null;
+        }
+        TbFamily family = familyService.getOne(new LambdaQueryWrapper<TbFamily>()
+                .eq(TbFamily::getId, middle.getFamilyId())
+        );
+        return family;
+    }
+
+    @Override
+    public boolean change(Long memberId,Long familyId) {
+        List<TbMemberMiddle> middleList = middleService.list(new LambdaQueryWrapper<TbMemberMiddle>()
+            .eq(TbMemberMiddle::getMemberId, memberId)
+        );
+        if (middleList.size() <= 0) {
+            return false;
+        }
+        middleList.forEach(item -> {
+            item.setAcquiesce("N");
+            if (familyId.equals(item.getFamilyId())) {
+                item.setAcquiesce("Y");
+            }
+        });
+        return middleService.updateBatchById(middleList);
+    }
+
 }
 }

+ 3 - 2
ruoyi-system/src/main/java/com/ruoyi/app/service/impl/TbMyFriendsServiceImpl.java

@@ -53,9 +53,10 @@ public class TbMyFriendsServiceImpl extends ServiceImpl<TbMyFriendsMapper, TbMyF
     }
     }
 
 
     @Override
     @Override
-    public TbMyFriends getByUid(Long userId) {
+    public TbMyFriends getByUid(Long userId, Long friendId) {
         return baseMapper.selectOne(new LambdaQueryWrapper<TbMyFriends>()
         return baseMapper.selectOne(new LambdaQueryWrapper<TbMyFriends>()
-            .eq(TbMyFriends::getAppUserId, userId)
+                .eq(TbMyFriends::getAppUserId, userId)
+                .eq(TbMyFriends::getFriendsUserId, friendId)
         );
         );
     }
     }
 }
 }

+ 9 - 0
ruoyi-system/src/main/resources/mapper/app/TbFamilyMapper.xml

@@ -43,5 +43,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         left join tb_family_member m on m.id = mi.member_id
         left join tb_family_member m on m.id = mi.member_id
         where m.app_user_id = #{userId}
         where m.app_user_id = #{userId}
     </select>
     </select>
+    <select id="selectByMemberId" resultType="com.ruoyi.app.domain.vo.AppFamilyVo">
+        select f.id,mi.id middle_id,m.id member_id,
+        f.name,f.address,f.contents,f.avatar,f.city,f.code,f.full_name,f.hometown,
+        f.create_by,f.create_time,f.update_by,f.update_time,f.remark
+        from tb_family f
+        left join tb_member_middle mi on f.id = mi.family_id
+        left join tb_family_member m on m.id = mi.member_id
+        where m.id = #{memberId}
+    </select>
 
 
 </mapper>
 </mapper>

+ 2 - 0
ruoyi-system/src/main/resources/mapper/app/TbMemberMiddleMapper.xml

@@ -11,6 +11,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="admin"    column="admin"    />
         <result property="admin"    column="admin"    />
         <result property="parentId"    column="parent_id"    />
         <result property="parentId"    column="parent_id"    />
         <result property="status"    column="status"    />
         <result property="status"    column="status"    />
+        <result property="acquiesce"    column="acquiesce"    />
+        <result property="patriarch"    column="patriarch"    />
     </resultMap>
     </resultMap>