今日份代码如下:

/**
 * 
 * @Author: SXD
 * @Description:
 * @Date: create in 2019/9/20 15:39
 */
public class ProSkuSearchRecordRedisData {

    private String  recordId;

    private String skuSearchData;

    private Date exportDate;

    private String exportUrl;

    private String errorMsg;

    private Double score;

    private Integer status;//异步导出状态   【1 可导出】【0后台未处理】【-1后台处理失败】

    public static ProSkuSearchRecordRedisData init(String recordId,String skuSearchData){
        ProSkuSearchRecordRedisData redisData = new ProSkuSearchRecordRedisData();
        redisData.setRecordId(recordId);            //格式yyyyMMddXXXXXXXXXX
        redisData.setSkuSearchData(skuSearchData);
        redisData.setExportDate(new Date());
        redisData.setScore(Double.parseDouble(recordId.substring(0, 8)));   //权重为Double.parseDouble(yyyyMMdd))
        redisData.setStatus(ProExprotRecordStatusEnum.STATUS_WAIT.getValue());

        return redisData;
    }

    /**
     * 获取 对象的 属性名+属性值
     * @param redisData
     * @return
     */
    public static Map<String,String> getReflexRecord(ProSkuSearchRecordRedisData redisData){
        Map<String,String> map = new HashMap<>();

        Class<? extends ProSkuSearchRecordRedisData> aClass = redisData.getClass();
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            declaredField.setAccessible(true);
            String fieldName = declaredField.getName();
            Object fieldValue = null;
            try {
                fieldValue = declaredField.get(redisData);
                if (fieldValue instanceof Date){
                    Date date = (Date)fieldValue;
                    fieldValue = getDateStr(date);
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

            map.put(fieldName,String.valueOf(fieldValue));
        }

        return map;
    }

    /**
     * 时间转成字符串
     * @param date
     * @return
     */
    private  static String getDateStr(Date date){
        LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return localDateTime.format(format);
    }


    /**
     * 字符串转时间
     * @param dateStr
     * @return
     */
    private static Date getDateByStr(String dateStr){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.parse(dateStr, formatter);
        ZoneId zone = ZoneId.systemDefault();
        Instant instant = localDateTime.atZone(zone).toInstant();
        return Date.from(instant);
    }

    /**
     * 设置 对象的 属性名+属性值
     * @param map
     * @return
     */
    public  static ProSkuSearchRecordRedisData setReflexRecord(Map<String,String> map){
        ProSkuSearchRecordRedisData obj = new ProSkuSearchRecordRedisData();
        Set<String> fieldSet = map.keySet();
        Class<? extends ProSkuSearchRecordRedisData> aClass = obj.getClass();
        for (String field : fieldSet) {
            try {
                Field declaredField = aClass.getDeclaredField(field);
                declaredField.setAccessible(true);
                Type genericType = declaredField.getGenericType();
                if (genericType.getTypeName().contains("String")){
                    declaredField.set(obj,map.get(field));
                }
                if (genericType.getTypeName().contains("Double")){
                    declaredField.set(obj,Double.parseDouble(map.get(field)));
                }
                if (genericType.getTypeName().contains("Integer")){
                    declaredField.set(obj,Integer.parseInt(map.get(field)));
                }
                if (genericType.getTypeName().contains("Date")){
                    Date value = getDateByStr(map.get(field));
                    declaredField.set(obj,value);
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return obj;
    }









    public String getRecordId() {
        return recordId;
    }

    public void setRecordId(String recordId) {
        this.recordId = recordId;
    }

    public String getSkuSearchData() {
        return skuSearchData;
    }

    public void setSkuSearchData(String skuSearchData) {
        this.skuSearchData = skuSearchData;
    }

    public Date getExportDate() {
        return exportDate;
    }

    public void setExportDate(Date exportDate) {
        this.exportDate = exportDate;
    }

    public String getExportUrl() {
        return exportUrl;
    }

    public void setExportUrl(String exportUrl) {
        this.exportUrl = exportUrl;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Double getScore() {
        return score;
    }

    public void setScore(Double score) {
        this.score = score;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
}