package org.jeecg.modules.subwayNetwork.controller;

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

import cn.hutool.core.util.ObjectUtil;
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.LightRailQueryDTO;
import org.jeecg.modules.subwayNetwork.entity.LightRail;
import org.jeecg.modules.subwayNetwork.service.ILightRailService;

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.LightRailQueryVO;
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-14
 * @Version: V1.0
 */
@Api(tags = "线路车站-轻轨线路")
@RestController
@RequestMapping("/subwayNetwork/lightRail")
@Slf4j
public class LightRailController extends JeecgController<LightRail, ILightRailService> {
    @Autowired
    private ILightRailService lightRailService;

    /**
     * 分页列表查询
     *
     * @return
     */
    @AutoLog(value = "线路车站-轻轨线路-分页列表查询")
    @ApiOperation(value = "线路车站-轻轨线路-分页列表查询", notes = "线路车站-轻轨线路-分页列表查询")
    @PostMapping(value = "/list")
    public Result<IPage<LightRailQueryVO>> queryPageList(@RequestBody PageSearch<LightRailQueryDTO> dto) {

        IPage<LightRailQueryVO> pageList = lightRailService.queryPageList(dto);
        return Result.OK(pageList);
    }


    @AutoLog(value = "线路车站-轻轨线路-编辑")
    @ApiOperation(value = "线路车站-轻轨线路-编辑", notes = "线路车站-轻轨线路-编辑")
    @PostMapping(value = "/edit")
    public Result<String> edit(@RequestBody LightRail lightRail) {
        if (ObjectUtil.isEmpty(lightRail.getId())) {
            lightRailService.save(lightRail);
        } else {
            lightRailService.updateById(lightRail);
        }

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

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

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

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "线路车站-轻轨线路-通过id查询")
    @ApiOperation(value = "线路车站-轻轨线路-通过id查询", notes = "线路车站-轻轨线路-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<LightRail> queryById(@RequestParam(name = "id", required = true) String id) {
        LightRail lightRail = lightRailService.getById(id);
        if (lightRail == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(lightRail);
    }

}
