package org.jeecg.modules.subwayNetwork.controller;

import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jeecg.common.api.dto.PageSearch;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.subwayNetwork.dto.SubwaySectionEditDTO;
import org.jeecg.modules.subwayNetwork.dto.SubwaySectionQueryDTO;
import org.jeecg.modules.subwayNetwork.entity.LightRail;
import org.jeecg.modules.subwayNetwork.entity.SubwaySection;
import org.jeecg.modules.subwayNetwork.service.ISubwaySectionService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.subwayNetwork.vo.SubwaySectionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

/**
 * @Description: 线路车站-地铁区间
 * @Author: jeecg-boot
 * @Date: 2023-06-15
 * @Version: V1.0
 */
@Api(tags = "线路车站-地铁区间")
@RestController
@RequestMapping("/subwayNetwork/subwaySection")
@Slf4j
public class SubwaySectionController extends JeecgController<SubwaySection, ISubwaySectionService> {
    @Autowired
    private ISubwaySectionService subwaySectionService;

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


    @AutoLog(value = "线路车站-地铁区间-编辑")
    @ApiOperation(value = "线路车站-地铁区间-编辑", notes = "线路车站-地铁区间-编辑")
    @PostMapping(value = "/edit")
    public Result<String> edit(@RequestBody SubwaySectionEditDTO dto) {

        subwaySectionService.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) {
        subwaySectionService.delete(id);
        return Result.OK("删除成功!");
    }

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


    @AutoLog(value = "线路车站-轻轨线路-获取全部线路")
    @ApiOperation(value = "线路车站-轻轨线路-获取全部线路", notes = "线路车站-轻轨线路-获取全部线路")
    @GetMapping(value = "/listAll")
    public Result<List<Map<String, Object>>> listAll() {
        List<SubwaySection> subwaySections = subwaySectionService.list();

        List<Map<String, Object>> list = new ArrayList<>();
        for (SubwaySection subwaySection : subwaySections) {
            Map<String, Object> map = new HashMap<>();
            map.put("label", subwaySection.getSectionName());
            map.put("value", subwaySection.getId());
            map.put("parentId", subwaySection.getLightRailId());
            map.put("lineAliasId",subwaySection.getLineAliasId());
            list.add(map);
        }
        return Result.OK(list);
    }
}
