zqy
2024-06-23 a69aafe60ce001834b981778f12fd74d4af77e23
小医生修改&下载分享数据
4个文件已修改
4个文件已添加
255 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfDoctorShareController.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/domain/ZfDoctorDownload.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/mapper/ZfDoctorDownloadMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/ZfDoctorDownloadService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/ZfDoctorShareService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorDownloadServiceImpl.java 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorShareServiceImpl.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfDoctorShareController.java
@@ -3,10 +3,17 @@
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.ShareMore;
import com.ruoyi.domain.ZfDoctor;
import com.ruoyi.domain.ZfDoctorDownload;
import com.ruoyi.service.ZInfoUserService;
import com.ruoyi.service.ZfDoctorDownloadService;
import com.ruoyi.service.ZfDoctorService;
import com.ruoyi.service.ZfDoctorShareService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/ZfDoctorShare")
@@ -14,6 +21,14 @@
    @Resource
    ZfDoctorShareService zfDoctorShareService;
    @Resource
    ZfDoctorService zfDoctorService;
    @Resource
    ZInfoUserService zInfoUserService;
    @Resource
    ZfDoctorDownloadService zfDoctorDownloadService;
    /**
     * 分享数据
     */
@@ -46,5 +61,29 @@
        return zfDoctorShareService.deleteZa(zfDoctor);
    }
    /**
     * 下载分享的数据
     */
    @PostMapping("/downloadDate")
    public AjaxResult ifDownLoad(@RequestBody ZfDoctorDownload zfDoctorDownload){
        return zfDoctorDownloadService.addData(zfDoctorDownload);
    }
    /**
     * 展示下载分享的数据
     */
    @GetMapping("/all")
    public List<ZfDoctor> data(ZfDoctorDownload zfDoctorDownload){
        List<ZfDoctorDownload> as = zfDoctorDownloadService.selectDoctorList(zfDoctorDownload);
        List<ZfDoctor> bs = new ArrayList<>();
        for (ZfDoctorDownload a: as) {
            if (zfDoctorService.getById(a.getDownloadContent()) != null) {
                ZfDoctor ds = zfDoctorService.getById(a.getDownloadContent());
                ds.setShareId(a.getShareId());
                bs.add(ds);
            }
        }
        return bs;
    }
}
zhang-content/src/main/java/com/ruoyi/domain/ZfDoctorDownload.java
New file
@@ -0,0 +1,23 @@
package com.ruoyi.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("zf_doctor_download")
public class ZfDoctorDownload {
    private static final long serialVersionUID = 1L;
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    private Long downloadId;
    private Long downloadContent;
    private Long shareId;
}
zhang-content/src/main/java/com/ruoyi/mapper/ZfDoctorDownloadMapper.java
New file
@@ -0,0 +1,7 @@
package com.ruoyi.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.ZfDoctorDownload;
public interface ZfDoctorDownloadMapper extends BaseMapper<ZfDoctorDownload> {
}
zhang-content/src/main/java/com/ruoyi/service/ZfDoctorDownloadService.java
New file
@@ -0,0 +1,18 @@
package com.ruoyi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.ZfDoctorDownload;
import java.util.List;
public interface ZfDoctorDownloadService extends IService<ZfDoctorDownload> {
    AjaxResult addData(ZfDoctorDownload zfDoctorDownload);
    AjaxResult deleteData(Long[] ids);
    List<ZfDoctorDownload> selectDoctorList(ZfDoctorDownload zfDoctorDownload);
}
zhang-content/src/main/java/com/ruoyi/service/ZfDoctorShareService.java
@@ -4,6 +4,7 @@
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.ShareMore;
import com.ruoyi.domain.ZfDoctor;
import com.ruoyi.domain.ZfDoctorDownload;
import com.ruoyi.domain.ZfDoctorShare;
import java.util.List;
@@ -22,4 +23,7 @@
    List<ZfDoctor> listUserId(Long shareId);
    Long getShareId(ZfDoctorDownload zfDoctorDownload);
}
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorDownloadServiceImpl.java
New file
@@ -0,0 +1,123 @@
package com.ruoyi.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.StringUtils;
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZfDoctorDownload;
import com.ruoyi.mapper.ZfDoctorDownloadMapper;
import com.ruoyi.service.*;
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.Arrays;
import java.util.List;
import java.util.UUID;
@Service
public class ZfDoctorDownloadServiceImpl extends ServiceImpl<ZfDoctorDownloadMapper, ZfDoctorDownload> implements ZfDoctorDownloadService {
    @Resource
    EsService esService;
    @Resource
    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());
        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());
        return lqw;
    }
    @Override
    public List<ZfDoctorDownload> selectDoctorList(ZfDoctorDownload zfDoctorDownload) {
        ZInfoUser myself = zInfoUserService.getMyself();
        LambdaQueryWrapper<ZfDoctorDownload> lqw = buildCondition(zfDoctorDownload,myself.getUserId());
        List<ZfDoctorDownload> beanRecords = list(lqw);
        return new ArrayList<>(beanRecords);
    }
    @Override
    public AjaxResult addData(ZfDoctorDownload zfDoctorDownload) {
    LambdaQueryWrapper<ZfDoctorDownload> lqw = uniqueCondition(zfDoctorDownload);
    List<ZfDoctorDownload> list = list(lqw);
        if (list.size() > 0) {
        throw new RuntimeException("请勿新增重复数据");
    }
        zfDoctorDownload.setDownloadId(getUserId());
        zfDoctorDownload.setShareId(zfDoctorShareService.getShareId(zfDoctorDownload));
        if (save(zfDoctorDownload)) {
        EsModel esModel = new EsModel();
        Integer inte = zfDoctorDownload.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()));
        //这里存储查询详情的路径
        esService.insertTable(esModel);
        return AjaxResult.success();
    } else {
        return AjaxResult.error();
    }
}
    @Override
    public AjaxResult deleteData(Long[] ids) {
        List<ZfDoctorDownload> zfDoctorDownloads = listByIds(Arrays.asList(ids));
        if (zfDoctorShareService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
            zfDoctorDownloads.stream().forEach(zfDoctorDownload -> {
                EsModel esModel = esService.findByCtId(zfDoctorDownload.getId().intValue(), "家庭小医生下载");
                if (esModel != null) {
                    DeleteRequest deleteRequest = new DeleteRequest("allsearchdata", esModel.getId());
                    try {
                        restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }
    public Long getUserId() {
        ZInfoUser myself = zInfoUserService.getMyself();
        return myself.getUserId();
    }
}
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java
@@ -86,11 +86,7 @@
        //加上自己家庭的id
        idList.add(familyId);
//        String familyIds = listFamilyIds();
//        String secondFamilyAuthority = listSecondFamilyIds();
        //查看别人分享
        List<ZfDoctor> bs = zfDoctorShareService.listUserId(myself.getUserId());
//        String secondFamilyAuthority = listSecondFamilyIds()
        LambdaQueryWrapper<ZfDoctor> lqw = buildCondition(zfDoctor, idList);
        Page<ZfDoctor> zfDoctorPage = new Page<>(pageNum, pageSize);
@@ -99,7 +95,6 @@
        List<ZfDoctor> beanRecords = pageResult.getRecords();//得到查询出来的数据
        List<ZfDoctor> dtoResult = markOwnData(familyId, beanRecords);
        dtoResult.addAll(bs);
        HashMap<String, Object> data = MapUtils.getResult(pageResult, dtoResult);
        return AjaxResult.success(data);
    }
@@ -121,12 +116,9 @@
        //加上自己家庭的id
        idList.add(familyId);
        //查看别人分享
        List<ZfDoctor> bs = zfDoctorShareService.listUserId(myself.getUserId());
        LambdaQueryWrapper<ZfDoctor> lambdaQueryWrapper = buildCondition(zfDoctor, idList);
        List<ZfDoctor> beanRecords = list(lambdaQueryWrapper);
        beanRecords.addAll(bs);
        log.info("从数据库中查到的为:{}", beanRecords);
        return markOwnData(familyId, beanRecords);
    }
@@ -166,10 +158,13 @@
        for (ZfDoctor zfDoctor : dataList) {
            if (zfDoctor.getSymptom().length() == 0 || zfDoctor.getSymptom() == null) {
                throw new RuntimeException("症状为空,导入数据失败");
            } else {
                zfDoctorService.addData(zfDoctor);
            if (zfDoctor.getSuitable().length() != 0 || zfDoctor.getType().length() != 0 || zfDoctor.getEffect().length() != 0 ) {
                if(zfDoctor.getSymptom().length() == 0 || zfDoctor.getSymptom() == null){
                    throw new RuntimeException("症状为空,导入数据失败");
                }
                else {
                    zfDoctorService.addData(zfDoctor);
                }
            }
        }
        return AjaxResult.success("导入数据成功");
@@ -191,7 +186,7 @@
//        List<ZfDoctorShare> authority1 = zfDoctorShareService.getAuthority();
//        List<Long> idList1 = authority1.stream().filter(auth -> auth.getShareContent().toString().equals(DOCTOR_LIST)).map(ZfDoctorShare::getShareId).collect(Collectors.toList());
        zfDoctorService.addData(zfDoctor);
//        zfDoctorService.addData(zfDoctor);
        if (zfDoctor.getFamilyId() != null && !familyIdList.contains(zfDoctor.getFamilyId())) {
            throw new RuntimeException("你没有权限操作此家庭的数据");
zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorShareServiceImpl.java
@@ -6,10 +6,7 @@
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.ShareMore;
import com.ruoyi.domain.ZInfoUser;
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;
@@ -172,5 +169,18 @@
        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;
        }
    }
}