package com.engine.salary.report.web;

import com.engine.common.util.ServiceUtil;
import com.engine.salary.entity.hrm.dto.EmployeeInfoExpandDTO;
import com.engine.salary.report.entity.dto.SalaryStatisticsDimensionFormDTO;
import com.engine.salary.report.entity.dto.SalaryStatisticsDimensionListDTO;
import com.engine.salary.report.entity.param.SalaryStatisticsDimensionQueryParam;
import com.engine.salary.report.entity.param.SalaryStatisticsDimensionSaveParam;
import com.engine.salary.report.wrapper.SalaryStatisticsDimensionWrapper;
import com.engine.salary.util.ResponseResult;
import com.engine.salary.util.page.PageInfo;
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;
import java.util.Collection;
import java.util.List;
import java.util.Map;

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

    private SalaryStatisticsDimensionWrapper getSalaryStatisticsDimensionWrapper(User user) {
        return ServiceUtil.getService(SalaryStatisticsDimensionWrapper.class, user);
    }


    /**
     * 薪酬统计维度列表
     *
     * @param queryParam
     * @return
     */
    @POST
    @Path("/list")
    @Produces(MediaType.APPLICATION_JSON)
    public String list(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryStatisticsDimensionQueryParam queryParam) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<SalaryStatisticsDimensionQueryParam, PageInfo<SalaryStatisticsDimensionListDTO>>(user).run(getSalaryStatisticsDimensionWrapper(user)::list, queryParam);
    }

    /**
     * 获取薪酬统计维度表单
     *
     * @return
     */
    @GET
    @Path("/getForm")
    @Produces(MediaType.APPLICATION_JSON)
    public String getForm(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "id") Long id) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<Long, SalaryStatisticsDimensionFormDTO>(user).run(getSalaryStatisticsDimensionWrapper(user)::getFrom, id);
    }


    /**
     * 保存薪酬统计维度
     *
     * @param saveParam
     * @return
     */
    @POST
    @Path("/save")
    @Produces(MediaType.APPLICATION_JSON)
    public String save(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody SalaryStatisticsDimensionSaveParam saveParam) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<SalaryStatisticsDimensionSaveParam, String>(user).run(getSalaryStatisticsDimensionWrapper(user)::save, saveParam);
    }

    /**
     * 保存薪酬统计维度扩展字段设置
     *
     * @param saveParam
     * @return
     */
    @POST
    @Path("/saveExpandFieldSettings")
    @Produces(MediaType.APPLICATION_JSON)
    public String saveExpandFieldSettings(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody EmployeeInfoExpandDTO saveParam) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<EmployeeInfoExpandDTO, String>(user).run(getSalaryStatisticsDimensionWrapper(user)::saveExpandFieldSettings, saveParam);
    }

    /**
     * 查询薪酬统计维度扩展字段设置
     *
     * @return
     */
    @GET
    @Path("/getExpandFieldSettings")
    @Produces(MediaType.APPLICATION_JSON)
    public String getExpandFieldSettings(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "module") String module) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<String, EmployeeInfoExpandDTO>(user).run(getSalaryStatisticsDimensionWrapper(user)::getExpandFieldSettings, module);
    }

    /**
     * 删除薪酬统计维度
     *
     * @param ids
     * @return
     */
    @POST
    @Path("/delete")
    @Produces(MediaType.APPLICATION_JSON)
    public String delete(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Collection<Long> ids) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<Collection<Long>, Map<String, Object>>(user).run(getSalaryStatisticsDimensionWrapper(user)::delete, ids);
    }

    /**
     * 薪酬统计维度下拉列表
     *
     * @return
     */
    @GET
    @Path("/selectList")
    @Produces(MediaType.APPLICATION_JSON)
    public String selectList(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<Collection<Long>, List<Map<String, Object>>>(user).run(getSalaryStatisticsDimensionWrapper(user)::selectList);
    }

}
