package com.steerinfo.meterwork.meterworkcarmetertime.controller;

import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.framework.utils.collection.ListUtils;
import com.steerinfo.meterwork.meterworkcaractualfirst.model.MeterWorkCarActualFirst;
import com.steerinfo.meterwork.meterworkcaractualfirst.service.IMeterWorkCarActualFirstService;
import com.steerinfo.meterwork.meterworkcarmetertime.model.GroupTimeVo;
import com.steerinfo.meterwork.meterworkcarmetertime.model.MeterWorkCarMeterTime;
import com.steerinfo.meterwork.meterworkcarmetertime.model.PointDetailsBo;
import com.steerinfo.meterwork.meterworkcarmetertime.model.PointDetailsVo;
import com.steerinfo.meterwork.meterworkcarmetertime.service.IMeterWorkCarMeterTimeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.math.BigDecimal;

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

   @Autowired
    IMeterWorkCarMeterTimeService meterWorkCarMeterTimeService;
    @Autowired
    IMeterWorkCarActualFirstService meterWorkCarActualFirstService;



    @ApiOperation(value="获取称点统计时间")
    @ApiImplicitParam(name = "meterWorkCarMeterTime", value = "详细实体meterWorkCarMeterTime", required = true, dataType = "MeterWorkCarMeterTime")
    @PostMapping(value = "/getGroupByTime")
    @Transactional
    public RESTfulResult getGroupByTime(@RequestBody(required = false) HashMap meterWorkCarMeterTime){
        try {
            List<GroupTimeVo> groupByTime = meterWorkCarMeterTimeService.getGroupByTime(meterWorkCarMeterTime);
            return success(groupByTime);
        }catch (Exception e){
            e.printStackTrace();
            return success(null,"操作失败");
        }
    }

    @ApiOperation(value="获取称点详情")
    @ApiImplicitParam(name = "meterWorkCarMeterTime", value = "详细实体meterWorkCarMeterTime", required = true, dataType = "MeterWorkCarMeterTime")
    @PostMapping(value = "/getPointDetails")
    @Transactional
    public RESTfulResult getPointDetails(@RequestBody(required = false) PointDetailsBo pointDetailsBo){
        try {

            if(pointDetailsBo==null||
                    (pointDetailsBo.getBaseSpotName()==null||
                    "".equals(pointDetailsBo.getBaseSpotName()))&&
                            (pointDetailsBo.getBaseSpotNo()==null||
                    "".equals(pointDetailsBo.getBaseSpotNo()))){
                return failed("参数错误：请传入计量点参数");
            }
            //分页功能
            PageHelper.startPage(pointDetailsBo.getPageNum(),pointDetailsBo.getPageSize());
            List<PointDetailsVo> pointDetails = meterWorkCarMeterTimeService.getPointDetails(pointDetailsBo);
            PageList<PointDetailsVo> pageList=new PageList<>(pointDetails);
            return success(pageList);
        }catch (Exception e){
            e.printStackTrace();
            return success(null,"操作失败");
        }
    }

    @ApiOperation(value="通过站点获取一次数据和计量时间效率分析列表", notes="分页查询")
    //@RequiresPermissions("meterworkcarmetertime:view")
    @PostMapping(value = "/carMeterTimeAndCarFirstBySpot")
    public RESTfulResult carMeterTimeAndCarFirstBySpot(@RequestBody HashMap parmas){
        PageList<MeterWorkCarMeterTime> list = meterWorkCarMeterTimeService.carMeterTimeAndCarFirstBySpot(parmas, Integer.parseInt(parmas.get("pageNum").toString()), Integer.parseInt(parmas.get("pageSize").toString()));
        return success(list);
    }

    @ApiOperation(value="获取计量及时性分析班组统计", notes="分页查询")
    //@RequiresPermissions("meterworkcarmetertime:view")
    @PostMapping(value = "/getCarMeterTimeAndCarFirstCount")
    public RESTfulResult getCarMeterTimeAndCarFirstCount(@RequestBody(required = false) HashMap parmas){
        List<Map<String, Object>> list = meterWorkCarMeterTimeService.getCarMeterTimeAndCarFirstCount(parmas);
        return success(list);
    }

    @ApiOperation(value="新增汽车衡计量时间")
    @ApiImplicitParam(name = "meterWorkCarMeterTime", value = "详细实体meterWorkCarMeterTime", required = true, dataType = "MeterWorkCarMeterTime")
    @PostMapping(value = "/insert")
    @Transactional
    public RESTfulResult insert(@RequestBody MeterWorkCarMeterTime meterWorkCarMeterTime){
        try {
            MeterWorkCarMeterTime add = meterWorkCarMeterTimeService.add(meterWorkCarMeterTime);
            return success(add,"新增成功");
        }catch (Exception e){
            e.printStackTrace();
            return success(null,"操作失败");
        }
    }

    @ApiOperation(value="获取列表", notes="分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("meterworkcarmetertime:view")
    @GetMapping(value = "/")
    public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
        PageList<MeterWorkCarMeterTime> list = meterWorkCarMeterTimeService.queryForPage(parmas, pageNum, pageSize);
        return success(list);
    }

    @ApiOperation(value="获取列表", notes="分页模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("meterworkcarmetertime:view")
    @GetMapping(value = "/like/")
    public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){
        PageList<MeterWorkCarMeterTime> list = meterWorkCarMeterTimeService.queryLikeForPage(parmas, pageNum, pageSize);
        return success(list);
    }

}
