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.DistributionService;
import com.th.demo.service.ware.InService;
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;

@RestController
@RequestMapping(value = "/WareDistribution")
public class DistributionController {
    @Autowired
    public DistributionService distributionService;
    String result = Type.FAIL;

    @RequestMapping(value = "/queryWaitTrucks.do" )
    public String queryWaitTrucks(
                     HttpServletRequest request) {

        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = distributionService.queryWaitTrucks(userId,belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }

    @RequestMapping(value = "/save.do" , method = RequestMethod.POST)
    public String save(String json,
                       String jsonList,
            HttpServletRequest request) {

        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = distributionService.save(json,jsonList,userId,belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }




    @RequestMapping(value = "/cancel.do" , method = RequestMethod.POST)
    public String cancel(String json,
                       String jsonList,
                       HttpServletRequest request) {

        try {
            String userId = (String) request.getAttribute("userId");
            String belongId = (String) request.getAttribute("belongId");
            result = distributionService.cancel(json,jsonList,userId,belongId);
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());
        } finally {
            return result;
        }
    }
}
