package com.prolog.eis.service.shelves.impl;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import com.prolog.eis.constants.base.BaseLockConstants;
import com.prolog.eis.dao.shelves.area.CategoryAreaNoMapper;
import com.prolog.eis.dto.shelves.CategoryAreaDto;
import com.prolog.eis.dto.shelves.FindCategoryAreaDto;
import com.prolog.eis.model.outbound.BizOutboundTask;
import com.prolog.eis.model.shelves.CategoryAreaNo;
import com.prolog.eis.model.shelves.GridInfo;
import com.prolog.eis.service.shelves.CategoryAreaNoService;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.core.restriction.RestrictionBuilder;
import com.prolog.framework.core.restriction.Restrictions;
import com.prolog.framework.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@SuppressWarnings("ALL")
@Service
@Slf4j
public class CategoryAreaNoServiceImpl implements CategoryAreaNoService {


    @Autowired
    CategoryAreaNoMapper categoryAreaNoMapper;

    @Override
    public List<CategoryAreaNo> query(FindCategoryAreaDto dto) throws Exception{
        Criteria criteria = new Criteria(CategoryAreaNo.class);
        RestrictionBuilder restrictionBuilder = criteria.restrictionBuilder();
        if(StrUtil.isNotBlank(dto.getItemBarcode())){
            restrictionBuilder.eq(CategoryAreaNo::getItemBarcode, dto.getItemBarcode());
        }
        if(StrUtil.isNotBlank(dto.getItemName())){
            restrictionBuilder.eq(CategoryAreaNo::getItemName, dto.getItemName());
        }

        restrictionBuilder.build();
        return categoryAreaNoMapper.findByCriteria(criteria);
    }

    @Override
    public void save(CategoryAreaDto dto) {
        final CategoryAreaNo categoryAreaNo = new CategoryAreaNo();
        categoryAreaNo.setAreaNo(dto.getAreaNo());
        categoryAreaNo.setItemHealthCategory(dto.getItemHealthCategory());
        categoryAreaNo.setItemHealthCategoryName(dto.getItemHealthCategoryName());
        categoryAreaNo.setCreateTime(new Date());
        categoryAreaNo.setItemBarcode(dto.getItemBarcode());
        categoryAreaNo.setItemName(dto.getItemName());
        categoryAreaNo.setItemType(dto.getItemType());
        categoryAreaNo.setOwnerId(dto.getOwnerId());
        categoryAreaNo.setOwnerName(dto.getOwnerName());
        categoryAreaNoMapper.save(categoryAreaNo);
    }


    @Override
    public void update(CategoryAreaDto dto) {
        CategoryAreaNo categoryAreaNo = new CategoryAreaNo();
        BeanUtils.copyProperties(dto,categoryAreaNo);
        categoryAreaNo.setUpdateTime(new Date());
        categoryAreaNoMapper.update(categoryAreaNo);
    }

    @Override
    public void delete(Long id) {
        categoryAreaNoMapper.deleteById(id,CategoryAreaNo.class);
    }


    @Override
    public List<String> queryArea() {
        return Lists.newArrayList("AREA");
    }
}
