package com.tuoheng.admin.controller;

import com.tuoheng.admin.entity.RoadInformation;
import com.tuoheng.admin.query.RoadInformationQuery;
import com.tuoheng.admin.service.road.RoadInformationService;
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("/roadInformation")
public class RoadInformationController {

    @Autowired
    private RoadInformationService roadInformationService;

    /**
     * 获取公路信息列表(分页)
     * @param query
     * @return
     */
    @GetMapping("/index")
    public JsonResult index(RoadInformationQuery query){
        return roadInformationService.queryPage(query);
    }

    /**
     * 获取公路信息列表
     * @param query
     * @return
     */
    @GetMapping("/getList")
    public JsonResult getList(RoadInformationQuery query){
        return roadInformationService.getListInfo(query);
    }

    /**
     * 根据当前租户id获取
     * @return
     */
    @GetMapping("/getListByTenantId")
    public JsonResult getListByTenantId(){
        return roadInformationService.getListByTenantId();

    }

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

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

    /**
     * 公路新增
     * @param entity
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody RoadInformation entity){
        return roadInformationService.editInfo(entity);
    }

    /**
     * 编辑公路
     * @param entity
     * @return
     */
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody RoadInformation entity){
        return roadInformationService.editInfo(entity);
    }

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

}
