package com.engine.htsc.coworkreport.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.coworkreport.service.TaskListService;
import com.engine.htsc.coworkreport.service.impl.TaskListServiceImpl;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.interfaces.htsc.comInfo.PropBean;

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 TaskListAction {

    public TaskListService getService(){
        return ServiceUtil.getService(TaskListServiceImpl.class);
    }

    @POST
    @Path("/deleteCowork")
    @Produces({MediaType.TEXT_PLAIN})
    public String deleteCowork(@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);
            TaskListService taskListService = getService();
            apidatas = taskListService.delteCowork(param,user);
            apidatas.put("api_status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }


    @POST
    @Path("/deleteTask")
    @Produces({MediaType.TEXT_PLAIN})
    public String deleteTask(@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);
            TaskListService taskListService = getService();
            apidatas = taskListService.delteTask(param,user);
            apidatas.put("api_status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }



    @POST
    @Path("/deleteCowork4Task")
    @Produces({MediaType.TEXT_PLAIN})
    public String deleteCowork4Task(@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);
            TaskListService taskListService = getService();
            apidatas = taskListService.deleteCowork4Task(param,user);
            apidatas.put("api_status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }
}
