package com.engine.matfron.web;

import com.engine.common.util.ServiceUtil;
import com.engine.matfron.entity.OptionVO;
import com.engine.matfron.entity.PortalTopVO;
import com.engine.matfron.service.StatisticsPortalService;
import com.engine.matfron.service.impl.StatisticsPortalServiceImpl;
import com.engine.matfron.util.ResponseResult;
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.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.LinkedList;
import java.util.Map;


/**
 * @Author liang.cheng
 * @Date 2023/9/26 5:51 PM
 * @Description:
 * @Version 1.0
 */
public class StatisticsPortalAction {

    private StatisticsPortalService getCommonDutyService(User user) {
        return ServiceUtil.getService(StatisticsPortalServiceImpl.class,user);
    }


    @GET
    @Path("/statistics/top")
    @Produces(MediaType.APPLICATION_JSON)
    public String getPortalTop(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, LinkedList<PortalTopVO>>(user).run(getCommonDutyService(user) :: getPortalTop);
    }

    @GET
    @Path("/statistics/department")
    @Produces(MediaType.APPLICATION_JSON)
    public String getPortalDepartment(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getPortalDepartment);
    }

    @GET
    @Path("/statistics/subcompany")
    @Produces(MediaType.APPLICATION_JSON)
    public String getPortalSubCompany(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getPortalSubCompany);
    }


    @GET
    @Path("/statistics/homePlace")
    @Produces(MediaType.APPLICATION_JSON)
    public String getHomePlace(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getHomePlace);
    }

    @GET
    @Path("/statistics/ethnic")
    @Produces(MediaType.APPLICATION_JSON)
    public String getPortalEthnic(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getPortalEthnic);
    }

    @GET
    @Path("/statistics/educational")
    @Produces(MediaType.APPLICATION_JSON)
    public String getEducational(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getEducational);
    }

    @GET
    @Path("/statistics/surname")
    @Produces(MediaType.APPLICATION_JSON)
    public String getSurname(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getSurname);
    }


    @GET
    @Path("/statistics/ageAndSex")
    @Produces(MediaType.APPLICATION_JSON)
    public String getAgeAndSex(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getAgeAndSex);
    }

    @GET
    @Path("/statistics/jobType")
    @Produces(MediaType.APPLICATION_JSON)
    public String getJobType(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, OptionVO>(user).run(getCommonDutyService(user) :: getJobType);
    }

    @GET
    @Path("/statistics/leaveMonth")
    @Produces(MediaType.APPLICATION_JSON)
    public String getLeaveMonth(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("departmentIds") String departmentIds) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, Map<String,Object>>(user).run(getCommonDutyService(user) :: getLeaveMonth,departmentIds);

    }

    @GET
    @Path("/statistics/leaveYear")
    @Produces(MediaType.APPLICATION_JSON)
    public String getLeaveYear(@Context HttpServletRequest request, @Context HttpServletResponse response,@QueryParam("departmentIds") String departmentIds) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, Map<String,Object>>(user).run(getCommonDutyService(user) :: getLeaveYear,departmentIds);
    }



}
