package com.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.ssm.manage.response.GenericResponse;
import com.ssm.manage.response.PageResponse;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.entity.StoreRoomHand;
import com.ssm.manage.query.StoreRoomHandRequest;
import com.ssm.manage.response.ResponseCode;
import com.ssm.manage.service.SsmStoreRoomHandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@Api(value="房间手牌controller",tags={"房间手牌相关接口"})
@RestController
@RequestMapping("/demay/ssm/storeRoomHand")
@Slf4j
public class SsmStoreRoomHandController {
    @Autowired
    private SsmStoreRoomHandService ssmStoreRoomHandService;

    @ApiOperation(value = "查询房间手牌",httpMethod = "POST",response = GenericResponse.class)
    @RequestMapping("/page")
    public PageResponse selectPage(@RequestBody StoreRoomHandRequest storeRoomRequest, HttpSession session){
        PageResponse<StoreRoomHand> pageResponse = new PageResponse<>();
        PageInfo<StoreRoomHand> pageInfo = new PageInfo<>();
        Long storeId = SessionHelp.getStoreId(session);
        storeRoomRequest.setStoreId(storeId);
        try {
            pageInfo = ssmStoreRoomHandService.selectPage(storeRoomRequest);
        }catch (Exception e){
            log.error("SsmCashController.selectPage:",e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

}
