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.PileModelInfo;
import com.jsowell.pile.service.IPileModelInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 充电桩型号信息Controller
 *
 * @author jsowell
 * @date 2022-08-26
 */
@RestController
@RequestMapping("/pile/model")
public class PileModelInfoController extends BaseController {
	@Autowired
	private IPileModelInfoService pileModelInfoService;

	/**
	 * 查询充电桩型号信息列表
	 */
	// @PreAuthorize("@ss.hasPermi('pile:model:list')")
	@GetMapping("/list")
	public TableDataInfo list(PileModelInfo pileModelInfo) {
		startPage();
		List<PileModelInfo> list = pileModelInfoService.selectPileModelInfoList(pileModelInfo);
		return getDataTable(list);
	}

	/**
	 * 导出充电桩型号信息列表
	 */
	@PreAuthorize("@ss.hasPermi('pile:model:export')")
	@Log(title = "充电桩型号信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, PileModelInfo pileModelInfo) {
		List<PileModelInfo> list = pileModelInfoService.selectPileModelInfoList(pileModelInfo);
		ExcelUtil<PileModelInfo> util = new ExcelUtil<PileModelInfo>(PileModelInfo.class);
		util.exportExcel(response, list, "充电桩型号信息数据");
	}

	/**
	 * 获取充电桩型号信息详细信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:model:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(pileModelInfoService.selectPileModelInfoById(id));
	}

	/**
	 * 新增充电桩型号信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:model:add')")
	@Log(title = "充电桩型号信息", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody PileModelInfo pileModelInfo) {
		return toAjax(pileModelInfoService.insertPileModelInfo(pileModelInfo));
	}

	/**
	 * 修改充电桩型号信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:model:edit')")
	@Log(title = "充电桩型号信息", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody PileModelInfo pileModelInfo) {
		return toAjax(pileModelInfoService.updatePileModelInfo(pileModelInfo));
	}

	/**
	 * 删除充电桩型号信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:model:remove')")
	@Log(title = "充电桩型号信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(pileModelInfoService.deletePileModelInfoByIds(ids));
	}
}
