package com.engine.attendance.workflow.web;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.attendance.workflow.service.AttendanceSummaryService;
import com.engine.attendance.workflow.service.BusinessTripsApplyService;
import com.engine.attendance.workflow.service.impl.AttendanceSummaryServiceImpl;
import com.engine.attendance.workflow.service.impl.BusinessTripsApplyServiceImpl;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
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;

/**
 * @Author: sy
 * @Description: 出勤汇总数据相关功能接口
 * @Date: 2024/3/25
 **/
public class AttendanceSummaryApi {

    private AttendanceSummaryService getAttendanceSummaryService(User user) {
        return ServiceUtil.getService(AttendanceSummaryServiceImpl.class,user);
    }

    /**
     * 出勤汇总报表查询条件
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getCqSummarySearchCondition")
    @Produces(MediaType.TEXT_PLAIN)
    public String getCqSummarySearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        User user = HrmUserVarify.getUser(request, response);
        apidatas = getAttendanceSummaryService(user).getCqSummarySearchCondition(ParamUtil.request2Map(request));
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取出勤汇总报表
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/getCqSummaryReport")
    @Produces(MediaType.TEXT_PLAIN)
    public String getCqSummaryReport(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        User user = HrmUserVarify.getUser(request, response);
        apidatas = getAttendanceSummaryService(user).getCqSummaryReport(ParamUtil.request2Map(request));
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 新增出勤汇总数据
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/addAttendanceSummary")
    @Produces(MediaType.APPLICATION_JSON)
    public String addAttendanceSummary(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        User user = HrmUserVarify.getUser(request, response);
        apidatas = getAttendanceSummaryService(user).addAttendanceSummary(ParamUtil.request2Map(request));
        return JSONObject.toJSONString(apidatas);
    }
}
