|
@@ -0,0 +1,75 @@
|
|
|
+package com.fdkankan.manage_jp.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.manage_jp.common.ResultCode;
|
|
|
+import com.fdkankan.manage_jp.entity.Platform;
|
|
|
+import com.fdkankan.manage_jp.entity.UserPlatform;
|
|
|
+import com.fdkankan.manage_jp.exception.BusinessException;
|
|
|
+import com.fdkankan.manage_jp.mapper.IUserPlatformMapper;
|
|
|
+import com.fdkankan.manage_jp.service.IPlatformService;
|
|
|
+import com.fdkankan.manage_jp.service.IUserPlatformService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.manage_jp.vo.request.GivePlatformAuthParam;
|
|
|
+import com.fdkankan.manage_jp.vo.request.UserParam;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2024-11-19
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class UserPlatformServiceImpl extends ServiceImpl<IUserPlatformMapper, UserPlatform> implements IUserPlatformService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IPlatformService platformService;
|
|
|
+ @Override
|
|
|
+ public void givePlatformAuth(GivePlatformAuthParam param) {
|
|
|
+ if(param.getUserId() == null ){
|
|
|
+ throw new BusinessException(ResultCode.PARAM_ERROR);
|
|
|
+ }
|
|
|
+ List<UserPlatform> userPlatforms = this.getByUserId(param.getUserId());
|
|
|
+ List<Integer> dbIds = userPlatforms.stream().map(UserPlatform::getPlatformId).collect(Collectors.toList());
|
|
|
+ List<Integer> addIds = param.getPlatformIds().stream().filter(e -> !dbIds.contains(e)).collect(Collectors.toList());
|
|
|
+ List<Integer> delIds = dbIds.stream().filter(e -> !param.getPlatformIds().contains(e)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ this.saveByPlatformIds(param.getUserId(),addIds);
|
|
|
+ this.delByPlatformIds(param.getUserId(),delIds);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void delByPlatformIds(Integer userId,List<Integer> delIds) {
|
|
|
+ LambdaQueryWrapper<UserPlatform> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(UserPlatform::getUserId,userId);
|
|
|
+ wrapper.in(UserPlatform::getPlatformId,delIds);
|
|
|
+ this.remove(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveByPlatformIds(Integer userId,List<Integer> addIds) {
|
|
|
+ for (Integer addId : addIds) {
|
|
|
+ Platform platform = platformService.getById(addId);
|
|
|
+ if(platform != null){
|
|
|
+ UserPlatform userPlatform = new UserPlatform();
|
|
|
+ userPlatform.setUserId(userId);
|
|
|
+ userPlatform.setPlatformKey(platform.getKey());
|
|
|
+ userPlatform.setPlatformId(platform.getId());
|
|
|
+ this.save(userPlatform);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<UserPlatform> getByUserId(Integer userId) {
|
|
|
+ LambdaQueryWrapper<UserPlatform> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(UserPlatform::getUserId,userId);
|
|
|
+ return this.list(wrapper);
|
|
|
+ }
|
|
|
+}
|