|
|
|
|
@ -3,17 +3,23 @@ import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.nov.KgLowDurable.mapper.UserMapper; |
|
|
|
|
import com.nov.KgLowDurable.pojo.entity.Department; |
|
|
|
|
import com.nov.KgLowDurable.pojo.entity.LdApprove; |
|
|
|
|
import com.nov.KgLowDurable.pojo.entity.Role; |
|
|
|
|
import com.nov.KgLowDurable.pojo.entity.User; |
|
|
|
|
import com.nov.KgLowDurable.pojo.vo.UserInfoVO; |
|
|
|
|
import com.nov.KgLowDurable.service.IDepartmentService; |
|
|
|
|
import com.nov.KgLowDurable.service.ILdApproveService; |
|
|
|
|
import com.nov.KgLowDurable.service.IUserService; |
|
|
|
|
import com.nov.KgLowDurable.util.HttpUtils; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
@ -26,6 +32,7 @@ import java.util.Map; |
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
@AllArgsConstructor |
|
|
|
|
@Slf4j |
|
|
|
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService { |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
@ -34,6 +41,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU |
|
|
|
|
@Autowired |
|
|
|
|
ILdApproveService ldApproveService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
IDepartmentService departmentService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public UserInfoVO getUserInfo() throws Exception { |
|
|
|
|
// Map<String, String> headers = new HashMap<String, String>() {{
|
|
|
|
|
@ -81,8 +91,82 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU |
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 模拟数据 - 直接使用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" + |
|
|
|
|
"}"; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean getApprover(String mainErDepartment, String type,Long formId) { |
|
|
|
|
// 参数校验
|
|
|
|
|
if (!StringUtils.hasText(type)) { |
|
|
|
|
throw new IllegalArgumentException("审批类型不能为空"); |
|
|
|
|
} |
|
|
|
|
if (formId == null || formId <= 0) { |
|
|
|
|
throw new IllegalArgumentException("表单ID必须大于0"); |
|
|
|
|
} |
|
|
|
|
log.info("模拟获取审批人,参数: deptId={}, type={}, formId={}", mainErDepartment, type, formId); |
|
|
|
|
// Map<String, String> headers = new HashMap<String, String>() {{
|
|
|
|
|
// put("Content-Type", "application/json");
|
|
|
|
|
// }};
|
|
|
|
|
@ -95,8 +179,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU |
|
|
|
|
// try {
|
|
|
|
|
// resp = EntityUtils.toString(
|
|
|
|
|
// HttpUtils.doGet(
|
|
|
|
|
// "http://192.168.198.1:8105",
|
|
|
|
|
// "/dsTasking/processAuthorized",
|
|
|
|
|
// "http://10.90.100.231:8132",
|
|
|
|
|
// "/ld-person-form/getApprove",
|
|
|
|
|
// "GET",
|
|
|
|
|
// headers,
|
|
|
|
|
// querys
|
|
|
|
|
@ -105,64 +189,109 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU |
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// JSONObject obj = JSON.parseObject(resp);
|
|
|
|
|
//
|
|
|
|
|
// if (!"200".equals(obj.getString("code"))) {
|
|
|
|
|
// throw new RuntimeException("失败: " + obj.getString("message"));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// ApproverUser approverUser = JSON.toJavaObject(obj.getJSONObject("data"), ApproverUser.class);
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// 1.解析模拟数据
|
|
|
|
|
JSONObject obj = JSON.parseObject(MOCK_APPROVAL_DATA); |
|
|
|
|
|
|
|
|
|
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<>(); |
|
|
|
|
|
|
|
|
|
// 遍历所有审批层级(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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 5. 批量保存审批人
|
|
|
|
|
boolean saveSuccess = false; |
|
|
|
|
if (!CollectionUtils.isEmpty(approversToSave)) { |
|
|
|
|
saveSuccess = ldApproveService.saveBatch(approversToSave); |
|
|
|
|
} else { |
|
|
|
|
throw new RuntimeException("未找到审批人信息"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return saveSuccess; |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException("处理审批人数据失败: " + e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建审批记录实体 |
|
|
|
|
*/ |
|
|
|
|
private LdApprove createLdApprove(User user, String level, Long formId, String type) { |
|
|
|
|
LdApprove ldApprove = new LdApprove(); |
|
|
|
|
ldApprove.setFormId(formId.intValue()); |
|
|
|
|
ldApprove.setUserId("LiuXu"); |
|
|
|
|
ldApprove.setUserName("刘旭"); |
|
|
|
|
ldApprove.setLevel("1"); |
|
|
|
|
ldApprove.setUserId(user.getUserId()); |
|
|
|
|
ldApprove.setUserName(user.getName()); |
|
|
|
|
ldApprove.setLevel(level); |
|
|
|
|
ldApprove.setStatus("0"); |
|
|
|
|
ldApprove.setOptTime(LocalDateTime.now()); |
|
|
|
|
ldApprove.setType(type); |
|
|
|
|
boolean save = ldApproveService.save(ldApprove); |
|
|
|
|
return save; |
|
|
|
|
|
|
|
|
|
return ldApprove; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public User getDeptApprove(String department) { |
|
|
|
|
// Map<String, String> headers = new HashMap<String, String>() {{
|
|
|
|
|
// put("Content-Type", "application/json");
|
|
|
|
|
// }};
|
|
|
|
|
//
|
|
|
|
|
// Map<String, String> querys = new HashMap<String, String>() {{
|
|
|
|
|
// put("deptId",department);
|
|
|
|
|
// }};
|
|
|
|
|
//
|
|
|
|
|
// String resp = null;
|
|
|
|
|
// try {
|
|
|
|
|
// resp = EntityUtils.toString(
|
|
|
|
|
// HttpUtils.doGet(
|
|
|
|
|
// "http://10.90.100.231:8132",
|
|
|
|
|
// "/lowDurableTest/ld-approver/getDeptApprove",
|
|
|
|
|
// "GET",
|
|
|
|
|
// headers,
|
|
|
|
|
// querys
|
|
|
|
|
// ).getEntity()
|
|
|
|
|
// );
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// JSONObject obj = JSON.parseObject(resp);
|
|
|
|
|
//
|
|
|
|
|
// if (!"200".equals(obj.getString("code"))) {
|
|
|
|
|
// throw new RuntimeException("失败: " + obj.getString("message"));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// UserInfoVO approverUser = JSON.toJavaObject(obj.getJSONObject("data"), UserInfoVO.class);
|
|
|
|
|
User user = new User(); |
|
|
|
|
user.setUserId("负责人ID"); |
|
|
|
|
user.setName("负责人名称"); |
|
|
|
|
|
|
|
|
|
String topDepartmentId = getTopDepartmentId(department); |
|
|
|
|
|
|
|
|
|
User user = userMapper.selectByLeaderInDept(topDepartmentId); |
|
|
|
|
|
|
|
|
|
if(null == user){ |
|
|
|
|
throw new RuntimeException(department+":部门负责人获取失败"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return user; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<User> getUserByDeptId(String departmentId) { |
|
|
|
|
return userMapper.selectByDepartmentId(departmentId); |
|
|
|
|
|