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.PileMerchantInfo;
import com.jsowell.pile.service.IPileMerchantInfoService;
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-27
 */
@RestController
@RequestMapping("/pile/merchant")
public class PileMerchantInfoController extends BaseController {
	@Autowired
	private IPileMerchantInfoService pileMerchantInfoService;

	/**
	 * 查询充电桩运营商信息列表
	 */
	@PreAuthorize("@ss.hasPermi('pile:merchant:list')")
	@GetMapping("/list")
	public TableDataInfo list(PileMerchantInfo pileMerchantInfo) {
		startPage();
		List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo);
		return getDataTable(list);
	}

	/**
	 * 获取运营商列表 不分页
	 * @param pileMerchantInfo
	 * @return
	 */
	@PreAuthorize("@ss.hasPermi('pile:merchant:list')")
	@GetMapping("/getMerchantList")
	public TableDataInfo getMerchantList(PileMerchantInfo pileMerchantInfo) {
		List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo);
		return getDataTable(list);
	}

	/**
	 * 导出充电桩运营商信息列表
	 */
	@PreAuthorize("@ss.hasPermi('pile:merchant:export')")
	@Log(title = "充电桩运营商信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, PileMerchantInfo pileMerchantInfo) {
		List<PileMerchantInfo> list = pileMerchantInfoService.selectPileMerchantInfoList(pileMerchantInfo);
		ExcelUtil<PileMerchantInfo> util = new ExcelUtil<PileMerchantInfo>(PileMerchantInfo.class);
		util.exportExcel(response, list, "充电桩运营商信息数据");
	}

	/**
	 * 获取充电桩运营商信息详细信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:merchant:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(pileMerchantInfoService.selectPileMerchantInfoById(id));
	}

	/**
	 * 新增充电桩运营商信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:merchant:add')")
	@Log(title = "充电桩运营商信息", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody PileMerchantInfo pileMerchantInfo) {
		return toAjax(pileMerchantInfoService.insertPileMerchantInfo(pileMerchantInfo));
	}

	/**
	 * 修改充电桩运营商信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:merchant:edit')")
	@Log(title = "充电桩运营商信息", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody PileMerchantInfo pileMerchantInfo) {
		return toAjax(pileMerchantInfoService.updatePileMerchantInfo(pileMerchantInfo));
	}

	/**
	 * 删除充电桩运营商信息
	 */
	@PreAuthorize("@ss.hasPermi('pile:merchant:remove')")
	@Log(title = "充电桩运营商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(pileMerchantInfoService.deletePileMerchantInfoByIds(ids));
	}
}
