/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.model.DistributionProdBind;
import com.yami.shop.distribution.comment.service.DistributionProdBindService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 分销商品绑定表
 *
 * @author xwc
 * @date 2019-04-22 10:01:44
 */
@RestController
@RequestMapping("/distribution/distributionProdBind")
@AllArgsConstructor
public class DistributionProdBindController {

    private final DistributionProdBindService distributionProdBindService;

    /**
     * 分页查询
     *
     * @param page                 分页对象
     * @param distributionProdBind 分销商品绑定表
     * @return 分页数据
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<DistributionProdBind>> getDistributionProdBindPage(PageParam<DistributionProdBind> page, DistributionProdBind distributionProdBind) {
        return ResponseEntity.ok(distributionProdBindService.page(page, new LambdaQueryWrapper<DistributionProdBind>()));
    }


    /**
     * 通过id查询分销商品绑定表
     *
     * @param id id
     * @return 单个数据
     */
    @GetMapping("/info/{id}")
    public ResponseEntity<DistributionProdBind> getById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(distributionProdBindService.getById(id));
    }

    /**
     * 新增分销商品绑定表
     *
     * @param distributionProdBind 分销商品绑定表
     * @return 是否新增成功
     */
    @SysLog("新增分销商品绑定表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:save')")
    public ResponseEntity<Boolean> save(@RequestBody @Valid DistributionProdBind distributionProdBind) {
        return ResponseEntity.ok(distributionProdBindService.save(distributionProdBind));
    }

    /**
     * 修改分销商品绑定表
     *
     * @param distributionProdBind 分销商品绑定表
     * @return 是否修改成功
     */
    @SysLog("修改分销商品绑定表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:update')")
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid DistributionProdBind distributionProdBind) {
        return ResponseEntity.ok(distributionProdBindService.updateById(distributionProdBind));
    }

    /**
     * 通过id删除分销商品绑定表
     *
     * @param id id
     * @return 是否删除成功
     */
    @SysLog("删除分销商品绑定表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionProdBind:delete')")
    public ResponseEntity<Boolean> removeById(@PathVariable Long id) {
        return ResponseEntity.ok(distributionProdBindService.removeById(id));
    }

}
