package jnpf.flowable.service.dev; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import jnpf.exception.WorkFlowException; import jnpf.flowable.mapper.DevApprovalSignatureMapper; import jnpf.util.UserProvider; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.Objects; @Service @RequiredArgsConstructor public class DevApprovalSignatures { private final DevApprovalSignatureMapper mapper; public DevApprovalSignature require(String taskId, String signId) throws WorkFlowException { if (signId == null || signId.isBlank()) throw new WorkFlowException("请先完成本轮电子签名"); String tenant = UserProvider.getUser().getTenantId(); DevApprovalSignature sign = mapper.find(signId, tenant == null || tenant.isBlank() ? "0" : tenant); if (sign == null || !Objects.equals(sign.getUserId(), UserProvider.getLoginUserId())) throw new WorkFlowException("电子签名不存在或不属于当前登录用户"); // A new native signature is required for each run; it can be reused only on this instance. long age = sign.getCreatedAt() == null ? Long.MAX_VALUE : System.currentTimeMillis() - sign.getCreatedAt().getTime(); if (age < -60000 || age > 30 * 60 * 1000 || (sign.getExtraJson() != null && !sign.getExtraJson().isBlank())) throw new WorkFlowException("电子签名已过期或已被其他业务使用,请重新签名"); JSONObject meta; try { meta = JSON.parseObject(sign.getMetaData()); } catch (RuntimeException e) { throw new WorkFlowException("电子签名业务信息无效"); } if (meta == null || !"workflow-dev-approval".equals(meta.getString("biz_module")) || meta.getJSONArray("biz_data") == null || meta.getJSONArray("biz_data").size() != 1 || !taskId.equals(meta.getJSONArray("biz_data").getString(0))) throw new WorkFlowException("电子签名不属于本流程的一键审批操作"); return sign; } }