package com.securitycontrol.system.controller;

import com.securitycontrol.common.core.domain.Result;
import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.core.web.page.TableDataInfo;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.system.dto.OrgDto;
import com.securitycontrol.entity.system.vo.OrgVo;
import com.securitycontrol.system.service.OrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 组织机构控制层
 *
 * @author HeiZi
 */
@RestController
@RequestMapping("/sys/org/")
public class OrgController extends BaseController {

    @Autowired
    private OrgService service;

    /**
     * @param dto
     * @return
     */
    @GetMapping("getOrgList")
    @Log(title = "系统管理", menu = "系统管理->组织机构", grade = OperationType.QUERY_SYS, details = "查询组织机构", type = "系统日志")
    public Result<List<OrgVo>> getOrgList(@Valid OrgDto dto) {
        return service.getOrgList(dto);
    }


    /**
     * 新增組織機構
     *
     * @param dto
     * @return
     */
    @PostMapping("addOrg")
    @Log(title = "系统管理", menu = "系统管理->组织机构", grade = OperationType.ADD_SYS, details = "新增组织机构", type = "系统日志")
    public Result<String> addOrg(@RequestBody @Valid OrgVo dto) {
        return service.addOrg(dto);
    }


    /**
     * 修改组织机构
     *
     * @param dto
     * @return
     */
    @PostMapping("updateOrg")
    @Log(title = "系统管理", menu = "系统管理->组织机构", grade = OperationType.UPDATE_SYS, details = "修改组织机构", type = "系统日志")
    public Result<String> updateOrg(@RequestBody @Valid OrgVo dto) {
        return service.updateOrg(dto);
    }


    /**
     * 新增組織機構
     *
     * @param dto
     * @return
     */
    @PostMapping("delOrg")
    @Log(title = "系统管理", menu = "系统管理->组织机构", grade = OperationType.DELETE_SYS, details = "删除组织机构", type = "系统日志")
    public Result<String> delOrg(@RequestBody OrgDto dto) {
        return service.delOrg(dto);
    }


    /**
     * 新增組織機構
     *
     * @param id
     * @return
     */
    @PostMapping("getDetails/{id}")
    public Result<OrgVo> getDetails(@PathVariable("id") String id) {
        return service.getDetails(id);
    }


}
