csjoz11

导航

new ArrayList json.parse

package com.sapdev.ws.getoperation;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;

import com.sap.engine.services.webservices.espbase.configuration.ann.dt.AuthenticationDT;
import com.sap.engine.services.webservices.espbase.configuration.ann.dt.AuthenticationEnumsAuthenticationLevel;
import com.sap.engine.services.webservices.espbase.configuration.ann.rt.AuthenticationRT;
import com.sap.me.extension.Services;
import com.sapdev.service.LogicServiceInterface;
import com.sapdev.service.dto.LogicQueryResponse;
import com.sapdev.service.dto.SqlQueryRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@AuthenticationDT(authenticationLevel = AuthenticationEnumsAuthenticationLevel.BASIC)
@AuthenticationRT(AuthenticationMethod = "sapsp:HTTPBasic")
@WebService
public class FirstOperationService {
    @Resource
    protected WebServiceContext wsContext;
    //private final String GET_OPERATION_OBJECT = "SELECT * FROM Z_DIALOG WHERE DIALOG_ID = ''{0}''";
    private final String GET_OPERATION_OBJECT = "SELECT operation,description,revision FROM operation WHERE status_bo =''StatusBO:{0},201'' ORDER BY operation";

    @WebMethod
    public String getOperation(@WebParam(name = "opRequest") OperationRequest opRequest) throws Exception {

        String site = opRequest.getSite();
        String sqls = MessageFormat.format(GET_OPERATION_OBJECT, site);
        LogicServiceInterface lservice = Services.getService("com.sapdev.service", "LogicService", site);
        // LogicService lservice = new LogicService();s
        SqlQueryRequest sqlrequest = new SqlQueryRequest();
        sqlrequest.setSql(sqls);
        LogicQueryResponse LQRresponse = lservice.query(sqlrequest);
        /*OperationResponse operationObj = new OperationResponse();

        List<Map> data = LQRresponse.getRecords();
        List<OperationRecord> operList = new ArrayList<OperationRecord>();
        if (data != null && data.size() > 0) {
            for (Map map : data) {
                OperationRecord or = new OperationRecord();
                or.setOperation(map.get("OPERATION").toString());
                or.setDeacription(map.get("DESCRIPTION").toString());
                or.setRevision(map.get("REVISION").toString());
                operList.add(or);
            }
        }
        operationObj.setData(operList);

        return operationObj;*/
        
        JSONObject json = new JSONObject();
        List<Map> data = LQRresponse.getRecords();
        List<OperationRecord> operList = new ArrayList<OperationRecord>();
        JSONArray array = new JSONArray();
        if (data != null && data.size() > 0) {
            for (Map map : data) {
                JSONObject object = new JSONObject();
                object.put("operation", map.get("OPERATION").toString());
                object.put("description", map.get("DESCRIPTION").toString());
                object.put("revision", map.get("REVISION").toString());
                
                array.add(object);
            }
        }        
        json.put("json", array);
        return json.toString();
    }
    
    /*    public static void main(String[] args) throws GetOperationException, Exception {
            GetOperationRequest request=new GetOperationRequest();
            request.setSite("1000");
            GetOperationResponse a=new GetOperationService().getOperation(request);
        }*/
}

posted on 2021-11-16 11:53  csjoz11  阅读(54)  评论(0编辑  收藏  举报