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

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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.model.DistributionLevelAuditing;
import com.yami.shop.distribution.comment.service.DistributionLevelAuditingService;
import com.yami.shop.security.platform.util.SecurityUtils;
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;
import java.util.Date;

/**
 * 等级申请
 *
 * @author xwc
 * @date 2019-04-16 11:46:09
 */
@RestController
@RequestMapping("/distribution/distributionLevelAuditing")
@AllArgsConstructor
public class DistributionLevelAuditingController {

    private final DistributionLevelAuditingService distributionLevelAuditingService;

    /**
     * 分页查询
     *
     * @param page                      分页对象
     * @param distributionLevelAuditing 等级申请
     * @return 分页数据
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('distribution:distributionLevelAuditing:page')")
    public ResponseEntity<IPage<DistributionLevelAuditing>> getdistributionLevelAuditingPage(PageParam page, DistributionLevelAuditing distributionLevelAuditing, String mobile) {
        IPage<DistributionLevelAuditing> list = distributionLevelAuditingService.distributionLevelAuditingPage(page, mobile, Constant.PLATFORM_SHOP_ID, distributionLevelAuditing);
        return ResponseEntity.ok(list);
    }


    /**
     * 通过id查询等级申请
     *
     * @param id id
     * @return 单个数据
     */
    @GetMapping("/info/{id}")
    public ResponseEntity<DistributionLevelAuditing> getById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(distributionLevelAuditingService.getById(id));
    }

    /**
     * 新增等级申请
     *
     * @param distributionLevelAuditing 等级申请
     * @return 是否新增成功
     */
    @SysLog("新增等级申请")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionLevelAuditing:save')")
    public ResponseEntity<Boolean> save(@RequestBody @Valid DistributionLevelAuditing distributionLevelAuditing) {
        distributionLevelAuditing.setCreateTime(new Date());
        return ResponseEntity.ok(distributionLevelAuditingService.save(distributionLevelAuditing));
    }

    /**
     * 修改等级申请
     *
     * @param distributionLevelAuditing 等级申请
     * @return 是否修改成功
     */
    @SysLog("修改等级申请")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionLevelAuditing:update')")
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid DistributionLevelAuditing distributionLevelAuditing) {
        distributionLevelAuditing.setModifier(SecurityUtils.getSysUser().getUserId());
        distributionLevelAuditing.setUpdateTime(new Date());
        return ResponseEntity.ok(distributionLevelAuditingService.updateById(distributionLevelAuditing));
    }

    /**
     * 等级审核
     */
    @SysLog("等级审核")
    @PutMapping("/auditing")
    @PreAuthorize("@pms.hasPermission('distribution: distributionLevelAuditing:update')")
    public ResponseEntity<Void> auditing(@RequestBody @Valid DistributionLevelAuditing distributionLevelAuditing) {
        distributionLevelAuditing.setModifier(SecurityUtils.getSysUser().getUserId());
        distributionLevelAuditing.setUpdateTime(new Date());
        distributionLevelAuditingService.auditing(distributionLevelAuditing);
        return ResponseEntity.ok().build();
    }


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

}
