package cn.pluss.platform.row;

import cn.pluss.platform.entity.DeviceBsj;
import cn.pluss.platform.util.excel.ExcelImportUtil;
import cn.pluss.platform.util.excel.RowInfoGetter;
import cn.pluss.platform.util.excel.model.RowInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

/**
 * 导入数据的数据转换类
 *
 * @author DJH
 */
public class DeviceBsjRowGetter implements RowInfoGetter<DeviceBsj> {

    private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());

    @Override
    public DeviceBsj getEntity(RowInfo rowInfo, int lineNum) {
        Row row = rowInfo.sheet.getRow(rowInfo.startRow);

        DeviceBsj entity = new DeviceBsj();
        entity.setSim(ExcelImportUtil.readCell(row.getCell(0)).toString());
        entity.setIccid(ExcelImportUtil.readCell(row.getCell(1)).toString());

        String expireTimeString = ExcelImportUtil.readCell(row.getCell(4)).toString();
        try {
            entity.setSimExpireTime(dateFormat.parse(expireTimeString));
        } catch (ParseException ignored) {
        }


        return entity;
    }
}
