package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.Channel;
import com.tuoheng.admin.query.ChannelQuery;
import com.tuoheng.admin.service.channel.ChannelService;
import com.tuoheng.common.core.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author ChengWang
 * @Date 2022/11/17
 */
@RestController
@RequestMapping("/channel")
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    /**
     * 获取航道信息列表(分页)
     * @param query
     * @return
     */
    @GetMapping("/index")
    public JsonResult index(ChannelQuery query){
        return channelService.queryPage(query);
    }

    /**
     * 获取航道信息列表
     * @param query
     * @return
     */
    @GetMapping("/getList")
    public JsonResult getList(ChannelQuery query){
        return channelService.getListInfo(query);
    }

    /**
     * 根据部门id获取该部门下航道信息列表
     * @param deptId
     * @return
     */
    @GetMapping("/list/by/dept/{deptId}")
    public JsonResult getListByDeptId(@PathVariable("deptId") String deptId){
        return channelService.getListByDeptId(deptId);
    }

    /**
     * 根据登录人角色获取该部门下航道信息列表
     * @return
     */
    @GetMapping("/list/by/dept/userType")
    public JsonResult getListByUserType(){
        return channelService.getListByUserType();
    }

    /**
     * 航道新增
     * @param entity
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody Channel entity){
        return channelService.editInfo(entity);
    }

    /**
     * 编辑航道
     * @param entity
     * @return
     */
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody Channel entity){
        return channelService.editInfo(entity);
    }

    /**
     * 删除航道
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") String[] ids){
        return channelService.deleteByIds(ids);
    }

}
