package com.mvc.service.copy;

import com.mvc.dao.TChkrptDetailMapper;
import com.mvc.entity.TChkrptDetail;
import com.mvc.entity.TChkrptDetailExample;
import com.mvc.model.TChkrptDetailModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@Transactional
public class TChkrptDetailService {
    @Autowired
    private TChkrptDetailMapper tChkrptDetailMapper;

    public TChkrptDetailModel updateTChkrpt(TChkrptDetailModel model) {
        TChkrptDetail tChkrptDetail = tChkrptDetailMapper.selectByPrimaryKey(model.getId());
        BeanUtils.copyProperties(model,tChkrptDetail);
        int i = tChkrptDetailMapper.updateByPrimaryKey(tChkrptDetail);
        return model;
    }

    /**
     * 根据deviceSn查询报告明细中包含该设备的主表ID List(ChkrptId)
     * @param deviceSn
     * @return
     */
    public List<String> findChkrptIdsByDeviceSn(String deviceSn){
        List<String> resList=new ArrayList<>();
        if(StringUtils.isNotEmpty(deviceSn)){
            TChkrptDetailExample example=new TChkrptDetailExample();
            TChkrptDetailExample.Criteria criteria=example.createCriteria();
            criteria.andDeviceSnEqualTo(deviceSn);
            List<TChkrptDetail> tChkrptDetails = tChkrptDetailMapper.selectByExample(example);

            for(TChkrptDetail detail:tChkrptDetails){
                resList.add(detail.getChkrptId());
            }
        }
        return resList;
    }
}
