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("发送失败");
|
}
|
|
}
|