package com.engine.jucailinkq.attendance.workflow.web;

import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.jucailinkq.attendance.workflow.service.OvertimePlanService;
import com.engine.jucailinkq.attendance.workflow.service.impl.OvertimePlanServiceImpl;
import com.engine.jucailinkq.common.util.ApiReturnTools;
import com.engine.jucailinkq.common.util.ResponseResult;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
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.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import java.lang.reflect.Type;
import java.util.Map;

/**
 * @Author: sy
 * @Description: 加班计划流程相关接口
 * @Date: 2024/7/18
 **/
@Slf4j
public class OvertimePlanApi {

    private OvertimePlanService getOvertimePlanService(User user) {
        return ServiceUtil.getService(OvertimePlanServiceImpl.class,user);
    }

    /**
     * 加班计划-生成加班计划明细表数据
     * @return
     */
    @GET
    @Path("/generateOvertimePlanDetails")
    @Produces({"text/plain"})
    public String generateOvertimePlanDetails(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            Map<String,Object> param = ParamUtil.request2Map(request);
            User user = HrmUserVarify.getUser(request, response);
            String mainTableDataStr = Util.null2String(param.get("mainTableData"));
            Gson gson = new Gson();
            Map<String,Object> mainTableData = gson.fromJson(mainTableDataStr, (Type) Map.class);

            param.put("mainTableData",mainTableData);
            return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getOvertimePlanService(user) :: generateOvertimePlanDetails,param);
        }catch (Exception e){
            log.error("generateOvertimePlanDetails status fail,catch error: [{}]",e);
            return ApiReturnTools.error("200","查询失败");
        }
    }
}
