package com.hzs.member.detail.controller.manage;

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.enums.EUpgradeType;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.member.detail.ext.CuMemberLevelExt;
import com.hzs.member.detail.param.CuMemberLevelParam;
import com.hzs.member.detail.service.ICuMemberLevelService;
import com.hzs.common.core.utils.poi.ExcelUtil;
import cn.hutool.core.bean.BeanUtil;
import com.hzs.member.detail.vo.CuMemberLevelUpVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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;

/**
 * 会员升级记录查询
 */
@RestController
@RequestMapping("/manager/member-level")
public class CuMemberLevelController extends BaseController {

    @Autowired
    private ICuMemberLevelService iCuMemberLevelService;

    /**
     * 升级记录列表
     **/
    @GetMapping("/list")
    public TableDataInfo list(CuMemberLevelParam param) {
        startPage();
        List<CuMemberLevelExt> list = iCuMemberLevelService.listMemberLevelList(param);
        return getDataTable(list);
    }

    /**
     * 导出升级记录
     **/
    @Log(module = EOperationModule.MEMBER_LEVEL_UP_RECORD, business = EOperationBusiness.MEMBER_LEVEL_UP_RECORD, method = EOperationMethod.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CuMemberLevelParam param) {
        List<CuMemberLevelUpVO> resultList = new ArrayList<>();
        List<CuMemberLevelExt> list = iCuMemberLevelService.listMemberLevelList(param);

        if (StringUtils.isNotEmpty(list)) {
            resultList = BeanUtil.copyToList(list, CuMemberLevelUpVO.class);
            for (CuMemberLevelUpVO vo : resultList) {
                vo.setUpTypeName(EUpgradeType.getEnumByValue(vo.getUpType()).getLabel());
            }

        }
        ExcelUtil<CuMemberLevelUpVO> util = new ExcelUtil<>(CuMemberLevelUpVO.class);
        util.exportExcel(response, resultList, "会员升级记录");
    }
}
