package com.steerinfo.pretrack.prerailwayscale.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.meterwork.except.MarkerMetException;
import com.steerinfo.pretrack.prerailwayscale.model.PreRailwayScale;
import com.steerinfo.pretrack.prerailwayscale.service.IPreRailwayScaleService;
import com.steerinfo.pretrack.pretrackscale.model.PreTrackScale;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
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;

/**
 * PreRailwayScale RESTful接口：
 *
 * @author generator
 * @version 1.0-SNAPSHORT 2020-10-21 09:55
 * 类描述
 * 修订历史：
 * 日期：2020-10-21
 * 作者：generator
 * 参考：
 * 描述：PreRailwayScale RESTful接口
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 * @see null
 */
@RestController
@RequestMapping("/${api.version}/prerailwayscales")
public class PreRailwayScaleController extends BaseRESTfulController {

    @Autowired
    IPreRailwayScaleService preRailwayScaleService;

    @ApiOperation(value = "获取列表", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("prerailwayscale:view")
    @GetMapping(value = "/")
    public RESTfulResult list(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<PreRailwayScale> list = preRailwayScaleService.queryForPage(parmas, pageNum, pageSize);
            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("prerailwayscale:view")
    @GetMapping(value = "/like/")
    public RESTfulResult listLike(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<PreRailwayScale> list = preRailwayScaleService.queryLikeForPage(parmas, pageNum, pageSize);
            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("prerailwayscale:view")
    @GetMapping(value = "/likeDesc/")
    public RESTfulResult likeDesc(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<PreRailwayScale> list = preRailwayScaleService.likeDesc(parmas, pageNum, pageSize);
            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("prerailwayscale:view")
    @PostMapping(value = "/like/")
    public RESTfulResult listLikePost(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<PreRailwayScale> list = preRailwayScaleService.queryLikeForPage(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "web端-计量委托倒序获取列表", notes = "分页模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    @GetMapping(value = "/likeByList/")
    public RESTfulResult likeByList(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<PreRailwayScale> list = preRailwayScaleService.likeByList(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "C#动轨倒序获取列表", notes = "不分页模糊查询")
    @PostMapping(value = "/noPage")
    public RESTfulResult listLikePost(@RequestBody HashMap parmas) {
        try {
            List<PreRailwayScale> list = preRailwayScaleService.noPage(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("prerailwayscale:view")
    @GetMapping(value = "/likeByDesc/")
    public RESTfulResult likeByDesc(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<PreRailwayScale> list = preRailwayScaleService.likeByDesc(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "创建", notes = "根据PreRailwayScale对象创建")
    @ApiImplicitParam(name = "preRailwayScale", value = "详细实体preRailwayScale", required = true, dataType = "PreRailwayScale")
    //@RequiresPermissions("prerailwayscale:create")
    @PostMapping(value = "/")
    public RESTfulResult add(@ModelAttribute PreRailwayScale model) {
        try {
            PreRailwayScale preRailwayScale = preRailwayScaleService.add(model);
            return success(preRailwayScale);
        } 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("prerailwayscale:view")
    @GetMapping(value = "/{id}")
    public RESTfulResult get(@PathVariable String id) {
        try {
            PreRailwayScale preRailwayScale = preRailwayScaleService.getById(id);
            return success(preRailwayScale);
        } catch (Exception ex) {
           ex.printStackTrace();
throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "web端--静轨一次、结净数据界面获取委托未过期的倒序列表", notes = "不分页模糊查询")
    @PostMapping(value = "/noPageDesc")
    public RESTfulResult noPageDesc(@RequestBody HashMap parmas) {
        try {
            List<PreRailwayScale> list = preRailwayScaleService.noPageDesc(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "更新详细信息", notes = "根据url的id来指定更新对象，并根据传过来的preRailwayScale信息来更新详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "preRailwayScale", value = "详细实体preRailwayScale", required = true, dataType = "PreRailwayScale")
    })
    //@RequiresPermissions("prerailwayscale:update")
    @PutMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
    public RESTfulResult update(@PathVariable String id, @RequestBody PreRailwayScale model) {
        try {
            model.setId(id);
            PreRailwayScale preRailwayScale = preRailwayScaleService.modify(model);
            return success(preRailwayScale);
        } 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("prerailwayscale: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);
                preRailwayScaleService.delete(ids);
            }
            return success();
        } catch (Exception ex) {
           ex.printStackTrace();
throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "车号获取", notes = "根据车号获取预报信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", dataType = "Integer")
    })
    @GetMapping(value = "/select")
    public RESTfulResult selectlist(@RequestParam String railwayNo, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<PreRailwayScale> pageInfo = preRailwayScaleService.selectlist(railwayNo, pageNum, pageSize);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "视图获取当前以及历史数据", notes = "获取预报信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", dataType = "Integer")
    })
    @GetMapping(value = "/selectView")
    public RESTfulResult selectView(@RequestParam HashMap param, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<PreRailwayScale> pageInfo = preRailwayScaleService.selectView(param, pageNum, pageSize);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "新增数据", notes = "根据PreRailwayScale对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/add")
    public RESTfulResult chechandadd(@RequestBody PreRailwayScale model) {
        RESTfulResult rm = failed();
        try {
            String id = preRailwayScaleService.checkandadd(model);
            if (id != null && !id.equals("")) {
                return success(id);
            } 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 = "根据PreRailwayScale对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/update")
    public RESTfulResult chechandupdate(@RequestBody PreRailwayScale model) {
        RESTfulResult rm = failed();
        try {
            PreRailwayScale pts = preRailwayScaleService.checkandupdate(model);
            if (pts != null) {
                return success(pts);
            } 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 = "根据PreRailwayScale对象停用")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/abolish")
    public RESTfulResult abolish(@RequestBody List<PreRailwayScale> models) {
        RESTfulResult rm = failed();
        try {
            int num = preRailwayScaleService.abolish(models);
            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 = "根据PreRailwayScale对象启用")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/recover")
    public RESTfulResult recover(@RequestBody List<PreRailwayScale> models) {
        RESTfulResult rm = failed();
        try {
            int num = preRailwayScaleService.recover(models);
            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 = "根据预报类型为联运的PreRailwayScale对象混装")
    @ApiImplicitParam(name = "models", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/combined")
    public RESTfulResult combined(@RequestBody List<PreRailwayScale> models) {
        RESTfulResult rm = failed();
        try {
            int num = preRailwayScaleService.combined(models);
            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 = "根据预报类型为混装的PreRailwayScale对象解除")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/remove")
    public RESTfulResult remove(@RequestBody List<PreRailwayScale> models) {
        RESTfulResult rm = failed();
        try {
            int num = preRailwayScaleService.remove(models);
            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 = "doQueryWf", notes = "获取预报信息")
    @GetMapping(value = "/doQueryWf")
    public RESTfulResult doQueryWf(@RequestParam HashMap param, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<PreRailwayScale> pageInfo = preRailwayScaleService.doQueryWf(param, pageNum, pageSize);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "通过车号查询未使用以及正使用的预报", notes = "获取预报信息")
    @GetMapping(value = "/doQueryByCar")
    public RESTfulResult doQueryByCar(@RequestParam HashMap param) {
        RESTfulResult rm = failed();
        try {
            List<PreRailwayScale> list = preRailwayScaleService.doQueryByCar(param);
            return success(list);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "静态轨道衡预报查询接口，将毛皮净信息也传过来", notes = "获取预报信息")
    @GetMapping(value = "/doQueryJLByCar")
    public RESTfulResult doQueryJLByCar(@RequestParam HashMap param) {
        RESTfulResult rm = failed();
        try {
            List<PreRailwayScale> list = preRailwayScaleService.doQueryJLByCar(param);
            return success(list);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！" + e.getMessage());
        }
        return rm;
    }

    @ApiOperation(value = "通过车号查询未使用以及正使用的预报", notes = "获取预报信息")
    @GetMapping(value = "/ceshi")
    public RESTfulResult ceshi() {
        try {
            preRailwayScaleService.InsertRailScale();
            return success();
        } catch (Exception ex) {
           ex.printStackTrace();
throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "铁水吊钩秤web端--降序获取委托列表", notes = "不分页模糊查询静态铁水衡和吊钩秤委托")
    @GetMapping(value = "/hookScaleByDesc/")
    public RESTfulResult hookScaleByDesc(@RequestParam HashMap parmas) {
        try {
            List<PreRailwayScale> list = preRailwayScaleService.hookScaleByDesc(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }
}
