Browse Source

调整收藏的代码

yujia 7 years ago
parent
commit
91a24bfaf3

+ 5 - 6
src/main/java/com/uas/platform/b2c/trade/presale/controller/CollectionController.java

@@ -185,8 +185,8 @@ public class CollectionController {
 	 */
 	@RequestMapping(value = "/save", method = RequestMethod.POST)
 	@ApiOperation(value = "保存收藏信息", httpMethod = "POST")
-	public String saveEntity(@ApiParam(required = true, value = "保存的json对象") @RequestBody String str, @RequestParam(defaultValue = "", required = false) String cmpuuid) {
-		String result = "success";
+	public ResultMap saveEntity(@ApiParam(required = true, value = "保存的json对象") @RequestBody String str) {
+		ResultMap map = ResultMap.success("ok");
 		if (StringUtils.hasText(str)) {
 			Collection store = FastjsonUtils.fromJson(str, Collection.class);
 			store.setUseruu(SystemSession.getUser().getUserUU());
@@ -197,12 +197,11 @@ public class CollectionController {
 				store.setDissociative(Type.PERSONAL.value());
 			}
 			store.setCreatetime(new Date());
-			if ((store.getComponentid() != null) || (!StringUtils.isEmpty(cmpuuid))) {
-				result = collectionService.save(store, cmpuuid);
+			if ((store.getComponentid() != null) || (!StringUtils.isEmpty(store.getCmpuuid()))) {
+				map = collectionService.save(store);
 			}
 		}
-		System.out.println("result = " + result);
-		return result;
+		return map;
 	}
 
 }

+ 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 cmpuuid);
+	ResultMap save(Collection store);
 
 	/**
 	 * 2016年3月23日 下午3:35:26

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

@@ -9,6 +9,7 @@ import com.uas.platform.b2c.trade.presale.dao.CollectionInfoDao;
 import com.uas.platform.b2c.trade.presale.model.Collection;
 import com.uas.platform.b2c.trade.presale.model.CollectionInfo;
 import com.uas.platform.b2c.trade.presale.service.CollectionService;
+import com.uas.platform.b2c.trade.support.CodeType;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.Type;
@@ -88,18 +89,17 @@ public class CollectionServiceImpl implements CollectionService {
 	}
 
 	@Override
-	public String save(Collection store, String cmpuuid) {
-		if ((!StringUtils.isEmpty(cmpuuid)) || (store.getComponentid() != null)) {
+	public ResultMap save(Collection store) {
+		if ((!StringUtils.isEmpty(store.getCmpuuid())) || (store.getComponentid() != null)) {
 			Component component = null;
-			if(!StringUtils.isEmpty(cmpuuid)) {
-				component = componentDao.findByUuid(cmpuuid);
+			if(!StringUtils.isEmpty(store.getCmpuuid())) {
+				component = componentDao.findByUuid(store.getCmpuuid());
 			} else if (store.getComponentid() != null) {
 				component = componentDao.findOne(store.getComponentid());
 			}
 
 			if (component != null) {
 				store.setComponentid(component.getId());
-				store.setCmpuuid(cmpuuid);
 				store.setSpec(component.getDescription());
 			}
 		}
@@ -115,7 +115,7 @@ public class CollectionServiceImpl implements CollectionService {
 			if (storeList.size() == 0) {
 				collectionDao.save(store);
 			}else {
-				return "repeat";
+				return new ResultMap(CodeType.NOT_PERMIT, "该信息已被收藏");
 			}
 		} else if (store.getKind() == 2) {
 			if (SystemSession.getUser().getEnterprise() != null){
@@ -127,10 +127,10 @@ public class CollectionServiceImpl implements CollectionService {
 			if (storeList.size() == 0) {
 				collectionDao.save(store);
 			}else {
-				return "repeat";
+				return new ResultMap(CodeType.NOT_PERMIT, "该信息已被收藏");
 			}
 		}
-		return "success";
+		return ResultMap.success("成功");
 	}
 
 	@Override