package com.yonge.cooleshow.admin.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.mybatis.support.PageUtil;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import com.yonge.cooleshow.biz.dal.vo.PianoRoomChangeRecordVo;
import com.yonge.cooleshow.biz.dal.dto.search.PianoRoomChangeRecordSearch;
import com.yonge.cooleshow.biz.dal.entity.PianoRoomChangeRecord;
import com.yonge.cooleshow.biz.dal.service.PianoRoomChangeRecordService;

@RestController
@RequestMapping("/pianoRoomChangeRecord")
@Api(value = "琴房时长变更记录表", tags = "琴房时长变更记录表")
public class PianoRoomChangeRecordController extends BaseController {
	@Autowired
	private SysUserFeignService sysUserFeignService;
    @Autowired
    private PianoRoomChangeRecordService pianoRoomChangeRecordService;

	/**
     * 查询单条
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "详情", notes = "传入id")
    public HttpResponseResult<PianoRoomChangeRecordVo> detail(@PathVariable("id") Long id) {
    	return succeed(pianoRoomChangeRecordService.detail(id));
	}
    
    /**
     * 查询分页
     */
    @PostMapping("/page")
    @ApiOperation(value = "查询分页", notes = "传入pianoRoomChangeRecordSearch")
    public HttpResponseResult<PageInfo<PianoRoomChangeRecordVo>> page(@RequestBody PianoRoomChangeRecordSearch query) {
		IPage<PianoRoomChangeRecordVo> pages = pianoRoomChangeRecordService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
	}
    
    /**
	 * 新增
	 */
	@PostMapping("/add")
	@ApiOperation(value = "新增", notes = "传入pianoRoomChangeRecord")
	public HttpResponseResult add(@Valid @RequestBody PianoRoomChangeRecord pianoRoomChangeRecord) {
		SysUser user = sysUserFeignService.queryUserInfo();
		if (user == null || null == user.getId()) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}
		pianoRoomChangeRecord.setCreateBy(user.getId());
		pianoRoomChangeRecord.setSourceType(SourceTypeEnum.PLATFORM);
    	return status(pianoRoomChangeRecordService.add(pianoRoomChangeRecord));
	}
}