[*] 每日优化

This commit is contained in:
acgist
2023-05-10 16:09:55 +08:00
parent 609acbd2eb
commit d8130f9d6e
24 changed files with 546 additions and 548 deletions

View File

@@ -4,4 +4,4 @@
media/deps
local.properties
local.properties

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
</manifest>

View File

@@ -7,7 +7,7 @@ import java.io.Serializable;
*
* @author acgist
*/
public class Header implements Serializable {
public class Header implements Cloneable, Serializable {
private static final long serialVersionUID = 1L;
@@ -24,20 +24,20 @@ public class Header implements Serializable {
*/
private String signal;
@Override
public Header clone() {
return new Header(this.v, this.id, this.signal);
}
public Header() {
}
public Header(String v, Long id, String signal) {
this.v = v;
this.id = id;
this.v = v;
this.id = id;
this.signal = signal;
}
@Override
public Header clone() {
return new Header(this.v, this.id, this.signal);
}
public String getV() {
return this.v;
}

View File

@@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
/**
* 消息
* 接口、信令、媒体信令通用消息模型
@@ -40,31 +39,22 @@ public class Message implements Cloneable, Serializable {
* 消息主体
*/
private Object body;
/**
* @param messageCode 状态编码
*/
public void setCode(MessageCode messageCode) {
this.setCode(messageCode, null);
public Message() {
}
/**
* @param messageCode 状态编码
* @param message 状态描述
*
* @return this
*/
public Message setCode(MessageCode messageCode, String message) {
this.code = messageCode.getCode();
this.message = StringUtils.isEmpty(message) ? messageCode.getMessage() : message;
return this;
public Message(String code, String message, Header header, Object body) {
this.code = code;
this.message = message;
this.header = header;
this.body = body;
}
/**
* @return 成功消息
*/
public static final Message success() {
return success(null);
return Message.success(null);
}
/**
@@ -83,7 +73,7 @@ public class Message implements Cloneable, Serializable {
* @return 失败消息
*/
public static final Message fail() {
return fail(null, null, null);
return Message.fail(null, null, null);
}
/**
@@ -92,7 +82,7 @@ public class Message implements Cloneable, Serializable {
* @return 失败消息
*/
public static final Message fail(MessageCode messageCode) {
return fail(messageCode, null, null);
return Message.fail(messageCode, null, null);
}
/**
@@ -102,15 +92,16 @@ public class Message implements Cloneable, Serializable {
* @return 失败消息
*/
public static final Message fail(MessageCode messageCode, Object body) {
return fail(messageCode, null, body);
return Message.fail(messageCode, null, body);
}
/**
* @param message 状态描述
*
* @return 失败消息
*/
public static final Message fail(String message) {
return fail(null, message, null);
return Message.fail(null, message, null);
}
/**
@@ -120,7 +111,7 @@ public class Message implements Cloneable, Serializable {
* @return 失败消息
*/
public static final Message fail(String message, Object body) {
return fail(null, message, body);
return Message.fail(null, message, body);
}
/**
@@ -130,7 +121,7 @@ public class Message implements Cloneable, Serializable {
* @return 失败消息
*/
public static final Message fail(MessageCode messageCode, String message) {
return fail(messageCode, message, null);
return Message.fail(messageCode, message, null);
}
/**
@@ -152,6 +143,25 @@ public class Message implements Cloneable, Serializable {
return new Message(this.code, this.message, this.header.clone(), this.body);
}
/**
* @param messageCode 状态编码
*/
public void setCode(MessageCode messageCode) {
this.setCode(messageCode, null);
}
/**
* @param messageCode 状态编码
* @param message 状态描述
*
* @return this
*/
public Message setCode(MessageCode messageCode, String message) {
this.code = messageCode.getCode();
this.message = StringUtils.isEmpty(message) ? messageCode.getMessage() : message;
return this;
}
/**
* 克隆消息排除消息主体
*
@@ -162,31 +172,24 @@ public class Message implements Cloneable, Serializable {
}
/**
* @return Map消息主体
* @return 消息主体
*/
public <T> T body() {
return (T) this.body;
}
/**
* @return 是否成功
*/
public boolean isSuccess() {
return CODE_0000.equals(this.code);
}
@Override
public String toString() {
return JSONUtils.toJSON(this);
}
public Message() {
}
public Message(String code, String message, Header header, Object body) {
this.code = code;
this.message = message;
this.header = header;
this.body = body;
}
public boolean isSuccess() {
return CODE_0000.equals(this.code);
}
public String getCode() {
return this.code;
}

View File

@@ -2,7 +2,7 @@ package com.acgist.taoyao.boot.model;
/**
* 状态编码
* <p>
*
* 1xxx = 前置错误
* 2xxx = 内部错误
* 3xxx = 请求错误
@@ -38,7 +38,7 @@ public enum MessageCode {
CODE_9999("9999", 500, "未知错误");
/**
* HTTP状态编码前缀
* HTTP Status前缀
*/
private static final String HTTP_STATUS = "3";
@@ -47,7 +47,7 @@ public enum MessageCode {
*/
private final String code;
/**
* 状态数值
* 状态数值HTTP Status
*/
private final Integer status;
/**
@@ -56,18 +56,19 @@ public enum MessageCode {
private final String message;
private MessageCode(String code, Integer status, String message) {
this.code = code;
this.status = status;
this.code = code;
this.status = status;
this.message = message;
}
/**
* @param code 状态编码
*
* @return 状态编码
*/
public static final MessageCode of(String code) {
final MessageCode[] values = MessageCode.values();
for (MessageCode value : values) {
for (final MessageCode value : values) {
if (value.code.equals(code)) {
return value;
}
@@ -77,10 +78,11 @@ public enum MessageCode {
/**
* @param status HTTP Status
*
* @return 状态编码
*/
public static final MessageCode of(Integer status) {
return of(HTTP_STATUS + status);
return MessageCode.of(HTTP_STATUS + status);
}
public String getCode() {

View File

@@ -1,5 +1,7 @@
package com.acgist.taoyao.boot.utils;
import android.util.Log;
import java.io.Closeable;
/**
@@ -23,7 +25,7 @@ public final class CloseableUtils {
closeable.close();
}
} catch (Exception e) {
// TODO日志
Log.e(CloseableUtils.class.getSimpleName(), "关闭资源异常", e);
}
}
@@ -38,7 +40,7 @@ public final class CloseableUtils {
closeable.close();
}
} catch (Exception e) {
// TODO日志
Log.e(CloseableUtils.class.getSimpleName(), "关闭资源异常", e);
}
}

View File

@@ -15,15 +15,12 @@ import java.util.Objects;
*/
public final class DateUtils {
private DateUtils() {
}
/**
* 日期
*
* @author acgist
*/
public static enum DateStyle {
public enum DateStyle {
YYMMDD("yyMMdd"),
YYYYMMDD("yyyyMMdd"),
@@ -51,6 +48,7 @@ public final class DateUtils {
public DateTimeFormatter getDateTimeFormatter() {
return this.dateTimeFormatter;
}
}
/**
@@ -58,7 +56,7 @@ public final class DateUtils {
*
* @author acgist
*/
public static enum TimeStyle {
public enum TimeStyle {
HH24("HH"),
HH24MM("HHmm"),
@@ -97,17 +95,8 @@ public final class DateUtils {
*
* @author acgist
*/
public static enum DateTimeStyle {
public enum DateTimeStyle {
// YYYY
YYYYMMDD_HH24_MM("yyyyMMdd HH:mm"),
YYYY_MM_DD_HH24_MM("yyyy-MM-dd HH:mm"),
YYYYMMDDHH24MMSS("yyyyMMddHHmmss"),
YYYYMMDDHH24MMSSSSS("yyyyMMddHHmmssSSS"),
YYYYMMDD_HH24_MM_SS("yyyyMMdd HH:mm:ss"),
YYYYMMDD_HH24_MM_SS_SSS("yyyyMMdd HH:mm:ss.SSS"),
YYYY_MM_DD_HH24_MM_SS("yyyy-MM-dd HH:mm:ss"),
YYYY_MM_DD_HH24_MM_SS_SSS("yyyy-MM-dd HH:mm:ss.SSS"),
// YY
YYMMDD_HH24_MM("yyMMdd HH:mm"),
YY_MM_DD_HH24_MM("yy-MM-dd HH:mm"),
@@ -117,6 +106,15 @@ public final class DateUtils {
YYMMDD_HH24_MM_SS_SSS("yyMMdd HH:mm:ss.SSS"),
YY_MM_DD_HH24_MM_SS("yy-MM-dd HH:mm:ss"),
YY_MM_DD_HH24_MM_SS_SSS("yy-MM-dd HH:mm:ss.SSS"),
// YYYY
YYYYMMDD_HH24_MM("yyyyMMdd HH:mm"),
YYYY_MM_DD_HH24_MM("yyyy-MM-dd HH:mm"),
YYYYMMDDHH24MMSS("yyyyMMddHHmmss"),
YYYYMMDDHH24MMSSSSS("yyyyMMddHHmmssSSS"),
YYYYMMDD_HH24_MM_SS("yyyyMMdd HH:mm:ss"),
YYYYMMDD_HH24_MM_SS_SSS("yyyyMMdd HH:mm:ss.SSS"),
YYYY_MM_DD_HH24_MM_SS("yyyy-MM-dd HH:mm:ss"),
YYYY_MM_DD_HH24_MM_SS_SSS("yyyy-MM-dd HH:mm:ss.SSS"),
// ISO
YY_MM_DD_HH24_MM_SS_ISO("yy-MM-dd'T'HH:mm:ss"),
YY_MM_DD_HH24_MM_SS_SSS_ISO("yy-MM-dd'T'HH:mm:ss.SSS"),
@@ -151,26 +149,27 @@ public final class DateUtils {
}
}
/**
* 生成时间戳
*
* @return 时间戳
* @see #buildTime(LocalDateTime)
*/
public static final String buildTime() {
return buildTime(LocalDateTime.now());
private DateUtils() {
}
/**
* @return 时间戳
*
* @see #buildTime(LocalDateTime)
*/
public static final String buildTime() {
return DateUtils.buildTime(LocalDateTime.now());
}
/**
* 生成时间戳
*
* @param localDateTime 日期时间
*
* @return 时间戳
*/
public static final String buildTime(LocalDateTime localDateTime) {
if (Objects.isNull(localDateTime)) {
return buildTime();
return DateUtils.buildTime();
}
return DateTimeStyle.YYYYMMDDHH24MMSS.getDateTimeFormatter().format(localDateTime);
}
@@ -179,6 +178,7 @@ public final class DateUtils {
* 日期转化
*
* @param date Date
*
* @return LocalDate
*/
public static final LocalDate toLocalDate(Date date) {
@@ -189,6 +189,7 @@ public final class DateUtils {
* 日期转化
*
* @param date Date
*
* @return LocalTime
*/
public static final LocalTime toLocalTime(Date date) {
@@ -199,6 +200,7 @@ public final class DateUtils {
* 日期转化
*
* @param date Date
*
* @return LocalDateTime
*/
public static final LocalDateTime toLocalDateTime(Date date) {
@@ -209,6 +211,7 @@ public final class DateUtils {
* 转换毫秒
*
* @param localDateTime LocalDateTime
*
* @return 毫秒
*/
public static final long toMilli(LocalDateTime localDateTime) {
@@ -220,6 +223,7 @@ public final class DateUtils {
*
* @param localDate LocalDate
* @param format 格式
*
* @return 日期字符串
*/
public static String format(LocalDate localDate, DateStyle format) {
@@ -231,6 +235,7 @@ public final class DateUtils {
*
* @param localTime LocalTime
* @param format 格式
*
* @return 时间字符串
*/
public static String format(LocalTime localTime, TimeStyle format) {
@@ -242,6 +247,7 @@ public final class DateUtils {
*
* @param localDateTime LocalDateTime
* @param format 格式
*
* @return 日期时间字符串
*/
public static String format(LocalDateTime localDateTime, DateTimeStyle format) {

View File

@@ -9,6 +9,10 @@ import java.time.LocalDateTime;
*/
public final class IdUtils {
/**
* 最大索引
*/
private static final int MAX_INDEX = 999;
/**
* 当前索引
*/
@@ -17,13 +21,12 @@ public final class IdUtils {
* 当前终端索引
*/
private static int clientIndex = 99999;
/**
* 最大索引
*/
private static final int MAX_INDEX = 999;
private IdUtils() {
}
/**
* @return 消息ID
* @return ID
*/
public static final long buildId() {
int index;

View File

@@ -21,8 +21,6 @@ import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -35,18 +33,19 @@ import java.util.TimeZone;
*/
public final class JSONUtils {
private JSONUtils() {
}
/**
* Mapper线程安全
*/
private static final ObjectMapper MAPPER = buildMapper();
private static final ObjectMapper MAPPER = JSONUtils.buildMapper();
private JSONUtils() {
}
/**
* Java转JSON
*
* @param object Java
*
* @return JSON
*/
public static final String toJSON(Object object) {
@@ -65,6 +64,7 @@ public final class JSONUtils {
*
* @param <T> Java类型
* @param json JSON
*
* @return Java
*/
public static final <T> T toJava(String json) {
@@ -85,6 +85,7 @@ public final class JSONUtils {
* @param <T> Java类型
* @param json JSON
* @param clazz Java类型
*
* @return Java
*/
public static final <T> T toJava(String json, Class<T> clazz) {
@@ -104,6 +105,7 @@ public final class JSONUtils {
* @param <T> Java类型
* @param json JSON
* @param type Java类型
*
* @return Java
*/
public static final <T> T toJava(String json, TypeReference<T> type) {
@@ -123,11 +125,12 @@ public final class JSONUtils {
* @param <K> K类型
* @param <V> V类型
* @param json JSON
*
* @return Map
*/
public static final <K, V> Map<K, V> toMap(String json) {
if (Objects.isNull(json)) {
return new HashMap<>();
return Map.of();
}
try {
return MAPPER.readValue(json, new TypeReference<Map<K, V>>() {
@@ -142,11 +145,12 @@ public final class JSONUtils {
*
* @param <T> 元素类型
* @param json JSON
*
* @return List
*/
public static final <T> List<T> toList(String json) {
if (Objects.isNull(json)) {
return new ArrayList<>();
return List.of();
}
try {
return MAPPER.readValue(json, new TypeReference<List<T>>() {
@@ -159,14 +163,15 @@ public final class JSONUtils {
/**
* JSON转List
*
* @param <T> 元素类型
* @param <T> Java类型
* @param json JSON
* @param clazz 类型
* @param clazz Java类型
*
* @return List
*/
public static final <T> List<T> toList(String json, Class<T> clazz) {
if (Objects.isNull(json)) {
return new ArrayList<>();
return List.of();
}
try {
return MAPPER.readValue(json, new TypeReference<List<T>>() {
@@ -184,7 +189,7 @@ public final class JSONUtils {
return mapper
.setTimeZone(TimeZone.getDefault())
.setDateFormat(new SimpleDateFormat(DateUtils.DateTimeStyle.YYYY_MM_DD_HH24_MM_SS.getFormat()))
.registerModules(buildCustomModule(), buildJavaTimeModule())
.registerModules(JSONUtils.buildCustomModule(), JSONUtils.buildJavaTimeModule())
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.setSerializationInclusion(Include.NON_NULL);
@@ -196,7 +201,7 @@ public final class JSONUtils {
private static final Module buildCustomModule() {
final SimpleModule customModule = new SimpleModule("CustomModule");
// 注意不能转换Long类型数据请求数据类型变化
// customModule.addSerializer(Long.class, ToStringSerializer.instance);
// customModule.addSerializer(Long.class, ToStringSerializer.instance);
return customModule;
}

View File

@@ -16,12 +16,11 @@ public final class ListUtils {
}
/**
* @param <T> 集合类型
* @param list 集合
* @param function 执行函数
*
* @return 集合首个元素
*
* @param <T> 集合类型
* @return 集合首个元素执行函数返回结果
*/
public static final <T> T getOnlyOne(List<T> list, Function<T, T> function) {
if(list == null || list.isEmpty()) {

View File

@@ -14,10 +14,9 @@ public final class MapUtils {
}
/**
* @param <T> 参数泛型
*
* @param <T> 参数泛型
* @param body 消息主体
* @param key 参数名称
* @param key 参数名称
*
* @return 参数值
*/
@@ -30,10 +29,9 @@ public final class MapUtils {
}
/**
* @param <T> 参数泛型
*
* @param body 消息主体
* @param key 参数名称
* @param <T> 参数泛型
* @param body 消息主体
* @param key 参数名称
* @param defaultValue 参数默认值
*
* @return 参数值
@@ -49,7 +47,7 @@ public final class MapUtils {
/**
* @param body 消息主体
* @param key 参数名称
* @param key 参数名称
*
* @return 参数值
*/
@@ -62,17 +60,17 @@ public final class MapUtils {
return null;
} else if(object instanceof Long value) {
return value;
} else if(object instanceof Integer value) {
return value.longValue();
} else if(object instanceof Double value) {
return value.longValue();
} else if(object instanceof Integer value) {
return value.longValue();
}
return new BigDecimal(object.toString()).longValue();
}
/**
* @param body 消息主体
* @param key 参数名称
* @param key 参数名称
*
* @return 参数值
*/
@@ -85,17 +83,17 @@ public final class MapUtils {
return null;
} else if(object instanceof Long value) {
return value.doubleValue();
} else if(object instanceof Integer value) {
return value.doubleValue();
} else if(object instanceof Double value) {
return value;
} else if(object instanceof Integer value) {
return value.doubleValue();
}
return new BigDecimal(object.toString()).doubleValue();
}
/**
* @param body 消息主体
* @param key 参数名称
* @param key 参数名称
*
* @return 参数值
*/
@@ -108,17 +106,17 @@ public final class MapUtils {
return null;
} else if(object instanceof Long value) {
return value.intValue();
} else if(object instanceof Integer value) {
return value;
} else if(object instanceof Double value) {
return value.intValue();
} else if(object instanceof Integer value) {
return value;
}
return new BigDecimal(object.toString()).intValue();
}
/**
* @param body 消息主体
* @param key 参数名称
* @param key 参数名称
*
* @return 参数值
*/
@@ -136,10 +134,9 @@ public final class MapUtils {
}
/**
* @param <T> 参数泛型
*
* @param <T> 参数泛型
* @param body 消息主体
* @param key 参数名称
* @param key 参数名称
*
* @return 参数值
*/

View File

@@ -22,7 +22,6 @@
<action android:name="android.intent.action.HOME" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@@ -32,13 +31,11 @@
android:exported="false"
android:label="@string/title_activity_settings"
android:theme="@style/Theme.Taoyao" />
<service
android:name=".MediaService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="mediaProjection" />
android:foregroundServiceType="camera|location|microphone|mediaProjection" />
<receiver
android:name=".TaoyaoReceiver"
android:enabled="true"
@@ -51,4 +48,4 @@
</receiver>
</application>
</manifest>
</manifest>

View File

@@ -6,4 +6,4 @@
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
</resources>
</resources>

View File

@@ -48,4 +48,4 @@
<integer name="iFrameInterval">1</integer>
<!-- 水印 -->
<string name="watermark">"'TAOYAO' yyyy-MM-dd HH:mm:ss"</string>
</resources>
</resources>

View File

@@ -14,4 +14,4 @@
<string name="signal_client_id">终端标识</string>
<string name="signal_username">信令帐号</string>
<string name="signal_password">信令密码</string>
</resources>
</resources>

View File

@@ -11,4 +11,4 @@
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
</style>
</resources>
</resources>

View File

@@ -1,2 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content></full-backup-content>
<full-backup-content>
</full-backup-content>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
<cloud-backup></cloud-backup>
</data-extraction-rules>
</data-extraction-rules>