package com.th.demo.controller.ware;

import com.th.demo.model.system.ResponseCodeMsg;
import com.th.demo.model.system.Type;
import com.th.demo.service.ware.SplitRecordService;
import com.th.demo.service.ware.SplitService;
import com.th.demo.tools.DateTools;
import com.th.demo.tools.JSONTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

@RestController
@RequestMapping(value = "/WareSplitRecord")
public class SplitRecordController {
    @Autowired
    public SplitRecordService splitRecordService;
    String result = Type.FAIL;

    @RequestMapping(value = "/query.do", method = RequestMethod.POST)
    public String query(int page, int rows,
                        String wareName,
                        String stackName,
                        String model,
                        String materialName,
                        String standard,
                        String customerName,
                        String plateNo,
                        String pFromDate,
                        String pToDate,
                        HttpServletRequest request) {
        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            Date fromDate = DateTools.StrToDate(pFromDate, "yyyy-MM-dd HH:mm:ss");
            Date toDate = DateTools.StrToDate(pToDate, "yyyy-MM-dd HH:mm:ss");
            result = splitRecordService.query(page, rows, wareName, stackName, model, materialName, standard, customerName,
                    plateNo,fromDate,toDate, userId, belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }

    @RequestMapping(value = "/queryTotal.do")
    public String queryTotalquery(int page, int rows,
                        String wareName,
                        String stackName,
                        String model,
                        String materialName,
                        String standard,
                        String customerName,
                        String plateNo,
                        String pFromDate,
                        String pToDate,
                        HttpServletRequest request) {
        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            Date fromDate = DateTools.StrToDate(pFromDate, "yyyy-MM-dd HH:mm:ss");
            Date toDate = DateTools.StrToDate(pToDate, "yyyy-MM-dd HH:mm:ss");
            result = splitRecordService.queryTotal(page, rows, wareName, stackName, model, materialName, standard, customerName,
                    plateNo,fromDate,toDate, userId, belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }


//    public List<Map<String,Object>> testtree() {
//        List<Map<String, Object>> areaList = fortestService.getTree();//父节点表
//        List<Map<String, Object>> treeList = new ArrayList<Map<String, Object>>();
//        //用了存放父节点的Map
//        Map<String, Object> node = new HashMap<String, Object>();
//        for (Map<String,Object> area : areaList) { //第一个节点
//            if((area.get("TREE_PARENT_ID").toString()).equals("1")) {
//                //节点id
//                node.put("id", area.get("TREE_ID").toString());
//                //节点名字
//                node.put("text", area.get("TREE_NAME").toString());
//                //拼装子节点，采用的是递归的方法
//                node.put("children", buildTree(area.get("TREE_ID").toString(), areaList));
//                //默认树的状态关闭
//                node.put("state", "closed"); treeList.add(node);
//                return treeList; }
//        }
//        return null;
//    }
//
//    }
}
