package org.jeecg.modules.subwayNetwork.controller;

import cn.hutool.core.util.ObjectUtil;
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.TrainStationEditDTO;
import org.jeecg.modules.subwayNetwork.dto.TrainStationQueryDTO;
import org.jeecg.modules.subwayNetwork.entity.LightRail;
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.*;

/**
 * @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 = "线路车站-地铁站-分页列表查询")
    @PostMapping(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 = "/edit")
    public Result<String> edit(@RequestBody TrainStationEditDTO dto) {

        trainStationService.edit(dto);

        return Result.OK("编辑成功!");
    }


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


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


    @AutoLog(value = "线路车站-地铁站-获取全部车站")
    @ApiOperation(value = "线路车站-地铁站-获取全部车站", notes = "线路车站-地铁站-获取全部车站")
    @GetMapping(value = "/listAll")
    public Result<List<Map<String, Object>>> listAll() {
        List<TrainStation> pageList = trainStationService.list();

        List<Map<String, Object>> list = new ArrayList<>();
        for (TrainStation trainStation : pageList) {
            Map<String, Object> map = new HashMap<>();
            map.put("label", trainStation.getStationName());
            map.put("value", trainStation.getId());
            map.put("lineAliasCode", trainStation.getLineAliasId());
            map.put("lightRailId", trainStation.getLightRailId());
            list.add(map);
        }
        return Result.OK(list);
    }

}
