OilController.java 2.94 KB
package cn.com.glsx.admin.modules.controller;

import cn.com.glsx.admin.modules.model.export.OilReportExport;
import cn.com.glsx.admin.modules.model.param.OilSearch;
import cn.com.glsx.admin.modules.service.OilService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.common.enums.OperateType;
import com.glsx.plat.core.web.R;
import com.glsx.plat.office.excel.EasyExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 项目名:ne-shield-trialdrive-admin
 * 包名: cn.com.glsx.admin.modules.controller
 * 作者: Yanglinlong
 * 日期: 2021/10/18 14:44
 */
@Slf4j
@RestController
@RequestMapping(value = "/oilstatistics")
@Api(value = "油耗统计", tags = {"油耗统计"})
public class OilController {

    @Autowired
    private OilService oilService;

    @Autowired
    private HttpServletResponse response;

    @GetMapping("/search")
    @SysLog(module = "查询油耗统计", value = "查询油耗统计", action = OperateType.QUERY)
    @ApiOperation(value = "查询油耗统计")
    public R search(OilSearch search) {
        Page<Object> page = PageHelper.startPage(search.getPageNumber(), search.getPageSize(), true);
        // 优先查询油耗 t_electric_oil_mileage 表获取分页页数
        List<OilReportExport> oilPageList = oilService.search(search);

        return R.ok().putPageData(oilPageList, page.getTotal());
    }

    @GetMapping(value = "/export")
    @SysLog(module = "导出油耗统计", value = "导出油耗统计", action = OperateType.QUERY)
    @ApiOperation(value = "导出油耗统计")
    public void exportTrialDriveReport(OilSearch search) throws Exception {
        log.info("油耗统计报表导出===start");
        String fileName = "油耗统计(按日" + DateFormatUtils.format(new Date(), "yyyy-MM-dd") + ")表";
        // 优先查询油耗 t_electric_oil_mileage 表获取分页页数
        List<OilReportExport> oilPageList = oilService.search(search);

        EasyExcelUtils.writeExcel(response, oilPageList, fileName, "Sheet1", OilReportExport.class);
        log.info("油耗统计报表导出===end");
    }

    @GetMapping(value = "/years")
    @SysLog(module = "油耗统计", value = "获取油耗有数据的年份", action = OperateType.QUERY, saveLog = false)
    @ApiOperation(value = "获取油耗有数据的年份")
    public R getYearWithData() {
        List<String> yearList = oilService.getYearWithData();
        return R.ok().data(yearList);
    }
}