package com.jsowell.web.controller.pile;

import com.jsowell.common.annotation.Log;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.core.page.TableDataInfo;
import com.jsowell.common.enums.BusinessType;
import com.jsowell.common.util.poi.ExcelUtil;
import com.jsowell.pile.domain.PileStationWhitelist;
import com.jsowell.pile.service.IPileStationWhitelistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 站点白名单Controller
 *
 * @author jsowell
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/pile/whitelist")
public class PileStationWhitelistController extends BaseController {
	@Autowired
	private IPileStationWhitelistService pileStationWhitelistService;

	/**
	 * 查询站点白名单列表
	 */
	@PreAuthorize("@ss.hasPermi('pile:whitelist:list')")
	@GetMapping("/list")
	public TableDataInfo list(PileStationWhitelist pileStationWhitelist) {
		startPage();
		List<PileStationWhitelist> list = pileStationWhitelistService.selectPileStationWhitelistList(pileStationWhitelist);
		return getDataTable(list);
	}

	/**
	 * 导出站点白名单列表
	 */
	@PreAuthorize("@ss.hasPermi('pile:whitelist:export')")
	@Log(title = "站点白名单", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, PileStationWhitelist pileStationWhitelist) {
		List<PileStationWhitelist> list = pileStationWhitelistService.selectPileStationWhitelistList(pileStationWhitelist);
		ExcelUtil<PileStationWhitelist> util = new ExcelUtil<PileStationWhitelist>(PileStationWhitelist.class);
		util.exportExcel(response, list, "站点白名单数据");
	}

	/**
	 * 获取站点白名单详细信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:whitelist:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(pileStationWhitelistService.selectPileStationWhitelistById(id));
	}

	/**
	 * 新增站点白名单
	 */
	@PreAuthorize("@ss.hasPermi('pile:whitelist:add')")
	@Log(title = "站点白名单", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody PileStationWhitelist pileStationWhitelist) {
		return toAjax(pileStationWhitelistService.insertPileStationWhitelist(pileStationWhitelist));
	}

	/**
	 * 修改站点白名单
	 */
	@PreAuthorize("@ss.hasPermi('pile:whitelist:edit')")
	@Log(title = "站点白名单", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody PileStationWhitelist pileStationWhitelist) {
		return toAjax(pileStationWhitelistService.updatePileStationWhitelist(pileStationWhitelist));
	}

	/**
	 * 删除站点白名单
	 */
	@PreAuthorize("@ss.hasPermi('pile:whitelist:remove')")
	@Log(title = "站点白名单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(pileStationWhitelistService.deletePileStationWhitelistByIds(ids));
	}
}
