package com.zhongzheng.controller.goods;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.modules.course.vo.CourseVo;
import com.zhongzheng.modules.goods.bo.GoodsCourseAddBo;
import com.zhongzheng.modules.goods.bo.GoodsCourseEditBo;
import com.zhongzheng.modules.goods.bo.GoodsCourseQueryBo;
import com.zhongzheng.modules.goods.service.IGoodsCourseService;
import com.zhongzheng.modules.goods.vo.GoodsCourseVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 商品课程关系Controller
 *
 * @author hjl
 * @date 2021-10-12
 */
@Api(value = "商品课程关系控制器", tags = {"商品课程关系管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/goods/course")
public class GoodsCourseController extends BaseController {

    private final IGoodsCourseService iGoodsCourseService;

    /**
     * 查询商品课程关系列表
     */
    @ApiOperation("查询商品课程关系列表")
    @PreAuthorize("@ss.hasPermi('system:course:list')")
    @GetMapping("/list/{id}")
    public TableDataInfo<CourseVo> list(@PathVariable Long id) {
        startPage();
        List<CourseVo> list = iGoodsCourseService.selectList(id);
        return getDataTable(list);
    }

    /**
     * 导出商品课程关系列表
     */
    /*@ApiOperation("导出商品课程关系列表")
    @PreAuthorize("@ss.hasPermi('system:course:export')")
    @Log(title = "商品课程关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<GoodsCourseVo> export(GoodsCourseQueryBo bo) {
        List<GoodsCourseVo> list = iGoodsCourseService.queryList(bo);
        ExcelUtil<GoodsCourseVo> util = new ExcelUtil<GoodsCourseVo>(GoodsCourseVo.class);
        return util.exportExcel(list, "商品课程关系");
    }*/

    /**
     * 获取商品课程关系详细信息
     */
   /* @ApiOperation("获取商品课程关系详细信息")
    @PreAuthorize("@ss.hasPermi('system:course:query')")
    @GetMapping("/{id}")
    public AjaxResult<GoodsCourseVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGoodsCourseService.queryById(id));
    }*/

    /**
     * 新增商品课程关系
     */
    @ApiOperation("新增商品课程关系")
    @PreAuthorize("@ss.hasPermi('system:course:add')")
    @Log(title = "商品课程关系", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody GoodsCourseAddBo bo) {
        return toAjax(iGoodsCourseService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改商品课程关系
     */
   /* @ApiOperation("修改商品课程关系")
    @PreAuthorize("@ss.hasPermi('system:course:edit')")
    @Log(title = "商品课程关系", businessType = BusinessType.UPDATE)
    @PostMapping()
    public AjaxResult<Void> edit(@RequestBody GoodsCourseEditBo bo) {
        return toAjax(iGoodsCourseService.updateByEditBo(bo) ? 1 : 0);
    }*/

    /**
     * 删除商品课程关系
     */
    @ApiOperation("删除商品课程关系")
    @PreAuthorize("@ss.hasPermi('system:course:remove')")
    @Log(title = "商品课程关系" , businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iGoodsCourseService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
