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

import com.prolog.eis.dao.out.BizOutboundTaskMapper;
import com.prolog.eis.dao.out.shelves.GridInfoMapper;
import com.prolog.eis.dto.bindgrid.BGDGridDto;
import com.prolog.eis.dto.bindgrid.BindGridDispatchDto;
import com.prolog.eis.model.shelves.GridInfo;
import com.prolog.eis.service.bindgrid.BindGridInitService;
import com.prolog.framework.utils.MapUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Version: 1.0
 * @Author: wuhan
 * @Created: 2024/8/1 15:38
 */
@Service
public class BindGridInitServiceImpl implements BindGridInitService {
    @Resource
    private GridInfoMapper gridInfoMapper;

    @Resource
    private BizOutboundTaskMapper bizOutboundTaskMapper;

    @Override
    public BindGridDispatchDto init() throws Exception {
        BindGridDispatchDto dispatchDto = new BindGridDispatchDto();

        List<GridInfo> gridInfoList = gridInfoMapper.findByMap(MapUtils.put("isLock", 0).getMap(), GridInfo.class);

        for (GridInfo gridInfo : gridInfoList) {
            BGDGridDto grid = new BGDGridDto();
            grid.setGridNo(gridInfo.getGridNo());
            grid.setGroupNo(gridInfo.getGroupNo());
            grid.setBindOrderId(gridInfo.getOrderId());

            dispatchDto.getGridList().add(grid);
        }

        List<Integer> orderIdList = bizOutboundTaskMapper.queryNotBindOrderIds();
        dispatchDto.setOrderIdList(orderIdList);

        dispatchDto.init();
        return dispatchDto;
    }
}
