Skip to content

Commit

Permalink
Merge pull request #68 from cheng521521/main
Browse files Browse the repository at this point in the history
feat:添加招聘模块
  • Loading branch information
yanyanho authored Dec 9, 2023
2 parents 127943c + 3eab4cf commit 93ea091
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 17 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/dl/officialsite/common/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ public class Constants {
public static final int REQUEST_TEAM = 1;

public static final int EXIT_TEAM = 2;

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

/**
* 辅助技术类型
*/
public static final int HIRING_OTHER_SKILL = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public enum CodeEnums {
TEAM_NOT_EXIST("1005", "team not exist"),
LOGIN_IN("2001", "please login"),
TEAM_ADMIN_NOT_EXIST("1006", "team admin not exist"),
MEMBER_ALREADY_REQUEST_TEAM("1007", "member already request team");
MEMBER_ALREADY_REQUEST_TEAM("1007", "member already request team"),

NOT_FOUND_JD("1008", "not found jd");

private String code;

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/dl/officialsite/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.dl.officialsite.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.firewall.StrictHttpFirewall;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/com/dl/officialsite/hiring/HireController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.dl.officialsite.hiring;

import com.dl.officialsite.common.base.BaseResponse;
import com.dl.officialsite.hiring.vo.HiringVO;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* @ClassName HireController
* @Author jackchen
* @Date 2023/11/7 10:45
* @Description HireController
**/
@RestController
@RequestMapping("/hire")
public class HireController {

@Autowired
private HireService hireService;

/**
* 添加简历
*/
@PostMapping
public BaseResponse add(@RequestParam String address,@RequestBody HiringVO hiringVO) {
hireService.add(hiringVO);
return BaseResponse.successWithData(null);
}

/**
* 查询简历详情
*/
@GetMapping
public BaseResponse detail(@RequestParam String address,@RequestParam Long id) {
HiringVO hiringVO = hireService.detail(id);
return BaseResponse.successWithData(hiringVO);
}

/**
* 查询所有简历
*/
@GetMapping("/all")
public BaseResponse all(@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> all = hireService.all(pageable);
return BaseResponse.successWithData(all);
}

/**
* 按照类型查看简历
*/
@GetMapping("/type")
public BaseResponse all(@RequestParam String address,@RequestParam List<String> skills) {
List<HiringVO> hiringVOList = hireService.selectBySkills(skills);
return BaseResponse.successWithData(hiringVOList);
}

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

import org.springframework.data.jpa.repository.JpaRepository;

/**
* @ClassName HireRepository
* @Author jackchen
* @Date 2023/11/7 10:45
* @Description TODO
**/
public interface HireRepository extends JpaRepository<Hiring, Long> {
}
107 changes: 107 additions & 0 deletions src/main/java/com/dl/officialsite/hiring/HireService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.dl.officialsite.hiring;

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

import com.dl.officialsite.common.constants.Constants;
import com.dl.officialsite.common.exception.BizException;
import com.dl.officialsite.hiring.vo.HiringVO;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
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.stereotype.Service;

/**
* @ClassName HireService
* @Author jackchen
* @Date 2023/11/7 10:45
* @Description HireService
**/
@Service
public class HireService {

@Autowired
private HireRepository hireRepository;

@Autowired
private HiringSkillRepository hiringSkillRepository;

public void add(HiringVO hiringVO) {
Hiring hiring = new Hiring();
BeanUtils.copyProperties(hiringVO, hiring);
hireRepository.save(hiring);
hiringVO.getMainSkills().forEach(mainSkill -> {
HiringSkill hiringSkill = new HiringSkill();
hiringSkill.setHiringId(hiring.getId());
hiringSkill.setSkill(mainSkill);
hiringSkill.setType(Constants.HIRING_MAIN_SKILL);
hiringSkillRepository.save(hiringSkill);
});

hiringVO.getOtherSkills().forEach(otherSkill -> {
HiringSkill hiringSkill = new HiringSkill();
hiringSkill.setHiringId(hiring.getId());
hiringSkill.setSkill(otherSkill);
hiringSkill.setType(Constants.HIRING_OTHER_SKILL);
hiringSkillRepository.save(hiringSkill);
});
}

public Page<HiringVO> all(Pageable pageable) {
List<HiringVO> hiringVOList = new ArrayList<>();;
Page<Hiring> hiringPage = hireRepository.findAll(pageable);
hiringPage.getContent().forEach(hiring -> {
List<String> skills = hiringSkillRepository.findByHiringId(hiring.getId()).stream()
.map(HiringSkill::getSkill)
.collect(Collectors.toList());
HiringVO hiringVO = new HiringVO();
BeanUtils.copyProperties(hiring, hiringVO);
hiringVO.setMainSkills(skills);
hiringVOList.add(hiringVO);
});
Page<HiringVO> hiringVOPage = new PageImpl<>(hiringVOList, pageable, hiringPage.getTotalElements());
return hiringVOPage;
}

public HiringVO detail(Long id) {
HiringVO hiringVO = new HiringVO();
Hiring hiring = hireRepository.findById(id)
.orElseThrow(() -> new BizException(NOT_FOUND_JD.getCode(), NOT_FOUND_JD.getMsg()));
BeanUtils.copyProperties(hiring, hiringVO);
List<HiringSkill> hiringSkills = hiringSkillRepository.findByHiringId(id);
List<String> mailSkills = hiringSkills.stream()
.filter(hiringSkill -> hiringSkill.getType() == Constants.HIRING_MAIN_SKILL)
.map(HiringSkill::getSkill)
.collect(Collectors.toList());
hiringVO.setMainSkills(mailSkills);
List<String> otherSkills = hiringSkills.stream()
.filter(hiringSkill -> hiringSkill.getType() == Constants.HIRING_OTHER_SKILL)
.map(HiringSkill::getSkill)
.collect(Collectors.toList());
hiringVO.setOtherSkills(otherSkills);
return hiringVO;
}

public List<HiringVO> selectBySkills(List<String> skills) {
//使用in查询
List<HiringSkill> hiringSkills = hiringSkillRepository.findBySkill(skills);
//去重通过hiringId
List<Long> hiringIds = hiringSkills.stream().map(HiringSkill::getHiringId).distinct().collect(Collectors.toList());
List<HiringVO> hiringVOList = new ArrayList<>();
hireRepository.findAllById(hiringIds).forEach(hiring -> {
HiringVO hiringVO = new HiringVO();
BeanUtils.copyProperties(hiring, hiringVO);
List<String> mainSkills = hiringSkills.stream()
.filter(hiringSkill -> hiringSkill.getHiringId().equals(hiring.getId()))
.map(HiringSkill::getSkill)
.collect(Collectors.toList());
hiringVO.setMainSkills(mainSkills);
hiringVOList.add(hiringVO);
});
return hiringVOList;
}
}
50 changes: 40 additions & 10 deletions src/main/java/com/dl/officialsite/hiring/Hiring.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
package com.dl.officialsite.hiring;


import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;

@Data
@Entity
@Table(name = "hiring")
public class Hiring {
private String headline;
private String employer;
private String jd;
private String role;
private String requirement;
private String locate;
private String salary;
private String memo;

private String contact;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String position;

private String description;

private String location;

private String email;

private String company;

private String invoice;

private int minYearlySalary;

private int maxYearlySalary;

private String benefits;

private String twitter;

@CreationTimestamp
@Column(updatable = false, nullable = false)
private Date createTime;

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

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;

/**
* @ClassName HiringSkill
* @Author jackchen
* @Date 2023/12/7 00:33
* @Description TODO
**/
@Data
@Entity
@Table(name = "hiring_skill")
public class HiringSkill {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Long hiringId;

private String skill;

private int type;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dl.officialsite.hiring;

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

/**
* @ClassName HiringSkillRepository
* @Author jackchen
* @Date 2023/12/7 00:36
* @Description HiringSkillRepository
**/
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 skill in (:skills)",nativeQuery = true)
List<HiringSkill> findBySkill(@Param("skills")List<String> skills);
}
41 changes: 41 additions & 0 deletions src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.dl.officialsite.hiring.vo;

import java.util.List;
import lombok.Data;

/**
* @ClassName HiringVO
* @Author jackchen
* @Date 2023/12/7 00:37
* @Description HiringVO
**/
@Data
public class HiringVO {

private Long id;

private String position;

private String description;

private String location;

private String email;

private List<String> mainSkills;

private List<String> otherSkills;

private String company;

private String invoice;

private int minYearlySalary;

private int maxYearlySalary;

private String benefits;

private String twitter;

}
1 change: 0 additions & 1 deletion src/main/java/com/dl/officialsite/mail/EmailService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dl.officialsite.mail;

import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
Expand Down

0 comments on commit 93ea091

Please sign in to comment.