From a69aafe60ce001834b981778f12fd74d4af77e23 Mon Sep 17 00:00:00 2001
From: zqy <2522236926@qq.com>
Date: 星期日, 23 六月 2024 22:04:42 +0800
Subject: [PATCH] 小医生修改&下载分享数据

---
 zhang-content/src/main/java/com/ruoyi/domain/ZfDoctorDownload.java                    |   23 ++++
 zhang-content/src/main/java/com/ruoyi/service/ZfDoctorShareService.java               |    4 
 zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorDownloadServiceImpl.java   |  123 ++++++++++++++++++++++++
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfDoctorShareController.java |   39 +++++++
 zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorShareServiceImpl.java      |   18 ++
 zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java           |   23 +--
 zhang-content/src/main/java/com/ruoyi/mapper/ZfDoctorDownloadMapper.java              |    7 +
 zhang-content/src/main/java/com/ruoyi/service/ZfDoctorDownloadService.java            |   18 +++
 8 files changed, 237 insertions(+), 18 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfDoctorShareController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfDoctorShareController.java
index 1cb8036..554f9ee 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfDoctorShareController.java
+++ b/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;
+    }
 
 }
diff --git a/zhang-content/src/main/java/com/ruoyi/domain/ZfDoctorDownload.java b/zhang-content/src/main/java/com/ruoyi/domain/ZfDoctorDownload.java
new file mode 100644
index 0000000..3b5e3b2
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/domain/ZfDoctorDownload.java
@@ -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;
+}
diff --git a/zhang-content/src/main/java/com/ruoyi/mapper/ZfDoctorDownloadMapper.java b/zhang-content/src/main/java/com/ruoyi/mapper/ZfDoctorDownloadMapper.java
new file mode 100644
index 0000000..4d86eb0
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/mapper/ZfDoctorDownloadMapper.java
@@ -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> {
+}
diff --git a/zhang-content/src/main/java/com/ruoyi/service/ZfDoctorDownloadService.java b/zhang-content/src/main/java/com/ruoyi/service/ZfDoctorDownloadService.java
new file mode 100644
index 0000000..95203ea
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/service/ZfDoctorDownloadService.java
@@ -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);
+
+
+}
diff --git a/zhang-content/src/main/java/com/ruoyi/service/ZfDoctorShareService.java b/zhang-content/src/main/java/com/ruoyi/service/ZfDoctorShareService.java
index 5b125ae..9f4d1d3 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/ZfDoctorShareService.java
+++ b/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);
+
+
 }
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorDownloadServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorDownloadServiceImpl.java
new file mode 100644
index 0000000..76e3fa6
--- /dev/null
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorDownloadServiceImpl.java
@@ -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();
+    }
+}
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java
index 9f1d5ab..9868b9b 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorServiceImpl.java
@@ -86,11 +86,7 @@
         //鍔犱笂鑷繁瀹跺涵鐨刬d
         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 @@
         //鍔犱笂鑷繁瀹跺涵鐨刬d
         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("浣犳病鏈夋潈闄愭搷浣滄瀹跺涵鐨勬暟鎹�");
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorShareServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorShareServiceImpl.java
index cef2d83..b2a34d5 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfDoctorShareServiceImpl.java
+++ b/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;
+        }
+    }
 
 }

--
Gitblit v1.9.1