package com.engine.organization.web;

import com.engine.common.util.ServiceUtil;
import com.engine.organization.entity.codesetting.param.CodeSaveParam;
import com.engine.organization.util.response.ReturnResult;
import com.engine.organization.wrapper.CodeSettingWrapper;
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;

/**
 * @Author weaver_cl
 * @description:
 * @Date 2022/5/30
 * @Version V1.0
 **/
public class CodeSettingController {

    public CodeSettingWrapper getCodeSettingWrapper(User user) {
        return ServiceUtil.getService(CodeSettingWrapper.class,user);
    }


    /**
     * 是否有权限
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getHasRight")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult getHasRight(@Context HttpServletRequest request, @Context HttpServletResponse response,
                                    @QueryParam("serialtype") String serialtype) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            return getCodeSettingWrapper(user).getHasRight(serialtype);
        } catch (Exception e) {
           return ReturnResult.exceptionHandle(e);
        }
    }


    @POST
    @Path("/saveOrUpdateCodeSetting")
    @Produces(MediaType.APPLICATION_JSON)
    public ReturnResult saveBaseComp(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody CodeSaveParam params) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            return getCodeSettingWrapper(user).saveOrUpdateCodeSetting(params);
        } catch (Exception e) {
           return ReturnResult.exceptionHandle(e);
        }
    }



}
