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.*;
|
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;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
|
@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<>();
|
lqw.eq(StringUtils.isNotEmpty(String.valueOf(zfDoctorShare.getShareId())), ZfDoctorShare::getShareId, zfDoctorShare.getShareId());
|
lqw.eq(StringUtils.isNotEmpty(String.valueOf(zfDoctorShare.getShareContent())), ZfDoctorShare::getShareContent, zfDoctorShare.getShareContent());
|
return lqw;
|
}
|
@Override
|
public List<ZfDoctorShare> getAuthority() {
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
Long userId = user.getUserId();
|
|
LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(ZfDoctorShare::getShareId,userId);
|
|
return list(lqw);
|
}
|
|
@Resource
|
ZfDoctorShareService zfDoctorShareService;
|
|
public void addData(ZfDoctorShare za)
|
{
|
LambdaQueryWrapper<ZfDoctorShare> lqw = uniqueCondition(za);
|
List<ZfDoctorShare> list = list(lqw);
|
|
if(list.size()>0){
|
throw new RuntimeException("请勿分享重复数据");
|
}
|
else {
|
zfDoctorShareService.save(za);
|
}
|
|
}
|
|
|
@Override
|
public AjaxResult saveZa(ShareMore zfDoctor) {
|
// boolean bl = zAuthorityService.saveOrUpdate(zAuthority);
|
Long [] shareIds = zfDoctor.getShareIds();
|
Long [] shareContents = zfDoctor.getShareContents();
|
for (Long shareId : shareIds) {
|
for (Long shareContent : shareContents) {
|
ZfDoctorShare za = new ZfDoctorShare();
|
za.setUserId(getUserId());
|
za.setShareContent(shareContent);
|
za.setShareId(shareId);
|
addData(za);
|
}
|
}
|
// Long []
|
// if(bl)
|
return AjaxResult.success("分享成功!");
|
// else
|
// return AjaxResult.error("权限新增失败!");
|
|
|
}
|
/**
|
* 根据UserId和分享人shareId查看已经授权给那些人那些数据
|
*/
|
@Override
|
public List<Long> listByFidAid(ShareMore zfDoctor) {
|
//找到对应的赋予数据的用户以及数据内容
|
Long [] shareIds = zfDoctor.getShareIds();
|
List<Long> beanRecord3 = new ArrayList<>();
|
for (Long shareId : shareIds) {
|
{
|
LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(ZfDoctorShare::getShareId,shareId)
|
.eq(ZfDoctorShare::getUserId, getUserId());
|
List<ZfDoctorShare> beanRecords = list(lqw);
|
for (ZfDoctorShare beanRecord : beanRecords ) {
|
beanRecord3.add(beanRecord.getShareContent());
|
}
|
}
|
}
|
|
return beanRecord3;
|
}
|
|
@Override
|
public AjaxResult deleteZa(ShareMore zfDoctor) {
|
Long [] shareIds = zfDoctor.getShareIds();
|
Long [] shareContents = zfDoctor.getShareContents();
|
for(Long shareId : shareIds)
|
for(Long shareContent: shareContents)
|
{
|
LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(ZfDoctorShare::getShareId,shareId)
|
.eq(ZfDoctorShare::getShareContent, shareContent)
|
.eq(ZfDoctorShare::getUserId, getUserId());
|
|
zfDoctorShareService.remove(lqw);
|
// addData(za);
|
}
|
return AjaxResult.success("数据收回成功!");
|
|
}
|
|
/**
|
* 用户自己查看别人分享的数据和分享人
|
*/
|
@Override
|
public AjaxResult listByUserId() {
|
//找到对应的赋予数据的用户以及数据内容
|
HashMap<Long,List<ZfDoctor>> bs = new HashMap<>();
|
LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(ZfDoctorShare::getShareId,getUserId());
|
List<ZfDoctorShare> beanRecords = list(lqw);
|
List<ZfDoctor> b1 = new ArrayList<>();
|
for (ZfDoctorShare beanRecord : beanRecords ) {
|
b1.add(zfDoctorService.getById(beanRecord.getShareContent()));
|
bs.put(beanRecord.getUserId(),b1);
|
}
|
log.info("从数据库中查到的为:{}", bs);
|
return AjaxResult.success(bs);
|
|
}
|
/**
|
* 用户自己查看别人分享的数据==用户自己查看别人分享的数据和分享人
|
*/
|
@Override
|
public AjaxResult listUserId() {
|
//找到对应的赋予数据的用户以及数据内容
|
List<ZfDoctor> bs = new ArrayList<>();
|
LambdaQueryWrapper<ZfDoctorShare> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(ZfDoctorShare::getShareId,getUserId());
|
List<ZfDoctorShare> beanRecords = list(lqw);
|
for (ZfDoctorShare beanRecord : beanRecords ) {
|
ZfDoctor bs2 = zfDoctorService.getById(beanRecord.getShareContent());
|
bs2.setShareId(beanRecord.getUserId());
|
bs.add(bs2);
|
}
|
log.info("从数据库中查到的为:{}", bs);
|
return AjaxResult.success(bs);
|
|
}
|
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;
|
}
|
}
|
|
}
|