This commit is contained in:
clay 2020-12-15 22:27:10 +08:00
parent ec742de4f2
commit 1037acfb14
6 changed files with 73 additions and 3 deletions

View File

@ -3,7 +3,9 @@ package live.tomey.api.express.controller;
import live.tomey.api.express.aop.Root;
import live.tomey.api.express.dto.Result;
import live.tomey.api.express.dto.ServerResult;
import live.tomey.api.express.entity.MailConfig;
import live.tomey.api.express.service.MailConfigService;
import live.tomey.api.express.unit.HttpServletRequestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -27,6 +29,28 @@ public class MailConfigController {
@Autowired
private MailConfigService mailConfigService;
@Root
@RequestMapping(value = "editmailconfig",method = RequestMethod.POST)
private Result editMailConfig(HttpServletRequest request){
try {
String sender = HttpServletRequestUtil.getString(request,"sender");
String personal = HttpServletRequestUtil.getString(request,"personal");
String emailSmtpHost = HttpServletRequestUtil.getString(request,"emailSmtpHost");
String emailSmtpPort = HttpServletRequestUtil.getString(request,"emailSmtpPort");
String username = HttpServletRequestUtil.getString(request,"username");
String password = HttpServletRequestUtil.getString(request,"password");
String encryption = HttpServletRequestUtil.getString(request,"encryption");
Integer state = HttpServletRequestUtil.getInteger(request,"state");
MailConfig mailConfig = new MailConfig(sender,personal,emailSmtpHost,emailSmtpPort,username,password,encryption,state);
ServerResult serverResult = mailConfigService.editMailConfig(mailConfig);
return new Result(serverResult.isStart(),0,serverResult.getMsg());
}catch (RuntimeException e){
logger.error(e.getMessage());
return new Result<>(false,-1,"系统错误!");
}
}
@Root
@RequestMapping(value = "getmailconfig" ,method = RequestMethod.POST)
private Result getMailConfig(HttpServletRequest request) {

View File

@ -1,6 +1,7 @@
package live.tomey.api.express.dao;
import live.tomey.api.express.entity.MailConfig;
import org.apache.ibatis.annotations.Param;
/**
* @author clay
@ -14,4 +15,6 @@ public interface MailConfigDao {
* @return
*/
MailConfig getMailConfig();
Integer updateMailConfig(@Param("mailConfig") MailConfig mailConfig);
}

View File

@ -9,7 +9,21 @@ public class MailConfig {
private String username;
private String password;
private String encryption;
private long state;
private Integer state;
public MailConfig() {
}
public MailConfig(String sender, String personal, String emailSmtpHost, String emailSmtpPort, String username, String password, String encryption, Integer state) {
this.sender = sender;
this.personal = personal;
this.emailSmtpHost = emailSmtpHost;
this.emailSmtpPort = emailSmtpPort;
this.username = username;
this.password = password;
this.encryption = encryption;
this.state = state;
}
public String getSender() {
return sender;
@ -74,11 +88,11 @@ public class MailConfig {
}
public long getState() {
public Integer getState() {
return state;
}
public void setState(long state) {
public void setState(Integer state) {
this.state = state;
}

View File

@ -13,5 +13,7 @@ public interface MailConfigService {
ServerResult<MailConfig> getMailConfig();
ServerResult editMailConfig(MailConfig mailConfig);
}

View File

@ -38,4 +38,19 @@ public class MailConfigServiceImpl implements MailConfigService {
return new ServerResult<>(false,"系统错误");
}
}
@Override
public ServerResult editMailConfig(MailConfig mailConfig) {
try {
Integer statr = mailConfigDao.updateMailConfig(mailConfig);
if (statr == 1){
return new ServerResult(true,"修改成功");
}else {
return new ServerResult(false,"修改失败");
}
}catch (RuntimeException e){
logger.error(e.getMessage());
return new ServerResult(false,"系统错误");
}
}
}

View File

@ -6,4 +6,16 @@
<select id="getMailConfig" resultType="live.tomey.api.express.entity.MailConfig">
SELECT * FROM w_mailconfig WHERE id = 1
</select>
<select id="updateMailConfig" resultType="updateMailConfig">
UPDATE w_mailconfig SET
w_mailconfig.sender = #{mailConfig.sender},
w_mailconfig.personal = #{mailConfig.personal},
w_mailconfig.email_smtp_host = #{mailConfig.emailSmtpHost},
w_mailconfig.email_smtp_port = #{mailConfig.emailSmtpPort},
w_mailconfig.username = #{mailConfig.username},
w_mailconfig.password = #{mailConfig.password},
w_mailconfig.encryption = #{mailConfig.encryption},
w_mailconfig.state = #{mailConfig.sender}
WHERE w_mailconfig.id = 1
</select>
</mapper>