Ver código fonte

提交代码

zlwu 1 ano atrás
pai
commit
8ddd3a0d09

+ 97 - 11
backend/ruoyi-modules/ruoyi-xg/src/main/java/org/dromara/xg/service/impl/XgDormApplicationServiceImpl.java

@@ -40,9 +40,11 @@ import org.dromara.xg.mapper.XgStudentManagerMapper;
 import org.dromara.xg.mapper.XgStudentManagerSourceMapper;
 import org.dromara.xg.mapper.XgClassMsgMapper;
 import org.dromara.xg.mapper.XgDormBedStudentMapper;
+import org.dromara.xg.service.IXgDormBedStudentService;
 import org.dromara.xg.domain.XgStudentManager;
 import org.dromara.xg.domain.XgStudentManagerSource;
 import org.dromara.xg.domain.XgClassMsg;
+import org.dromara.xg.domain.XgDormBedStudent;
 
 import java.util.List;
 import java.util.Map;
@@ -67,6 +69,7 @@ public class XgDormApplicationServiceImpl implements IXgDormApplicationService {
     private final XgDormApplicationMapper baseMapper;
     private final WorkflowService workflowService;
     private final XgDormBedStudentMapper xgDormBedStudentMapper;
+    private final IXgDormBedStudentService xgDormBedStudentService;
     // 添加权限过滤需要的依赖
     private final SysDeptMapper sysDeptMapper;
     private final SysUserMapper sysUserMapper;
@@ -427,32 +430,115 @@ public class XgDormApplicationServiceImpl implements IXgDormApplicationService {
     private void executeApplicationOperation(XgDormApplication application) {
         try {
             if ("1".equals(application.getApplicationType())) {
-                // 调宿申请 - 调用宿舍调整接口
+                // 调宿申请 - 区分两种场景处理
                 log.info("执行调宿操作: 学生ID={}, 目标床位ID={}", application.getStudentId(), application.getTargetBedId());
 
-                // 构建调宿参数并调用接口
-                // 参考提示词中的接口:/dormBedStudent/dormBedStudent/classTeacherExchangeBeds
-                // TODO: 这里需要根据实际情况调用相应的宿舍管理接口
-                log.info("调宿操作参数: sourceStudentId={}, targetBedId={}, classId={}",
-                        application.getStudentId(), application.getTargetBedId(), application.getClassId());
+                // 1. 根据目标床位ID查找当前占用该床位的学生ID
+                Long targetStudentId = findStudentByBedId(application.getTargetBedId());
+
+                Boolean operationResult = false;
+
+                if (targetStudentId != null) {
+                    // 场景1:目标床位有学生 - 两个学生互换床位
+                    log.info("目标床位已有学生,执行床位互换: 申请学生ID={}, 目标学生ID={}",
+                            application.getStudentId(), targetStudentId);
+
+                    operationResult = xgDormBedStudentService.classTeacherExchangeBeds(
+                            application.getStudentId(), // 源学生ID(申请人)
+                            targetStudentId, // 目标学生ID(目标床位当前占用者)
+                            application.getClassId() // 班级ID
+                    );
+
+                    if (operationResult) {
+                        log.info("床位互换操作执行成功: 申请学生ID={}, 目标学生ID={}, 班级ID={}",
+                                application.getStudentId(), targetStudentId, application.getClassId());
+                    } else {
+                        log.error("床位互换操作执行失败: 申请学生ID={}, 目标学生ID={}, 班级ID={}",
+                                application.getStudentId(), targetStudentId, application.getClassId());
+                        throw new RuntimeException("床位互换操作执行失败");
+                    }
+
+                } else {
+                    // 场景2:目标床位为空 - 学生移动到新床位
+                    log.info("目标床位为空,执行床位移动: 申请学生ID={}, 目标床位ID={}",
+                            application.getStudentId(), application.getTargetBedId());
+
+                    operationResult = xgDormBedStudentService.classTeacherMoveBed(
+                            application.getStudentId(), // 源学生ID(申请人)
+                            application.getTargetBedId(), // 目标床位ID
+                            application.getClassId() // 班级ID
+                    );
+
+                    if (operationResult) {
+                        log.info("床位移动操作执行成功: 申请学生ID={}, 目标床位ID={}, 班级ID={}",
+                                application.getStudentId(), application.getTargetBedId(), application.getClassId());
+                    } else {
+                        log.error("床位移动操作执行失败: 申请学生ID={}, 目标床位ID={}, 班级ID={}",
+                                application.getStudentId(), application.getTargetBedId(), application.getClassId());
+                        throw new RuntimeException("床位移动操作执行失败");
+                    }
+                }
 
             } else if ("2".equals(application.getApplicationType())) {
                 // 退宿申请 - 调用退宿接口
                 log.info("执行退宿操作: 学生ID={}, 当前床位ID={}", application.getStudentId(), application.getCurrentBedId());
 
                 // 构建退宿参数并调用接口
-                // 参考提示词中的接口:/dormBedStudent/dormBedStudent/classTeacherStayawaySelectedBeds
-                // TODO: 这里需要根据实际情况调用相应的宿舍管理接口
                 List<Long> bedIds = List.of(application.getCurrentBedId());
-                log.info("退宿操作参数: studentId={}, bedIds={}, classId={}",
-                        application.getStudentId(), bedIds, application.getClassId());
+                Boolean stayawayResult = xgDormBedStudentService.classTeacherStayawaySelectedBeds(
+                        bedIds, // 床位ID列表
+                        application.getClassId() // 班级ID
+                );
+
+                if (stayawayResult) {
+                    log.info("退宿操作执行成功: 学生ID={}, 床位ID={}, 班级ID={}",
+                            application.getStudentId(), application.getCurrentBedId(), application.getClassId());
+                } else {
+                    log.error("退宿操作执行失败: 学生ID={}, 床位ID={}, 班级ID={}",
+                            application.getStudentId(), application.getCurrentBedId(), application.getClassId());
+                    throw new RuntimeException("退宿操作执行失败");
+                }
+            } else {
+                log.error("未知的申请类型: {}", application.getApplicationType());
+                throw new RuntimeException("未知的申请类型: " + application.getApplicationType());
             }
 
             log.info("宿舍申请操作执行成功,申请ID: {}", application.getId());
 
         } catch (Exception e) {
             log.error("宿舍申请操作执行失败,申请ID: {}, 错误信息: {}", application.getId(), e.getMessage(), e);
-            // 可以考虑设置申请状态为失败或者发送通知
+            // 抛出异常,让调用方处理
+            throw new RuntimeException("宿舍申请操作执行失败: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * 根据床位ID查找当前占用该床位的学生ID
+     *
+     * @param bedId 床位ID
+     * @return 学生ID,如果没有找到则返回null
+     */
+    private Long findStudentByBedId(Long bedId) {
+        if (bedId == null) {
+            return null;
+        }
+        try {
+            LambdaQueryWrapper<XgDormBedStudent> queryWrapper = Wrappers.lambdaQuery();
+            queryWrapper.eq(XgDormBedStudent::getBedId, bedId)
+                    .eq(XgDormBedStudent::getStatus, "0") // 0-正常状态
+                    .eq(XgDormBedStudent::getDeleted, 0L); // 未删除
+
+            XgDormBedStudent bedStudent = xgDormBedStudentMapper.selectOne(queryWrapper);
+            if (bedStudent != null) {
+                log.info("根据床位ID: {} 找到学生ID: {}", bedId, bedStudent.getStudentId());
+                return bedStudent.getStudentId();
+            } else {
+                log.warn("床位ID: {} 没有找到对应的学生", bedId);
+                return null;
+            }
+        } catch (Exception e) {
+            log.error("根据床位ID: {} 查找学生失败: {}", bedId, e.getMessage(), e);
+            return null;
         }
     }
 

+ 77 - 4
web/src/components/Process/approvalRecord.vue

@@ -12,10 +12,19 @@
               <el-table-column prop="nodeName" label="任务名称" sortable align="center"></el-table-column>
               <el-table-column prop="approveName" :show-overflow-tooltip="true" label="办理人" sortable align="center">
                 <template #default="scope">
-                  <template v-if="scope.row.approveName">
+                  <template v-if="scope.row.approveUserDetails && scope.row.approveUserDetails.length > 0">
+                    <div v-for="(userDetail, index) in scope.row.approveUserDetails" :key="index" style="margin-bottom: 4px">
+                      <el-tag type="success">
+                        {{ `${userDetail.nickName}/${userDetail.userName}/${userDetail.phonenumber || '无'}` }}
+                      </el-tag>
+                    </div>
+                  </template>
+                  <template v-else-if="scope.row.approveName">
                     <el-tag v-for="(item, index) in scope.row.approveName.split(',')" :key="index" type="success">{{ item }}</el-tag>
                   </template>
-                  <template v-else> <el-tag type="success">无</el-tag></template>
+                  <template v-else>
+                    <el-tag type="success">无</el-tag>
+                  </template>
                 </template>
               </el-table-column>
               <el-table-column prop="flowStatus" label="状态" width="80" sortable align="center">
@@ -62,6 +71,8 @@
 import { flowHisTaskList } from '@/api/workflow/instance';
 import { propTypes } from '@/utils/propTypes';
 import { listByIds } from '@/api/system/oss';
+import { optionSelect } from '@/api/system/user';
+import { UserVO } from '@/api/system/user/types';
 import FlowChart from '@/components/Process/flowChart.vue';
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 const { wf_task_status } = toRefs<any>(proxy?.useDict('wf_task_status'));
@@ -81,11 +92,15 @@ const init = async (businessId: string | number) => {
   loading.value = true;
   tabActiveName.value = 'image';
   historyList.value = [];
-  flowHisTaskList(businessId).then((resp) => {
+
+  try {
+    const resp = await flowHisTaskList(businessId);
     if (resp.data) {
       historyList.value = resp.data.list;
       insId.value = resp.data.instanceId;
+
       if (historyList.value.length > 0) {
+        // 获取附件信息
         historyList.value.forEach((item) => {
           if (item.ext) {
             getIds(item.ext).then((res) => {
@@ -95,16 +110,74 @@ const init = async (businessId: string | number) => {
             item.attachmentList = [];
           }
         });
+
+        // 获取所有办理人的详细信息
+        await getUserDetails();
       }
       loading.value = false;
     }
-  });
+  } catch (error) {
+    console.error('获取审批记录失败:', error);
+    loading.value = false;
+  }
 };
 const getIds = async (ids: string | number) => {
   const res = await listByIds(ids);
   return res;
 };
 
+// 获取所有办理人的详细信息
+const getUserDetails = async () => {
+  try {
+    // 收集所有办理人的用户ID
+    const allUserIds = new Set<string>();
+
+    historyList.value.forEach((item) => {
+      if (item.approver) {
+        const approverIds = item.approver.split(',').filter((id) => id.trim());
+        approverIds.forEach((id) => allUserIds.add(id.trim()));
+      }
+    });
+
+    if (allUserIds.size > 0) {
+      // 批量获取用户详细信息
+      const userIds = Array.from(allUserIds);
+      const userResponse = await optionSelect(userIds);
+
+      if (userResponse.data && userResponse.data.length > 0) {
+        // 创建用户ID到用户详细信息的映射
+        const userMap = new Map();
+        userResponse.data.forEach((user: UserVO) => {
+          userMap.set(String(user.userId), user);
+        });
+
+        // 为每个审批记录项添加办理人详细信息
+        historyList.value.forEach((item) => {
+          if (item.approver) {
+            const approverIds = item.approver.split(',').filter((id) => id.trim());
+            item.approveUserDetails = approverIds.map((id) => {
+              const userId = id.trim();
+              return (
+                userMap.get(userId) || {
+                  userId: userId,
+                  nickName: '未知用户',
+                  userName: userId,
+                  phonenumber: ''
+                }
+              );
+            });
+          } else {
+            item.approveUserDetails = [];
+          }
+        });
+      }
+    }
+  } catch (error) {
+    console.error('获取用户详细信息失败:', error);
+    // 如果获取用户详细信息失败,保持原有显示方式
+  }
+};
+
 /** 下载按钮操作 */
 const handleDownload = (ossId: string, originalName: string) => {
   console.log(ossId);