Commit 814659b8 by HlQ

[add]

1.添加钉钉用户同步 Redis 接口
2.添加项目经理负责项目报表接口
1 parent 40ad5f18
...@@ -244,15 +244,23 @@ public class StoreController { ...@@ -244,15 +244,23 @@ public class StoreController {
@PostMapping("/store/file/table") @PostMapping("/store/file/table")
@SaCheckPermission(value = "store:file:table", orRole = "admin") @SaCheckPermission(value = "store:file:table", orRole = "admin")
public Map<String, Map<String, Map<String, Long>>> storeFileTable(StoreDTO data, public Map<String, Map<String, Map<String, Long>>> storeFileTable(StoreDTO data,
@RequestBody(required = false) List<OrderItem> orderItemList, @RequestBody(required = false) List<OrderItem> orderItemList,
HttpServletResponse response) { HttpServletResponse response) {
return storeService.storeFileTable(data, orderItemList, response); return storeService.storeFileTable(data, orderItemList, response);
} }
@PostMapping("/store/file/export") @PostMapping("/store/file/export")
@SaCheckPermission(value = "store:file:export", orRole = "admin") @SaCheckPermission(value = "store:file:export", orRole = "admin")
public void storeFileExport(StoreDTO data, @RequestBody(required = false) List<OrderItem> orderItemList, public void storeFileExport(StoreDTO data,
@RequestBody(required = false) List<OrderItem> orderItemList,
HttpServletResponse response) { HttpServletResponse response) {
storeService.storeFileExport(data, orderItemList, response); storeService.storeFileExport(data, orderItemList, response);
} }
@GetMapping("/store/mainUser/table")
@SaCheckPermission(value = "store:mainUser:table", orRole = "admin")
public Map<String, Map<String, Long>> storeTableByMainUser() {
return storeService.storeTableByMainUser();
}
} }
...@@ -152,4 +152,17 @@ public class UserController { ...@@ -152,4 +152,17 @@ public class UserController {
return wechatMod.getFollowingOpenid(id, flag, code); return wechatMod.getFollowingOpenid(id, flag, code);
} }
/**
* 同步用户到 Redis
*
* @return java.lang.String
*/
@GetMapping("/user/sync")
@SaCheckPermission(value = "user:sync", orRole = "admin")
// todo 未加权限
public String syncDict() {
userService.syncUser();
return "同步成功";
}
} }
...@@ -43,6 +43,5 @@ public interface IStoreService extends MPJBaseService<Store> { ...@@ -43,6 +43,5 @@ public interface IStoreService extends MPJBaseService<Store> {
void storeFileExport(StoreDTO data, List<OrderItem> orderItemList, HttpServletResponse response); void storeFileExport(StoreDTO data, List<OrderItem> orderItemList, HttpServletResponse response);
Map<String, Map<String, Long>> storeTableByMainUser();
} }
...@@ -15,4 +15,5 @@ public interface IUserService extends MPJBaseService<User> { ...@@ -15,4 +15,5 @@ public interface IUserService extends MPJBaseService<User> {
List<MapTree<String>> getOrgTree(String deptId); List<MapTree<String>> getOrgTree(String deptId);
void syncUser();
} }
...@@ -658,6 +658,31 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp ...@@ -658,6 +658,31 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
} }
} }
@Override
public Map<String, Map<String, Long>> storeTableByMainUser() {
var projectStateMap = redissonClient.<Integer, String>getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.PROJECT_STATE.getVal());
var wrapper = new MPJLambdaWrapper<Store>()
.select(Store::getId, Store::getName, Store::getProjectState)
.selectAs(RStoreUser::getUserId, StoreVO::getMainUser)
.leftJoin(RStoreUser.class,
on -> on.eq(RStoreUser::getStoreId, Store::getId).eq(RStoreUser::getIsMain, 1));
var storeVOList = this.selectJoinList(StoreVO.class, wrapper);
var useridArr = storeVOList.stream()
.map(StoreVO::getMainUser)
.map(mainUser -> RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + mainUser)
.toArray(String[]::new);
var id2UserMap = redissonClient.getBuckets().get(useridArr);
// 项目经理 -> (项目状态 -> 数量)
return storeVOList.stream()
.filter(val -> ObjUtil.isNotNull(val.getMainUser()))
.collect(Collectors.groupingBy(vo -> ((User) id2UserMap.get(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + vo.getMainUser())).getUsername(),
Collectors.groupingBy(vo -> projectStateMap.getOrDefault(vo.getProjectState(), "未知"),
Collectors.counting())));
}
JSONObject buildMsg(String storeName, String userid) { JSONObject buildMsg(String storeName, String userid) {
var jsonObj = JSONUtil.ofObj() var jsonObj = JSONUtil.ofObj()
.set("agent_id", 2358374016L) .set("agent_id", 2358374016L)
......
...@@ -12,7 +12,9 @@ import org.dromara.hutool.core.tree.MapTree; ...@@ -12,7 +12,9 @@ import org.dromara.hutool.core.tree.MapTree;
import org.dromara.hutool.core.tree.TreeNode; import org.dromara.hutool.core.tree.TreeNode;
import org.dromara.hutool.core.tree.TreeUtil; import org.dromara.hutool.core.tree.TreeUtil;
import org.dromara.hutool.core.util.ObjUtil; import org.dromara.hutool.core.util.ObjUtil;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import vion.constant.RedisKeyEnum;
import vion.dto.UserDTO; import vion.dto.UserDTO;
import vion.mapper.UserMapper; import vion.mapper.UserMapper;
import vion.model.Dept; import vion.model.Dept;
...@@ -39,6 +41,7 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem ...@@ -39,6 +41,7 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
private final IDeptService deptService; private final IDeptService deptService;
private final IRoleService roleService; private final IRoleService roleService;
private final IRUserRoleService userRoleService; private final IRUserRoleService userRoleService;
private final RedissonClient redissonClient;
private final Converter converter; private final Converter converter;
@Override @Override
...@@ -97,4 +100,13 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem ...@@ -97,4 +100,13 @@ public class UserServiceImpl extends MPJBaseServiceImpl<UserMapper, User> implem
return resTree; return resTree;
}).orElse(wholeTree); }).orElse(wholeTree);
} }
@Override
public void syncUser() {
Opt.ofEmptyAble(this.list())
.ifPresent(l -> l.forEach(user -> {
redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_ID.getVal() + user.getId()).set(user);
redissonClient.getBucket(RedisKeyEnum.DING_PREFIX.getVal() + RedisKeyEnum.USER_NAME.getVal() + user.getUsername()).set(user);
}));
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!