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.DeficitRecordService;
import com.th.demo.service.ware.DeficitService;
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.Date;

@RestController
@RequestMapping(value = "/WareDeficitRecord")
public class DeficitRecordController {

    @Autowired
    public DeficitRecordService deficitRecordService;
    String result = Type.FAIL;

    @RequestMapping(value = "/query.do" )
    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 = deficitRecordService.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 queryTotal(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 = deficitRecordService.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;
        }
    }
}
