/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

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

import com.yami.shop.user.comment.model.UserLevelLog;
import com.yami.shop.user.comment.service.UserLevelLogService;
import com.yami.shop.common.annotation.SysLog;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 * 用户等级日志管理实现
 *
 * @author LGH
 * @version 1.0.0
 * @since 2020-02-26
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user/userLevelLog" )
public class UserLevelLogController {

    private final UserLevelLogService userLevelLogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userLevelLog
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<UserLevelLog>> getUserLevelLogPage(PageParam<UserLevelLog> page, UserLevelLog userLevelLog) {
        return ResponseEntity.ok(userLevelLogService.getPage(page,userLevelLog));
    }


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

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

    /**
     * 修改
     * @param userLevelLog
     * @return 是否修改成功
     */
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:userLevelLog:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserLevelLog userLevelLog) {
        userLevelLog.setState(1);
        return ResponseEntity.ok(userLevelLogService.updateById(userLevelLog));
    }

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

}
