package com.younike.admin;

import java.util.List;

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

/**
 * 商品服务人员信息Controller
 * 
 * @author elev
 * @date 2022-01-08
 */
@Api("商品服务人员信息接口")
@RestController
@RequestMapping("/admin/goods/server")
public class AdminGoodsServerController extends BaseController {
    @Autowired
    private IGoodsServerService goodsServerService;

    /**
     * 查询商品服务人员信息列表
     */
    @ApiOperation("查询商品服务人员信息列表")
    @PreAuthorize("@ss.hasPermi('system:server:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsServer goodsServer) {
        startPage();
        List<GoodsServer> list = goodsServerService.selectGoodsServerList(goodsServer);
        return getDataTable(list);
    }

    /**
     * 查询商品服务人员信息列表
     */
    @ApiOperation("根据服务人员查询服务列表")
    @PreAuthorize("@ss.hasPermi('system:server:list')")
//    @AnonymousAccess
    @GetMapping("/serverGoodsList")
    public TableDataInfo serverGoodsList(@RequestParam("serverId") Long serverId) {
        startPage();
        List<GoodsServerResultVo> list = goodsServerService.serverGoodsList(serverId);
        return getDataTable(list);
    }

    /**
     * 导出商品服务人员信息列表
     */
    @ApiOperation("导出商品服务人员信息列表")
    @PreAuthorize("@ss.hasPermi('system:server:export')")
    @Log(title = "商品服务人员信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GoodsServer goodsServer) {
        List<GoodsServer> list = goodsServerService.selectGoodsServerList(goodsServer);
        ExcelUtil<GoodsServer> util = new ExcelUtil<GoodsServer>(GoodsServer.class);
        return util.exportExcel(list, "商品服务人员信息数据");
    }

    /**
     * 获取商品服务人员信息详细信息
     */
    @ApiOperation("获取商品服务人员信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:server:query')")
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId) {
        return AjaxResult.success(goodsServerService.selectGoodsServerByGoodsId(goodsId));
    }

    /**
     * 新增商品服务人员信息
     */
    @ApiOperation("新增商品服务人员信息")
    @PreAuthorize("@ss.hasPermi('system:server:add')")
    @Log(title = "商品服务人员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsServer goodsServer) {
        return toAjax(goodsServerService.insertGoodsServer(goodsServer));
    }

    /**
     * 修改商品服务人员信息
     */
    @ApiOperation("修改商品服务人员信息")
    @PreAuthorize("@ss.hasPermi('system:server:edit')")
    @Log(title = "商品服务人员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsServer goodsServer) {
        return toAjax(goodsServerService.updateGoodsServer(goodsServer));
    }

    /**
     * 删除商品服务人员信息
     */
    @ApiOperation("删除商品服务人员信息")
    @PreAuthorize("@ss.hasPermi('system:server:remove')")
    @Log(title = "商品服务人员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds) {
        return toAjax(goodsServerService.deleteGoodsServerByGoodsIds(goodsIds));
    }
}
