package com.fzm.mall.server.front.asset.controller;


import com.fzm.mall.server.front.asset.model.UserAsset;
import com.fzm.mall.server.front.asset.model.UserAssetRecord;
import com.fzm.mall.server.front.asset.model.vo.asset.UserAssetRecordVo;
import com.fzm.mall.server.front.asset.model.vo.asset.UserAssetVo;
import com.fzm.mall.server.front.asset.service.IUserAssetRecordService;
import com.fzm.mall.server.front.base.PageVO;
import com.fzm.mall.server.front.base.ResponseVO;
import com.fzm.mall.server.front.constant.MallResponseEnum;
import com.fzm.mall.server.front.constant.PageConst;
import com.fzm.mall.server.front.user.model.Header;
import com.fzm.mall.server.front.valid.LongValid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 用户资产变更记录表 前端控制器
 * </p>
 *
 * @author tdz
 * @since 2021-05-17
 */
@Api(tags = "资产记录接口", description = "资产记录")
@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/mall/assetRecord")
public class UserAssetRecordController {
    private final IUserAssetRecordService assetRecordService;
    @ApiOperation(value = "分页查询用户资产记录")
    @PostMapping("/select")
    public ResponseVO<PageVO<UserAssetRecord>> pageAssetRecord(@RequestBody UserAssetRecordVo assetRecordVo, @ApiIgnore @RequestAttribute Header header) {
        String page = assetRecordVo.getPage();
        String size = assetRecordVo.getSize();
        if (!LongValid.positiveLong(page)) {
            page = PageConst.DEFAULT_PAGE;
        }
        if (!LongValid.positiveLong(size)) {
            size = PageConst.DEFAULT_SIZE;
        }
        assetRecordVo.setPage(page);
        assetRecordVo.setSize(size);
        assetRecordVo.setUid(header.getUid());
        PageVO<UserAssetRecord> pageAsset = assetRecordService.pageAssetRecord(assetRecordVo);
        return new ResponseVO<>(MallResponseEnum.SUCCESS, pageAsset);
    }
}
