zhaowenxuan
2024-05-24 4b3bc0db42b5f57b2422247ec73eb96d4f1ba7c4
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
package com.ltkj.web.controller.system;
 
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import com.ltkj.web.controller.email.MailConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.LazyMap;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.*;
 
 
/**
 * @Company: 西安路泰科技有限公司
 * @Author: zjh
 * @Date: 2023/5/18 11:34
 */
@RestController
@RequestMapping("/hosp/yqorder")
@Api(tags = "体检延期记录接口")
@Slf4j
public class TjYqOrderController {
 
    @Resource
    private TjYqOrderService yqOrderService;
    @Resource
    private ITjProjectService projectService;
    @Resource
    private ITjSendTemplateService templateService;
    @Resource
    private MailConfig mailConfig;
    @Resource
    private ITjSendRecordService sendRecordService;
 
    /**
     * 查询体检延期记录列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询体检延期记录列表")
    public AjaxResult list(@ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer pageNum,
                           @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize,
                           @ApiParam(value = "体检号") @RequestParam(required = false) String tjNum,
                           @ApiParam(value = "姓名") @RequestParam(required = false) String name,
                           @ApiParam(value = "登记开始时间") @RequestParam(required = false) String djbeginTime,
                           @ApiParam(value = "登记结束时间") @RequestParam(required = false) String djendTime,
                           @ApiParam(value = "延期开始时间") @RequestParam(required = false) String yqbeginTime,
                           @ApiParam(value = "延期结束时间") @RequestParam(required = false) String yqendTime) {
        LambdaQueryWrapper<TjYqOrder>wq=new LambdaQueryWrapper<>();
        Page<TjYqOrder> page=new Page<>(pageNum,pageSize);
        if(null !=tjNum){
            wq.likeLeft(TjYqOrder::getTjNum,tjNum);
        }
        if(null !=name){
            wq.like(TjYqOrder::getCusName,name);
        }
        if(null !=djbeginTime && null !=djendTime){
            Date date = DateUtil.parse(djendTime,"yyyy-MM-dd");
            wq.between(TjYqOrder::getOrderTime,djbeginTime,DateUtil.endOfDay(date));
        }
        if(null !=yqbeginTime && null !=yqendTime){
            Date date = DateUtil.parse(yqendTime,"yyyy-MM-dd");
            wq.between(TjYqOrder::getYqTime,yqbeginTime,DateUtil.endOfDay(date));
        }
        Page<TjYqOrder> orderPage = yqOrderService.page(page, wq);
        List<TjYqOrder> orderList = orderPage.getRecords();
        if(null !=orderList && orderList.size()>0){
            for (TjYqOrder yqOrder : orderList) {
                yqOrder.setCusName(MatchUtils.hideCusName(yqOrder.getCusName()));
                yqOrder.setPhone(MatchUtils.hidePhoneNum(yqOrder.getPhone()));
                if(null !=yqOrder.getProIds()){
                    String[] strings = StringUtils.split(yqOrder.getProIds(), ",");
                    String names = projectService.appendTjProjectNames(strings);
                    yqOrder.setNames(names);
                }
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("list",orderList);
        map.put("total",orderPage.getTotal());
        return AjaxResult.success(map);
    }
 
 
 
    /**
     * 批量发送短信或邮件
     */
    @PostMapping("/sendMessageOrEmail")
    @ApiOperation(value = "批量发送短信或邮件")
    public AjaxResult sendMessage(@RequestBody Map<String, Object> map) {
        Object type = map.get("type");
        if(null !=type){
            if(type.equals(1)){
                return sendMali(map);
            }
            if(type.equals(2)){
                return sendMsg(map);
            }
            if(type.equals(3)){
                extracted(map);
                sendMsg(map);
                return AjaxResult.success("操作成功");
            }
        }
        return AjaxResult.error("操作失败");
    }
 
    //发送短信2
    private AjaxResult sendMsg(Map<String, Object> map) {
        extracted(map);
        return AjaxResult.success("短信发送成功!");
    }
 
    private void extracted(Map<String, Object> map) {
        Integer tempId = (Integer) map.get("tempId");
        List<String> yqorderIds = ( List<String>) map.get("yqorderIds");
        TjSendTemplate byId = templateService.getById(Long.valueOf(tempId));
        if (byId != null) {
            if(null !=yqorderIds){
                for (String id : yqorderIds) {
                    TjSendRecord tjSendRecord = new TjSendRecord();
                    TjYqOrder one = yqOrderService.getById(id);
                    if (one != null) {
//                        if(one.getEmilSend().equals("1")){
//                            continue;
//                        }
                        if (null !=one.getEmail()) {
                            String subject = "路泰体检中心";
                            String head = "尊敬的" +one.getCusName()  + "先生/女士,";
                            String content = head + byId.getTempContent();
                            tjSendRecord.setTjNumber(one.getTjNum());
                            tjSendRecord.setType("2");
                            tjSendRecord.setSendStatus("1");
                            tjSendRecord.setSendTime(new DateTime());
                            tjSendRecord.setSubject(subject);
                            tjSendRecord.setContent(content);
                            one.setMsgSend("1");
                            yqOrderService.updateById(one);
                        }
                        sendRecordService.save(tjSendRecord);
                    }
                }
            }
        }
    }
 
    //发送邮件1
    private AjaxResult sendMali(Map<String, Object> map) {
        Integer tempId = (Integer) map.get("tempId");
        List<String> yqorderIds = ( List<String>) map.get("yqorderIds");
        TjSendTemplate byId = templateService.getById(Long.valueOf(tempId));
        if (byId != null) {
            if(null!=yqorderIds) {
                for (String id : yqorderIds) {
                TjSendRecord tjSendRecord = new TjSendRecord();
                TjYqOrder one = yqOrderService.getById(id);
                if (one != null) {
//                    if(one.getEmilSend().equals("1")){
//                        continue;
//                    }
                    String[] strings = StringUtils.split(one.getProIds(), ",");
                    String names = projectService.appendTjProjectNames(strings);
                    if (null !=one.getEmail()) {
                        String subject = "路泰体检中心";
                        String head = "尊敬的" + one.getCusName() + "先生/女士,";
                        String content = head +"您所延期的 ("+names+")项目 "+ byId.getTempContent();
                        tjSendRecord.setTjNumber(one.getTjNum());
                        tjSendRecord.setType("1");
                        tjSendRecord.setSendStatus("1");
                        tjSendRecord.setSendTime(new DateTime());
                        tjSendRecord.setSubject(subject);
                        tjSendRecord.setContent(content);
                        SimpleMailMessage message = new SimpleMailMessage();
                        message.setFrom("1138758025@qq.com");
                        // 邮件接收人(可以使用 String[] 发送给多个用户)
                        message.setTo(one.getEmail());
                        message.setSubject(subject);
                        message.setText(content);
                        try {
                            mailConfig.getMailSender("1138758025@qq.com", "lwsbmlbqgpaqfgdb").send(message);
                            one.setEmilSend("1");
                            yqOrderService.updateById(one);
                        } catch (MailException e) {
                            e.printStackTrace();
                        }
                    }
                    tjSendRecord.setSendStatus("0");
                    sendRecordService.save(tjSendRecord);
                }
            }
            }
            return AjaxResult.success("邮件发送成功");
        }
        return AjaxResult.error("发送失败");
    }
 
}