package com.engine.htsc.seal.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.seal.service.SealChangeService;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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 SealChangeAction {

    SealChangeService getService(){
        return ServiceUtil.getService(SealChangeService.class);
    }

    @POST
    @Path("/getSealInfoByRequestid")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSealInfoByRequestid(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----sealChange-----");
        try{
            String gllc = request.getParameter("gllc");

            SealChangeService sealChangeService = getService();
            apidatas = sealChangeService.getSealInfoByRequestid(gllc);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/getSealInfoByInfoids")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSealInfoByInfoids(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("----sealChange-----");
        try{
            String infoids = request.getParameter("infoids");

            SealChangeService sealChangeService = getService();
            apidatas = sealChangeService.getSealInfoByInfoids(infoids);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }

        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/sendApplyPrint")
    @Produces({MediaType.TEXT_PLAIN})
    public String SendApplyPrint(@Context HttpServletRequest request, @Context HttpServletResponse response){
        BaseBean bs = new BaseBean();
        Map<String, Object> apidatas = new HashMap<String, Object>();
        bs.writeLog("-------------sealChange-------------");
        try{
            String requestid = Util.null2String(request.getParameter("requestid"));
            String docids = Util.null2String(request.getParameter("docid"));
            String bglb = Util.null2String(request.getParameter("bglb"));
            String bglx = Util.null2String(request.getParameter("bglx"));
            User user = HrmUserVarify.getUser(request, response);

            SealChangeService sealChangeService = getService();
            return sealChangeService.sendSealChange(user,requestid,docids,bglb,bglx);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }
}
