/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.stocks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.stocks.entity.Shelves;
import com.tofly.stocks.entity.Store;
import com.tofly.stocks.service.ShelvesService;
import com.tofly.stocks.vo.ShelvesVo;

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

import org.springframework.stereotype.Service;
import com.tofly.stocks.mapper.ShelvesMapper;

/**
 * 库存货架表
 *
 * @author admin
 * @date Fri Nov 25 00:00:00 CST 2022
 */
@Service("shelvesService")
public class ShelvesServiceImpl extends ServiceImpl<ShelvesMapper, Shelves> implements ShelvesService {

	@Override
	public List<ShelvesVo> getShelves(Map<String, Object> queryMap) {
		return baseMapper.getShelves(queryMap);
	}

	@Override
	public Page<ShelvesVo> getShelvesPage(Page page, Map<String, Object> queryMap) {
		return page.setRecords(baseMapper.getShelvesPage(page, queryMap));
	}
	/**
	 * 检查名称是否存在，用于修改和新增
	 * @param shelves
	 * @return
	 */
	@Override
	public boolean isExist(Shelves shelves) {

		QueryWrapper<Shelves> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("STORE_ID", shelves.getStoreId());
		queryWrapper.eq("SHELVES_NO", shelves.getShelvesNo());

		if (shelves.getId()!=null && shelves.getId()>0) {
			queryWrapper.ne("ID", shelves.getId());
		}
		Integer count = baseMapper.selectCount(queryWrapper);

		if (count > 0) {
			return true;
		}
		return false;
	}
}
