zqy
5 天以前 b02beccf4567068cb47a3f1181a00039456c872d
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorDownloadServiceImpl.java
@@ -1,13 +1,17 @@
package com.ruoyi.service.impl;
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.EsModel;
import com.ruoyi.common.utils.MapUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZfDoctorDownload;
import com.ruoyi.mapper.ZfDoctorDownloadMapper;
import com.ruoyi.domain.ZfDoctor;
import com.ruoyi.domain.ZfDownload;
import com.ruoyi.domain.ZfShare;
import com.ruoyi.mapper.ZfDownloadMapper;
import com.ruoyi.service.*;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.client.RequestOptions;
@@ -16,13 +20,11 @@
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ZfDoctorDownloadServiceImpl extends ServiceImpl<ZfDoctorDownloadMapper, ZfDoctorDownload> implements ZfDoctorDownloadService {
public class ZfDoctorDownloadServiceImpl extends ServiceImpl<ZfDownloadMapper, ZfDownload> implements ZfDoctorDownloadService {
    @Resource
    EsService esService;
@@ -31,56 +33,76 @@
    ZfDoctorShareService zfDoctorShareService;
    @Resource
    ZfDoctorService zfDoctorService;
    @Resource
    ZInfoUserService zInfoUserService;
    @Resource
    private RestHighLevelClient restHighLevelClient;
    private LambdaQueryWrapper<ZfDoctorDownload> buildCondition(ZfDoctorDownload zfDoctorDownload,Long userId) {
        LambdaQueryWrapper<ZfDoctorDownload> lqw = new LambdaQueryWrapper<>();
        lqw.in(ZfDoctorDownload::getDownloadId,userId);
        lqw.orderByDesc(ZfDoctorDownload::getDownloadId);
        lqw.like(zfDoctorDownload.getDownloadId() != null, ZfDoctorDownload::getDownloadId, zfDoctorDownload.getDownloadId())
            .like(zfDoctorDownload.getDownloadContent() != null, ZfDoctorDownload::getDownloadContent, zfDoctorDownload.getDownloadContent());
    private LambdaQueryWrapper<ZfDownload> buildCondition(ZfDownload zfDownload, Long userId) {
        LambdaQueryWrapper<ZfDownload> lqw = new LambdaQueryWrapper<>();
        lqw.in(ZfDownload::getDownloadId,userId);
        lqw.orderByDesc(ZfDownload::getDownloadId);
        lqw.like(zfDownload.getDownloadId() != null, ZfDownload::getDownloadId, zfDownload.getDownloadId())
            .like(zfDownload.getDownloadContent() != null, ZfDownload::getDownloadContent, zfDownload.getDownloadContent())
            .eq( ZfDownload::getSysMenuId, zfDownload.getSysMenuId());
        return lqw;
}
    private LambdaQueryWrapper<ZfDoctorDownload> uniqueCondition(ZfDoctorDownload zfDoctorDownload) {
        LambdaQueryWrapper<ZfDoctorDownload> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(String.valueOf(zfDoctorDownload.getDownloadId())), ZfDoctorDownload::getDownloadId, zfDoctorDownload.getDownloadId())
            .eq(StringUtils.isNotEmpty(String.valueOf(zfDoctorDownload.getDownloadContent())), ZfDoctorDownload::getDownloadContent, zfDoctorDownload.getDownloadContent());
    private LambdaQueryWrapper<ZfDownload> uniqueCondition(ZfDownload zfDownload) {
        LambdaQueryWrapper<ZfDownload> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StringUtils.isNotEmpty(String.valueOf(zfDownload.getDownloadId())), ZfDownload::getDownloadId, zfDownload.getDownloadId())
            .eq(StringUtils.isNotEmpty(String.valueOf(zfDownload.getDownloadContent())), ZfDownload::getDownloadContent, zfDownload.getDownloadContent())
            .eq(ZfDownload::getSysMenuId, zfDownload.getSysMenuId());
        return lqw;
    }
    @Override
    public List<ZfDoctorDownload> selectDoctorList(ZfDoctorDownload zfDoctorDownload , Integer pageNum, Integer pageSize) {
    public AjaxResult selectDoctorList(ZfDownload zfDownload, Integer pageNo , Integer pageSize ) {
        ZInfoUser myself = zInfoUserService.getMyself();
        LambdaQueryWrapper<ZfDoctorDownload> lqw = buildCondition(zfDoctorDownload,myself.getUserId());
        List<ZfDoctorDownload> beanRecords = list(lqw);
        return new ArrayList<>(beanRecords);
        LambdaQueryWrapper<ZfDownload> lqw = buildCondition(zfDownload,myself.getUserId());
        List<ZfDownload> beanRecords = list(lqw);
        List<ZfDoctor> bs = new ArrayList<>();
        for (ZfDownload a: beanRecords) {
            if (zfDoctorService.getById(a.getDownloadContent()) != null) {
                ZfDoctor ds = zfDoctorService.getById(a.getDownloadContent());
                ds.setShareId(a.getShareId());
                bs.add(ds);
            }
        }
        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,bs.size());
        return AjaxResult.success(data);
    }
    @Override
    public AjaxResult addData(ZfDoctorDownload zfDoctorDownload) {
    zfDoctorDownload.setDownloadId(getUserId());
    LambdaQueryWrapper<ZfDoctorDownload> lqw = uniqueCondition(zfDoctorDownload);
    List<ZfDoctorDownload> list = list(lqw);
    public AjaxResult addData(ZfDownload zfDownload) {
    zfDownload.setDownloadId(getUserId());
    LambdaQueryWrapper<ZfDownload> lqw = uniqueCondition(zfDownload);
    List<ZfDownload> list = list(lqw);
        if (list.size() > 0) {
        throw new RuntimeException("请勿新增重复数据");
        throw new RuntimeException("请勿重复下载数据");
    }
        zfDoctorDownload.setDownloadId(getUserId());
        zfDoctorDownload.setShareId(zfDoctorShareService.getShareId(zfDoctorDownload));
        if (save(zfDoctorDownload)) {
        zfDownload.setDownloadId(getUserId());
        zfDownload.setShareId(zfDoctorShareService.getShareId(zfDownload));
        if (save(zfDownload)) {
        EsModel esModel = new EsModel();
        Integer inte = zfDoctorDownload.getId().intValue();
        Integer inte = zfDownload.getId().intValue();
        String uuid = UUID.randomUUID().toString().replace("-", "");
        esModel.setId(uuid);
        esModel.setCtId(Long.valueOf(inte));
        esModel.setCtTableName("家庭小医生");
        esModel.setBy1(String.valueOf(zfDoctorDownload.getDownloadId()));
        esModel.setBy2(String.valueOf(zfDoctorDownload.getDownloadContent()));
        esModel.setBy3(String.valueOf(zfDoctorDownload.getShareId()));
        esModel.setBy1(String.valueOf(zfDownload.getDownloadId()));
        esModel.setBy2(String.valueOf(zfDownload.getDownloadContent()));
        esModel.setBy3(String.valueOf(zfDownload.getShareId()));
        //这里存储查询详情的路径
        esService.insertTable(esModel);
        return AjaxResult.success();
@@ -89,14 +111,29 @@
    }
}
    @Override
    public AjaxResult deleteData(Long[] ids) {
        List<ZfDoctorDownload> zfDoctorDownloads = listByIds(Arrays.asList(ids));
    public Boolean deleteData(Long[] ids) {
        List<Long> id = new ArrayList<>();
        if (zfDoctorShareService.removeByIds(Arrays.asList(ids))) {
        LambdaQueryWrapper<ZfDownload> lqw = new LambdaQueryWrapper<>();
        lqw.in(ids != null, ZfDownload::getDownloadContent,  ids)
                .eq(ZfDownload::getSysMenuId, 2019L);
        List<ZfDownload> zfDownloads = list(lqw);
        System.out.println(zfDownloads);
        if (zfDownloads.size() == 0){
            return true;
        }
        for (ZfDownload zfDownload: zfDownloads) {
            id.add(zfDownload.getId());
        }
        System.out.println(id);
        if (removeByIds(id)) {
            //删除es中的数据
            zfDoctorDownloads.stream().forEach(zfDoctorDownload -> {
                EsModel esModel = esService.findByCtId(zfDoctorDownload.getId().intValue(), "家庭小医生下载");
            zfDownloads.stream().forEach(zfDoctorDownload -> {
                EsModel esModel = esService.findByCtId(zfDoctorDownload.getId().intValue(), "家庭小医生下载删除");
                if (esModel != null) {
                    DeleteRequest deleteRequest = new DeleteRequest("allsearchdata", esModel.getId());
@@ -107,9 +144,9 @@
                    }
                }
            });
            return AjaxResult.success();
            return true;
        } else {
            return AjaxResult.error();
            return false;
        }
    }
@@ -118,4 +155,11 @@
        ZInfoUser myself = zInfoUserService.getMyself();
        return myself.getUserId();
    }
    @Override
    public List<ZfDownload> getByUserId(Long userId) {
        LambdaQueryWrapper<ZfDownload> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ZfDownload::getDownloadId, userId);
        return list(lqw);
    }
}