package com.yunzhupaas.flowable.service.impl;

import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.flowable.entity.OperatorEntity;
import com.yunzhupaas.flowable.entity.RejectDataEntity;
import com.yunzhupaas.flowable.entity.TaskEntity;
import com.yunzhupaas.exception.WorkFlowException;
import com.yunzhupaas.flowable.mapper.RejectDataMapper;
import com.yunzhupaas.flowable.service.RejectDataService;
import com.yunzhupaas.util.JsonUtil;
import com.yunzhupaas.util.RandomUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类的描述
 *
 * @author YUNZHUPAASYUNZHUPAAS开发组
 * @version 5.0.x
 * @since 2024/5/8 18:08
 */
@Service
public class RejectDataServiceImpl extends SuperServiceImpl<RejectDataMapper, RejectDataEntity>
        implements RejectDataService {

    @Override
    public RejectDataEntity getInfo(String id) throws WorkFlowException {
        RejectDataEntity entity = this.getById(id);
        if (entity == null) {
            throw new WorkFlowException(MsgCode.FA001.get());
        }
        return entity;
    }

    @Override
    public RejectDataEntity create(TaskEntity taskEntity, List<OperatorEntity> operatorEntityList, String nodeCode) {
        RejectDataEntity entity = new RejectDataEntity();
        entity.setId(RandomUtil.uuId());
        entity.setTaskJson(JsonUtil.getObjectToString(taskEntity));
        entity.setOperatorJson(JsonUtil.getObjectToString(operatorEntityList));
        entity.setNodeCode(nodeCode);
        this.save(entity);
        return entity;
    }

}
