DataInterfaceUserServiceImpl.java 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package jnpf.base.service.impl;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import jnpf.base.entity.DataInterfaceUserEntity;
  5. import jnpf.base.mapper.DataInterfaceUserMapper;
  6. import jnpf.base.model.InterfaceOauth.InterfaceUserForm;
  7. import jnpf.base.service.DataInterfaceUserService;
  8. import jnpf.base.service.SuperServiceImpl;
  9. import jnpf.permission.service.UserService;
  10. import jnpf.util.*;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import java.util.List;
  15. import java.util.stream.Collectors;
  16. /**
  17. * @author JNPF开发平台组
  18. * @version V3.4.7
  19. * @copyright 引迈信息技术有限公司
  20. * @date 2021/9/20 9:22
  21. */
  22. @Service
  23. @Slf4j
  24. public class DataInterfaceUserServiceImpl extends SuperServiceImpl<DataInterfaceUserMapper, DataInterfaceUserEntity> implements DataInterfaceUserService {
  25. @Autowired
  26. protected AuthUtil authUtil;
  27. @Override
  28. public void saveUserList(InterfaceUserForm interfaceUserForm) {
  29. if (interfaceUserForm.getUserIds() != null) {
  30. List<String> userList = interfaceUserForm.getUserIds();
  31. List<DataInterfaceUserEntity> select = this.select(interfaceUserForm.getInterfaceIdentId());
  32. List<String> dbList = select.stream().map(DataInterfaceUserEntity::getUserId).collect(Collectors.toList());
  33. List<String> saveList = userList.stream().filter(t -> !dbList.contains(t)).collect(Collectors.toList());
  34. List<DataInterfaceUserEntity> updateList = select.stream().filter(t -> userList.contains(t.getUserId())).collect(Collectors.toList());
  35. List<DataInterfaceUserEntity> deleteList = select.stream().filter(t -> !userList.contains(t.getUserId())).collect(Collectors.toList());
  36. for (String userId : saveList) {
  37. DataInterfaceUserEntity entity = new DataInterfaceUserEntity();
  38. entity.setId(RandomUtil.uuId());
  39. entity.setUserKey(RandomUtil.uuId().substring(2));
  40. entity.setOauthId(interfaceUserForm.getInterfaceIdentId());
  41. entity.setUserId(userId);
  42. entity.setCreatorUserId(UserProvider.getUser().getUserId());
  43. entity.setCreatorTime(DateUtil.getNowDate());
  44. this.save(entity);
  45. }
  46. for (DataInterfaceUserEntity updateE : updateList) {
  47. this.updateById(updateE);
  48. }
  49. for (DataInterfaceUserEntity deleteE : deleteList) {
  50. this.removeById(deleteE.getId());
  51. }
  52. }
  53. }
  54. @Override
  55. public List<DataInterfaceUserEntity> select(String oauthId) {
  56. QueryWrapper<DataInterfaceUserEntity> queryWrapper = new QueryWrapper<>();
  57. queryWrapper.lambda().eq(DataInterfaceUserEntity::getOauthId, oauthId);
  58. return this.list(queryWrapper);
  59. }
  60. @Override
  61. public String getInterfaceUserToken(String tenantId, String oauthId, String userKey) {
  62. List<DataInterfaceUserEntity> select = this.select(oauthId);
  63. if (CollectionUtil.isEmpty(select)) {
  64. return null;
  65. }
  66. if (StringUtil.isEmpty(userKey)) {
  67. throw new RuntimeException("未填写UserKey,请确认");
  68. }
  69. DataInterfaceUserEntity entity = select.stream().filter(item -> item.getUserKey().equals(userKey)).findFirst().orElse(null);
  70. if (entity == null) {
  71. throw new RuntimeException("UserKey不匹配,请填写正确的UserKey");
  72. }
  73. String token = authUtil.loginTempUser(entity.getUserId(), tenantId, true);
  74. return token;
  75. }
  76. }