Skip to content

Commit

Permalink
Merge pull request #80 from cheng521521/main
Browse files Browse the repository at this point in the history
feat:1. 招聘创建 会重复创建,每次返回id都是0
  • Loading branch information
yanyanho authored Dec 11, 2023
2 parents 32f58fe + d51ffb0 commit 7bf2630
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum CodeEnums {
MEMBER_ALREADY_REQUEST_TEAM("1007", "member already request team"),

NOT_FOUND_JD("1008", "not found jd"),
NOT_FOUND_MEMBER("1008", "not found user");
//Sharing
SHARING_NOT_FOUND("5001", "Sharing not found"),
SHARING_NOT_OWNER("5002", "You are no sharing user"),
Expand All @@ -30,7 +31,6 @@ public enum CodeEnums {




private String code;

private String msg;
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/com/dl/officialsite/hiring/HireController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.dl.officialsite.hiring;

import com.dl.officialsite.common.base.BaseResponse;
import com.dl.officialsite.hiring.vo.ApplyVo;
import com.dl.officialsite.hiring.vo.HiringVO;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -81,9 +84,36 @@ public BaseResponse all(@RequestParam String address,@RequestParam List<String>
* 按照创建者查看简历
*/
@GetMapping("/address")
public BaseResponse all(@RequestParam String address) {
List<HiringVO> hiringVOList = hireService.selectByAddress(address);
public BaseResponse allByAddress(@RequestParam String address,
@RequestParam(defaultValue = "1") Integer pageNumber,
@RequestParam(defaultValue = "10") Integer pageSize) {
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize, Sort.by(Sort.Direction.DESC, "createTime"));
Page<HiringVO> hiringVOList = hireService.selectByAddress(address,pageable);
return BaseResponse.successWithData(hiringVOList);
}

/**
*
*/
@GetMapping("/sponsors")
public BaseResponse sponsor() {
List<SponsorVo> sponsorVos = new ArrayList<>();
SponsorVo sponsorVo = new SponsorVo();
sponsorVo.setCompany("Optimism");
sponsorVo.setLink("https://www.optimism.io/");
sponsorVo.setIcon("https://assets-global.website-files.com/611dbb3c82ba72fbc285d4e2/611fd32ef63b79b5f8568d58_OPTIMISM-logo.svg");
for (int i = 0; i < 4; i++) {
sponsorVos.add(sponsorVo);
}
return BaseResponse.successWithData(sponsorVos);
}

/**
* 投递职位
*/
@PostMapping("/apply")
public BaseResponse apply(@ModelAttribute ApplyVo applyVo) {
hireService.apply(applyVo.getHireId(), applyVo.getFile());
return BaseResponse.successWithData(null);
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/dl/officialsite/hiring/HireRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

Expand All @@ -11,7 +12,8 @@
* @Date 2023/11/7 10:45
* @Description TODO
**/
public interface HireRepository extends JpaRepository<Hiring, Long> {
public interface HireRepository extends JpaRepository<Hiring, Long>,
JpaSpecificationExecutor<Hiring> {


/**
Expand Down
53 changes: 44 additions & 9 deletions src/main/java/com/dl/officialsite/hiring/HireService.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package com.dl.officialsite.hiring;

import static com.dl.officialsite.common.enums.CodeEnums.NOT_FOUND_JD;
import static com.dl.officialsite.common.enums.CodeEnums.NOT_FOUND_MEMBER;

import com.dl.officialsite.common.constants.Constants;
import com.dl.officialsite.common.exception.BizException;
import com.dl.officialsite.hiring.vo.HiringSkillVO;
import com.dl.officialsite.hiring.vo.HiringVO;
import com.dl.officialsite.mail.EmailService;
import com.dl.officialsite.member.Member;
import com.dl.officialsite.member.MemberRepository;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
* @ClassName HireService
Expand All @@ -31,6 +39,12 @@ public class HireService {
@Autowired
private HiringSkillRepository hiringSkillRepository;

@Autowired
private MemberRepository memberRepository;

@Autowired
private EmailService emailService;

public HiringVO add(HiringVO hiringVO) {
Hiring hiring = new Hiring();
BeanUtils.copyProperties(hiringVO, hiring);
Expand Down Expand Up @@ -175,32 +189,53 @@ public void update(HiringVO hiringVO) {
});
}

public List<HiringVO> selectByAddress(String address) {
public Page<HiringVO> selectByAddress(String address, Pageable pageable) {
List<HiringVO> list = new ArrayList<>();
hireRepository.findAllByAddress(address).forEach(hiring -> {
HiringVO hiringVO = new HiringVO();
BeanUtils.copyProperties(hiring, hiringVO);
List<HiringSkill> hiringSkills = hiringSkillRepository.findByHiringId(hiring.getId());
List<HiringSkillVO> mailSkills = hiringSkills.stream()
Specification<Hiring> spec = (root, query, criteriaBuilder) -> {
Path<Hiring> path = root.get("address");
Predicate equal = criteriaBuilder.equal(path, address);
return equal;
};
Page<Hiring> page = hireRepository.findAll(spec, pageable);
page.getContent().forEach(hiring -> {
List<HiringSkillVO> mainSkills = hiringSkillRepository.findByHiringId(hiring.getId())
.stream()
.filter(hiringSkill -> hiringSkill.getType() == Constants.HIRING_MAIN_SKILL)
.map(hiringSkill -> {
HiringSkillVO hiringSkillVO = new HiringSkillVO();
BeanUtils.copyProperties(hiringSkill, hiringSkillVO);
return hiringSkillVO;
})
.collect(Collectors.toList());
hiringVO.setMainSkills(mailSkills);
List<HiringSkillVO> otherSkills = hiringSkills.stream()
List<HiringSkillVO> otherSkills = hiringSkillRepository.findByHiringId(hiring.getId())
.stream()
.filter(hiringSkill -> hiringSkill.getType() == Constants.HIRING_OTHER_SKILL)
.map(hiringSkill -> {
HiringSkillVO hiringSkillVO = new HiringSkillVO();
BeanUtils.copyProperties(hiringSkill, hiringSkillVO);
return hiringSkillVO;
})
.collect(Collectors.toList());
HiringVO hiringVO = new HiringVO();
BeanUtils.copyProperties(hiring, hiringVO);
hiringVO.setMainSkills(mainSkills);
hiringVO.setOtherSkills(otherSkills);
list.add(hiringVO);
});
return list;
Page<HiringVO> hiringVOPage = new PageImpl<>(list, pageable, page.getTotalElements());
return hiringVOPage;
}

public void apply(Long hireId, MultipartFile file) {
Hiring hiring = hireRepository.findById(hireId)
.orElseThrow(() -> new BizException(NOT_FOUND_JD.getCode(), NOT_FOUND_JD.getMsg()));
String address = hiring.getAddress();
Member member = memberRepository.findByAddress(address).orElseThrow(() -> new BizException(
NOT_FOUND_MEMBER.getCode(), NOT_FOUND_MEMBER.getMsg()));
try {
emailService.sendMailWithFile(member.getEmail(), "有新人投递简历", "有新人投递简历", file);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
4 changes: 1 addition & 3 deletions src/main/java/com/dl/officialsite/hiring/Hiring.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class Hiring {

private String invoice;

private int minYearlySalary;

private int maxYearlySalary;
private String yearlySalary;

private String benefits;

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/dl/officialsite/hiring/SponsorVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.dl.officialsite.hiring;

import lombok.Data;

/**
* @ClassName SponsorVo
* @Author jackchen
* @Date 2023/12/11 21:16
* @Description 广告
**/
@Data
public class SponsorVo {

private String company;

private String link;

private String icon;

}
18 changes: 18 additions & 0 deletions src/main/java/com/dl/officialsite/hiring/vo/ApplyVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.dl.officialsite.hiring.vo;

import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

/**
* @ClassName ApplyVo
* @Author jackchen
* @Date 2023/12/11 21:45
* @Description TODO
**/
@Data
public class ApplyVo {

private Long hireId;

private MultipartFile file;
}
7 changes: 2 additions & 5 deletions src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ public class HiringVO {

private String invoice;

@NotNull(message = "最小年薪不能为空")
private int minYearlySalary;

@NotNull(message = "最大年薪不能为空")
private int maxYearlySalary;
@NotNull(message = "年薪不能为空")
private String yearlySalary;

private String benefits;

Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/dl/officialsite/mail/EmailService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.dl.officialsite.mail;

import java.io.File;
import java.util.List;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;


@Component
Expand Down Expand Up @@ -50,4 +59,59 @@ public void sendMail(String to, String subject, String text) {
emailSender.send(message);
}

public void sendMailWithFile(String to, String subject, String text, MultipartFile file)
throws Exception {
//1.创建一封邮件的实例对象
MimeMessage msg = emailSender.createMimeMessage();
//2.设置发件人地址
msg.setFrom("15503679582@163.com");
msg.setRecipient(MimeMessage.RecipientType.TO,new InternetAddress(to));
//4.设置邮件主题
msg.setSubject(subject);

//下面是设置邮件正文
//msg.setContent("简单的纯文本邮件!", "text/html;charset=UTF-8");

// 9. 创建附件"节点"
MimeBodyPart attachment = new MimeBodyPart();
// 读取本地文件
//mutilpart to file

DataSource ds2 = new FileDataSource(MultipartFileToFile(file));
DataHandler dh2 = new DataHandler(ds2);
// 将附件数据添加到"节点"
attachment.setDataHandler(dh2);
// 设置附件的文件名(需要编码)
attachment.setFileName(file.getName());

// 10. 设置(文本+图片)和 附件 的关系(合成一个大的混合"节点" / Multipart )
MimeMultipart mm = new MimeMultipart();
mm.addBodyPart(attachment); // 如果有多个附件,可以创建多个多次添加
mm.setSubType("mixed"); // 混合关系

// 11. 设置整个邮件的关系(将最终的混合"节点"作为邮件的内容添加到邮件对象)
msg.setContent(mm);

emailSender.send(msg);
}

//将MultipartFile转换为File
public static File MultipartFileToFile(MultipartFile multiFile) {
// 获取文件名
String fileName = multiFile.getOriginalFilename();
if (fileName == null){
return null;
}
// 获取文件后缀
String prefix = fileName.substring(fileName.lastIndexOf("."));
// 若须要防止生成的临时文件重复,能够在文件名后添加随机码
try {
File file = File.createTempFile(fileName, prefix);
multiFile.transferTo(file);
return file;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

0 comments on commit 7bf2630

Please sign in to comment.