Browse Source

解决对齐点无法保存问题

master
白凤吉 4 months ago
parent
commit
2d079f9ba6
  1. 61
      app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java
  2. 10
      app/src/main/java/com/iflytop/profilometer/api/measure/MeasureRoutes.kt
  3. 5
      app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java
  4. 2
      app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java
  5. 1
      app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/RailProfileDrawer.java
  6. 5
      app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordPointSetDao.java

61
app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java

@ -24,7 +24,6 @@ import com.iflytop.profilometer.service.RailProfileDrawerService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
@ -77,28 +76,28 @@ public class MeasureApi {
/** /**
* 保存测量 * 保存测量
*/ */
public String save(Map<String, String> params) {
public String save(JSONObject params) {
ProfileRecordDao profileRecordDao = new ProfileRecordDao(context); ProfileRecordDao profileRecordDao = new ProfileRecordDao(context);
ProfileRecordPointSetDao profileRecordPointSetDao = new ProfileRecordPointSetDao(context); ProfileRecordPointSetDao profileRecordPointSetDao = new ProfileRecordPointSetDao(context);
ProfileRecordDescription profileRecordDescription = new ProfileRecordDescription(); ProfileRecordDescription profileRecordDescription = new ProfileRecordDescription();
profileRecordDescription.setUuid(UUID.randomUUID().toString()); profileRecordDescription.setUuid(UUID.randomUUID().toString());
profileRecordDescription.setOperator(params.get("operator"));
profileRecordDescription.setName(params.get("name"));
profileRecordDescription.setTljCode(params.get("tljCode"));
profileRecordDescription.setGwdCode(params.get("gwdCode"));
profileRecordDescription.setXmCode(params.get("xmCode"));
profileRecordDescription.setStationCode(params.get("stationCode"));
profileRecordDescription.setDataType(params.get("dataType"));
profileRecordDescription.setDataSource(params.get("dataSource"));
profileRecordDescription.setRailSize(params.get("railSize"));
profileRecordDescription.setLineClassify(params.get("lineClassify"));
profileRecordDescription.setBatch(params.get("batch"));
profileRecordDescription.setXbCode(params.get("xbCode"));
profileRecordDescription.setMileage(params.get("mileage"));
profileRecordDescription.setUnitType(params.get("unitType"));
profileRecordDescription.setExtraDesc(params.get("extraDesc"));
profileRecordDescription.setTurnoutNum(params.get("turnoutNum"));
profileRecordDescription.setSleeperNum(params.get("sleeperNum"));
profileRecordDescription.setOperator(params.getStr("operator"));
profileRecordDescription.setName(params.getStr("name"));
profileRecordDescription.setTljCode(params.getStr("tljCode"));
profileRecordDescription.setGwdCode(params.getStr("gwdCode"));
profileRecordDescription.setXmCode(params.getStr("xmCode"));
profileRecordDescription.setStationCode(params.getStr("stationCode"));
profileRecordDescription.setDataType(params.getStr("dataType"));
profileRecordDescription.setDataSource(params.getStr("dataSource"));
profileRecordDescription.setRailSize(params.getStr("railSize"));
profileRecordDescription.setLineClassify(params.getStr("lineClassify"));
profileRecordDescription.setBatch(params.getStr("batch"));
profileRecordDescription.setXbCode(params.getStr("xbCode"));
profileRecordDescription.setMileage(params.getStr("mileage"));
profileRecordDescription.setUnitType(params.getStr("unitType"));
profileRecordDescription.setExtraDesc(params.getStr("extraDesc"));
profileRecordDescription.setTurnoutNum(params.getStr("turnoutNum"));
profileRecordDescription.setSleeperNum(params.getStr("sleeperNum"));
profileRecordDescription.setSyncStatus(SyncStatus.wait); profileRecordDescription.setSyncStatus(SyncStatus.wait);
profileRecordDao.insertProfileRecord(profileRecordDescription); profileRecordDao.insertProfileRecord(profileRecordDescription);
@ -109,19 +108,21 @@ public class MeasureApi {
profileRecordPointSet.setProfileRecordUuid(profileRecordDescription.getUuid()); profileRecordPointSet.setProfileRecordUuid(profileRecordDescription.getUuid());
profileRecordPointSet.setLeftPoints(JSONUtil.toJsonStr(leftPoint)); profileRecordPointSet.setLeftPoints(JSONUtil.toJsonStr(leftPoint));
profileRecordPointSet.setRightPoints(JSONUtil.toJsonStr(rightPoint)); profileRecordPointSet.setRightPoints(JSONUtil.toJsonStr(rightPoint));
List<XYPoint> alignPoints = JSONUtil.toList(params.get("alignPoints"), XYPoint.class);
if (alignPoints == null || alignPoints.isEmpty()) {
alignPoints = taskState.getAlignPointSetList();
}
if (alignPoints.isEmpty()) {
List<XYPoint> leftPointsRevers = new ArrayList<>(leftPoint);
Collections.reverse(leftPointsRevers);
alignPoints.addAll(leftPointsRevers);
alignPoints.addAll(rightPoint);
JSONArray alignPointsJsonArray = params.getJSONArray("alignPoints");
if (alignPointsJsonArray != null && !alignPointsJsonArray.isEmpty()) {
profileRecordPointSet.setAlignPoints(alignPointsJsonArray.toString());
} else {
List<XYPoint> alignPoints = taskState.getAlignPointSetList();
if (alignPoints.isEmpty()) {
List<XYPoint> leftPointsRevers = new ArrayList<>(leftPoint);
Collections.reverse(leftPointsRevers);
alignPoints.addAll(leftPointsRevers);
alignPoints.addAll(rightPoint);
profileRecordPointSet.setAlignPoints(JSONUtil.toJsonStr(alignPoints));
}
} }
profileRecordPointSet.setAlignPoints(JSONUtil.toJsonStr(alignPoints));
profileRecordPointSetDao.insertProfileRecordPointSet(profileRecordPointSet); profileRecordPointSetDao.insertProfileRecordPointSet(profileRecordPointSet);
return Result.success(); return Result.success();
} }

10
app/src/main/java/com/iflytop/profilometer/api/measure/MeasureRoutes.kt

@ -1,9 +1,12 @@
package com.iflytop.profilometer.api.measure package com.iflytop.profilometer.api.measure
import android.content.Context import android.content.Context
import cn.hutool.json.JSONObject
import cn.hutool.json.JSONUtil
import io.ktor.http.ContentType import io.ktor.http.ContentType
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.request.receive import io.ktor.server.request.receive
import io.ktor.server.request.receiveText
import io.ktor.server.response.respondText import io.ktor.server.response.respondText
import io.ktor.server.routing.Routing import io.ktor.server.routing.Routing
import io.ktor.server.routing.post import io.ktor.server.routing.post
@ -31,8 +34,11 @@ fun Routing.measureRoutes(context: Context) {
* *
*/ */
post("/api/measure/save") { post("/api/measure/save") {
val params = call.receive<Map<String, String>>()
val jsonResponse = api.save(params)
// 接收原始的 JSON 字符串
val jsonString = call.receiveText()
// 使用 Hutool 将 JSON 字符串转换为 JSONObject
val jsonObject: JSONObject = JSONUtil.parseObj(jsonString)
val jsonResponse = api.save(jsonObject)
call.respondText(jsonResponse, ContentType.Application.Json) call.respondText(jsonResponse, ContentType.Application.Json)
} }

5
app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java

@ -68,8 +68,9 @@ public class RecordApi {
map.put("sleeperNum", profileRecordDescription.getSleeperNum()); map.put("sleeperNum", profileRecordDescription.getSleeperNum());
map.put("radius", profileRecordDescription.getRadius()); map.put("radius", profileRecordDescription.getRadius());
map.put("leftPoints", pointSet.getLeftPoints());
map.put("rightPoints", pointSet.getRightPoints());
// map.put("leftPoints", pointSet.getLeftPoints());
// map.put("rightPoints", pointSet.getRightPoints());
map.put("alignPoints", pointSet.getAlignPoints());
map.put("createTime", profileRecordDescription.getCreateTime()); map.put("createTime", profileRecordDescription.getCreateTime());
return Result.success(map); return Result.success(map);
} }

2
app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java

@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteOpenHelper;
public class MyDatabaseHelper extends SQLiteOpenHelper { public class MyDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "app.db"; private static final String DATABASE_NAME = "app.db";
private static final int DATABASE_VERSION = 12; // 升级版本号
private static final int DATABASE_VERSION = 13; // 升级版本号
// 表名 // 表名
public static final String TABLE_APP_USER = "app_user"; public static final String TABLE_APP_USER = "app_user";

1
app/src/main/java/com/iflytop/profilometer/core/migration/measure/drawer/RailProfileDrawer.java

@ -182,6 +182,7 @@ public class RailProfileDrawer {
//左负数右正 //左负数右正
MeasureSide side = rad1 < 0 ? MeasureSide.LEFT : MeasureSide.RIGHT; MeasureSide side = rad1 < 0 ? MeasureSide.LEFT : MeasureSide.RIGHT;
state.isInStartPosArea = isInTheStartPos(side, newPulleyPoint); state.isInStartPosArea = isInTheStartPos(side, newPulleyPoint);
// Log.w(TAG,String.format("Current Side %s",side));
if (state.isInStartPosArea && state.isStill) { if (state.isInStartPosArea && state.isStill) {

5
app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordPointSetDao.java

@ -33,6 +33,7 @@ public class ProfileRecordPointSetDao {
values.put("profile_record_uuid", pointSet.getProfileRecordUuid()); values.put("profile_record_uuid", pointSet.getProfileRecordUuid());
values.put("left_points", pointSet.getLeftPoints()); values.put("left_points", pointSet.getLeftPoints());
values.put("right_points", pointSet.getRightPoints()); values.put("right_points", pointSet.getRightPoints());
values.put("align_points", pointSet.getAlignPoints());
long id = db.insert(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, null, values); long id = db.insert(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, null, values);
db.close(); db.close();
return id; return id;
@ -46,6 +47,7 @@ public class ProfileRecordPointSetDao {
values.put("profile_record_uuid", pointSet.getProfileRecordUuid()); values.put("profile_record_uuid", pointSet.getProfileRecordUuid());
values.put("left_points", pointSet.getLeftPoints()); values.put("left_points", pointSet.getLeftPoints());
values.put("right_points", pointSet.getRightPoints()); values.put("right_points", pointSet.getRightPoints());
values.put("align_points", pointSet.getAlignPoints());
int rows = db.update(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, values, "id = ?", new String[]{String.valueOf(pointSet.getId())}); int rows = db.update(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, values, "id = ?", new String[]{String.valueOf(pointSet.getId())});
db.close(); db.close();
return rows; return rows;
@ -72,6 +74,7 @@ public class ProfileRecordPointSetDao {
pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid"))); pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid")));
pointSet.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points"))); pointSet.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points")));
pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_points"))); pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_points")));
pointSet.setAlignPoints(cursor.getString(cursor.getColumnIndex("align_points")));
pointSet.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER)); pointSet.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER));
pointSet.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER)); pointSet.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER));
list.add(pointSet); list.add(pointSet);
@ -94,6 +97,7 @@ public class ProfileRecordPointSetDao {
pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid"))); pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid")));
pointSet.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points"))); pointSet.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points")));
pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_points"))); pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_points")));
pointSet.setAlignPoints(cursor.getString(cursor.getColumnIndex("align_points")));
pointSet.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER)); pointSet.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER));
pointSet.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER)); pointSet.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER));
cursor.close(); cursor.close();
@ -114,6 +118,7 @@ public class ProfileRecordPointSetDao {
pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid"))); pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid")));
pointSet.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points"))); pointSet.setLeftPoints(cursor.getString(cursor.getColumnIndex("left_points")));
pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_points"))); pointSet.setRightPoints(cursor.getString(cursor.getColumnIndex("right_points")));
pointSet.setAlignPoints(cursor.getString(cursor.getColumnIndex("align_points")));
pointSet.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER)); pointSet.setCreateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("create_time")), FORMATTER));
pointSet.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER)); pointSet.setUpdateTime(LocalDateTime.parse(cursor.getString(cursor.getColumnIndex("update_time")), FORMATTER));
cursor.close(); cursor.close();

Loading…
Cancel
Save