package com.steerinfo.appservice.appprerailwayscale.controller;

import com.steerinfo.appservice.appprerailwayscale.model.AppPreRailwayScale;
import com.steerinfo.appservice.appprerailwayscale.service.IAppPreRailwayScaleService;
import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.util.StringUtils;
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.ArrayList;
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}/appservice/prerailwayscales")
public class AppPreRailwayScaleController extends BaseRESTfulController {

    @Autowired
    IAppPreRailwayScaleService appPreRailwayScaleService;

    @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 = "/queryForApp")
    public RESTfulResult queryForApp(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<AppPreRailwayScale> list = appPreRailwayScaleService.queryForApp(parmas, pageNum, pageSize);
            return success(list);
        } 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")
    @PostMapping(value = "/delete")//String
    public RESTfulResult delete(@RequestBody AppPreRailwayScale model) {
        try {
            List<String> ids = new ArrayList<>();
            ids.add(model.getPredictionNo());
            if (ids.size() >= 0) {
                appPreRailwayScaleService.delete(ids);
            } else {

            }
            return success();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "新增数据", notes = "根据PreRailwayScale对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/add")
    public RESTfulResult chechandadd(@RequestBody AppPreRailwayScale model) {
        RESTfulResult rm = failed();
        try {
            String id = appPreRailwayScaleService.checkandadd(model);
            if (StringUtils.isNotEmpty(id)) {
                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 = "将数据改为未使用（1），重置时间")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/check")
    public RESTfulResult approval(@RequestBody AppPreRailwayScale model) {
        RESTfulResult rm = failed();
        try {
            String no = appPreRailwayScaleService.approval(model);
            if (StringUtils.isNotEmpty(no)) {
                return success(no);
            } 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 = "将数据改为未配车（0），重置时间")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    @PostMapping(value = "/uncheck")
    public RESTfulResult uncheck(@RequestBody AppPreRailwayScale model) {
        RESTfulResult rm = failed();
        try {
            String no = appPreRailwayScaleService.uncheck(model);
            if (StringUtils.isNotEmpty(no)) {
                return success(no);
            } else {
                return failed("新增失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

}
