package com.ruoyi.web.controller.business;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
import com.alibaba.fastjson.JSON;
import com.ruoyi.business.domain.*;
import com.ruoyi.business.service.*;
import com.ruoyi.business.utils.OrderCodeFactory;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hpsf.GUID;
import org.apache.poi.openxml4j.opc.internal.ContentType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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;

import static java.lang.System.out;

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

    @Autowired
    private ITOngoodsshelfBakService tOngoodsshelfServiceBak;

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

    /**
     * 查询入库任务单列表
     */
    @RequiresPermissions("business:inreport:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DateCover date)
    {
        startPage();
        List<TOngoodsshelfBak> list = tOngoodsshelfServiceBak.selectTOngoodsshelfBakByCreateDate(
                date.getStartDate(),
                date.getEndDate(), "0", date.getSearch());
        return getDataTable(list);
    }

    /**
     * 导出入库任务单列表
     */
    @RequiresPermissions("business:inreport:export")
    @Log(title = "导出入库任务单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DateCover date)
    {
        List<TOngoodsshelfBak> list = tOngoodsshelfServiceBak.selectTOngoodsshelfBakByCreateDate(
                date.getStartDate(),
                date.getEndDate(), "0", date.getSearch());
//        tOngoodsshelfBak.setTasktype("0");
//        List<TOngoodsshelfBak> list = tOngoodsshelfServiceBak.selectTOngoodsshelfBakWithoutEmpty(tOngoodsshelfBak);
        ExcelUtil<TOngoodsshelfBak> util = new ExcelUtil<TOngoodsshelfBak>(TOngoodsshelfBak.class);
        return util.exportExcel(list, "入库任务单数据");
    }

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

    /**
     * 筛选入库任务单
     */
    @PostMapping("/filter/{date}")
    @ResponseBody
    public TableDataInfo filter(@PathVariable("date") String date)
    {
        startPage();
        Map dateMap = JSON.parseObject(date);
        List<TOngoodsshelfBak> list = tOngoodsshelfServiceBak.selectTOngoodsshelfBakByCreateDate(
                String.valueOf(dateMap.get("startDate")).replace("-", ""),
                String.valueOf(dateMap.get("endDate")).replace("-", ""), "0", "");
        return getDataTable(list);
    }
}
