编辑代码

import groovy.json.*
import java.text.SimpleDateFormat
class UnifiedParam{
    String methodName;
    Object param;
}
class ReportHistory{
    Date startDate;
    Date endDate;
}
class RecordBase{
    String orgId;
    String idcard;
    String cardType;
    String checkNumber;
    String checkRecordId
}
def paramConvert(param){
    def jsonSlurper = new JsonSlurper()
    def object = jsonSlurper.parseText(param)
    def method = object.method;
    def returnParam;
    switch(method){
        case "PE_REPORT_HISTORY":returnParam =  reportHistoryConvert(object);break;
        case "PE_REPORT_INFO":returnParam = reportInfoConvert(object);break;
        case "PE_REPORT_PDF_BASE64":returnParam = reportPdfConvert(object);break;
        case "PE_EXAM_INFO_BASE":returnParam = recordInfoConvert(object);break;
    }
    return returnParam;
}
def reportHistoryConvert(param){
    def sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    def startTime = sdf.parse(param.param.start_date);
    def endTime = sdf.parse(param.param.end_date)
    def reportHistory =  new ReportHistory(startDate:startTime,endDate:endTime);
    def unifiedParam = new UnifiedParam(methodName:"PE_REPORT_HISTORY",param:reportHistory);
    return JsonOutput.toJson(unifiedParam);
}
def reportInfoConvert(param){
    def checkRecordIds = []
    for(id in param.param){
        checkRecordIds.add(id.toInteger())
    }
    def unifiedParam = new UnifiedParam(methodName:"PE_REPORT_INFO",param:checkRecordIds);
    return JsonOutput.toJson(unifiedParam);
}
def reportPdfConvert(param){
    def unifiedParam = new UnifiedParam(methodName:"PE_REPORT_PDF_BASE64",param:param.param.toInteger());
    return JsonOutput.toJson(unifiedParam);
}
def recordInfoConvert(param){
    def recordBase = new RecordBase(orgId:param.param.part_code,idcard:param.param.idcard,cardType:param.param.idcard_type,
    checkNumber:param.param.his_order_num,checkRecordId:param.param.his_reg_no)
    def unifiedParam = new UnifiedParam(methodName:"PE_EXAM_INFO_BASE",param:recordBase);
    return JsonOutput.toJson(unifiedParam);
}