package com.ruoyi.web.controller.nanjing;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.nanjing.domain.TBdSubstation;
import com.ruoyi.nanjing.service.ITBdSubstationService;
import com.ruoyi.nanjing.service.ITSyTracestateService;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Controller
@RequestMapping("/nanjing/selectStationPara")
public class StationParaInfoController extends BaseController {
    private String prefix = "nanjing/StationParaInfo";
    @Autowired
    private ITSyTracestateService tracestateService;
    @Autowired
    private ITBdSubstationService substationService;

    @RequiresPermissions("nanjing:StationPara:view")
    @GetMapping()
    public String ProRpList(ModelMap map) {
        List<TBdSubstation> substations = substationService.selectTBdSubstationList(new TBdSubstation());
        map.addAttribute("list", substations);
        return prefix + "/StationParaInfo";
    }

    @RequiresPermissions("nanjing:StationPara:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HttpServletRequest request) {

        String stationCode = request.getParameter("stationCode");
        String semiBarcode = request.getParameter("semiBarcode");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("beginTime", beginTime);
        map.put("endTime", endTime);
        map.put("StationID", stationCode);
        map.put("Barcode", "");
        map.put("SemiBarcode", semiBarcode);
        map.put("StateID", "");
        List<Map<String, Object>> list = tracestateService.selectStationPara(map);
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).containsKey("产品码")) {
                continue;
            } else {
                list.get(i).put("产品码", "-");
            }
        }
        return getDataTable(list);
    }


    //    @RequiresPermissions("nanjing:StationPara:export")
//    @Log(title = "产品码查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HttpServletRequest request,HttpServletResponse response) {
        String semiBarcode = request.getParameter("semiBarcode");
        Map map = new HashMap<String, Object>();
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        map.put("beginTime", null);
        map.put("endTime", null);
        map.put("semiBarcode", semiBarcode);
        List list = tracestateService.selectStationPara(map);
        for (int i = 0; i < list.size() ; i++) {
            System.out.println(list.get(i));
        }

//        try {
//            ByteArrayOutputStream os = new ByteArrayOutputStream();
//            ExcelUtil.createWorkBook()
//        }catch (IOException e){
//            e.printStackTrace();
//        }finally {
//
//        }
        return null;
    }
}
