package com.sckw.system.controller;

import com.sckw.core.exception.SystemException;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.system.model.KwsDept;
import com.sckw.system.service.KwsDeptService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 组织机构
 * @author zk
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/kwsDept")
public class KwsDeptController {

    @Autowired
    private KwsDeptService kwsDeptService;

    /**
     * @param id 主键ID
     * @return
     * @description 根据主键查询
     * @author zk
     * @date 2023/5/30
     **/
    @GetMapping("/detail")
    public HttpResult selectByKey(@RequestParam Long id) {
        KwsDept sysDict = kwsDeptService.selectByKey(id);
        return HttpResult.ok(sysDict);
    }

    /**
     * @param params
     * @return
     * @description 分页查询
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/findDeptTree")
    public HttpResult findPage(@RequestBody KwsDept params) {
        return HttpResult.ok(kwsDeptService.findTree(params));
    }

    /**
     * @param params {name 机构名称、company 是否公司}
     * @return
     * @description 新增
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/add")
    public HttpResult add(@Valid @RequestBody KwsDept params) {
        kwsDeptService.add(params);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @param params {id 主键ID、name 机构名称、company 是否公司}
     * @return
     * @description 更新
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/update")
    public HttpResult update(@Valid @RequestBody KwsDept params) {
        kwsDeptService.update(params);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * @param ids {ids：主键ID（多个以逗号隔开）}
     * @return
     * @description 删除
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/dels")
    public HttpResult del(@RequestParam String ids) {
        kwsDeptService.deleteByKey(ids);
        return HttpResult.ok(HttpStatus.MSG_008);
    }

}
