111
Jinquan_Ou
2023-04-08 1836f7863882ceae0e5c246556196be48bd12384
zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java
@@ -6,7 +6,9 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZfEvent;
@@ -19,8 +21,10 @@
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
@@ -102,6 +106,7 @@
                    UserRelationDto userRelationDto = new UserRelationDto();
                    BeanUtils.copyProperties(otherUser,userRelationDto);
                    userRelationDto.setRelation(relation.getRelation());
                    userRelationDto.setId(relation.getId());
                    otherUserList.add(userRelationDto);
                    return relation;
                }
@@ -109,4 +114,53 @@
        return AjaxResult.success(otherUserList);
    }
    /**
     * 检查传入对方的id是否存在
     * @param zfRelation
     */
    private void checkRelation(ZfRelation zfRelation){
        LambdaQueryWrapper<ZInfoUser> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZInfoUser::getUserId, zfRelation.getOtherId());
        ZInfoUser zInfoUser2 = getOne(lqw);
        if (zInfoUser2==null){
            throw new RuntimeException("对方的id不存在");
        }
    }
    @Override
    @Transactional
    public AjaxResult addRelation(ZfRelation zfRelation) {
        checkRelation(zfRelation);
        //获取自己的id并传入
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
        zfRelation.setMyId(userId);
        zfRelationService.save(zfRelation);
        return AjaxResult.success();
    }
    @Override
    @Transactional
    public AjaxResult updateRelation(ZfRelation zfRelation) {
        checkRelation(zfRelation);
        zfRelationService.updateById(zfRelation);
        return AjaxResult.success();
    }
    @Override
    public AjaxResult deleteRelation(Long[] ids) {
        boolean flag = zfRelationService.removeByIds(Arrays.asList(ids));
        if (flag){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
}