我正在创建一个帐户,然后发送带有密码的电子邮件。现在,它首先发送电子邮件,然后保存用户。如何更改订单,因为退货后我无法使用电子邮件功能。
我该如何解决?我应该为这两个功能创建另一个功能吗?
public WorkDetail setWorkerData(PatchWorkerRequest request, User user, WorkDetail workDetail) {
if (request.getName() != null) {
user.setName(request.getName());
}
if (request.getIdCode() != null) {
user.setIdCode(request.getIdCode());
}
if (request.getEmail() != null) {
user.setEmail(request.getEmail());
}
if (request.getPhone() != null) {
user.setPhone(request.getPhone());
}
if (request.getStatus() != null) {
user.setStatus(request.getStatus());
}
// Work details
if (request.getJobRelation() != null) {
workDetail.setJobRelation(request.getJobRelation());
}
if (request.getSalary() != null) {
workDetail.setSalary(request.getSalary());
}
if (request.getDistricts() != null) {
workDetail.setDistricts(request.getDistricts());
}
if (request.getCompetences() != null) {
workDetail.setCompetences(request.getCompetences());
}
workDetail = workDetailRepository.save(workDetail);
user.setWorkDetail(workDetail);
workDetail.setUser(user);
return workDetailRepository.save(workDetail);
}
public WorkDetail createWorker(PatchWorkerRequest request) {
WorkDetail workDetail = new WorkDetail();
User user = new User();
String generatedPassword = userService.generatePassword(8);
user.setPassword(passwordEncoder.encode(generatedPassword));
emailService.sendMail("SYDA", new String[]{request.getEmail()},
"SYDA: teile loodi kasutaja",
"Teile loodi SYDA süsteemi kasutaja. Teie parool on: " + generatedPassword +
"\nSisse saate logida kasutades emaili: " + request.getEmail());
return this.setWorkerData(request, user, workDetail);
}
答案 0 :(得分:1)
代替
emailService.sendMail("SYDA", new String[]{request.getEmail()},
"SYDA: teile loodi kasutaja",
"Teile loodi SYDA süsteemi kasutaja. Teie parool on: " + generatedPassword +
"\nSisse saate logida kasutades emaili: " + request.getEmail());
return this.setWorkerData(request, user, workDetail);
写
WorkDetail workDetailSaved = this.setWorkerData(request, user, workDetail);
emailService.sendMail("SYDA", new String[]{request.getEmail()},
"SYDA: teile loodi kasutaja",
"Teile loodi SYDA süsteemi kasutaja. Teie parool on: " + generatedPassword +
"\nSisse saate logida kasutades emaili: " + request.getEmail());
return workDetailSaved;
(由Stultuske提议)
示例:
public WorkDetail createWorker(PatchWorkerRequest request) {
User user = buildUser(request); // builds a new User-instance from the request
String generatedPassword = userService.generatePassword(8);
user.setPassword(passwordEncoder.encode(generatedPassword));
WorkDetail workDetail = buildWorkDetail(request, user); // builds a new WorkDetail-instance from the request
workDetail.setUser(user);
workDetailRepository.save(workDetail);
user.setWorkDetail(workDetail);
emailService.sendMail("SYDA", new String[]{request.getEmail()},
"...",
"...);
return workDetail;
}