FlowApproveRpc.java
1.96 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cn.fw.valhalla.rpc.flow;
import cn.fw.data.base.domain.common.Message;
import cn.fw.flow.api.FlowApi;
import cn.fw.flow.param.ApprovalDataDto;
import cn.fw.flow.result.FlowOrderDto;
import cn.fw.valhalla.rpc.flow.dto.FlowDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.Objects;
import static cn.fw.common.businessvalidator.Validator.BV;
/**
* @author kurisu
* @description: 发起审批
* @date 2019/9/22.
*/
@Service
@Slf4j
public class FlowApproveRpc {
private final FlowApi flowApi;
@Autowired
public FlowApproveRpc(FlowApi flowApi) {
this.flowApi = flowApi;
}
public String initiate(final FlowDto flowDto) {
ApprovalDataDto dataDto = new ApprovalDataDto();
BeanUtils.copyProperties(flowDto, dataDto);
dataDto.setBriefContentList(flowDto.getBriefContentList());
dataDto.setParam(flowDto.getParam());
Message<FlowOrderDto> msg = flowApi.initiateApproval(dataDto);
log.info("发起审批FlowApproveRpc.initiateApproval, 参数:[{}] 结果:{}", dataDto, msg.getResult());
boolean success = msg.isSuccess() && Objects.nonNull(msg.getData());
BV.isTrue(success, msg.getResult());
FlowOrderDto data = msg.getData();
return data.getOrderNo();
}
public boolean cancel(final String orderNo) {
try {
Message<Boolean> msg = flowApi.cancelApproval(Collections.singletonList(orderNo));
log.info("取消审批FlowApproveRpc.cancelApproval, 参数:[{}] 结果:{}", orderNo, msg.getResult());
return msg.isSuccess() && Objects.equals(Boolean.TRUE, msg.getData());
} catch (Exception e) {
log.error("取消审批失败, 参数:[{}]", orderNo);
e.printStackTrace();
}
return false;
}
}