All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.flowable.demo.leave.service.impl.DefaultProcessLeaveServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.flowable.demo.leave.service.impl;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.zodiac.commons.util.Func;
import org.zodiac.core.service.exception.ServiceException;
import org.zodiac.flowable.business.service.FlowService;
import org.zodiac.flowable.core.constants.ProcessConstants;
import org.zodiac.flowable.core.model.PlatformProcessFlow;
import org.zodiac.flowable.core.util.ProcessFlowUtil;
import org.zodiac.flowable.core.util.ProcessTaskUtil;
import org.zodiac.flowable.demo.leave.mapper.ProcessLeaveEntityMapper;
import org.zodiac.flowable.demo.leave.model.entity.ProcessLeaveEntity;
import org.zodiac.flowable.demo.leave.service.ProcessLeaveService;
import org.zodiac.mybatisplus.base.SecurityBaseServiceImpl;
import org.zodiac.sdk.toolkit.support.Kv;
import org.zodiac.sdk.toolkit.util.DateTimeUtil;
import org.zodiac.security.SecurityAuthOperations2;

// @AllArgsConstructor
public class DefaultProcessLeaveServiceImpl, E extends ProcessLeaveEntity>
    extends SecurityBaseServiceImpl implements ProcessLeaveService {

    protected Logger log = LoggerFactory.getLogger(getClass());

    private final FlowService flowService;

    public DefaultProcessLeaveServiceImpl(SecurityAuthOperations2 securityAuthOperations, FlowService flowService) {
        super(securityAuthOperations);
        this.flowService = flowService;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean startProcess(E leave) {
        String businessTable = ProcessFlowUtil.getBusinessTable(ProcessConstants.LEAVE_KEY);
        if (Func.isEmpty(leave.getId())) {
            /*保存leave。*/
            leave.setApplyTime(new Date());
            save(leave);
            /*启动流程。*/
            Kv variables =
                Kv.create().set(ProcessConstants.TASK_VARIABLE_CREATE_USER, getSecurityAuthOperations().getUsername())
                    .set("taskUser", ProcessTaskUtil.getTaskUser(leave.getTaskUser()))
                    .set("days", DateTimeUtil.between(leave.getStartTime(), leave.getEndTime()).toDays());
            PlatformProcessFlow flow = flowService.startProcessInstanceById(leave.getProcessDefinitionId(),
                ProcessFlowUtil.getBusinessKey(businessTable, String.valueOf(leave.getId())), variables);
            if (Func.isNotEmpty(flow)) {
                log.debug("流程已启动,流程ID:" + flow.getProcessInstanceId());
                /*返回流程id写入leave。*/
                leave.setProcessInstanceId(flow.getProcessInstanceId());
                updateById(leave);
            } else {
                throw new ServiceException("开启流程失败");
            }
        } else {

            updateById(leave);
        }
        return true;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy