1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* 支持服务查询API
*/
public with sharing class psp_GetCareProgramsApi {

/**
* 获取查询CareProgram(子查询:Care Program Product),条件:Status: In Progress
* @param items 请求项
* @param response 响应
* @return void
*/
public static void getCarePrograms(
List<psp_GenericApiRequest.RequestItem> items,
psp_GenericApiResponse response
) {
try {
// 调用 DAO 层获取进行中的 CareProgram 及其关联的 CareProgramProduct
List<SObject> activePrograms = psp_CareProgramProductDao.getActiveCareProgramsWithProducts();

// 将结果添加到每个请求项
for (psp_GenericApiRequest.RequestItem item : items) {
psp_GenericApiService.addResult(
response,
item,
'Success',
'成功获取进行中的支持项目列表',
null,
null,
activePrograms
);
}

System.debug('✅ 成功返回 ' + activePrograms.size() + ' 个进行中的支持项目');

} catch (Exception e) {
// 为每个请求项返回失败结果
for (psp_GenericApiRequest.RequestItem item : items) {
psp_GenericApiService.addResult(
response,
item,
'Fail',
'查询进行中的支持项目失败',
'QUERY_ERROR',
e.getMessage(),
null
);
}

System.debug('❌ 查询进行中的支持项目时发生异常: ' + e.getMessage());
System.debug(e.getStackTraceString());
}
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* Apex名 : psp_GetCareProgramsApi
* 说明 : 获取进行中的支持服务项目及其关联产品
*/
public with sharing class psp_GetCareProgramsApi {

/**
* 支持服务项目响应类
*/
public class CareProgramResponse extends psp_CommonResponseObject {
public String id;
public String name;
public String status;
public String description;
public Date startDate;
public Date endDate;
public List<CareProgramProductResponse> careProgramProducts;

/**
* 构造函数
*/
public CareProgramResponse() {
}

/**
* 从CareProgram构建响应对象
*/
public CareProgramResponse(CareProgram program) {
if (program != null) {
this.id = program.Id;
this.name = program.Name;
this.status = program.Status;
this.description = program.Description;
this.startDate = program.StartDate;
this.endDate = program.EndDate;

// 处理关联的CareProgramProduct记录
if (program.CareProgramProducts != null && !program.CareProgramProducts.isEmpty()) {
this.careProgramProducts = new List<CareProgramProductResponse>();
for (CareProgramProduct product : program.CareProgramProducts) {
this.careProgramProducts.add(new CareProgramProductResponse(product));
}
}
}
}
}

/**
* 支持服务项目产品响应类
*/
public class CareProgramProductResponse extends psp_CommonResponseObject {
public String id;
public String name;
public String careProgramId;
public String productId;
public String genericName;
public String diseaseField;
public String indicationName;
public String productName;
public String productIndicationRelationship;
public String status;

/**
* 构造函数
*/
public CareProgramProductResponse() {
}

/**
* 从CareProgramProduct构建响应对象
*/
public CareProgramProductResponse(CareProgramProduct product) {
if (product != null) {
this.id = product.Id;
this.name = product.Name;
this.careProgramId = product.CareProgramId;
this.productId = product.ProductId;
this.genericName = product.GenericName__c;
this.diseaseField = product.DiseaseField__c;
this.indicationName = product.IndicationName__c;
this.productName = product.ProductName__c;
this.productIndicationRelationship = product.ProductIndicationRelationship__c;
this.status = product.Status;
}
}
}

/**
* 获取进行中的支持服务项目及其关联产品
* @param items 请求项目列表
* @param response 响应对象
*/
public static void getCarePrograms(List<psp_GenericApiRequest.RequestItem> items, psp_GenericApiResponse response) {
System.debug('🔔 开始处理支持服务项目查询,请求数量: ' + (items != null ? items.size() : 0));

if (items == null || items.isEmpty()) {
System.debug('⚠️ 没有支持服务项目查询请求需要处理');
return;
}

try {
// 获取所有进行中的支持服务项目及其激活的产品
List<CareProgram> carePrograms = psp_CareProgramProductDao.getActiveCareProgramsWithProducts();

String message;
if (carePrograms != null && !carePrograms.isEmpty()) {
message = '成功获取进行中的支持服务项目,共 ' + carePrograms.size() + ' 条';
} else {
message = '未找到进行中的支持服务项目';
carePrograms = new List<CareProgram>();
}

// 为每个请求返回相同结果
for (psp_GenericApiRequest.RequestItem item : items) {
if (item != null) {
// 转换为自定义响应对象
List<psp_CommonResponseObject> customData = new List<psp_CommonResponseObject>();
if (carePrograms != null) {
for (CareProgram program : carePrograms) {
customData.add(new CareProgramResponse(program));
}
}
psp_GenericApiService.addResult(response, item, psp_Constants.RESPONSE_STATUS_SUCCESS, message, null, null, null, customData);
}
}

} catch (Exception e) {
System.debug('❌ 获取支持服务项目出错: ' + e.getMessage());
// 为所有请求添加错误结果
for (psp_GenericApiRequest.RequestItem item : items) {
if (item != null) {
String errorMessage = '获取支持服务项目时发生错误: ' + e.getMessage();
psp_GenericApiService.addResult(response, item, psp_Constants.RESPONSE_STATUS_FAIL, errorMessage, null, null, null, null);
}
}
}
}
}