'use strict';
/**
 * @ngdoc function
 * @name mesFrontendApp.controller:partMachineLoadService
 * @description
 * # partMachineLoadService
 * Controller of the mesFrontendApp
 */
 var app = angular.module('mesFrontendApp');
	

app.service("partMachineLoadService", ['$http','$window','$q',function($http,$window,$q) {


	/*同步獲取組織下拉選單*/ 
	 this.getGroups = function () {	 
		  var deferred = $q.defer();  
   	  $http
   	  .get( $window.defultUrl +"/sysMain/getGroups")
   	  .success(function(data, status, headers, config) {  
   		   
   	        deferred.resolve(data);  
   	      }) 
   	  .error(function(data, status, headers, config) {  
   		    console.log("連線異常，請洽系統管理員：partMachineLoadService.getGroups");
   	        deferred.reject(data);  
   	    });      	  
			return deferred.promise;    
    } 
	 /*同步獲取登入人所在組織*/ 
	 this.getUser = function (userId) {	 
		  var deferred = $q.defer();  
   	  $http
   	  .get( $window.defultUrl +"/user/getUser/"+userId)
   	  .success(function(data, status, headers, config) {  
   		   
   	        deferred.resolve(data);  
   	      }) 
   	  .error(function(data, status, headers, config) {  
   		    console.log("連線異常，請洽系統管理員：partProcessQueryService.getUser");
   	        deferred.reject(data);  
   	    });      	  
			return deferred.promise;    
    } 
	 /*同步獲取機台廠牌下拉選單*/ 
		this.getMachineBrands = function () {	 
			  var deferred = $q.defer();  
	    	  $http
	    	  .get( $window.defultUrl +"/machine/getMachineBrands")
	    	  .success(function(data, status, headers, config) {  
	    		  
	    	        deferred.resolve(data);  
	    	      }) 
	    	  .error(function(data, status, headers, config) {  
	    		    console.log("連線異常，請洽系統管理員：partMachineLoadService.getMachineBrands");
	    	        deferred.reject(data);  
	    	    });      	  
				return deferred.promise;    
	     } 		
	 

	/*同步獲取狀態下拉選單*/ 
		this.getStatusList = function () {	 
			  var deferred = $q.defer();  
	   	  $http
	   	  .get( $window.defultUrl +"/sysMain/getStatusList")
	   	  .success(function(data, status, headers, config) {  
	   		   
	   	        deferred.resolve(data);  
	   	      }) 
	   	  .error(function(data, status, headers, config) {  
	   		    console.log("連線異常，請洽系統管理員：partMachineLoadService.getStatusList");
	   	        deferred.reject(data);  
	   	    });      	  
				return deferred.promise;    
	} 
	/*查詢機台負載資料*/ 
	this.getMachineLoadBetweenDate = function (userId,factoryId,groupId,machineBrandId,searchMachineName,startDate,endDate) {	 
			  var deferred = $q.defer();  
	    	  $http
	    	  .get( $window.defultUrl +"/processInfo/getMachineLoadBetweenDate/"+userId+"/"+factoryId+"/"+groupId+"/"+machineBrandId+"/"+searchMachineName+"/"+startDate+"/"+endDate)
	    	  .success(function(data, status, headers, config) {  
	    		  console.log($window.defultUrl +"/processInfo/getMachineLoadBetweenDate/"+userId+"/"+factoryId+"/"+groupId+"/"+machineBrandId+"/"+searchMachineName+"/"+startDate+"/"+endDate);
	    		   
	    	        deferred.resolve(data);  
	    	      }) 
	    	  .error(function(data, status, headers, config) {  
	    		    console.log("連線異常，請洽系統管理員：partMachineLoadService.getMachineLoadBetweenDate");
	    	        deferred.reject(data);  
	    	    });      	  
				return deferred.promise;    
	   } 
		 	
	/*獲取零件料號及零件版次下拉選單*/ 
	 this.getPartAndRev = function (userId) {	 
		  var deferred = $q.defer();  
 	  $http
  	  .get( $window.defultUrl +"/partInfo/getPartAndRev/"+userId)
 	  .success(function(data, status, headers, config) {    		   
 	        deferred.resolve(data);  
 	  }) 
 	  .error(function(data, status, headers, config) {  
 		    console.log("連線異常，請洽系統管理員：partInfoQueryService.getPartAndRev");
 	        deferred.reject(data);  
 	  });      	  
			return deferred.promise;    
  }
	 
	 
}])

