|
|
@@ -1,8 +1,6 @@
|
|
|
-import 'dart:math';
|
|
|
-
|
|
|
+import 'package:chicken_farm/core/api/api_service.dart';
|
|
|
import 'package:chicken_farm/modes/breeding/batch.dart';
|
|
|
import 'package:chicken_farm/modes/breeding/family.dart';
|
|
|
-import 'package:chicken_farm/modes/breeding/wing_tag_num.dart';
|
|
|
import 'package:chicken_farm/modes/api/page_model.dart';
|
|
|
|
|
|
class BreedQueryApi {
|
|
|
@@ -12,229 +10,39 @@ class BreedQueryApi {
|
|
|
|
|
|
BreedQueryApi._internal();
|
|
|
|
|
|
- // 预生成的批次模拟数据,仅包含必填字段
|
|
|
- static final List<BatchModel> _mockBatchData = [
|
|
|
- BatchModel(batchNum: 'BATCH001', batchName: '批次一号'),
|
|
|
- BatchModel(batchNum: 'BATCH002', batchName: '批次二号'),
|
|
|
- BatchModel(batchNum: 'BATCH003', batchName: '批次三号'),
|
|
|
- BatchModel(batchNum: 'BATCH004', batchName: '批次四号'),
|
|
|
- BatchModel(batchNum: 'BATCH005', batchName: '批次五号'),
|
|
|
- BatchModel(batchNum: 'BATCH006', batchName: '批次六号'),
|
|
|
- BatchModel(batchNum: 'BATCH007', batchName: '批次七号'),
|
|
|
- BatchModel(batchNum: 'BATCH008', batchName: '批次八号'),
|
|
|
- BatchModel(batchNum: 'BATCH009', batchName: '批次九号'),
|
|
|
- BatchModel(batchNum: 'BATCH010', batchName: '批次十号'),
|
|
|
- BatchModel(batchNum: 'BATCH011', batchName: '批次十一号'),
|
|
|
- BatchModel(batchNum: 'BATCH012', batchName: '批次十二号'),
|
|
|
- BatchModel(batchNum: 'BATCH013', batchName: '批次十三号'),
|
|
|
- BatchModel(batchNum: 'BATCH014', batchName: '批次十四号'),
|
|
|
- BatchModel(batchNum: 'BATCH015', batchName: '批次十五号'),
|
|
|
- BatchModel(batchNum: 'BATCH016', batchName: '批次十六号'),
|
|
|
- BatchModel(batchNum: 'BATCH017', batchName: '批次十七号'),
|
|
|
- BatchModel(batchNum: 'BATCH018', batchName: '批次十八号'),
|
|
|
- BatchModel(batchNum: 'BATCH019', batchName: '批次十九号'),
|
|
|
- BatchModel(batchNum: 'BATCH020', batchName: '批次二十号'),
|
|
|
- ];
|
|
|
-
|
|
|
- // 预生成的翅号模拟数据,仅包含必填字段
|
|
|
- static final List<WingTagNumModel> _mockWingTagData = [
|
|
|
- WingTagNumModel(wingTagNum: 'WING0001'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0002'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0003'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0004'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0005'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0006'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0007'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0008'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0009'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0010'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0011'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0012'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0013'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0014'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0015'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0016'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0017'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0018'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0019'),
|
|
|
- WingTagNumModel(wingTagNum: 'WING0020'),
|
|
|
- ];
|
|
|
-
|
|
|
- // 预生成的家系模拟数据,仅包含必填字段
|
|
|
- static final List<FamilyModel> _mockFamilyData = [
|
|
|
- FamilyModel(id: 1, familyNum: 'FAM001'),
|
|
|
- FamilyModel(id: 2, familyNum: 'FAM002'),
|
|
|
- FamilyModel(id: 3, familyNum: 'FAM003'),
|
|
|
- FamilyModel(id: 4, familyNum: 'FAM004'),
|
|
|
- FamilyModel(id: 5, familyNum: 'FAM005'),
|
|
|
- FamilyModel(id: 6, familyNum: 'FAM006'),
|
|
|
- FamilyModel(id: 7, familyNum: 'FAM007'),
|
|
|
- FamilyModel(id: 8, familyNum: 'FAM008'),
|
|
|
- FamilyModel(id: 9, familyNum: 'FAM009'),
|
|
|
- FamilyModel(id: 10, familyNum: 'FAM010'),
|
|
|
- FamilyModel(id: 11, familyNum: 'FAM011'),
|
|
|
- FamilyModel(id: 12, familyNum: 'FAM012'),
|
|
|
- FamilyModel(id: 13, familyNum: 'FAM013'),
|
|
|
- FamilyModel(id: 14, familyNum: 'FAM014'),
|
|
|
- FamilyModel(id: 15, familyNum: 'FAM015'),
|
|
|
- FamilyModel(id: 16, familyNum: 'FAM016'),
|
|
|
- FamilyModel(id: 17, familyNum: 'FAM017'),
|
|
|
- FamilyModel(id: 18, familyNum: 'FAM018'),
|
|
|
- FamilyModel(id: 19, familyNum: 'FAM019'),
|
|
|
- FamilyModel(id: 20, familyNum: 'FAM020'),
|
|
|
- ];
|
|
|
+ static final String apiPrefix = '/app/breeding';
|
|
|
|
|
|
Future<PageResultModel<BatchModel>> queryPageBatchs(dynamic query) async {
|
|
|
- // 模拟数据 - 注释掉原来的API调用
|
|
|
- /*final response = await ApiService().get(
|
|
|
- '/app/breeding/listBatch',
|
|
|
+ final result = await ApiService().get(
|
|
|
+ '$apiPrefix/listBatch/${query['keyword']}',
|
|
|
queryParameters: query,
|
|
|
);
|
|
|
- if (response == null) return PageResultModel.empty();
|
|
|
- final List<BatchModel> rows = (response['rows'] as List)
|
|
|
- .map((e) => BatchModel.fromJson(e))
|
|
|
- .toList();
|
|
|
- return PageResultModel<BatchModel>(rows: rows, total: response['total']);*/
|
|
|
-
|
|
|
- // 使用预生成的模拟数据
|
|
|
- // 根据keyword筛选数据
|
|
|
- List<BatchModel> filteredData = _mockBatchData;
|
|
|
- if (query != null &&
|
|
|
- query['keyword'] != null &&
|
|
|
- query['keyword'].toString().isNotEmpty) {
|
|
|
- final keyword = query['keyword'].toString().toLowerCase();
|
|
|
- filteredData = _mockBatchData
|
|
|
- .where((batch) => batch.batchNum.toLowerCase().contains(keyword))
|
|
|
+ if (result.success) {
|
|
|
+ final List<BatchModel> rows = (result.data['rows'] as List)
|
|
|
+ .map((e) => BatchModel.fromJson(e))
|
|
|
.toList();
|
|
|
+ return PageResultModel<BatchModel>(
|
|
|
+ rows: rows,
|
|
|
+ total: result.data['total'],
|
|
|
+ );
|
|
|
}
|
|
|
-
|
|
|
- int page = query != null && query['pageNum'] != null
|
|
|
- ? query['pageNum'] as int
|
|
|
- : 1;
|
|
|
- int pageSize = query != null && query['pageSize'] != null
|
|
|
- ? query['pageSize'] as int
|
|
|
- : 10;
|
|
|
- int startIndex = (page - 1) * pageSize;
|
|
|
- int endIndex = startIndex + pageSize < filteredData.length
|
|
|
- ? startIndex + pageSize
|
|
|
- : filteredData.length;
|
|
|
-
|
|
|
- List<BatchModel> pageRows = startIndex < filteredData.length
|
|
|
- ? filteredData.sublist(startIndex, endIndex)
|
|
|
- : [];
|
|
|
-
|
|
|
- return PageResultModel<BatchModel>(
|
|
|
- rows: pageRows,
|
|
|
- total: filteredData.length,
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- Future<PageResultModel<WingTagNumModel>> queryPageWingTags(
|
|
|
- dynamic query,
|
|
|
- ) async {
|
|
|
- // 模拟数据 - 注释掉原来的API调用
|
|
|
- /*final response = await ApiService().get(
|
|
|
- '/app/breeding/listWingTag',
|
|
|
- queryParameters: query,
|
|
|
- );
|
|
|
- if (response == null) return PageResultModel.empty();
|
|
|
- final List<WingTagNumModel> rows = (response['rows'] as List)
|
|
|
- .map((e) => WingTagNumModel.fromJson(e))
|
|
|
- .toList();
|
|
|
- return PageResultModel<WingTagNumModel>(
|
|
|
- rows: rows,
|
|
|
- total: response['total'],
|
|
|
- );*/
|
|
|
-
|
|
|
- // 使用预生成的模拟数据
|
|
|
- int page = query != null && query['pageNum'] != null
|
|
|
- ? query['pageNum'] as int
|
|
|
- : 1;
|
|
|
- int pageSize = query != null && query['pageSize'] != null
|
|
|
- ? query['pageSize'] as int
|
|
|
- : 10;
|
|
|
- int startIndex = (page - 1) * pageSize;
|
|
|
- int endIndex = startIndex + pageSize < _mockWingTagData.length
|
|
|
- ? startIndex + pageSize
|
|
|
- : _mockWingTagData.length;
|
|
|
-
|
|
|
- List<WingTagNumModel> pageRows = startIndex < _mockWingTagData.length
|
|
|
- ? _mockWingTagData.sublist(startIndex, endIndex)
|
|
|
- : [];
|
|
|
-
|
|
|
- return PageResultModel<WingTagNumModel>(
|
|
|
- rows: pageRows,
|
|
|
- total: _mockWingTagData.length,
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- Future<List<WingTagNumModel>> queryWingTags(dynamic query) async {
|
|
|
- // 模拟数据 - 注释掉原来的API调用
|
|
|
- /*final response = await ApiService().get(
|
|
|
- '/app/breeding/listWingTag',
|
|
|
- queryParameters: query,
|
|
|
- );
|
|
|
- if (response == null) return [];
|
|
|
- return response
|
|
|
- .map<WingTagNumModel>((e) => WingTagNumModel.fromJson(e))
|
|
|
- .toList();*/
|
|
|
-
|
|
|
- // 使用预生成的模拟数据,随机返回5-10条
|
|
|
- final random = Random();
|
|
|
- final count = 5 + random.nextInt(6); // 5到10之间的随机数
|
|
|
- final indices = <int>{};
|
|
|
-
|
|
|
- // 随机选择不重复的索引
|
|
|
- while (indices.length < count) {
|
|
|
- indices.add(random.nextInt(_mockWingTagData.length));
|
|
|
- }
|
|
|
-
|
|
|
- // 根据索引获取数据
|
|
|
- return indices.map((index) => _mockWingTagData[index]).toList();
|
|
|
+ return PageResultModel.empty();
|
|
|
}
|
|
|
|
|
|
Future<PageResultModel<FamilyModel>> queryPageFamilys(dynamic query) async {
|
|
|
- // 模拟数据 - 注释掉原来的API调用
|
|
|
- /*final response = await ApiService().get(
|
|
|
- '/app/breeding/listFamily',
|
|
|
+ final result = await ApiService().get(
|
|
|
+ '$apiPrefix/listFamily/${query['keyword']}',
|
|
|
queryParameters: query,
|
|
|
);
|
|
|
- if (response == null) return PageResultModel.empty();
|
|
|
- final List<FamilyModel> rows = (response['rows'] as List)
|
|
|
- .map((e) => FamilyModel.fromJson(e))
|
|
|
- .toList();
|
|
|
- return PageResultModel<FamilyModel>(rows: rows, total: response['total']);*/
|
|
|
-
|
|
|
- // 使用预生成的模拟数据
|
|
|
- // 根据keyword筛选数据
|
|
|
- List<FamilyModel> filteredData = _mockFamilyData;
|
|
|
- if (query != null &&
|
|
|
- query['keyword'] != null &&
|
|
|
- query['keyword'].toString().isNotEmpty) {
|
|
|
- final keyword = query['keyword'].toString().toLowerCase();
|
|
|
- filteredData = _mockFamilyData
|
|
|
- .where((family) => family.familyNum.toLowerCase().contains(keyword))
|
|
|
+ if (result.success) {
|
|
|
+ final List<FamilyModel> rows = (result.data['rows'] as List)
|
|
|
+ .map((e) => FamilyModel.fromJson(e))
|
|
|
.toList();
|
|
|
+ return PageResultModel<FamilyModel>(
|
|
|
+ rows: rows,
|
|
|
+ total: result.data['total'],
|
|
|
+ );
|
|
|
}
|
|
|
-
|
|
|
- int page = query != null && query['pageNum'] != null
|
|
|
- ? query['pageNum'] as int
|
|
|
- : 1;
|
|
|
- int pageSize = query != null && query['pageSize'] != null
|
|
|
- ? query['pageSize'] as int
|
|
|
- : 10;
|
|
|
- int startIndex = (page - 1) * pageSize;
|
|
|
- int endIndex = startIndex + pageSize < filteredData.length
|
|
|
- ? startIndex + pageSize
|
|
|
- : filteredData.length;
|
|
|
-
|
|
|
- List<FamilyModel> pageRows = startIndex < filteredData.length
|
|
|
- ? filteredData.sublist(startIndex, endIndex)
|
|
|
- : [];
|
|
|
-
|
|
|
- return PageResultModel<FamilyModel>(
|
|
|
- rows: pageRows,
|
|
|
- total: filteredData.length,
|
|
|
- );
|
|
|
+ return PageResultModel.empty();
|
|
|
}
|
|
|
}
|