完成contact

This commit is contained in:
yyhouc 2023-04-14 18:05:15 +08:00
parent 4d0aeb8bc6
commit 033da7dc22
3 changed files with 67 additions and 119 deletions

View File

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
@ -11,6 +13,7 @@ import java.io.Serializable;
* @TableName contact
*/
@TableName(value ="contact")
@Data
public class Contact implements Serializable {
/**
* 用户姓名
@ -37,123 +40,28 @@ public class Contact implements Serializable {
*/
private Long id;
/**
* 留言时间
*/
private String contactDate;
/**
* 回复时间
*/
private String replyDate;
/**
* 状态
*/
private int status;
/**
* 回复内容
*/
private String text;
/**
* 回复主题
*/
private String subject;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
/**
* 用户姓名
*/
public String getUserName() {
return userName;
}
/**
* 用户姓名
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* 电子邮件
*/
public String getEmail() {
return email;
}
/**
* 电子邮件
*/
public void setEmail(String email) {
this.email = email;
}
/**
* 组织
*/
public String getOrganization() {
return organization;
}
/**
* 组织
*/
public void setOrganization(String organization) {
this.organization = organization;
}
/**
* 意见建议
*/
public String getMessage() {
return message;
}
/**
* 意见建议
*/
public void setMessage(String message) {
this.message = message;
}
/**
* 数据自增列
*/
public Long getId() {
return id;
}
/**
* 数据自增列
*/
public void setId(Long id) {
this.id = id;
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Contact other = (Contact) that;
return (this.getUserName() == null ? other.getUserName() == null : this.getUserName().equals(other.getUserName()))
&& (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
&& (this.getOrganization() == null ? other.getOrganization() == null : this.getOrganization().equals(other.getOrganization()))
&& (this.getMessage() == null ? other.getMessage() == null : this.getMessage().equals(other.getMessage()))
&& (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getUserName() == null) ? 0 : getUserName().hashCode());
result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
result = prime * result + ((getOrganization() == null) ? 0 : getOrganization().hashCode());
result = prime * result + ((getMessage() == null) ? 0 : getMessage().hashCode());
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", userName=").append(userName);
sb.append(", email=").append(email);
sb.append(", organization=").append(organization);
sb.append(", message=").append(message);
sb.append(", id=").append(id);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@ -3,7 +3,9 @@ package com.kening.vordm.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.kening.vordm.entity.Email;
import com.kening.vordm.service.ContactService;
import com.kening.vordm.service.EmailService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@ -11,6 +13,7 @@ import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springblade.core.mp.support.Query;
@ -18,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
import com.kening.vordm.entity.Contact;
import java.util.Arrays;
import java.util.Date;
@RestController
@AllArgsConstructor
@ -32,6 +36,8 @@ public class ContactController{
})
@GetMapping("/list")
public R<IPage<Contact>> list(Contact contact, Query query) {
QueryWrapper<Contact> queryWrapper = Condition.getQueryWrapper(contact);
queryWrapper.orderByDesc("contact_date");
IPage<Contact> pages = contactService.page(Condition.getPage(query), Condition.getQueryWrapper(contact));
return R.data(pages);
}
@ -64,7 +70,37 @@ public class ContactController{
@ApiOperation(value = "提交", notes = "传入Contact")
@PostMapping("/submit")
public R submit(@ApiParam(value = "Contact对象", required = true) @RequestBody Contact contact) {
contact.setContactDate(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
return R.status(contactService.saveOrUpdate(contact));
}
private final EmailService emailService;
@ApiOperationSupport(order = 6)
@ApiOperation(value = "提交", notes = "传入Contact")
@PostMapping("/sendEmail")
public R sendEmail(@ApiParam(value = "Contact对象", required = true) @RequestBody Contact contact) {
contact.setReplyDate(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
contact.setStatus(1);
Email email = new Email();
email.setSubject(contact.getSubject());
email.setText(contact.getText());
String [] to = new String[]{contact.getEmail()};
email.setTos(to);
email.setHtmlText(true);
try {
emailService.sendMimeMessage(email);
return R.status(contactService.saveOrUpdate(contact));
} catch (Exception e) {
return R.fail("发送失败");
}
}
@ApiOperationSupport(order = 8)
@ApiOperation(value = "详情", notes = "传入id")
@GetMapping("/observed")
public R<String> observed(@ApiParam(value = "主键", required = true) @RequestParam String id) {
Contact contact = new Contact();
contact.setId(Long.valueOf(id));
contact.setStatus(2);
return R.data(contactService.updateById(contact)? "ok" : "false");
}
}

View File

@ -4,8 +4,10 @@ import com.kening.vordm.entity.Email;
import com.kening.vordm.service.EmailService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -15,13 +17,15 @@ import javax.mail.MessagingException;
@RequestMapping("/ui/email")
@RequiredArgsConstructor
@Api(value = "邮箱发送", tags = "邮箱发送")
@Slf4j
public class EmailController {
private final EmailService emailService;
@PostMapping("/emailSend")
public R emailSend(Email email) {
public R emailSend(@RequestBody Email email) {
try {
log.info("email:{}", email.getText());
emailService.sendMimeMessage(email);
return R.success("OK");
} catch (MessagingException e) {