package com.cyl.manager.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.h5.controller.req.MemberPointHistoryReq;
import com.cyl.manager.ums.domain.MemberPointHistory;
import com.cyl.manager.ums.domain.Pet;
import com.cyl.manager.ums.mapper.MemberPointHistoryMapper;
import com.cyl.manager.ums.pojo.query.PetQuery;
import com.cyl.manager.ums.service.MemberPointHistoryService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class MemberPointHistoryServiceImpl  implements MemberPointHistoryService {

    @Autowired
    private MemberPointHistoryMapper memberPointHistoryMapper;

    @Override
    public ResponseEntity<MemberPointHistory>  selectMemberPointHistoryById(Integer id) {
        return null;
    }

    @Override
    public List<MemberPointHistory> selectMemberPointHistoryList(Long member,String type, Pageable page ) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<MemberPointHistory> dd = new QueryWrapper<>();
        if(!StringUtils.isEmpty(member)){
            dd.eq("member_id",member);
        }
        if(!StringUtils.isEmpty(type)){
            dd.eq("type",type);
        }
        dd.orderByDesc("create_at");
        return memberPointHistoryMapper.selectList(dd);
    }

    @Override
    public ResponseEntity<Integer>  insertMemberPointHistory(MemberPointHistory memberPointHistory) {
        //        Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
//        memberPointHistory.setUserId(member.getId());
        return ResponseEntity.ok(memberPointHistoryMapper.insert(memberPointHistory));
    }

}
