package cn.axzo.workflow.core.service.impl;

import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
import cn.axzo.workflow.core.repository.entity.ExtAxReProcDef;
import cn.axzo.workflow.core.repository.mapper.ExtAxReProcDefMapper;
import cn.axzo.workflow.core.service.ExtAxReProcDefService;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 流程定义扩展表操作服务实现
 *
 * @author wangli
 * @since 2023/11/18 22:27
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class ExtAxReProcDefServiceImpl implements ExtAxReProcDefService {

    @Resource
    private ExtAxReProcDefMapper extAxReProcDefMapper;

    @Override
    public List<ExtAxReProcDef> listByProcDefIds(List<String> procDefIds) {
        return extAxReProcDefMapper.selectList(new QueryWrapper<ExtAxReProcDef>().in("proc_def_id", procDefIds));
    }

    @Override
    public void create(String procDefId, BpmnTaskDelegateAssigner operatorAssigner) {
        ExtAxReProcDef extAxReProcDef = new ExtAxReProcDef();
        extAxReProcDef.setProcDefId(procDefId);
        extAxReProcDef.setOperatorId(operatorAssigner.getAssignee());
        extAxReProcDef.setOperatorName(operatorAssigner.getAssignerName());
        extAxReProcDef.setOperatorType(operatorAssigner.getAssigneeType());
        extAxReProcDef.setTenantId(operatorAssigner.getTenantId());
        extAxReProcDef.setOperatorMetaData(JSONUtil.toJsonStr(operatorAssigner));
        extAxReProcDefMapper.insert(extAxReProcDef);
    }
}
