package com.steerinfo.baseinfo.meterbasevideoinfo.controller;

import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.framework.utils.collection.ListUtils;
import com.steerinfo.baseinfo.meterbasevideoinfo.model.MeterBaseVideoinfo;
import com.steerinfo.baseinfo.meterbasevideoinfo.service.IMeterBaseVideoinfoService;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * MeterBaseVideoinfo RESTful接口：
 *
 * @author generator
 * @version 1.0-SNAPSHORT 2020-10-15 03:15
 * 类描述
 * 修订历史：
 * 日期：2020-10-15
 * 作者：generator
 * 参考：
 * 描述：MeterBaseVideoinfo RESTful接口
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 * @see null
 */
@RestController
@RequestMapping("/${api.version}/meterbasevideoinfos")
@Api(value = "/${api.version}/meterbasevideoinfos", tags = "视频配置 - MeterBaseVideoinfoController")
public class MeterBaseVideoinfoController extends BaseRESTfulController {

    @Autowired
    IMeterBaseVideoinfoService meterBaseVideoinfoService;

    @ApiOperation(value = "获取列表", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("meterbasevideoinfo:view")
    @GetMapping(value = "/")
    public RESTfulResult list(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterBaseVideoinfo> list = meterBaseVideoinfoService.queryForPage(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }


    @ApiOperation(value = "获取列表", notes = "不分页查询")
    //@RequiresPermissions("meterbasevideoinfo:view")
    @GetMapping(value = "/list")
    public RESTfulResult listall(@RequestParam HashMap parmas) {
        try {
            List<MeterBaseVideoinfo> list = meterBaseVideoinfoService.queryAll(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "获取列表", notes = "分页模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("meterbasevideoinfo:view")
    @GetMapping(value = "/like/")
    public RESTfulResult listLike(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterBaseVideoinfo> list = meterBaseVideoinfoService.queryLikeForPage(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "创建", notes = "根据MeterBaseVideoinfo对象创建")
    @ApiImplicitParam(name = "meterBaseVideoinfo", value = "详细实体meterBaseVideoinfo", required = true, dataType = "MeterBaseVideoinfo")
    //@RequiresPermissions("meterbasevideoinfo:create")
    @PostMapping(value = "/")
    public RESTfulResult add(@ModelAttribute MeterBaseVideoinfo model) {
        try {
            MeterBaseVideoinfo meterBaseVideoinfo = meterBaseVideoinfoService.add(model);
            return success(meterBaseVideoinfo);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
    //@RequiresPermissions("meterbasevideoinfo:view")
    @GetMapping(value = "/{id}")
    public RESTfulResult get(@PathVariable String id) {
        try {
            MeterBaseVideoinfo meterBaseVideoinfo = meterBaseVideoinfoService.getById(id);
            return success(meterBaseVideoinfo);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
    //@RequiresPermissions("meterbasevideoinfo:delete")
    @DeleteMapping(value = "/{id}")//String
    public RESTfulResult delete(@PathVariable String id) {
        try {
            List<String> list = Arrays.asList(id.split(","));
            if (ListUtils.isNotEmpty(list)) {
                List<String> ids = ListUtils.convertList(list);
                meterBaseVideoinfoService.delete(ids);
            }
            return success();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }


    @ApiOperation(value = "新增数据", notes = "根据MeterBaseVideoinfo对象创建")
    @ApiImplicitParam(name = "meterBaseVideoinfo", value = "详细实体meterBaseVideoinfo", required = true, dataType = "MeterBaseVideoinfo")
    //@RequiresPermissions("meterbasevideoinfo:create")
    @PostMapping(value = "/add")
    public RESTfulResult checkandadd(@RequestBody MeterBaseVideoinfo model) {
        RESTfulResult rm = failed();
        try {
            int num = meterBaseVideoinfoService.checkandadd(model);
            if (num == 1) {
                return success(num);
            } else {
                return failed("新增失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "修改数据", notes = "根据MeterBaseVideoinfo对象修改")
    @ApiImplicitParam(name = "meterBaseVideoinfo", value = "详细实体meterBaseVideoinfo", required = true, dataType = "MeterBaseVideoinfo")
    //@RequiresPermissions("meterbasevideoinfo:create")
    @PostMapping(value = "/{id}")
    public RESTfulResult checkandupdate(@PathVariable String id, @RequestBody MeterBaseVideoinfo model) {
        RESTfulResult rm = failed();
        try {
            int num = meterBaseVideoinfoService.checkandupdate(id, model);
            if (num == 1) {
                return success(num);
            } else {
                return failed("修改失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "删除数据", notes = "根据MeterBaseVideoinfo对象删除")
    @ApiImplicitParam(name = "meterBaseVideoinfo", value = "详细实体meterBaseVideoinfo", required = true, dataType = "MeterBaseVideoinfo")
    //@RequiresPermissions("meterbasevideoinfo:create")
    @PostMapping(value = "/delete")
    public RESTfulResult checkanddelete(@RequestParam String pointid) {
        RESTfulResult rm = failed();
        try {

            int num = meterBaseVideoinfoService.checkanddelete(pointid);
            if (num == 1) {
                return success(num);
            } else {
                return failed("新增失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

}
