package org.jeecg.modules.subwayNetwork.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.dto.PageSearch;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.subwayNetwork.dto.TrainStationQueryDTO;
import org.jeecg.modules.subwayNetwork.entity.TrainStation;
import org.jeecg.modules.subwayNetwork.service.ITrainStationService;
import org.jeecg.modules.subwayNetwork.vo.TrainStationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @Description: 线路车站-地铁站
 * @Author: jeecg-boot
 * @Date: 2023-06-14
 * @Version: V1.0
 */
@Api(tags = "线路车站-地铁站")
@RestController
@RequestMapping("/subwayNetwork/trainStation")
@Slf4j
public class TrainStationController extends JeecgController<TrainStation, ITrainStationService> {
    @Autowired
    private ITrainStationService trainStationService;

    @AutoLog(value = "线路车站-地铁站-分页列表查询")
    @ApiOperation(value = "线路车站-地铁站-分页列表查询", notes = "线路车站-地铁站-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<TrainStationVO>> queryPageList(@RequestBody PageSearch<TrainStationQueryDTO> dto) {
        IPage<TrainStationVO> pageList = trainStationService.queryPageList(dto);
        return Result.OK(pageList);
    }

    @AutoLog(value = "线路车站-地铁站-添加")
    @ApiOperation(value = "线路车站-地铁站-添加", notes = "线路车站-地铁站-添加")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody TrainStation trainStation) {
        trainStationService.save(trainStation);
        return Result.OK("添加成功！");
    }

    @AutoLog(value = "线路车站-地铁站-编辑")
    @ApiOperation(value = "线路车站-地铁站-编辑", notes = "线路车站-地铁站-编辑")
    @PostMapping(value = "/edit")
    public Result<String> edit(@RequestBody TrainStation trainStation) {
        trainStationService.updateById(trainStation);
        return Result.OK("编辑成功!");
    }


    @AutoLog(value = "线路车站-地铁站-通过id删除")
    @ApiOperation(value = "线路车站-地铁站-通过id删除", notes = "线路车站-地铁站-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        trainStationService.removeById(id);
        return Result.OK("删除成功!");
    }


    @AutoLog(value = "线路车站-地铁站-批量删除")
    @ApiOperation(value = "线路车站-地铁站-批量删除", notes = "线路车站-地铁站-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.trainStationService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }


}
