package com.liquidnet.client.admin.web.controller.zhengzai.sweet;

import com.github.pagehelper.PageInfo;
import com.liquidnet.client.admin.common.annotation.Log;
import com.liquidnet.client.admin.common.core.controller.BaseController;
import com.liquidnet.client.admin.common.core.domain.AjaxResult;
import com.liquidnet.client.admin.common.core.page.TableDataInfo;
import com.liquidnet.client.admin.common.enums.BusinessType;
import com.liquidnet.client.admin.common.utils.poi.ExcelUtil;
import com.liquidnet.client.admin.zhengzai.kylin.dto.OrderExpressExportExcelListDao;
import com.liquidnet.client.admin.zhengzai.sweet.service.ISweetIntegralActivityDrawService;
import com.liquidnet.service.kylin.dao.OrderExpressExportListDao;
import com.liquidnet.service.sweet.dto.SweetIntegralActivityDto;
import com.liquidnet.service.sweet.dto.param.admin.SweetIntegralActivityDrawListSearchParam;
import com.liquidnet.service.sweet.dto.param.admin.SweetIntegralActivityListSearchParam;
import com.liquidnet.service.sweet.entity.SweetIntegralActivityDraw;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 积分活动抽奖记录表 前端控制器
 * </p>
 *
 * @author jiangxiulong
 * @since 2021-10-22
 */
@Api(tags = "积分活动管理")
@Validated
@Controller
@RequestMapping("/sweet/IntegralActivityDraw")
public class SweetIntegralActivityDrawController extends BaseController {
    private String prefix = "zhengzai/sweet/integralActivityDraw";

    @Autowired
    private ISweetIntegralActivityDrawService iSweetIntegralActivityDrawService;

    @Log(title = "积分活动中奖列表数据", businessType = BusinessType.LIST)
    @RequiresPermissions("sweet:integralActivityDraw:list")
    @ApiOperation(value = "积分活动列表数据")
    @PostMapping("list")
    @ResponseBody
    public TableDataInfo list(SweetIntegralActivityDrawListSearchParam listParam) {
        PageInfo<SweetIntegralActivityDraw> result = iSweetIntegralActivityDrawService.drawList(listParam);
        return getDataTable(result.getList());
    }

    @Log(title = "积分活动导出中奖列表数据", businessType = BusinessType.EXPORT)
    @RequiresPermissions("kylin:integralActivityDraw:exportExcel")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestParam("ids") String integralActivityId) {
        List<OrderExpressExportListDao> list = iSweetIntegralActivityDrawService.selectExpressList(integralActivityId);
        ExcelUtil<OrderExpressExportExcelListDao> excelUtil = new ExcelUtil<>(OrderExpressExportExcelListDao.class);
        List<OrderExpressExportExcelListDao> excelList = new ArrayList<>();
        list.forEach(r -> {
            excelList.add(OrderExpressExportExcelListDao.getNew().copy(r));
        });
        return excelUtil.exportExcel(excelList, "积分活动导出中奖列表数据");
    }

    @GetMapping("listView/{id}")
    @ApiOperation(value = "积分活动中奖列表view")
    public String listView(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("integralActivityId", id);
        return prefix + "/list";
    }

}
