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.OrderRedeemLog;
import com.younike.service.service.IOrderRedeemLogService;
import com.younike.common.core.page.TableResult;

/**
 * 门店订单核销记录（订单与核销码一对多）Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/orderRedeemLog")
public class OrderRedeemLogController extends BaseController {
    @Autowired
    private IOrderRedeemLogService orderRedeemLogService;

    /**
     * 查询门店订单核销记录（订单与核销码一对多）列表
     */
    @RequiresPermissions("log:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<OrderRedeemLog> page) {

        return orderRedeemLogService.page(page);
    }


    /**
     * 获取门店订单核销记录（订单与核销码一对多）详细信息
     */
    @RequiresPermissions("log:query")
    @GetMapping(value = "/{orderRedeemLogId}")
    public APIResult getInfo(@PathVariable("orderRedeemLogId") String orderRedeemLogId) {
        return ResultGenerator.getSuccessResult(orderRedeemLogService.getById(orderRedeemLogId));
    }

    /**
     * 新增门店订单核销记录（订单与核销码一对多）
     */
    @RequiresPermissions("log:add")
    @OpLog(title = "门店订单核销记录（订单与核销码一对多）", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody OrderRedeemLog orderRedeemLog) {
        return ResultGenerator.getSuccessResult(orderRedeemLogService.save(orderRedeemLog));
    }

    /**
     * 修改门店订单核销记录（订单与核销码一对多）
     */
    @RequiresPermissions("log:edit")
    @OpLog(title = "门店订单核销记录（订单与核销码一对多）", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody OrderRedeemLog orderRedeemLog) {
        return ResultGenerator.getSuccessResult(orderRedeemLogService.updateById(orderRedeemLog));
    }

    /**
     * 删除门店订单核销记录（订单与核销码一对多）
     */
    @RequiresPermissions("log:remove")
    @OpLog(title = "门店订单核销记录（订单与核销码一对多）", type = BusinessType.DELETE)
    @DeleteMapping("/{orderRedeemLogIds}")
    public APIResult remove(@PathVariable List<String> orderRedeemLogIds) {
        return ResultGenerator.getSuccessResult(orderRedeemLogService.removeByIds(orderRedeemLogIds));
    }
}
