package com.engine.htxc.jzxcshb.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htxc.jzxcshb.service.JzxcshbService;
import com.engine.htxc.jzxcshb.service.impl.JzxcshbServiceImpl;
import org.apache.commons.lang3.StringUtils;
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;
/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810027
 * @version: 1.0
 * @CreateDate: 2022-08-22 14:00
 * @Description:竞争性磋商汇报相关接口
 * @ModifyLog:
 **/
public class JzxcshbAction {

    private JzxcshbService getService(){
        return  ServiceUtil.getService(JzxcshbServiceImpl.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);
    }

    /**
     * 这个接口是用来回来获取领导i审批节点的领导的最新审批意见
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getNewRequestLog")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNewRequestLog(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            User user = HrmUserVarify.getUser( request, response );
            Map<String,Object> param = ParamUtil.request2Map(request);
            JAVATools.writelog("竞争性磋商汇报requestid="+param.get("requestid"));
            String  result = getService().getNewRequestLog(param);
            if(StringUtils.isNotBlank(result)){
                map.put("data",result);
            }else{
                map.put("data","");
            }
            map.put("code",200);
            map.put("msg","success");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code",500);
            map.put("msg",e.getMessage());
        }
        return JSONObject.toJSONString(map);
    }
}
