package com.zg.project.Inventory.AutoInventory.controller;

import com.zg.common.utils.poi.ExcelUtil;
import com.zg.framework.web.controller.BaseController;
import com.zg.framework.web.domain.AjaxResult;
import com.zg.framework.web.page.TableDataInfo;
import com.zg.project.Inventory.AutoInventory.service.InventoryMatchScanService;
import com.zg.project.Inventory.domain.dto.MatchScanPageDTO;
import com.zg.project.Inventory.domain.entity.InventoryMatchScan;
import com.zg.project.Inventory.domain.entity.InventoryTask;
import com.zg.project.Inventory.domain.vo.InventoryMatchScanSimpleVO;
import com.zg.project.Inventory.domain.vo.InventoryMatchScanVO;
import com.zg.project.Inventory.domain.vo.RkInfoMatchVO;
import com.zg.project.wisdom.domain.RkInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

import static com.zg.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/MatchScan")
public class InventoryMatchScanController extends BaseController {

    @Autowired
    private InventoryMatchScanService inventoryMatchScanService;


    /**
     * 分页查询盘点结果
     * @param matchScan
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(InventoryMatchScan matchScan) {
        startPage();
        List<InventoryMatchScan> list = inventoryMatchScanService.selectInventoryMatchScanList(matchScan);
        return getDataTable(list);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, InventoryMatchScan criteria) {
        List<InventoryMatchScan> list = inventoryMatchScanService.selectInventoryMatchScanList(criteria);
        ExcelUtil<InventoryMatchScan> util = new ExcelUtil<>(InventoryMatchScan.class);
        util.exportExcel(response, list, "盘点匹配结果");
    }

    /**
     * 根据盘点任务id查看盘点结果
     * @param matchScan
     * @return
     */
    @GetMapping("/countList")
    public TableDataInfo countList(InventoryMatchScan matchScan) {
        // 开启分页
        startPage();
        // 调用 service 层查询数据
        List<RkInfoMatchVO> list = inventoryMatchScanService.selectMatchScanCountList(matchScan);
        // 返回分页后的结果
        return getDataTable(list);
    }


    /**
     * 根据任务名称分页查询盘点结果
     * @param dto
     * @return
     */
    @PostMapping("/taskNameHistory")
    @ApiOperation("分页查询盘点结果")
    public AjaxResult getByTaskName(@RequestBody MatchScanPageDTO dto) {

        startPage();

        List<InventoryMatchScanVO> list = inventoryMatchScanService.getByTaskName(dto);

        return AjaxResult.success(getDataTable(list));

    }
}
