package com.elephant.framework.galaxy.aroad.module.zhjg.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.elephant.framework.galaxy.aroad.module.zhjg.entity.CxysBeyondFormat;
import com.elephant.framework.galaxy.aroad.module.zhjg.entity.CxysDataAnalysis;
import com.elephant.framework.galaxy.aroad.module.zhjg.entity.ShowCxysTotal;
import com.elephant.framework.galaxy.aroad.response.R;
import com.elephant.framework.galaxy.aroad.module.common.annotation.SysLog;
import com.elephant.framework.galaxy.aroad.module.zhjg.entity.ZhjgLzglCxysxk;
import com.elephant.framework.galaxy.aroad.module.zhjg.service.ZhjgLzglCxysxkService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;

import java.util.List;
import java.util.UUID;


/**
 * 超限运输许可表
 *
 * @author wangjian
 * @date 2019-03-27 17:46:24
 */
@RestController
@AllArgsConstructor
@RequestMapping("/zhjg/lzglcxysxk")
public class ZhjgLzglCxysxkController extends BaseController  {

  private final  ZhjgLzglCxysxkService zhjgLzglCxysxkService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param zhjgLzglCxysxk 超限运输许可表
   * @return
   */
  @GetMapping("/page")
  public R getZhjgLzglCxysxkPage(Page page, ZhjgLzglCxysxk zhjgLzglCxysxk) {
    return  new R<>(zhjgLzglCxysxkService.page(page,Wrappers.query(zhjgLzglCxysxk)));
  }

  /**
   * 超限许可许可公示分页查询
   *
   * @param page 分页对象
   * @param startDate 开始时间
   * @param endDate 结束时间
   * @param xkdh 许可单号
   * @param cph 车牌号
   * @return
   */
  @GetMapping("/xkgsByPage")
  public R selectCxysXkgsByCurrentDate(Page page, String startDate, String endDate, String xkdh, String cph) {
    return new R<>(zhjgLzglCxysxkService.selectCxysXkgsByCurrentDate(page, startDate, endDate, xkdh, cph));
  }

  /**
   * 查询跨省发证审批数量
   * @param startDate 开始时间
   * @param endDate 结束时间
   * @return 数量
   */
  @GetMapping("/ksfzspNumber")
  public R selectCountKsFzSpByDate(String startDate, String endDate) {
    System.out.println("startDate: "+startDate);
    System.out.println("endDate: "+endDate);

    return new R<>(zhjgLzglCxysxkService.selectCountKsFzSpByDate(startDate,endDate));
  }

  /**
   * 根据许可单号查询超限许可信息是否已存在(大于0表示已存在)
   * @param xkdh
   * @return
   */
  @GetMapping("/{xkdh}")
  public Integer getZhjgLzglCxysxkByXkdh(String xkdh){
      return zhjgLzglCxysxkService.getZhjgLzglCxysxkByXkdh(xkdh);
  }

  /**
   * 超限运输数据分析页面统计数据
   */
  @GetMapping("/cxysSjfx")
  public CxysDataAnalysis selectCxysSjfx(Double startLong, Double endLong,
                                        Double startWidth, Double endWidth,
                                        Double startHeight, Double endHeight,
                                        Double startWeight, Double endWeight,
                                        String startDate, String endDate) {
    System.out.println("startLong :"+startLong);
    System.out.println("endLong :"+endLong);
    System.out.println("startWidth :"+startWidth);
    System.out.println("endWidth :"+endWidth);
    System.out.println("startHeight :"+startHeight);
    System.out.println("endHeight :"+endHeight);
    System.out.println("startWeight :"+startWeight);
    System.out.println("endWeight :"+endWeight);
    System.out.println("startDate :"+startDate);
    System.out.println("endDate :"+endDate);

    return  zhjgLzglCxysxkService.selectCxysSjfx(startLong,endLong,startWidth,endWidth,startHeight,endHeight,startWeight,endWeight,startDate,endDate);
  }

  /**
   * 查询某时间段内数据
   * @param startDate
   * @param endDate
   * @return
   */
  @GetMapping("/getDataByDate")
  public List<ZhjgLzglCxysxk> findZhjgLzglCxysxkByDate(String startDate, String endDate) {
    if(startDate==null || endDate==null){
      return null;
    }
    startDate = startDate.trim();
    endDate = endDate.trim();
    return  zhjgLzglCxysxkService.findZhjgLzglCxysxkByDate(startDate,endDate);
  }

  /**
   * 超限运输综合展示页面
   * @param startDate
   * @param endDate
   * @return
   */
  @GetMapping("/cxysZhzs")
  public ShowCxysTotal seleCxysZhzs(String startDate, String endDate) {
    return zhjgLzglCxysxkService.seleCxysZhzs(startDate,endDate);
  }

  /**
   * 通过id查询超限运输许可表
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(zhjgLzglCxysxkService.getById(id));
  }

  /**
   * 新增超限运输许可表
   * @param zhjgLzglCxysxk 超限运输许可表
   * @return R
   */
  @SysLog("新增超限运输许可表")
  @PostMapping
  public R save(@RequestBody ZhjgLzglCxysxk zhjgLzglCxysxk){
    return new R<>(zhjgLzglCxysxkService.save(zhjgLzglCxysxk));
  }

  /**
   * 修改超限运输许可表
   * @param zhjgLzglCxysxk 超限运输许可表
   * @return R
   */
  @SysLog("修改超限运输许可表")
  @PutMapping
  public R updateById(@RequestBody ZhjgLzglCxysxk zhjgLzglCxysxk){
    return new R<>(zhjgLzglCxysxkService.updateById(zhjgLzglCxysxk));
  }

  /**
   * 通过id删除超限运输许可表
   * @param id id
   * @return R
   */
  @SysLog("删除超限运输许可表")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(zhjgLzglCxysxkService.removeById(id));
  }

}
