package com.lz.modules.flow.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.modules.flow.dao.FlowApprovalRoleMapper;
import com.lz.modules.flow.entity.EvaluationStartStaff;
import com.lz.modules.flow.entity.FlowApprovalRole;
import com.lz.modules.flow.service.FlowApprovalRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* <p>
* 流程审批表 服务类
* </p>
*
* @author quyixiao
* @since 2020-10-13
*/

@Service
public class FlowApprovalRoleServiceImpl extends ServiceImpl<FlowApprovalRoleMapper, FlowApprovalRole> implements FlowApprovalRoleService {


    @Autowired
	private FlowApprovalRoleMapper flowApprovalRoleMapper;

    static int maxInsertSQL = 100;


	@Override
	public FlowApprovalRole selectFlowApprovalRoleById(Long id){
		return flowApprovalRoleMapper.selectFlowApprovalRoleById(id);
	}



	@Override
	public Long insertFlowApprovalRole(FlowApprovalRole flowApprovalRole){
		return flowApprovalRoleMapper.insertFlowApprovalRole(flowApprovalRole);
	}



	@Override
	public int updateFlowApprovalRoleById(FlowApprovalRole flowApprovalRole){
		return flowApprovalRoleMapper.updateFlowApprovalRoleById(flowApprovalRole);
	}



	@Override
	public int updateCoverFlowApprovalRoleById(FlowApprovalRole flowApprovalRole){
		return flowApprovalRoleMapper.updateCoverFlowApprovalRoleById(flowApprovalRole);
	}



	@Override
	public int deleteFlowApprovalRoleById(Long id){
		return flowApprovalRoleMapper.deleteFlowApprovalRoleById(id);
	}
	@Override
	public Long insertFlowApprovalRoles(List<FlowApprovalRole> flowApprovalRoles){
		if(flowApprovalRoles.size() <= maxInsertSQL){
			return flowApprovalRoleMapper.insertFlowApprovalRoles(flowApprovalRoles);
		}
		//下面防止sql语句过大
		Long count = Long.parseLong("0");
		int insert = 0;
		List<FlowApprovalRole> approvalRoles = new ArrayList<>();
		for (FlowApprovalRole role:flowApprovalRoles
		) {
			approvalRoles.add(role);
			insert++;
			if(insert >= maxInsertSQL){
				count += flowApprovalRoleMapper.insertFlowApprovalRoles(approvalRoles);
				approvalRoles.clear();
				insert = 0;
			}

		}
		if(approvalRoles.size() > 0){
			count += flowApprovalRoleMapper.insertFlowApprovalRoles(approvalRoles);
		}
		return count;

	}

    @Override
    public List<FlowApprovalRole> selectFlowApprovalRoleList(List<Long> flowIds) {

		return flowApprovalRoleMapper.selectFlowApprovalRoleList(flowIds);

    }


}
