Browse Source

修改产品收藏重复收藏的逻辑

hulh 8 years ago
parent
commit
a209453503

+ 4 - 2
src/main/java/com/uas/platform/b2c/trade/presale/controller/CollectionController.java

@@ -157,6 +157,7 @@ public class CollectionController {
 	@RequestMapping(value = "/save", method = RequestMethod.POST)
 	@ApiOperation(value = "保存收藏信息", httpMethod = "POST")
 	public String saveEntity(@ApiParam(required = true, value = "保存的json对象") @RequestBody String str) {
+		String result = "success";
 		if (StringUtils.hasText(str)) {
 			Collection store = FastjsonUtils.fromJson(str, Collection.class);
 			store.setUseruu(SystemSession.getUser().getUserUU());
@@ -167,9 +168,10 @@ public class CollectionController {
 				store.setDissociative(Type.PERSONAL.value());
 			}
 			store.setCreatetime(new Date());
-			collectionService.save(store);
+			result = collectionService.save(store);
 		}
-		return "success";
+		System.out.println("result = " + result);
+		return result;
 	}
 
 }

+ 4 - 0
src/main/java/com/uas/platform/b2c/trade/presale/service/impl/CollectionServiceImpl.java

@@ -75,12 +75,16 @@ public class CollectionServiceImpl implements CollectionService {
 
 			if (storeList.size() == 0) {
 				collectionDao.save(store);
+			}else {
+				return "repeat";
 			}
 		} else if (store.getKind() == 2) {
 			List<Collection> storelist = collectionDao.findStoreByUseruuAndEnuuAndKindAndComponentid(
 					SystemSession.getUser().getUserUU(), SystemSession.getUser().getEnterprise().getUu(), 2, store.getComponentid());
 			if (storelist.size() == 0) {
 				collectionDao.save(store);
+			}else {
+				return "repeat";
 			}
 		}
 		return "success";

+ 1 - 0
src/main/webapp/resources/js/prod/controllers/ComponentCtrl.js

@@ -364,6 +364,7 @@ define([ 'app/app', 'jquery-summernote' ], function(app) {
 	}]);
 	
 	app.register.controller('CollectModelCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance){
+		$scope.haveAdd = true;
 		$scope.cancel = function() {
 			$modalInstance.dismiss();
 		};

+ 12 - 2
src/main/webapp/resources/js/usercenter/app.js

@@ -557,7 +557,16 @@ define([ 'angularAMD', 'ui.router', 'ui-bootstrap', 'ngLocal', 'ngTable', 'commo
 				$modal.open({
 					 templateUrl : $rootScope.rootPath + '/static/view/usercenter/modal/collectModel.html',
 					 controller : 'CollectModelCtrl',
-					 size : 'sm'
+					 size : 'sm',
+					 resolve : {
+						haveAdd : function(){
+							if (data == "success"){
+								return true;
+							} else{
+								return false;
+							}
+						}
+					 }
 				});
 				$rootScope.componentCount++;
 			}, function(error) {
@@ -567,7 +576,8 @@ define([ 'angularAMD', 'ui.router', 'ui-bootstrap', 'ngLocal', 'ngTable', 'commo
 			
 	}]);
 	
-	app.controller('CollectModelCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance){
+	app.controller('CollectModelCtrl', ['$scope', '$modalInstance', 'haveAdd', function($scope, $modalInstance, haveAdd){
+		$scope.haveAdd = haveAdd;
 		$scope.cancel = function() {
 			$modalInstance.dismiss();
 		};

+ 2 - 1
src/main/webapp/resources/view/usercenter/modal/collectModel.html

@@ -20,7 +20,8 @@
 </style>
 <div>
 	<div class="modal-header">
-		<h3 class="header-text">收藏成功!</h3>
+		<h3 class="header-text" ng-if="haveAdd">收藏成功!</h3>
+		<h3 class="header-text" ng-if="!haveAdd">请勿重复收藏!</h3>
 	</div>
 	<div class="modal-body">
 		<button type="button" ng-click="cancel()" class="btn" style="margin-left:25px;">关&nbsp;&nbsp;闭</button>