From 453ee097563df5788f96e102b38249f0ca70d82a Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期二, 14 十月 2025 18:41:54 +0800
Subject: [PATCH] 诊所和供应商首页统计

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysAppUserController.java |  209 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 197 insertions(+), 12 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysAppUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysAppUserController.java
index 0c373bf..d3f7dbe 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysAppUserController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysAppUserController.java
@@ -1,33 +1,47 @@
 package com.ruoyi.web.controller.api;
 
 
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.system.model.TSysAppUser;
-import com.ruoyi.system.model.TSysChronicDisease;
-import com.ruoyi.system.model.TSysInspection;
+import com.ruoyi.common.utils.WebUtils;
+import com.ruoyi.framework.web.service.TokenService;
+import com.ruoyi.system.export.TCrmClinicAuditExport;
+import com.ruoyi.system.export.TSysAppUserClinicExport;
+import com.ruoyi.system.export.TSysAppUserExport;
+import com.ruoyi.system.export.TSysAppUserListExport;
+import com.ruoyi.system.model.*;
+import com.ruoyi.system.query.TCrmClinicQuery;
 import com.ruoyi.system.query.TSysAppUserQuery;
-import com.ruoyi.system.service.TSysAppUserService;
-import com.ruoyi.system.service.TSysChronicDiseaseService;
-import com.ruoyi.system.service.TSysInspectionService;
-import com.ruoyi.system.service.TSysOrderService;
+import com.ruoyi.system.service.*;
 import com.ruoyi.system.vo.TSysAppUserVO;
 import com.ruoyi.system.vo.TSysOrderVO;
+import com.ruoyi.web.controller.tool.MsgUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -46,12 +60,20 @@
     private final TSysInspectionService sysInspectionService;
     private final TSysOrderService sysOrderService;
     private final TSysChronicDiseaseService sysChronicDiseaseService;
+    private final MsgUtils msgUtils;
+    private final TSysMessageTemplateService sysMessageTemplateService;
+    private final TCrmClinicService crmClinicService;
+    private final TokenService tokenService;
     @Autowired
-    public TSysAppUserController(TSysAppUserService sysAppUserService, TSysInspectionService sysInspectionService, TSysOrderService sysOrderService, TSysChronicDiseaseService sysChronicDiseaseService) {
+    public TSysAppUserController(TSysAppUserService sysAppUserService, TSysInspectionService sysInspectionService, TSysOrderService sysOrderService, TSysChronicDiseaseService sysChronicDiseaseService, MsgUtils msgUtils, TSysMessageTemplateService sysMessageTemplateService, TCrmClinicService crmClinicService, TokenService tokenService) {
         this.sysAppUserService = sysAppUserService;
         this.sysInspectionService = sysInspectionService;
         this.sysOrderService = sysOrderService;
         this.sysChronicDiseaseService = sysChronicDiseaseService;
+        this.msgUtils = msgUtils;
+        this.sysMessageTemplateService = sysMessageTemplateService;
+        this.crmClinicService = crmClinicService;
+        this.tokenService = tokenService;
     }
 
     /**
@@ -70,6 +92,30 @@
     @PostMapping(value = "/pageChronicDiseaseUserList")
     public R<PageInfo<TSysAppUserVO>> pageChronicDiseaseUserList(@RequestBody TSysAppUserQuery query) {
         return R.ok(sysAppUserService.pageChronicDiseaseUserList(query));
+    }
+
+
+    /**
+     * 用药提醒
+     */
+    @ApiOperation(value = "慢性病患者-用药提醒", notes = "userId:患者用户id,templateId:短信模板id")
+    @GetMapping(value = "/medicationReminder")
+    public R<String> medicationReminder(@RequestParam(value = "userId") String userId,
+                                                         @RequestParam(value = "templateId") String templateId) {
+        TSysAppUser sysAppUser = sysAppUserService.getById(userId);
+        if(StringUtils.isNotBlank(sysAppUser.getPhone())){
+            sysAppUser.setLastReminderTime(LocalDateTime.now());
+            sysAppUserService.updateById(sysAppUser);
+            TSysMessageTemplate messageTemplate = sysMessageTemplateService.getById(templateId);
+            // 发送短信
+            try {
+                Map<String,String> params = new HashMap<>();
+                msgUtils.sendMsg(sysAppUser.getPhone(),params, messageTemplate.getTemplateCode());
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return R.ok();
     }
 
     /**
@@ -93,6 +139,10 @@
         if (sysAppUserService.isExit(dto)) {
             return R.fail("用户管理信息已存在");
         }
+        Long userId = tokenService.getLoginUser().getUserId();
+        TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                .eq(TCrmClinic::getUserId, userId));
+        dto.setClinicId(crmClinic.getId());
         return R.ok(sysAppUserService.save(dto));
     }
 
@@ -127,6 +177,24 @@
         }
         // 查询检测信息
         List<TSysInspection> sysInspections = sysInspectionService.list(Wrappers.lambdaQuery(TSysInspection.class).eq(TSysInspection::getAppUserId, id));
+        if(!CollectionUtils.isEmpty(sysInspections)){
+            List<String> clinicIds = sysInspections.stream().map(TSysInspection::getClinicId).collect(Collectors.toList());
+            List<TCrmClinic> clinicList = crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).in(TCrmClinic::getId, clinicIds));
+            List<TSysOrder> sysOrderList = sysOrderService.list(Wrappers.lambdaQuery(TSysOrder.class).in(TSysOrder::getClinicId, clinicIds));
+            for (TSysInspection sysInspection : sysInspections) {
+                TCrmClinic clinic = clinicList.stream().filter(c -> c.getId().equals(sysInspection.getClinicId())).findFirst().orElse(null);
+                if(clinic != null){
+                    sysInspection.setClinicName(clinic.getClinicName());
+                }
+                List<TSysOrder> sysOrders = sysOrderList.stream().filter(c -> sysInspection.getId().equals(c.getInspectionId())).collect(Collectors.toList());
+                if(CollectionUtils.isEmpty(sysOrders)){
+                    sysInspection.setIsPrescribeMedicine(0);
+                }else {
+                    sysInspection.setIsPrescribeMedicine(1);
+                    sysInspection.setOrderId(sysOrders.get(0).getId());
+                }
+            }
+        }
         sysAppUserVO.setSysInspections(sysInspections);
         // 订单信息
         List<TSysOrderVO> sysOrders = sysOrderService.queryListByAppUserId(id);
@@ -182,8 +250,8 @@
     /**
      * 分公司管理解冻冻结
      */
-    @Log(title = "用户管理信息-分公司管理解冻冻结", businessType = BusinessType.UPDATE)
-    @ApiOperation(value = "分公司管理解冻冻结",notes = "状态 1=使用中 2=冻结")
+    @Log(title = "用户管理信息-用户管理解冻冻结", businessType = BusinessType.UPDATE)
+    @ApiOperation(value = "用户管理解冻冻结",notes = "状态 1=使用中 2=冻结")
     @PutMapping(value = "/thawOrFreeze")
     public R<Boolean> thawOrFreeze(@RequestParam(value = "id")String id,
                                    @RequestParam(value = "status")Integer status) {
@@ -197,5 +265,122 @@
         return R.ok();
     }
 
+    /**
+     * 修改用户慢性病
+     */
+    @Log(title = "用户管理信息-修改用户慢性病", businessType = BusinessType.UPDATE)
+    @ApiOperation(value = "修改用户慢性病")
+    @PostMapping(value = "/updateDisease")
+    public R<Boolean> updateDisease(@RequestParam(value = "id") String id,
+                                    @RequestParam(value = "chronicDiseaseId") String chronicDiseaseId) {
+        TSysAppUser sysAppUser = new TSysAppUser();
+        sysAppUser.setId(id);
+        sysAppUser.setChronicDiseaseId(chronicDiseaseId);
+        return R.ok(sysAppUserService.updateById(sysAppUser));
+    }
+
+
+    @Log(title = "用户管理信息-慢性病患者导出-平台", businessType = BusinessType.EXPORT)
+    @ApiOperation(value = "慢性病患者导出-平台")
+    @PostMapping("/exportList")
+    public void exportList(@RequestBody TSysAppUserQuery query){
+        List<TSysAppUserListExport> sysAppUserListExports = sysAppUserService.exportList(query);
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TSysAppUserListExport.class, sysAppUserListExports);
+        HttpServletResponse response = WebUtils.response();
+        assert response != null;
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        ServletOutputStream outputStream = null;
+        try {
+            String fileName = URLEncoder.encode("慢性病患者.xls", "utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+    @Log(title = "用户管理信息-慢性病患者导出-诊所", businessType = BusinessType.EXPORT)
+    @ApiOperation(value = "慢性病患者导出-诊所")
+    @PostMapping("/exportListClinic")
+    public void exportListClinic(@RequestBody TSysAppUserQuery query){
+        List<TSysAppUserClinicExport> sysAppUserClinicExports = sysAppUserService.exportListClinic(query);
+        for (TSysAppUserClinicExport sysAppUserClinicExport : sysAppUserClinicExports) {
+            String lastReminderTime = sysAppUserClinicExport.getLastReminderTime();
+            lastReminderTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(lastReminderTime);
+            sysAppUserClinicExport.setLastReminderTime(lastReminderTime);
+        }
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TSysAppUserClinicExport.class, sysAppUserClinicExports);
+        HttpServletResponse response = WebUtils.response();
+        assert response != null;
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        ServletOutputStream outputStream = null;
+        try {
+            String fileName = URLEncoder.encode("慢性病患者.xls", "utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @Log(title = "用户管理信息-用户管理信息导出", businessType = BusinessType.EXPORT)
+    @ApiOperation(value = "用户管理信息导出")
+    @PostMapping("/exportListAppUser")
+    public void exportListAppUser(@RequestBody TSysAppUserQuery query){
+        List<TSysAppUserExport> sysAppUserExports = sysAppUserService.exportListAppUser(query);
+        for (TSysAppUserExport sysAppUserExport : sysAppUserExports) {
+            String lastInspectionTime = sysAppUserExport.getLastInspectionTime();
+            if(StringUtils.isNotEmpty(lastInspectionTime)){
+                lastInspectionTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(lastInspectionTime);
+                sysAppUserExport.setLastInspectionTime(lastInspectionTime);
+            }
+            sysAppUserExport.setCreateTimeStr(sysAppUserExport.getCreateTime().toLocalDate().toString());
+        }
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TSysAppUserExport.class, sysAppUserExports);
+        HttpServletResponse response = WebUtils.response();
+        assert response != null;
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        ServletOutputStream outputStream = null;
+        try {
+            String fileName = URLEncoder.encode("用户管理信息.xls", "utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
 }
 

--
Gitblit v1.7.1