package com.th.demo.controller.customer;

import com.th.demo.model.system.ResponseCodeMsg;
import com.th.demo.model.system.Type;
import com.th.demo.service.customer.StoreQueryService;
import com.th.demo.service.finance.AccountService;
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.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/CustomerStoreQuery")
public class StoreQueryController {

    @Autowired
    public StoreQueryService storeQueryService;
    String result = Type.FAIL;

    @RequestMapping(value = "/queryStore.do" )
    public String query(int page,
                        int rows,
                        String wareName,
                        String stackName,
                        String model,
                        String materialName,
                        String standard,
                        String customerName,
                        String plateNo,
                        String beginDate,
                        String endDate,
                          String ordNo,
                          HttpServletRequest request) {
        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = storeQueryService.query(page,rows,
                      wareName,
                      stackName,
                      model,
                      materialName,
                      standard,
                      customerName,
                      plateNo,
                      beginDate,
                      endDate,
                     userId,belongId,ordNo);
        } 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 beginDate,
                        String endDate,
                        String ordNo,
                        HttpServletRequest request) {
        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = storeQueryService.queryTotal(page,rows,
                    wareName,
                    stackName,
                    model,
                    materialName,
                    standard,
                    customerName,
                    plateNo,
                    beginDate,
                    endDate,
                    userId,belongId,ordNo);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }
}
