刘光辉
4 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
    }
}