package com.ym.mec.web.controller;

import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.biz.service.SysEmployeePositionService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.tenant.TenantContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("employeePosition")
@Api(tags = "员工职位管理")
@RestController
public class SysEmployeePositionController extends BaseController {

    @Autowired
    private SysEmployeePositionService employeePositionService;
    @Autowired
    private OrganizationService organizationService;

    @ApiOperation(value = "获取分部下员工职位列表")
    @GetMapping("/findOrganPosition")
    @PreAuthorize("@pcs.hasPermissions('employeePosition/findOrganPosition')")
    public Object findAll(String id) throws Exception {
        if(StringUtils.isEmpty(id)){
            id = organizationService.getEmployeeOrgan(id);
        }
        Integer tenantId = TenantContextHolder.getTenantId();
        return succeed(employeePositionService.findOrganPosition(id, tenantId));
    }
}
