package com.oqpo.api.service.stockmng;


import com.oqpo.api.entity.stockmng.StckMgntBaseInfoEntity;
import com.oqpo.api.exception.GlobalException;
import com.oqpo.api.mapper.stockmng.StockMngMapper;
import com.oqpo.api.service.CommonService;
import com.oqpo.api.web.dto.request.GridRequest;
import com.oqpo.api.web.dto.request.stockmng.SaveStockBaseInfoRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.stockmng.StockMngListResponse;
import lombok.extern.slf4j.Slf4j;
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.stream.Collectors;

@Service
@Slf4j
public class StockBaseMngService extends CommonService {

    @Autowired
    private StockMngMapper stockMngMapper;

    /* 재고기준정보 저장 */
    @Transactional
    public void saveStockBaseInfo(String userId, SaveStockBaseInfoRequest saveStockBaseInfoRequest) throws Exception {
        try {
            List<StckMgntBaseInfoEntity> list = saveStockBaseInfoRequest.toEntities(saveStockBaseInfoRequest.getGridUpdateData());
            for (StckMgntBaseInfoEntity item : list) {
                stockMngMapper.updateStckMgntBaseInfo4BaseChg(userId, item);
            }
        } catch (GlobalException e) {
            e.getStackTrace();
            throw new GlobalException(e.getSystemMessageCode());
        } catch (Exception e) {
            e.getStackTrace();
            throw new RuntimeException();
        }
    }

}
