package com.xinelu.manage.controller.goodsInfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.custominterface.Insert;
import com.xinelu.common.custominterface.Update;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.manage.domain.goodsInfo.GoodsInfo;
import com.xinelu.manage.dto.goodsInfo.GoodsInfoDTO;
import com.xinelu.manage.service.goodsInfo.GoodsOperateInfoService;
import com.xinelu.manage.service.goodsInfo.IGoodsInfoService;
import com.xinelu.manage.vo.goodsInfo.GetGoodDetails;
import com.xinelu.manage.vo.goodsInfo.GoodsInfoVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @Description 运营商品管理控制器
 * @Author 纪寒
 * @Date 2022-11-08 11:04:25
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/operateGoodInfo")
public class OperateGoodInfoController extends BaseController {

    @Resource
    private IGoodsInfoService goodsInfoService;
    @Resource
    private GoodsOperateInfoService goodsOperateInfoService;

    /**
     * 运营PC-查询商品基本信息列表
     *
     * @param goodsInfo 查询条件
     * @return 列表信息
     */
    @PreAuthorize("@ss.hasPermi('system:operateGoodInfo:goodsInfoList')")
    @GetMapping("/goodsInfoList")
    public TableDataInfo goodsInfoList(GoodsInfoVO goodsInfo) {
        startPage();
        List<GoodsInfoVO> goodsInfoList = goodsInfoService.getGoodsInfoList(goodsInfo);
        return getDataTable(goodsInfoList);
    }

    /**
     * 运营PC-根据商品id查询商品详细信息
     *
     * @param goodsInfoId 商品详细id
     * @return 商品详情信息
     **/
    @PreAuthorize("@ss.hasPermi('system:operateGoodInfo:goodsDetails')")
    @GetMapping("/goodsDetails")
    public AjaxResult goodsDetails(Long goodsInfoId) {
        if (Objects.isNull(goodsInfoId)) {
            return AjaxResult.error("商品详细id不能为空！");
        }
        GetGoodDetails goodsDetails = goodsInfoService.getGoodsDetails(goodsInfoId);
        return AjaxResult.success(goodsDetails);
    }

    /**
     * 运营PC端-新增商品基本信息
     *
     * @param goodsInfo 商品信息
     * @return 添加结果
     */
    @PreAuthorize("@ss.hasPermi('system:operateGoodInfo:add')")
    @Log(title = "运营PC端商品基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated(Insert.class) @RequestBody GoodsInfoDTO goodsInfo) {
        return goodsOperateInfoService.insertGoodsOperateInfo(goodsInfo);
    }

    /**
     * 运营PC-修改商品基本信息
     *
     * @param goodsInfo 商品信息
     * @return 修改结果
     */
    @PreAuthorize("@ss.hasPermi('system:operateGoodInfo:edit')")
    @Log(title = "运营PC端商品基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated(Update.class) @RequestBody GoodsInfoDTO goodsInfo) {
        return goodsOperateInfoService.updateGoodsOperateInfo(goodsInfo);
    }

    /**
     * 运营PC-删除商品基本信息
     *
     * @param ids 商品id集合
     * @return 删除信息
     */
    @PreAuthorize("@ss.hasPermi('system:operateGoodInfo:remove')")
    @Log(title = "运营PC端商品基本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return goodsInfoService.deleteGoodsInfoByIds(ids);
    }

    /**
     * 运营PC-修改商品上架状态基本信息
     *
     * @param goodsInfo 商品信息
     * @return 上架结果
     */
    @PreAuthorize("@ss.hasPermi('system:operateGoodInfo:editGoodsWhetherShelf')")
    @Log(title = "运营PC端商品基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/editGoodsWhetherShelf")
    public AjaxResult editGoodsWhetherShelf(@RequestBody GoodsInfo goodsInfo) {
        return AjaxResult.success(goodsInfoService.updateGoodsWhetherShelf(goodsInfo));
    }
}
