package com.zd.bottle.controller;

import com.zd.bottle.domain.BottleStorage;
import com.zd.bottle.domain.BottleStorageOut;
import com.zd.bottle.service.BottleStorageOutService;
import com.zd.bottle.service.BottleStorageService;
import com.zd.bottle.vo.BottleStorageOutVo;
import com.zd.bottle.vo.BottleStorageVo;
import com.zd.bottle.vo.UseRecordVo;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: liujh
 * @Date: 2022/09/15/14:13
 * @Description:
 * 信息统计
 */
@RestController
@Api(tags = "信息统计")
@RequestMapping("/statistics")
public class StatisticsController extends BaseController {

    @Autowired
    private BottleStorageOutService outService;

    @Autowired
    private BottleStorageService bottleStorageService;

    /****
     * 信息统计出库列表
     * @param vo
     * @return
     */
    @PreAuthorize(hasPermi = PerPrefix.BOTTLE_STATISTICS + "outList")
    @GetMapping("/outList")
    @ApiOperation(value = "查询报警记录列表")
    public TableDataInfo<BottleStorage> outList(BottleStorageOutVo vo) {
        startPage("create_time","descending");
        List<BottleStorageOutVo> list = outService.getOutListVo(vo);
        return getDataTable(list);
    }


    /***
     * 信息统计出库详情
     * @param id
     * @return
     */
    @ApiOperation(value = "出库详情")
    @PreAuthorize(hasPermi = PerPrefix.BOTTLE_STATISTICS + "queryout")
    @GetMapping(value = "/out/{id}")
    public AjaxResult OutGetInfo(@PathVariable("id") Long id) {
        Map<String,Object> map = new HashMap<String,Object>();
        //出库详情
        BottleStorageOut storageOut =  outService.getById(id);
        map.put("bottleStorageOut",storageOut);

        //查询入库详情
        BottleStorage bottleStorage = bottleStorageService.getById(storageOut.getStorageId());
        map.put("bottleStorage",bottleStorage);

        return AjaxResult.success(map);
    }


    /**
     * 导出气瓶出库列表导出
     */
    @ApiOperation(value = "导出气瓶出库列表导出")
    @PreAuthorize(hasPermi = PerPrefix.BOTTLE_STATISTICS+ "exportout")
    @Log(title = "气瓶入库", businessType = BusinessType.EXPORT)
    @PostMapping("/exportout")
    public void exportOut(HttpServletResponse response, BottleStorageOutVo vo) throws IOException
    {
        // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<BottleStorageOutVo> listVo = outService.getOutListVo(vo);
        ExcelUtil<BottleStorageOutVo> util = new ExcelUtil<BottleStorageOutVo>(BottleStorageOutVo.class);
        LocalDate nowDate = LocalDate.now();
        util.exportExcel(response, listVo, "出库数据", null, "出库信息导出表"+nowDate);
    }







    /****
     * 信息统计入库列表
     * @param vo
     * @return
     */
    @PreAuthorize(hasPermi = PerPrefix.BOTTLE_STATISTICS + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询报警记录列表")
    public TableDataInfo<BottleStorage> list(BottleStorageVo vo) {
        startPage("create_time","descending");
        List<BottleStorageVo> list = bottleStorageService.getListVo(vo);
        return getDataTable(list);
    }

    /***
     * 信息统计入库详情
     * @param id
     * @return
     */
    @ApiOperation(value = "入库详情")
    @PreAuthorize(hasPermi = PerPrefix.BOTTLE_STATISTICS + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        Map<String,Object> map = new HashMap<String,Object>();
        //查询入库详情
        BottleStorage bottleStorage = bottleStorageService.getById(id);
        map.put("bottleStorage",bottleStorage);
        return AjaxResult.success(map);
    }

    /**
     * 导出气瓶入库列表导出
     */
    @ApiOperation(value = "导出气瓶入库列表导出")
    @PreAuthorize(hasPermi = PerPrefix.BOTTLE_STATISTICS+ PerFun.EXPORT)
    @Log(title = "气瓶入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BottleStorageVo vo) throws IOException
    {
        // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<BottleStorageVo> listVo = bottleStorageService.getListVo(vo);
        ExcelUtil<BottleStorageVo> util = new ExcelUtil<BottleStorageVo>(BottleStorageVo.class);
        LocalDate nowDate = LocalDate.now();
        util.exportExcel(response, listVo, "入库数据", null, "入库信息导出表"+nowDate);
    }

}
