Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
liberhe committed Dec 17, 2023
2 parents 48cfce7 + 420a8ea commit 35e2d55
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 105 deletions.
21 changes: 13 additions & 8 deletions src/main/java/com/dl/officialsite/common/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
public class Constants {

/**
* 0: 已加入
* 1: 申请中
* 2: 已退出
* 0: 已加入 1: 申请中 2: 已退出
*/
public static final int IN_TEAM = 0;

/**
* 0: 同意加入
* 1: 申请中
* 0: 同意加入 1: 申请中
*/
public static final int REQUEST_TEAM = 1;

Expand All @@ -27,14 +24,22 @@ public class Constants {
public static final int REJECT_TEAM = 3;



/**
* 主要技术类型
* 主要技术类型
*/
public static final int HIRING_MAIN_SKILL = 1;

/**
* 辅助技术类型
* 辅助技术类型
*/
public static final int HIRING_OTHER_SKILL = 2;

/**
* 岗位状态 0:jd 删除 1:jd 招聘中 2:jd 过期
*/
public static final int JD_DELTE = 0;

public static final int JD_ING = 1;

public static final int JD_INVAILD = 2;
}
21 changes: 7 additions & 14 deletions src/main/java/com/dl/officialsite/hiring/HireController.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
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.List;

import com.dl.officialsite.login.Auth;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
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 All @@ -29,6 +26,7 @@
**/
@RestController
@RequestMapping("/hire")
@Slf4j
public class HireController {

@Autowired
Expand All @@ -53,6 +51,10 @@ public BaseResponse update(@RequestParam String address,@RequestBody HiringVO hi
return BaseResponse.successWithData(null);
}

/**
* 删除简历
*/

/**
* 查询简历详情
*/
Expand Down Expand Up @@ -95,13 +97,4 @@ public BaseResponse allByAddress(@RequestParam String address,
return BaseResponse.successWithData(hiringVOList);
}


/**
* 投递职位 todo
*/
@PostMapping("/apply")
public BaseResponse apply(@RequestBody ApplyVo applyVo) {
hireService.apply(applyVo.getHireId(), applyVo.getFile());
return BaseResponse.successWithData(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @ClassName HireRepository
* @Author jackchen
* @Date 2023/11/7 10:45
* @Description TODO
* @Description 简历
**/
public interface HireRepository extends JpaRepository<Hiring, Long>,
JpaSpecificationExecutor<Hiring> {
Expand Down
122 changes: 81 additions & 41 deletions src/main/java/com/dl/officialsite/hiring/HireService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@
import com.dl.officialsite.mail.EmailService;
import com.dl.officialsite.member.Member;
import com.dl.officialsite.member.MemberRepository;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.persistence.criteria.CriteriaBuilder.In;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import lombok.extern.slf4j.Slf4j;
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 @@ -34,6 +36,7 @@
* @Description HireService
**/
@Service
@Slf4j
public class HireService {

@Autowired
Expand All @@ -56,7 +59,6 @@ public HiringVO add(HiringVO hiringVO) {
BeanUtils.copyProperties(hiringVO, hiring);
hireRepository.save(hiring);

// optimise todo saveall
ArrayList<HiringSkill> hiringSkillList = new ArrayList<>();
hiringVO.getMainSkills().forEach(mainSkill -> {
HiringSkill hiringSkill = new HiringSkill();
Expand All @@ -81,39 +83,76 @@ public HiringVO add(HiringVO hiringVO) {
}

public Page<HiringVO> all(Pageable pageable) {
List<HiringVO> hiringVOList = new ArrayList<>();;
Page<Hiring> hiringPage = hireRepository.findAll(pageable);
List<Long> hiringIds = hiringPage.getContent().stream()
.map(Hiring::getId)
.collect(Collectors.toList());

//find HiringId in [] query one time !
hiringPage.getContent().forEach(hiring -> {
List<HiringSkillVO> mainSkills = hiringSkillRepository.findByHiringId(hiring.getId())
.stream()
.map(hiringSkill -> {
HiringSkillVO hiringSkillVO = new HiringSkillVO();
BeanUtils.copyProperties(hiringSkill, hiringSkillVO);
return hiringSkillVO;
})
.collect(Collectors.toList());
Map<Long, List<HiringSkillVO>> skillsMap = fetchSkillsMapByHiringIds(hiringIds);

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);
hiringVOList.add(hiringVO);
});
Page<HiringVO> hiringVOPage = new PageImpl<>(hiringVOList, pageable, hiringPage.getTotalElements());
return hiringVOPage;
List<HiringVO> hiringVOList = hiringPage.getContent().stream()
.map(hiring -> mapHiringToHiringVO(hiring, skillsMap))
.collect(Collectors.toList());

return new PageImpl<>(hiringVOList, pageable, hiringPage.getTotalElements());
}

public Page<HiringVO> all(Pageable pageable, List<Long> hiringIds) {
Map<Long, List<HiringSkillVO>> skillsMap = fetchSkillsMapByHiringIds(hiringIds);

Page<Hiring> hiringPage = hireRepository.findAll(
(root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
In<Object> in = criteriaBuilder.in(root.get("id"));
for (Long hiringId : hiringIds) {
in.value(hiringId);
}
predicates.add(in);

return criteriaQuery.where(predicates.toArray(new Predicate[predicates.size()]))
.getRestriction();
}, pageable);

List<HiringVO> hiringVOList = hiringPage.getContent().stream()
.map(hiring -> mapHiringToHiringVO(hiring, skillsMap))
.collect(Collectors.toList());

return new PageImpl<>(hiringVOList, pageable, hiringPage.getTotalElements());
}

private Map<Long, List<HiringSkillVO>> fetchSkillsMapByHiringIds(List<Long> hiringIds) {
List<HiringSkillVO> allSkills = hiringSkillRepository.findByHiringId(hiringIds).stream()
.map(hiringSkill -> {
HiringSkillVO hiringSkillVO = new HiringSkillVO();
BeanUtils.copyProperties(hiringSkill, hiringSkillVO);
return hiringSkillVO;
})
.collect(Collectors.toList());

return allSkills.stream()
.collect(Collectors.groupingBy(HiringSkillVO::getHiringId));
}

private HiringVO mapHiringToHiringVO(Hiring hiring, Map<Long, List<HiringSkillVO>> skillsMap) {
HiringVO hiringVO = new HiringVO();
BeanUtils.copyProperties(hiring, hiringVO);

List<HiringSkillVO> mainSkillList = skillsMap.getOrDefault(hiring.getId(), Collections.emptyList())
.stream()
.filter(skill -> skill.getType() == Constants.HIRING_MAIN_SKILL)
.collect(Collectors.toList());

List<HiringSkillVO> otherSkillList = skillsMap.getOrDefault(hiring.getId(), Collections.emptyList())
.stream()
.filter(skill -> skill.getType() == Constants.HIRING_OTHER_SKILL)
.collect(Collectors.toList());

hiringVO.setMainSkills(mainSkillList);
hiringVO.setOtherSkills(otherSkillList);
return hiringVO;
}


public HiringVO detail(Long id) {
HiringVO hiringVO = new HiringVO();
Hiring hiring = hireRepository.findById(id)
Expand Down Expand Up @@ -186,23 +225,23 @@ public void update(HiringVO hiringVO) {
BeanUtils.copyProperties(hiringVO, hiring);
hireRepository.save(hiring);
//删除原有的技能

//todo
hiringSkillRepository.deleteByHiringId(hiring.getId());
List<HiringSkill> hiringSkills = new ArrayList<>();
//添加新的技能
hiringVO.getMainSkills().forEach(mainSkill -> {
HiringSkill hiringSkill = new HiringSkill();
BeanUtils.copyProperties(mainSkill, hiringSkill);
hiringSkill.setHiringId(hiring.getId());
hiringSkillRepository.save(hiringSkill);
hiringSkills.add(hiringSkill);
});

hiringVO.getOtherSkills().forEach(otherSkill -> {
HiringSkill hiringSkill = new HiringSkill();
BeanUtils.copyProperties(otherSkill, hiringSkill);
hiringSkill.setHiringId(hiring.getId());
hiringSkillRepository.save(hiringSkill);
hiringSkills.add(hiringSkill);
});
hiringSkillRepository.saveAll(hiringSkills);
}

public Page<HiringVO> selectByAddress(String address, Pageable pageable) {
Expand Down Expand Up @@ -246,20 +285,21 @@ public Page<HiringVO> selectByAddress(String address, Pageable pageable) {


//application
public void apply(Long hireId, String file) {
public void apply(Long hireId, String fileKey) {
Hiring hiring = hireRepository.findById(hireId)
.orElseThrow(() -> new BizException(NOT_FOUND_JD.getCode(), NOT_FOUND_JD.getMsg()));
String address = hiring.getAddress();
System.out.println("address!!! " + address);
Member member = memberRepository.findByAddress(address).orElseThrow(() -> new BizException(
NOT_FOUND_MEMBER.getCode(), NOT_FOUND_MEMBER.getMsg()));
try {
// File file1 = new File(String.valueOf(fileService.download("")));
// emailService.sendMailWithFile(member.getEmail(), "有新人投递简历", "有新人投递简历", file1);
emailService.sendMail(member.getEmail(), "有新人投递简历", "有新人投递简历:\n简历地址:\n "+ "https://dlh-1257682033.cos.ap-hongkong.myqcloud.com/"+ file );
emailService.sendMail(member.getEmail(), "有新人投递简历", "有新人投递简历:\n简历地址:\n "+ "https://dlh-1257682033.cos.ap-hongkong.myqcloud.com/"+ fileKey );

} catch (Exception e) {
throw new RuntimeException(e);
}
}

public <T> Optional<Hiring> findById(Long hireId) {
return hireRepository.findById(hireId);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/dl/officialsite/hiring/Hiring.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package com.dl.officialsite.hiring;


import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Data
@Entity
@Table(name = "hiring")
@EntityListeners(AuditingEntityListener.class)
public class Hiring {

@Id
Expand All @@ -39,8 +44,21 @@ public class Hiring {

@CreationTimestamp
@Column(updatable = false, nullable = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;

@LastModifiedDate
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;

private String address;

/**
* 0:jd 删除
* 1:jd 招聘中
* 2:jd 过期
* 设置默认值,默认值为招聘中
*/
private int status = 1;

}
2 changes: 1 addition & 1 deletion src/main/java/com/dl/officialsite/hiring/HiringSkill.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @ClassName HiringSkill
* @Author jackchen
* @Date 2023/12/7 00:33
* @Description TODO
* @Description 招聘技能
**/
@Data
@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public interface HiringSkillRepository extends JpaRepository<HiringSkill, Long>
@Query(value = "select * from hiring_skill where hiring_id = :hiring_id",nativeQuery = true)
List<HiringSkill> findByHiringId(@Param("hiring_id")Long hiring_id);

@Query(value = "select * from hiring_skill where hiring_id in (:hiring_ids)",nativeQuery = true)
List<HiringSkill> findByHiringId(@Param("hiring_ids") List<Long> hiring_ids);

@Query(value = "select * from hiring_skill where skill in (:skills)",nativeQuery = true)
List<HiringSkill> findBySkill(@Param("skills")List<String> skills);

Expand Down
Loading

0 comments on commit 35e2d55

Please sign in to comment.