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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.modules.app.dto.ApprovalDto;
import com.lz.modules.flow.dao.FlowChangeMapper;
import com.lz.modules.flow.entity.FlowChange;
import com.lz.modules.flow.entity.FlowRecord;
import com.lz.modules.flow.service.FlowChangeService;
import com.lz.modules.sys.entity.app.ResultRecord;
import com.lz.modules.sys.service.app.ResultRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* <p>
* 变动记录表 服务类
* </p>
*
* @author quyixiao
* @since 2020-10-13
*/

@Service
public class FlowChangeServiceImpl extends ServiceImpl<FlowChangeMapper, FlowChange> implements FlowChangeService {


    @Autowired
	private FlowChangeMapper flowChangeMapper;


    @Autowired
	private ResultRecordService resultRecordService;


	@Override
	public FlowChange selectFlowChangeById(Long id){
		return flowChangeMapper.selectFlowChangeById(id);
	}



	@Override
	public Long insertFlowChange(FlowChange flowChange){
		return flowChangeMapper.insertFlowChange(flowChange);
	}



	@Override
	public int updateFlowChangeById(FlowChange flowChange){
		return flowChangeMapper.updateFlowChangeById(flowChange);
	}



	@Override
	public int updateCoverFlowChangeById(FlowChange flowChange){
		return flowChangeMapper.updateCoverFlowChangeById(flowChange);
	}



	@Override
	public int deleteFlowChangeById(Long id){
		return flowChangeMapper.deleteFlowChangeById(id);
	}

    @Override
    public void saveChange(ApprovalDto approvalDto, FlowRecord flowRecord, int type) {
		FlowChange flowChange = new FlowChange();
		flowChange.setApprovalId(flowRecord.getApprovalStaffId());
		flowChange.setToApprovalId(approvalDto.getTransferStaffId());
		flowChange.setOptId(approvalDto.getLoginUserId());
		flowChange.setFlowRecordId(flowRecord.getId());
		flowChange.setRecordId(flowRecord.getRecordId());
		ResultRecord resultRecord = resultRecordService.selectResultRecordById(flowRecord.getRecordId());
		flowChange.setStaffId(resultRecord.getStaffId());
		flowChange.setType(type);
		flowChangeMapper.insertFlowChange(flowChange);
	}

	@Override
	public FlowChange selectFlowChangeByRecordIdAndToIdAndType(Long recordId, Long toStaffId, int type){
		return flowChangeMapper.selectFlowChangeByRecordIdAndToIdAndType(recordId, toStaffId, type);
	}

	@Override
	public FlowChange selectFlowChangeByFlowRecordIdAndType(Long flowRecordId, int type){
		return flowChangeMapper.selectFlowChangeByFlowRecordIdAndType(flowRecordId, type);
	}


}
