package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.Section;
import com.tuoheng.admin.query.SectionQuery;
import com.tuoheng.admin.service.section.ISectionService;
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("/section")
public class SectionController {

    @Autowired
    private ISectionService sectionService;

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

    /**
     * 获取路段列表
     * @param query
     * @return
     */
    @GetMapping("/getList")
    public JsonResult getList(SectionQuery query){
        return sectionService.getListInfo(query);
    }

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

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

    /**
     * 根据公路id获取该公路下路段信息列表
     * @param roadId
     * @return
     */
    @GetMapping("/list/by/road/{roadId}")
    public JsonResult getListByRoadId(@PathVariable("roadId") String roadId) {
        return sectionService.getListByRoadId(roadId);
    }

    /**
     * 根据公路id和部门id获取该公路下路段信息列表
     * @param roadId
     * @return
     */
    @GetMapping(value = {"/list/by/road/dept/{roadId}","/list/by/road/dept/{roadId}/{deptId}"})
    public JsonResult getListByRoadIdAndDeptId(@PathVariable(value = "roadId") String roadId, @PathVariable(required = false) String deptId) {
        return sectionService.getListByRoadIdAndDeptId(roadId, deptId);
    }

    /**
     * 根据id获取路段详情
     * @param sectionId
     * @return
     */
    @GetMapping("/info/{sectionId}")
    public JsonResult info(@PathVariable("sectionId") String sectionId){
        return sectionService.getSectionInfo(sectionId);
    }

    /**
     * 新增路段
     * @param entity
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody Section entity){
        return sectionService.editInfo(entity);
    }

    /**
     * 编辑路段
     * @param section
     * @return
     */
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody Section section){
        return sectionService.editInfo(section);
    }

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



}
