zqy
5 天以前 b02beccf4567068cb47a3f1181a00039456c872d
zhang-content/src/main/java/com/ruoyi/service/impl/ZfPetSharServiceImpl.java
@@ -5,20 +5,22 @@
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.EsModel;
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.ZfShareMapper;
import com.ruoyi.service.TravelDetailService;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfPetService;
import com.ruoyi.service.ZfPetSharService;
import com.ruoyi.service.*;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -34,6 +36,12 @@
    @Resource
    private ZInfoUserService zInfoUserService;
    @Resource
    private RestHighLevelClient restHighLevelClient;
    @Resource
    EsService esService;
    private LambdaQueryWrapper<ZfShare> uniqueCondition(ZfShare zfShare) {
        LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(String.valueOf(zfShare.getShareId())), ZfShare::getShareId, zfShare.getShareId());
@@ -48,26 +56,24 @@
        Long userId = user.getUserId();
        LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfShare::getShareId,userId);
        lqw.eq(ZfShare::getShareId, userId);
        return list(lqw);
    }
    public Long getUserId(){
    public Long getUserId() {
        ZInfoUser myself = zInfoUserService.getMyself();
        return myself.getUserId();
    }
    public void addData(ZfShare za)
    {
    public void addData(ZfShare za) {
        LambdaQueryWrapper<ZfShare> lqw = uniqueCondition(za);
        List<ZfShare> list = list(lqw);
        if(list.size()>0){
        if (list.size() > 0) {
            throw new RuntimeException("请勿分享重复数据");
        }
        else {
        } else {
            save(za);
        }
@@ -75,8 +81,8 @@
    @Override
    public AjaxResult saveZa(ShareMore shareMore) {
        Long [] shareIds = shareMore.getShareIds();
        Long [] shareContents =  shareMore.getShareContents();
        Long[] shareIds = shareMore.getShareIds();
        Long[] shareContents = shareMore.getShareContents();
        for (Long shareId : shareIds) {
            for (Long shareContent : shareContents) {
                ZfShare za = new ZfShare();
@@ -94,39 +100,38 @@
    @Override
    public AjaxResult listByFidAid(ShareMore shareMore, Integer pageNo, Integer pageSize) {
        Long [] shareIds = shareMore.getShareIds();
        Long[] shareIds = shareMore.getShareIds();
        List<ZfPet> beanRecord3 = new ArrayList<>();
        for (Long shareId : shareIds) {
            {
                LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
                lqw.eq(ZfShare::getShareId,shareId)
                        .eq(ZfShare::getSysMenuId,shareMore.getSysMenuId())
                lqw.eq(ZfShare::getShareId, shareId)
                        .eq(ZfShare::getSysMenuId, shareMore.getSysMenuId())
                        .eq(ZfShare::getUserId, getUserId());
                List<ZfShare> beanRecords = list(lqw);
                for (ZfShare beanRecord : beanRecords ) {
                for (ZfShare beanRecord : beanRecords) {
                    beanRecord3.add(zfPetService.getById(beanRecord.getShareContent()));
                }
            }
        }
        List<ZfPet>  record =  beanRecord3.stream().skip((pageNo-1)*pageSize).limit(pageSize).collect(Collectors.toList());
        List<ZfPet> record = beanRecord3.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        int totalPage = (beanRecord3.size() -1) / pageSize +1;
        int totalPage = (beanRecord3.size() - 1) / pageSize + 1;
        Page<ZfPet> zfPetPage = new Page<>(pageNo, pageSize,totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(zfPetPage, record,beanRecord3.size());
        Page<ZfPet> zfPetPage = new Page<>(pageNo, pageSize, totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(zfPetPage, record, beanRecord3.size());
        return AjaxResult.success(data);
    }
    @Override
    public AjaxResult deleteZa(ShareMore shareMore) {
        Long [] shareIds = shareMore.getShareIds();
        Long [] shareContents =  shareMore.getShareContents();
        for(Long shareId : shareIds)
            for(Long shareContent: shareContents)
            {
        Long[] shareIds = shareMore.getShareIds();
        Long[] shareContents = shareMore.getShareContents();
        for (Long shareId : shareIds)
            for (Long shareContent : shareContents) {
                LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
                lqw.eq(ZfShare::getShareId,shareId)
                lqw.eq(ZfShare::getShareId, shareId)
                        .eq(ZfShare::getShareContent, shareContent)
                        .eq(ZfShare::getSysMenuId, shareMore.getSysMenuId())
                        .eq(ZfShare::getUserId, getUserId());
@@ -139,15 +144,15 @@
    @Override
    public AjaxResult listByUserId() {
        HashMap<Long,List<ZfPet>>  bs = new HashMap<>();
        HashMap<Long, List<ZfPet>> bs = new HashMap<>();
        LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfShare::getShareId,getUserId());
        lqw.eq(ZfShare::getSysMenuId,2022L);
        lqw.eq(ZfShare::getShareId, getUserId());
        lqw.eq(ZfShare::getSysMenuId, 2022L);
        List<ZfShare> beanRecords = list(lqw);
        List<ZfPet> b1 = new ArrayList<>();
        for (ZfShare beanRecord : beanRecords ) {
        for (ZfShare beanRecord : beanRecords) {
            b1.add(zfPetService.getById(beanRecord.getShareContent()));
            bs.put(beanRecord.getUserId(),b1);
            bs.put(beanRecord.getUserId(), b1);
        }
        log.info("从数据库中查到的为:{}", bs);
        return AjaxResult.success(bs);
@@ -155,23 +160,23 @@
    @Override
    public AjaxResult listUserId(Integer pageNo, Integer pageSize) {
        List<ZfPet>  bs = new ArrayList<>();
        List<ZfPet> bs = new ArrayList<>();
        LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfShare::getShareId,getUserId());
        lqw.eq(ZfShare::getSysMenuId,2022L);
        lqw.eq(ZfShare::getShareId, getUserId());
        lqw.eq(ZfShare::getSysMenuId, 2022L);
        List<ZfShare> beanRecords = list(lqw);
        for (ZfShare beanRecord : beanRecords ) {
        for (ZfShare beanRecord : beanRecords) {
            ZfPet bs2 = zfPetService.getById(beanRecord.getShareContent());
            bs2.setShareId(beanRecord.getUserId().intValue());
            bs.add(bs2);
        }
        log.info("从数据库中查到的为:{}", bs);
        List<ZfPet>  record = bs.stream().skip((pageNo-1)*pageSize).limit(pageSize).collect(Collectors.toList());
        List<ZfPet> record = bs.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        int totalPage = (bs.size() -1) / pageSize +1;
        int totalPage = (bs.size() - 1) / pageSize + 1;
        Page<ZfPet> zfPetPage = new Page<>(pageNo, pageSize,totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(zfPetPage, record,bs.size());
        Page<ZfPet> zfPetPage = new Page<>(pageNo, pageSize, totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(zfPetPage, record, bs.size());
        return AjaxResult.success(data);
    }
@@ -182,11 +187,47 @@
                .eq(ZfShare::getShareContent, zfDownload.getDownloadContent())
                .eq(ZfShare::getSysMenuId, zfDownload.getSysMenuId());
        List<ZfShare> beanRecords = list(lqw);
        if (beanRecords.size() != 0){
        if (beanRecords.size() != 0) {
            return beanRecords.get(0).getUserId();
        }
        else {
        } else {
            return null;
        }
    }
    @Override
    public Boolean deleteByContentId(Long[] ids) {
        List<Long> id = new ArrayList<>();
        LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
        lqw.in(ids != null, ZfShare::getShareContent, ids)
                .eq(ZfShare::getSysMenuId, 2022L);
        List<ZfShare> zfShares = list(lqw);
        if (zfShares.size() == 0) {
            return true;
        }
        for (ZfShare zfShare : zfShares) {
            id.add(zfShare.getId());
        }
        System.out.println(id);
        if (removeByIds(id)) {
            //删除es中的数据
            zfShares.forEach(zfDoctorDownload -> {
                EsModel esModel = esService.findByCtId(zfDoctorDownload.getId().intValue(), "宠物分享删除");
                if (esModel != null) {
                    DeleteRequest deleteRequest = new DeleteRequest("allsearchdata", esModel.getId());
                    System.out.println(deleteRequest);
                    try {
                        restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            return true;
        } else {
            return false;
        }
    }
}