Просмотр исходного кода

物料产品增加批量修改功能

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@8918 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
hejq 9 лет назад
Родитель
Сommit
6605d315b4

+ 18 - 0
src/main/java/com/uas/platform/b2b/controller/ProductController.java

@@ -6,12 +6,15 @@ import java.util.List;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Sort.Direction;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
+import com.alibaba.fastjson.JSONObject;
 import com.uas.platform.b2b.model.Product;
 import com.uas.platform.b2b.search.SearchService;
 import com.uas.platform.b2b.service.ProductService;
@@ -141,4 +144,19 @@ public class ProductController {
 		logger.log("物料资料", "导出Excel列表", "导出全部Excel列表");
 		return modelAndView;
 	}
+	
+	/**
+	 * 批量修改物料数据
+	 * 
+	 * @param products
+	 * @param updatetype
+	 * @param keyword
+	 * @return
+	 */
+	@RequestMapping(value = "/updateByBatch", method = RequestMethod.POST)
+	@ResponseBody
+	private ModelMap updateByBatch(@RequestBody String products, String updatetype, String keyword) {
+		List<Product> prods = JSONObject.parseArray(products, Product.class);
+		return productService.updateByBatch(prods, updatetype, keyword);
+	}
 }

+ 2 - 0
src/main/java/com/uas/platform/b2b/erp/controller/ProdController.java

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import com.alibaba.fastjson.JSON;
 import com.uas.platform.b2b.erp.model.Prod;
 import com.uas.platform.b2b.erp.service.ProdService;
 import com.uas.platform.b2b.erp.support.ErpBufferedLogger;
@@ -65,6 +66,7 @@ public class ProdController {
 	public void updateProducts(@RequestParam("data") String data) throws UnsupportedEncodingException {
 		String jsonStr = URLDecoder.decode(data, "UTF-8");
 		List<Prod> prods = FlexJsonUtils.fromJsonArray(jsonStr, Prod.class);
+		System.out.println(JSON.toJSON(prods));
 		productService.save(prodService.convertProduct(prods));
 		logger.log("物料资料", "定时任务更新物料资料", prods.size());
 	}

+ 58 - 0
src/main/java/com/uas/platform/b2b/model/UpdateType.java

@@ -0,0 +1,58 @@
+package com.uas.platform.b2b.model;
+
+public enum UpdateType {
+	/**
+	 * {@code 101  品牌}
+	 */
+	BRANDUPDATE(101, "品牌"),
+
+	/**
+	 * {@code 102  名称(类目)}
+	 */
+	TITLEUPDATE(102, "名称(类目)"),
+
+	/**
+	 * {@code 103  原厂型号}
+	 */
+	SPECUPDATE(103, "原厂型号");
+
+	private UpdateType(int value, String phrase) {
+		this.value = value;
+		this.phrase = phrase;
+	}
+
+	private final int value;
+	private final String phrase;
+
+	public int getValue() {
+		return this.value;
+	}
+
+	public String getPhrase() {
+		return this.phrase;
+	}
+
+	/**
+	 * @param statusCode
+	 *            状态的编码
+	 * @return 状态
+	 * @throws IllegalArgumentException
+	 *             如果statusCode不存在的话
+	 */
+	public static UpdateType valueOf(int statusCode) {
+		for (UpdateType status : values()) {
+			if (status.value == statusCode) {
+				return status;
+			}
+		}
+		throw new IllegalArgumentException("没有与编号 [" + statusCode + "]匹配的状态");
+	}
+
+	/**
+	 * 返回状态的编号
+	 */
+	@Override
+	public String toString() {
+		return Integer.toString(value);
+	}
+}

+ 10 - 0
src/main/java/com/uas/platform/b2b/service/ProductService.java

@@ -3,6 +3,7 @@ package com.uas.platform.b2b.service;
 import java.util.List;
 
 import org.springframework.data.domain.Page;
+import org.springframework.ui.ModelMap;
 
 import com.uas.platform.b2b.model.Product;
 import com.uas.platform.core.model.PageInfo;
@@ -55,4 +56,13 @@ public interface ProductService {
 	 */
 	public void lockPurc(Long id);
 
+	/**
+	 * 批量修改物料数据
+	 * 
+	 * @param products
+	 * @param updatetype
+	 * @param keyword
+	 * @return
+	 */
+	public ModelMap updateByBatch(List<Product> products, String updatetype, String keyword);
 }

+ 24 - 0
src/main/java/com/uas/platform/b2b/service/impl/ProductServiceImpl.java

@@ -12,12 +12,15 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import com.uas.platform.b2b.core.util.ContextUtils;
 import com.uas.platform.b2b.dao.ProductDao;
 import com.uas.platform.b2b.event.ProductSaveEvent;
 import com.uas.platform.b2b.model.Product;
+import com.uas.platform.b2b.model.UpdateType;
 import com.uas.platform.b2b.search.SearchService;
 import com.uas.platform.b2b.service.ProductService;
 import com.uas.platform.core.model.Constant;
@@ -103,4 +106,25 @@ public class ProductServiceImpl implements ProductService {
 			e.printStackTrace();
 		}
 	}
+
+	@Override
+	public ModelMap updateByBatch(List<Product> products, String updatetype, String keyword) {
+		ModelMap map = new ModelMap();
+		if (!CollectionUtils.isEmpty(products)) {
+			for (Product prod : products) {
+				if (updatetype.equals(UpdateType.BRANDUPDATE.getPhrase())) {
+					prod.setBrand(keyword);
+					productDao.save(prod);
+				} else if (updatetype.equals(UpdateType.SPECUPDATE.getPhrase())) {
+					prod.setSpec(keyword);
+					productDao.save(prod);
+				} else if (updatetype.equals(UpdateType.TITLEUPDATE.getPhrase())) {
+					prod.setTitle(keyword);
+					productDao.save(prod);
+				}
+			}
+			map.put("success", updatetype + "修改成功");
+		}
+		return map;
+	}
 }

+ 164 - 2
src/main/webapp/resources/js/index/app.js

@@ -9720,7 +9720,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 	/**
 	 * 物料资料
 	 */
-	app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$rootScope', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout, $rootScope) {
+	app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$rootScope', '$modal', function($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout, $rootScope, $modal) {
 		BaseService.scrollBackToTop();
 		$scope.active = 'all';
 		$scope.agreedText = '全部';
@@ -9818,6 +9818,100 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 				toaster.pop('error', '提示', response.data);
 			})
 		}
+		
+		var products = [];
+		$scope.checks = {
+	            checked: false
+	        };
+		
+		// 全选框
+	    $scope.checkAll = function() {
+	    	products = [];// 每次选择时先清空,防止重复
+	            angular.forEach($scope.tableParams.data, function(product) {
+	            	if(product.cmpUuId == null) {
+	            		product.checked = $scope.checks.checked;
+	            	}
+	        });
+	     };
+
+        // 单选
+        $scope.checkOne = function(product) {
+        	products = [];// 每次选择时先清空,防止重复
+    		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.updateByBatch = function(updatetype) {
+        	angular.forEach($scope.tableParams.data, function(product) { // 单选全部时,全选选中
+        		if (product.checked) {
+        			products.push(product);
+        		}
+        	});
+        	console.log(products);
+        	if(products.length == 0) {
+				toaster.pop('warning', 'ts', '请至少选择一个产品');
+			} else {
+				var modalInstance = $modal.open({
+					templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
+					controller: 'UpdateByBatchCtrl',
+					size: 'lg',
+					resolve: {
+						products: function() {
+							return products;
+						},
+						updatetype: function() {
+							return updatetype;
+						}
+					}
+				});
+				
+				modalInstance.result.then(function(data) {
+					toaster.pop('success', '提示', data.data);
+					$scope.tableParams.reload();
+				}, function(){
+					
+				});
+			}
+        }
+	}]);
+	
+	/**
+	 * 批量修改
+	 */
+	app.controller('UpdateByBatchCtrl', ['$scope', '$modalInstance', 'toaster', 'BaseService', 'updatetype', 'products', 'Products', function($scope, $modalInstance, toaster, BaseService, updatetype, products, Products) {
+		$scope.updatetype = updatetype;
+		$scope.products = products;
+		$scope.changed = false;
+		$scope.ensure = function(keyword) {
+			$scope.keyword = keyword;
+			$scope.changed = true;
+		}
+		$scope.returnUpdate = function() {
+			$scope.changed = false;
+		}
+		$scope.cancel = function() {
+			$modalInstance.dismiss();
+		}
+		$scope.okay = function() {
+			Products.updateByBatch({updatetype: updatetype, keyword: $scope.keyword}, $scope.products, function(data) {
+				$modalInstance.close(data);
+			}, function(response) {
+				toaster.pop('error', '提示', response.data);
+			});
+		}
 	}]);
 	
 	/**
@@ -15305,7 +15399,7 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 	/**
 	 * 采购物料资料
 	 */
-	app.controller('PurcProductCtrl', ['$scope', 'PurcProduct', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', function($scope, PurcProduct, ngTableParams, $filter, BaseService, toaster, $timeout, Products) {
+	app.controller('PurcProductCtrl', ['$scope', 'PurcProduct', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$modal', function($scope, PurcProduct, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $modal) {
 		BaseService.scrollBackToTop();
 		$scope.active = 'all';
 		$scope.agreedText = '全部';
@@ -15397,6 +15491,74 @@ define([ 'toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 				toaster.pop('error', '提示', response.data);
 			})
 		}
+		
+		var products = [];
+		$scope.checks = {
+	            checked: false
+	        };
+		
+		// 全选框
+	    $scope.checkAll = function() {
+	    	products = [];// 每次选择时先清空,防止重复
+	            angular.forEach($scope.tableParams.data, function(product) {
+	            	if(product.cmpUuId == null) {
+	            		product.checked = $scope.checks.checked;
+	            	}
+	        });
+	     };
+
+        // 单选
+        $scope.checkOne = function(product) {
+        	products = [];// 每次选择时先清空,防止重复
+    		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.updateByBatch = function(updatetype) {
+        	angular.forEach($scope.tableParams.data, function(product) { // 单选全部时,全选选中
+        		if (product.checked) {
+        			products.push(product);
+        		}
+        	});
+        	console.log(products);
+        	if(products.length == 0) {
+				toaster.pop('warning', 'ts', '请至少选择一个产品');
+			} else {
+				var modalInstance = $modal.open({
+					templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
+					controller: 'UpdateByBatchCtrl',
+					size: 'lg',
+					resolve: {
+						products: function() {
+							return products;
+						},
+						updatetype: function() {
+							return updatetype;
+						}
+					}
+				});
+				
+				modalInstance.result.then(function(data) {
+					toaster.pop('success', '提示', data.data);
+					$scope.tableParams.reload();
+				}, function(){
+					
+				});
+			}
+        }
 	}]);
 	
 	/**

+ 4 - 0
src/main/webapp/resources/js/index/services/Product.js

@@ -25,6 +25,10 @@ define([ 'ngResource'], function() {
 			toggle: {
 				url: 'purcProduct/toggle/:status',
 				method: 'POST'
+			},
+			updateByBatch: {
+				url: 'product/updateByBatch',
+				method: 'POST'
 			}
 		});
 	}]).factory('PurcProduct', ['$resource', function($resource) {

+ 44 - 0
src/main/webapp/resources/tpl/index/baseInfo/modal/updateByBatch_modal.html

@@ -0,0 +1,44 @@
+<style>
+.headerline .content {
+	width: 100px;
+	font-size: 14px;
+}
+.modal-body {
+	min-height: 350px;
+}
+.modal {
+ 	top: 70px;
+}
+</style>
+<div class="modal-body" style="min-height: 500px;">
+	<div class="headerline">
+		<span class="content"><i class="fa fa-fw fa-edit text-primary"></i>修改类型-{{updatetype}}</span>
+	</div>
+	<table class="block table table-default table-striped table-bordered" ng-if="changed">
+		<thead>
+			<tr class="header">
+				<th width="160px">原{{updatetype}}</th>
+				<th width="160px">--></th>
+				<th width="160px">新{{updatetype}}</th>
+			</tr>
+		</thead>
+		<tbody>
+			<tr ng-repeat="product in products">
+				<td class="text-center" ng-if="updatetype == '品牌'"><span ng-bind="::product.brand"></span></td>
+				<td class="text-center" ng-if="updatetype == '名称(类目)'"><span ng-bind="::product.title"></span></td>
+				<td class="text-center" ng-if="updatetype == '产品型号'"><span ng-bind="::product.spec"></span></td>
+				<td class="text-center">--></td>
+				<td class="text-center"><span ng-bind="::keyword"></span></td>
+			</tr>
+		</tbody>
+	</table>
+	<div ng-if="!changed">
+		<input ng-model="keyword">
+		<a class="btn btn-default" ng-click="ensure(keyword)">确定</a>
+	</div>
+</div>
+<div class="modal-footer">
+	<button class="btn btn-default" ng-click="okay()" type="button" ng-if="changed">确定修改</button>
+	<button class="btn btn-default" ng-click="returnUpdate()" type="button" ng-if="changed">返回修改</button>
+	<button class="btn btn-default" ng-click="cancel()" type="button" ng-if="!changed">取消</button>
+</div>

+ 9 - 0
src/main/webapp/resources/tpl/index/baseInfo/prodList.html

@@ -159,6 +159,13 @@
                         </div>
                     </div>
                 </div>
+                 <a ng-click="">批量修改</a>
+                 <select type="select" ng-model="product.updatetype" ng-init="product.updatetype = '品牌'">
+                 	<option value="品牌">品牌</option>
+                 	<option value="名称(类目)">名称(类目)</option>
+                 	<option value="产品型号">产品型号</option>
+                 </select>
+                 <a ng-click="updateByBatch(product.updatetype)">确定</a>
             </div>
         </div>
     </div>
@@ -166,6 +173,7 @@
         <table class="order-table block " ng-table="tableParams">
             <thead>
             <tr class="header">
+            	<th><input type="checkbox" ng-model="checks.checked" ng-click="checkAll()"></th>
                 <th width="140">产品编号</th>
                 <th>产品名称(类目)</th>
                 <th width="160">产品型号</th>
@@ -182,6 +190,7 @@
             </thead>
             <tbody ng-repeat="product in $data">
             <tr class="order-hd">
+            	<td><input type="checkbox" ng-model="product.checked" ng-click="checkOne(product)" ng-disabled="product.cmpUuId != null"></td>
                 <td class="text-center" title="{{product.code}}" ng-bind="::product.code"></td>
                 <td class="line-h20 first text-center">
                     <div class="order-main">

+ 9 - 0
src/main/webapp/resources/tpl/index/purc/prodList.html

@@ -160,6 +160,13 @@
                         </div>
                     </div>
                 </div>
+                 <a ng-click="">批量修改</a>
+                 <select type="select" ng-model="product.updatetype" ng-init="product.updatetype = '品牌'">
+                 	<option value="品牌">品牌</option>
+                 	<option value="名称(类目)">名称(类目)</option>
+                 	<option value="产品型号">产品型号</option>
+                 </select>
+                 <a ng-click="updateByBatch(product.updatetype)">确定</a>
             </div>
         </div>
     </div>
@@ -167,6 +174,7 @@
         <table class="order-table block " ng-table="tableParams">
             <thead>
             <tr class="header">
+          		<th><input type="checkbox" ng-model="checks.checked" ng-click="checkAll()"></th>
                 <th width="140">物料编号</th>
                 <th>物料名称(类目)</th>
                 <th width="160">物料型号</th>
@@ -183,6 +191,7 @@
             </thead>
             <tbody ng-repeat="product in $data">
             <tr class="order-hd">
+            	<td><input type="checkbox" ng-model="product.checked" ng-click="checkOne(product)" ng-disabled="product.cmpUuId != null"></td>
                 <td class="text-center" title="{{product.code}}" ng-bind="::product.code"></td>
                 <td class="line-h20 first text-center">
                     <div class="order-main">