package com.engine.htxc.tycgsq.web;

import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.Util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810027
 * @version: 1.0
 * @CreateDate: 2022-08-24 15:01
 * @Description:采购相关接口
 * @ModifyLog:
 **/
public class GetLdspAjax {
    @GET
    @Path("/getLdspAjax")
    @Produces({MediaType.TEXT_PLAIN})
    public String getLdspAjax(@Context HttpServletRequest request, @Context HttpServletResponse response){
        int requestid = Util.getIntValue(Util.null2String(request.getParameter("requestid")));    //
        int workflowid = Util.getIntValue(Util.null2String(request.getParameter("workflowid")));  //
        String nodeid = Util.null2String( request.getParameter( "nodeid" ) );
        List<Map<String,String>> dataList = new ArrayList<Map<String,String>>();
        Map<String,Object> dataMap = new HashMap<String,Object>();
        String fieldvalue = "";
        RecordSet rs = new RecordSet();
        String sql =" select t.userid,h.lastname,k.departmentname \n" +
                " from workflow_currentoperator t\n" +
                " inner join hrmresource h on h.id = t.userid\n" +
                " inner join hrmdepartment k on k.id = h.departmentid\n" +
                " where t.requestid=" +requestid +
                " and t.workflowid=" + workflowid+
                " and t.nodeid in("+nodeid+") " +
                //" and t.agenttype in(0,1) " +
                " order by receivedate,receivetime";
        rs.execute(sql);

        while (rs.next()){
            String userid = Util.null2String(rs.getString("userid"));
            String lastname = Util.null2String(rs.getString("lastname"));
            String departmentname = Util.null2String(rs.getString("departmentname"));
            fieldvalue += fieldvalue == ""? userid : ","+userid ;
            Map<String,String> itemMap = new HashMap<String,String>();
            itemMap.put("id",userid);
            itemMap.put("name",lastname+"("+departmentname+")");
            dataList.add(itemMap);
        }
        dataMap.put("value",fieldvalue);
        dataMap.put("specialobj",dataList);
        dataMap.put("code",200);
        return JSONObject.toJSONString(dataMap);
    }
}
