package com.game.business.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.game.business.domain.AppUser;
import com.game.business.domain.FinTranRecord;
import com.game.business.dto.AppUserDividendListDto;
import com.game.business.dto.AppUserDividendSendDto;
import com.game.business.service.IAppUserService;
import com.game.business.service.IFinTranRecordService;
import com.game.common.annotation.RepeatSubmit;
import com.game.common.constant.AppSceneType;
import com.game.common.constant.finance.FinTranAddedInfo;
import com.game.common.constant.finance.FinTranType1;
import com.game.common.constant.finance.FinTranType3;
import com.game.common.constant.finance.TranCurrencyType;
import com.game.common.core.domain.HttpRet;
import com.game.common.core.domain.HttpRetPageArr;
import com.game.common.core.domain.R;
import com.game.common.core.redis.RedisCache;
import com.game.common.exception.ServiceException;
import com.game.common.utils.MoneyUtils;
import com.game.common.utils.SecurityUtils;
import com.game.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.game.common.annotation.Log;
import com.game.common.core.controller.BaseController;
import com.game.common.core.domain.AjaxResult;
import com.game.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.game.business.domain.AppUserCountDividend;
import com.game.business.service.IAppUserCountDividendService;
import com.game.common.utils.poi.ExcelUtil;
import com.game.common.core.page.TableDataInfo;

/**
 * 用户代理分红Controller
 * 
 * @author game
 * @date 2024-06-30
 */
@RestController
@RequestMapping("/business/dividend")
@Api(value = "AppUserCountDividendController", description = "用户代理表接口", tags = {"用户代理表接口"})
public class AppUserCountDividendController extends BaseController
{
    @Autowired
    private IAppUserCountDividendService appUserCountDividendService;

    @Autowired
    private IAppUserService appUserService;

    @Autowired
    private IFinTranRecordService finTranRecordService;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询用户代理分红列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询周分红列表", notes = "获取周分红列表")
    public HttpRetPageArr<AppUserCountDividend> list(AppUserDividendListDto dto)
    {
        startPage();
        List<AppUserCountDividend> list = appUserCountDividendService.selectUserDividendList(SecurityUtils.getUserId(),null,null,null);
        return HttpRetPageArr.success("查询成功", getDataTable(list));
    }

    /**
     * 发放分红
     */
    @PostMapping("/send")
    @ApiOperation(value = "发放分红", notes = "发放分红")
//    @Transactional
    @RepeatSubmit(message = "频繁操作")
    public HttpRet<Boolean> send(@RequestBody AppUserDividendSendDto dto) throws Exception
    {
        try {
            logger.info("分红发放{}", JSONObject.toJSONString(dto));
        }catch (Exception e){

        }

        String userId = dto.getUserId();
        String dateNo = dto.getDateNum();
        Long curUserId = SecurityUtils.getUserId();
        /*if(null == userId && StringUtils.isBlank(dateNo)){
            return HttpRet.fail("发放失败，参数为空");
        }*/

        return appUserCountDividendService.send(userId,dateNo,curUserId);
    }

    /*@PostConstruct
    private void test(){
        appUserCountDividendService.send("10302","2024-09-30",10013L);
    }*/

}
