You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

407 lines
14 KiB

6 months ago
package com.nov.KgLowDurable.service.Impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
6 months ago
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nov.KgLowDurable.mapper.UserMapper;
5 months ago
import com.nov.KgLowDurable.pojo.entity.*;
import com.nov.KgLowDurable.pojo.vo.*;
import com.nov.KgLowDurable.service.*;
import com.nov.KgLowDurable.util.HttpUtils;
6 months ago
import lombok.AllArgsConstructor;
5 months ago
import lombok.extern.slf4j.Slf4j;
import org.apache.http.util.EntityUtils;
5 months ago
import org.springframework.beans.BeanUtils;
6 months ago
import org.springframework.beans.factory.annotation.Autowired;
5 months ago
import org.springframework.context.annotation.Lazy;
6 months ago
import org.springframework.stereotype.Service;
5 months ago
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
6 months ago
import java.time.LocalDateTime;
6 months ago
import java.util.ArrayList;
import java.util.HashMap;
6 months ago
import java.util.List;
import java.util.Map;
5 months ago
import java.util.stream.Collectors;
6 months ago
/**
* 服务实现类
6 months ago
* @author liweidong
6 months ago
*/
@Service
@AllArgsConstructor
5 months ago
@Slf4j
6 months ago
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
@Autowired
UserMapper userMapper;
6 months ago
@Autowired
ILdApproveService ldApproveService;
5 months ago
@Autowired
IDepartmentService departmentService;
5 months ago
6 months ago
@Override
public UserInfoVO getUserInfo() throws Exception {
6 months ago
// Map<String, String> headers = new HashMap<String, String>() {{
// put("Content-Type", "application/json");
// }};
//
// Map<String, String> querys = new HashMap<String, String>() {{
// put("taskId", "1");
// }};
//
// String resp = EntityUtils.toString(
// HttpUtils.doGet(
// "http://10.90.100.231:8132",
// "/AES/decryptAndGetUser",
6 months ago
// "GET",
// headers,
// querys
// ).getEntity()
// );
//
// JSONObject obj = JSON.parseObject(resp);
//
// if (!"200".equals(obj.getString("code"))) {
// throw new RuntimeException("失败: " + obj.getString("message"));
// }
//
6 months ago
// UserInfoVO data = JSON.toJavaObject(obj.getJSONObject("data"), UserInfoVO.class);
6 months ago
6 months ago
UserInfoVO data = new UserInfoVO();
6 months ago
data.setUserId("AnXinghe");
data.setName("安星河");
data.setDepartment("中国民用航空青岛空中交通管理站/实业公司/IT事业部");
data.setGender("男");
data.setPhone("13526109603");
data.setRoleNames("普通用户,超级管理员");
data.setMainErDepartment("12");
data.setMainErDepartmentName("实业公司");
6 months ago
Role role = new Role();
role.setId(1L);
5 months ago
role.setCode("admin");
role.setName("超级管理员");
6 months ago
List<Role> roleList = new ArrayList<>();
roleList.add(role);
data.setRolelist(roleList);
6 months ago
return data;
}
5 months ago
/**
* 模拟数据 - 直接使用JSON字符串
*/
private static final String MOCK_APPROVAL_DATA = "{\n" +
" \"success\": true,\n" +
" \"message\": \"获取审批列表成功\",\n" +
" \"code\": 200,\n" +
" \"result\": {\n" +
" \"1\": [\n" +
" {\n" +
" \"userId\": \"LiuXu\",\n" +
" \"name\": \"刘旭\",\n" +
" \"department\": \"青岛空管站/实业公司/IT事业部/产品研发室\",\n" +
" \"mainDepartment\": \"82\",\n" +
" \"mainErDepartment\": \"20\",\n" +
" \"leaderInDept\": \",\",\n" +
" \"gender\": \"女\",\n" +
" \"phone\": \"17853572157\",\n" +
" \"mail\": null,\n" +
" \"roleList\": null,\n" +
" \"roleNames\": null,\n" +
" \"checked\": false,\n" +
" \"manageNum\": \"1\",\n" +
" \"deptId\": null,\n" +
" \"deptList\": null,\n" +
" \"postName\": null,\n" +
" \"virPostName\": null,\n" +
" \"apprStatus\": null,\n" +
" \"isCanAbnormal\": false,\n" +
" \"userSort\": 1000,\n" +
" \"isDel\": false,\n" +
" \"mainErDepartmentName\": null\n" +
" }\n" +
" ],\n" +
" \"2\": [\n" +
" {\n" +
" \"userId\": \"AnXingHe\",\n" +
" \"name\": \"安星河\",\n" +
" \"department\": \"青岛空管站/实业公司/IT事业部/产品研发室\",\n" +
" \"mainDepartment\": \"82\",\n" +
" \"mainErDepartment\": \"20\",\n" +
" \"leaderInDept\": \",20,\",\n" +
" \"gender\": \"男\",\n" +
" \"phone\": \"13526109603\",\n" +
" \"mail\": null,\n" +
" \"roleList\": null,\n" +
" \"roleNames\": null,\n" +
" \"checked\": false,\n" +
" \"manageNum\": \"1\",\n" +
" \"deptId\": null,\n" +
" \"deptList\": null,\n" +
" \"postName\": null,\n" +
" \"virPostName\": null,\n" +
" \"apprStatus\": null,\n" +
" \"isCanAbnormal\": false,\n" +
" \"userSort\": 1000,\n" +
" \"isDel\": false,\n" +
" \"mainErDepartmentName\": null\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"timestamp\": 1767767650684\n" +
"}";
6 months ago
@Override
public String getApprover(String mainErDepartment, String type,Long formId) {
5 months ago
// 参数校验
if (!StringUtils.hasText(type)) {
throw new IllegalArgumentException("审批类型不能为空");
}
if (formId == null || formId <= 0) {
throw new IllegalArgumentException("表单ID必须大于0");
}
Map<String, String> headers = new HashMap<String, String>() {{
put("Content-Type", "application/json");
}};
Map<String, String> querys = new HashMap();
querys. put("type",type);
if ("1".equals(type)) {
querys.put("deptId", mainErDepartment);
}
String resp = null;
try {
resp = EntityUtils.toString(
HttpUtils.doGet(
"http://10.90.100.231:8132",
"/ld-person-form/getApprove",
"GET",
headers,
querys
).getEntity()
);
} catch (Exception e) {
e.printStackTrace();
}
5 months ago
try {
// 1.解析模拟数据
JSONObject obj = JSON.parseObject(resp);
5 months ago
if (!"200".equals(obj.getString("code")) || !obj.getBooleanValue("success")) {
String message = obj.getString("message");
throw new RuntimeException("获取审批人失败: " + message);
}
// 2.获取审批结果数据
JSONObject result = obj.getJSONObject("result");
if (result == null || result.isEmpty()) {
throw new RuntimeException("未找到审批人数据");
}
// 3.保存审批人信息到数据库
List<LdApprove> approversToSave = new ArrayList<>();
// 构建审批人json结构 [{"level":1,"ids":"LiuXu"},{"level":2,"ids":"AnXingHe"},{"level":3,"ids":"LiuXu"}]
List<JSONObject> approvers = new ArrayList<>();
5 months ago
// 遍历所有审批层级(1, 2, 3...)
for (String level : result.keySet()) {
// 获取该层级的所有用户
List<User> users = result.getJSONArray(level).toJavaList(User.class);
if (CollectionUtils.isEmpty(users)) {
log.warn("层级 {} 没有审批人", level);
continue;
}
for (int i = 0; i < users.size(); i++) {
User user = users.get(i);
LdApprove ldApprove = createLdApprove(user, level, formId, type);
approversToSave.add(ldApprove);
JSONObject approver = new JSONObject();
approver.put("level", level);
approver.put("ids", user.getUserId());
approvers.add(approver);
5 months ago
}
}
// 5. 批量保存审批人
boolean saveSuccess = false;
if (!CollectionUtils.isEmpty(approversToSave)) {
saveSuccess = ldApproveService.saveBatch(approversToSave);
} else {
throw new RuntimeException("未找到审批人信息");
}
return JSONObject.toJSONString(approvers);
5 months ago
} catch (Exception e) {
throw new RuntimeException("处理审批人数据失败: " + e.getMessage(), e);
}
}
/**
* 创建审批记录实体
*/
private LdApprove createLdApprove(User user, String level, Long formId, String type) {
6 months ago
LdApprove ldApprove = new LdApprove();
6 months ago
ldApprove.setFormId(formId.intValue());
5 months ago
ldApprove.setUserId(user.getUserId());
ldApprove.setUserName(user.getName());
ldApprove.setLevel(level);
6 months ago
ldApprove.setStatus("0");
ldApprove.setOptTime(LocalDateTime.now());
5 months ago
ldApprove.setType("1".equals(type)?"3":type);
5 months ago
return ldApprove;
6 months ago
}
@Override
6 months ago
public User getDeptApprove(String department) {
5 months ago
String topDepartmentId = getTopDepartmentId(department);
User user = userMapper.selectByLeaderInDept(topDepartmentId);
if(null == user){
throw new RuntimeException(department+":部门负责人获取失败");
}
6 months ago
return user;
6 months ago
}
5 months ago
public String getTopDepartmentId(String departmentId) {
int maxDepth = 20;
int currentDepth = 0;
String currentId = departmentId;
while (currentDepth < maxDepth) {
Department dept = departmentService.getByDepartmentId(currentId);
if (dept == null) {
throw new RuntimeException("部门不存在: " + currentId);
}
String parentId = dept.getParentid();
//如果是顶级部门 返回当前部门ID
if ("0".equals(parentId) || "1".equals(parentId)) {
return dept.getId();
}
//否则继续查询父部门
currentId = parentId;
currentDepth++;
}
throw new RuntimeException("部门负责人获取失败,查询深度超过限制: " + departmentId);
}
6 months ago
@Override
public List<User> getUserByDeptId(String departmentId) {
return userMapper.selectByDepartmentId(departmentId);
}
5 months ago
@Override
5 months ago
public void submitApproval(String json) {
Map<String, String> headers = new HashMap<String, String>() {{
put("Content-Type", "application/json");
}};
5 months ago
Map<String, String> querys = new HashMap<String, String>() {{
}};
5 months ago
String resp = null;
try {
resp = EntityUtils.toString(
HttpUtils.doPost(
"http://10.90.100.231:8132",
"/qywx/applySubmit",
"POST",
headers,
querys,
json
).getEntity()
);
} catch (Exception e) {
e.printStackTrace();
}
5 months ago
}
@Override
public List<GroupVO> getOutGroupName() {
Map<String, String> headers = new HashMap<String, String>() {{
put("Content-Type", "application/json");
}};
5 months ago
Map<String, String> querys = new HashMap<String, String>() {{
}};
String resp = null;
try {
resp = EntityUtils.toString(
HttpUtils.doGet(
"http://10.90.100.231:8132",
"/ld-person-form/getOutGroupName",
"GET",
headers,
querys
).getEntity()
);
} catch (Exception e) {
e.printStackTrace();
}
5 months ago
JSONObject obj = JSON.parseObject(resp);
if (!"200".equals(obj.getString("code"))) {
throw new RuntimeException("失败: " + obj.getString("message"));
}
5 months ago
List<GroupVO> list = obj.getJSONArray("result").toJavaList(GroupVO.class);
if(CollectionUtils.isEmpty(list)){
throw new RuntimeException("解析失败: " + obj.getString("message"));
}
return list;
}
@Override
public List<GroupMaterialVO> getGroupMaterial(String groupName, String departmentId) {
Map<String, String> headers = new HashMap<String, String>() {{
put("Content-Type", "application/json");
}};
5 months ago
Map<String, String> querys = new HashMap<String, String>() {{
put("groupName",groupName);
}};
String resp = null;
try {
resp = EntityUtils.toString(
HttpUtils.doGet(
"http://10.90.100.231:8132",
"/ld-person-form/getGroupMaterial",
"GET",
headers,
querys
).getEntity()
);
} catch (Exception e) {
e.printStackTrace();
}
5 months ago
JSONObject obj = JSON.parseObject(resp);
if (!"200".equals(obj.getString("code"))) {
throw new RuntimeException("失败: " + obj.getString("message"));
}
5 months ago
GroupResultVO result = JSON.parseObject(
obj.getJSONObject("result").toString(),
GroupResultVO.class
);
List<GroupMaterialVO> materialVOList = result.getMaterials();
return materialVOList;
5 months ago
}
6 months ago
}