赵士淞
2023-05-09 b8441a1ac74d2c3325dd36d69ced511f19cd760b
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/business/service/impl/BusinessExpenseServiceFlowableImpl.java
@@ -23,14 +23,27 @@
import me.zhengjie.modules.business.service.dto.BusinessExpenseDto;
import me.zhengjie.modules.business.service.dto.BusinessExpenseReimbursementDto;
import me.zhengjie.modules.business.service.dto.BusinessPlanDto;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.project.service.ProjectService;
import me.zhengjie.modules.project.service.dto.ProjectDto;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.RoleRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.ObjectUtil;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -45,9 +58,14 @@
@RequiredArgsConstructor
public class BusinessExpenseServiceFlowableImpl implements BusinessExpenseFlowableService {
    @Value("${flowable.url}")
    private String flowableUrl;
    private final Api api;
    private final BusinessPlanService businessPlanService;
    private final ProjectService projectService;
    private final RoleRepository roleRepository;
    private final UserRepository userRepository;
    /**
     * 我发起的
@@ -57,7 +75,7 @@
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> report() throws Exception {
        // 发起通信
        Object returnObject = api.post("http://localhost:8888/api/common/report?key=" + "businessExpenseApply" + "&userId=" + SecurityUtils.getCurrentUserId(), new HashMap<>());
        Object returnObject = api.post(flowableUrl + "/api/common/report?key=" + "businessExpenseApply" + "&userId=" + SecurityUtils.getCurrentUserId(), new HashMap<>());
        // 查询处理
        return queryHandle(returnObject);
    }
@@ -70,7 +88,7 @@
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> approve() throws Exception {
        // 发起通信
        Object returnObject = api.post("http://localhost:8888/api/common/approve?key=" + "businessExpenseApply" + "&userId=" + SecurityUtils.getCurrentUserId(), new HashMap<>());
        Object returnObject = api.post(flowableUrl + "/api/common/approve?key=" + "businessExpenseApply" + "&userId=" + SecurityUtils.getCurrentUserId(), new HashMap<>());
        // 查询处理
        return queryHandle(returnObject);
    }
@@ -117,11 +135,27 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(BusinessExpenseDto resources) throws Exception {
        // 查询指定角色
        Role role = roleRepository.findByLevel(Constant.ROLE_LEVEL_FINANCE.intValue());
        // 查询指定角色用户
        List<User> userList = userRepository.findByRoleId(role.getId());
        // 审批人字符串
        String approver = "";
        // 循环指定角色用户
        for (int i = 0; i < userList.size(); i ++) {
            if (i == 0) {
                // 审批人字符串
                approver = userList.get(i).getId().toString();
            } else {
                // 审批人字符串
                approver += "," + userList.get(i).getId().toString();
            }
        }
        // 参数
        Map<String, Object> params = ObjectUtil.toObjectMap(resources);
        params.put("approver", "1,2,3,4,5");
        params.put("approver", approver);
        // 发起通信
        api.post("http://localhost:8888/api/common/run?key=" + "businessExpenseApply" + "&userId=" + SecurityUtils.getCurrentUserId(), params);
        api.post(flowableUrl + "/api/common/run?key=" + "businessExpenseApply" + "&userId=" + SecurityUtils.getCurrentUserId(), params);
    }
    /**
@@ -135,7 +169,7 @@
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("approve", "true");
        // 发起通信
        api.post("http://localhost:8888/api/common/next?processInstanceId=" + processInstanceId, paramsMap);
        api.post(flowableUrl + "/api/common/next?processInstanceId=" + processInstanceId, paramsMap);
    }
    /**
@@ -149,6 +183,23 @@
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("approve", "false");
        // 发起通信
        api.post("http://localhost:8888/api/common/next?processInstanceId=" + processInstanceId, paramsMap);
        api.post(flowableUrl + "/api/common/next?processInstanceId=" + processInstanceId, paramsMap);
    }
    /**
     * 流程图
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void processDiagram(HttpServletRequest request, HttpServletResponse response, String processInstanceId) throws Exception {
        // 发起通信
        byte[] obj = api.postStream(flowableUrl + "/api/common/processDiagram?processInstanceId=" + processInstanceId, new HashMap<>());
        // 输入流
        InputStream in = new ByteArrayInputStream(obj);
        // inputStream 转 File
        File file = FileUtil.inputStreamToFile(in, "流程图-" + new Date().getTime() + ".jpeg");
        // 下载文件
        FileUtil.downloadFile(request, response, file, true);
    }
}