package com.ruoyi.web.controller.business;

import java.util.*;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;
import com.ruoyi.business.domain.DateCover;
import com.ruoyi.business.domain.TCkPickingwavegoodsBack;
import com.ruoyi.business.service.ITCkPickingwavegoodsBackService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
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.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退货记录表 Controller
 *
 * @author wms
 * @date 2022-05-29
 */
@Controller
@RequestMapping("/business/returnGoodsReport")
public class ReturnGoodsReportController extends BaseController
{
    private String prefix = "business/returnGoods";

    @Autowired
    private ITCkPickingwavegoodsBackService tCkPickingwavegoodsBackService;

    @RequiresPermissions("business:returnGoodsReport:view")
    @GetMapping()
    public String outReportMain(ModelMap mmap)
    {
        // 获取用户
        SysUser sysUser = ShiroUtils.getCurrentUser();
        mmap.put("sysUser", sysUser);
        return prefix + "/returnGoodsReport";
    }

    /**
     * 查询退货记录列表
     */
    @RequiresPermissions("business:returnGoodsReport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DateCover date)
    {
        startPage();
        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBakByCreateDate(
                date.getStartDate(),
                date.getEndDate(), "6", date.getSearch());
        return getDataTable(list);
    }

    /**
     * 导出出库任务单列表
     */
    @RequiresPermissions("business:returnGoodsReport:export")
    @Log(title = "导出退货记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DateCover date)
    {
        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBakByCreateDate(
                date.getStartDate(),
                date.getEndDate(), "6", date.getSearch());
//        tCkPickingwavegoodsBack.setCkType("6");
//        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBackWithoutEmpty(tCkPickingwavegoodsBack);
        ExcelUtil<TCkPickingwavegoodsBack> util = new ExcelUtil<TCkPickingwavegoodsBack>(TCkPickingwavegoodsBack.class);
        return util.exportExcel(list, "退货记录表");
    }

    /**
     * 状态说明弹框
     */
    @GetMapping("/stsDescribe")
    public String stsDescribe()
    {
        return prefix + "/stsdescribe";
    }
}
