zqy
5 天以前 b02beccf4567068cb47a3f1181a00039456c872d
zhang-content/src/main/java/com/ruoyi/service/impl/ZfCollectionShaServiceImpl.java
@@ -4,6 +4,7 @@
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;
@@ -12,9 +13,13 @@
import com.ruoyi.mapper.ZfShareMapper;
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;
@@ -22,7 +27,9 @@
@Slf4j
@Service
public class ZfCollectionShaServiceImpl extends ServiceImpl<ZfShareMapper, ZfShare> implements ZfCollectionShareService {
    @Resource
@@ -30,6 +37,11 @@
    @Resource
    private ZInfoUserService zInfoUserService;
    @Resource
    private RestHighLevelClient restHighLevelClient;
    @Resource
    EsService esService;
    private LambdaQueryWrapper<ZfShare> uniqueCondition(ZfShare zfShare) {
        LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
@@ -80,7 +92,10 @@
                za.setUserId(getUserId());
                za.setShareContent(shareContent);
                za.setShareId(shareId);
                za.setSysMenuId(2018L);
                addData(za);
            }
        }
@@ -109,8 +124,12 @@
        int totalPage = (beanRecord3.size() -1) / pageSize +1;
        Page<ZfCollection> zfCollectionPage = new Page<>(pageNo, pageSize,totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(zfCollectionPage, record,beanRecord3.size());
        return AjaxResult.success(data);
    }
@@ -139,7 +158,10 @@
        HashMap<Long,List<ZfCollection>>  bs = new HashMap<>();
        LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfShare::getShareId,getUserId());
        lqw.eq(ZfShare::getSysMenuId,2018L);
        List<ZfShare> beanRecords = list(lqw);
        List<ZfCollection> b1 = new ArrayList<>();
        for (ZfShare beanRecord : beanRecords ) {
@@ -155,7 +177,9 @@
        List<ZfCollection>  bs = new ArrayList<>();
        LambdaQueryWrapper<ZfShare> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfShare::getShareId,getUserId());
        lqw.eq(ZfShare::getSysMenuId,2018L);
        List<ZfShare> beanRecords = list(lqw);
        for (ZfShare beanRecord : beanRecords ) {
            ZfCollection bs2 = zfCollectionService.getById(beanRecord.getShareContent());
@@ -167,7 +191,10 @@
        int totalPage = (bs.size() -1) / pageSize +1;
        Page<ZfCollection> zfCollectionPage = new Page<>(pageNo, pageSize,totalPage);
        HashMap<String, Object> data = MapUtils.getShareResult(zfCollectionPage, record,bs.size());
        return AjaxResult.success(data);
    }
@@ -186,4 +213,42 @@
            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, 2018L);
        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;
        }
    }
}