yujia 7 лет назад
Родитель
Сommit
2f07ab841c

+ 12 - 16
src/main/java/com/uas/platform/b2c/trade/presale/controller/CollectionController.java

@@ -16,11 +16,7 @@ import com.wordnik.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.util.StringUtils;
-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.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -189,20 +185,20 @@ public class CollectionController {
 	 */
 	@RequestMapping(value = "/save", method = RequestMethod.POST)
 	@ApiOperation(value = "保存收藏信息", httpMethod = "POST")
-	public String saveEntity(@ApiParam(required = true, value = "保存的json对象") @RequestBody String str) {
+	public String saveEntity(@ApiParam(required = true, value = "保存的json对象") @RequestBody String str, @RequestParam(defaultValue = "", required = false) String cmpuuid) {
 		String result = "success";
 		if (StringUtils.hasText(str)) {
 			Collection store = FastjsonUtils.fromJson(str, Collection.class);
-			if (store.getComponentid() != null){
-				store.setUseruu(SystemSession.getUser().getUserUU());
-				if (SystemSession.getUser().getEnterprise() != null) {
-					store.setDissociative(Type.ENTERPRISING.value());
-					store.setEnuu(SystemSession.getUser().getEnterprise().getUu());
-				} else {
-					store.setDissociative(Type.PERSONAL.value());
-				}
-				store.setCreatetime(new Date());
-				result = collectionService.save(store);
+			store.setUseruu(SystemSession.getUser().getUserUU());
+			if (SystemSession.getUser().getEnterprise() != null) {
+				store.setDissociative(Type.ENTERPRISING.value());
+				store.setEnuu(SystemSession.getUser().getEnterprise().getUu());
+			} else {
+				store.setDissociative(Type.PERSONAL.value());
+			}
+			store.setCreatetime(new Date());
+			if ((store.getComponentid() != null) || (!StringUtils.isEmpty(cmpuuid))) {
+				result = collectionService.save(store, cmpuuid);
 			}
 		}
 		System.out.println("result = " + result);

+ 1 - 1
src/main/java/com/uas/platform/b2c/trade/presale/service/CollectionService.java

@@ -52,7 +52,7 @@ public interface CollectionService {
 	 * @param store 收藏的信息
 	 * @return String 返回success
 	 */
-	String save(Collection store);
+	String save(Collection store, String cmpuuid);
 
 	/**
 	 * 2016年3月23日 下午3:35:26

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

@@ -2,6 +2,8 @@ package com.uas.platform.b2c.trade.presale.service.impl;
 
 import com.uas.platform.b2c.common.account.model.User;
 import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
+import com.uas.platform.b2c.prod.product.component.modal.Component;
 import com.uas.platform.b2c.trade.presale.dao.CollectionDao;
 import com.uas.platform.b2c.trade.presale.dao.CollectionInfoDao;
 import com.uas.platform.b2c.trade.presale.model.Collection;
@@ -15,6 +17,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
@@ -37,6 +40,9 @@ public class CollectionServiceImpl implements CollectionService {
 	@Autowired
 	private CollectionInfoDao collectionInfoDao;
 
+	@Autowired
+	private ComponentDao componentDao;
+
 	@Override
 	public List<CollectionInfo> deleteById(Long id) {
 		collectionDao.delete(id);
@@ -82,7 +88,13 @@ public class CollectionServiceImpl implements CollectionService {
 	}
 
 	@Override
-	public String save(Collection store) {
+	public String save(Collection store, String cmpuuid) {
+		if (!StringUtils.isEmpty(cmpuuid)) {
+			Component component = componentDao.findByUuid(cmpuuid);
+			if (component != null) {
+				store.setComponentid(component.getId());
+			}
+		}
 		List<Collection> storeList = new ArrayList<Collection>();
 		if (store.getKind() == 1) {
 			if (SystemSession.getUser().getEnterprise() != null) {