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.utils.StringUtils;
import com.ruoyi.web.v2.entity.JsStockInfo;
import com.ruoyi.web.v2.entity.JsStockInfoRequest;
import com.ruoyi.web.v2.mapper.JsStockInfoMapper;
import com.ruoyi.web.v2.service.IJsStockInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.namespace.QName;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-11-11
 */
@Service
public class JsStockInfoServiceImpl extends ServiceImpl<JsStockInfoMapper, JsStockInfo> implements IJsStockInfoService {

    @Autowired
    private JsStockInfoMapper jsStockInfoMapper;

    @Override
    public Page<JsStockInfo> listPage(JsStockInfoRequest jsStockInfoRequest) {

        QueryWrapper<JsStockInfo> infoQueryWrapper = getWrapper(jsStockInfoRequest);
        Page<JsStockInfo> page = jsStockInfoMapper.listPage(infoQueryWrapper,new Page<JsStockInfo>(jsStockInfoRequest.getPageNum(),jsStockInfoRequest.getPageSize()));
        return page;
    }

    @Override
    public List<JsStockInfo> listList(JsStockInfoRequest jsStockInfoRequest) {
        QueryWrapper<JsStockInfo> infoQueryWrapper = getWrapper(jsStockInfoRequest);
        return jsStockInfoMapper.listList(infoQueryWrapper);

    }

    private QueryWrapper<JsStockInfo> getWrapper(JsStockInfoRequest jsStockInfoRequest) {
        QueryWrapper<JsStockInfo> infoQueryWrapper = new QueryWrapper<>();
        infoQueryWrapper.ge(StringUtils.isNotEmpty(jsStockInfoRequest.getStartTime()),"create_time",jsStockInfoRequest.getStartTime());
        infoQueryWrapper.le(StringUtils.isNotEmpty(jsStockInfoRequest.getEndTime()),"create_time",jsStockInfoRequest.getEndTime());
        infoQueryWrapper.like(StringUtils.isNotEmpty(jsStockInfoRequest.getMaterialName()),"material_name",jsStockInfoRequest.getMaterialName());
        infoQueryWrapper.like(StringUtils.isNotEmpty(jsStockInfoRequest.getLinghuoren()),"linghuoren",jsStockInfoRequest.getLinghuoren());
        return infoQueryWrapper;
    }
}
