package com.engine.attendance.component.calendarscheduling.web;

import com.engine.attendance.component.calendarscheduling.service.WorkRulesService;
import com.engine.attendance.component.calendarscheduling.service.impl.WorkRulesServiceImpl;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ResponseResult;
import com.engine.common.util.ServiceUtil;
import oracle.jdbc.proxy.annotation.Post;
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.Map;

/**
 * @Author liang.cheng
 * @Date 2023/12/26 6:52 PM
 * @Description: TODO
 * @Version 1.0
 */
public class WorkRulesController {

    private WorkRulesService getReportCollectService(User user) {
        return ServiceUtil.getService(WorkRulesServiceImpl.class,user);
    }


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

    @GET
    @Path("/queryDepartSchedule")
    @Produces(MediaType.APPLICATION_JSON)
    public String getDepartSchedule(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String,Object> paramMap = ParamUtil.request2Map(request);
        return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getReportCollectService(user) :: getDepartSchedule,paramMap);
    }

    @Post
    @Path("/saveCalendarWork")
    @Produces(MediaType.APPLICATION_JSON)
    public String saveCalendarWork(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String,Object> paramMap = ParamUtil.request2Map(request);
        return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getReportCollectService(user) :: saveCalendarWork,paramMap);
    }
}
