package com.younike.admin;

import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.common.enums.BusinessType;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.system.domain.Agent;
import com.younike.system.service.IAgentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商户代理商Controller
 * 
 * @author dail
 * @date 2022-03-09
 */
@Api("商户代理商接口")
@RestController
@RequestMapping("/admin/agent")
public class AdminAgentController extends BaseController {

    @Autowired
    private IAgentService agentService;


    /**
     * 查询商户代理商列表
     */
    @ApiOperation("查询商户代理商列表")
//    @PreAuthorize("@ss.hasPermi('system:agent:list')")
    @PreAuthorize("@ss.hasRole('operation')")
    @GetMapping("/list")
    public TableDataInfo list(Agent agent) {
        startPage();
        List<Agent> list = agentService.selectAgentList(agent);
        return getDataTable(list);
    }

    /**
     * 导出商户代理商列表
     */
    @ApiOperation("导出商户代理商列表")
//    @PreAuthorize("@ss.hasPermi('system:agent:export')")
    @PreAuthorize("@ss.hasRole('operation')")
    @Log(title = "商户代理商", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Agent agent) {
        List<Agent> list = agentService.selectAgentList(agent);
        ExcelUtil<Agent> util = new ExcelUtil<Agent>(Agent.class);
        return util.exportExcel(list, "商户代理商数据");
    }

    /**
     * 获取商户代理商详细信息
     */
    @ApiOperation("获取商户代理商详细信息")
//    @PreAuthorize("@ss.hasPermi('system:agent:query')")
    @PreAuthorize("@ss.hasRole('operation')")
    @GetMapping(value = "/{agentId}")
    public AjaxResult getInfo(@PathVariable("agentId") Long agentId) {
        return AjaxResult.success(agentService.selectAgentByAgentId(agentId));
    }

    /**
     * 新增商户代理商
     */
    @ApiOperation("新增商户代理商")
//    @PreAuthorize("@ss.hasPermi('system:agent:add')")
    @PreAuthorize("@ss.hasRole('operation')")
    @Log(title = "商户代理商", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Agent agent) {
        return toAjax(agentService.insertAgent(agent));
    }

    /**
     * 修改商户代理商
     */
    @ApiOperation("修改商户代理商")
//    @PreAuthorize("@ss.hasPermi('system:agent:edit')")
    @PreAuthorize("@ss.hasRole('operation')")
    @Log(title = "商户代理商", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Agent agent) {
        return toAjax(agentService.updateAgent(agent));
    }

    /**
     * 删除商户代理商
     */
    @ApiOperation("删除商户代理商")
//    @PreAuthorize("@ss.hasPermi('system:agent:remove')")
    @PreAuthorize("@ss.hasRole('operation')")
    @Log(title = "商户代理商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agentIds}")
    public AjaxResult remove(@PathVariable Long[] agentIds) {
        return toAjax(agentService.deleteAgentByAgentIds(agentIds));
    }

    /**
     * 逻辑删除商户代理商
     */
    @ApiOperation("逻辑删除商户代理商")
//    @PreAuthorize("@ss.hasPermi('system:agent:remove')")
    @PreAuthorize("@ss.hasRole('operation')")
    @Log(title = "商户代理商", businessType = BusinessType.UPDATE)
    @PutMapping("/{agentId}")
    public AjaxResult logicalRemoveById(@PathVariable Long agentId) {
        return toAjax(agentService.logicalRemoveById(agentId));
    }
}
