package com.younike.merchant;

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.bean.BeanUtils;
import com.younike.system.domain.Goods;
import com.younike.system.domain.ServerUser;
import com.younike.system.domain.vo.*;
import com.younike.system.service.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;

/**
 * 服务项目信息Controller
 *
 * @author elev
 * @date 2022-01-04
 */
@RestController
@RequestMapping("/system/goods")
public class GoodsController extends BaseController
{
    @Autowired
    private IGoodsService goodsService;
    @Autowired
    private IGoodsServerService goodsServerService;
    @Autowired
    private IServerUserService serverUserService;

    @Log(title = "保存服务项目", businessType = BusinessType.INSERT)
    @PostMapping("save")
    public AjaxResult save(@RequestBody GoodsFormVO goodsFormVO)
    {
        return AjaxResult.success(goodsService.save(goodsFormVO));
    }

    @ApiOperation("查询服务列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Goods goods) {
        startPage();
        return getDataTable(goodsService.list(goods));
    }

    @Log(title = "删除服务项目", businessType = BusinessType.DELETE)
    @GetMapping("/remove")
    public AjaxResult remove(@RequestParam("goodsId") Long goodsId) {
        return AjaxResult.success(goodsService.remove(goodsId));
    }

    @ApiOperation("上架")
    @GetMapping("/onShelf")
    public AjaxResult onShelf(@RequestParam("goodsId") Long goodsId) {
        return AjaxResult.success(goodsService.onShelf(goodsId));
    }

    @ApiOperation("下架")
    @GetMapping("/offShelf")
    public AjaxResult offShelf(@RequestParam("goodsId") Long goodsId) {
        return AjaxResult.success(goodsService.offShelf(goodsId));
    }

    @ApiOperation("查询商品详细")
    @GetMapping("/detail")
    public AjaxResult detail(@RequestParam("goodsId") Long goodsId) {
        return AjaxResult.success(goodsService.detail(goodsId));
    }

    @ApiOperation("查询服务人员列表")
    @PostMapping("/serverUserList")
    public TableDataInfo serverUserList(@RequestBody ServerUserSearchParam searchParam) {
        startPage();
        List<ServerUser> list = serverUserService.getServerUserList(searchParam);
        return getDataTable(list);
    }


}
