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); } } } } }
|