diff --git a/README.md b/README.md index b0460732..c095715d 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ https://github.com/spruceid/siwe-go/blob/main/message.go ## build ``` - ssh root@81.69.8.95 + ssh root@43.135.22.107 ./gradlew build -x test - scp ./dist/apps/dl.jar root@81.69.8.95:/root/Dapp-Learning-Official-web/dist/apps + scp ./dist/apps/dl.jar root@43.135.22.107:/root/Official-website-backend/dist/app ``` diff --git a/src/main/java/com/dl/officialsite/OfficialSiteApplication.java b/src/main/java/com/dl/officialsite/OfficialSiteApplication.java index f97c6cb4..9281ccd2 100644 --- a/src/main/java/com/dl/officialsite/OfficialSiteApplication.java +++ b/src/main/java/com/dl/officialsite/OfficialSiteApplication.java @@ -15,6 +15,7 @@ public class OfficialSiteApplication { public static void main(String[] args) { + SpringApplication.run(OfficialSiteApplication.class, args); } diff --git a/src/main/java/com/dl/officialsite/common/constants/Constants.java b/src/main/java/com/dl/officialsite/common/constants/Constants.java index 30059984..26ddd8fa 100644 --- a/src/main/java/com/dl/officialsite/common/constants/Constants.java +++ b/src/main/java/com/dl/officialsite/common/constants/Constants.java @@ -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; } 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 f4b2874e..c319acea 100644 --- a/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java +++ b/src/main/java/com/dl/officialsite/common/enums/CodeEnums.java @@ -21,12 +21,16 @@ 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"), //Sharing SHARING_NOT_FOUND("5001", "Sharing not found"), SHARING_NOT_OWNER("5002", "You are no sharing user"), SHARING_LOCKED("5003", "Sharing locked, please contact admin to unlock"); + + + private String code; private String msg; diff --git a/src/main/java/com/dl/officialsite/config/SecurityConfig.java b/src/main/java/com/dl/officialsite/config/SecurityConfig.java index 8b60693f..c97a4608 100644 --- a/src/main/java/com/dl/officialsite/config/SecurityConfig.java +++ b/src/main/java/com/dl/officialsite/config/SecurityConfig.java @@ -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; diff --git a/src/main/java/com/dl/officialsite/hiring/HireController.java b/src/main/java/com/dl/officialsite/hiring/HireController.java new file mode 100644 index 00000000..2f30e924 --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/HireController.java @@ -0,0 +1,80 @@ +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.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 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); + } + + /** + * 修改简历 + */ + @PutMapping + public BaseResponse update(@RequestParam String address,@RequestBody HiringVO hiringVO) { + hireService.update(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 all = hireService.all(pageable); + return BaseResponse.successWithData(all); + } + + /** + * 按照类型查看简历 + */ + @GetMapping("/type") + public BaseResponse all(@RequestParam String address,@RequestParam List skills) { + List hiringVOList = hireService.selectBySkills(skills); + return BaseResponse.successWithData(hiringVOList); + } + +} diff --git a/src/main/java/com/dl/officialsite/hiring/HireRepository.java b/src/main/java/com/dl/officialsite/hiring/HireRepository.java new file mode 100644 index 00000000..8093df5b --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/HireRepository.java @@ -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 { +} diff --git a/src/main/java/com/dl/officialsite/hiring/HireService.java b/src/main/java/com/dl/officialsite/hiring/HireService.java new file mode 100644 index 00000000..5d516828 --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/HireService.java @@ -0,0 +1,175 @@ +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.HiringSkillVO; +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(); + BeanUtils.copyProperties(mainSkill, hiringSkill); + hiringSkill.setType(Constants.HIRING_MAIN_SKILL); + hiringSkill.setHiringId(hiring.getId()); + hiringSkillRepository.save(hiringSkill); + }); + + hiringVO.getOtherSkills().forEach(otherSkill -> { + HiringSkill hiringSkill = new HiringSkill(); + BeanUtils.copyProperties(otherSkill, hiringSkill); + hiringSkill.setType(Constants.HIRING_OTHER_SKILL); + hiringSkill.setHiringId(hiring.getId()); + hiringSkillRepository.save(hiringSkill); + }); + } + + public Page all(Pageable pageable) { + List hiringVOList = new ArrayList<>();; + Page hiringPage = hireRepository.findAll(pageable); + hiringPage.getContent().forEach(hiring -> { + List 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()); + List 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 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 hiringSkills = hiringSkillRepository.findByHiringId(id); + List mailSkills = hiringSkills.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 otherSkills = hiringSkills.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.setOtherSkills(otherSkills); + return hiringVO; + } + + public List selectBySkills(List skills) { + //使用in查询 + List hiringSkills = hiringSkillRepository.findBySkill(skills); + //去重通过hiringId + List hiringIds = hiringSkills.stream().map(HiringSkill::getHiringId).distinct().collect(Collectors.toList()); + List hiringVOList = new ArrayList<>(); + hireRepository.findAllById(hiringIds).forEach(hiring -> { + HiringVO hiringVO = new HiringVO(); + BeanUtils.copyProperties(hiring, hiringVO); + List mainSkills = hiringSkills.stream() + .filter(hiringSkill -> hiringSkill.getHiringId().equals(hiring.getId())) + .filter(hiringSkill -> hiringSkill.getType() == Constants.HIRING_MAIN_SKILL) + .map(hiringSkill -> { + HiringSkillVO hiringSkillVO = new HiringSkillVO(); + BeanUtils.copyProperties(hiringSkill, hiringSkillVO); + return hiringSkillVO; + }) + .collect(Collectors.toList()); + + List otherSkills = hiringSkills.stream() + .filter(hiringSkill -> hiringSkill.getHiringId().equals(hiring.getId())) + .filter(hiringSkill -> hiringSkill.getType() == Constants.HIRING_OTHER_SKILL) + .map(hiringSkill -> { + HiringSkillVO hiringSkillVO = new HiringSkillVO(); + BeanUtils.copyProperties(hiringSkill, hiringSkillVO); + return hiringSkillVO; + }) + .collect(Collectors.toList()); + hiringVO.setMainSkills(mainSkills); + hiringVO.setOtherSkills(otherSkills); + hiringVOList.add(hiringVO); + }); + return hiringVOList; + } + + /** + * 修改简历 + * @param hiringVO + */ + public void update(HiringVO hiringVO) { + Hiring hiring = hireRepository.findById(hiringVO.getId()) + .orElseThrow(() -> new BizException(NOT_FOUND_JD.getCode(), NOT_FOUND_JD.getMsg())); + BeanUtils.copyProperties(hiringVO, hiring); + hireRepository.save(hiring); + //删除原有的技能 + hiringSkillRepository.deleteByHiringId(hiring.getId()); + //添加新的技能 + hiringVO.getMainSkills().forEach(mainSkill -> { + HiringSkill hiringSkill = new HiringSkill(); + BeanUtils.copyProperties(mainSkill, hiringSkill); + hiringSkill.setHiringId(hiring.getId()); + hiringSkillRepository.save(hiringSkill); + }); + + hiringVO.getOtherSkills().forEach(otherSkill -> { + HiringSkill hiringSkill = new HiringSkill(); + BeanUtils.copyProperties(otherSkill, hiringSkill); + hiringSkill.setHiringId(hiring.getId()); + hiringSkillRepository.save(hiringSkill); + }); + } +} diff --git a/src/main/java/com/dl/officialsite/hiring/Hiring.java b/src/main/java/com/dl/officialsite/hiring/Hiring.java index d429496e..19475a97 100644 --- a/src/main/java/com/dl/officialsite/hiring/Hiring.java +++ b/src/main/java/com/dl/officialsite/hiring/Hiring.java @@ -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; } diff --git a/src/main/java/com/dl/officialsite/hiring/HiringSkill.java b/src/main/java/com/dl/officialsite/hiring/HiringSkill.java new file mode 100644 index 00000000..c918c16f --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/HiringSkill.java @@ -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; + +} diff --git a/src/main/java/com/dl/officialsite/hiring/HiringSkillRepository.java b/src/main/java/com/dl/officialsite/hiring/HiringSkillRepository.java new file mode 100644 index 00000000..93481ea5 --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/HiringSkillRepository.java @@ -0,0 +1,28 @@ +package com.dl.officialsite.hiring; + +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Transactional; + +/** + * @ClassName HiringSkillRepository + * @Author jackchen + * @Date 2023/12/7 00:36 + * @Description HiringSkillRepository + **/ +@Transactional +public interface HiringSkillRepository extends JpaRepository { + + @Query(value = "select * from hiring_skill where hiring_id = :hiring_id",nativeQuery = true) + List findByHiringId(@Param("hiring_id")Long hiring_id); + + @Query(value = "select * from hiring_skill where skill in (:skills)",nativeQuery = true) + List findBySkill(@Param("skills")List skills); + + @Query(value = "delete from hiring_skill where hiring_id = :hiring_id",nativeQuery = true) + @Modifying + void deleteByHiringId(@Param("hiring_id")Long hiring_id); +} diff --git a/src/main/java/com/dl/officialsite/hiring/vo/HiringSkillVO.java b/src/main/java/com/dl/officialsite/hiring/vo/HiringSkillVO.java new file mode 100644 index 00000000..423bc774 --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/vo/HiringSkillVO.java @@ -0,0 +1,19 @@ +package com.dl.officialsite.hiring.vo; + +import lombok.Data; + +/** + * @ClassName HiringSkillVO + * @Author jackchen + * @Date 2023/12/9 14:34 + * @Description HiringSkillVO + **/ +@Data +public class HiringSkillVO { + + private Long id; + + private String skill; + + private int type; +} diff --git a/src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java b/src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java new file mode 100644 index 00000000..621e927a --- /dev/null +++ b/src/main/java/com/dl/officialsite/hiring/vo/HiringVO.java @@ -0,0 +1,45 @@ +package com.dl.officialsite.hiring.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import java.util.Date; +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 mainSkills; + + private List otherSkills; + + private String company; + + private String invoice; + + private int minYearlySalary; + + private int maxYearlySalary; + + private String benefits; + + private String twitter; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; +} diff --git a/src/main/java/com/dl/officialsite/mail/EmailService.java b/src/main/java/com/dl/officialsite/mail/EmailService.java index 9002c01d..28479fdd 100644 --- a/src/main/java/com/dl/officialsite/mail/EmailService.java +++ b/src/main/java/com/dl/officialsite/mail/EmailService.java @@ -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; diff --git a/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java b/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java index 73778680..40f41cdf 100644 --- a/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java +++ b/src/main/java/com/dl/officialsite/redpacket/RedPacketService.java @@ -1,20 +1,12 @@ package com.dl.officialsite.redpacket; -import com.dl.officialsite.common.constants.Constants; -import com.dl.officialsite.common.enums.CodeEnums; -import com.dl.officialsite.common.exception.BizException; -import com.dl.officialsite.mail.EmailService; -import com.dl.officialsite.member.Member; -import com.dl.officialsite.member.MemberRepository; -import com.dl.officialsite.team.Team; -import com.dl.officialsite.team.TeamMember; -import com.dl.officialsite.team.TeamMemberRepository; -import com.dl.officialsite.team.TeamRepository; -import com.dl.officialsite.team.vo.*; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -23,22 +15,9 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.jpa.domain.Specification; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import org.springframework.util.ObjectUtils; - -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; -import javax.transaction.Transactional; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; /** * @ClassName TeamService @@ -58,6 +37,7 @@ public class RedPacketService { @Scheduled(cron = "0 0/2 * * * ? ") public void updateRedpacketStatus() throws IOException { log.info("schedule task begin --------------------- "); + System.out.println("验证是否是新代码--------------"); HttpPost request = new HttpPost("http://api.studio.thegraph.com/proxy/55957/dapp-learning-redpacket/version/latest"); request.setHeader("Content-Type", "application/json"); // Define your GraphQL query diff --git a/src/main/java/com/dl/officialsite/team/TeamController.java b/src/main/java/com/dl/officialsite/team/TeamController.java index ae8f5349..9f46995d 100644 --- a/src/main/java/com/dl/officialsite/team/TeamController.java +++ b/src/main/java/com/dl/officialsite/team/TeamController.java @@ -3,6 +3,7 @@ import com.dl.officialsite.common.base.BaseResponse; import com.dl.officialsite.member.Member; import com.dl.officialsite.team.vo.TeamMemberApproveVO; +import com.dl.officialsite.team.vo.TeamMemberBatchJoinVO; import com.dl.officialsite.team.vo.TeamMemberJoinVO; import com.dl.officialsite.team.vo.TeamQueryVo; import com.dl.officialsite.team.vo.TeamVO; @@ -50,6 +51,15 @@ BaseResponse join(@RequestBody TeamMemberJoinVO teamMember, @RequestParam String return BaseResponse.successWithData(null); } + /** + * 批量加入团队 + */ + @PostMapping("/join/batch") + BaseResponse batchJoin(@RequestBody TeamMemberBatchJoinVO teamMembers, @RequestParam String address) { + teamService.batchJoin(teamMembers); + return BaseResponse.successWithData(null); + } + /** * 退出团队 */ diff --git a/src/main/java/com/dl/officialsite/team/TeamService.java b/src/main/java/com/dl/officialsite/team/TeamService.java index dc5b78e3..14132b4e 100644 --- a/src/main/java/com/dl/officialsite/team/TeamService.java +++ b/src/main/java/com/dl/officialsite/team/TeamService.java @@ -8,6 +8,7 @@ import com.dl.officialsite.member.Member; import com.dl.officialsite.member.MemberRepository; import com.dl.officialsite.team.vo.TeamMemberApproveVO; +import com.dl.officialsite.team.vo.TeamMemberBatchJoinVO; import com.dl.officialsite.team.vo.TeamMemberJoinVO; import com.dl.officialsite.team.vo.TeamQueryVo; import com.dl.officialsite.team.vo.TeamVO; @@ -246,4 +247,26 @@ public TeamsMembersVo getTeamById(Long teamId) { CodeEnums.TEAM_NOT_EXIST.getMsg()); } } + + public void batchJoin(TeamMemberBatchJoinVO teamMembers) { + teamMembers.getMemberIds().forEach(memberId -> { + Optional optional = teamMemberRepository.findByTeamAndMember( + teamMembers.getTeamId(), memberId); + if (optional.isPresent()) { + TeamMember teamMember2 = optional.get(); + if (teamMember2.getStatus() == Constants.REQUEST_TEAM) { + throw new BizException(CodeEnums.MEMBER_ALREADY_REQUEST_TEAM.getCode(), + CodeEnums.MEMBER_ALREADY_REQUEST_TEAM.getMsg()); + } + teamMember2.setStatus(Constants.APPROVE_TEAM); + teamMemberRepository.save(teamMember2); + } else { + TeamMember teamMember1 = new TeamMember(); + teamMember1.setMemberId(memberId); + teamMember1.setTeamId(teamMembers.getTeamId()); + teamMember1.setStatus(Constants.APPROVE_TEAM); + teamMemberRepository.save(teamMember1); + } + }); + } } \ No newline at end of file diff --git a/src/main/java/com/dl/officialsite/team/vo/TeamMemberBatchJoinVO.java b/src/main/java/com/dl/officialsite/team/vo/TeamMemberBatchJoinVO.java new file mode 100644 index 00000000..42fd15ae --- /dev/null +++ b/src/main/java/com/dl/officialsite/team/vo/TeamMemberBatchJoinVO.java @@ -0,0 +1,18 @@ +package com.dl.officialsite.team.vo; + +import java.util.List; +import lombok.Data; + +/** + * @ClassName TeamMemberBatchJoinVO + * @Author jackchen + * @Date 2023/12/9 15:14 + * @Description TODO + **/ +@Data +public class TeamMemberBatchJoinVO { + + private Long teamId; + + private List memberIds; +}