package org.springblade.business.service.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.business.entity.MileagePart;
import org.springblade.business.mapper.MileagePartMapper;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangyj
 */
@Service
public class MileagePartService extends BaseServiceImpl<MileagePartMapper, MileagePart>{



    public void updatePart(String projectId ,String partNo ,String newPartNo){
        baseMapper.updateByProjectIdAndPrefix(projectId,partNo,newPartNo);
    }


    public MileagePart getMileagePart(String projectId, String partNo){
          MileagePart part = new MileagePart();
          part.setPrefix(partNo);
          part.setProjectId(projectId);
          List<MileagePart> data= this.list(Wrappers.query(part));
          if(CollectionUtil.isNotEmpty(data)){
              return data.get(0);
          }
          return null;
    }

    public MileagePart getMileagePart(String projectId, String partNo ,String contractId){
        MileagePart query = new MileagePart();
        if(StringUtil.isNotBlank(partNo)){
            query.setContractId(contractId);
            query.setPrefix(partNo);
        }else {
            query.setProjectId(projectId);
        }
        List<MileagePart> parts =  this.list(Wrappers.query(query));
        if(CollectionUtil.isNotEmpty(parts)){
            return  parts.get(0);
        }
        return null;
    }




}
