diff --git a/app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java b/app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java index f13ab14..28552bf 100644 --- a/app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java +++ b/app/src/main/java/com/iflytop/profilometer/ProfilometerApplication.java @@ -6,7 +6,9 @@ import android.os.Bundle; import androidx.annotation.NonNull; +import com.iflytop.profilometer.dao.BaseProfileRecordPointSetDao; import com.iflytop.profilometer.dao.UserDao; +import com.iflytop.profilometer.model.entity.BaseProfileRecordPointSet; public class ProfilometerApplication extends Application { private Activity currentActivity; @@ -14,10 +16,269 @@ public class ProfilometerApplication extends Application { @Override public void onCreate() { super.onCreate(); -// + UserDao userDao = new UserDao(this); userDao.insertAdminUserIfNotExists(); + BaseProfileRecordPointSetDao baseProfileRecordPointSetDao = new BaseProfileRecordPointSetDao(this); + BaseProfileRecordPointSet baseProfileRecordPointSet = new BaseProfileRecordPointSet(); + baseProfileRecordPointSet.setName("60型标准轨"); + baseProfileRecordPointSet.setCode("60"); + baseProfileRecordPointSet.setPoints("[{\n" + + "\t\t\"type\": \"arc\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": 0,\n" + + "\t\t\t\"y\": 0\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": -9.949,\n" + + "\t\t\t\"y\": 0.165\n" + + "\t\t},\n" + + "\t\t\"radius\": 300,\n" + + "\t\t\"color\": \"#000000\",\n" + + "\t\t\"side\": \"right\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"arc\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": -9.949,\n" + + "\t\t\t\"y\": 0.165\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": -25.35,\n" + + "\t\t\t\"y\": 2.185\n" + + "\t\t},\n" + + "\t\t\"radius\": 80,\n" + + "\t\t\"color\": \"#000000\",\n" + + "\t\t\"side\": \"right\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"arc\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": -25.35,\n" + + "\t\t\t\"y\": 2.185\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": -35.4,\n" + + "\t\t\t\"y\": 14.2\n" + + "\t\t},\n" + + "\t\t\"radius\": 13,\n" + + "\t\t\"color\": \"#000000\",\n" + + "\t\t\"side\": \"right\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"line\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": -35.4,\n" + + "\t\t\t\"y\": 14.2\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": -36.317,\n" + + "\t\t\t\"y\": 32.539\n" + + "\t\t},\n" + + "\t\t\"color\": \"#000000\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"arc\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": -36.317,\n" + + "\t\t\t\"y\": 32.539\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": -32.904,\n" + + "\t\t\t\"y\": 37.532\n" + + "\t\t},\n" + + "\t\t\"radius\": 5,\n" + + "\t\t\"color\": \"#000000\",\n" + + "\t\t\"side\": \"right\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"line\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": -32.904,\n" + + "\t\t\t\"y\": 37.532\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": -20,\n" + + "\t\t\t\"y\": 41.833\n" + + "\t\t},\n" + + "\t\t\"color\": \"#000000\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"arc\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": 0,\n" + + "\t\t\t\"y\": 0\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": 9.949,\n" + + "\t\t\t\"y\": 0.165\n" + + "\t\t},\n" + + "\t\t\"radius\": 300,\n" + + "\t\t\"color\": \"#000000\",\n" + + "\t\t\"side\": \"right\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"arc\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": 9.949,\n" + + "\t\t\t\"y\": 0.165\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": 25.35,\n" + + "\t\t\t\"y\": 2.185\n" + + "\t\t},\n" + + "\t\t\"radius\": 80,\n" + + "\t\t\"color\": \"#000000\",\n" + + "\t\t\"side\": \"left\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"arc\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": 25.35,\n" + + "\t\t\t\"y\": 2.185\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": 35.4,\n" + + "\t\t\t\"y\": 14.2\n" + + "\t\t},\n" + + "\t\t\"radius\": 13,\n" + + "\t\t\"color\": \"#000000\",\n" + + "\t\t\"side\": \"left\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"line\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": 35.4,\n" + + "\t\t\t\"y\": 14.2\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": 36.317,\n" + + "\t\t\t\"y\": 32.539\n" + + "\t\t},\n" + + "\t\t\"color\": \"#000000\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"arc\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": 36.317,\n" + + "\t\t\t\"y\": 32.539\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": 32.904,\n" + + "\t\t\t\"y\": 37.532\n" + + "\t\t},\n" + + "\t\t\"radius\": 5,\n" + + "\t\t\"color\": \"#000000\",\n" + + "\t\t\"side\": \"left\"\n" + + "\t},\n" + + "\t{\n" + + "\t\t\"type\": \"line\",\n" + + "\t\t\"start\": {\n" + + "\t\t\t\"x\": 32.904,\n" + + "\t\t\t\"y\": 37.532\n" + + "\t\t},\n" + + "\t\t\"end\": {\n" + + "\t\t\t\"x\": 20,\n" + + "\t\t\t\"y\": 41.833\n" + + "\t\t},\n" + + "\t\t\"color\": \"#000000\"\n" + + "\t}\n" + + "]"); + + baseProfileRecordPointSet.setCalPoints("[\n" + + " {\n" + + " \"type\": \"arc\",\n" + + " \"start\": {\n" + + " \"x\": 0,\n" + + " \"y\": 0\n" + + " },\n" + + " \"end\": {\n" + + " \"x\": -9.949,\n" + + " \"y\": 0.165\n" + + " },\n" + + " \"radius\": 300,\n" + + " \"color\": \"#339900\",\n" + + " \"side\": \"right\"\n" + + " },\n" + + " {\n" + + " \"type\": \"arc\",\n" + + " \"start\": {\n" + + " \"x\": -9.949,\n" + + " \"y\": 0.165\n" + + " },\n" + + " \"end\": {\n" + + " \"x\": -25.35,\n" + + " \"y\": 2.185\n" + + " },\n" + + " \"radius\": 80,\n" + + " \"color\": \"#336699\",\n" + + " \"side\": \"right\"\n" + + " },\n" + + " {\n" + + " \"type\": \"arc\",\n" + + " \"start\": {\n" + + " \"x\": -25.35,\n" + + " \"y\": 2.185\n" + + " },\n" + + " \"end\": {\n" + + " \"x\": -35.4,\n" + + " \"y\": 14.2\n" + + " },\n" + + " \"radius\": 13,\n" + + " \"color\": \"#660000\",\n" + + " \"side\": \"right\"\n" + + " },\n" + + " {\n" + + " \"type\": \"arc\",\n" + + " \"start\": {\n" + + " \"x\": 0,\n" + + " \"y\": 0\n" + + " },\n" + + " \"end\": {\n" + + " \"x\": 9.949,\n" + + " \"y\": 0.165\n" + + " },\n" + + " \"radius\": 300,\n" + + " \"color\": \"#99CCCC\",\n" + + " \"side\": \"left\"\n" + + " },\n" + + " {\n" + + " \"type\": \"arc\",\n" + + " \"start\": {\n" + + " \"x\": 9.949,\n" + + " \"y\": 0.165\n" + + " },\n" + + " \"end\": {\n" + + " \"x\": 25.35,\n" + + " \"y\": 2.185\n" + + " },\n" + + " \"radius\": 80,\n" + + " \"color\": \"#CC0033\",\n" + + " \"side\": \"left\"\n" + + " },\n" + + " {\n" + + " \"type\": \"arc\",\n" + + " \"start\": {\n" + + " \"x\": 25.35,\n" + + " \"y\": 2.185\n" + + " },\n" + + " \"end\": {\n" + + " \"x\": 35.4,\n" + + " \"y\": 14.2\n" + + " },\n" + + " \"radius\": 13,\n" + + " \"color\": \"#CC6600\",\n" + + " \"side\": \"left\"\n" + + " }\n" + + "]"); + + + if(baseProfileRecordPointSetDao.getBaseProfileRecordPointSetByCode("60") == null){ + baseProfileRecordPointSetDao.insertBaseProfileRecordPointSet(baseProfileRecordPointSet); + } + + registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { @Override public void onActivityCreated(@NonNull Activity activity, Bundle savedInstanceState) { diff --git a/app/src/main/java/com/iflytop/profilometer/api/basic/BasicApi.java b/app/src/main/java/com/iflytop/profilometer/api/basic/BasicApi.java new file mode 100644 index 0000000..9e48287 --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/api/basic/BasicApi.java @@ -0,0 +1,40 @@ +package com.iflytop.profilometer.api.basic; + +import android.content.Context; + +import com.iflytop.profilometer.common.result.Result; +import com.iflytop.profilometer.dao.BaseProfileRecordPointSetDao; +import com.iflytop.profilometer.model.entity.BaseProfileRecordPointSet; + +import java.util.List; + +/** + * 基础数据接口 + */ +public class BasicApi { + private final Context context; + + public BasicApi(Context context) { + this.context = context.getApplicationContext(); + } + + /** + * 获取基础轨型列表 + */ + public String trackList() { + BaseProfileRecordPointSetDao baseProfileRecordPointSetDao = new BaseProfileRecordPointSetDao(context); + List baseProfileRecordPointSetList = baseProfileRecordPointSetDao.getAllBaseProfileRecordPointSets(); + return Result.success(baseProfileRecordPointSetList); + } + + /** + * 根据CODE获取基础轨 + */ + public String getTrackByCode(String code) { + BaseProfileRecordPointSetDao baseProfileRecordPointSetDao = new BaseProfileRecordPointSetDao(context); + BaseProfileRecordPointSet baseProfileRecordPointSet = baseProfileRecordPointSetDao.getBaseProfileRecordPointSetByCode(code); + return Result.success(baseProfileRecordPointSet); + } + + +} diff --git a/app/src/main/java/com/iflytop/profilometer/api/basic/BasicRoutes.kt b/app/src/main/java/com/iflytop/profilometer/api/basic/BasicRoutes.kt new file mode 100644 index 0000000..71eca51 --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/api/basic/BasicRoutes.kt @@ -0,0 +1,37 @@ +package com.iflytop.profilometer.api.basic + +import android.content.Context +import io.ktor.http.ContentType +import io.ktor.server.application.call +import io.ktor.server.request.receive +import io.ktor.server.response.respondText +import io.ktor.server.routing.Routing +import io.ktor.server.routing.post + +/** + * 基础数据接口 + */ +fun Routing.basicRoutes(context: Context) { + val api = BasicApi(context) + + /** + * 获取基础轨型列表 + */ + post("/api/basic/track-list") { + val jsonResponse = api.trackList() + call.respondText(jsonResponse, ContentType.Application.Json) + } + + + /** + * 根据CODE获取基础轨 + */ + post("/api/basic/track/get-by-code") { + val params = call.receive>() + val jsonResponse = api.getTrackByCode(params["code"]) + call.respondText(jsonResponse, ContentType.Application.Json) + } + + +} + diff --git a/app/src/main/java/com/iflytop/profilometer/api/ws/BleWebsocketManager.java b/app/src/main/java/com/iflytop/profilometer/api/ws/BleWebsocketManager.java index 2bd24e2..5f5fda6 100644 --- a/app/src/main/java/com/iflytop/profilometer/api/ws/BleWebsocketManager.java +++ b/app/src/main/java/com/iflytop/profilometer/api/ws/BleWebsocketManager.java @@ -2,14 +2,16 @@ package com.iflytop.profilometer.api.ws; import android.annotation.SuppressLint; import android.bluetooth.BluetoothDevice; -import android.content.Context; +import android.bluetooth.BluetoothGatt; import com.iflytop.profilometer.core.bluetooth.BleManager; import com.iflytop.profilometer.core.websocket.WebSocketManager; import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -42,11 +44,24 @@ public class BleWebsocketManager { scheduledTask = scheduler.scheduleWithFixedDelay(() -> { List scannedDevices = BleManager.getInstance().getScannedDevices(); scannedDevices.sort(Comparator.comparing(BluetoothDevice::getAddress)); - List bleList = new ArrayList<>(); + Map listMap = new HashMap<>(); + listMap.put("type", "ble-list"); + List> bleList = new ArrayList<>(); + BluetoothGatt gatt = BleManager.getInstance().getBluetoothGatt(); for (BluetoothDevice bluetoothDevice : scannedDevices) { - bleList.add(bluetoothDevice.getName() + "_" + bluetoothDevice.getAddress()); + Map bleMap = new HashMap<>(); + String mac = bluetoothDevice.getAddress(); + bleMap.put("mac", mac); + bleMap.put("name", bluetoothDevice.getName() == null ? "未命名" : bluetoothDevice.getName()); + if (gatt != null && mac.equals(gatt.getDevice().getAddress())) { + bleMap.put("linked", true); + } else { + bleMap.put("linked", false); + } + bleList.add(bleMap); } - WebSocketManager.send(JSONUtil.toJsonStr(bleList)); + listMap.put("data", bleList); + WebSocketManager.send(JSONUtil.toJsonStr(listMap)); }, 0, 2000, TimeUnit.MILLISECONDS); } diff --git a/app/src/main/java/com/iflytop/profilometer/common/base/BaseEntity.java b/app/src/main/java/com/iflytop/profilometer/common/base/BaseEntity.java index d9733f0..18895b9 100644 --- a/app/src/main/java/com/iflytop/profilometer/common/base/BaseEntity.java +++ b/app/src/main/java/com/iflytop/profilometer/common/base/BaseEntity.java @@ -2,6 +2,7 @@ package com.iflytop.profilometer.common.base; import java.io.Serializable; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; public class BaseEntity implements Serializable { private Long id; diff --git a/app/src/main/java/com/iflytop/profilometer/common/result/Result.java b/app/src/main/java/com/iflytop/profilometer/common/result/Result.java index 123c628..49e3176 100644 --- a/app/src/main/java/com/iflytop/profilometer/common/result/Result.java +++ b/app/src/main/java/com/iflytop/profilometer/common/result/Result.java @@ -4,6 +4,7 @@ package com.iflytop.profilometer.common.result; import java.util.HashMap; import java.util.Map; +import cn.hutool.json.JSONConfig; import cn.hutool.json.JSONUtil; public final class Result { @@ -17,7 +18,8 @@ public final class Result { Map resultMap = new HashMap<>(); resultMap.put("success", true); resultMap.put("data", data); - return JSONUtil.toJsonStr(resultMap); + JSONConfig jsonConfig = JSONConfig.create().setDateFormat("yyyy-MM-dd HH:mm:ss"); + return JSONUtil.toJsonStr(resultMap, jsonConfig); } /** diff --git a/app/src/main/java/com/iflytop/profilometer/dao/BaseProfileRecordPointSetDao.java b/app/src/main/java/com/iflytop/profilometer/dao/BaseProfileRecordPointSetDao.java index 6e89ed1..d0a4a29 100644 --- a/app/src/main/java/com/iflytop/profilometer/dao/BaseProfileRecordPointSetDao.java +++ b/app/src/main/java/com/iflytop/profilometer/dao/BaseProfileRecordPointSetDao.java @@ -72,8 +72,6 @@ public class BaseProfileRecordPointSetDao { entity.setId(cursor.getLong(cursor.getColumnIndex("id"))); entity.setName(cursor.getString(cursor.getColumnIndex("name"))); entity.setCode(cursor.getString(cursor.getColumnIndex("code"))); - entity.setPoints(cursor.getString(cursor.getColumnIndex("points"))); - entity.setCalPoints(cursor.getString(cursor.getColumnIndex("cal_points"))); entity.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER)); entity.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER)); list.add(entity); @@ -105,6 +103,27 @@ public class BaseProfileRecordPointSetDao { return entity; } + // 根据 code 查询基础测量点集记录 + @SuppressLint("Range") + public BaseProfileRecordPointSet getBaseProfileRecordPointSetByCode(String code) { + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_BASE_PROFILE_RECORD_POINT_SET, null, "code = ?", new String[]{code}, null, null, null); + BaseProfileRecordPointSet entity = null; + if (cursor.moveToFirst()) { + entity = new BaseProfileRecordPointSet(); + entity.setId(cursor.getLong(cursor.getColumnIndex("id"))); + entity.setName(cursor.getString(cursor.getColumnIndex("name"))); + entity.setCode(cursor.getString(cursor.getColumnIndex("code"))); + entity.setPoints(cursor.getString(cursor.getColumnIndex("points"))); + entity.setCalPoints(cursor.getString(cursor.getColumnIndex("cal_points"))); + entity.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER)); + entity.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER)); + cursor.close(); + } + db.close(); + return entity; + } + private String getCurrentTime() { return LocalDateTime.now().format(FORMATTER); } diff --git a/app/src/main/java/com/iflytop/profilometer/server/HttpServer.kt b/app/src/main/java/com/iflytop/profilometer/server/HttpServer.kt index 6a6c94a..e272625 100644 --- a/app/src/main/java/com/iflytop/profilometer/server/HttpServer.kt +++ b/app/src/main/java/com/iflytop/profilometer/server/HttpServer.kt @@ -2,6 +2,7 @@ package com.iflytop.profilometer.server import android.content.Context import com.iflytop.profilometer.api.auth.authRoutes +import com.iflytop.profilometer.api.basic.basicRoutes import com.iflytop.profilometer.api.ble.bleRoutes import com.iflytop.profilometer.api.measure.measureRoutes import com.iflytop.profilometer.api.record.recordRoutes @@ -99,6 +100,7 @@ object HttpServer { recordRoutes(context) syncRoutes(context) systemRoutes(context) + basicRoutes(context) } } server?.start(wait = false)