/*
 * 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.DistributionUserInfo;
import com.yami.shop.distribution.comment.service.DistributionUserInfoService;
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-15 16:59:13
 */
@RestController
@AllArgsConstructor
@RequestMapping("/distribution/distributionUserInfo")
public class DistributionUserInfoController {


    private final DistributionUserInfoService distributionUserInfoService;

    /**
     * 分页查询
     *
     * @param page                 分页对象
     * @param distributionUserInfo
     * @return 分页数据
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<DistributionUserInfo>> getDistributionUserInfoPage(PageParam<DistributionUserInfo> page, DistributionUserInfo distributionUserInfo) {
        return ResponseEntity.ok(distributionUserInfoService.page(page, new LambdaQueryWrapper<DistributionUserInfo>()));
    }


    /**
     * 通过id查询
     *
     * @param distributionUserInfoId id
     * @return 单个数据
     */
    @GetMapping("/info/{distributionUserInfoId}")
    public ResponseEntity<DistributionUserInfo> getById(@PathVariable("distributionUserInfoId") Long distributionUserInfoId) {
        return ResponseEntity.ok(distributionUserInfoService.getById(distributionUserInfoId));
    }

    /**
     * 新增
     *
     * @param distributionUserInfo
     * @return 是否新增成功
     */
    @SysLog("新增")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserInfo:save')")
    public ResponseEntity<Boolean> save(@RequestBody @Valid DistributionUserInfo distributionUserInfo) {
        return ResponseEntity.ok(distributionUserInfoService.save(distributionUserInfo));
    }

    /**
     * 修改
     *
     * @param distributionUserInfo
     * @return 是否修改成功
     */
    @SysLog("修改")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserInfo:update')")
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid DistributionUserInfo distributionUserInfo) {
        return ResponseEntity.ok(distributionUserInfoService.updateById(distributionUserInfo));
    }

    /**
     * 通过id删除
     *
     * @param distributionUserInfoId id
     * @return 是否删除成功
     */
    @SysLog("删除")
    @DeleteMapping("/{distributionUserInfoId}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserInfo:delete')")
    public ResponseEntity<Boolean> removeById(@PathVariable Long distributionUserInfoId) {
        return ResponseEntity.ok(distributionUserInfoService.removeById(distributionUserInfoId));
    }

}
