package com.hzs.activity.draw.controller.manage;


import cn.hutool.core.bean.BeanUtil;
import com.hzs.activity.draw.param.AcDrawRecordParam;
import com.hzs.activity.draw.param.AcDrawRewardNumParam;
import com.hzs.activity.draw.service.IAcDrawRewardNumService;
import com.hzs.activity.draw.service.IAcDrawRewardRecordService;
import com.hzs.activity.draw.vo.AcDrawRewardNumVO;
import com.hzs.activity.draw.vo.AcDrawRewardRecordVO;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.EOperationBusiness;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.activity.draw.ext.AcDrawRewardNumExt;
import com.hzs.common.domain.activity.draw.ext.AcDrawRewardRecordExt;
import com.hzs.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 抽奖 前端控制器
 * </p>
 *
 * @author hzs
 * @since 2023-04-21
 */
@RestController
@RequestMapping("/manage/draw")
public class AcDrawRewardRecordController extends BaseController {

    @Autowired
    private IAcDrawRewardRecordService acDrawRewardRecordService;

    @Autowired
    private IAcDrawRewardNumService acDrawRewardNumService;

    /*
     * @description: 查询会员中奖记录
     * @author: sui q
     * @date: 2023/6/1 13:49
     * @param: null null
     **/
    @Log(module = EOperationModule.DRAW_RECORD,business = EOperationBusiness.DRAW_RECORD , method = EOperationMethod.SELECT)
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody AcDrawRecordParam acDrawRecordParam) {
        acDrawRecordParam.setPkCountry(SecurityUtils.getPkCountry());
        startPage();
        return getDataTable(acDrawRewardRecordService.queryCuMemberGiftRecordByCondition(acDrawRecordParam));
    }

    /**
     * 导出会员中奖记录
     */
    @PostMapping("/export-record")
    @Log(module = EOperationModule.DRAW_RECORD,business = EOperationBusiness.DRAW_RECORD , method = EOperationMethod.EXPORT)
    public void exportCuMemberRecord(HttpServletResponse response, AcDrawRecordParam acDrawRecordParam){
        acDrawRecordParam.setPkCountry(SecurityUtils.getPkCountry());
        List<AcDrawRewardRecordExt> acDrawRewardRecordExtList = acDrawRewardRecordService.queryCuMemberGiftRecordByCondition(acDrawRecordParam);
        List<AcDrawRewardRecordVO> acDrawRewardRecordVOList = new ArrayList<>(acDrawRewardRecordExtList.size());
        acDrawRewardRecordExtList.forEach(acDrawRewardRecordExt -> {
            acDrawRewardRecordVOList.add(BeanUtil.copyProperties(acDrawRewardRecordExt, AcDrawRewardRecordVO.class));
        });
        ExcelUtil<AcDrawRewardRecordVO> util = new ExcelUtil<>(AcDrawRewardRecordVO.class);
        util.exportExcel(response, acDrawRewardRecordVOList, "中奖记录导出");
    }

    /**
     * @description: 查询会员礼包收货地址列表
     * @author: sshcode
     * @date: 2022/10/20 10:36
     * @param: [memberAuthorityParam]
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @Log(module = EOperationModule.DRAW_DETAIL, business = EOperationBusiness.DRAW_DETAIL ,method = EOperationMethod.SELECT)
    @PostMapping("/list-number")
    public TableDataInfo listDrawNumber(@RequestBody AcDrawRewardNumParam acDrawRewardNumParam) {
        acDrawRewardNumParam.setPkCountry(SecurityUtils.getPkCountry());
        startPage();
        return getDataTable(acDrawRewardNumService.queryDrawRewardExtNumByCondition(acDrawRewardNumParam));
    }

    /**
     * 导出会员抽奖次数
     */
    @PostMapping("/export-number")
    @Log(module = EOperationModule.DRAW_DETAIL,business = EOperationBusiness.DRAW_DETAIL , method = EOperationMethod.EXPORT)
    public void exportCuMemberNumber(HttpServletResponse response, AcDrawRewardNumParam acDrawRewardNumParam){
        acDrawRewardNumParam.setPkCountry(SecurityUtils.getPkCountry());
        List<AcDrawRewardNumExt> acDrawRewardNumExtList = acDrawRewardNumService.queryDrawRewardExtNumByCondition(acDrawRewardNumParam);
        List<AcDrawRewardNumVO> acDrawRewardNumVOList = new ArrayList<>(acDrawRewardNumExtList.size());
        acDrawRewardNumExtList.forEach(acDrawRewardNumExt -> {
            acDrawRewardNumVOList.add(BeanUtil.copyProperties(acDrawRewardNumExt, AcDrawRewardNumVO.class));
        });
        ExcelUtil<AcDrawRewardNumVO> util = new ExcelUtil<>(AcDrawRewardNumVO.class);
        util.exportExcel(response, acDrawRewardNumVOList, "抽奖次数导出");
    }
}
