Search in sources :

Example 1 with OapiProcessinstanceCreateResponse

use of com.dingtalk.api.response.OapiProcessinstanceCreateResponse in project dingtalk-app-server by nju-softeng.

the class OAApi method createAbsentOA.

public String createAbsentOA(AbsentOA absentOA) {
    try {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/create");
        OapiProcessinstanceCreateRequest request = new OapiProcessinstanceCreateRequest();
        request.setAgentId(BaseApi.AGENTID);
        // 设置process code
        request.setProcessCode(absentOAProcessCode);
        request.setOriginatorUserId(userService.getUserid(absentOA.getUser().getId()));
        request.setDeptId(-1L);
        // 设置表单内容
        List<OapiProcessinstanceCreateRequest.FormComponentValueVo> form = new ArrayList<>();
        OapiProcessinstanceCreateRequest.FormComponentValueVo type = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
        form.add(type);
        type.setName("请假类型");
        type.setValue(absentOA.getType());
        OapiProcessinstanceCreateRequest.FormComponentValueVo start = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
        form.add(start);
        start.setName("开始时间");
        start.setValue(absentOA.getDingTalkSchedule().getStart().toString());
        OapiProcessinstanceCreateRequest.FormComponentValueVo end = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
        form.add(end);
        end.setName("结束时间");
        end.setValue(absentOA.getDingTalkSchedule().getEnd().toString());
        // OapiProcessinstanceCreateRequest.FormComponentValueVo dayNum = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
        // form.add(dayNum);
        // dayNum.setName("结束时间");
        // dayNum.setValue(absentOA.getDayNum().toString());
        OapiProcessinstanceCreateRequest.FormComponentValueVo reason = new OapiProcessinstanceCreateRequest.FormComponentValueVo();
        form.add(reason);
        reason.setName("请假缘由");
        reason.setValue(absentOA.getReason());
        request.setFormComponentValues(form);
        // 设置审批人
        List<OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo> processInstanceApproverVoList = new ArrayList<>();
        OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo processInstanceApproverVo = new OapiProcessinstanceCreateRequest.ProcessInstanceApproverVo();
        processInstanceApproverVoList.add(processInstanceApproverVo);
        request.setApprovers(absentOA.getDingTalkSchedule().getOrganizer().getUserid());
        OapiProcessinstanceCreateResponse rsp = client.execute(request, getAccessToken());
        return rsp.getProcessInstanceId();
    } catch (Exception e) {
        throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) OapiProcessinstanceCreateRequest(com.dingtalk.api.request.OapiProcessinstanceCreateRequest) ArrayList(java.util.ArrayList) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient) ApiException(com.taobao.api.ApiException) ResponseStatusException(org.springframework.web.server.ResponseStatusException) OapiProcessinstanceCreateResponse(com.dingtalk.api.response.OapiProcessinstanceCreateResponse) ResponseStatusException(org.springframework.web.server.ResponseStatusException)

Aggregations

DefaultDingTalkClient (com.dingtalk.api.DefaultDingTalkClient)1 DingTalkClient (com.dingtalk.api.DingTalkClient)1 OapiProcessinstanceCreateRequest (com.dingtalk.api.request.OapiProcessinstanceCreateRequest)1 OapiProcessinstanceCreateResponse (com.dingtalk.api.response.OapiProcessinstanceCreateResponse)1 ApiException (com.taobao.api.ApiException)1 ArrayList (java.util.ArrayList)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1