package com.bonus.material.expectations.service.impl;

import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.expectations.domain.ExpectationsEntity;
import com.bonus.material.expectations.mapper.ExpectationsMapper;
import com.bonus.material.expectations.service.ExpectationsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Slf4j
@Service
public class ExpectationsServiceImpl implements ExpectationsService {

    @Resource
    private ExpectationsMapper mapper;

    /**
     * 在库，在用列表
     *
     * @param entity 条件
     * @return 集合
     */
    @Override
    public List<ExpectationsEntity> getExpectationsList(ExpectationsEntity entity) {
        try {
            List<ExpectationsEntity> expectationsList = mapper.getExpectationsList(entity);
            return ObjectUtils.isNotEmpty(expectationsList) ? expectationsList : Collections.emptyList();
        } catch (Exception e) {
            log.error(e.getMessage());
            return Collections.emptyList();
        }

    }

    /**
     * 获取数量
     *
     * @param entity
     */
    @Override
    public AjaxResult getCountExpectations(ExpectationsEntity entity) {
        try {
            Map<String, Objects> countExpectations = mapper.getCountExpectations(entity);
            return ObjectUtils.isNotEmpty(countExpectations) ? AjaxResult.success(countExpectations) : AjaxResult.error();
        }catch (Exception e) {
            log.error(e.getMessage());
            return AjaxResult.error();
        }
    }

    /**
     * @param entity
     * @return
     */
    @Override
    public List<ExpectationsEntity> getListDetails(ExpectationsEntity entity) {
        try {
            List<ExpectationsEntity> expectationsList = mapper.getListDetails(entity);
            return ObjectUtils.isNotEmpty(expectationsList) ? expectationsList : Collections.emptyList();
        } catch (Exception e) {
            log.error(e.getMessage());
            return Collections.emptyList();
        }
    }
}
