package com.cyl.h5.controller;

import java.util.Collections;
import java.util.List;

import com.cyl.h5.controller.req.MemberPointHistoryReq;
import com.cyl.manager.ums.domain.Member;
import com.cyl.manager.ums.domain.MemberPointHistory;
import com.cyl.manager.ums.domain.Pet;
import com.cyl.manager.ums.service.MemberPointHistoryService;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.LocalDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;

/**
 * 积分集点明细Controller
 * 
 * @author daixiande
 * @date 2024-07-13
 */
//@Api("积分集点明细")
@RestController
@RequestMapping("/h5/memberPointHistory")
public class H5MemberPointHistoryController extends BaseController {
    @Autowired
    private MemberPointHistoryService memberPointHistoryService;

    /**
     * 查询积分集点明细列表
     */
    //@ApiOperation("查询积分集点明细列表")
    @GetMapping("/list")
    public ResponseEntity<Page<MemberPointHistory>>  list( @RequestParam("type")  String type, Pageable page) throws Exception {
        startPage();
        Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
        if(StringUtils.isEmpty(Collections.singleton(member.getId()))){
            throw new Exception("memberId不能为空");
        }
        if(StringUtils.isEmpty(type)){
            throw new Exception("type不能为空");
        }
        List<MemberPointHistory> list = memberPointHistoryService.selectMemberPointHistoryList(member.getId(),type,page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));

    }

    /**
     * 获取积分集点明细详细信息
     */
    //@ApiOperation("获取积分集点明细详细信息")
    @GetMapping(value = "/{id}")
    public  ResponseEntity<MemberPointHistory>  getInfo(@PathVariable("id") Integer id) {
        return  memberPointHistoryService.selectMemberPointHistoryById(id);
    }

    /**
     * 新增积分集点明细
     */
    //@ApiOperation("新增积分集点明细")
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody MemberPointHistory memberPointHistory) {
        return memberPointHistoryService.insertMemberPointHistory(memberPointHistory);
    }

}
