package com.engine.salary.report.web;

import com.engine.common.util.ServiceUtil;
import com.engine.salary.report.entity.dto.SalaryStatisticsEchartsDTO;
import com.engine.salary.report.wrapper.SalaryStatisticsEchartsWrapper;
import com.engine.salary.util.ResponseResult;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

/**
 * 薪酬统计图表
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public class SalaryStatisticsEchartsController {

    private SalaryStatisticsEchartsWrapper getSalaryStatisticsEchartsWrapper(User user) {
        return ServiceUtil.getService(SalaryStatisticsEchartsWrapper.class, user);
    }
    /**
     * 分析图数据展示范围设置保存
     *
     * @param saveParam
     * @return
     */
    @POST
    @Path("/saveRangeSetting")
    @Produces(MediaType.APPLICATION_JSON)
    public String saveRangeSetting(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryStatisticsEchartsDTO saveParam) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<SalaryStatisticsEchartsDTO, String>(user).run(getSalaryStatisticsEchartsWrapper(user)::saveRangeSetting, saveParam);
    }


    /**
     * 分析图数据展示范围设置删除
     *
     * @param reportId
     * @return
     */
    @GET
    @Path("/deleteRangeSetting")
    @Produces(MediaType.APPLICATION_JSON)
    public String deleteRangeSetting(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "reportId")Long reportId) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<Long, String>(user).run(getSalaryStatisticsEchartsWrapper(user)::deleteRangeSetting, reportId);
    }

    /**
     * 分析图数据展示范围设置查询
     *
     * @param reportId
     * @param chartsType
     * @return
     */
    @GET
    @Path("/queryRangeSetting")
    @Produces(MediaType.APPLICATION_JSON)
    public String deleteRangeSetting(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "reportId")Long reportId, @QueryParam(value = "chartsType")Integer chartsType) {
        User user = HrmUserVarify.getUser(request, response);
        SalaryStatisticsEchartsDTO resp = SalaryStatisticsEchartsDTO.builder()
                .reportId(reportId)
                .chartsType(chartsType)
                .build();
        return new ResponseResult<SalaryStatisticsEchartsDTO, SalaryStatisticsEchartsDTO>(user).run(getSalaryStatisticsEchartsWrapper(user)::queryRangeSetting, resp);
    }

}
