package com.izouma.nineth.web;

import com.izouma.nineth.domain.User;
import com.izouma.nineth.domain.UserWareHouse;
import com.izouma.nineth.domain.WhiteListConfigInfo;
import com.izouma.nineth.dto.PageQuery;
import com.izouma.nineth.dto.UserWareHouseExcelDTO;
import com.izouma.nineth.enums.ItemType;
import com.izouma.nineth.exception.BusinessException;
import com.izouma.nineth.repo.UserRepo;
import com.izouma.nineth.repo.UserWareHouseRepo;
import com.izouma.nineth.repo.WhitelistConfigInfoRepo;
import com.izouma.nineth.service.UserWareHouseService;
import com.izouma.nineth.service.WhitelistConfigInfoService;
import com.izouma.nineth.utils.ObjUtils;
import com.izouma.nineth.utils.excel.ExcelUtils;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/whiteListConfigInfo")
@AllArgsConstructor
public class WhiteListConfigInfoController extends BaseController {


    private WhitelistConfigInfoRepo whitelistConfigInfoRepo;

    private WhitelistConfigInfoService whitelistConfigInfoService;

    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/all")
    public Page<WhiteListConfigInfo> all(@RequestBody  PageQuery pageQuery){
        return whitelistConfigInfoService.all(pageQuery);
    }


    @GetMapping("/get/{id}")
    public WhiteListConfigInfo get(@PathVariable Long id) {
        WhiteListConfigInfo whiteListConfigInfo = whitelistConfigInfoRepo.findById(id).orElseThrow(new BusinessException("无记录"));
        return whiteListConfigInfo;
    }

    @PostMapping("/batchSave")
    @PreAuthorize("hasRole('ADMIN')")
    public WhiteListConfigInfo batchSave(@RequestBody WhiteListConfigInfo info) {
        return whitelistConfigInfoService.batchSave(info);
    }

    @PostMapping("/delWhiteList")
    @PreAuthorize("hasRole('ADMIN')")
    @Transactional
    public void delWhitelistConfigById(Long whiteListId) {
        whitelistConfigInfoService.delById(whiteListId);
    }


}