package com.engine.htsc.workflow.ld;

import com.weaver.general.Util;
import net.sf.json.JSONObject;
import weaver.general.BaseBean;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

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;

/**
 * @Description: TODO()
 * <p>
 * Development(开发部门): OA项目组-泛微
 * <p>
 * Copyright(版权):
 * @date(创建时间): 2020/11/10 14:18
 * @author(作者): 李丹
 * <p>
 * Last modified(最后修改时间): 2020/11/10 14:18
 * <p>
 * Modified by(修改人): 李丹
 */

public class WorkflowCreateWHAction {
    @GET
    @Path("/createcompanywh")
    @Produces(MediaType.TEXT_PLAIN)
    public String ActionMethod(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        new BaseBean().writeLog("Start=====创建公司文号===");
        JSONObject jsonObject = new JSONObject();
        String reqid = Util.null2String(request.getParameter("reqid"));//流程请求id
        String wfid = Util.null2String(request.getParameter("wfid"));//流程请求id
        String zhtype = Util.null2String(request.getParameter("zhtype"));
        String wh = "";
        if(!reqid.equals("") && !wfid.equals("") && !zhtype.equals("")){
            User user = HrmUserVarify.getUser(request, response);
            String uid = weaver.general.Util.null2String(user.getUID());
            CompanyWHUtil whUtil = new CompanyWHUtil();
            wh = whUtil.CompanyWH(wfid,reqid,zhtype,uid);
            whGetTableTools whGetTableTools=new whGetTableTools();

           if(!whGetTableTools.getTableByRequestid(reqid)){
               jsonObject.put("sfbhresult","0");
           }else{
               jsonObject.put("sfbhresult","1");
           }

        }
        jsonObject.put("result",wh);
        new BaseBean().writeLog("END=====创建公司文号===");
        return jsonObject.toString();
    }

    @GET
    @Path("/createdeptwh")
    @Produces(MediaType.TEXT_PLAIN)
    public String createDeptWHActionMethod(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        new BaseBean().writeLog("Start=====创建部门发文文号===");
        JSONObject jsonObject = new JSONObject();
        String reqid = Util.null2String(request.getParameter("reqid"));//流程请求id
        String wfid = Util.null2String(request.getParameter("wfid"));//流程请求id
        String deptid = Util.null2String(request.getParameter("deptid"));
        String htlx = Util.null2String(request.getParameter("htlx"));  //红头类型
        String wh = "";
        if(!reqid.equals("") && !wfid.equals("") && !deptid.equals("")){
            User user = HrmUserVarify.getUser(request, response);
            String uid = weaver.general.Util.null2String(user.getUID());
            DeptWHUtil whUtil = new DeptWHUtil();
            wh = DeptWHUtil.deptWH(wfid,reqid,deptid,uid,htlx);
            whGetTableTools whGetTableTools=new whGetTableTools();

            if(!whGetTableTools.getTableByRequestid(reqid)){
                jsonObject.put("sfbhresult","0");
            }else{
                jsonObject.put("sfbhresult","1");
            }
        }
        jsonObject.put("result",wh);
        new BaseBean().writeLog("END=====创建部门发文文号===");
        return jsonObject.toString();
    }


    @GET
    @Path("/createfzjgwh")
    @Produces(MediaType.TEXT_PLAIN)
    public String createfzjgWHActionMethod(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        new BaseBean().writeLog("Start=====创建分支机构发文文号===");
        JSONObject jsonObject = new JSONObject();
        String reqid = Util.null2String(request.getParameter("reqid"));//流程请求id
        String wfid = Util.null2String(request.getParameter("wfid"));//流程请求id
        String deptid = Util.null2String(request.getParameter("deptid"));
        String htlx = Util.null2String(request.getParameter("htlx"));  //红头类型
        String wh = "";
        if(!reqid.equals("") && !wfid.equals("") && !deptid.equals("")){
            User user = HrmUserVarify.getUser(request, response);
            String uid = weaver.general.Util.null2String(user.getUID());
            FzjgWHUtil fzjgWHUtil = new FzjgWHUtil();
            wh = fzjgWHUtil.createWH(wfid,reqid,deptid,uid,htlx);
            whGetTableTools whGetTableTools=new whGetTableTools();
            if(!whGetTableTools.getTableByRequestid(reqid)){
                jsonObject.put("sfbhresult","0");
            }else{
                jsonObject.put("sfbhresult","1");
            }
        }
        jsonObject.put("result",wh);
        new BaseBean().writeLog("END=====创建分支机构发文文号===");
        return jsonObject.toString();
    }


    @GET
    @Path("/creategovermentwh")
    @Produces(MediaType.TEXT_PLAIN)
    public String createGovernmentWHActionMethod(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        new BaseBean().writeLog("Start=====创建党工团文号===");
        JSONObject jsonObject = new JSONObject();
        String reqid = Util.null2String(request.getParameter("reqid"));//流程请求id
        String wfid = Util.null2String(request.getParameter("wfid"));//流程请求id
        String zhtype = Util.null2String(request.getParameter("zhtype"));
        String wh = "";
        if(!reqid.equals("") && !wfid.equals("") && !zhtype.equals("")){
            User user = HrmUserVarify.getUser(request, response);
            String uid = weaver.general.Util.null2String(user.getUID());
            GovernmentWHUtil whUtil = new GovernmentWHUtil();
            wh = whUtil.GovernmentWH(wfid,reqid,zhtype,uid);
            whGetTableTools whGetTableTools=new whGetTableTools();

            if(!whGetTableTools.getTableByRequestid(reqid)){
                jsonObject.put("sfbhresult","0");
            }else{
                jsonObject.put("sfbhresult","1");
            }
        }
        jsonObject.put("result",wh);
        new BaseBean().writeLog("END=====创建党工团文号===");
        return jsonObject.toString();
    }

    @GET
    @Path("/createfoundationwh")
    @Produces(MediaType.TEXT_PLAIN)
    public String createFoundationWHActionMethod(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        new BaseBean().writeLog("Start=====创建基金会文号===");
        JSONObject jsonObject = new JSONObject();
        String reqid = Util.null2String(request.getParameter("reqid"));//流程请求id
        String wfid = Util.null2String(request.getParameter("wfid"));//流程请求id
        String zhtype = Util.null2String(request.getParameter("zhtype"));
        String wh = "";
        if(!reqid.equals("") && !wfid.equals("") && !zhtype.equals("")){
            User user = HrmUserVarify.getUser(request, response);
            String uid = weaver.general.Util.null2String(user.getUID());
            FoundationWHUtil whUtil = new FoundationWHUtil();
            wh = whUtil.FoundationWH(wfid,reqid,zhtype,uid);
            whGetTableTools whGetTableTools=new whGetTableTools();

            if(!whGetTableTools.getTableByRequestid(reqid)){
                jsonObject.put("sfbhresult","0");
            }else{
                jsonObject.put("sfbhresult","1");
            }
        }
        jsonObject.put("result",wh);
        new BaseBean().writeLog("END=====创建基金会文号===");
        return jsonObject.toString();
    }

}
