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 14:50
 * @Description:采购相关接口
 * @ModifyLog:
 **/
public class GetBrowerValue {


    @GET
    @Path("/getBrowerValue")
    @Produces({MediaType.TEXT_PLAIN})
    public String getBrowerValue(@Context HttpServletRequest request, @Context HttpServletResponse response){

        String fieldvalue = Util.null2String(request.getParameter("fieldvalue"));
        Map<String,Object> dataMap = new HashMap<String,Object>();
        RecordSet rs = new RecordSet();
        String sql = "select a.id,lastname,workcode,departmentname from hrmresource a " +
                " left join hrmdepartment b on a.departmentid=b.id where a.id in ("+fieldvalue+") order by instr('"+fieldvalue+"',id)";
        rs.execute(sql);
        List<Map<String,String>> dataList = new ArrayList<Map<String,String>>();
        while(rs.next()){
            String id = Util.null2String(rs.getString("id"));
            String name = Util.null2String(rs.getString("lastname"));
            String workcode = Util.null2String(rs.getString("workcode"));
            String departmentname = Util.null2String(rs.getString("departmentname"));

            Map<String,String> itemMap = new HashMap<String,String>();
            itemMap.put("id",id);
            itemMap.put("name",name+"("+departmentname+")");

            dataList.add(itemMap);

        }

        dataMap.put("value",fieldvalue);
        dataMap.put("specialobj",dataList);
        dataMap.put("code",200);
//        out.print(JSONObject.fromObject(dataMap).toString());
        return JSONObject.toJSONString(dataMap);
    }
}
