package com.engine.htxc.swtp.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htxc.swtp.service.SwtpService;
import com.engine.htxc.swtp.service.impl.SwtpServiceImpl;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
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.HashMap;
import java.util.Map;

public class SwtpAction {

    private SwtpService getService(){
        return  ServiceUtil.getService(SwtpServiceImpl.class);
    }

    @POST
    @Path("/createFreeNode")
    @Produces({MediaType.TEXT_PLAIN})
    public String createFreeNode(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            User user = HrmUserVarify.getUser( request, response );
            Map<String,Object> param = ParamUtil.request2Map(request);
            apidatas = getService().createFreeNode(user,param);
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 送办结之前校验送过公司领导，否则限制提交
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/judgeLdsp")
    @Produces({MediaType.TEXT_PLAIN})
    public String judgeLdsp(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            User user = HrmUserVarify.getUser( request, response );
            Map<String,Object> param = ParamUtil.request2Map(request);
            JAVATools.writelog("招标汇报requestid="+param.get("requestid"));
            apidatas = getService().judgeLdsp(param);
            apidatas.put("code",200);
            apidatas.put("msg","success");
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("code",500);
            apidatas.put("msg",e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }
    /**
     * 这个接口是用来获取采购项目跳转过来的通知阅读人员，添加到页面通知阅读人员
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getTzydry")
    @Produces({MediaType.TEXT_PLAIN})
    public String getTzydry(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String,Object> apidatas = new HashMap<String,Object>();
        try {
            User user = HrmUserVarify.getUser( request, response );
            Map<String,Object> param = ParamUtil.request2Map(request);
            JAVATools.writelog("招标汇报requestid="+param.get("requestid"));
            Map<String,Object>  result = getService().getTzydry(param);
            apidatas.put("data",result);
            apidatas.put("code",200);
            apidatas.put("msg","success");
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("code",500);
            apidatas.put("msg",e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }
}
