package com.td.WaDa.game.comsnbtran.controller;

import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.td.WaDa.common.controller.*;
import com.td.WaDa.common.pojo.Result;
import com.td.WaDa.game.comsnbtran.pojo.ComSnbTran;
import com.td.WaDa.game.comsnbtran.vo.ComSnbTranVo;
import com.td.WaDa.game.comsnbtran.service.ComSnbTranService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/game/comSnbTran/")
public class ComSnbTranController extends CommonController<ComSnbTranVo, ComSnbTran, String> {
    @Autowired
    private ComSnbTranService comSnbTranService;


    /**
     * 获取snb 资产明细
     *
     * @param userId
     * @return
     */
    @GetMapping("getList")
    public Result<Page<ComSnbTran>> getLandFunction(
            @RequestParam(value = "userId") String userId,
            @RequestParam(value = "page") Integer page,
            @RequestParam(value = "limit") Integer limit
    ) {
        //ComSnbTranVo comSnbTranVo = new ComSnbTranVo();
        //comSnbTranVo.setUserId(userId);
        //comSnbTranVo.setPage(page);
        //comSnbTranVo.setRows(limit);
        PageRequest pageRequest = PageRequest.of(page-1, limit, Sort.by(Sort.Direction.DESC,"createTime"));
//            进行查询,查询后的对象封装到page里
        Page<ComSnbTran> backPage = comSnbTranService.findAllByUserId(userId,pageRequest);
        //return comSnbTranService.page(comSnbTranVo);
        return Result.of(backPage);
    }

    private static String translate1(String fieldName){
        return new PropertyNamingStrategy.SnakeCaseStrategy().translate(fieldName).toLowerCase();
    }
}
