package com.yami.trading.bean.syspara.domain; import com.aliyuncs.utils.StringUtils; import com.baomidou.mybatisplus.annotation.TableName; import com.yami.trading.common.domain.BaseEntity; import com.yami.trading.common.domain.UUIDEntity; import lombok.Data; import lombok.EqualsAndHashCode; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; /** * 配置参数Entity * @author lucas * @version 2023-03-17 */ @Data @EqualsAndHashCode(callSuper = false) @TableName("t_syspara") public class Syspara extends UUIDEntity { private static final long serialVersionUID = 1L; /** * CODE */ private String code; /** * PARTY_ID */ private String partyId; /** * Ssvalue */ private String svalue; /** * SORDER */ private Long sorder; /** * STYPE */ private Long stype; /** * NOTES */ private String notes; /** * 0/可修改;1/不可修改; */ private Long modify; /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常 *

* * @return */ public Integer getInteger() { if (StringUtils.isEmpty(svalue)) { return null; } try { return Integer.parseInt(svalue); } catch (Exception ex) { return null; } } /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常 *

* * @return */ public Long getLong() { if (StringUtils.isEmpty(svalue)) { return null; } try { return Long.parseLong(svalue); } catch (Exception ex) { return null; } } /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常 *

* * @return */ public Double getDouble() { if (StringUtils.isEmpty(svalue)) { return null; } try { return Double.parseDouble(svalue); } catch (Exception ex) { return null; } } /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常 *

* * @return */ public Float getFloat() { if (StringUtils.isEmpty(svalue)) { return null; } try { return Float.parseFloat(svalue); } catch (Exception ex) { return null; } } /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常 *

* * @return */ public BigDecimal getBigDecimal() { if (StringUtils.isEmpty(svalue)) { return null; } try { return new BigDecimal(svalue); } catch (Exception ex) { return null; } } /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常
* 3.默认格式:yyyy-MM-dd *

* * @return "yyyy-MM-dd" * @throws ParseException */ public Date getDate() { return getDate("yyyy-MM-dd"); } /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常
* 3.按传入的日期格式,将svalue转化成date *

* * @param date * @return * @throws ParseException */ public Date getDate(String pattern) { if (StringUtils.isEmpty(svalue)) { return null; } try { return (new SimpleDateFormat(pattern)).parse(svalue); } catch (Exception ex) { return null; } } /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常
* 3.按指定的enum的类型转化 *

* * @param str * @return * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") public Enum getEnum(String enumType) { try { return getEnum(Class.forName(enumType).asSubclass(Enum.class)); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException(ex); } } /** *

* Description: 1.空值或者空字串返回null
* 2.如果转换失败,直接抛异常
* 3.按指定的enum的类型转化 *

* * @param enumType * @return */ public > T getEnum(Class enumType) { if (StringUtils.isEmpty(svalue)) { return null; } return T.valueOf(enumType, svalue); } /** * *

* Description: 获取boolean值,会将参数值转化为boolean值 *

* * @return true or false */ public boolean getBoolean() { if ("Y".equalsIgnoreCase(svalue) || "true".equalsIgnoreCase(svalue) || "1".equals(svalue)) { return true; } else { return false; } } }