xuhy
2026-01-19 e7952253147b024333b5e0d5903b7b7aa4f7bbac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.constant.WxConstant;
import com.ruoyi.common.core.controller.FileController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TCrmClinicAuditDTO;
import com.ruoyi.system.dto.TCrmClinicDTO;
import com.ruoyi.system.dto.UnbindDTO;
import com.ruoyi.system.export.TCrmChangePointsBranchExport;
import com.ruoyi.system.export.TCrmClinicAuditExport;
import com.ruoyi.system.export.TCrmClinicListExport;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TCrmChangePointsQuery;
import com.ruoyi.system.query.TCrmClinicQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.utils.util.ObsUploadUtil;
import com.ruoyi.system.utils.wx.model.WeixinProperties;
import com.ruoyi.system.utils.wx.tools.WxAppletTools;
import com.ruoyi.system.utils.xiMaUtil.XimaAIUtil;
import com.ruoyi.system.vo.TCrmClinicVO;
import com.ruoyi.system.vo.TSysAppUserVO;
import com.ruoyi.web.controller.tool.MsgUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 * crm诊所管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-08-20
 */
@Slf4j
@Api(tags = "crm诊所管理")
@RestController
@RequestMapping("/t-crm-clinic")
public class TCrmClinicController {
 
    private final TCrmClinicService crmClinicService;
    private final TCrmSupplierService crmSupplierService;
    private final TCrmBranchService crmBranchService;
    private final TCrmWarehouseService crmWarehouseService;
    private final TCrmSalespersonService crmSalespersonService;
    private final ISysUserService sysUserService;
    private final TCrmDeviceService crmDeviceService;
    private final TokenService tokenService;
    private final MsgUtils msgUtils;
    private final TSysMessageTemplateService sysMessageTemplateService;
    private final RedisCache redisCache;
    private final RestTemplate restTemplate;
    private final WeixinProperties wxConfig;
    @Autowired
    public TCrmClinicController(TCrmClinicService crmClinicService, TCrmSupplierService crmSupplierService, TCrmBranchService crmBranchService, TCrmWarehouseService crmWarehouseService, TCrmSalespersonService crmSalespersonService, ISysUserService sysUserService, TCrmDeviceService crmDeviceService, TokenService tokenService, MsgUtils msgUtils, TSysMessageTemplateService sysMessageTemplateService, RedisCache redisCache, RestTemplate restTemplate, WeixinProperties wxConfig) {
        this.crmClinicService = crmClinicService;
        this.crmSupplierService = crmSupplierService;
        this.crmBranchService = crmBranchService;
        this.crmWarehouseService = crmWarehouseService;
        this.crmSalespersonService = crmSalespersonService;
        this.sysUserService = sysUserService;
        this.crmDeviceService = crmDeviceService;
        this.tokenService = tokenService;
        this.msgUtils = msgUtils;
        this.sysMessageTemplateService = sysMessageTemplateService;
        this.redisCache = redisCache;
        this.restTemplate = restTemplate;
        this.wxConfig = wxConfig;
    }
 
    /**
     * 获取crm诊所管理管理列表
     */
    @ApiOperation(value = "获取crm诊所管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TCrmClinicVO>> pageList(@RequestBody TCrmClinicQuery query) {
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        Long userId = tokenService.getLoginUser().getUserId();
        if(roleType == 2){
            query.setUserId(userId);
            query.setRoleType(roleType);
            // 查询账号绑定的分公司
            TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
                    .eq(TCrmBranch::getUserId,userId)
                    .last("LIMIT 1"));
            List<String> branchIds = new ArrayList<>();
            if(crmBranch != null && crmBranch.getPersonType() == 1){
                List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getPersonType, 2)
                        .eq(TCrmBranch::getCorrelationPersonId, userId));
                if(!CollectionUtils.isEmpty(crmBranches)){
                    branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                    List<Long> userIds = crmBranches.stream().map(TCrmBranch::getUserId).collect(Collectors.toList());
                    List<TCrmBranch> crmBranches1 = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                            .eq(TCrmBranch::getPersonType, 3)
                            .in(TCrmBranch::getCorrelationPersonId, userIds));
                    if(!CollectionUtils.isEmpty(crmBranches1)){
                        List<String> childrenIds = crmBranches1.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                        branchIds.addAll(childrenIds);
                    }
                }
            }
            if(crmBranch != null && crmBranch.getPersonType() == 2){
                List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getPersonType, 3)
                        .eq(TCrmBranch::getCorrelationPersonId, userId));
                if(!CollectionUtils.isEmpty(crmBranches)){
                    branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                }
                branchIds.add(crmBranch.getId());
            }
            if(crmBranch != null && crmBranch.getPersonType() == 3){
                branchIds.add(crmBranch.getId());
            }
//            query.setBranchId(crmBranch.getId());
            branchIds = branchIds.stream().distinct().collect(Collectors.toList());
            query.setBranchIds(branchIds);
        }
        if(roleType == 3){
            query.setUserId(userId);
            query.setRoleType(roleType);
            // 查询账号绑定的业务员
            TCrmSalesperson crmSalesperson = crmSalespersonService.getOne(Wrappers.lambdaQuery(TCrmSalesperson.class)
                    .eq(TCrmSalesperson::getUserId,userId)
                    .last("LIMIT 1"));
            query.setSalespersonId(crmSalesperson.getId());
        }
        if (roleType == 1){
            query.setRoleType(roleType);
        }
        return R.ok(crmClinicService.pageList(query));
    }
 
    /**
     * 获取crm诊所管理管理列表
     */
    @ApiOperation(value = "获取crm诊所管理审核分页列表")
    @PostMapping(value = "/pageAuditList")
    public R<PageInfo<TCrmClinicVO>> pageAuditList(@RequestBody TCrmClinicQuery query) {
        return R.ok(crmClinicService.pageAuditList(query));
    }
 
    /**
     * 获取crm诊所管理管理列表
     */
    @ApiOperation(value = "获取crm诊所管理列表",notes = "type 1=设备使用 2=其他")
    @PostMapping(value = "/list")
    public R<List<TCrmClinic>> list(@RequestParam(value = "type") Integer type) {
        if(type == 1){
            List<TCrmDevice> list = crmDeviceService.list();
            LambdaQueryWrapper<TCrmClinic> wrapper = new LambdaQueryWrapper<>();
            if(!CollectionUtils.isEmpty(list)){
                List<String> clinicIds = list.stream().map(TCrmDevice::getClinicId).collect(Collectors.toList());
                wrapper.notIn(TCrmClinic::getId,clinicIds);
            }
            wrapper.eq(TCrmClinic::getStatus,3).orderByDesc(TCrmClinic::getCreateTime);
            return R.ok(crmClinicService.list(wrapper));
        }else {
            return R.ok(crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class)
                    .eq(TCrmClinic::getStatus,3)
                    .orderByDesc(TCrmClinic::getCreateTime)));
        }
    }
 
    /**
     * 添加crm诊所管理管理
     */
    @Log(title = "crm诊所管理信息-新增crm诊所管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "添加crm诊所管理")
    @PostMapping(value = "/add")
    public R<String> add(@Validated @RequestBody TCrmClinicDTO dto) {
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        if (roleType == 1){
            dto.setStatus(3);
        }else {
            dto.setStatus(1);
        }
        crmClinicService.addClinic(dto);
        WxAppletTools wxAppletTools = new WxAppletTools(restTemplate, wxConfig, redisCache);
        // 获取access_token
        String accessToken = wxAppletTools.getAccessToken();
        // 替换CREATE_CODE_URL
        String url = WxConstant.CREATE_CODE_URL.replace("ACCESS_TOKEN", accessToken);
        // 发送请求
        try {
            HashMap<String, Object> map = new HashMap<>();
            map.put("page", "pages/home/home");
            map.put("scene", "clinicId=" + dto.getId());
            map.put("check_path", false);
            map.put("env_version", "release");
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpEntity requestEntity = new HttpEntity(map, headers);
            ResponseEntity<byte[]> rep = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);
            byte[] bytes = rep.getBody();
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
            MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), byteArrayInputStream);
            String stringApiResult = ObsUploadUtil.obsUpload(file);
            dto.setQrCode(stringApiResult);
        } catch (Exception e) {
            log.error("生成小程序码失败:{}", e.getMessage());
        }
        crmClinicService.updateById(dto);
        return R.ok();
    }
 
    /**
     * 修改crm诊所管理
     */
    @Log(title = "crm诊所管理信息-修改crm诊所管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改crm诊所管理")
    @PostMapping(value = "/update")
    public R<Boolean> update(@Validated @RequestBody TCrmClinicDTO dto) {
        return crmClinicService.updateClinic(dto);
    }
 
    /**
     * 查看crm诊所管理详情
     */
    @ApiOperation(value = "查看crm诊所管理详情")
    @GetMapping(value = "/getDetailById")
    public R<TCrmClinicVO> getDetailById(@RequestParam String id) {
        TCrmClinic crmSupplier = crmClinicService.getById(id);
        TCrmClinicVO crmSupplierVO = new TCrmClinicVO();
        BeanUtils.copyProperties(crmSupplier, crmSupplierVO);
        // 获取关联的分公司名称
        TCrmBranch crmBranch = crmBranchService.getById(crmSupplier.getBranchId());
        if(Objects.nonNull(crmBranch)){
            crmSupplierVO.setBranchName(crmBranch.getBranchName());
        }
        // 获取关联的业务员名称
        TCrmSalesperson crmSalesperson = crmSalespersonService.getById(crmSupplier.getSalespersonId());
        if(Objects.nonNull(crmSalesperson)){
            crmSupplierVO.setSalespersonName(crmSalesperson.getSalespersonName());
        }
        // 获取关联仓库
        TCrmWarehouse crmWarehouse = crmWarehouseService.getById(crmSupplier.getWarehouseId());
        if(Objects.nonNull(crmWarehouse)){
            crmSupplierVO.setWarehouseName(crmWarehouse.getWarehouseName());
        }
        return R.ok(crmSupplierVO);
    }
 
    /**
     * 删除crm诊所管理
     */
    @Log(title = "crm诊所管理信息-删除crm诊所管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除crm诊所管理")
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        // 删除账号
        TCrmClinic crmClinic = crmClinicService.getById(id);
        sysUserService.deleteUserById(crmClinic.getUserId());
        return R.ok(crmClinicService.removeById(id));
    }
 
    /**
     * 批量删除crm诊所管理
     */
    @Log(title = "crm诊所管理信息-删除crm诊所管理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除crm诊所管理")
    @DeleteMapping(value = "/deleteByIds")
    public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
        // 删除账号
        List<TCrmClinic> crmClinicList = crmClinicService.list(Wrappers.lambdaQuery(TCrmClinic.class).in(TCrmClinic::getId, ids));
        List<Long> userIds = crmClinicList.stream().map(TCrmClinic::getUserId).collect(Collectors.toList());
        sysUserService.deleteUserByIds(userIds);
        return R.ok(crmClinicService.removeByIds(ids));
    }
 
    /**
     * 批量删除crm诊所管理
     */
    @Log(title = "crm诊所管理信息-诊所管理解冻冻结", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "诊所管理解冻冻结",notes = "状态 3=使用中 4=冻结")
    @PutMapping(value = "/thawOrFreeze")
    public R<Boolean> thawOrFreeze(@RequestParam(value = "id")String id,
                                   @RequestParam(value = "status")Integer status) {
        TCrmClinic crmClinic = crmClinicService.getById(id);
        crmClinic.setStatus(status);
        crmClinicService.updateById(crmClinic);
        // 查询用户
        SysUser sysUser = sysUserService.selectUserById(crmClinic.getUserId());
        switch (status){
            case 3:
                // 解冻
                sysUser.setStatus("0");
                sysUserService.updateUser(sysUser);
                break;
            case 4:
                // 冻结
                sysUser.setStatus("1");
                sysUserService.updateUser(sysUser);
                break;
        }
        return R.ok();
    }
 
    /**
     * 批量删除crm诊所管理
     */
    @Log(title = "crm诊所管理信息-诊所管理审核", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "诊所管理审核",notes = "状态 1=待审核 2=已拒绝 3=使用中 4=冻结")
    @PutMapping(value = "/auditClinic")
    public R<Boolean> auditClinic(@RequestBody TCrmClinicAuditDTO dto) {
        TCrmClinic crmClinic = crmClinicService.getById(dto.getId());
        crmClinic.setStatus(dto.getStatus());
        crmClinic.setAuditRemark(dto.getAuditRemark());
        crmClinicService.updateById(crmClinic);
        // 查询用户
        if(dto.getStatus() == 3){
            SysUser sysUser = sysUserService.selectUserById(crmClinic.getUserId());
            sysUser.setDelFlag("0");
            sysUserService.updateUser(sysUser);
        }
        return R.ok();
    }
 
    @Log(title = "crm诊所管理信息-诊所管理导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "诊所管理导出")
    @PostMapping("/exportList")
    public void exportList(@RequestBody TCrmClinicQuery query){
 
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        Long userId = tokenService.getLoginUser().getUserId();
        if(roleType == 2){
            query.setUserId(userId);
            query.setRoleType(roleType);
            // 查询账号绑定的分公司
            TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
                    .eq(TCrmBranch::getUserId,userId)
                    .last("LIMIT 1"));
            List<String> branchIds = new ArrayList<>();
            if(crmBranch != null && crmBranch.getPersonType() == 1){
                List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getPersonType, 2)
                        .eq(TCrmBranch::getCorrelationPersonId, userId));
                if(!CollectionUtils.isEmpty(crmBranches)){
                    branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                    List<Long> userIds = crmBranches.stream().map(TCrmBranch::getUserId).collect(Collectors.toList());
                    List<TCrmBranch> crmBranches1 = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                            .eq(TCrmBranch::getPersonType, 3)
                            .in(TCrmBranch::getCorrelationPersonId, userIds));
                    if(!CollectionUtils.isEmpty(crmBranches1)){
                        List<String> childrenIds = crmBranches1.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                        branchIds.addAll(childrenIds);
                    }
                }
            }
            if(crmBranch != null && crmBranch.getPersonType() == 2){
                List<TCrmBranch> crmBranches = crmBranchService.list(Wrappers.lambdaQuery(TCrmBranch.class)
                        .eq(TCrmBranch::getPersonType, 3)
                        .eq(TCrmBranch::getCorrelationPersonId, userId));
                if(!CollectionUtils.isEmpty(crmBranches)){
                    branchIds = crmBranches.stream().map(TCrmBranch::getId).collect(Collectors.toList());
                }
                branchIds.add(crmBranch.getId());
            }
            if(crmBranch != null && crmBranch.getPersonType() == 3){
                branchIds.add(crmBranch.getId());
            }
//            query.setBranchId(crmBranch.getId());
            branchIds = branchIds.stream().distinct().collect(Collectors.toList());
            query.setBranchIds(branchIds);
        }
        if(roleType == 3){
            query.setUserId(userId);
            query.setRoleType(roleType);
            // 查询账号绑定的业务员
            TCrmSalesperson crmSalesperson = crmSalespersonService.getOne(Wrappers.lambdaQuery(TCrmSalesperson.class)
                    .eq(TCrmSalesperson::getUserId,userId)
                    .last("LIMIT 1"));
            query.setSalespersonId(crmSalesperson.getId());
        }
        if (roleType == 1){
            query.setRoleType(roleType);
        }
 
        List<TCrmClinicListExport> crmClinicListExports = crmClinicService.exportList(query);
        for (TCrmClinicListExport crmClinicListExport : crmClinicListExports) {
            if(Objects.nonNull(crmClinicListExport.getLowProcurementMoney())){
                crmClinicListExport.setLowProcurementMoneyStr("¥"+crmClinicListExport.getLowProcurementMoney());
            }
            if(Objects.nonNull(crmClinicListExport.getMonthPurchaseAmount())){
                crmClinicListExport.setMonthPurchaseAmountStr("¥"+crmClinicListExport.getMonthPurchaseAmount());
            }
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TCrmClinicListExport.class, crmClinicListExports);
        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 = "crm诊所管理信息-诊所审核导出", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "诊所审核导出")
    @PostMapping("/exportAudit")
    public void exportAudit(@RequestBody TCrmClinicQuery query){
        List<TCrmClinicAuditExport> crmClinicAuditExports = crmClinicService.exportAudit(query);
        for (TCrmClinicAuditExport crmClinicAuditExport : crmClinicAuditExports) {
            if(Objects.nonNull(crmClinicAuditExport.getLowProcurementMoney())){
                crmClinicAuditExport.setLowProcurementMoneyStr("¥"+crmClinicAuditExport.getLowProcurementMoney());
            }
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TCrmClinicAuditExport.class, crmClinicAuditExports);
        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();
            }
        }
    }
 
    /**
     * 业绩短信提醒
     */
    @ApiOperation(value = "crm诊所管理信息-业绩短信提醒", notes = "clinicId:诊所id")
    @GetMapping(value = "/medicationReminder")
    public R<String> medicationReminder(@RequestParam(value = "clinicId") String clinicId) {
        TCrmClinic crmClinic = crmClinicService.getById(clinicId);
        if(StringUtils.isNotBlank(crmClinic.getPhone())){
            int performanceCount = crmClinic.getPerformanceCount() + 1;
            TCrmSalesperson crmSalesperson = crmSalespersonService.getById(crmClinic.getSalespersonId());
            TSysMessageTemplate messageTemplate = sysMessageTemplateService.getOne(Wrappers.lambdaQuery(TSysMessageTemplate.class)
                    .eq(TSysMessageTemplate::getTemplateType, 2));
            // 发送短信
            try {
                Map<String,String> params = new HashMap<>();
                params.put("name",crmSalesperson.getSalespersonName());
                params.put("num", Integer.toString(performanceCount));
                msgUtils.sendMsg(crmClinic.getPhone(),params, messageTemplate.getTemplateCode());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return R.ok();
    }
 
}