ApprovalController.java 5.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
package pwc.taxtech.atms.controller;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.ProcessDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
gary's avatar
gary committed
11
import org.springframework.security.access.annotation.Secured;
12
import org.springframework.web.bind.annotation.*;
13
import pwc.taxtech.atms.common.util.MyAsserts;
14
import pwc.taxtech.atms.dto.approval.ApprovalDto;
15
import pwc.taxtech.atms.entity.Template;
16
import pwc.taxtech.atms.exception.Exceptions;
17
import pwc.taxtech.atms.vat.dpo.ApprovalTaskInfo;
18
import pwc.taxtech.atms.vat.service.impl.ApprovalService;
19 20 21 22 23 24 25 26 27 28 29 30 31 32

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

@RestController
@RequestMapping(value = "/api/v1/approval")
public class ApprovalController {
    private static Logger logger = LoggerFactory.getLogger(ApprovalController.class);
    @Autowired
    RuntimeService runtimeService;
    @Autowired
    TaskService taskService;
    @Autowired
33 34
    ApprovalService approvalService;
    @Autowired
35 36 37 38 39 40 41 42 43
    RepositoryService repositoryService;

    @ResponseBody
    @RequestMapping(value = "/deploy", method = RequestMethod.POST)
    public ResponseEntity deploy() {
        repositoryService.createDeployment().addClasspathResource("bpmn/approval.bpmn").deploy();
        return ResponseEntity.ok().build();
    }

gary's avatar
gary committed
44
//    @ApiOperation(value = "提交报表")
45 46
    @ResponseBody
    @RequestMapping(value = "/commit", method = RequestMethod.POST)
gary's avatar
gary committed
47
    @Secured("vatApproval:commit")
48
    public ApprovalDto approval(@RequestBody ApprovalDto dto) {
49 50 51
        MyAsserts.assertNotEmpty(dto.getProjectId(), Exceptions.EMPTY_PROJECT_PARAM);
        MyAsserts.assertNotEmpty(dto.getPeriodDate(), Exceptions.EMPTY_PRIODDATE_PARAM);
        approvalService.startInstanceAndAssignee(dto);
52 53 54 55
        return dto;
    }

    @ResponseBody
56 57 58
    @RequestMapping(value = "/tasks/{assignee}/{year}/{month}")
    public List<ApprovalTaskInfo> data(@PathVariable String assignee,@PathVariable Integer year,@PathVariable Integer month) {//accountant manager
        return approvalService.getTask(year,month);
59 60
    }

61 62
    @ResponseBody
    @RequestMapping(value = "/templateInfo/{templateId}")
63
    public Template getFirstTemplate(@PathVariable Long templateId) {//accountant manager
64 65 66
        return approvalService.getTemplateInfo(templateId);
    }

gary's avatar
gary committed
67
//    @ApiOperation(value = "审批报表")
68 69 70 71 72 73 74
    /**
     * 同机构的不同角色不会有相同的用户
     * @param projectId
     * @param period
     * @param decide
     * @param comment
     */
75
    @ResponseBody
neo's avatar
neo committed
76
    @RequestMapping(value = "/check/{projectId}/{period}",method = RequestMethod.PUT)
gary's avatar
gary committed
77
    @Secured("vatApproval:check")
78
    public void check(@PathVariable String projectId,@PathVariable Integer period, @RequestParam String decide, @RequestParam String comment) {//only for manager role
79
        approvalService.checkTask(projectId, period, decide,comment,"");
80 81
    }

82 83 84 85 86 87
    @ResponseBody
    @RequestMapping(value = "/status/{projectId}/{period}")
    public String getApprovalStatus(@PathVariable String projectId,@PathVariable Integer period){
        return  approvalService.getApprovalStatus(projectId,period);
    }

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    @RequestMapping(value = "/show/{procDefId}")//获取流程图
    public void showImg(@PathVariable String procDefId, HttpServletResponse response) {
        try {
            ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
            String diagramResourceName = pd.getDiagramResourceName();
            InputStream pic = repositoryService.getResourceAsStream(pd.getDeploymentId(), diagramResourceName);

            byte[] b = new byte[1024];
            int len = -1;
            while ((len = pic.read(b, 0, 1024)) != -1) {
                response.getOutputStream().write(b, 0, len);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @ResponseBody
    @RequestMapping(value = "/showImg/{procDefId}/{executionId}")//获取流程坐标
    public Rect showImg(@PathVariable String procDefId, @PathVariable String executionId) {
        Rect rect = new Rect();
        try {
            repositoryService.getProcessDefinition(procDefId);
//            ActivityImpl img = Workflow.getProcessMap(procDefId,executionId );
//            rect.setX(img.getX());
//            rect.setY(img.getY());
//            rect.setWidth(img.getWidth());
//            rect.setHeight(img.getHeight());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rect;
    }


    static class Rect {
        String X;
        String Y;
        String width;
        String height;

        public String getX() {
            return X;
        }

        public void setX(String x) {
            X = x;
        }

        public String getY() {
            return Y;
        }

        public void setY(String y) {
            Y = y;
        }

        public String getWidth() {
            return width;
        }

        public void setWidth(String width) {
            this.width = width;
        }

        public String getHeight() {
            return height;
        }

        public void setHeight(String height) {
            this.height = height;
        }
    }



}