xuhy
2026-01-19 38c1973c9f0f7c53f165c3045d38509205552a51
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysAppUserController.java
@@ -7,18 +7,17 @@
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
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.TSysAppUser;
import com.ruoyi.system.model.TSysChronicDisease;
import com.ruoyi.system.model.TSysInspection;
import com.ruoyi.system.model.TSysMessageTemplate;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TCrmClinicQuery;
import com.ruoyi.system.query.TSysAppUserQuery;
import com.ruoyi.system.service.*;
@@ -30,6 +29,7 @@
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.*;
@@ -42,6 +42,7 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
/**
 * <p>
@@ -62,14 +63,22 @@
    private final TSysChronicDiseaseService sysChronicDiseaseService;
    private final MsgUtils msgUtils;
    private final TSysMessageTemplateService sysMessageTemplateService;
    private final TCrmClinicService crmClinicService;
    private final TokenService tokenService;
    private final TSysOtherConfigService sysOtherConfigService;
    private final ISysUserService sysUserService;
    @Autowired
    public TSysAppUserController(TSysAppUserService sysAppUserService, TSysInspectionService sysInspectionService, TSysOrderService sysOrderService, TSysChronicDiseaseService sysChronicDiseaseService, MsgUtils msgUtils, TSysMessageTemplateService sysMessageTemplateService) {
    public TSysAppUserController(TSysAppUserService sysAppUserService, TSysInspectionService sysInspectionService, TSysOrderService sysOrderService, TSysChronicDiseaseService sysChronicDiseaseService, MsgUtils msgUtils, TSysMessageTemplateService sysMessageTemplateService, TCrmClinicService crmClinicService, TokenService tokenService, TSysOtherConfigService sysOtherConfigService, ISysUserService sysUserService) {
        this.sysAppUserService = sysAppUserService;
        this.sysInspectionService = sysInspectionService;
        this.sysOrderService = sysOrderService;
        this.sysChronicDiseaseService = sysChronicDiseaseService;
        this.msgUtils = msgUtils;
        this.sysMessageTemplateService = sysMessageTemplateService;
        this.crmClinicService = crmClinicService;
        this.tokenService = tokenService;
        this.sysOtherConfigService = sysOtherConfigService;
        this.sysUserService = sysUserService;
    }
    /**
@@ -78,6 +87,15 @@
    @ApiOperation(value = "获取用户管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TSysAppUserVO>> pageList(@RequestBody TSysAppUserQuery query) {
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        Long userId = tokenService.getLoginUser().getUserId();
        query.setRoleType(roleType);
        if(roleType == 5){
            TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getUserId, userId)
                    .last("LIMIT 1"));
            query.setClinicId(crmClinic.getId());
        }
        return R.ok(sysAppUserService.pageList(query));
    }
@@ -87,6 +105,8 @@
    @ApiOperation(value = "获取慢性病患者分页列表")
    @PostMapping(value = "/pageChronicDiseaseUserList")
    public R<PageInfo<TSysAppUserVO>> pageChronicDiseaseUserList(@RequestBody TSysAppUserQuery query) {
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        query.setRoleType(roleType);
        return R.ok(sysAppUserService.pageChronicDiseaseUserList(query));
    }
@@ -98,6 +118,26 @@
    @GetMapping(value = "/medicationReminder")
    public R<String> medicationReminder(@RequestParam(value = "userId") String userId,
                                                         @RequestParam(value = "templateId") String templateId) {
        Long clinicUserId = tokenService.getLoginUser().getUserId();
        TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                .eq(TCrmClinic::getUserId, clinicUserId)
                .last("LIMIT 1"));
        // ---
        if(Objects.isNull(crmClinic)){
            SysUser sysUser = sysUserService.selectUserById(clinicUserId);
            crmClinic = crmClinicService.getById(sysUser.getObjectId());
        }
        if(crmClinic == null){
            return R.fail("未找到该诊所信息");
        }
        // 查询其他设置
        TSysOtherConfig sysOtherConfig = sysOtherConfigService.getById(1);
        if(crmClinic.getSendMessageCount()>=sysOtherConfig.getMsgCount()){
            return R.fail("该诊所今日发送短信次数已达上限");
        }
        crmClinic.setSendMessageCount(crmClinic.getSendMessageCount() + 1);
        crmClinicService.updateById(crmClinic);
        TSysAppUser sysAppUser = sysAppUserService.getById(userId);
        if(StringUtils.isNotBlank(sysAppUser.getPhone())){
            sysAppUser.setLastReminderTime(LocalDateTime.now());
@@ -131,11 +171,23 @@
    @Log(title = "用户管理信息-新增用户管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "添加用户管理")
    @PostMapping(value = "/add")
    public R<Boolean> add(@Validated @RequestBody TSysAppUser dto) {
    public R<String> add(@Validated @RequestBody TSysAppUser dto) {
        if (sysAppUserService.isExit(dto)) {
            return R.fail("用户管理信息已存在");
        }
        return R.ok(sysAppUserService.save(dto));
        Long userId = tokenService.getLoginUser().getUserId();
        TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class)
                .eq(TCrmClinic::getUserId, userId));
        // ---
        if(Objects.isNull(crmClinic)){
            SysUser sysUser = sysUserService.selectUserById(userId);
            crmClinic = crmClinicService.getById(sysUser.getObjectId());
        }
        String identifierNumber = UUID.randomUUID().toString().replace("-", "");
        dto.setIdentifierNumber(identifierNumber);
        dto.setClinicId(crmClinic.getId());
        sysAppUserService.save(dto);
        return R.ok(dto.getId());
    }
    /**
@@ -168,10 +220,37 @@
            sysAppUserVO.setSysChronicDiseases(sysChronicDiseases);
        }
        // 查询检测信息
        List<TSysInspection> sysInspections = sysInspectionService.list(Wrappers.lambdaQuery(TSysInspection.class).eq(TSysInspection::getAppUserId, id));
        List<TSysInspection> sysInspections = sysInspectionService.list(Wrappers.lambdaQuery(TSysInspection.class)
                .eq(TSysInspection::getAppUserId, id)
                .orderByDesc(TSysInspection::getCreateTime));
        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);
        for (TSysOrderVO sysOrder : sysOrders) {
            List<TSysInspection> tSysInspections = sysInspections.stream().filter(c -> c.getId().equals(sysOrder.getInspectionId())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(tSysInspections)){
                TSysInspection sysInspection = tSysInspections.get(0);
                sysOrder.setSysInspection(sysInspection);
            }
        }
        sysAppUserVO.setSysOrders(sysOrders);
        if(sysAppUserVO.getBirthTime() != null){
            long age = ChronoUnit.YEARS.between(sysAppUserVO.getBirthTime(), LocalDateTime.now());
@@ -186,7 +265,7 @@
    @ApiOperation(value = "根据用户id查询检测信息")
    @GetMapping(value = "/getInspectionByAppUserId")
    public R<List<TSysInspection>> getInspectionByAppUserId(@RequestParam String appUserId) {
        // 订单信息
        // 检测信息
        List<TSysInspection> sysInspections = sysInspectionService.list(Wrappers.lambdaQuery(TSysInspection.class).eq(TSysInspection::getAppUserId, appUserId));
        return R.ok(sysInspections);
    }
@@ -258,6 +337,8 @@
    @ApiOperation(value = "慢性病患者导出-平台")
    @PostMapping("/exportList")
    public void exportList(@RequestBody TSysAppUserQuery query){
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        query.setRoleType(roleType);
        List<TSysAppUserListExport> sysAppUserListExports = sysAppUserService.exportList(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TSysAppUserListExport.class, sysAppUserListExports);
        HttpServletResponse response = WebUtils.response();
@@ -287,12 +368,14 @@
    @ApiOperation(value = "慢性病患者导出-诊所")
    @PostMapping("/exportListClinic")
    public void exportListClinic(@RequestBody TSysAppUserQuery query){
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        query.setRoleType(roleType);
        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);
        }
//        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;
@@ -324,11 +407,11 @@
    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);
            }
//            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);