package com.hys.app.service.erp.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hys.app.framework.database.WebPage;
import com.hys.app.framework.exception.ServiceException;
import com.hys.app.framework.util.PageConvert;
import com.hys.app.framework.util.StringUtil;
import com.hys.app.mapper.erp.AppVersionMapper;
import com.hys.app.mapper.erp.StockStatisticsMapper;
import com.hys.app.model.erp.dos.ProductDO;
import com.hys.app.model.erp.dos.StockStatistics;
import com.hys.app.model.erp.dto.StockStatisticsQueryParam;
import com.hys.app.model.system.dos.AppVersion;
import com.hys.app.service.erp.AppVersionManager;
import com.hys.app.service.erp.ProductManager;
import com.hys.app.service.erp.StockStatisticsManager;
import com.hys.app.util.ValidateUtil;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static com.hys.app.framework.util.CollectionUtils.convertList;

/**
 * 库存统计业务接口实现
 *
 * @author dmy
 * 2023-12-05
 */
@Service
public class AppVersionManagerImpl extends ServiceImpl<AppVersionMapper, AppVersion> implements AppVersionManager {
    @Override
    public Long addVersion(AppVersion appVersion) {
        AppVersion one = getOne(new LambdaQueryWrapper<AppVersion>().eq(AppVersion::getVersion, appVersion.getVersion()));
        if (ObjectUtil.isNotNull(one)) {
            throw new ServiceException("版本号重复");
        }
        List<AppVersion> list = list();
        list.forEach(item ->item.setStatus(false));
        one.setStatus(true);
        list.add(one);
        saveOrUpdateBatch(list);
        return one.getId();
    }
}
