package com.hzs.system.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.EOrderPrefix;
import com.hzs.common.domain.system.sys.SysApprovalBusiness;
import com.hzs.common.domain.system.sys.ext.SysApprovalBusinessExt;
import com.hzs.system.index.param.CompleteApprovalParam;
import com.hzs.system.sys.mapper.SysApprovalBusinessMapper;
import com.hzs.system.sys.param.ApprovalQueryParam;
import com.hzs.system.sys.service.ISysApprovalBusinessService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 审批业务表 服务实现类
 *
 * @author hzs
 * @since 2022-09-21
 */
@Service
public class SysApprovalBusinessServiceImpl extends ServiceImpl<SysApprovalBusinessMapper, SysApprovalBusiness> implements ISysApprovalBusinessService {

    @Override
    public int checkBusinessExist(List<Integer> approvalBusinessList, List<String> businessCodeList, Integer pkCountry) {
        return baseMapper.checkBusinessExist(approvalBusinessList, businessCodeList, pkCountry);
    }

    @Override
    public List<SysApprovalBusinessExt> queryBusinessAndDetail(Integer approvalBusiness, List<String> businessCodeList, Integer pkCountry) {
        return baseMapper.queryBusinessAndDetail(approvalBusiness, businessCodeList, pkCountry);
    }


    @Override
    public SysApprovalBusinessExt queryByApprovalCode(String approvalCode) {
        return baseMapper.queryByApprovalCode(approvalCode);
    }

    @Override
    public List<SysApprovalBusiness> queryApprovalList(ApprovalQueryParam param, Long userId, Integer pkCountry) {
        return baseMapper.queryApprovalList(param, userId, pkCountry);
    }

    @Override
    public int waitApprovalNum(Long userId, Integer pkCountry) {
        return baseMapper.waitApprovalNum(userId, pkCountry);
    }

    @Override
    public List<SysApprovalBusinessExt> waitApproval(Long userId, Integer pkCountry) {
        return baseMapper.waitApproval(userId, pkCountry);
    }

    @Override
    public List<SysApprovalBusinessExt> completeApproval(CompleteApprovalParam param, Long userId, Integer pkCountry) {
        return baseMapper.completeApproval(param, userId, pkCountry);
    }

    @Override
    public String queryLastCode() {
        String code = baseMapper.queryLastCode();
        if (null == code) {
            code = EOrderPrefix.APPROVAL_CODE.getValue() + "00000100";
        } else {
            code = EOrderPrefix.APPROVAL_CODE.getValue() + String.format("%08d", (Integer.parseInt(code.replaceAll(EOrderPrefix.APPROVAL_CODE.getValue(), "")) + 1));
        }
        return code;
    }

}
