|
@@ -3,9 +3,11 @@ package com.sky.ioc.service.system.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.sky.ioc.constant.Constant;
|
|
|
+import com.sky.ioc.entity.domain.carbon.CarbonNotice;
|
|
|
import com.sky.ioc.entity.domain.system.Menus;
|
|
|
import com.sky.ioc.entity.domain.system.Users;
|
|
|
import com.sky.ioc.entity.result.system.LoginUserVo;
|
|
|
+import com.sky.ioc.mapper.job.TokenMapper;
|
|
|
import com.sky.ioc.mapper.system.MenuMapper;
|
|
|
import com.sky.ioc.mapper.system.UserMapper;
|
|
|
import com.sky.ioc.service.system.UserService;
|
|
@@ -13,17 +15,25 @@ import com.sky.ioc.tool.JwtUtil;
|
|
|
import com.sky.ioc.tool.Pbkdf2Sha256Digest;
|
|
|
import com.sky.ioc.tool.RedisUtil;
|
|
|
import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class UserServiceImpl implements UserService {
|
|
|
|
|
|
@Autowired
|
|
@@ -35,6 +45,14 @@ public class UserServiceImpl implements UserService {
|
|
|
@Autowired
|
|
|
MenuMapper menuMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ TokenMapper tokenMapper;
|
|
|
+
|
|
|
+ @Value("${sky.dataIp}")
|
|
|
+ private String dataIp;
|
|
|
+
|
|
|
+ final static String USER_URL="%s/api/hr/HR/staff/list";
|
|
|
+
|
|
|
@Override
|
|
|
public ReturnMsg updateCommonMenusByUserIdAndMenuId(long userId, String menuIDs) {
|
|
|
userMapper.updateCommonMenusByUserIdAndMenuId(userId,menuIDs);
|
|
@@ -138,4 +156,53 @@ public class UserServiceImpl implements UserService {
|
|
|
}
|
|
|
return ReturnMsg.ok(users);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg getUserData() {
|
|
|
+ String url = String.format(USER_URL,"http://"+dataIp)+"??pageNum=1&pageSize=1000";
|
|
|
+ Map<String,String> tokenMap = tokenMapper.getNewToken();
|
|
|
+ String token ="Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6IjUwZTU1NTRkLWJjYzYtNGRhMS1iZDUxLWFhNTc3YzU4YTFiNCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.X10VPYJfeeRTka7OtqNPOGMpL4QkW3fR_TfCKXCmO-yXbIIrr_40fcwiVnpXfYVENo_BvXWEACRd-Y6nXsbkog";
|
|
|
+ if(tokenMap!=null){
|
|
|
+ token = "Bearer "+tokenMap.get("token");
|
|
|
+ }
|
|
|
+ // 创建一个请求头对象
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ // 设置参数
|
|
|
+ httpHeaders.set("authorization", token);
|
|
|
+ // 创建一个响应体对象
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity(httpHeaders);
|
|
|
+ // 3.创建RestTemplate
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ // 发送GET请求
|
|
|
+ ResponseEntity<Map> responseEntity = restTemplate.exchange(url, HttpMethod.GET, httpEntity, Map.class);
|
|
|
+ // 获取响应对象里的 body 对象
|
|
|
+ Map<String, Object> body = responseEntity.getBody();
|
|
|
+ // 获取状态码
|
|
|
+ Integer code = (Integer)body.get("code");
|
|
|
+ // 获取响应信息
|
|
|
+ String message = (String)body.get("msg");
|
|
|
+ if(code==200){
|
|
|
+ ArrayList list = (ArrayList) body.get("rows");
|
|
|
+ if(list!=null&&list.size()>0){
|
|
|
+ userMapper.delete(new LambdaQueryWrapper<Users>().gt(Users::getId,2));
|
|
|
+ for (int i=0;i<list.size();i++){
|
|
|
+ LinkedHashMap json = (LinkedHashMap) list.get(i);
|
|
|
+ Users users = new Users();
|
|
|
+ users.setId((Integer) json.get("id"));
|
|
|
+ users.setUserName(String.valueOf(json.get("staffNo")));
|
|
|
+ users.setName(String.valueOf(json.get("staffName")));
|
|
|
+ users.setPhone(String.valueOf(json.get("phone")));
|
|
|
+ users.setPassword(Pbkdf2Sha256Digest.encode("123456"));
|
|
|
+ userMapper.insert(users);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ReturnMsg.ok();
|
|
|
+
|
|
|
+ }else{
|
|
|
+ log.info("获取双碳通知数据:"+message);
|
|
|
+ return ReturnMsg.fail(message);
|
|
|
+ }
|
|
|
+ // return null;
|
|
|
+ }
|
|
|
}
|