package com.engine.attendance.workflow.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.attendance.workflow.service.AllowanceService;
import com.engine.attendance.workflow.service.impl.AllowanceServiceImpl;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
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/4/9
 **/
public class AllowanceApi {

    private AllowanceService getAllowanceService(User user) {
        return ServiceUtil.getService(AllowanceServiceImpl.class,user);
    }

    /**
     * 生成出勤津贴数据
     * @param request
     * @param response
     * @return
     */
    @POST
    @Path("/addAllowanceRecords")
    @Produces(MediaType.TEXT_PLAIN)
    public String addAllowanceRecords(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        User user = HrmUserVarify.getUser(request, response);
        apidatas = getAllowanceService(user).addAllowanceRecords(ParamUtil.request2Map(request));
        return JSONObject.toJSONString(apidatas);
    }
}
