package cn.com.ty.lift.ud.dataBank.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.ty.lift.ud.dataBank.controller.query.LiftFileQuery;
import cn.com.ty.lift.ud.dataBank.mapper.LiftBrandMapper;
import cn.com.ty.lift.ud.dataBank.mapper.LiftFileMapper;
import cn.com.ty.lift.ud.dataBank.mapper.entity.LiftBrandEntity;
import cn.com.ty.lift.ud.dataBank.mapper.entity.LiftFaultCodeEntity;
import cn.com.ty.lift.ud.dataBank.mapper.entity.LiftFileEntity;
import cn.com.ty.lift.ud.dataBank.service.ILiftFileService;

/**
 * 资料库文件 -ServiceImpl
 *
 * @author Xson
 * @date 2020-04-23
 */
@Service
@Transactional
public class LiftFileServiceImpl extends ServiceImpl<LiftFileMapper, LiftFileEntity> implements ILiftFileService {

    @Autowired
    private LiftFileMapper liftFileMapper;
    @Autowired
    private LiftBrandMapper liftBrandMapper;

    @Override
    public List<LiftFileEntity> getListByDataIdAndDataTable(Long dataId, Integer type) {
        return liftFileMapper.getListByDataIdAndDataTable(dataId, type);
    }

    @Override
    public void updateByIds(List<Long> ids, Integer status) {
        for (Long id : ids) {
            LiftFileEntity bit = new LiftFileEntity();
            bit.setId(id);
            bit.setStatuz(status);
            liftFileMapper.updateById(bit);
        }
    }

    @Override
    public IPage<LiftFileEntity> selectByExample(LiftFileQuery query) {
        IPage page = query.page();
        List<LiftFileEntity> list = liftFileMapper.selectByQuery(query.condition(), query);
        for (LiftFileEntity le : list) {
            LiftBrandEntity selectById = liftBrandMapper.selectById(le.getBrandId());
            if (selectById != null) {
                le.setBrandName(selectById.getName());
            }
        }
        int total = liftFileMapper.countByQuery(query.condition());
        page.setRecords(list);
        page.setTotal(total);
        return page;
    }

}
