package com.ruoyi.web.controller.business;

import com.alibaba.fastjson.JSON;
import com.ruoyi.business.domain.DateCover;
import com.ruoyi.business.domain.TCkPickingwavegoods;
import com.ruoyi.business.domain.TCkPickingwavegoodsBack;
import com.ruoyi.business.domain.TOngoodsshelfBak;
import com.ruoyi.business.service.ITCkPickingwavegoodsBackService;
import com.ruoyi.business.service.ITCkPickingwavegoodsService;
import com.ruoyi.business.service.ITOngoodsshelfBakService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
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 java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 入库报表Controller
 *
 * @author liangzhou
 * @date 2022-06-20
 */
@Controller
@RequestMapping("/business/outreport")
public class TOutReportController extends BaseController {
    private String prefix = "business/outreport";

    @Autowired
    private ITCkPickingwavegoodsBackService tCkPickingwavegoodsBackService;

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

    /**
     * 查询出库任务单列表
     */
    @RequiresPermissions("business:outreport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DateCover date) {
        startPage();
        List<TCkPickingwavegoodsBack> list = tCkPickingwavegoodsBackService.selectTCkPickingwavegoodsBakByCreateDate(
                date.getStartDate(),
                date.getEndDate(), "4", date.getSearch());
        return getDataTable(list);
    }

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

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