parent
6d9e1c4b25
commit
7a49d79707
@ -0,0 +1,16 @@ |
|||||||
|
package com.unionmed.framework.authentication.annotation; |
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.Mapping; |
||||||
|
|
||||||
|
import java.lang.annotation.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ianChen |
||||||
|
* @date 2023/5/9 11:28 |
||||||
|
*/ |
||||||
|
@Mapping |
||||||
|
@Documented |
||||||
|
@Target({ElementType.TYPE, ElementType.METHOD}) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
public @interface Auth { |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
package com.unionmed.framework.spring.mvc.dto; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.util.Collection; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ianChen |
||||||
|
* @date 2023/5/4 16:28 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class PageData<E> { |
||||||
|
|
||||||
|
private int number; |
||||||
|
private Collection<E> member; |
||||||
|
|
||||||
|
public static <E> PageData inst(Collection<E> collection) { |
||||||
|
PageData data = new PageData(); |
||||||
|
data.number = collection == null ? 0 : collection.size(); |
||||||
|
data.member = collection; |
||||||
|
return data; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
package com.unionmed.framework.spring.mvc.dto; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
@ApiModel |
||||||
|
public class Paging { |
||||||
|
|
||||||
|
//分页数
|
||||||
|
@ApiModelProperty(value = "分页数") |
||||||
|
private int page; |
||||||
|
|
||||||
|
//每页展示数
|
||||||
|
@ApiModelProperty(value = "每页展示数") |
||||||
|
private int rows; |
||||||
|
|
||||||
|
|
||||||
|
public int getPage() { |
||||||
|
return Math.max(page, 1); |
||||||
|
} |
||||||
|
|
||||||
|
public int getRows() { |
||||||
|
return rows < 1 ? 10 : rows; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,117 @@ |
|||||||
|
package com.unionmed.framework.util; |
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
import java.text.DecimalFormat; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author ianChen |
||||||
|
* @date 2023/3/14 14:33 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
public class CashConverter { |
||||||
|
|
||||||
|
private static String REGEX = "^\\d+\\.\\d{1,}|\\d+"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 将字符串转为现金值,单位:分 |
||||||
|
* |
||||||
|
* @param cash 转换的字符串 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static int toInt(String cash) { |
||||||
|
return Converter.toInt(toNum(cash)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将字符串转为现金值,单位:分 |
||||||
|
* |
||||||
|
* @param cash 转换的字符串 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static long toLong(String cash) { |
||||||
|
return Converter.toLong(toNum(cash)); |
||||||
|
} |
||||||
|
|
||||||
|
//金额四舍五入 单位里
|
||||||
|
public static int amountRound(int amount) { |
||||||
|
DecimalFormat decimalFormat = new DecimalFormat("#.0"); |
||||||
|
return (int) Math.round(Double.valueOf(decimalFormat.format(Integer.valueOf(amount).doubleValue() / 10))) * 10; |
||||||
|
} |
||||||
|
|
||||||
|
protected static String toNum(String cash) { |
||||||
|
if (!isMatchRegex(REGEX, cash)) { |
||||||
|
log.warn("转换 [" + cash + "] 失败,不是合法的数字"); |
||||||
|
return "0"; |
||||||
|
} |
||||||
|
|
||||||
|
String[] splits = cash.split("\\."); |
||||||
|
if (splits.length == 1) |
||||||
|
return splits[0] + "00"; |
||||||
|
|
||||||
|
if (splits[1].length() > 2) |
||||||
|
splits[1] = splits[1].substring(0, 2); |
||||||
|
|
||||||
|
return splits[0] + (splits[1].length() == 1 ? splits[1] + "0" : splits[1]); |
||||||
|
} |
||||||
|
|
||||||
|
private static boolean isMatchRegex(String regex, String s) { |
||||||
|
return !ObjectUtils.isNull(regex) && !ObjectUtils.isNull(s) && Pattern.compile(regex).matcher(s).matches(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将整数金额转换字符串,单位:元 |
||||||
|
* |
||||||
|
* @param cash 转换的金额 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String toString(int cash) { |
||||||
|
return toString(cash + ""); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将整数金额转换(负数)字符串,单位:元 |
||||||
|
* |
||||||
|
* @param cash 转换的金额 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String toNegativeString(int cash) { |
||||||
|
return toString((cash > 0 ? -cash : cash) + ""); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将整数金额转换字符串,单位:元 |
||||||
|
* |
||||||
|
* @param cash 转换的金额 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String toString(long cash) { |
||||||
|
return toString(cash + ""); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将整数金额转换(负数)字符串,单位:元 |
||||||
|
* |
||||||
|
* @param cash 转换的金额 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String toNegativeString(long cash) { |
||||||
|
return toString((cash > 0 ? -cash : cash) + ""); |
||||||
|
} |
||||||
|
|
||||||
|
protected static String toString(String cash) { |
||||||
|
String str = cash + "", preffix = ""; |
||||||
|
if (cash.startsWith("-")) { |
||||||
|
str = str.substring(1); |
||||||
|
preffix = "-"; |
||||||
|
} |
||||||
|
|
||||||
|
if (str.length() == 1) |
||||||
|
return preffix + "0.0" + str; |
||||||
|
if (str.length() == 2) |
||||||
|
return preffix + "0." + str; |
||||||
|
|
||||||
|
return preffix + str.substring(0, str.length() - 2) + "." + str.substring(str.length() - 2); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue