package com.yh.saas.plugin.operation.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.yh.saas.plugin.operation.entity.CommonOperator;
import com.yh.saas.plugin.operation.service.IOperatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 账户信息 服务类
 * </p>
 *
 * @author zhangb
 */
@RestController
@RequestMapping("/operator")
public class OperatorController {

    @Autowired
    private IOperatorService operatorService;

    /**
     * 创建账户
     *
     * @param operator 账户信息
     */
    @PostMapping("/api/create")
    public void create(@RequestBody @Valid CommonOperator operator) {
        operatorService.create(operator);
    }

    /**
     * 修改账户信息
     *
     * @param operator 账户信息
     */
    @PostMapping("/api/changeInfo")
    public void changeInfo(@RequestBody CommonOperator operator) {
        operatorService.changeInfo(operator);
    }

    /**
     * 启用账户
     *
     * @param operator staff -> operatorId，账户ID
     */
    @PostMapping("/api/enable")
    public void enable(@RequestBody CommonOperator operator) {
        operatorService.enable(operator.getOperatorId());
    }

    /**
     * 禁用账户
     *
     * @param operator -> operatorId，账户ID
     */
    @PostMapping("/api/disable")
    public void disable(@RequestBody CommonOperator operator) {
        operatorService.disable(operator.getOperatorId());
    }

    /**
     * 删除账户
     *
     * @param operator 账户批量操作
     */
    @PostMapping("/api/remove")
    public void remove(@RequestBody CommonOperator operator) {
        operatorService.remove(operator.getOperatorId());
    }

    /**
     * 获取账户详情
     *
     * @param operatorId 账户ID
     * @return 账户详情
     */
    @GetMapping("/query/staffInfo")
    public CommonOperator getOperatorInfo(@RequestParam String operatorId) {
        return operatorService.selectById(operatorId);
    }

    /**
     * 查询账户
     *
     * @param operator 查询条件
     * @return 账户列表
     */
    @GetMapping("/query/operators")
    public Page<CommonOperator> findOperators(CommonOperator operator) {
        return operatorService.findOperators(operator.getKeyword(),operator.getQueryPage());
    }

}

