/*
 * 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.config.Constant;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.model.DistributionUserIncome;
import com.yami.shop.distribution.comment.param.RangeTimeParam;
import com.yami.shop.distribution.comment.service.DistributionUserIncomeService;
import com.yami.shop.security.platform.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/distribution/distributionUserIncome")
public class DistributionUserIncomeController {

    @Autowired
    private DistributionUserIncomeService distributionUserIncomeService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:page')")
    public ResponseEntity<IPage<DistributionUserIncome>> page(DistributionUserIncome distributionUserIncome, PageParam<DistributionUserIncome> page) {
        IPage<DistributionUserIncome> list = distributionUserIncomeService.page(page, new LambdaQueryWrapper<DistributionUserIncome>());
        return ResponseEntity.ok(list);
    }

    /**
     * 分页获取
     */
    @GetMapping("/page/anduser")
    public ResponseEntity<IPage<DistributionUserIncome>> page(PageParam<DistributionUserIncome> page,
                                                              RangeTimeParam rangeTimeParam
            , String userMobile
            , String orderNumber
            , Integer state
    ) {
        IPage<DistributionUserIncome> list = distributionUserIncomeService.incomeAndDistributionUserPage(page, Constant.PLATFORM_SHOP_ID, rangeTimeParam, userMobile, orderNumber,state);
        return ResponseEntity.ok(list);
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:info')")
    public ResponseEntity<DistributionUserIncome> info(@PathVariable("id") Long id) {
        DistributionUserIncome distributionUserIncome = distributionUserIncomeService.getById(id);
        return ResponseEntity.ok(distributionUserIncome);
    }

    /**
     * 保存
     */
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:save')")
    public ResponseEntity<Void> save(@RequestBody @Valid DistributionUserIncome distributionUserIncome) {
        distributionUserIncomeService.save(distributionUserIncome);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:update')")
    public ResponseEntity<Void> update(@RequestBody @Valid DistributionUserIncome distributionUserIncome) {
        distributionUserIncomeService.updateById(distributionUserIncome);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserIncome:delete')")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        distributionUserIncomeService.removeById(id);
        return ResponseEntity.ok().build();
    }
}
