package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.Leg;
import com.tuoheng.admin.query.LegQuery;
import com.tuoheng.admin.service.leg.ILegService;
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("/leg")
public class LegController {

    @Autowired
    private ILegService legService;

    /**
     * 获取航段列表(分页)
     * @param query
     * @return
     */
    @GetMapping("/index")
    public JsonResult index(LegQuery query){
        return legService.queryPage(query);
    }

    /**
     * 获取航段列表
     * @param query
     * @return
     */
    @GetMapping("/getList")
    public JsonResult getList(LegQuery query){
        return legService.getListInfo(query);
    }

    /**
     * 部门管理员或普通用户获取所属部门监管范围航段之和
     * @return
     */
    @GetMapping("/listByUserType")
    public JsonResult getListByUserType(){
        return legService.getLegList();
    }

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

    /**
     * 根据航道id获取该航道下航段信息列表
     * @param channelId
     * @return
     */
    @GetMapping("/list/by/channel/{channelId}")
    public JsonResult getListByChannelId(@PathVariable("channelId") String channelId) {
        return legService.getListByChannelId(channelId);
    }

    /**
     * 根据航道id和部门id获取该航道下航段信息列表
     * @param channelId
     * @return
     */
    @GetMapping("/list/by/channel/dept/{channelId}/{deptId}")
    public JsonResult getListByRoadIdAndDeptId(@PathVariable("channelId") String channelId, @PathVariable("deptId") String deptId) {
        return legService.getListByChannelIdAndDeptId(channelId, deptId);
    }

    /**
     * 根据id获取航段详情
     * @param legId
     * @return
     */
    @GetMapping("/info/{legId}")
    public JsonResult info(@PathVariable("legId") String legId){
        return legService.getLegInfo(legId);
    }

    /**
     * 新增航段
     * @param entity
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody Leg entity){
        return legService.editInfo(entity);
    }

    /**
     * 编辑航段
     * @param leg
     * @return
     */
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody Leg leg){
        return legService.editInfo(leg);
    }

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



}
