package com.chinaweal.aiccs.aiccs.auditing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chinaweal.aiccs.aiccs.auditing.entity.TSOpinion;
import com.chinaweal.aiccs.aiccs.auditing.mapper.TSOpinionMapper;
import com.chinaweal.aiccs.aiccs.auditing.service.TSOpinionService;
import com.chinaweal.aiccs.common.util.HandleWorkFlowUtil;
import com.chinaweal.aicorg.model.AICUser;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.BaseServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 监管共用审批意见表 服务实现类
 * </p>
 *
 * @author <a href="https://blog.lroyia.top">lroyia</a>
 * @since 2021-01-22
 */
@Service
public class TSOpinionServiceImpl extends BaseServiceImpl<TSOpinionMapper, TSOpinion> implements TSOpinionService {

    @Override
    public List<TSOpinion> selectByAuditingID(String auditingID) {
        return list(new LambdaQueryWrapper<TSOpinion>().eq(TSOpinion::getWorkflowid, auditingID).orderByAsc(TSOpinion::getLauptime));
    }

    @Override
    public TSOpinion createOpinion(String workflowId, String opinionType, AICUser handler, String opinion) {
        return HandleWorkFlowUtil.createOpinion(workflowId, opinionType, handler, opinion);
    }

    @Override
    public List<TSOpinion> getOpinionsWithOrg(String workflowId) {
        return baseMapper.selectOpinionWithOrg(workflowId);
    }
    @Override
    public TSOpinion getOpinionByOne(String workflowId) {
        return baseMapper.getOpinionByOne(workflowId);
    }

    @Override
    public TSOpinion getNewestOpinion(String workflowId, String opinionType) {
        LambdaQueryWrapper<TSOpinion> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TSOpinion::getWorkflowid,workflowId)
                .eq(TSOpinion::getOpiniontype,opinionType)
                .orderByDesc(TSOpinion::getLauptime).last("limit 1");
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<TSOpinion> queryByWorkflowId(String workflowId) {
        return baseMapper.queryByWorkflowId(workflowId);
    }

    @Override
    public List<TSOpinion> getRecoverList() {
        return baseMapper.getRecoverListInbiz();
    }

    @Override
    public List<TSOpinion> getRecoverListReturn() {
        return baseMapper.getRecoverListReturn();
    }

    @Override
    public List<TSOpinion> getRecoverListFinish() {
        return baseMapper.getRecoverListFinish();
    }

}
