package com.engine.attendance.component.persongroup.web;

import com.engine.attendance.component.persongroup.service.PersonGroupService;
import com.engine.attendance.component.persongroup.service.impl.PersonGroupServiceImpl;
import com.engine.common.util.ApiReturnTools;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import lombok.extern.slf4j.Slf4j;
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 java.util.Map;

@Slf4j
public class PersonGroupAction {

    private PersonGroupService basicsetService = ServiceUtil.getService(PersonGroupServiceImpl.class);

    /**
     * @return
     */
    @GET
    @Path("/getHrmCondition")
    @Produces({"text/plain"})
    public String getHrmCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request,response);
            Map<String,Object> paramMap = ParamUtil.request2Map(request);
            Map<String,Object> dataMap = basicsetService.getHrmCondition(paramMap,user);
            return ApiReturnTools.success(dataMap);
        }catch (Exception e){
            log.error("execute fail,catch error: [{}]",e);
            return ApiReturnTools.error("500","getHrmCondition error");
        }

    }

    /**
     * 适用组织存储
     * @return
     */
    @POST
    @Path("/saveApplicableOrganization")
    @Produces({"text/plain"})
    public String saveApplicableOrganization(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            Map<String,Object> paramMap = ParamUtil.request2Map(request);
            Map<String,Object> dataMap = basicsetService.saveApplicableOrganization(paramMap);
            return ApiReturnTools.success(dataMap);
        }catch (Exception e){
            log.error("execute fail,catch error: [{}]",e);
            return ApiReturnTools.error("500","saveApplicableOrganization error");
        }
    }

}
