Merge branch 'feature/REQ-5965' into dev

This commit is contained in:
wangli 2025-11-19 15:26:04 +08:00
commit d1833584b2
2 changed files with 89 additions and 44 deletions

View File

@ -1,5 +1,6 @@
package cn.axzo.workflow.server.controller.web; package cn.axzo.workflow.server.controller.web;
import cn.axzo.framework.domain.data.AssertUtil;
import cn.axzo.infra.xxl220to250.XxlJobLogger; import cn.axzo.infra.xxl220to250.XxlJobLogger;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceAbortDTO; import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceAbortDTO;
import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceCancelDTO; import cn.axzo.workflow.common.model.request.bpmn.process.BpmnProcessInstanceCancelDTO;
@ -16,7 +17,7 @@ import cn.axzo.workflow.server.xxljob.DangerSuperOperationJobHandler;
import cn.azxo.framework.common.model.CommonResponse; import cn.azxo.framework.common.model.CommonResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RuntimeService; import org.flowable.engine.RuntimeService;
import org.springframework.http.MediaType; import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -33,6 +34,7 @@ import javax.servlet.http.HttpSession;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import static cn.axzo.workflow.common.code.BpmnInstanceRespCode.PROCESS_INSTANCE_NOT_EXISTS;
import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_INITIATOR; import static cn.axzo.workflow.common.constant.BpmnConstants.INTERNAL_INITIATOR;
import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.PROCESSING; import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.PROCESSING;
@ -104,8 +106,9 @@ public class DangerOperationController {
} }
// 处理表单提交 // 处理表单提交
@PostMapping(value = "/web/process/handle", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @PostMapping(value = "/web/process/handle")
public String handleProcess(@Validated @RequestBody DangerSuperOperationJobHandler.DangerOperationJobParam jobParam, Model model) { @ResponseBody
public CommonResponse<String> handleProcess(@Validated @RequestBody DangerSuperOperationJobHandler.DangerOperationJobParam jobParam, Model model) {
// 处理表单提交的逻辑 // 处理表单提交的逻辑
log.info("操作类型: {}", jobParam.getOperationType()); log.info("操作类型: {}", jobParam.getOperationType());
@ -113,6 +116,9 @@ public class DangerOperationController {
log.info("自然人ID: {}", jobParam.getPersonId()); log.info("自然人ID: {}", jobParam.getPersonId());
log.info("意见: {}", jobParam.getComment()); log.info("意见: {}", jobParam.getComment());
try {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(jobParam.getProcessInstanceId()).singleResult();
AssertUtil.notNull(processInstance, PROCESS_INSTANCE_NOT_EXISTS);
// 这里可以添加实际的业务逻辑如调用流程引擎API等 // 这里可以添加实际的业务逻辑如调用流程引擎API等
switch (jobParam.getOperationType()) { switch (jobParam.getOperationType()) {
case CANCEL: case CANCEL:
@ -133,10 +139,14 @@ public class DangerOperationController {
default: default:
break; break;
} }
// 可以将处理结果添加到模型中返回给页面 // 可以将处理结果添加到模型中返回给页面
model.addAttribute("message", "操作已成功提交"); model.addAttribute("message", "操作已成功提交");
return "form"; // 处理完成后返回表单页面 return CommonResponse.success("操作已成功提交");
} catch (Exception e) {
model.addAttribute("message", "操作失败: " + e.getMessage());
return CommonResponse.error("操作失败: " + e.getMessage());
}
} }

View File

@ -62,6 +62,11 @@
} }
} }
</style> </style>
<!-- 全局上下文路径变量 -->
<script th:inline="javascript">
const ctx = [[@{/}]]; // 自动获取servlet.context.path
</script>
</head> </head>
<body class="bg-gray-50 font-inter min-h-screen flex flex-col"> <body class="bg-gray-50 font-inter min-h-screen flex flex-col">
<!-- 顶部导航 --> <!-- 顶部导航 -->
@ -174,7 +179,7 @@
</button> </button>
</div> </div>
<p class="mt-2 text-xs text-gray-500"> <p class="mt-2 text-xs text-gray-500">
<i class="fa fa-clock-o mr-1"></i>授权码有效期为1分钟,请及时使用 <i class="fa fa-clock-o mr-1"></i>授权码有效期为30分钟,请及时使用
</p> </p>
</div> </div>
@ -276,6 +281,9 @@
<i class="fa fa-check mr-2"></i>提交 <i class="fa fa-check mr-2"></i>提交
</button> </button>
</div> </div>
<!-- 操作消息显示区域 -->
<div id="operationMessage" class="mt-4 p-4 rounded-lg hidden"></div>
</form> </form>
</div> </div>
@ -345,6 +353,7 @@
const copyToast = document.getElementById('copyToast'); const copyToast = document.getElementById('copyToast');
const submitMask = document.getElementById('submitMask'); const submitMask = document.getElementById('submitMask');
const maskMessage = document.getElementById('maskMessage'); const maskMessage = document.getElementById('maskMessage');
const operationMessage = document.getElementById('operationMessage');
// 错误提示元素 // 错误提示元素
const processInstanceIdError = document.getElementById('processInstanceIdError'); const processInstanceIdError = document.getElementById('processInstanceIdError');
@ -524,7 +533,7 @@
async function getAuthCode() { async function getAuthCode() {
const password = authPassword.value.trim(); const password = authPassword.value.trim();
if (!password) { if (!password) {
getAuthError.textContent = '<i class="fa fa-exclamation-circle mr-1"></i>请输入管理员密码'; getAuthError.innerHTML = '<i class="fa fa-exclamation-circle mr-1"></i>请输入管理员密码';
getAuthError.classList.remove('hidden'); getAuthError.classList.remove('hidden');
return; return;
} }
@ -534,16 +543,15 @@
getAuthError.classList.add('hidden'); getAuthError.classList.add('hidden');
try { try {
// 构造带查询参数的URLPOST方式但参数通过URL传递 // 使用全局上下文路径变量拼接URL
const url = `/web/process/get-auth-code?password=${encodeURIComponent(password)}`; const url = `${ctx}web/process/get-auth-code?password=${encodeURIComponent(password)}`;
// 保持POST请求方式参数通过URL查询参数传递 // 保持POST请求方式参数通过URL查询参数传递
const response = await fetch(url, { const response = await fetch(url, {
method: 'POST', // 保持POST请求方式 method: 'POST',
headers: { headers: {
'Accept': 'application/json' // 只保留接收JSON的头 'Accept': 'application/json'
} }
// 移除body参数通过URL传递
}); });
const result = await response.json(); const result = await response.json();
@ -559,7 +567,7 @@
// }, 1000); // }, 1000);
} else { } else {
// 显示错误信息 // 显示错误信息
getAuthError.innerHTML = '<i class="fa fa-exclamation-circle mr-1"></i>' + (result.message || '密码错误,无法获取授权码'); getAuthError.innerHTML = '<i class="fa fa-exclamation-circle mr-1"></i>' + (result.msg || '密码错误,无法获取授权码');
getAuthError.classList.remove('hidden'); getAuthError.classList.remove('hidden');
} }
} catch (error) { } catch (error) {
@ -602,6 +610,7 @@
}; };
try { try {
// 使用全局上下文路径变量
const response = await fetch(this.action, { const response = await fetch(this.action, {
method: this.method, method: this.method,
headers: { headers: {
@ -611,18 +620,28 @@
body: JSON.stringify(formData) body: JSON.stringify(formData)
}); });
if (response.ok) { const result = await response.json();
showSuccessToast();
processForm.reset(); // 显示消息区域
updateFormFields(); operationMessage.classList.remove('hidden');
if (response.ok && result.code === 200) {
// 成功消息 - 绿色背景
operationMessage.className = 'mt-4 p-4 rounded-lg bg-green-50 border border-green-200 text-green-700';
operationMessage.innerHTML = `<i class="fa fa-check-circle mr-2"></i>${result.msg || '操作已成功提交'}`;
} else { } else {
alert('提交失败,请重试'); // 错误消息 - 红色背景
operationMessage.className = 'mt-4 p-4 rounded-lg bg-red-50 border border-red-200 text-red-700';
operationMessage.innerHTML = `<i class="fa fa-exclamation-circle mr-2"></i>${result.msg || '操作失败,请重试'}`;
} }
} catch (error) { } catch (error) {
console.error('请求错误:', error); console.error('请求错误:', error);
alert('网络错误,请稍后重试'); // 网络错误消息
operationMessage.className = 'mt-4 p-4 rounded-lg bg-red-50 border border-red-200 text-red-700';
operationMessage.innerHTML = `<i class="fa fa-exclamation-circle mr-2"></i>网络错误,请稍后重试`;
operationMessage.classList.remove('hidden');
} finally { } finally {
// 无论成功或失败,都隐藏遮罩层 // 隐藏遮罩层
hideMask(); hideMask();
} }
}); });
@ -651,10 +670,26 @@
updateFormFields(); updateFormFields();
} }
// 如果有授权错误,显示错误信息 // 页面加载时检查后端消息
document.addEventListener('DOMContentLoaded', function () {
// 检查流程操作的后端消息(使用 Thymeleaf JS 内联语法)
/*[[#{
if (${message != null}) {
operationMessage.classList.remove('hidden');
if (${message.startsWith('操作成功')}) {
operationMessage.className = 'mt-4 p-4 rounded-lg bg-green-50 border border-green-200 text-green-700';
} else {
operationMessage.className = 'mt-4 p-4 rounded-lg bg-red-50 border border-red-200 text-red-700';
}
operationMessage.innerHTML = '<i class="fa ' + (${message.startsWith('操作成功')} ? 'fa-check-circle' : 'fa-exclamation-circle') + ' mr-2"></i>' + '${message}';
}
}]]*/
// 显示授权错误(如果有)
if (authError && authError.textContent.trim() !== '') { if (authError && authError.textContent.trim() !== '') {
authError.classList.remove('hidden'); authError.classList.remove('hidden');
} }
});
</script> </script>
</body> </body>
</html> </html>