package com.pwt.web.controller;

import com.pwt.common.annotation.Log;
import com.pwt.common.core.controller.BaseController;
import com.pwt.common.core.domain.AjaxResult;
import com.pwt.common.core.page.TableDataInfo;
import com.pwt.common.enums.BusinessType;
import com.pwt.common.utils.poi.ExcelUtil;
import com.pwt.web.domain.ChangePowerModel;
import com.pwt.web.domain.PwtChangeBatteryRecord;
import com.pwt.web.service.IPwtChangeBatteryRecordService;
import io.swagger.annotations.Api;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 换电记录Controller
 * 
 * @author linyun
 * @date 2022-11-17
 */
@Api("换电记录")
@RestController
@RequestMapping("/web/changePowerRecord")
public class PwtChangeBatteryRecordController extends BaseController
{
    @Autowired
    private IPwtChangeBatteryRecordService pwtChangeBatteryRecordService;

    /**
     * @Description: 信息汇总换电量/换电趋势图
     * @Author: linyun
     * @Date: 2022/11/23 14:54
     * @Param:[queryType 查询参数 1：日报表 2：月报表 3：年报表]
     * @Return:com.pwt.common.core.domain.AjaxResult
     **/
    @ApiOperation("换电量/换电趋势图")
    @ApiImplicitParam(name = "queryType", value = "查询参数 1：日报表 2：月报表 3：年报表", required = true, dataType = "int", dataTypeClass = int.class)
    @GetMapping("/getChangePowerInfo")
    public AjaxResult getChangePowerInfo(int queryType)
    {
        switch (queryType)
        {
            case 1:
                List<ChangePowerModel> dayList = pwtChangeBatteryRecordService.getDayDataInfo();
                return AjaxResult.success(dayList);
            case 2:
                List<ChangePowerModel> monthList = pwtChangeBatteryRecordService.getMonthDataInfo();
                return AjaxResult.success(monthList);
            case 3:
                List<ChangePowerModel> yearList = pwtChangeBatteryRecordService.getYearDataInfo();
                return AjaxResult.success(yearList);
            default:
            return AjaxResult.error("查询参数不正确");
        }
    }

    /**
     * 查询换电记录列表
     */
    @ApiOperation("查询换电记录列表")
    @PreAuthorize("@ss.hasPermi('web:changePowerRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(PwtChangeBatteryRecord pwtChangeBatteryRecord)
    {
        startPage();
        List<PwtChangeBatteryRecord> list = pwtChangeBatteryRecordService.selectPwtChangeBatteryRecordList(pwtChangeBatteryRecord);
        return getDataTable(list);
    }

    /**
     * 导出换电记录列表
     */
    @ApiOperation("导出换电记录列表")
    @PreAuthorize("@ss.hasPermi('web:changePowerRecord:export')")
    @Log(title = "换电记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PwtChangeBatteryRecord pwtChangeBatteryRecord)
    {
        List<PwtChangeBatteryRecord> list = pwtChangeBatteryRecordService.selectPwtChangeBatteryRecordList(pwtChangeBatteryRecord);
        ExcelUtil<PwtChangeBatteryRecord> util = new ExcelUtil<PwtChangeBatteryRecord>(PwtChangeBatteryRecord.class);
        util.exportExcel(response, list, "换电记录");
    }

    /**
     * 获取换电记录详细信息
     */
    @ApiOperation("获取换电记录详细信息")
    @ApiImplicitParam(name = "recordId", value = "记录id", required = true, dataType = "Long", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermi('web:changePowerRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {

        return AjaxResult.success(pwtChangeBatteryRecordService.selectPwtChangeBatteryRecordById(recordId));
    }

    /**
     * 新增换电记录
     */
    @ApiOperation("新增换电记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "recordId", value = "记录id", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "vehicleNo", value = "车牌号", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "vin", value = "vin", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "changeBatterySn", value = "换下电池SN", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "changeBatteryPower", value = "换下电池电量", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
            @ApiImplicitParam(name = "placeBatteryCompartmentNo", value = "放置电池仓号", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "exchangeBatterySn", value = "换取电池SN", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "exchangeBatteryPower", value = "换取电池电量", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
            @ApiImplicitParam(name = "takeBatteryCompartmentNo", value = "取电池仓格号", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "changeStartTime", value = "换电开始时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "changeEndTime", value = "换电结束时间", dataType = "Date", dataTypeClass = Date.class)
    })
    @PreAuthorize("@ss.hasPermi('web:changePowerRecord:add')")
    @Log(title = "换电记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PwtChangeBatteryRecord pwtChangeBatteryRecord)
    {
        return toAjax(pwtChangeBatteryRecordService.insertPwtChangeBatteryRecord(pwtChangeBatteryRecord));
    }

    /**
     * 修改换电记录
     */
    @ApiOperation("修改换电记录")
    @PreAuthorize("@ss.hasPermi('web:changePowerRecord:edit')")
    @Log(title = "换电记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PwtChangeBatteryRecord pwtChangeBatteryRecord)
    {
        return toAjax(pwtChangeBatteryRecordService.updatePwtChangeBatteryRecord(pwtChangeBatteryRecord));
    }

    /**
     * 删除换电记录
     */
    @ApiOperation("删除换电记录")
    @PreAuthorize("@ss.hasPermi('web:changePowerRecord:remove')")
    @Log(title = "换电记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(pwtChangeBatteryRecordService.deletePwtChangeBatteryRecordByIds(recordIds));
    }
}
