Commit 819a2bea by HlQ

[add] 使用 Redisson 替换 SpringBoot 自带的 Redis 客户端

[chg] 修改整个项目的文件换行符
1 parent 828b8914
......@@ -18,6 +18,7 @@
<sqlserver.version>12.2.0.jre8</sqlserver.version>
<lombok.version>1.18.30</lombok.version>
<hutool.version>6.0.0-M11</hutool.version>
<redisson.verion>3.27.1</redisson.verion>
<mapstruct-plus.version>1.3.5</mapstruct-plus.version>
<mp.version>3.5.5</mp.version>
<mp-join.version>1.4.7.2</mp-join.version>
......@@ -82,8 +83,9 @@
<version>${wx-mp.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>${redisson.verion}</version>
</dependency>
<dependency>
<groupId>cn.dev33</groupId>
......
......@@ -3,12 +3,11 @@ package vion.config;
import com.github.liaochong.myexcel.core.converter.CustomWriteContext;
import com.github.liaochong.myexcel.core.converter.CustomWriteConverter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;
import vion.constant.RedisKeyEnum;
import java.util.Map;
/**
* @author HlQ
* @date 2024/2/2
......@@ -17,11 +16,11 @@ import java.util.Map;
@RequiredArgsConstructor
public class FaultTypeConverter implements CustomWriteConverter<Integer, Object> {
private final RedisTemplate redisTemplate;
private final RedissonClient redissonClient;
@Override
public Object convert(Integer originalData, CustomWriteContext customWriteContext) {
Map<String, String> faultTypeMap = redisTemplate.opsForHash().entries(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.FAULT_TYPE.getVal());
RMap<String, String> faultTypeMap = redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.FAULT_TYPE.getVal());
return faultTypeMap.getOrDefault(originalData.toString(), "故障类型不存在");
}
}
package vion.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.text.SimpleDateFormat;
/**
* @author HlQ
......@@ -20,32 +16,23 @@ import java.text.SimpleDateFormat;
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
//我们为了自己开发方便,一般使用String , Object
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
//序列化配置
//jackson的序列化
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.activateDefaultTyping(om.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL);
// Date序列化 yyyy-MM-dd HH:mm:ss/yyyy-MM-dd hh:mm:ss:SSS
om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS"));
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
@Value("${spring.data.redis.host}")
private String host;
@Value("${spring.data.redis.port}")
private Integer port;
@Value("${spring.data.redis.password}")
private String password;
@Value("${spring.data.redis.database}")
private Integer database;
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(om, Object.class);
//String 的序列化
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
//key采用String的序列化方式
template.setKeySerializer(stringRedisSerializer);
//hash的key也采用String的序列化方式
template.setHashKeySerializer(stringRedisSerializer);
//value的序列化方式采用jackson
template.setValueSerializer(jackson2JsonRedisSerializer);
//hash的value也采用jackson的序列化方式
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
@Bean(destroyMethod = "shutdown")
public RedissonClient redissonClient() {
Config config = new Config();
config.setCodec(JsonJacksonCodec.INSTANCE);
SingleServerConfig singleServerConfig = config.useSingleServer();
singleServerConfig.setAddress("redis://" + host + ":" + port)
.setPassword(password)
.setDatabase(database);
return Redisson.create(config);
}
}
package vion.config;
import org.dromara.hutool.core.lang.Opt;
import com.github.liaochong.myexcel.core.converter.CustomWriteContext;
import com.github.liaochong.myexcel.core.converter.CustomWriteConverter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.dromara.hutool.core.lang.Opt;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;
import vion.constant.RedisKeyEnum;
import vion.model.User;
......@@ -17,13 +17,14 @@ import vion.model.User;
@RequiredArgsConstructor
public class UserNameConverter implements CustomWriteConverter<Long, String> {
private final RedisTemplate redisTemplate;
private final RedissonClient redissonClient;
@Override
public String convert(Long originalData, CustomWriteContext customWriteContext) {
return Opt.ofNullable(((User) redisTemplate.opsForValue().get(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + originalData)))
return Opt.ofNullable(redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + originalData).get())
.map(u -> (User) u)
.map(User::getUsername)
.orElse("未知");
}
}
\ No newline at end of file
package vion.cron;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.core.text.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.dromara.hutool.core.util.ObjUtil;
import org.redisson.api.RedissonClient;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vion.constant.RedisKeyEnum;
import vion.model.*;
import vion.model.Dictionary;
import vion.model.*;
import vion.service.*;
import java.math.BigDecimal;
......@@ -37,7 +37,7 @@ public class ContractRunner {
private final IRContractStoreService contractStoreService;
private final IStoreService storeService;
private final IPaymentService paymentService;
private final RedisTemplate redisTemplate;
private final RedissonClient redissonClient;
@Scheduled(cron = "0 0 * * * *")
public void contractSync() {
......@@ -47,7 +47,7 @@ public class ContractRunner {
.stream().collect(Collectors.toMap(Dictionary::getValue, Dictionary::getKey));
List<Contract> insOrUpdContractList = new ArrayList<>();
String modifyTime = Opt.ofNullable((String) redisTemplate.opsForValue().get(RedisKeyEnum.CONTRACT_SYNC_TIME.getVal()))
String modifyTime = Opt.ofNullable((String) redissonClient.getBucket(RedisKeyEnum.CONTRACT_SYNC_TIME.getVal()).get())
.orElse("1970-01-01 00:00:00");
String url = "jdbc:sqlserver://47.92.144.255:1433;databaseName=UFDATA_001_2020;encrypt=false";
String username = "vion-reader";
......@@ -138,7 +138,7 @@ public class ContractRunner {
// 合同状态不为空,代表此条记录为新增,需要同步销售人信息到 r_contract_user 表中
if (ObjUtil.isNotNull(v.getStatus())) {
RContractUser contractUser = new RContractUser();
String userId = Opt.ofNullable(redisTemplate.opsForValue().get(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_NAME.getVal() + v.getSaleName()))
String userId = Opt.ofNullable(redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_NAME.getVal() + v.getSaleName()).get())
.map(u -> (User) u)
.map(User::getUserid)
.orElse(null);
......@@ -246,7 +246,7 @@ public class ContractRunner {
});
log.info("【结束】从crm系统同步合同信息");
redisTemplate.opsForValue().set(RedisKeyEnum.CONTRACT_SYNC_TIME.getVal(), DateUtil.formatDateTime(insOrUpdContractList.get(0).getOriginalModTime()));
redissonClient.getBucket(RedisKeyEnum.CONTRACT_SYNC_TIME.getVal()).set(DateUtil.formatDateTime(insOrUpdContractList.get(0).getOriginalModTime()));
}
@Scheduled(cron = "0 0 1 * * ?")
......
package vion.service.impl;
import org.dromara.hutool.core.lang.Opt;
import com.github.yulichang.base.MPJBaseServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.dromara.hutool.core.lang.Opt;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import vion.constant.RedisKeyEnum;
import vion.mapper.DictionaryMapper;
......@@ -16,12 +16,12 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class DictionaryServiceImpl extends MPJBaseServiceImpl<DictionaryMapper, Dictionary> implements IDictionaryService {
private final RedisTemplate redisTemplate;
private final RedissonClient redissonClient;
@Override
public void syncDict() {
Opt.ofEmptyAble(this.list())
.map(l -> l.stream().collect(Collectors.groupingBy(Dictionary::getType, Collectors.toMap(d -> d.getKey().toString(), Dictionary::getValue))))
.ifPresent(m -> m.forEach((type, map) -> redisTemplate.opsForHash().putAll(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.getValByKey(type), map)));
.ifPresent(m -> m.forEach((type, map) -> redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.getValByKey(type)).putAll(map)));
}
}
......@@ -24,8 +24,9 @@ import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.json.JSONArray;
import org.dromara.hutool.json.JSONObject;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vion.constant.RedisKeyEnum;
......@@ -57,7 +58,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
private final DingMod dingMod;
private final WechatMod wechatMod;
private final Converter converter;
private final RedisTemplate redisTemplate;
private final RedissonClient redissonClient;
@Value("${fileUrl:}")
private String fileUrl;
......@@ -133,6 +134,8 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
var wrapper = new MPJLambdaWrapper<Task>()
.selectAll(Task.class)
.selectAs(Store::getName, TaskVO::getStoreName)
.selectAs(Store::getSalesperson, TaskVO::getSalesperson)
.selectAs(Store::getMaintainStatus, TaskVO::getMaintainStatus)
.selectCollection(FileInfo.class, TaskTempVO::getFileList)
.leftJoin(Store.class, Store::getId, Task::getStoreId)
.leftJoin(FileInfo.class, on -> on
......@@ -194,7 +197,8 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
task.setUuid(IdUtil.nanoId());
this.save(task);
Opt.ofNullable((User) redisTemplate.opsForValue().get(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + store.getSalesperson()))
Opt.ofNullable(redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + store.getSalesperson()).get())
.map(u -> (User) u)
.map(User::getUserid)
.ifPresent(userid -> dingMod.workMsg(buildMsg2(userid, store.getName(), task)));
......@@ -209,7 +213,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
.filter(CollUtil::isNotEmpty)
.ifPresent(fileInfoList -> fileInfoList.forEach(fileInfo -> {
String path = fileUrl + FileUtil.FILE_SEPARATOR + task.getStoreId() + FileUtil.FILE_SEPARATOR + task.getId() + FileUtil.FILE_SEPARATOR + fileInfo.getName();
File tarFile = FileUtil.copy(fileInfo.getUrl(), path, true);
FileUtil.copy(fileInfo.getUrl(), path, true);
FileInfo newFileInfo = new FileInfo();
newFileInfo.setStoreId(task.getStoreId());
......@@ -288,9 +292,11 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
private void sendNotifications(Task task, UserVO user, Store store) {
Task existTask = this.getById(task.getId());
Long activeUserId = task.getActiveUser();
User activeUser = (User) redisTemplate.opsForValue().get(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + activeUserId);
Set<String> useridList = new HashSet<>();
useridList.add(activeUser.getUserid());
Opt.ofNullable(redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + activeUserId).get())
.map(u -> (User) u)
.map(User::getUserid)
.ifPresent(useridList::add);
if (task.getStatus() == 3) {
// 工单完成时,推送钉钉消息到预工单的确认人
Opt.ofNullable(existTask.getTaskTempId())
......@@ -370,6 +376,8 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
MPJLambdaWrapper<Task> wrapper = new MPJLambdaWrapper<Task>()
.selectAll(Task.class)
.selectAs(Store::getName, TaskVO::getStoreName)
.selectAs(Store::getSalesperson, TaskVO::getSalesperson)
.selectAs(Store::getMaintainStatus, TaskVO::getMaintainStatus)
.selectCollection(FaultLog.class, TaskVO::getFaultLogList)
.leftJoin(Store.class, Store::getId, Task::getStoreId)
.leftJoin(FaultLog.class, FaultLog::getTaskId, Task::getId)
......@@ -404,10 +412,13 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
public String urgeTask(Long taskId, String remark) {
Task task = this.getById(taskId);
Long activeUserId = task.getActiveUser();
User activeUser = (User) redisTemplate.opsForValue().get(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + activeUserId);
String userid = Opt.ofNullable(redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + activeUserId).get())
.map(u -> (User) u)
.map(User::getUserid)
.orElse(null);
Store store = storeService.getById(task.getStoreId());
JSONObject msg = buildMsg4(activeUser.getUserid(), store.getName(), task, remark);
JSONObject msg = buildMsg4(userid, store.getName(), task, remark);
String pushRes = dingMod.workMsg(msg);
if (StrUtil.contains(pushRes, "ok")) {
return "成功";
......@@ -511,7 +522,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
}
JSONObject buildMsg(String userid, String storeName, Task task) {
Map<String, String> orderStatusMap = redisTemplate.opsForHash().entries(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
RMap<Integer, String> orderStatusMap = redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
......@@ -530,7 +541,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
#### 发送时间:{}
""";
String markdown = StrUtil.format(template,
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus().toString()), task.getFaultDescription(), DateUtil.now());
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus()), task.getFaultDescription(), DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
......@@ -575,7 +586,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
}
JSONObject buildMsg3(String userid, String storeName, Task task) {
Map<String, String> orderStatusMap = redisTemplate.opsForHash().entries(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
RMap<Integer, String> orderStatusMap = redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
......@@ -594,7 +605,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
#### 发送时间:{}
""";
String markdown = StrUtil.format(template,
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus().toString()), task.getFaultDescription(), DateUtil.now());
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus()), task.getFaultDescription(), DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
......@@ -609,7 +620,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
}
JSONObject buildMsg4(String userid, String storeName, Task task, String remark) {
Map<String, String> orderStatusMap = redisTemplate.opsForHash().entries(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
RMap<Integer, String> orderStatusMap = redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.ORDER_STATUS.getVal());
JSONObject jsonObj = new JSONObject();
jsonObj.set("agent_id", 2358374016L);
......@@ -628,7 +639,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
#### 发送时间:{}
""";
String markdown = StrUtil.format(template,
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus().toString()), remark, DateUtil.now());
storeName, task.getUuid(), task.getRepairPeople(), task.getRepairPhone(), orderStatusMap.get(task.getStatus()), remark, DateUtil.now());
content.set("markdown", markdown);
content.set("btn_orientation", "1");
......
package vion.third;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.github.linpeilie.Converter;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.codec.binary.Base64;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.crypto.SecureUtil;
import org.dromara.hutool.crypto.digest.mac.HMac;
import org.dromara.hutool.http.HttpUtil;
......@@ -16,12 +21,8 @@ import org.dromara.hutool.http.client.Response;
import org.dromara.hutool.json.JSONArray;
import org.dromara.hutool.json.JSONObject;
import org.dromara.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import vion.constant.RedisKeyEnum;
import vion.dto.DingDTO;
......@@ -30,14 +31,12 @@ import vion.service.*;
import vion.vo.RoleVO;
import vion.vo.UserVO;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -61,7 +60,7 @@ public class DingMod {
private final IRRoleResourceService roleResourceService;
private final IDeptService deptService;
private final Converter converter;
private final RedisTemplate redisTemplate;
private final RedissonClient redissonClient;
/**
* 获取钉钉token
......@@ -69,13 +68,13 @@ public class DingMod {
* @return java.lang.String
*/
public String getToken() {
return (String) Opt.ofNullable(redisTemplate.opsForValue().get(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.ACCESS_TOKEN.getVal()))
return (String) Opt.ofNullable(redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.ACCESS_TOKEN.getVal()).get())
.orElseGet(() -> {
String res = HttpUtil.get("https://oapi.dingtalk.com/gettoken?appkey=" + appKey + "&appsecret=" + appSecret);
JSONObject jsonObj = JSONUtil.parseObj(res);
if (jsonObj.containsKey("access_token")) {
String accessToken = jsonObj.getStr("access_token");
redisTemplate.opsForValue().set(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.ACCESS_TOKEN.getVal(), accessToken, 7000, TimeUnit.SECONDS);
redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.ACCESS_TOKEN.getVal()).set(accessToken, Duration.ofSeconds(7000));
return accessToken;
}
return "";
......@@ -92,11 +91,11 @@ public class DingMod {
Long offset = 0L;
boolean flag = true;
while (flag) {
JSONObject paramJson = new JSONObject();
// 2:试用期 3:正式 5:待离职 -1:无状态
paramJson.set("status_list", "2,3,5,-1");
paramJson.set("size", 50);
paramJson.set("offset", offset);
JSONObject paramJson = JSONUtil.ofObj()
.set("status_list", "2,3,5,-1")
.set("size", 50)
.set("offset", offset);
String res = HttpUtil.post("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/queryonjob?access_token=" + accessToken, paramJson.toString());
JSONObject jsonObject = JSONUtil.parseObj(res);
if (jsonObject.getBool("success", false)) {
......@@ -120,10 +119,10 @@ public class DingMod {
List<List<String>> userIdListSplit = ListUtil.partition(userIdList, 90);
userIdListSplit.forEach(tmpList -> {
JSONObject paramJson = new JSONObject();
paramJson.set("agentid", 2358374016L);
paramJson.set("userid_list", String.join(",", tmpList));
paramJson.set("field_filter_list", "sys00-name,sys00-mobile,sys00-mainDeptId,sys00-mainDept,sys01-employeeStatus");
JSONObject paramJson = JSONUtil.ofObj()
.set("agentid", 2358374016L)
.set("userid_list", String.join(",", tmpList))
.set("field_filter_list", "sys00-name,sys00-mobile,sys00-mainDeptId,sys00-mainDept,sys01-employeeStatus");
String res = HttpUtil.post("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/list?access_token=" + accessToken, paramJson.toString());
JSONObject jsonObject = JSONUtil.parseObj(res);
......@@ -150,8 +149,8 @@ public class DingMod {
}
userService.saveOrUpdate(user, Wrappers.<User>lambdaUpdate().eq(User::getUserid, userid));
User one = userService.lambdaQuery().eq(User::getUserid, userid).one();
redisTemplate.opsForValue().set(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + one.getId(), user);
redisTemplate.opsForValue().set(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_NAME.getVal() + one.getUsername(), user);
redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + one.getId()).set(user);
redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_NAME.getVal() + one.getUsername()).set(user);
}
}
});
......@@ -208,11 +207,11 @@ public class DingMod {
*/
public Object dingCallback(String target, DingDTO dto, HttpServletResponse res) {
if (StrUtil.equals(target, "login")) {
JSONObject jsonObject = new JSONObject();
jsonObject.set("clientId", appKey);
jsonObject.set("clientSecret", appSecret);
jsonObject.set("code", dto.getAuthCode());
jsonObject.set("grantType", "authorization_code");
JSONObject jsonObject = JSONUtil.ofObj()
.set("clientId", appKey)
.set("clientSecret", appSecret)
.set("code", dto.getAuthCode())
.set("grantType", "authorization_code");
String tokenRes = HttpUtil.post("https://api.dingtalk.com/v1.0/oauth2/userAccessToken", jsonObject.toString());
JSONObject tokenObj = JSONUtil.parseObj(tokenRes);
if (!tokenObj.containsKey("accessToken")) {
......
......@@ -24,8 +24,12 @@ public class TaskVO {
/**
* 门店名称
*/
@ExcelColumn(order = 0, title = "项目名称")
@ExcelColumn(title = "项目名称")
private String storeName;
private Integer salesperson;
private String maintainStatus;
/**
* 预处理工单id
*/
......
......@@ -10,7 +10,7 @@ spring.data.redis.password=RtOTnx2V
spring.data.redis.port=6379
spring.data.redis.database=8
wx.mp.config-storage.type=RedisTemplate
wx.mp.config-storage.type=Redisson
wx.mp.config-storage.key-prefix=wa
wx.mp.config-storage.redis.host=r-2zejlb88mng3q50aw7pd.redis.rds.aliyuncs.com
wx.mp.config-storage.redis.password==RtOTnx2V
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!