初始提交
This commit is contained in:
241
bin/controller/AreaController.dart
Normal file
241
bin/controller/AreaController.dart
Normal file
@@ -0,0 +1,241 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../service/AreaService.dart';
|
||||
|
||||
part 'AreaController.route.dart';
|
||||
|
||||
@RequestMapping(path: "/report")
|
||||
class AreaController {
|
||||
final AreaService areaService = AreaService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
AreaController();
|
||||
|
||||
// 获取实时数据
|
||||
@RequestMapping(path: "/getInstantData", method: HttpMethod.GET,auth: false)
|
||||
Future<Response> getInstantData(
|
||||
Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List> apiResponse = ApiResponse();
|
||||
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
String? mac = queryParameters['mac'];
|
||||
String? openId = queryParameters['openId'];
|
||||
|
||||
if (mac == null || mac.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败,设备mac不能为空";
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
if (openId == null || openId.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败,设备openId不能为空";
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
Map result = await areaService.getInstantData(mac,openId);
|
||||
if (result['flag'] == 1) {
|
||||
// 成功
|
||||
// apiResponse.code = ResponseJsonCode.success;
|
||||
// apiResponse.message = result['msg'] ?? "查询成功";
|
||||
// apiResponse.data = result['data'];
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result['msg'] ?? "查询成功";
|
||||
|
||||
// 2. 将 result['data'] 包装成 List<Map<String, dynamic>>
|
||||
if (result['data'] != null) {
|
||||
// result['data'] 是一个 Map,包装成 List
|
||||
Map<String, dynamic> dataMap =
|
||||
Map<String, dynamic>.from(result['data']);
|
||||
|
||||
// 可以在这里添加一些额外字段(可选)
|
||||
dataMap['responseTime'] = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
// 将单个 Map 放入 List 中
|
||||
apiResponse.data = [dataMap];
|
||||
} else {
|
||||
apiResponse.data = [];
|
||||
}
|
||||
} else {
|
||||
// 失败
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result['msg'] ?? "查询失败";
|
||||
apiResponse.data = null;
|
||||
}
|
||||
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e";
|
||||
return Response(
|
||||
HttpStatusCode.internalServerError,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 开始体验设备
|
||||
@RequestMapping(path: "/start", method: HttpMethod.POST,auth: false)
|
||||
Future<Response> start(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
|
||||
if (data == null || data.isEmpty || data['mac'] == null) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "请求失败,设备mac不能为空";
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
if (data == null || data.isEmpty || data['openId'] == null) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "请求失败,设备openId不能为空";
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
|
||||
Map result = await areaService.startKuaijian(data);
|
||||
if (result['flag'] == 1) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result['msg'] ?? MessageConstants.ADD_SUCCESS;
|
||||
} else {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result['msg'] ?? "操作失败";
|
||||
}
|
||||
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "添加失败: $e";
|
||||
return Response(
|
||||
HttpStatusCode.internalServerError,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 结束体验设备
|
||||
@RequestMapping(path: "/end", method: HttpMethod.POST,auth: false)
|
||||
Future<Response> end(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
if (data == null || data.isEmpty || data['mac'] == null) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "请求失败,设备mac不能为空";
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
if (data == null || data.isEmpty || data['openId'] == null) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "请求失败,设备openId不能为空";
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
|
||||
Map result = await areaService.endKuaijian(data);
|
||||
if (result['flag'] == 1) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result['msg'] ?? MessageConstants.ADD_SUCCESS;
|
||||
} else {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result['msg'] ?? "操作失败";
|
||||
}
|
||||
|
||||
return Response(
|
||||
HttpStatusCode.ok,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "添加失败: $e";
|
||||
return Response(
|
||||
HttpStatusCode.internalServerError,
|
||||
body: apiResponse.serialize(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// // 更新区域
|
||||
// @RequestMapping(path: "/updateArea", method: HttpMethod.PUT)
|
||||
// Future<Response> updateArea(Request request) async {
|
||||
// ApiResponse<String> apiResponse = ApiResponse();
|
||||
// try {
|
||||
// var data = jsonDecode(await request.readAsString());
|
||||
// var areaId = data['_id'];
|
||||
// var updatedArea = Area.fromJson(data);
|
||||
// if (updatedArea.id == null || updatedArea.id!.isEmpty) {
|
||||
// apiResponse.code = ResponseJsonCode.fail;
|
||||
// apiResponse.message = "区域ID不能为空";
|
||||
// String serializedJson = apiResponse.serialize();
|
||||
// return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
// }
|
||||
// var result = await areaService.updateArea(areaId, updatedArea);
|
||||
// apiResponse.code = 1;
|
||||
// apiResponse.message = result;
|
||||
// String serializedJson = apiResponse.serialize();
|
||||
// return Response(200, body: serializedJson); // 发送成功响应
|
||||
// } catch (e) {
|
||||
// apiResponse.code = -1;
|
||||
// apiResponse.message = "更新失败: $e"; // 包含异常信息
|
||||
// String serializedJson = apiResponse.serialize();
|
||||
// return Response(500, body: serializedJson); // 发送失败响应
|
||||
// }
|
||||
// }
|
||||
|
||||
// 删除区域
|
||||
// @RequestMapping(path: "/deleteArea", method: HttpMethod.DELETE)
|
||||
// Future<Response> deleteArea(Request request) async {
|
||||
// ApiResponse<String> apiResponse = ApiResponse();
|
||||
// try {
|
||||
// var data = jsonDecode(await request.readAsString());
|
||||
// var areaId = data['areaId'];
|
||||
// var result = await areaService.deleteArea(areaId);
|
||||
// apiResponse.code = 1;
|
||||
// if (result.isEmpty) {
|
||||
// apiResponse.code = ResponseJsonCode.success;
|
||||
// apiResponse.message = MessageConstants.DELETE_SUCCESS;
|
||||
// String serializedJson = apiResponse.serialize();
|
||||
// return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
// }
|
||||
// apiResponse.code = ResponseJsonCode.fail;
|
||||
// apiResponse.message = result;
|
||||
// String serializedJson = apiResponse.serialize();
|
||||
// return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
// } catch (e) {
|
||||
// apiResponse.code = -1;
|
||||
// apiResponse.message = "删除失败: $e"; // 包含异常信息
|
||||
// String serializedJson = apiResponse.serialize();
|
||||
// return Response(500, body: serializedJson); // 发送失败响应
|
||||
// }
|
||||
// }
|
||||
}
|
||||
24
bin/controller/AreaController.route.dart
Normal file
24
bin/controller/AreaController.route.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'AreaController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
[
|
||||
"/report/getInstantData",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.getInstantData,
|
||||
2,
|
||||
false
|
||||
]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
["/report/start", HttpResponseType.JSON, _callHandler.start, 1, false],
|
||||
["/report/end", HttpResponseType.JSON, _callHandler.end, 1, false]
|
||||
],
|
||||
};
|
||||
181
bin/controller/BedController.dart
Normal file
181
bin/controller/BedController.dart
Normal file
@@ -0,0 +1,181 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../model/Bed.dart';
|
||||
import '../service/BedService.dart';
|
||||
import '../model/Reservation.dart';
|
||||
|
||||
part 'BedController.route.dart';
|
||||
@RequestMapping(path: "/bed")
|
||||
class BedController {
|
||||
final BedService bedService = BedService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
BedController();
|
||||
|
||||
// 获取床位列表
|
||||
@RequestMapping(path: "/bedList", method: HttpMethod.GET)
|
||||
Future<Response> getBedList(Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
Bed query = Bed.fromQueryParameters(queryParameters,jwt);
|
||||
List<dynamic> bedList = await bedService.getBedList(query);
|
||||
int bedCount = await bedService.getBedCount(query);
|
||||
List<Map<String, dynamic>> bedListMap =
|
||||
bedList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = bedListMap;
|
||||
apiResponse.total = bedCount;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取单个床位信息
|
||||
/* @RequestMapping(path: "/getBed", method: HttpMethod.GET)
|
||||
Future<Response> getBedById(Request request) async {
|
||||
ApiResponse<Map<String, dynamic>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var bedId = data['bed_id'];
|
||||
if (bedId == null) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = '床位ID不能为空';
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送错误响应
|
||||
}
|
||||
var bed = await bedService.getBedById(bedId);
|
||||
if (bed != null) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = bed.toJson();
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} else {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = '未找到床位';
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送未找到响应
|
||||
}
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = '查询失败: $e';
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
} */
|
||||
|
||||
// 添加床位信息
|
||||
@RequestMapping(path: "/addBed", method: HttpMethod.POST)
|
||||
Future<Response> addBed(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var bed = Bed.fromJson(data);
|
||||
var result = await bedService.createBed(bed);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.ADD_ERROR; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 更新床位信息
|
||||
@RequestMapping(path: "/updateBed", method: HttpMethod.PUT)
|
||||
Future<Response> updateBed(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var bedId = data['bed_id'];
|
||||
var updatedBed = Bed.fromJson(data);
|
||||
if (updatedBed.id == null || updatedBed.id!.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "床位ID不能为空";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
var result = await bedService.updateBed(bedId, updatedBed);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "更新失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 删除床位信息
|
||||
@RequestMapping(path: "/deleteBed", method: HttpMethod.DELETE)
|
||||
Future<Response> deleteBed(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var bedId = data['bed_id'];
|
||||
var result = await bedService.deleteBed(bedId);
|
||||
if (result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.DELETE_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.DELETE_ERROR; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 查询预约信息
|
||||
@RequestMapping(path: "/orderCheckIn", method: HttpMethod.GET)
|
||||
Future<Response> orderCheckIn(Request request,Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
Reservation query = Reservation.fromQueryParameters(queryParameters,jwt);
|
||||
List<dynamic> bedList = await bedService.getOrderCheckIn(query);
|
||||
// int bedCount = await bedService.getBedCount(query);
|
||||
List<Map<String, dynamic>> bedListMap =
|
||||
bedList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = bedListMap;
|
||||
// apiResponse.total = bedCount;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
bin/controller/BedController.route.dart
Normal file
30
bin/controller/BedController.route.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'BedController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
["/bed/bedList", HttpResponseType.JSON, _callHandler.getBedList, 2, true],
|
||||
[
|
||||
"/bed/orderCheckIn",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.orderCheckIn,
|
||||
2,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
["/bed/addBed", HttpResponseType.JSON, _callHandler.addBed, 1, true]
|
||||
],
|
||||
HttpMethod.PUT: [
|
||||
["/bed/updateBed", HttpResponseType.JSON, _callHandler.updateBed, 1, true]
|
||||
],
|
||||
HttpMethod.DELETE: [
|
||||
["/bed/deleteBed", HttpResponseType.JSON, _callHandler.deleteBed, 1, true]
|
||||
],
|
||||
};
|
||||
121
bin/controller/BedTypeController.dart
Normal file
121
bin/controller/BedTypeController.dart
Normal file
@@ -0,0 +1,121 @@
|
||||
import 'dart:convert';
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
|
||||
import '../model/BedType.dart';
|
||||
import '../service/BedTypeService.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
|
||||
part 'BedTypeController.route.dart';
|
||||
@RequestMapping(path: "/bedType")
|
||||
class BedTypeController {
|
||||
final BedTypeService bedTypeService = BedTypeService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
BedTypeController();
|
||||
|
||||
// 获取床位类型列表
|
||||
@RequestMapping(path: "/bedTypeList", method: HttpMethod.GET)
|
||||
Future<Response> getBedTypeList(Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
BedType query = BedType.fromQueryParameters(queryParameters,jwt);
|
||||
List<dynamic> bedTypeList = await bedTypeService.getBedTypeList(query);
|
||||
int bedTypeCount = await bedTypeService.getBedTypeCount(query);
|
||||
List<Map<String, dynamic>> bedTypeListMap =
|
||||
bedTypeList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = bedTypeListMap;
|
||||
apiResponse.total = bedTypeCount;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加床位类型
|
||||
@RequestMapping(path: "/addBedType", method: HttpMethod.POST)
|
||||
Future<Response> addBedType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var bedType = BedType.fromJson(data);
|
||||
var result = await bedTypeService.addBedType(bedType);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.ADD_ERROR; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 更新床位类型
|
||||
@RequestMapping(path: "/updateBedType", method: HttpMethod.PUT)
|
||||
Future<Response> updateBedType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var bedTypeId = data['bed_type_id'];
|
||||
var updatedBedType = BedType.fromJson(data);
|
||||
if (updatedBedType.id == null || updatedBedType.id!.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "床位类型ID不能为空";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
var result =
|
||||
await bedTypeService.updateBedType(bedTypeId, updatedBedType);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "更新失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 删除床位类型
|
||||
@RequestMapping(path: "/deleteBedType", method: HttpMethod.DELETE)
|
||||
Future<Response> deleteBedType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var bedTypeId = data['bed_type_id'];
|
||||
var result = await bedTypeService.deleteBedType(bedTypeId);
|
||||
if (result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.DELETE_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.DELETE_ERROR; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
}
|
||||
47
bin/controller/BedTypeController.route.dart
Normal file
47
bin/controller/BedTypeController.route.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'BedTypeController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
[
|
||||
"/bedType/bedTypeList",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.getBedTypeList,
|
||||
2,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
[
|
||||
"/bedType/addBedType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.addBedType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.PUT: [
|
||||
[
|
||||
"/bedType/updateBedType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.updateBedType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.DELETE: [
|
||||
[
|
||||
"/bedType/deleteBedType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.deleteBedType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
};
|
||||
111
bin/controller/DictionaryTypeController.dart
Normal file
111
bin/controller/DictionaryTypeController.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../model/DictionaryType.dart';
|
||||
import '../service/DictionaryService.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
|
||||
part 'DictionaryTypeController.route.dart';
|
||||
@RequestMapping(path: "/dictionary")
|
||||
class DictionaryTypeController {
|
||||
final DictionaryService dictionaryService = DictionaryService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
DictionaryTypeController();
|
||||
|
||||
// 获取字典列表
|
||||
@RequestMapping(path: "/list", method: HttpMethod.GET)
|
||||
Future<Response> getDictionaryList(
|
||||
Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
DictionaryType query =
|
||||
DictionaryType.fromQueryParameters(queryParameters, jwt);
|
||||
List<DictionaryType> dictionaryList =
|
||||
await dictionaryService.getDictionaryList(query);
|
||||
List<Map<String, dynamic>> dictionaryListMap =
|
||||
dictionaryList.map((e) => e.toJson()).toList(); // 转换为 Map
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = dictionaryListMap;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加字典
|
||||
@RequestMapping(path: "/add", method: HttpMethod.POST)
|
||||
Future<Response> addDictionary(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var dictionary = DictionaryType.fromJson(data);
|
||||
var result = await dictionaryService.addDictionary(dictionary);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "添加失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 更新字典
|
||||
@RequestMapping(path: "/update", method: HttpMethod.PUT)
|
||||
Future<Response> updateDictionary(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var dictionaryId = data['_id'];
|
||||
var updatedDictionary = DictionaryType.fromJson(data);
|
||||
var result = await dictionaryService.updateDictionary(
|
||||
dictionaryId, updatedDictionary);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "更新失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 删除字典
|
||||
@RequestMapping(path: "/delete", method: HttpMethod.DELETE)
|
||||
Future<Response> deleteDictionary(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var dictionaryId = data['_id'];
|
||||
var result = await dictionaryService.deleteDictionary(dictionaryId);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "删除失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
}
|
||||
47
bin/controller/DictionaryTypeController.route.dart
Normal file
47
bin/controller/DictionaryTypeController.route.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'DictionaryTypeController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
[
|
||||
"/dictionary/list",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.getDictionaryList,
|
||||
2,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
[
|
||||
"/dictionary/add",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.addDictionary,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.PUT: [
|
||||
[
|
||||
"/dictionary/update",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.updateDictionary,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.DELETE: [
|
||||
[
|
||||
"/dictionary/delete",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.deleteDictionary,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
};
|
||||
117
bin/controller/DiseaseTypeController.dart
Normal file
117
bin/controller/DiseaseTypeController.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'dart:convert';
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
|
||||
import '../model/DiseaseType.dart';
|
||||
import '../service/DiseaseTypeService.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
|
||||
part 'DiseaseTypeController.route.dart';
|
||||
@RequestMapping(path: "/diseaseType")
|
||||
class DiseaseTypeController {
|
||||
final DiseaseTypeService diseaseTypeService = DiseaseTypeService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
DiseaseTypeController();
|
||||
|
||||
// 获取疾病类型列表
|
||||
@RequestMapping(path: "/diseaseTypeList", method: HttpMethod.GET)
|
||||
Future<Response> getDiseaseTypeList(Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
DiseaseType query = DiseaseType.fromQueryParameters(queryParameters,jwt);
|
||||
List<dynamic> diseaseTypeList = await diseaseTypeService.getDiseaseTypeList(query);
|
||||
int diseaseTypeCount = await diseaseTypeService.getDiseaseTypeCount(query);
|
||||
List<Map<String, dynamic>> diseaseTypeListMap =
|
||||
diseaseTypeList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = diseaseTypeListMap;
|
||||
apiResponse.total = diseaseTypeCount;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加疾病类型
|
||||
@RequestMapping(path: "/addDiseaseType", method: HttpMethod.POST)
|
||||
Future<Response> addDiseaseType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var diseaseType = DiseaseType.fromJson(data);
|
||||
var result = await diseaseTypeService.addDiseaseType(diseaseType);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.ADD_ERROR; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 更新疾病类型
|
||||
@RequestMapping(path: "/updateDiseaseType", method: HttpMethod.PUT)
|
||||
Future<Response> updateDiseaseType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var diseaseTypeId = data['_id'];
|
||||
var updatedDiseaseType = DiseaseType.fromJson(data);
|
||||
if (updatedDiseaseType.id == null || updatedDiseaseType.id!.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "疾病类型ID不能为空";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
var result = await diseaseTypeService.updateDiseaseType(diseaseTypeId, updatedDiseaseType);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "更新失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 删除疾病类型
|
||||
@RequestMapping(path: "/deleteDiseaseType", method: HttpMethod.DELETE)
|
||||
Future<Response> deleteDiseaseType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var diseaseTypeId = data['id'];
|
||||
var result = await diseaseTypeService.deleteDiseaseType(diseaseTypeId);
|
||||
if (result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.DELETE_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.DELETE_ERROR; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
}
|
||||
47
bin/controller/DiseaseTypeController.route.dart
Normal file
47
bin/controller/DiseaseTypeController.route.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'DiseaseTypeController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
[
|
||||
"/diseaseType/diseaseTypeList",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.getDiseaseTypeList,
|
||||
2,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
[
|
||||
"/diseaseType/addDiseaseType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.addDiseaseType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.PUT: [
|
||||
[
|
||||
"/diseaseType/updateDiseaseType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.updateDiseaseType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.DELETE: [
|
||||
[
|
||||
"/diseaseType/deleteDiseaseType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.deleteDiseaseType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
};
|
||||
98
bin/controller/FileUploadController.dart
Normal file
98
bin/controller/FileUploadController.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:shelf_multipart/shelf_multipart.dart'; // 导入 shelf_multipart 插件
|
||||
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
|
||||
part 'FileUploadController.route.dart';
|
||||
@RequestMapping(path: "/file")
|
||||
class FileUploadController {
|
||||
FileUploadController();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
// 上传文件
|
||||
@RequestMapping(path: "/upload", method: HttpMethod.POST)
|
||||
Future<Response> uploadFile(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
request.formData();
|
||||
|
||||
try {
|
||||
// 检查请求的 Content-Type 是否为 multipart/form-data
|
||||
var contentType = request.headers['content-type'];
|
||||
if (contentType == null ||
|
||||
!contentType.startsWith('multipart/form-data')) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "请求格式必须是 multipart/form-data";
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: apiResponse.serialize());
|
||||
}
|
||||
if (request.formData() case var form?) {
|
||||
String description = "上传成功";
|
||||
String bucket = "";
|
||||
String? fileExtension; // 文件后缀
|
||||
|
||||
var file;
|
||||
await for (final formData in form.formData) {
|
||||
if (formData.name == 'bucket') {
|
||||
bucket = await formData.part.readString();
|
||||
}
|
||||
if (formData.name == 'file') {
|
||||
final filename = formData.filename;
|
||||
if (filename != null && filename.isNotEmpty) {
|
||||
fileExtension = filename.split('.').last; // 提取文件后缀
|
||||
}
|
||||
file = await formData.part.readBytes();
|
||||
}
|
||||
}
|
||||
if (bucket.isEmpty) {
|
||||
description = "桶名不能为空";
|
||||
}
|
||||
if (file == null) {
|
||||
description = "文件不能为空";
|
||||
}
|
||||
final String folderName =
|
||||
DateFormat('yyyy-MM-dd').format(DateTime.now());
|
||||
String objectName =
|
||||
"$folderName/${DateTime.now().millisecondsSinceEpoch}.$fileExtension";
|
||||
// 创建存储桶(如果不存在)
|
||||
await EasyDartModule.storage.createBucket(bucket);
|
||||
|
||||
// 上传文件
|
||||
var path =
|
||||
await EasyDartModule.storage.uploadObject(bucket, objectName, file);
|
||||
|
||||
// EasyDartModule.storage.getObject(bucket, objectName).then((data) {
|
||||
// print("下载文件");
|
||||
// File("b.gif").writeAsBytesSync(data);
|
||||
// print("下载完毕");
|
||||
// });
|
||||
return Response.ok(path);
|
||||
} else if (request.multipart() case var multipart?) {
|
||||
final description = StringBuffer('Regular multipart request\n');
|
||||
|
||||
await for (final part in multipart.parts) {
|
||||
description.writeln('new part');
|
||||
|
||||
part.headers.forEach(
|
||||
(key, value) => description.writeln('Header $key=$value'));
|
||||
final content = await part.readString();
|
||||
description.writeln('content: $content');
|
||||
|
||||
description.writeln('end of part');
|
||||
}
|
||||
return Response.ok(description.toString());
|
||||
} else {
|
||||
return Response.ok('Not a multipart request');
|
||||
}
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "文件上传失败: $e";
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: apiResponse.serialize());
|
||||
}
|
||||
}
|
||||
}
|
||||
14
bin/controller/FileUploadController.route.dart
Normal file
14
bin/controller/FileUploadController.route.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'FileUploadController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.POST: [
|
||||
["/file/upload", HttpResponseType.JSON, _callHandler.uploadFile, 1, true]
|
||||
],
|
||||
};
|
||||
114
bin/controller/PersonController.dart
Normal file
114
bin/controller/PersonController.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../model/Person.dart';
|
||||
import '../service/PersonService.dart';
|
||||
|
||||
part 'PersonController.route.dart';
|
||||
@RequestMapping(path: "/person")
|
||||
class PersonController {
|
||||
final PersonService personService = PersonService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
PersonController();
|
||||
|
||||
// 获取人员列表
|
||||
@RequestMapping(path: "/personList", method: HttpMethod.GET)
|
||||
Future<Response> getPersonList(
|
||||
Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
Person query = Person.fromQueryParameters(queryParameters, jwt);
|
||||
var personList = await personService.getPersonList(query);
|
||||
int personCount = await personService.getPersonCount(query);
|
||||
print(personList);
|
||||
List<Map<String, dynamic>> personListMap =
|
||||
personList.map((e) => e as Map<String, dynamic>).toList();
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = personListMap;
|
||||
apiResponse.total = personCount;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加人员
|
||||
@RequestMapping(path: "/addPerson", method: HttpMethod.POST)
|
||||
Future<Response> addPerson(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var person = Person.fromJson(data);
|
||||
var result = await personService.addPerson(person);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.ADD_ERROR;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新人员信息
|
||||
@RequestMapping(path: "/updatePerson", method: HttpMethod.PUT)
|
||||
Future<Response> updatePerson(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var personId = data['_id'];
|
||||
var updatedPerson = Person.fromJson(data);
|
||||
var result = await personService.updatePerson(personId, updatedPerson);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "更新失败: $e";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除人员
|
||||
@RequestMapping(path: "/deletePerson", method: HttpMethod.DELETE)
|
||||
Future<Response> deletePerson(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var personId = data['_id'];
|
||||
var result = await personService.deletePerson(personId);
|
||||
if (result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.DELETE_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "删除失败: $e";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
bin/controller/PersonController.route.dart
Normal file
47
bin/controller/PersonController.route.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'PersonController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
[
|
||||
"/person/personList",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.getPersonList,
|
||||
2,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
[
|
||||
"/person/addPerson",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.addPerson,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.PUT: [
|
||||
[
|
||||
"/person/updatePerson",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.updatePerson,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.DELETE: [
|
||||
[
|
||||
"/person/deletePerson",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.deletePerson,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
};
|
||||
111
bin/controller/PersonTypeController.dart
Normal file
111
bin/controller/PersonTypeController.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
|
||||
import '../model/PersonType.dart';
|
||||
import '../service/PersonTypeService.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
|
||||
part 'PersonTypeController.route.dart';
|
||||
@RequestMapping(path: "/personType")
|
||||
class PersonTypeController {
|
||||
final PersonTypeService personTypeService = PersonTypeService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
PersonTypeController();
|
||||
|
||||
// 获取人员类型列表
|
||||
@RequestMapping(path: "/personTypeList", method: HttpMethod.GET)
|
||||
Future<Response> getPersonTypeList(Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
PersonType query = PersonType.fromQueryParameters(queryParameters,jwt);
|
||||
var personTypeList = await personTypeService.getPersonTypeList(query);
|
||||
List<Map<String, dynamic>> personTypeListMap =
|
||||
personTypeList.map((e) => e as Map<String, dynamic>).toList();
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = personTypeListMap;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加人员类型
|
||||
@RequestMapping(path: "/addPersonType", method: HttpMethod.POST)
|
||||
Future<Response> addPersonType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var personType = PersonType.fromJson(data);
|
||||
var result = await personTypeService.addPersonType(personType);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.ADD_ERROR;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新人员类型
|
||||
@RequestMapping(path: "/updatePersonType", method: HttpMethod.PUT)
|
||||
Future<Response> updatePersonType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var personTypeId = data['person_type_id'];
|
||||
var updatedPersonType = PersonType.fromJson(data);
|
||||
var result = await personTypeService.updatePersonType(
|
||||
personTypeId, updatedPersonType);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.UPDATE_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "更新失败: $e";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除人员类型
|
||||
@RequestMapping(path: "/deletePersonType", method: HttpMethod.DELETE)
|
||||
Future<Response> deletePersonType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var personTypeId = data['person_type_id'];
|
||||
var result = await personTypeService.deletePersonType(personTypeId);
|
||||
if (result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.DELETE_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "删除失败: $e";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
bin/controller/PersonTypeController.route.dart
Normal file
47
bin/controller/PersonTypeController.route.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'PersonTypeController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
[
|
||||
"/personType/personTypeList",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.getPersonTypeList,
|
||||
2,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
[
|
||||
"/personType/addPersonType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.addPersonType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.PUT: [
|
||||
[
|
||||
"/personType/updatePersonType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.updatePersonType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.DELETE: [
|
||||
[
|
||||
"/personType/deletePersonType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.deletePersonType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
};
|
||||
235
bin/controller/RoomController.dart
Normal file
235
bin/controller/RoomController.dart
Normal file
@@ -0,0 +1,235 @@
|
||||
import 'dart:convert';
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
import '../model/Room.dart';
|
||||
import '../service/RoomService.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
import '../const/HttpStatusCode.dart';
|
||||
|
||||
part 'RoomController.route.dart';
|
||||
@RequestMapping(path: "/room")
|
||||
class RoomController {
|
||||
final RoomService roomService = RoomService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
RoomController();
|
||||
|
||||
// 获取房间列表
|
||||
@RequestMapping(path: "/roomList", method: HttpMethod.GET)
|
||||
Future<Response> getRoomList(
|
||||
Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
Room query = Room.fromQueryParameters(queryParameters, jwt);
|
||||
List<dynamic> roomList = await roomService.getRoomList(query,
|
||||
page: queryParameters['page'] == null
|
||||
? 1
|
||||
: int.parse(queryParameters['page']!),
|
||||
pageSize: queryParameters['limit'] == null
|
||||
? 10
|
||||
: int.parse(queryParameters['limit']!));
|
||||
int roomTypeCount = await roomService.getRoomCount(query);
|
||||
List<Map<String, dynamic>> roomListMap =
|
||||
roomList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data = roomListMap;
|
||||
apiResponse.total = roomTypeCount;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加房间
|
||||
@RequestMapping(path: "/addRoom", method: HttpMethod.POST)
|
||||
Future<Response> addRoom(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var room = Room.fromJson(data);
|
||||
var result = await roomService.addRoom(room);
|
||||
if (result == null || result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "添加失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(500, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 更新房间
|
||||
@RequestMapping(path: "/updateRoom", method: HttpMethod.PUT)
|
||||
Future<Response> updateRoom(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var roomId = data['_id'];
|
||||
var updatedRoom = Room.fromJson(data);
|
||||
if (updatedRoom.id == null || updatedRoom.id!.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "房间类型ID不能为空";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
var result = await roomService.updateRoom(roomId, updatedRoom);
|
||||
apiResponse.code = 1;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(200, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = -1;
|
||||
apiResponse.message = "更新失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(500, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 删除房间
|
||||
@RequestMapping(path: "/deleteRoom", method: HttpMethod.DELETE)
|
||||
Future<Response> deleteRoom(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var roomId = data['roomId'];
|
||||
var result = await roomService.deleteRoom(roomId);
|
||||
apiResponse.code = 1;
|
||||
if (result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.DELETE_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = -1;
|
||||
apiResponse.message = "删除失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(500, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
//办理预约信息
|
||||
@RequestMapping(path: "/addOrderCheckIn", method: HttpMethod.POST)
|
||||
Future<Response> addOrderCheckIn(
|
||||
Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var result = await roomService.addOrderCheckIn(data,jwt);
|
||||
if (result == null || result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
roomService.addReservationMessage(data, jwt);
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "添加失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(500, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
//删除预约入住信息
|
||||
@RequestMapping(path: "/delOrderCheckIn", method: HttpMethod.POST)
|
||||
Future<Response> delOrderCheckIn(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var result = await roomService.delOrderCheckIn(data);
|
||||
if (result == null || result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "添加失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(500, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
//办理入住信息
|
||||
@RequestMapping(path: "/addRuzhuCheckIn", method: HttpMethod.POST)
|
||||
Future<Response> addRuzhuCheckIn(
|
||||
Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var result = await roomService.addRuzhuCheckIn(data, jwt);
|
||||
if (result == null || result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "添加失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(500, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//办理退住信息
|
||||
@RequestMapping(path: "/checkout", method: HttpMethod.POST)
|
||||
Future<Response> checkout(
|
||||
Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var result = await roomService.checkout(data, jwt);
|
||||
if (result == null || result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "添加失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(500, body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
}
|
||||
57
bin/controller/RoomController.route.dart
Normal file
57
bin/controller/RoomController.route.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'RoomController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
["/room/roomList", HttpResponseType.JSON, _callHandler.getRoomList, 2, true]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
["/room/addRoom", HttpResponseType.JSON, _callHandler.addRoom, 1, true],
|
||||
[
|
||||
"/room/addOrderCheckIn",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.addOrderCheckIn,
|
||||
2,
|
||||
true
|
||||
],
|
||||
[
|
||||
"/room/delOrderCheckIn",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.delOrderCheckIn,
|
||||
1,
|
||||
true
|
||||
],
|
||||
[
|
||||
"/room/addRuzhuCheckIn",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.addRuzhuCheckIn,
|
||||
2,
|
||||
true
|
||||
],
|
||||
["/room/checkout", HttpResponseType.JSON, _callHandler.checkout, 2, true]
|
||||
],
|
||||
HttpMethod.PUT: [
|
||||
[
|
||||
"/room/updateRoom",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.updateRoom,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.DELETE: [
|
||||
[
|
||||
"/room/deleteRoom",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.deleteRoom,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
};
|
||||
122
bin/controller/RoomTypeController.dart
Normal file
122
bin/controller/RoomTypeController.dart
Normal file
@@ -0,0 +1,122 @@
|
||||
import 'dart:convert';
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:EasyDartModule/base/webserver/WebServer.dart';
|
||||
|
||||
import '../model/RoomType.dart';
|
||||
import '../service/RoomTypeService.dart';
|
||||
import '../model/ApiResponse.dart';
|
||||
import '../const/HttpStatusCode.dart';
|
||||
import '../const/MessageConstants.dart';
|
||||
import '../const/ResponseJsonCode.dart';
|
||||
|
||||
part 'RoomTypeController.route.dart';
|
||||
@RequestMapping(path: "/roomType")
|
||||
class RoomTypeController {
|
||||
final RoomTypeService roomTypeService = RoomTypeService();
|
||||
set callHandler(handler) => _callHandler = handler;
|
||||
Map<HttpMethod, List<List>> get routeMap => routes;
|
||||
|
||||
RoomTypeController();
|
||||
|
||||
// 获取房间类型列表
|
||||
@RequestMapping(path: "/roomTypeList", method: HttpMethod.GET)
|
||||
Future<Response> getRoomTypeList(Request request, Map<String, dynamic> jwt) async {
|
||||
ApiResponse<List<Map<String, dynamic>>> apiResponse = ApiResponse();
|
||||
try {
|
||||
var queryParameters = request.requestedUri.queryParameters;
|
||||
RoomType query = RoomType.fromQueryParameters(queryParameters,jwt);
|
||||
List<dynamic> roomTypeList = await roomTypeService.getRoomTypeList(query);
|
||||
int roomTypeCount = await roomTypeService.getRoomTypeCount(query);
|
||||
List<Map<String, dynamic>> roomTypeListMap =
|
||||
roomTypeList.map((e) => e as Map<String, dynamic>).toList(); // 强制转换
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.data =
|
||||
roomTypeListMap;
|
||||
apiResponse.total = roomTypeCount;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "查询失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError, body: serializedJson);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加房间类型
|
||||
@RequestMapping(path: "/addRoomType", method: HttpMethod.POST)
|
||||
Future<Response> addRoomType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var roomType = RoomType.fromJson(data);
|
||||
var result = await roomTypeService.addRoomType(roomType);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.ADD_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.ADD_ERROR; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 更新房间类型
|
||||
@RequestMapping(path: "/updateRoomType", method: HttpMethod.PUT)
|
||||
Future<Response> updateRoomType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var roomTypeId = data['_id'];
|
||||
var updatedRoomType = RoomType.fromJson(data);
|
||||
if (updatedRoomType.id == null || updatedRoomType.id!.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "房间类型ID不能为空";
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
}
|
||||
var result =
|
||||
await roomTypeService.updateRoomType(roomTypeId, updatedRoomType);
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = "更新失败: $e"; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
|
||||
// 删除房间类型
|
||||
@RequestMapping(path: "/deleteRoomType", method: HttpMethod.DELETE)
|
||||
Future<Response> deleteRoomType(Request request) async {
|
||||
ApiResponse<String> apiResponse = ApiResponse();
|
||||
try {
|
||||
var data = jsonDecode(await request.readAsString());
|
||||
var roomTypeId = data['id'];
|
||||
var result = await roomTypeService.deleteRoomType(roomTypeId);
|
||||
if (result.isEmpty) {
|
||||
apiResponse.code = ResponseJsonCode.success;
|
||||
apiResponse.message = MessageConstants.DELETE_SUCCESS;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson); // 发送成功响应
|
||||
}
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = result;
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.ok, body: serializedJson);
|
||||
} catch (e) {
|
||||
apiResponse.code = ResponseJsonCode.fail;
|
||||
apiResponse.message = MessageConstants.DELETE_ERROR; // 包含异常信息
|
||||
String serializedJson = apiResponse.serialize();
|
||||
return Response(HttpStatusCode.internalServerError,
|
||||
body: serializedJson); // 发送失败响应
|
||||
}
|
||||
}
|
||||
}
|
||||
47
bin/controller/RoomTypeController.route.dart
Normal file
47
bin/controller/RoomTypeController.route.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// **************************************************************************
|
||||
// RouteGenerator
|
||||
// **************************************************************************
|
||||
|
||||
part of 'RoomTypeController.dart';
|
||||
|
||||
late var _callHandler;
|
||||
final Map<HttpMethod, List<List>> routes = {
|
||||
HttpMethod.GET: [
|
||||
[
|
||||
"/roomType/roomTypeList",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.getRoomTypeList,
|
||||
2,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.POST: [
|
||||
[
|
||||
"/roomType/addRoomType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.addRoomType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.PUT: [
|
||||
[
|
||||
"/roomType/updateRoomType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.updateRoomType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
HttpMethod.DELETE: [
|
||||
[
|
||||
"/roomType/deleteRoomType",
|
||||
HttpResponseType.JSON,
|
||||
_callHandler.deleteRoomType,
|
||||
1,
|
||||
true
|
||||
]
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user