package com.ruoyi.web.controller.nanjing;

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.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.nanjing.domain.TBdSubstation;
import com.ruoyi.nanjing.domain.TRpWorktrayrealtimeinfo;
import com.ruoyi.nanjing.service.ITBdSubstationService;
import com.ruoyi.nanjing.service.ITRpWorktrayrealtimeinfoService;
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 javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 托盘管理Controller
 * 
 * @author limy
 * @date 2021-01-28
 */
@Controller
@RequestMapping("/nanjing/selectWorkTrayRealTimeInfo")
public class SelectWorktrayrealtimeinfoController extends BaseController {
    private String prefix = "nanjing/WorkTrayRealTimeInfo";

    @Autowired
    private ITRpWorktrayrealtimeinfoService tRpWorktrayrealtimeinfoService;
    @Autowired
    private ITBdSubstationService substationService;
    @RequiresPermissions("nanjing:selectWorkTrayRealTimeInfo:view")
    @GetMapping()
    public String WorkTrayRealTimeInfo(ModelMap map) {
        List<TBdSubstation> substations = substationService.selectTBdSubstationList(new TBdSubstation());
        map.addAttribute("list",substations);
        return prefix + "/SelectWorkTrayRealTimeInfo";
    }

    /**
     * 查询托盘管理列表
     */
    @RequiresPermissions("nanjing:selectWorkTrayRealTimeInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TRpWorktrayrealtimeinfo tRpWorktrayrealtimeinfo) {
        startPage();
        List<TRpWorktrayrealtimeinfo> list = tRpWorktrayrealtimeinfoService.selectrealtimeinfoList(tRpWorktrayrealtimeinfo);
        return getDataTable(list);
    }

    /**
     * 导出托盘管理列表
     */
    @RequiresPermissions("nanjing:selectWorkTrayRealTimeInfo:export")
    @Log(title = "托盘管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRpWorktrayrealtimeinfo tRpWorktrayrealtimeinfo) {
        List<TRpWorktrayrealtimeinfo> list = tRpWorktrayrealtimeinfoService.selectrealtimeinfoList(tRpWorktrayrealtimeinfo);
        for (TRpWorktrayrealtimeinfo tw:list)
        {
            if(tw.getBarcoderelationship()!=null){
                if (tw.getBarcoderelationship().getProductBarcode()!=null){
                    tw.setProductCode(tw.getBarcoderelationship().getProductBarcode());
                }
            }
        }
        ExcelUtil<TRpWorktrayrealtimeinfo> util = new ExcelUtil<TRpWorktrayrealtimeinfo>(TRpWorktrayrealtimeinfo.class);
        return util.exportExcel(list, "托盘实时信息");
    }
}

