zqy
2024-07-21 94b1a3bde93ad87f9347d8a08d70dd4f2318f1ce
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorShareServiceImpl.java
@@ -1,15 +1,17 @@
package com.ruoyi.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.ShareMore;
import com.ruoyi.domain.ZfDoctor;
import com.ruoyi.domain.ZfDoctorShare;
import com.ruoyi.domain.*;
import com.ruoyi.mapper.ZfDoctorShareMapper;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfDoctorService;
import com.ruoyi.service.ZfDoctorShareService;
import lombok.extern.slf4j.Slf4j;
@@ -19,12 +21,18 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import static com.alibaba.druid.sql.PagerUtils.limit;
@Slf4j
@Service
public class ZfDoctorShareServiceImpl extends ServiceImpl<ZfDoctorShareMapper, ZfDoctorShare> implements ZfDoctorShareService {
    @Resource
    private ZfDoctorService zfDoctorService;
    @Resource
    private ZInfoUserService zInfoUserService;
    private LambdaQueryWrapper<ZfDoctorShare> uniqueCondition(ZfDoctorShare zfDoctorShare) {
        LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
@@ -69,7 +77,7 @@
        for (Long shareId : shareIds) {
            for (Long shareContent : shareContents) {
                ZfDoctorShare za = new ZfDoctorShare();
                za.setUserId(zfDoctor.getUserId());
                za.setUserId(getUserId());
                za.setShareContent(shareContent);
                za.setShareId(shareId);
                addData(za);
@@ -87,7 +95,7 @@
     * 根据UserId和分享人shareId查看已经授权给那些人那些数据
     */
    @Override
    public AjaxResult listByFidAid(ShareMore zfDoctor) {
    public AjaxResult listByFidAid(ShareMore zfDoctor,Integer pageNo ,Integer pageSize) {
        //找到对应的赋予数据的用户以及数据内容
        Long [] shareIds = zfDoctor.getShareIds();
        List<ZfDoctor> beanRecord3 = new ArrayList<>();
@@ -95,16 +103,21 @@
            {
                LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
                lqw.eq(ZfDoctorShare::getShareId,shareId)
                        .eq(ZfDoctorShare::getUserId, zfDoctor.getUserId());
                        .eq(ZfDoctorShare::getUserId, getUserId());
                List<ZfDoctorShare> beanRecords = list(lqw);
                for (ZfDoctorShare beanRecord : beanRecords ) {
                    beanRecord3.add(zfDoctorService.getById(beanRecord.getShareContent()));
                }
            }
        }
        log.info("从数据库中查到的为:{}", beanRecord3);
        List<ZfDoctor>  record =  beanRecord3.stream().skip((pageNo-1)*pageSize).limit(pageSize).collect(Collectors.toList());
        return AjaxResult.success(beanRecord3);
        int totalPage = (beanRecord3.size() -1) / pageSize +1;
        Page<ZfDoctor> zfDoctorPage = new Page<>(pageNo, pageSize,totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(zfDoctorPage, record);
        return AjaxResult.success(data);
    }
    @Override
@@ -117,7 +130,7 @@
                LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
                lqw.eq(ZfDoctorShare::getShareId,shareId)
                        .eq(ZfDoctorShare::getShareContent, shareContent)
                        .eq(ZfDoctorShare::getUserId, zfDoctor.getUserId());
                        .eq(ZfDoctorShare::getUserId, getUserId());
                zfDoctorShareService.remove(lqw);
                //   addData(za);
@@ -130,28 +143,30 @@
     * 用户自己查看别人分享的数据和分享人
     */
    @Override
    public AjaxResult listByUserId(Long shareId) {
    public AjaxResult listByUserId() {
        //找到对应的赋予数据的用户以及数据内容
        HashMap<Long,ZfDoctor>  bs = new HashMap<>();
        HashMap<Long,List<ZfDoctor>>  bs = new HashMap<>();
        LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfDoctorShare::getShareId,shareId);
        lqw.eq(ZfDoctorShare::getShareId,getUserId());
        List<ZfDoctorShare> beanRecords = list(lqw);
        List<ZfDoctor> b1 = new ArrayList<>();
        for (ZfDoctorShare beanRecord : beanRecords ) {
            bs.put(beanRecord.getUserId(),zfDoctorService.getById(beanRecord.getShareContent()));
                b1.add(zfDoctorService.getById(beanRecord.getShareContent()));
                bs.put(beanRecord.getUserId(),b1);
        }
        log.info("从数据库中查到的为:{}", bs);
        return AjaxResult.success(bs);
    }
    /**
     * 用户自己查看别人分享的数据
     * 用户自己查看别人分享的数据==用户自己查看别人分享的数据和分享人
     */
    @Override
    public List<ZfDoctor> listUserId(Long shareId) {
    public AjaxResult listUserId(Integer pageNo ,Integer pageSize) {
        //找到对应的赋予数据的用户以及数据内容
        List<ZfDoctor>  bs = new ArrayList<>();
        LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfDoctorShare::getShareId,shareId);
        lqw.eq(ZfDoctorShare::getShareId,getUserId());
        List<ZfDoctorShare> beanRecords = list(lqw);
        for (ZfDoctorShare beanRecord : beanRecords ) {
            ZfDoctor bs2 = zfDoctorService.getById(beanRecord.getShareContent());
@@ -159,9 +174,32 @@
            bs.add(bs2);
        }
        log.info("从数据库中查到的为:{}", bs);
        return bs;
        List<ZfDoctor>  record = bs.stream().skip((pageNo-1)*pageSize).limit(pageSize).collect(Collectors.toList());
        int totalPage = (bs.size() -1) / pageSize +1;
        Page<ZfDoctor> zfDoctorPage = new Page<>(pageNo, pageSize,totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(zfDoctorPage, record);
        return AjaxResult.success(data);
    }
    public Long getUserId(){
        ZInfoUser myself = zInfoUserService.getMyself();
        return myself.getUserId();
    }
    @Override
    public Long getShareId(ZfDoctorDownload zfDoctorDownload){
        LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfDoctorShare::getShareId,zfDoctorDownload.getDownloadId())
                .eq(ZfDoctorShare::getShareContent,zfDoctorDownload.getDownloadContent());
        List<ZfDoctorShare> beanRecords = list(lqw);
        if (beanRecords.size() != 0){
            return beanRecords.get(0).getUserId();
        }
        else {
            return null;
        }
    }
}