package com.engine.organization.web;

import com.engine.common.util.ServiceUtil;
import com.engine.organization.entity.staff.param.StaffOutParam;
import com.engine.organization.service.StaffOutService;
import com.engine.organization.service.impl.StaffOutServiceImpl;
import com.engine.organization.util.response.ReturnResult;
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.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

/**
 * @Author liang.cheng
 * @Date 2023/9/1 10:19 AM
 * @Description: 编制外部调用
 * @Version 1.0
 */
public class StaffOutController {

    public StaffOutService staffOutService(User user) {
        return ServiceUtil.getService(StaffOutServiceImpl.class, user);
    }


    @POST
    @Path("/change")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult changeStaff(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody StaffOutParam staffOutParam) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            return ReturnResult.successed(user,staffOutService(user).changeStaff(staffOutParam));
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }

    @POST
    @Path("/transaction")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult transactionOnJob(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody StaffOutParam staffOutParam) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            return ReturnResult.successed(user,staffOutService(user).transactionOnJob(staffOutParam));
        } catch (Exception e) {
            return ReturnResult.exceptionHandle(e);
        }
    }

}
