package cn.report.excel.easyexcel.custom;

import cn.report.excel.easyexcel.api.converters.Converter;
import cn.report.excel.easyexcel.api.enums.CellDataTypeEnum;
import cn.report.excel.easyexcel.api.metadata.GlobalConfiguration;
import cn.report.excel.easyexcel.api.metadata.data.ReadCellData;
import cn.report.excel.easyexcel.api.metadata.data.WriteCellData;
import cn.report.excel.easyexcel.api.metadata.property.ExcelContentProperty;
/**
 * 加载类型转换器
  .registerConverter(new SexConverter())
*/
public class SamSexConverter implements Converter<Integer>
{
	@Override
	public Class<Integer> supportJavaTypeKey() {
		return Integer.class;
	}

	@Override
	public CellDataTypeEnum supportExcelTypeKey() {
		return CellDataTypeEnum.STRING;
	}
	 /**数据库中为1、0*/
	public Integer convertToJavaData(ReadCellData<?> cellData, 
			ExcelContentProperty contentProperty, 
			GlobalConfiguration globalConfiguration) throws Exception {
		return "男".equals(cellData.getStringValue()) ? 1 : 0;
	}
	
    /**Excel中为男女*/
	@Override
	public WriteCellData<?> convertToExcelData(Integer value,
			ExcelContentProperty contentProperty, 
			GlobalConfiguration globalConfiguration) throws Exception {
		  // RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
           //String s = redisUtils.get("WYM" + code);
		return new WriteCellData<>(value.equals(1) ? "男" : "女");
	}
}

