package com.engine.bmj.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.bmj.service.MaterialCreateService;
import com.engine.bmj.service.impl.MaterialCreateServiceImpl;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
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;
import java.util.HashMap;
import java.util.Map;



public class MaterialCreateAction {

    public MaterialCreateService getService(){
        return (MaterialCreateService) ServiceUtil.getService(MaterialCreateServiceImpl.class);

    }

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

        Map<String,Object> apidatas = new HashMap<String,Object>();
        try{
            Map<String,Object> dataMap = ParamUtil.request2Map(request);
            User user = HrmUserVarify.getUser(request, response);
            apidatas.putAll(getService().createDocByMaterial(dataMap,user));
        }catch (Exception e){
            apidatas.put("api_status",false);
            apidatas.put("api_errormsg","exception:"+e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);

    }
}
