package com.ruoyi.web.v2.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.v2.model.JsStock;
import com.ruoyi.web.v2.mapper.JsStockMapper;
import com.ruoyi.web.v2.service.IJsStockService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * <p>
 * v2.0库存管理 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-05-23
 */
@Service
public class JsStockServiceImpl extends ServiceImpl<JsStockMapper, JsStock> implements IJsStockService {

    @Autowired
    private JsStockMapper stockMapper;

    @Override
    public AjaxResult page(Integer pageNum, Integer pageSize, String materialBatch, String materialName, Integer materialType) {
        Page<JsStock> page = new Page<>(pageNum, pageSize);
        QueryWrapper<JsStock> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(materialBatch), "material_batch", materialBatch)
                .or().like(StringUtils.isNotEmpty(materialName), "material_name", materialName);
        if (null != materialType) {
            queryWrapper.eq("material_type", materialType);
        }
        return success(stockMapper.selectPage(page, queryWrapper));
    }

    @Override
    public AjaxResult listAll(Map<String, String> paramsMap) {
        String materialBatch = paramsMap.get("materialBatch");
        QueryWrapper<JsStock> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(materialBatch), "material_batch", materialBatch);
        return success(stockMapper.selectList(queryWrapper));
    }
}
