package com.ylx.shoppingfunds.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.common.core.domain.R;
import com.ylx.giftCard.domain.dto.UserShoppingFundsDetailQueryDTO;
import com.ylx.giftCard.domain.vo.UserShoppingFundsDetailItemVO;
import com.ylx.giftCard.domain.vo.UserShoppingFundsDetailVO;
import com.ylx.giftCard.service.IGiftCardOrderService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * PC后台购物金Controller
 */
@Slf4j
@RestController
@RequestMapping("/admin/shoppingFunds")
public class AdminShoppingFundsController {

    @Resource
    private IGiftCardOrderService giftCardOrderService;

    /**
     * 根据用户ID查询用户购物金明细
     *
     * @param page 分页参数
     * @param queryDTO 查询条件，包含用户ID、明细类型、开始时间、结束时间
     * @return R<UserShoppingFundsDetailVO> 用户购物金明细
     */
    @GetMapping("/getUserShoppingFundsDetail")
    @ApiOperation("根据用户ID查询用户购物金明细")
    public R<UserShoppingFundsDetailVO> getUserShoppingFundsDetail(Page<UserShoppingFundsDetailItemVO> page, UserShoppingFundsDetailQueryDTO queryDTO) {
        try {
            if (StringUtils.isBlank(queryDTO.getUserId())) {
                return R.fail("userId不能为空");
            }
            return R.ok(giftCardOrderService.getPcUserShoppingFundsDetail(page, queryDTO));
        } catch (IllegalArgumentException e) {
            return R.fail(e.getMessage());
        } catch (Exception e) {
            log.error("查询用户购物金明细失败", e);
            return R.fail("查询用户购物金明细失败");
        }
    }
}
