package com.shinsoft.sto.service.impl.ware;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shinsoft.sto.mapper.ware.WareStoreMapper;
import com.shinsoft.sto.model.system.ResponseCodeMsg;
import com.shinsoft.sto.model.system.ResultJSON;
import com.shinsoft.sto.model.ware.WareStoreQueryVO;
import com.shinsoft.sto.service.ware.WareStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class WareStoreServiceImpl implements WareStoreService {

    @Autowired
    private WareStoreMapper wareStoreMapper;

    @Override
    public ResultJSON query(int page, int rows, Map<String, Object> params) {
        try {
            Page<WareStoreQueryVO> pageParam = new Page<>(page, rows);
            IPage<WareStoreQueryVO> result = wareStoreMapper.selectWareStorePage(pageParam, params);
            return ResultJSON.success(result);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultJSON.error(ResponseCodeMsg.CODE_EX, ex.getMessage());
        }
    }

    @Override
    public ResultJSON statistics(Map<String, Object> params) {
        try {
            Map<String, Object> stat = wareStoreMapper.selectWareStoreStat(params);
            return ResultJSON.success(stat);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResultJSON.error(ResponseCodeMsg.CODE_EX, ex.getMessage());
        }
    }
}

