Browse Source

更新一键更新匹配的方法

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@9223 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
hejq 8 years ago
parent
commit
aecd481317

+ 44 - 1
src/main/java/com/uas/platform/b2b/controller/ProductController.java

@@ -267,7 +267,7 @@ public class ProductController {
 	}
 	
 	/**
-	 * 查看匹配的物料信息
+	 * 查看匹配的物料信息(全部)
 	 */
 	@RequestMapping(value = "/matchResult", method = RequestMethod.GET)
 	@ResponseBody
@@ -281,6 +281,38 @@ public class ProductController {
 		return searchService.searchProductsCheckIds(keyword, pageParams);
 	}
 
+	/**
+	 * 查看匹配的物料信息(销售)
+	 */
+	@RequestMapping(value = "/matchResult", params = RequestState.STANDARD, method = RequestMethod.GET)
+	@ResponseBody
+	public SPage<Product> getmatchResultOnSale(PageParams params, String keyword) {
+		com.uas.search.b2b.model.PageParams pageParams = searchService.convertPageParams(params, null);
+		pageParams.getFilters().put("pr_enuu", SystemSession.getUser().getEnterprise().getUu());
+		pageParams.getFilters().put("pr_matchstatus", Status.SUBMITTED.value());
+		pageParams.getFilters().put("pr_issale", Constant.YES);
+		List<Sort> sortList = new ArrayList<>();
+		sortList.add(new Sort("pr_id", false, Type.LONG, new Long(1)));
+		pageParams.getFilters().put(SearchConstants.SORT_KEY, sortList);
+		return searchService.searchProductsCheckIds(keyword, pageParams);
+	}
+
+	/**
+	 * 查看匹配的物料信息(采购)
+	 */
+	@RequestMapping(value = "/matchResult", params = RequestState.NONSTANDARD, method = RequestMethod.GET)
+	@ResponseBody
+	public SPage<Product> getmatchResultOnPurc(PageParams params, String keyword) {
+		com.uas.search.b2b.model.PageParams pageParams = searchService.convertPageParams(params, null);
+		pageParams.getFilters().put("pr_enuu", SystemSession.getUser().getEnterprise().getUu());
+		pageParams.getFilters().put("pr_matchstatus", Status.SUBMITTED.value());
+		pageParams.getFilters().put("pr_ispurchase", Constant.YES);
+		List<Sort> sortList = new ArrayList<>();
+		sortList.add(new Sort("pr_id", false, Type.LONG, new Long(1)));
+		pageParams.getFilters().put(SearchConstants.SORT_KEY, sortList);
+		return searchService.searchProductsCheckIds(keyword, pageParams);
+	}
+
 	/**
 	 * 更新物料
 	 * 
@@ -306,6 +338,17 @@ public class ProductController {
 		return productService.updateall(idStrings);
 	}
 	
+	/**
+	 * 全部更新
+	 * 
+	 * @return
+	 */
+	@RequestMapping(value = "/updateByEn", method = RequestMethod.POST)
+	@ResponseBody
+	public ModelMap updateByEn() {
+		return productService.updateByEn();
+	}
+	
 	/**
 	 * 单个匹配
 	 * 

+ 9 - 0
src/main/java/com/uas/platform/b2b/dao/ProductDao.java

@@ -143,4 +143,13 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
 	 */
 	@Procedure(procedureName = "PRODUCT$MATCHES")
 	public String upateResultByEnuu(Long enuu);
+
+	/**
+	 * 根据状态更新数据
+	 * 
+	 * @param uu
+	 * @param status
+	 * @return
+	 */
+	public List<Product> findByEnUUAndMatchstatus(Long uu, Integer status);
 }

+ 31 - 4
src/main/java/com/uas/platform/b2b/service/impl/ProductServiceImpl.java

@@ -292,7 +292,6 @@ public class ProductServiceImpl implements ProductService {
 		// map.put("error", "暂未查询到当前企业的非标准的物料信息");
 		// }
 		String num = productDao.upateResultByEnuu(SystemSession.getUser().getEnterprise().getUu());
-		System.out.println(num);
 		map.put("size", num);
 		return map;
 	}
@@ -306,7 +305,7 @@ public class ProductServiceImpl implements ProductService {
 	public ModelMap refreshproduct(Long id) {
 		ModelMap map = new ModelMap();
 		ProductMatchResult re = productMatchResultDao.findOne(id);
-		if(null != re){
+		if (null != re) {
 			Product prod = productDao.findOne(re.getPrid());
 			prod.setPbrand(re.getBrandcn());
 			prod.setPbranden(re.getBranden());
@@ -321,7 +320,6 @@ public class ProductServiceImpl implements ProductService {
 			} catch (Exception e) {
 				e.printStackTrace();
 			}
-			map.put("success", "更新成功");
 		}
 		return map;
 	}
@@ -330,8 +328,20 @@ public class ProductServiceImpl implements ProductService {
 	public ModelMap updateall(List<Long> idStrings) {
 		ModelMap map = new ModelMap();
 		for (Long id : idStrings) {
-			map = refreshproduct(id);
+			refreshproduct(id);
 		}
+		List<Product> products = productDao.findByEnUUAndMatchstatus(SystemSession.getUser().getEnterprise().getUu(),
+				Status.SUBMITTED.value());
+		if (!CollectionUtils.isEmpty(products)) {
+			for (Product porduct : products) {
+				if (porduct.getMatchresults().size() == 1) {
+					for (ProductMatchResult result : porduct.getMatchresults()) {
+						refreshproduct(result.getId());
+					}
+				}
+			}
+		}
+		map.put("success", "更新成功");
 		return map;
 	}
 
@@ -366,4 +376,21 @@ public class ProductServiceImpl implements ProductService {
 		}
 		return results;
 	}
+
+	@Override
+	public ModelMap updateByEn() {
+		ModelMap map = new ModelMap();
+		List<Product> products = productDao.findByEnUUAndMatchstatus(SystemSession.getUser().getEnterprise().getUu(),
+				Status.SUBMITTED.value());
+		if (!CollectionUtils.isEmpty(products)) {
+			for (Product porduct : products) {
+				if (porduct.getMatchresults().size() == 1) {
+					for (ProductMatchResult re : porduct.getMatchresults()) {
+						map = refreshproduct(re.getId());
+					}
+				}
+			}
+		}
+		return map;
+	}
 }

+ 372 - 17
src/main/webapp/resources/js/index/app.js

@@ -212,7 +212,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         }).state('purc.productmatches', {
             url : "/productmatches",
             templateUrl : "static/tpl/index/approvalFlow/productmatches.html",
-            controller: 'ProductmatchesCtrl'
+            controller: 'ProductmatchesForPurcCtrl'
         }).state('purc.uploadProduct', {
             url : "/uploadProduct",
             templateUrl : "static/tpl/index/purc/uploadByBatch.html",
@@ -382,7 +382,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         }).state('sale.productmatches', {
             url : "/productmatches",
             templateUrl : "static/tpl/index/approvalFlow/productmatches.html",
-            controller: 'ProductmatchesCtrl'
+            controller: 'ProductmatchesForSaleCtrl'
         }).state('sale.maketodo', {
             url : "/maketodo",
             templateUrl : "static/tpl/index/make/todo.html"
@@ -10081,7 +10081,6 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 			Products.matchall({}, function(data) {
 				toaster.pop('info', '提示', '匹配成功'+data.size+'标准器件');
 				window.location.href = "#/sale/productmatches";
-				$rootScope.productMatchStatus = "sale";
 			}, function(response) {
 				toaster.pop('error', '提示', response.data);
 			});
@@ -15719,11 +15718,12 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 					$scope.tableParams.page(1);
 			}
 		};
+		
 		var getService = function() {
 			if($rootScope.productMatchStatus === 'sale') {
-				return GetProductInfo;
+				return Products.matchResultforSale;
 			} else if($rootScope.productMatchStatus === 'purc') {
-				return PurcProduct;
+				return Products.matchResultforPurc;
 			} else {
 				return Products.matchResult;
 			}
@@ -15846,7 +15846,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
         	checkResults(result);
         }
         
-		// 一键更新
+     // 一键更新
 		$scope.updateAll = function() {
 			angular.forEach($scope.tableParams.data, function(product) {
 				if(product.checked) {
@@ -15861,21 +15861,377 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 						});
 					}
 				} 
+			});
+			Products.updateall( {}, ids, function(data) {
+				if(data.success) {
+					toaster.pop('success', '提示', data.success);
+					$scope.tableParams.page(1);
+					$scope.tableParams.reload();
+				}
+				ids = []; // 清空ids,防止重复点击出现多余的数据
+			}, function(response) {
+				toaster.pop('error', '提示', response.data);
+			});
+		}
+	}]);
+	
+	// 当前企业匹配的标准物料信息(销售)
+	app.controller('ProductmatchesForSaleCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
+		BaseService.scrollBackToTop();
+		$scope.active = 'all';
+		$scope.agreedText = '全部';
+		$scope.dateZoneText = '一个月内';
+		$scope.condition = {dateZone: 1};
+		$scope.currency = Symbol.currency;//将币别转化为对应的符号
+		$scope.changeAgreed = function(agreed) {
+			$scope.condition.agreed = agreed;
+			$scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
+			$scope.condition.$agreedOpen = false;
+		};
+		$scope.changeDateZone = function(zone) {
+			$scope.condition.dateZone = zone;
+			$scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
+			$scope.condition.$dateZoneOpen = false;
+			getDateCondition(zone, $scope.condition);
+			$scope.tableParams.reload();
+		};
+		$scope.setActive = function(state) {
+			if($scope.active != state) {
+				$scope.active = state;
+				if($scope.tableParams.page() == 1)
+					$scope.tableParams.reload();
+				else
+					$scope.tableParams.page(1);
+			}
+		};
+		
+		var getService = function() {
+			return Products.matchResultforSale;
+		};
+		
+		$scope.tableParams = new ngTableParams({
+			page : 1, 
+			count : 5,
+			sorting: {
+            }
+		}, {
+			total : 0, 
+			counts: [5, 10, 25, 50],
+			getData : function($defer, params) {
+				$scope.loading = true;
+				var pageParams = params.url();
+				pageParams.keyword = $scope.keyword;
+				pageParams.searchFilter = $scope.searchFilter;
+				getService().call(null, BaseService.parseParams(pageParams), function(page){
+					$scope.loading = false;
+					if(page) {
+						console.log(page);
+						params.total(page.totalElement);
+						$defer.resolve(page.content);
+						$scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
+						$scope.searchFilterXls = angular.copy(pageParams.searchFilter);
+						angular.forEach(page.content, function(product) { // 每次进入判断全选状态,然后给单据赋状态
+							ids = [];
+							if(product.matchresults.length == 1) {
+								product.checked = $scope.checks.checked;
+							}
+						});
+					}
+				}, function(response) {
+					$scope.loading = false;
+					toaster.pop('error', '数据加载失败', response.data);
+				});
+			}
+		});
+
+		// 搜索框回车
+		$scope.onSearch = function() {
+			$scope.tableParams.page(1);
+			$scope.tableParams.reload();
+		};
+		
+		var ids = [];
+		$scope.checks = {
+	            checked: false
+	        };
+		
+		// 全选框
+	    $scope.checkAll = function() {
+	    	ids = [];// 每次选择时先清空,防止重复
+            angular.forEach($scope.tableParams.data, function(product) {
+            	if(product.matchresults.length == 1) {
+            		product.checked = $scope.checks.checked;
+            	}
+            });
+	     };
+
+        // 单选
+        $scope.checkOne = function(product) {
+        	ids = [];// 每次选择时先清空,防止重复
+        	product.checked = !product.checked;
+    		var result = true;
+    		angular.forEach($scope.tableParams.data, function(item) {
+    			if(item.$selected != true){
+    				result = false;
+    				return;
+    			}
+    		});
+    		$scope.checks.checked = result;
+    		 var checked = true;
+             angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
+                 if (!message.checked) {
+                     checked = false;
+                 }
+             });
+             $scope.checks.checked = checked;
+        };
+        
+        $scope.product = {
+	            checked: false
+	        };
+        
+        var checkResults = function(result) {
+        	angular.forEach($scope.tableParams.data, function(product) {
+        		if (product.id == result.prid) {
+        			product.checked = false;
+        			angular.forEach(product.matchresults, function(item) {
+        				if(result.id == item.id) {
+        					if(item.checked) {
+        						product.checked = true;
+        						return;
+        					} 
+        				} else {
+        					item.checked = false;
+        				}
+        			});
+        		}
         	});
-        	if(ids.length == 0) {
-				toaster.pop('info', '提示', '请先选择标准器件');
-			} else {
-				Products.updateall( {}, ids, function(data) {
-					if(data.success) {
-						toaster.pop('success', '提示', data.success);
-						$scope.tableParams.page(1);
-						$scope.tableParams.reload();
+//        	checkProductCheck();
+        };
+        
+        var checkProductCheck = function () {
+        	var checked = true;
+        	angular.forEach($scope.tableParams.data, function(product) {
+        		if(!product.checked) {
+        			checked = false;
+        		}
+        	});
+        	$scope.product.checked = checked;
+        }
+        
+        // 单选明细
+        $scope.checkItem = function(result) { 
+        	ids = [];
+        	result.checked = !result.checked;
+        	checkResults(result);
+        }
+        
+     // 一键更新
+		$scope.updateAll = function() {
+			angular.forEach($scope.tableParams.data, function(product) {
+				if(product.checked) {
+					if(product.matchresults.length == 1) {
+						ids.push(product.matchresults[0].id);
+					} 
+					if (product.matchresults.length > 1) {
+						angular.forEach(product.matchresults, function(item) {
+							if(item.checked) {
+								ids.push(item.id);
+							}
+						});
+					}
+				} 
+			});
+			Products.updateall( {}, ids, function(data) {
+				if(data.success) {
+					toaster.pop('success', '提示', data.success);
+					$scope.tableParams.page(1);
+					$scope.tableParams.reload();
+				}
+				ids = []; // 清空ids,防止重复点击出现多余的数据
+			}, function(response) {
+				toaster.pop('error', '提示', response.data);
+			});
+		}
+	}]);
+	
+	// 当前企业匹配的标准物料信息(采购)
+	app.controller('ProductmatchesForPurcCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
+		BaseService.scrollBackToTop();
+		$scope.active = 'all';
+		$scope.agreedText = '全部';
+		$scope.dateZoneText = '一个月内';
+		$scope.condition = {dateZone: 1};
+		$scope.currency = Symbol.currency;//将币别转化为对应的符号
+		$scope.changeAgreed = function(agreed) {
+			$scope.condition.agreed = agreed;
+			$scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
+			$scope.condition.$agreedOpen = false;
+		};
+		$scope.changeDateZone = function(zone) {
+			$scope.condition.dateZone = zone;
+			$scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
+			$scope.condition.$dateZoneOpen = false;
+			getDateCondition(zone, $scope.condition);
+			$scope.tableParams.reload();
+		};
+		$scope.setActive = function(state) {
+			if($scope.active != state) {
+				$scope.active = state;
+				if($scope.tableParams.page() == 1)
+					$scope.tableParams.reload();
+				else
+					$scope.tableParams.page(1);
+			}
+		};
+		
+		var getService = function() {
+			return Products.matchResultforPurc;
+		};
+		
+		$scope.tableParams = new ngTableParams({
+			page : 1, 
+			count : 5,
+			sorting: {
+            }
+		}, {
+			total : 0, 
+			counts: [5, 10, 25, 50],
+			getData : function($defer, params) {
+				$scope.loading = true;
+				var pageParams = params.url();
+				pageParams.keyword = $scope.keyword;
+				pageParams.searchFilter = $scope.searchFilter;
+				getService().call(null, BaseService.parseParams(pageParams), function(page){
+					$scope.loading = false;
+					if(page) {
+						console.log(page);
+						params.total(page.totalElement);
+						$defer.resolve(page.content);
+						$scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
+						$scope.searchFilterXls = angular.copy(pageParams.searchFilter);
+						angular.forEach(page.content, function(product) { // 每次进入判断全选状态,然后给单据赋状态
+							ids = [];
+							if(product.matchresults.length == 1) {
+								product.checked = $scope.checks.checked;
+							}
+						});
 					}
-					ids = []; // 清空ids,防止重复点击出现多余的数据
 				}, function(response) {
-					toaster.pop('error', '提示', response.data);
+					$scope.loading = false;
+					toaster.pop('error', '数据加载失败', response.data);
 				});
 			}
+		});
+
+		// 搜索框回车
+		$scope.onSearch = function() {
+			$scope.tableParams.page(1);
+			$scope.tableParams.reload();
+		};
+		
+		var ids = [];
+		$scope.checks = {
+	            checked: false
+	        };
+		
+		// 全选框
+	    $scope.checkAll = function() {
+	    	ids = [];// 每次选择时先清空,防止重复
+            angular.forEach($scope.tableParams.data, function(product) {
+            	if(product.matchresults.length == 1) {
+            		product.checked = $scope.checks.checked;
+            	}
+            });
+	     };
+
+        // 单选
+        $scope.checkOne = function(product) {
+        	ids = [];// 每次选择时先清空,防止重复
+        	product.checked = !product.checked;
+    		var result = true;
+    		angular.forEach($scope.tableParams.data, function(item) {
+    			if(item.$selected != true){
+    				result = false;
+    				return;
+    			}
+    		});
+    		$scope.checks.checked = result;
+    		 var checked = true;
+             angular.forEach($scope.tableParams.data, function(message) { // 单选全部时,全选选中
+                 if (!message.checked) {
+                     checked = false;
+                 }
+             });
+             $scope.checks.checked = checked;
+        };
+        
+        $scope.product = {
+	            checked: false
+	        };
+        
+        var checkResults = function(result) {
+        	angular.forEach($scope.tableParams.data, function(product) {
+        		if (product.id == result.prid) {
+        			product.checked = false;
+        			angular.forEach(product.matchresults, function(item) {
+        				if(result.id == item.id) {
+        					if(item.checked) {
+        						product.checked = true;
+        						return;
+        					} 
+        				} else {
+        					item.checked = false;
+        				}
+        			});
+        		}
+        	});
+//        	checkProductCheck();
+        };
+        
+        var checkProductCheck = function () {
+        	var checked = true;
+        	angular.forEach($scope.tableParams.data, function(product) {
+        		if(!product.checked) {
+        			checked = false;
+        		}
+        	});
+        	$scope.product.checked = checked;
+        }
+        
+        // 单选明细
+        $scope.checkItem = function(result) { 
+        	ids = [];
+        	result.checked = !result.checked;
+        	checkResults(result);
+        }
+        
+		// 一键更新
+		$scope.updateAll = function() {
+			angular.forEach($scope.tableParams.data, function(product) {
+				if(product.checked) {
+					if(product.matchresults.length == 1) {
+						ids.push(product.matchresults[0].id);
+					} 
+					if (product.matchresults.length > 1) {
+						angular.forEach(product.matchresults, function(item) {
+							if(item.checked) {
+								ids.push(item.id);
+							}
+						});
+					}
+				} 
+			});
+			Products.updateall( {}, ids, function(data) {
+				if(data.success) {
+					toaster.pop('success', '提示', data.success);
+					$scope.tableParams.page(1);
+					$scope.tableParams.reload();
+				}
+				ids = []; // 清空ids,防止重复点击出现多余的数据
+			}, function(response) {
+				toaster.pop('error', '提示', response.data);
+			});
 		}
 	}]);
 	
@@ -16041,7 +16397,6 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 			Products.matchall({}, function(data) {
 				toaster.pop('info', '提示', '匹配成功'+data.size+'标准器件');
 				window.location.href = "#/purc/productmatches";
-				$rootScope.productMatchStatus = 'purc';
 			}, function(response) {
 				toaster.pop('error', '提示', response.data);
 			});

+ 22 - 1
src/main/webapp/resources/js/index/services/Product.js

@@ -63,7 +63,28 @@ define([ 'ngResource'], function() {
 			},
 			matchResult: {
 				url: 'product/matchResult',
-				method: 'GET'
+				method: 'GET',
+				params: {
+					_state: 'all'
+				}
+			},
+			matchResultforSale: {
+				url: 'product/matchResult',
+				method: 'GET',
+				params: {
+					_state: 'standard'
+				}
+			},
+			matchResultforPurc: {
+				url: 'product/matchResult',
+				method: 'GET',
+				params: {
+					_state: 'nonstandard'
+				}
+			},
+			updateByEn: {
+				url: 'product/updateByEn',
+				method: 'POST'
 			}
 		});
 	}]).factory('PurcProduct', ['$resource', function($resource) {