package com.doumee.core.constants;
|
|
import lombok.AllArgsConstructor;
|
import lombok.Getter;
|
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.math.BigDecimal;
|
import java.net.InetAddress;
|
import java.net.UnknownHostException;
|
import java.util.*;
|
|
/**
|
* 框架级常量
|
* @author dm
|
* @since 2025/03/31 16:44
|
*/
|
public class Constants {
|
|
public static final String OSS ="OSS" ;
|
|
public static final String RESOURCE_PATH ="RESOURCE_PATH" ;
|
public static final String QYWX_CORPID = "QYWX_CORPID";
|
public static final String QYWX_SECRET = "QYWX_SECRET";
|
public static final String QYWX_TOKEN = "QYWX_TOKEN";
|
public static final String QYWX_AGENTID = "QYWX_AGENTID";
|
public static final String QYWX_JS_API_TICKET = "QYWX_JS_API_TICKET";
|
public static final String JUMP_OUT_URL = "JUMP_OUT_URL";
|
public static final String SYSTEM ="SYSTEM" ;
|
public static final String IMG_DIR = "IMG_DIR";
|
public static final String FILE_DIR ="FILE_DIR" ;
|
public static final String FOOT_IMGURL ="FOOT_IMGURL" ;
|
public static final String LINK_PHONE ="LINK_PHONE" ;
|
public static final String LINK_MOBILE ="LINK_MOBILE" ;
|
public static final String SERVER_TIME ="SERVER_TIME" ;
|
public static final String ADDRESS ="ADDRESS" ;
|
public static final String SOLVE_SCHEME ="SOLVE_SCHEME" ;
|
public static final String WISDOM_SYSTEM ="WISDOM_SYSTEM" ;
|
public static final String FOOT_WORDS ="FOOT_WORDS" ;
|
|
public static final String WX_CONFIG ="WX_CONFIG" ;
|
public static final String APPID ="APPID" ;
|
public static final String SECRET ="SECRET" ;
|
public static final String ACCESS_TOKEN ="ACCESS_TOKEN" ;
|
public static final String SERVER_INTRODUCE ="SERVER_INTRODUCE" ;
|
public static final String FEE_STANDARDS ="FEE_STANDARDS" ;
|
public static final String ABOUT_US ="ABOUT_US" ;
|
public static final String SERVER_PHONE ="SERVER_PHONE" ;
|
public static final String USER_AGREEMENT ="USER_AGREEMENT" ;
|
public static final String PRIVACY_AGREEMENT ="PRIVACY_AGREEMENT" ;
|
|
public static final String ACCESS_ID="ACCESS_ID";
|
public static final String BUCKETNAME = "BUCKETNAME";
|
|
public static final String ACCESS_KEY = "ACCESS_KEY";
|
public static final String ENDPOINT = "ENDPOINT";
|
|
public static final String QYWX = "QYWX";
|
public static final Integer ONE = 1;
|
public static final Integer TWO = 2;
|
public static final Integer ZERO = 0;
|
public static final Integer THREE = 3;
|
public static final Integer FOUR = 4;
|
public static final Integer SIX = 6;
|
public static final Integer FIVE = 5;
|
public static final String INENTITY_FILES = "INENTITY_FILES";
|
public static final String MEMBER_FILES = "MEMBER_FILES";
|
public static final String CATEGORY_FILES = "CATEGORY_FILES";
|
public static final String SHOP_FILES = "SHOP_FILES";
|
public static final String DRIVER_FILES = "DRIVER_FILES";
|
public static final String BANNER_FILES = "BANNER_FILES";
|
public static final String ORDERS_FILES = "ORDERS_FILES";
|
|
// 运营配置
|
public static final String OPERATION_CONFIG = "OPERATION_CONFIG";
|
public static final String OP_DRIVER_DAILY_CANCEL_LIMIT = "DRIVER_DAILY_CANCEL_LIMIT";
|
public static final String OP_UNPICKED_DISCOUNT = "UNPICKED_DISCOUNT";
|
public static final String OP_SETTLEMENT_DATE = "SETTLEMENT_DATE";
|
public static final String OP_URGENT_COEFFICIENT = "URGENT_COEFFICIENT";
|
public static final String OP_AUTO_CANCEL_TIME = "AUTO_CANCEL_TIME";
|
public static final String OP_INSURANCE_RATE = "INSURANCE_RATE";
|
public static final String OP_ORDER_ACCEPT_LIMIT = "ORDER_ACCEPT_LIMIT";
|
public static final String OP_AUTO_CONFIRM_RECEIPT = "AUTO_CONFIRM_RECEIPT";
|
public static boolean WORKORDER_SHE_EMAIL_SENDING = false;
|
public static boolean DEALING_COMPANY_SYNC = false ;
|
public static boolean DEALING_MEMBER_SYNC = false ;
|
public static final String WORKORDER_FILE_PATH ="WORKORDER_FILE_PATH" ;
|
public static final String WORKORDER_LOG_FILE_PATH ="WORKORDER_LOG_FILE_PATH" ;
|
|
public static final String REDIS_TOKEN_KEY = "token_";
|
public static final String REDIS_VERIFY_CODE_KEY = "verify_code_";
|
|
|
|
public final static String GOODS_ORDER_CREATE_LOCK = "goods:order:create:lock:";
|
|
// 订单日志操作类型
|
public static final int ORDER_LOG_DISPATCH = 1; // 派单
|
public static final int ORDER_LOG_URGENT_FEE = 2; // 加急费
|
public static final int ORDER_LOG_ASSIGN_DRIVER = 3; // 指派司机
|
public static final int ORDER_LOG_CANCEL = 4; // 取消订单
|
public static final int ORDER_LOG_CONFIRM_ARRIVE = 5; // 确认顾客到店
|
|
public static final String SUCCESS = "SUCCESS";
|
public static final String FAIL = "FAIL";
|
public static final String CANCELLED = "CANCELLED";
|
|
|
public interface uploadType{
|
String blob = "blob";
|
String ftp = "ftp";
|
}
|
|
/**
|
* 缓存Key
|
*/
|
interface CacheKey {
|
}
|
/**
|
* 操作类型,用于做接口验证分组
|
*/
|
public interface OperaType {
|
|
/**
|
* 创建
|
*/
|
interface Create {}
|
|
/**
|
* 修改
|
*/
|
interface Update {}
|
|
/**
|
* 修改状态
|
*/
|
interface UpdateStatus {}
|
}
|
|
|
public static boolean equalsInteger(Integer a, Integer b) {
|
if (formatIntegerNum(a) == formatIntegerNum(b)) {
|
return true;
|
}
|
return false;
|
}
|
|
public static int formatIntegerNum(Integer d) {
|
if (d == null) {
|
d = 0;
|
}
|
return d.intValue();
|
}
|
public static double getFormatMoney(Long d) {
|
BigDecimal r = new BigDecimal(formatLongNum(d));
|
r = r.divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
|
|
return r.doubleValue();
|
}
|
|
public static long formatLongNum(Long d) {
|
if (d == null) {
|
d = 0L;
|
}
|
return d.longValue();
|
}
|
public static BigDecimal formatBigDecimal(BigDecimal d) {
|
if (d == null) {
|
new BigDecimal(0);
|
}
|
return d;
|
}
|
|
/**
|
* Job常量
|
*/
|
public interface Job {
|
|
// jobId在JOB实例中的存储参数键
|
String JOB_DATA_MAP_JOB_ID = "JOB_ID";
|
|
/**
|
* JOB状态
|
*/
|
@Getter
|
@AllArgsConstructor
|
enum JobStatus {
|
PAUSE( -1, "暂停"),
|
READY( 0, "已准备"),
|
RUNNING( 1, "运行中"),
|
;
|
private int code;
|
private String remark;
|
}
|
|
/**
|
* 分片状态
|
*/
|
@Getter
|
@AllArgsConstructor
|
enum SnippetStatus {
|
READY((int) 0, "已准备"),
|
RUNNING((int) 1, "运行中"),
|
SUCCESS((int) 2, "执行成功"),
|
FAILED((int) -2, "执行失败"),
|
;
|
private int code;
|
private String remark;
|
}
|
|
/**
|
* 分片状态
|
*/
|
@Getter
|
@AllArgsConstructor
|
enum LogStatus {
|
FAILED((int) 0, "执行失败"),
|
SUCCESS((int) 1, "执行成功"),
|
IGNORE((int) 2, "跳过"),
|
NONE((int) -1, "执行中"),
|
;
|
private int code;
|
private String remark;
|
}
|
|
/**
|
* 触发类型
|
*/
|
@Getter
|
@AllArgsConstructor
|
enum TriggerType {
|
SYSTEM("SYSTEM", "系统"),
|
MANUAL("MANUAL", "手动"),
|
;
|
private String code;
|
private String remark;
|
}
|
}
|
|
/**
|
* 跟踪日志异常等级
|
*/
|
@Getter
|
@AllArgsConstructor
|
public enum ExceptionLevel {
|
DANGER((int)10, "高"),
|
WARN((int)5, "中"),
|
LOW((int)0, "低"),
|
;
|
|
private int level;
|
|
private String remark;
|
}
|
|
/**
|
* MyBatis自动注入忽略
|
*/
|
public interface Ignore {
|
/**
|
* 忽略时间,当不需要更新createTime/updateTime时,可使用该常量进行填充。
|
*/
|
Date IGNORE_TIME = new IgnoreDate();
|
|
/**
|
* 忽略用户,当不需要更新createUser/updateUser时,可使用该常量进行填充。
|
*/
|
Integer IGNORE_USER = -1;
|
|
/**
|
* 忽略时间类
|
*/
|
class IgnoreDate extends Date {}
|
}
|
|
|
|
public enum WorkOrderStatus{
|
waitConfirm( 0, "待分配WTS","{title}上报","","待分配WTS" ),
|
waitAllocation(1, "待分配任务","待分配任务","","待分配任务"),
|
waitDeal(2, "待处理","待处理","","待工程师处理"),
|
sheClose(3, "已解决","SHE已关闭","","SHE已关闭"),
|
wtsClose(4, "已解决","WTS已关闭","","WTS已关闭"),
|
close(5, "已解决","已解决","","工程师关闭"),
|
urge (6, "催促","","","")
|
;
|
|
private int status;
|
private String statusInfo;
|
private String statusName;
|
private String logTitle;
|
private String noticeContent;
|
|
// 构造方法
|
WorkOrderStatus(int status, String statusInfo,String logTitle,String noticeContent,String statusName ) {
|
this.status = status;
|
this.statusInfo = statusInfo;
|
this.logTitle = logTitle;
|
this.noticeContent = noticeContent;
|
this.statusName = statusName;
|
}
|
public static String getName(int index) {
|
for (WorkOrderStatus c : WorkOrderStatus.values()) {
|
if (c.getKey() == index) {
|
return c.statusInfo;
|
}
|
}
|
return null;
|
}
|
public static String getStatusName(int index) {
|
for (WorkOrderStatus c : WorkOrderStatus.values()) {
|
if (c.getKey() == index) {
|
return c.statusName;
|
}
|
}
|
return null;
|
}
|
|
public int getKey() {
|
return status;
|
}
|
|
public void setKey(int key) {
|
this.status = status;
|
}
|
|
public int getStatus() {
|
return status;
|
}
|
|
public void setStatus(int status) {
|
this.status = status;
|
}
|
|
public String getStatusName() {
|
return statusName;
|
}
|
|
public void setStatusName(String statusName) {
|
this.statusName = statusName;
|
}
|
|
public String getStatusInfo() {
|
return statusInfo;
|
}
|
|
public void setStatusInfo(String statusInfo) {
|
this.statusInfo = statusInfo;
|
}
|
|
public String getLogTitle() {
|
return logTitle;
|
}
|
|
public void setLogTitle(String logTitle) {
|
this.logTitle = logTitle;
|
}
|
|
public String getNoticeContent() {
|
return noticeContent;
|
}
|
|
public void setNoticeContent(String noticeContent) {
|
this.noticeContent = noticeContent;
|
}
|
}
|
|
|
/**
|
* 附件类型(对应 multifile.objType)
|
*/
|
@Getter
|
@AllArgsConstructor
|
public enum FileType {
|
OTHER_MATERIAL(0, "门店其他材料"),
|
STORE_INTERIOR(1, "门店内部照片"),
|
ORDER_DEPOSIT(2, "订单寄存图片"),
|
ORDER_TAKE(3, "门店入库图片"),
|
DRIVER_TAKE(4, "司机取件图片"),
|
DRIVER_DONE(5, "司机完成图片"),
|
DRIVER_CAR(6, "司机实名认证车辆照片"),
|
DRIVER_LICENSE(7, "司机实名认证驾驶证照片"),
|
DRIVER_OTHER(8, "司机实名认证其他图片"),
|
STORE_FRONT(9, "门店门头照"),
|
SOCIAL_SECURITY(10, "社保缴纳证明"),
|
LABOR_CONTRACT(11, "有效劳动合同"),
|
ORDER_FILE(12,"下单图片"),
|
STORE_OUT(13,"门店出库图片"),
|
REFUND_TAKE(14,"退款取件图片")
|
|
;
|
|
private final int key;
|
private final String name;
|
}
|
|
@Getter
|
@AllArgsConstructor
|
public enum OrderLogType {
|
urgent(0, "平台加急", "平台加急,奖励金 {param} 元。"),
|
dispatch(1, "平台指派", "平台指派司机 {param} 接单。")
|
;
|
private int status;
|
private String title;
|
private String statusInfo;
|
}
|
|
/**
|
* 订单支付类型
|
*/
|
@Getter
|
@AllArgsConstructor
|
public enum OrdersAttach {
|
STORAGE_ORDER("storageOrder", "寄存订单"),
|
SHOP_DEPOSIT("shopDeposit", "店铺押金订单"),
|
DRIVER_DEPOSIT("driverDeposit", "司机押金订单"),
|
OVERDUE_FEE("overdueFee", "订单逾期费用")
|
;
|
|
private final String key;
|
private final String name;
|
}
|
|
|
/**
|
* 订单状态(就地/异地统一)
|
* 就地寄存: 0→1→2→3→(6)→7 / 96~99
|
* 异地寄存: 0→1→2→3→4→5→(6)→7 / 96~99
|
*/
|
@Getter
|
@AllArgsConstructor
|
public enum OrderStatus {
|
waitPay(0, "待支付"),
|
waitDeposit(1, "待寄存"),
|
deposited(2, "已寄存"),
|
accepted(3, "已接单"),
|
delivering(4, "派送中"),
|
arrived(5, "已到店/已送达/待取件"),
|
overdue(6, "存在逾期"), //弃用
|
finished(7, "已完成"),
|
closed(96, "订单关闭(退款)"),
|
cancelOverdue(97, "取消逾期"), //弃用
|
cancelling(98, "取消中"),
|
cancelled(99, "已取消")
|
;
|
private final int status;
|
private final String desc;
|
|
public int getKey() { return status; }
|
public String getValue() { return desc; }
|
|
public static OrderStatus getByKey(int index) {
|
for (OrderStatus c : OrderStatus.values()) {
|
if (c.getKey() == index) {
|
return c;
|
}
|
}
|
return null;
|
}
|
|
public static String getDescByKey(int index) {
|
for (OrderStatus c : OrderStatus.values()) {
|
if (c.getKey() == index) {
|
return c.getValue();
|
}
|
}
|
return "";
|
}
|
}
|
|
/**
|
* 会员端合并订单状态(用于分页筛选)
|
*/
|
@Getter
|
@AllArgsConstructor
|
public enum OrderCombinedStatus {
|
waitPay(0, "待支付", new int[]{OrderStatus.waitPay.status}),
|
waitDeposit(1, "待核验", new int[]{OrderStatus.waitDeposit.status}),
|
waitDeliver(2, "待配送", new int[]{OrderStatus.accepted.status}),
|
waitReceive(3, "待收货", new int[]{ OrderStatus.delivering.status, OrderStatus.arrived.status}),
|
finished(4, "已完成", new int[]{OrderStatus.finished.status}),
|
refund(5, "退款", new int[]{OrderStatus.closed.status, OrderStatus.cancelling.status})
|
;
|
private final int key;
|
private final String desc;
|
private final int[] statuses;
|
|
public static OrderCombinedStatus getByKey(int key) {
|
for (OrderCombinedStatus c : OrderCombinedStatus.values()) {
|
if (c.getKey() == key) {
|
return c;
|
}
|
}
|
return null;
|
}
|
}
|
|
/**
|
* 得到request对象
|
*
|
* @return
|
*/
|
public static HttpServletRequest getRequest() {
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
return request;
|
}
|
|
|
public static String getIpAddr() {
|
HttpServletRequest request = Constants.getRequest();
|
String ipAddress = null;
|
try {
|
ipAddress = request.getHeader("x-forwarded-for");
|
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
ipAddress = request.getHeader("Proxy-Client-IP");
|
}
|
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
}
|
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
ipAddress = request.getRemoteAddr();
|
if (ipAddress.equals("127.0.0.1")) {
|
// 根据网卡取本机配置的IP
|
InetAddress inet = null;
|
try {
|
inet = InetAddress.getLocalHost();
|
} catch (UnknownHostException e) {
|
e.printStackTrace();
|
}
|
ipAddress = inet.getHostAddress();
|
}
|
}
|
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
|
if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length()
|
// = 15
|
if (ipAddress.indexOf(",") > 0) {
|
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
|
}
|
}
|
} catch (Exception e) {
|
ipAddress = "127.0.0.1";
|
}
|
// ipAddress = this.getRequest().getRemoteAddr();
|
|
return ipAddress;
|
}
|
|
|
/**
|
* 根据身份证号码获取性别
|
* @param idCard 身份证号码(15位或18位)
|
* @return 1-男,2-女,null-无法判断
|
*/
|
public static Integer getGenderByIdCard(String idCard) {
|
if (idCard == null || (idCard.length() != 15 && idCard.length() != 18)) {
|
return null;
|
}
|
// 15位身份证:最后一位为性别码;18位身份证:第17位(索引16)为性别码
|
int genderIndex = idCard.length() == 15 ? 14 : 16;
|
int genderCode = Character.getNumericValue(idCard.charAt(genderIndex));
|
return genderCode % 2 == 1 ? 1 : 2;
|
}
|
|
public static BigDecimal formatBigdecimal4Float(BigDecimal d) {
|
if (d == null) {
|
d = new BigDecimal(0.0);
|
}
|
//保留两位小数且四舍五入
|
d = d.setScale(4, BigDecimal.ROUND_HALF_UP);
|
return d;
|
}
|
|
/**
|
* 司机定级:5=S 4=A 3=B 2=C 1=D
|
*
|
* @param level 等级 1-5
|
* @return 等级文本
|
*/
|
public static String getDriverLevelName(Integer level) {
|
if (level == null) return null;
|
switch (level) {
|
case 5: return "S";
|
case 4: return "A";
|
case 3: return "B";
|
case 2: return "C";
|
case 1: return "D";
|
default: return null;
|
}
|
}
|
|
}
|