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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.hzs.activity.pick.param.AcRetailPickParam;
import com.hzs.activity.pick.service.IAcRetailPickService;
import com.hzs.activity.pick.vo.AcRetailPickVO;
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.pick.ext.AcRetailPickExt;
import com.hzs.common.security.utils.SecurityUtils;
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;

/**
 * @Description: 新零售会员提货数据
 * @Author: jiang chao
 * @Time: 2025/2/10 10:12
 * @Classname: AcRetailPickController
 * @PackageName: com.hzs.activity.pick.controller.manage
 */
@RestController
@RequestMapping("/manage/retail-pick")
public class AcRetailPickController extends BaseController {

    @Autowired
    private IAcRetailPickService iAcRetailPickService;

    /**
     * 数据列表
     *
     * @param param
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(AcRetailPickParam param) {
        param.setPkCountry(SecurityUtils.getPkCountry());
        param.setSystemType(SecurityUtils.getSystemType());

        List<AcRetailPickVO> resultList = new ArrayList<>();

        startPage();
        List<AcRetailPickExt> list = iAcRetailPickService.listData(param);
        if (CollectionUtil.isNotEmpty(list)) {
            resultList = BeanUtil.copyToList(list, AcRetailPickVO.class);
        }

        TableDataInfo tableDataInfo = getDataTable(list);
        tableDataInfo.setRows(resultList);
        return tableDataInfo;
    }

    /**
     * 数据导出
     *
     * @param response
     * @param param
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, AcRetailPickParam param) {
        param.setPkCountry(SecurityUtils.getPkCountry());
        param.setSystemType(SecurityUtils.getSystemType());

        List<AcRetailPickVO> resultList = new ArrayList<>();

        List<AcRetailPickExt> list = iAcRetailPickService.listData(param);
        if (CollectionUtil.isNotEmpty(list)) {
            resultList = BeanUtil.copyToList(list, AcRetailPickVO.class);
        }
        ExcelUtil<AcRetailPickVO> util = new ExcelUtil<>(AcRetailPickVO.class);
        util.exportExcel(response, resultList, "提货数据");
    }

}
