package com.zg.project.Inventory.AutoInventory.service.impl;

import com.zg.framework.web.page.TableDataInfo;
import com.zg.project.Inventory.domain.dto.MatchScanPageDTO;
import com.zg.project.Inventory.domain.entity.InventoryMatchScan;
import com.zg.project.Inventory.AutoInventory.mapper.InventoryMatchScanMapper;
import com.zg.project.Inventory.AutoInventory.service.InventoryMatchScanService;
import com.zg.project.Inventory.domain.vo.InventoryMatchScanSimpleVO;
import com.zg.project.Inventory.domain.vo.InventoryMatchScanVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InventoryMatchScanServiceImpl implements InventoryMatchScanService {

    @Autowired
    private InventoryMatchScanMapper mapper;

    @Override
    public void saveBatch(List<InventoryMatchScan> list) {
        mapper.insertBatch(list);
    }

    @Override
    public Map<String, Object> getAll() {

        List<InventoryMatchScan> list = mapper.getAll();


        Map<String, Object> resultMap = new HashMap<>();

        resultMap.put("list", list);


        return resultMap;
    }

    @Override
    public TableDataInfo getHistoryList(MatchScanPageDTO dto) {
        int pageNum = dto.getPageNum() == null ? 1 : dto.getPageNum();
        int pageSize = dto.getPageSize() == null ? 10 : dto.getPageSize();
        int offset = (pageNum - 1) * pageSize;

        int total = mapper.countGroupedHistory(dto);
        List<InventoryMatchScanSimpleVO> pageList = mapper.getGroupedHistoryList(dto, offset, pageSize);

        return new TableDataInfo(pageList, total);
    }

    @Override
    public List<InventoryMatchScanVO> getByTaskName(MatchScanPageDTO dto) {
        return mapper.getByTaskName(dto);
    }

}
