package com.hzs.system.base.controller.api;

import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.EOperationBusiness;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.base.service.IBdStorehouseAreaMiddleService;
import com.hzs.system.base.service.IBdStorehouseService;
import com.hzs.system.base.vo.BdStorehouseAreaMiddleVO;
import com.hzs.system.base.vo.BdStorehouseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库配置前端控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/storehouse")
public class ApiBdStorehouseController extends BaseController {

    @Autowired
    private IBdStorehouseService iBdStorehouseService;
    @Autowired
    private IBdStorehouseAreaMiddleService iBdStorehouseAreaMiddleService;

    /**
     * 获取仓库列表
     */
    @Log(module = EOperationModule.STOREHOUSE, business = EOperationBusiness.STOREHOUSE, method = EOperationMethod.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(BdStorehouseVO bdStorehouse) {
        if (bdStorehouse.getPkCountry() == null) {
            bdStorehouse.setPkCountry(SecurityUtils.getPkCountry());
        }
        List<BdStorehouseVO> list = iBdStorehouseService.selectBdStorehouseList(bdStorehouse);
        list.forEach(itm -> {
            BdStorehouseAreaMiddleVO sam = new BdStorehouseAreaMiddleVO();
            sam.setPkStorehouse(itm.getPkId());
            sam.setPkCountry(bdStorehouse.getPkCountry());
            List<BdStorehouseAreaMiddleVO> samList = iBdStorehouseAreaMiddleService.getBdStorehouseAreaMiddleList(sam);
            itm.setSamList(samList);
        });
        return getDataTable(list);
    }


}
