From ea126149983ccd3459e523f1af1dbb6daa4dd0a9 Mon Sep 17 00:00:00 2001 From: chengpengxiang <15503679582@163.com> Date: Mon, 11 Dec 2023 22:18:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:1.=20=E6=8B=9B=E8=81=98=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=20=E4=BC=9A=E9=87=8D=E5=A4=8D=E5=88=9B=E5=BB=BA=EF=BC=8C?= =?UTF-8?q?=E6=AF=8F=E6=AC=A1=E8=BF=94=E5=9B=9Eid=E9=83=BD=E6=98=AF0=20=20?= =?UTF-8?q?=20=20=20=202.=20=E6=8F=90=E4=BE=9B=E6=8C=89=E7=85=A7=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E8=80=85address=E6=9F=A5=E8=AF=A2=E6=8B=9B=E8=81=98?= =?UTF-8?q?=E7=9A=84=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=20=20=20=20=20=20?= =?UTF-8?q?3.=20=E7=94=B3=E8=AF=B7=E8=81=8C=E4=BD=8D=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20=20=20=20=20=204.=20=E6=8B=9B=E8=81=98=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=A1=B5=E7=BD=AE=E9=A1=B6=E5=B9=BF=E5=91=8A=E4=BD=8D?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20=20=20=20=20=205.=20=E6=8B=9B=E8=81=98?= =?UTF-8?q?=E8=96=AA=E8=B5=84=E5=AD=97=E6=AE=B5=E6=94=B9=E6=88=90=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../officialsite/common/enums/CodeEnums.java | 3 +- .../officialsite/hiring/HireController.java | 34 +++++++++- .../officialsite/hiring/HireRepository.java | 4 +- .../dl/officialsite/hiring/HireService.java | 53 ++++++++++++--- .../com/dl/officialsite/hiring/Hiring.java | 4 +- .../com/dl/officialsite/hiring/SponsorVo.java | 20 ++++++ .../dl/officialsite/hiring/vo/ApplyVo.java | 18 ++++++ .../dl/officialsite/hiring/vo/HiringVO.java | 7 +- .../dl/officialsite/mail/EmailService.java | 64 +++++++++++++++++++ 9 files changed, 186 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/dl/officialsite/hiring/SponsorVo.java create mode 100644 src/main/java/com/dl/officialsite/hiring/vo/ApplyVo.java diff --git a/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java b/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java index 3a88cb28..52495372 100644 --- a/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java +++ b/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java @@ -21,7 +21,8 @@ public enum CodeEnums { TEAM_ADMIN_NOT_EXIST("1006", "team admin not exist"), MEMBER_ALREADY_REQUEST_TEAM("1007", "member already request team"), - NOT_FOUND_JD("1008", "not found jd"); + NOT_FOUND_JD("1008", "not found jd"), + NOT_FOUND_MEMBER("1008", "not found user"); private String code; diff --git a/src/main/java/com/dl/officialsite/hiring/HireController.java b/src/main/java/com/dl/officialsite/hiring/HireController.java index b4019793..4e94c7c5 100644 --- a/src/main/java/com/dl/officialsite/hiring/HireController.java +++ b/src/main/java/com/dl/officialsite/hiring/HireController.java @@ -1,7 +1,9 @@ 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; @@ -9,6 +11,7 @@ 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; @@ -81,9 +84,36 @@ public BaseResponse all(@RequestParam String address,@RequestParam List * 按照创建者查看简历 */ @GetMapping("/address") - public BaseResponse all(@RequestParam String address) { - List 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 hiringVOList = hireService.selectByAddress(address,pageable); return BaseResponse.successWithData(hiringVOList); } + /** + * + */ + @GetMapping("/sponsors") + public BaseResponse sponsor() { + List 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); + } } diff --git a/src/main/java/com/dl/officialsite/hiring/HireRepository.java b/src/main/java/com/dl/officialsite/hiring/HireRepository.java index 20656c98..5fa2a118 100644 --- a/src/main/java/com/dl/officialsite/hiring/HireRepository.java +++ b/src/main/java/com/dl/officialsite/hiring/HireRepository.java @@ -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; @@ -11,7 +12,8 @@ * @Date 2023/11/7 10:45 * @Description TODO **/ -public interface HireRepository extends JpaRepository { +public interface HireRepository extends JpaRepository, + JpaSpecificationExecutor { /** diff --git a/src/main/java/com/dl/officialsite/hiring/HireService.java b/src/main/java/com/dl/officialsite/hiring/HireService.java index 3b329f3d..787f8189 100644 --- a/src/main/java/com/dl/officialsite/hiring/HireService.java +++ b/src/main/java/com/dl/officialsite/hiring/HireService.java @@ -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 @@ -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); @@ -175,13 +189,17 @@ public void update(HiringVO hiringVO) { }); } - public List selectByAddress(String address) { + public Page selectByAddress(String address, Pageable pageable) { List list = new ArrayList<>(); - hireRepository.findAllByAddress(address).forEach(hiring -> { - HiringVO hiringVO = new HiringVO(); - BeanUtils.copyProperties(hiring, hiringVO); - List hiringSkills = hiringSkillRepository.findByHiringId(hiring.getId()); - List mailSkills = hiringSkills.stream() + Specification spec = (root, query, criteriaBuilder) -> { + Path path = root.get("address"); + Predicate equal = criteriaBuilder.equal(path, address); + return equal; + }; + Page page = hireRepository.findAll(spec, pageable); + page.getContent().forEach(hiring -> { + List mainSkills = hiringSkillRepository.findByHiringId(hiring.getId()) + .stream() .filter(hiringSkill -> hiringSkill.getType() == Constants.HIRING_MAIN_SKILL) .map(hiringSkill -> { HiringSkillVO hiringSkillVO = new HiringSkillVO(); @@ -189,8 +207,8 @@ public List selectByAddress(String address) { return hiringSkillVO; }) .collect(Collectors.toList()); - hiringVO.setMainSkills(mailSkills); - List otherSkills = hiringSkills.stream() + List otherSkills = hiringSkillRepository.findByHiringId(hiring.getId()) + .stream() .filter(hiringSkill -> hiringSkill.getType() == Constants.HIRING_OTHER_SKILL) .map(hiringSkill -> { HiringSkillVO hiringSkillVO = new HiringSkillVO(); @@ -198,9 +216,26 @@ public List selectByAddress(String address) { 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 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); + } } } diff --git a/src/main/java/com/dl/officialsite/hiring/Hiring.java b/src/main/java/com/dl/officialsite/hiring/Hiring.java index 416a8c66..7c82d0db 100644 --- a/src/main/java/com/dl/officialsite/hiring/Hiring.java +++ b/src/main/java/com/dl/officialsite/hiring/Hiring.java @@ -32,9 +32,7 @@ public class Hiring { private String invoice; - private int minYearlySalary; - - private int maxYearlySalary; + private String yearlySalary; private String benefits; diff --git a/src/main/java/com/dl/officialsite/hiring/SponsorVo.java b/src/main/java/com/dl/officialsite/hiring/SponsorVo.java new file mode 100644 index 00000000..b4251b86 --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/SponsorVo.java @@ -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; + +} diff --git a/src/main/java/com/dl/officialsite/hiring/vo/ApplyVo.java b/src/main/java/com/dl/officialsite/hiring/vo/ApplyVo.java new file mode 100644 index 00000000..301e2ab4 --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/vo/ApplyVo.java @@ -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; +} diff --git a/src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java b/src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java index 2e14b796..cf60236c 100644 --- a/src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java +++ b/src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java @@ -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; diff --git a/src/main/java/com/dl/officialsite/mail/EmailService.java b/src/main/java/com/dl/officialsite/mail/EmailService.java index 28479fdd..79caca7b 100644 --- a/src/main/java/com/dl/officialsite/mail/EmailService.java +++ b/src/main/java/com/dl/officialsite/mail/EmailService.java @@ -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 @@ -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; + } }