package cn.iocoder.yudao.module.bpm.service.definition;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.filter.BpmInstanceFilterPageReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmInstanceFilterDO;
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmInstanceFilterMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 流程实例过滤 Service 接口
 *

 */
@Service
@Validated
@Slf4j
public class BpmInstanceFilterServiceImpl implements  BpmInstanceFilterService{

    @Resource
    private BpmInstanceFilterMapper instanceFilterMapper;

    @Override
    public Long createInstanceFilter(String processInstanceId) {
        // 插入
        BpmInstanceFilterDO instanceFilter  =  new BpmInstanceFilterDO() ;
        instanceFilter.setProcessInstanceId(processInstanceId) ;
        instanceFilter.setStatus(1) ;
        instanceFilterMapper.insert(instanceFilter);
        // 返回
        return instanceFilter.getId();
    }

    @Override
    public void updateInstanceFilterStatus(Long id, Integer status) {
        BpmInstanceFilterDO result = instanceFilterMapper.selectById(id);
        result.setStatus(status) ;
        instanceFilterMapper.updateById(result) ;
    }

    @Override
    public void deleteInstanceFilter(Long id) {
        instanceFilterMapper.deleteById(id) ;
    }

    @Override
    public PageResult<BpmInstanceFilterDO> getInstanceFilterPage(BpmInstanceFilterPageReqVO pageReqVO) {
        return instanceFilterMapper.selectPage(pageReqVO);
    }
}
