Skip to content

Commit

Permalink
Merge pull request #218 from cheng521521/main
Browse files Browse the repository at this point in the history
feat: admin
  • Loading branch information
liberhe authored Mar 24, 2024
2 parents dffde43 + 386b577 commit 7eeb9bd
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 69 deletions.
97 changes: 97 additions & 0 deletions src/main/java/com/dl/officialsite/admin/AdminController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.dl.officialsite.admin;

import com.dl.officialsite.admin.vo.HireSearchParams;
import com.dl.officialsite.bounty.BountyService;
import com.dl.officialsite.bounty.vo.BountySearchVo;
import com.dl.officialsite.bounty.vo.BountyVo;
import com.dl.officialsite.common.base.BaseResponse;
import com.dl.officialsite.common.enums.CodeEnums;
import com.dl.officialsite.common.exception.BizException;
import com.dl.officialsite.hiring.HireService;
import com.dl.officialsite.member.MemberService;
import com.dl.officialsite.team.TeamService;
import lombok.extern.slf4j.Slf4j;
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.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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 AdminController
* @Author jackchen
* @Date 2024/3/23 15:26
* @Description admin
**/
@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminController {

private final MemberService memberService;

private final TeamService teamService;

private final HireService hireService;

private final BountyService bountyService;

public AdminController(MemberService memberService, TeamService teamService, HireService hireService,
BountyService bountyService) {
this.memberService = memberService;
this.teamService = teamService;
this.hireService = hireService;
this.bountyService = bountyService;
}

/**
* freeze member
* //todo 查询member list把禁用的member filter out/ member不可登录
*/
@PutMapping("/member/freeze")
public BaseResponse freezeMember(@RequestParam String adminAddress,
@RequestParam String address) {
if (!teamService.checkMemberIsSuperAdmin(adminAddress)) {
throw new BizException(CodeEnums.NOT_THE_ADMIN);
}
memberService.freeze(address);
return BaseResponse.success();
}

@PostMapping("/hire/all")
public BaseResponse allHire(@RequestParam String adminAddress,
@RequestBody HireSearchParams hireSearchParams) {
if (!teamService.checkMemberIsSuperAdmin(adminAddress)) {
throw new BizException(CodeEnums.NOT_THE_ADMIN);
}
return BaseResponse.successWithData(hireService.getAllHire(hireSearchParams));
}

@DeleteMapping("/hire/delete")
public BaseResponse deleteHire(@RequestParam String adminAddress, @RequestParam Long hireId) {
if (!teamService.checkMemberIsSuperAdmin(adminAddress)) {
throw new BizException(CodeEnums.NOT_THE_ADMIN);
}
hireService.deleteHire(hireId);
return BaseResponse.success();
}

@PostMapping("/bounty/all")
public BaseResponse allBounty(@RequestParam String adminAddress,
@RequestParam(defaultValue = "1") Integer pageNumber,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestBody BountySearchVo bountySearchParams) {
if (!teamService.checkMemberIsSuperAdmin(adminAddress)) {
throw new BizException(CodeEnums.NOT_THE_ADMIN);
}
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize, Sort.by(Sort.Direction.DESC, "createTime"));
Page<BountyVo> page = bountyService.search(bountySearchParams, pageable);
return BaseResponse.successWithData(page);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/dl/officialsite/admin/AdminService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dl.officialsite.admin;

import org.springframework.stereotype.Service;

/**
* @ClassName AdminService
* @Author jackchen
* @Date 2024/3/23 15:27
* @Description AdminService
**/
@Service
public class AdminService {

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

import lombok.Data;

/**
* @ClassName HireSearchParams
* @Author jackchen
* @Date 2024/3/23 15:40
* @Description HireSearchParams
**/
@Data
public class HireSearchParams {

/**
* hiring creator
*/
private String creator;

/**
* hiring status
*/
private String status;

/**
* hiring title
*/
private String title;
}
20 changes: 10 additions & 10 deletions src/main/java/com/dl/officialsite/bounty/BountyService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dl.officialsite.bounty;

import static com.dl.officialsite.common.constants.Constants.BOUNTY_MEMBER_MAP_STATUS_FINISH;
import static com.dl.officialsite.common.enums.CodeEnums.NOT_FOUND_BOUNTY;

import com.dl.officialsite.bot.constant.BotEnum;
import com.dl.officialsite.bot.constant.ChannelEnum;
import com.dl.officialsite.bot.event.EventNotify;
Expand All @@ -13,21 +16,18 @@
import com.dl.officialsite.common.exception.BizException;
import com.dl.officialsite.member.Member;
import com.dl.officialsite.member.MemberRepository;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.criteria.Predicate;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.persistence.criteria.Predicate;
import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;

import static com.dl.officialsite.common.constants.Constants.BOUNTY_MEMBER_MAP_STATUS_FINISH;
import static com.dl.officialsite.common.enums.CodeEnums.NOT_FOUND_BOUNTY;
import org.springframework.util.StringUtils;

/**
* @ClassName BountyService
Expand Down Expand Up @@ -92,12 +92,12 @@ public Page<BountyVo> search(BountySearchVo bountySearchVo, Pageable pageable) {
}

private Specification<Bounty> hasCreator(String creator) {
return (root, query, criteriaBuilder) -> creator != null ?
return (root, query, criteriaBuilder) -> StringUtils.hasText(creator) ?
criteriaBuilder.equal(root.get("creator"), creator) : null;
}

private Specification<Bounty> hasTitle(String title) {
return (root, query, criteriaBuilder) -> title != null ?
return (root, query, criteriaBuilder) -> StringUtils.hasText(title) ?
criteriaBuilder.like(root.get("title"), "%" + title + "%") : null;
}

Expand Down
82 changes: 54 additions & 28 deletions src/main/java/com/dl/officialsite/hiring/HireService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.admin.vo.HireSearchParams;
import com.dl.officialsite.common.constants.Constants;
import com.dl.officialsite.common.exception.BizException;
import com.dl.officialsite.file.cos.FileService;
Expand Down Expand Up @@ -30,6 +31,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @ClassName HireService
Expand Down Expand Up @@ -58,31 +60,34 @@ public class HireService {

@Autowired
private MemberService memberService;

/**
* 新增岗位
* @param hiringVO
* @return
*/
public HiringVO add(HiringVO hiringVO, String address) {

//check in hiring team or in sharing team

MemberWithTeam memberWithTeam = memberService.getMemberWithTeamInfoByAddress(address);
MemberWithTeam memberWithTeam = memberService.getMemberWithTeamInfoByAddress(address);
ArrayList<Team> teams = memberWithTeam.getTeams();
List teamNames = teams.stream().map(Team::getTeamName).collect(Collectors.toList());
if(!teamNames.contains("Dapp-Learning DAO co-founders") && !teamNames.contains("Dapp-Learning DAO sharing group") && !teamNames.contains("Hiring Team")) {
if (!teamNames.contains("Dapp-Learning DAO co-founders") && !teamNames.contains(
"Dapp-Learning DAO sharing group") && !teamNames.contains("Hiring Team")) {
throw new BizException("1001", "no permission");
}
//do nothing

//do nothing

Hiring hiring = new Hiring();
BeanUtils.copyProperties(hiringVO, hiring);
hireRepository.save(hiring);

List<HiringSkill> hiringSkillList = new ArrayList<>();
hiringVO.getMainSkills().forEach(skill -> createHiringSkill(Constants.HIRING_MAIN_SKILL, skill, hiring, hiringSkillList));
hiringVO.getOtherSkills().forEach(skill -> createHiringSkill(Constants.HIRING_OTHER_SKILL, skill, hiring, hiringSkillList));
hiringVO.getMainSkills().forEach(
skill -> createHiringSkill(Constants.HIRING_MAIN_SKILL, skill, hiring,
hiringSkillList));
hiringVO.getOtherSkills().forEach(
skill -> createHiringSkill(Constants.HIRING_OTHER_SKILL, skill, hiring,
hiringSkillList));

hiringSkillRepository.saveAll(hiringSkillList);
hiringVO.setId(hiring.getId());
Expand All @@ -91,17 +96,17 @@ public HiringVO add(HiringVO hiringVO, String address) {
return hiringVO;
}

private void createHiringSkill(int skillType, HiringSkillVO skillVO, Hiring hiring, List<HiringSkill> hiringSkillList) {
private void createHiringSkill(int skillType, HiringSkillVO skillVO, Hiring hiring,
List<HiringSkill> hiringSkillList) {
HiringSkill hiringSkill = new HiringSkill();
BeanUtils.copyProperties(skillVO, hiringSkill);
hiringSkill.setType(skillType);
hiringSkill.setHiringId(hiring.getId());
hiringSkillList.add(hiringSkill);
}

/**
* 查询所有岗位
* @param pageable
* @return
*/
public Page<HiringVO> all(Pageable pageable) {
Page<Hiring> hiringPage = hireRepository.findAll(pageable);
Expand All @@ -120,9 +125,6 @@ public Page<HiringVO> all(Pageable pageable) {

/**
* 根据岗位ID,查询岗位详情
* @param pageable
* @param hiringIds
* @return
*/
public Page<HiringVO> all(Pageable pageable, List<Long> hiringIds) {
Map<Long, List<HiringSkillVO>> skillsMap = fetchSkillsMapByHiringIds(hiringIds);
Expand All @@ -149,8 +151,6 @@ public Page<HiringVO> all(Pageable pageable, List<Long> hiringIds) {

/**
* 根据岗位ID集合查询岗位标签
* @param hiringIds
* @return
*/
private Map<Long, List<HiringSkillVO>> fetchSkillsMapByHiringIds(List<Long> hiringIds) {
List<HiringSkillVO> allSkills = hiringSkillRepository.findByHiringId(hiringIds).stream()
Expand All @@ -167,20 +167,19 @@ private Map<Long, List<HiringSkillVO>> fetchSkillsMapByHiringIds(List<Long> hiri

/**
* 将Hiring转换为HiringVO
* @param hiring
* @param skillsMap
* @return
*/
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())
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())
List<HiringSkillVO> otherSkillList = skillsMap.getOrDefault(hiring.getId(),
Collections.emptyList())
.stream()
.filter(skill -> skill.getType() == Constants.HIRING_OTHER_SKILL)
.collect(Collectors.toList());
Expand All @@ -202,8 +201,6 @@ public HiringVO detail(Long id) {

/**
* 根据技能筛选岗位
* @param skills
* @return
*/
public List<HiringVO> selectBySkills(List<String> skills) {
List<HiringSkill> hiringSkills = hiringSkillRepository.findBySkill(skills);
Expand All @@ -215,7 +212,8 @@ public List<HiringVO> selectBySkills(List<String> skills) {
})
.collect(Collectors.groupingBy(HiringSkillVO::getHiringId));

List<Long> hiringIds = hiringSkills.stream().map(HiringSkill::getHiringId).distinct().collect(Collectors.toList());
List<Long> hiringIds = hiringSkills.stream().map(HiringSkill::getHiringId).distinct()
.collect(Collectors.toList());

return hireRepository.findAllById(hiringIds).stream()
.map(hiring -> this.mapHiringToHiringVO(hiring, skillsMap))
Expand All @@ -224,7 +222,6 @@ public List<HiringVO> selectBySkills(List<String> skills) {

/**
* 修改简历
* @param hiringVO
*/
public void update(HiringVO hiringVO) {
Hiring hiring = hireRepository.findById(hiringVO.getId())
Expand Down Expand Up @@ -252,10 +249,12 @@ public void update(HiringVO hiringVO) {
}

public Page<HiringVO> selectByAddress(String address, Pageable pageable) {
Specification<Hiring> spec = (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("address"), address);
Specification<Hiring> spec = (root, query, criteriaBuilder) -> criteriaBuilder.equal(
root.get("address"), address);
Page<Hiring> page = hireRepository.findAll(spec, pageable);

List<Long> hiringIds = page.getContent().stream().map(Hiring::getId).collect(Collectors.toList());
List<Long> hiringIds = page.getContent().stream().map(Hiring::getId)
.collect(Collectors.toList());
Map<Long, List<HiringSkillVO>> skillsMap = this.fetchSkillsMapByHiringIds(hiringIds);

List<HiringVO> hiringVOList = page.getContent().stream()
Expand All @@ -274,7 +273,8 @@ public void apply(Long hireId, String fileKey) {
Member member = memberRepository.findByAddress(address).orElseThrow(() -> new BizException(
NOT_FOUND_MEMBER.getCode(), NOT_FOUND_MEMBER.getMsg()));
try {
emailService.sendMail(member.getEmail(), "有新人投递简历", "有新人投递简历:\n简历地址:\n "+ "https://dlh-1257682033.cos.ap-hongkong.myqcloud.com/"+ fileKey );
emailService.sendMail(member.getEmail(), "有新人投递简历", "有新人投递简历:\n简历地址:\n "
+ "https://dlh-1257682033.cos.ap-hongkong.myqcloud.com/" + fileKey);

} catch (Exception e) {
throw new RuntimeException(e);
Expand All @@ -284,4 +284,30 @@ public void apply(Long hireId, String fileKey) {
public <T> Optional<Hiring> findById(Long hireId) {
return hireRepository.findById(hireId);
}

public Object getAllHire(HireSearchParams hireSearchParams) {
return hireRepository.findAll(((root, query, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.hasText(hireSearchParams.getCreator())) {
predicates.add(
criteriaBuilder.equal(root.get("address"), hireSearchParams.getCreator()));
}
if (StringUtils.hasText(hireSearchParams.getStatus())) {
predicates.add(
criteriaBuilder.equal(root.get("status"), hireSearchParams.getStatus()));
}
if (StringUtils.hasText(hireSearchParams.getTitle())) {
predicates.add(criteriaBuilder.like(root.get("position"),
"%" + hireSearchParams.getTitle() + "%"));
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
}));
}

public void deleteHire(Long hireId) {
Hiring hiring = hireRepository.findById(hireId)
.orElseThrow(() -> new BizException(NOT_FOUND_JD.getCode(), NOT_FOUND_JD.getMsg()));
hiring.setStatus(1);
hireRepository.save(hiring);
}
}
Loading

0 comments on commit 7eeb9bd

Please sign in to comment.