package com.engine.salary.web;

import com.engine.common.util.ServiceUtil;
import com.engine.salary.entity.salaryarchive.dto.SalaryItemAdjustRecordListDTO;
import com.engine.salary.entity.salaryarchive.param.SalaryItemAdjustRecordQueryParam;
import com.engine.salary.entity.siaccount.param.QueryAccountDetailParam;
import com.engine.salary.util.ResponseResult;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.wrapper.SIReportWrapper;
import com.engine.salary.wrapper.SalaryArchiveItemWrapper;
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.GET;
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.Map;
import java.util.Optional;

/**
 * 福利报表
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
public class SIReportController {

    private SalaryArchiveItemWrapper salaryArchiveItemWrapper;

    private SalaryArchiveItemWrapper getSalaryArchiveItemWrapper(User user) {
        return (SalaryArchiveItemWrapper) ServiceUtil.getService(SalaryArchiveItemWrapper.class, user);
    }

    private SIReportWrapper getSIReportWrapper(User user) {
        return (SIReportWrapper) ServiceUtil.getService(SIReportWrapper.class, user);
    }

    @POST
    @Path("welfare/list")
    @Produces(MediaType.APPLICATION_JSON)
    public String list(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody QueryAccountDetailParam queryParam) {
        User user = HrmUserVarify.getUser(request, response);
        return new ResponseResult<QueryAccountDetailParam, Map<String,Object>>(user).run(getSIReportWrapper(user)::welfareList, queryParam);
    }


    @GET
    @Path("record/list")
    @Produces(MediaType.APPLICATION_JSON)
    public String recordList(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        SalaryItemAdjustRecordQueryParam salaryItemAdjustRecordQueryParam = new SalaryItemAdjustRecordQueryParam();
        salaryItemAdjustRecordQueryParam.setEmployeeId((long)user.getUID());
        String current = Optional.ofNullable(request.getParameter("current")).orElse("1");
        String pageSize = Optional.ofNullable(request.getParameter("pageSize")).orElse("10");
        salaryItemAdjustRecordQueryParam.setCurrent(Integer.valueOf(current));
        salaryItemAdjustRecordQueryParam.setPageSize(Integer.valueOf(pageSize));
        return new ResponseResult<SalaryItemAdjustRecordQueryParam, PageInfo<SalaryItemAdjustRecordListDTO>>(user).run(getSalaryArchiveItemWrapper(user)::myAdjustRecordList, salaryItemAdjustRecordQueryParam);
    }
}
