package com.younike.member.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
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.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.dto.AjaxResult;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.OrderGoods;
import com.younike.service.service.IOrderGoodsService;
import com.younike.common.core.page.TableResult;

/**
 * 订单明细Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/orderGoods")
public class OrderGoodsController extends BaseController {
    @Autowired
    private IOrderGoodsService orderGoodsService;

    /**
     * 查询订单明细列表
     */
    @RequiresPermissions("goods:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<OrderGoods> page) {

        return orderGoodsService.page(page);
    }


    /**
     * 获取订单明细详细信息
     */
    @RequiresPermissions("goods:query")
    @GetMapping(value = "/{orderGoodsId}")
    public APIResult getInfo(@PathVariable("orderGoodsId") String orderGoodsId) {
        return ResultGenerator.getSuccessResult(orderGoodsService.getById(orderGoodsId));
    }

    /**
     * 新增订单明细
     */
    @RequiresPermissions("goods:add")
    @OpLog(title = "订单明细", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody OrderGoods orderGoods) {
        return ResultGenerator.getSuccessResult(orderGoodsService.save(orderGoods));
    }

    /**
     * 修改订单明细
     */
    @RequiresPermissions("goods:edit")
    @OpLog(title = "订单明细", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody OrderGoods orderGoods) {
        return ResultGenerator.getSuccessResult(orderGoodsService.updateById(orderGoods));
    }

    /**
     * 删除订单明细
     */
    @RequiresPermissions("goods:remove")
    @OpLog(title = "订单明细", type = BusinessType.DELETE)
    @DeleteMapping("/{orderGoodsIds}")
    public APIResult remove(@PathVariable List<String> orderGoodsIds) {
        return ResultGenerator.getSuccessResult(orderGoodsService.removeByIds(orderGoodsIds));
    }
}
