package com.xueyi.system.staff.controller.api;

import com.alibaba.fastjson2.JSONObject;
import com.xueyi.common.core.constant.basic.SecurityConstants;
import com.xueyi.system.api.device.domain.vo.DeviceTenantSourceMergeVo;
import com.xueyi.system.api.staff.domain.dto.DmStaffCommonDto;
import com.xueyi.system.api.staff.feign.RemoteStaffService;
import com.xueyi.system.resource.controller.api.BaseApiController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 员工管理 API业务处理
 *
 * @author xueyi
 */
@RestController
@RequestMapping("/staff/api")
public class DmStaffApiController extends BaseApiController {

    @Autowired
    private RemoteStaffService staffService;

    @GetMapping(value = "fetchOne/{devId}/{staffId}")
    @ResponseBody
    public JSONObject fetchStaff(@PathVariable("devId") String devId, @PathVariable("staffId") String staffId){
        DeviceTenantSourceMergeVo vo = super.getDeviceTenantSourceMergeVo(devId);
        return staffService.fetchStaff(staffId, vo.getTenantId(), vo.getSourceSlave(), SecurityConstants.INNER);
    }


    @PostMapping(value = "new-staff")
    @ResponseBody
    public com.alibaba.fastjson2.JSONObject newStaff(@RequestBody DmStaffCommonDto commonDto){
        DeviceTenantSourceMergeVo vo = super.getDeviceTenantSourceMergeVo(commonDto.getDevId());
        return staffService.addStaff(commonDto, vo.getTenantId(), vo.getSourceSlave(), SecurityConstants.INNER);
    }
}
