|
@@ -1,6 +1,9 @@
|
|
package com.gis.admin.service.impl;
|
|
package com.gis.admin.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -13,6 +16,8 @@ import com.gis.common.base.exception.BaseRuntimeException;
|
|
//import com.gis.common.base.service.LogService;
|
|
//import com.gis.common.base.service.LogService;
|
|
//import com.gis.common.base.service.impl.MyBaseServiceImpl;
|
|
//import com.gis.common.base.service.impl.MyBaseServiceImpl;
|
|
import com.gis.common.base.service.IBaseService;
|
|
import com.gis.common.base.service.IBaseService;
|
|
|
|
+import com.gis.common.constant.ApiConstant;
|
|
|
|
+import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.util.*;
|
|
import com.gis.common.util.*;
|
|
import com.gis.admin.entity.dto.PasswordDto;
|
|
import com.gis.admin.entity.dto.PasswordDto;
|
|
import com.gis.admin.entity.dto.UserDto;
|
|
import com.gis.admin.entity.dto.UserDto;
|
|
@@ -30,6 +35,7 @@ import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -54,6 +60,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
@Autowired
|
|
@Autowired
|
|
IBaseService baseService;
|
|
IBaseService baseService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ ConfigConstant configConstant;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* redis 用户名
|
|
* redis 用户名
|
|
*/
|
|
*/
|
|
@@ -112,6 +121,67 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
return Result.success(entity);
|
|
return Result.success(entity);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * by owen 2022-06-21
|
|
|
|
+ * 同步用户到本地, 不保存密码
|
|
|
|
+ * @param entity
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void syncUserToLocal(SysUserEntity entity) {
|
|
|
|
+ SysUserEntity dbUser = this.findByUserName(entity.getUserName());
|
|
|
|
+ if (dbUser == null){
|
|
|
|
+ entity.setIsAdmin(0);
|
|
|
|
+ entity.setUserKey(EncryptUtils.getEncrypt(USER_KEY, entity.getUserName()));
|
|
|
|
+ this.save(entity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * by owen 2022-06-21
|
|
|
|
+ * 同步用户四维用户系统
|
|
|
|
+ */
|
|
|
|
+ private Result syncUserToAgeUser(UserDto param) {
|
|
|
|
+ String api = configConstant.ageUserHost + ApiConstant.AGE_USER_Add;
|
|
|
|
+
|
|
|
|
+ param.setId(null);
|
|
|
|
+ String token = baseService.getToken();
|
|
|
|
+ log.info("token: {}", token);
|
|
|
|
+ log.info("请求地址: {}", api);
|
|
|
|
+ String s = HttpUtil.createPost(api)
|
|
|
|
+ .header("token", token)
|
|
|
|
+ .body(JSON.toJSONString(param), "application/json;charset=UTF-8")
|
|
|
|
+ .execute().body();
|
|
|
|
+ log.info("授权返回值: {}", s);
|
|
|
|
+
|
|
|
|
+ Result result = JSON.parseObject(s, Result.class);
|
|
|
|
+ // 2010 用户名重复, 不需要同步
|
|
|
|
+ if (result.getCode() != 0 || result.getCode() != 2010){
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ log.info("完成:同步用户到用户中心");
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result syncUpdatePwd(PasswordDto param) {
|
|
|
|
+ String api = configConstant.ageUserHost + ApiConstant.AGE_USER_UPDATE_PWD;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String s = HttpUtil.createPost(api)
|
|
|
|
+ .body(JSON.toJSONString(param), "application/json;charset=UTF-8")
|
|
|
|
+ .header("token", baseService.getToken())
|
|
|
|
+ .execute().body();
|
|
|
|
+ log.info("授权返回值: {}", s);
|
|
|
|
+
|
|
|
|
+ Result result = JSON.parseObject(s, Result.class);
|
|
|
|
+ // 2010 用户名重复, 不需要同步
|
|
|
|
+ if (result.getCode() != 0 ){
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ log.info("完成:密码更新到用户中心");
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -123,6 +193,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 新增会同步用户到用户中心
|
|
|
|
+ * @param param
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@Override
|
|
@Override
|
|
public Result saveEntity(UserDto param) {
|
|
public Result saveEntity(UserDto param) {
|
|
SysUserEntity entity;
|
|
SysUserEntity entity;
|
|
@@ -130,12 +205,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
if (id == null) {
|
|
if (id == null) {
|
|
entity = this.findByUserName(param.getUserName());
|
|
entity = this.findByUserName(param.getUserName());
|
|
if (entity != null) {
|
|
if (entity != null) {
|
|
- return Result.failure("用户名已存在");
|
|
|
|
|
|
+ return Result.failure("用户名已存在, 请直接登录");
|
|
}
|
|
}
|
|
entity = new SysUserEntity();
|
|
entity = new SysUserEntity();
|
|
BeanUtils.copyProperties(param, entity);
|
|
BeanUtils.copyProperties(param, entity);
|
|
|
|
+
|
|
entity.setIsAdmin(0);
|
|
entity.setIsAdmin(0);
|
|
- entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
|
|
|
+ entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
entity.setCreatorId(baseService.getUserId());
|
|
entity.setCreatorId(baseService.getUserId());
|
|
entity.setUserKey(EncryptUtils.getEncrypt(USER_KEY, entity.getUserName()));
|
|
entity.setUserKey(EncryptUtils.getEncrypt(USER_KEY, entity.getUserName()));
|
|
this.save(entity);
|
|
this.save(entity);
|
|
@@ -155,6 +231,47 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserEntity
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Result syncSaveEntity(UserDto param) {
|
|
|
|
+ SysUserEntity entity;
|
|
|
|
+ Long id = param.getId();
|
|
|
|
+ if (id == null) {
|
|
|
|
+ entity = this.findByUserName(param.getUserName());
|
|
|
|
+ if (entity != null) {
|
|
|
|
+ return Result.failure("用户名已存在, 请直接登录");
|
|
|
|
+ }
|
|
|
|
+ entity = new SysUserEntity();
|
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
|
+
|
|
|
|
+ // 同步用户到用户中心
|
|
|
|
+ Result result = syncUserToAgeUser(param);
|
|
|
|
+ if (result != null){
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// entity.setIsAdmin(0);
|
|
|
|
+// entity.setCreatorId(baseService.getUserId());
|
|
|
|
+// entity.setUserKey(EncryptUtils.getEncrypt(USER_KEY, entity.getUserName()));
|
|
|
|
+// this.save(entity);
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ entity = this.getById(id);
|
|
|
|
+ if (entity == null) {
|
|
|
|
+ log.error("用户不存在: {}", id);
|
|
|
|
+ return Result.failure("用户不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
|
+ this.updateById(entity);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|