|
@@ -1,26 +1,29 @@
|
|
|
package cn.com.taiji.duty.task;
|
|
|
|
|
|
|
|
|
-import cn.com.taiji.duty.model.DutyLoginLog;
|
|
|
-import cn.com.taiji.duty.model.DutySeatDutyUnit;
|
|
|
-import cn.com.taiji.duty.model.DutySignInRecord;
|
|
|
-import cn.com.taiji.duty.model.DutyStatistics;
|
|
|
+import cn.com.taiji.duty.model.*;
|
|
|
import cn.com.taiji.duty.service.*;
|
|
|
import cn.com.taiji.duty.utils.StringUtils;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.WeekFields;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description
|
|
@@ -32,6 +35,42 @@ import java.util.List;
|
|
|
@Slf4j
|
|
|
public class TimeTask {
|
|
|
|
|
|
+ @Value("${idaas-info.url-prefix}")
|
|
|
+ private String idaasUrlPrefix;
|
|
|
+
|
|
|
+ @Value("${idaas-info.api-url.login}")
|
|
|
+ private String loginApi;
|
|
|
+
|
|
|
+ @Value("${idaas-info.api-url.role-accounts}")
|
|
|
+ private String roleAccountsApi;
|
|
|
+
|
|
|
+ @Value("${idaas-info.api-url.userInfo}")
|
|
|
+ private String userInfoApi;
|
|
|
+
|
|
|
+ @Value("${idaas-info.api-url.org}")
|
|
|
+ private String orgApi;
|
|
|
+
|
|
|
+ @Value("${idaas-info.param.clientId}")
|
|
|
+ private String clientId;
|
|
|
+
|
|
|
+ @Value("${idaas-info.param.clientSecret}")
|
|
|
+ private String clientSecret;
|
|
|
+
|
|
|
+ @Value("${idaas-info.param.username}")
|
|
|
+ private String username;
|
|
|
+
|
|
|
+ @Value("${idaas-info.param.password}")
|
|
|
+ private String password;
|
|
|
+
|
|
|
+ @Value("${idaas-info.param.role-zby}")
|
|
|
+ private String roleZby;
|
|
|
+
|
|
|
+ @Value("${idaas-info.param.role-zbgl}")
|
|
|
+ private String roleZbgl;
|
|
|
+
|
|
|
+ @Value("${idaas-info.param.psId}")
|
|
|
+ private String psId;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IDutyStatisticsService statisticsService;
|
|
|
|
|
@@ -50,6 +89,15 @@ public class TimeTask {
|
|
|
@Autowired
|
|
|
private IDutyConfigService configService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IDutyRoleAccountService roleAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDutyAccountService accountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDutyDepartmentService departmentService;
|
|
|
+
|
|
|
@Scheduled(cron = "0 0 0 * * ?")
|
|
|
public void signScheduleOne() {
|
|
|
log.info("===========签卡处理定时开始===========");
|
|
@@ -231,4 +279,123 @@ public class TimeTask {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ?")
|
|
|
+ public void dataSchedule() {
|
|
|
+ log.info("===========数据同步定时开始===========");
|
|
|
+ // 记录请求开始时间
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ this.data();
|
|
|
+ // 记录请求结束时间
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ // 计算本次请求耗时
|
|
|
+ long takeTime = endTime - startTime;
|
|
|
+ log.info("任务耗时:{}",takeTime);
|
|
|
+ log.info("===========数据同步定时结束===========");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void data() {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ String token = redisTemplate.opsForValue().get("dataToken-" + username);
|
|
|
+ if (StringUtils.isEmpty(token)) {
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ jsonObj.put("clientId", clientId);
|
|
|
+ jsonObj.put("clientSecret", clientSecret);
|
|
|
+ jsonObj.put("username", username);
|
|
|
+ jsonObj.put("password", password);
|
|
|
+ HttpEntity<String> entity = new HttpEntity<String>(jsonObj.toJSONString(), headers);
|
|
|
+ //post发送请求
|
|
|
+ ResponseEntity<JSONObject> exchange = restTemplate.exchange(idaasUrlPrefix + loginApi, HttpMethod.POST, entity, JSONObject.class);
|
|
|
+ //获取idaas返回的json
|
|
|
+ JSONObject resData = exchange.getBody();
|
|
|
+ JSONObject data = resData.getJSONObject("data");
|
|
|
+ // 获取SSOToken时效
|
|
|
+ long expires = data.getLong("expiresIn");
|
|
|
+ // 获取SSOToken
|
|
|
+ String dataToken = data.getString("accessToken");
|
|
|
+ redisTemplate.opsForValue().set("dataToken-" + username, dataToken, expires, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ headers.set("Authorization","Bearer " + token);
|
|
|
+ int pageSize = 100;
|
|
|
+ int currentPage = 1;
|
|
|
+ // 值班员请求
|
|
|
+ String url = idaasUrlPrefix + roleAccountsApi + "?privilegeUuid=" + roleZby + "&psSystemUuid="
|
|
|
+ + psId + "&pageSize=" + pageSize + "¤tPage=" + currentPage;
|
|
|
+ new JSONObject();
|
|
|
+ HttpEntity entity = new HttpEntity<>(headers);
|
|
|
+ //get发送请求
|
|
|
+ ResponseEntity<JSONObject> exchange = restTemplate.exchange(url, HttpMethod.GET, entity, JSONObject.class);
|
|
|
+ JSONObject resData = exchange.getBody();
|
|
|
+ JSONObject data = resData.getJSONObject("data");
|
|
|
+ JSONArray jsonArray = data.getJSONArray("list");
|
|
|
+ List<DutyRoleAccount> roleAccounts = JSONArray.parseArray(jsonArray.toJSONString(), DutyRoleAccount.class);
|
|
|
+ roleAccounts.forEach(dutyRoleAccount -> dutyRoleAccount.setRoleUuid(roleZby));
|
|
|
+
|
|
|
+
|
|
|
+ // 值班管理员请求
|
|
|
+ String urlZbgl = idaasUrlPrefix + roleAccountsApi + "?privilegeUuid=" + roleZbgl + "&psSystemUuid="
|
|
|
+ + psId + "&pageSize=" + pageSize + "¤tPage=" + currentPage;
|
|
|
+ //get发送请求
|
|
|
+ ResponseEntity<JSONObject> exchangeZbgl = restTemplate.exchange(urlZbgl, HttpMethod.GET, entity, JSONObject.class);
|
|
|
+ JSONObject resDataZbgl = exchangeZbgl.getBody();
|
|
|
+ JSONObject dataZbgl = resDataZbgl.getJSONObject("data");
|
|
|
+ JSONArray jsonArrayZbgl = dataZbgl.getJSONArray("list");
|
|
|
+ List<DutyRoleAccount> roleAccountsZbgl = JSONArray.parseArray(jsonArrayZbgl.toJSONString(), DutyRoleAccount.class);
|
|
|
+ roleAccountsZbgl.forEach(dutyRoleAccount -> dutyRoleAccount.setRoleUuid(roleZbgl));
|
|
|
+
|
|
|
+ List<DutyRoleAccount> dutyRoleAccounts = new ArrayList<>();
|
|
|
+ dutyRoleAccounts.addAll(roleAccounts);
|
|
|
+ dutyRoleAccounts.addAll(roleAccountsZbgl);
|
|
|
+ dutyRoleAccounts.forEach(dutyRoleAccount -> {
|
|
|
+ roleAccountService.saveOrUpdate(dutyRoleAccount,new LambdaQueryWrapper<DutyRoleAccount>()
|
|
|
+ .eq(DutyRoleAccount::getUdAccountUuid,dutyRoleAccount.getUdAccountUuid())
|
|
|
+ .eq(DutyRoleAccount::getRoleUuid,dutyRoleAccount.getRoleUuid()));
|
|
|
+ });
|
|
|
+ // roleAccountService.saveBatch(dutyRoleAccounts);
|
|
|
+
|
|
|
+ List<String> stringList = dutyRoleAccounts.parallelStream().map(DutyRoleAccount::getUdAccountUuid).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ List<DutyAccount> accounts = new ArrayList<>();
|
|
|
+ // 用户信息请求
|
|
|
+ stringList.forEach(t -> {
|
|
|
+ ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(idaasUrlPrefix + userInfoApi + "?userUuid=" + t, HttpMethod.GET, entity, JSONObject.class);
|
|
|
+ JSONObject jsonObject = responseEntity.getBody().getJSONObject("data").getJSONObject("userInformation");
|
|
|
+ DutyAccount account = JSONObject.parseObject(jsonObject.toJSONString(), DutyAccount.class);
|
|
|
+ account.setUuid(t);
|
|
|
+ DutyAccount one = accountService.getOne(new LambdaQueryWrapper<DutyAccount>().eq(DutyAccount::getUuid, t));
|
|
|
+ if (one != null) {
|
|
|
+ account.setId(one.getId());
|
|
|
+ accountService.updateById(account);
|
|
|
+ } else {
|
|
|
+ accounts.add(account);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (accounts.size() > 0) {
|
|
|
+ accountService.saveBatch(accounts);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> collect = accounts.parallelStream().map(DutyAccount::getOuUuid).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ List<DutyDepartment> departments = new ArrayList<>();
|
|
|
+ // 用户信息请求
|
|
|
+ collect.forEach(f -> {
|
|
|
+ ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(idaasUrlPrefix + orgApi + f + "?uuid=" + f, HttpMethod.GET, entity, JSONObject.class);
|
|
|
+ JSONObject jsonObject = responseEntity.getBody().getJSONObject("data").getJSONObject("formDto");
|
|
|
+ DutyDepartment department = JSONObject.parseObject(jsonObject.toJSONString(), DutyDepartment.class);
|
|
|
+ department.setOrganizationName(jsonObject.get("name").toString());
|
|
|
+ DutyDepartment one = departmentService.getOne(new LambdaQueryWrapper<DutyDepartment>().eq(DutyDepartment::getUuid, f));
|
|
|
+ if (one != null) {
|
|
|
+ department.setId(one.getId());
|
|
|
+ departmentService.updateById(department);
|
|
|
+ } else {
|
|
|
+ departments.add(department);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (departments.size() > 0) {
|
|
|
+ departmentService.saveBatch(departments);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|