diff --git a/luoo_user/src/main/java/com/luoo/user/controller/ArtistController.java b/luoo_user/src/main/java/com/luoo/user/controller/ArtistController.java index f49e98a..eac533d 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/ArtistController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/ArtistController.java @@ -2,6 +2,7 @@ package com.luoo.user.controller; import api.Result; import com.luoo.user.dto.ArtistRegisterDto; +import com.luoo.user.dto.ArtistUserBindDto; import com.luoo.user.service.ArtistService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -37,4 +38,16 @@ public class ArtistController { return Result.success(); } + @ApiOperation(value = "音乐人-成员绑定", notes = "音乐人-成员绑定") + public Result memberBind(@ApiParam(value = "绑定对象",required = true) @Valid @RequestBody ArtistUserBindDto artistUserBindDto) { + artistService.bindArtistAndMember(artistUserBindDto); + return Result.success(); + } + + @ApiOperation(value = "音乐人-成员解绑", notes = "音乐人-成员解绑") + public Result memberUnBind(@ApiParam(value = "解绑对象",required = true) @Valid @RequestBody ArtistUserBindDto artistUserBindDto) { + artistService.unBindArtistAndMember(artistUserBindDto); + return Result.success(); + } + } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/ArtistUserDao.java b/luoo_user/src/main/java/com/luoo/user/dao/ArtistUserDao.java new file mode 100644 index 0000000..6399ae3 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/ArtistUserDao.java @@ -0,0 +1,19 @@ +package com.luoo.user.dao; + +import com.luoo.user.pojo.ArtistUser; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** + * @Author: yawei.huang + * @Package: com.luoo.user.dao + * @Project: luoo_parent + * @Date: 2024/4/25 16:02 + * @Filename: ArtistUserDao + * @Describe: + */ +public interface ArtistUserDao extends JpaRepository, JpaSpecificationExecutor { + + public ArtistUser findArtistUserByArtistIdAndUserId(String artist, String userId); + +} diff --git a/luoo_user/src/main/java/com/luoo/user/dto/ArtistUserBindDto.java b/luoo_user/src/main/java/com/luoo/user/dto/ArtistUserBindDto.java new file mode 100644 index 0000000..a9ec9e2 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/ArtistUserBindDto.java @@ -0,0 +1,28 @@ +package com.luoo.user.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * @Author: yawei.huang + * @Package: com.luoo.user.dto + * @Project: luoo_parent + * @Date: 2024/4/25 16:06 + * @Filename: ArtistUserBindDto + * @Describe: 音乐人与成员绑定/解绑用 + */ +@Data +public class ArtistUserBindDto implements Serializable { + @ApiModelProperty(name = "音乐人id") + @NotNull(message = "音乐人id必填") + private String artistId; + + @ApiModelProperty(name = "成员id") + @NotNull(message = "成员id必填") + private String UserId; +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/ArtistUser.java b/luoo_user/src/main/java/com/luoo/user/pojo/ArtistUser.java new file mode 100644 index 0000000..895b19c --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/pojo/ArtistUser.java @@ -0,0 +1,37 @@ +package com.luoo.user.pojo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serializable; + +/** + * @Author: yawei.huang + * @Package: com.luoo.user.pojo + * @Project: luoo_parent + * @Date: 2024/4/25 15:53 + * @Filename: ArtistUser + * @Describe: 音乐人与成员绑定对象 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode +@Builder +@Entity +@Table(name="tb_artist_user") +public class ArtistUser implements Serializable { + + @Id + @ApiModelProperty("id") + private String id; + + @ApiModelProperty("音乐人id") + private String artistId; + + @ApiModelProperty("成员id") + private String userId; +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/ArtistService.java b/luoo_user/src/main/java/com/luoo/user/service/ArtistService.java index 0b8a454..4ba197d 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/ArtistService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/ArtistService.java @@ -1,11 +1,11 @@ package com.luoo.user.service; -import com.luoo.user.dao.ArtistInfoDao; -import com.luoo.user.dao.ArtistResponsibleDao; -import com.luoo.user.dao.UserInfoDao; +import com.luoo.user.dao.*; import com.luoo.user.dto.ArtistRegisterDto; +import com.luoo.user.dto.ArtistUserBindDto; import com.luoo.user.pojo.ArtistInfo; import com.luoo.user.pojo.ArtistResponsible; +import com.luoo.user.pojo.ArtistUser; import com.luoo.user.pojo.UserInfo; import constants.Constants; import enums.UserStatusEnum; @@ -48,6 +48,9 @@ public class ArtistService { @Autowired private BCryptPasswordEncoder encoder; + @Autowired + private ArtistUserDao artistUserDao; + /** * 音乐人注册 * @@ -97,5 +100,40 @@ public class ArtistService { } + /** + * 音乐人-成员绑定 + * + * @param artistUserBindDto + */ + @Transactional(rollbackFor = Exception.class) + public void bindArtistAndMember(ArtistUserBindDto artistUserBindDto) { + ArtistUser artistUser = artistUserDao.findArtistUserByArtistIdAndUserId(artistUserBindDto.getArtistId(), artistUserBindDto.getUserId()); + if(artistUser == null) { + ArtistUser build = ArtistUser.builder() + .id(String.valueOf(idWorker.nextId())) + .artistId(artistUserBindDto.getArtistId()) + .userId(artistUser.getUserId()) + .build(); + + artistUserDao.save(build); + } else { + throw new RuntimeException("请勿重复绑定!"); + } + } + + /** + * 音乐人-成员解绑 + * @param artistUserBindDto + */ + public void unBindArtistAndMember(ArtistUserBindDto artistUserBindDto) { + ArtistUser artistUser = artistUserDao.findArtistUserByArtistIdAndUserId(artistUserBindDto.getArtistId(), artistUserBindDto.getUserId()); + if(artistUser != null) { + artistUserDao.delete(artistUser); + } else { + throw new RuntimeException("没有绑定关系!"); + } + } + + }