package com.sw.mes.yb.turnstore.service.impl;


import com.sw.mes.core.base.BaseServiceImpl;
import com.sw.mes.utils.StringUtils;
import com.sw.mes.yb.turnstore.dao.TurnstoreInItemDao;
import com.sw.mes.yb.turnstore.entity.TurnstoreInItem;
import com.sw.mes.yb.turnstore.service.TurnstoreInItemService;
import com.sw.mes.yb.turnstore.statics.EnumValues;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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


/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@Service
@Transactional
public class TurnstoreInItemServiceImpl extends BaseServiceImpl<TurnstoreInItem> implements TurnstoreInItemService {
    TurnstoreInItemDao dao;

    @Autowired
    public void setDao(TurnstoreInItemDao dao) {
        super.setBaseDao(dao);
        this.dao = dao;
    }

    @Override
    public List<TurnstoreInItem> getItemsByOrderNo(String orderNo) {
        return dao.getItemsByOrderNo(orderNo);
    }

    @Override
    public List<TurnstoreInItem> getItemsByInId(Integer inId) {
        return dao.getItemsByInId(inId);
    }

    @Override
    public List<Map<String, Object>> getStaticIn(String sDate, String eDate, String type) {
        return dao.getStaticIn(sDate, eDate, type);
    }

    @Override
    public TurnstoreInItem getLastByTypeAndStateAndSectionNoOrderByIdDesc(String type, String state, String sectionNo) {
        return dao.getLastByTypeAndStateAndSectionNoOrderByIdDesc(type, state, sectionNo);
    }

    @Override
    public Boolean getIsReturnRecordBySectionNoList(List<String> sectionNoList, String purpose) {
        if (CollectionUtils.isEmpty(sectionNoList) || StringUtils.isBlank(purpose)) {
            return false;
        }
        List<TurnstoreInItem> itemsBySectionNoList = dao.getItemsBySectionNoList(sectionNoList, purpose);
        if (null != itemsBySectionNoList && itemsBySectionNoList.size() != 0) {
            for (TurnstoreInItem turnstoreInItem : itemsBySectionNoList) {
                if (StringUtils.equals(turnstoreInItem.getState(), EnumValues.InState.待入库.getValue())) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public TurnstoreInItem findOneBySectionNo(String sectionNo) {
        return dao.findOneBySectionNoOrderByIdDesc(sectionNo);
    }

    @Override
    public List<TurnstoreInItem> getItemsBySectionNoAndType(String sectionNo, String type) {
        return dao.getItemsBySectionNoAndType(sectionNo, type);
    }
}
