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

Merge remote-tracking branch 'origin/dev' into dev

wangdy 8 лет назад
Родитель
Сommit
435f97f081

+ 24 - 15
src/main/java/com/uas/platform/b2c/trade/presale/controller/CollectionController.java

@@ -136,13 +136,20 @@ public class CollectionController {
 		while (it.hasNext()){
 			String uuid = it.next();
 			ComponentInfo componentInfo = componentInfoDao.findByUuid(uuid);
-			Collection store = new Collection();
-			store.setComponentid(componentInfo.getId());
-			store.setUseruu(SystemSession.getUser().getUserUU());
-			store.setEnuu(SystemSession.getUser().getEnterprise().getUu());
-			store.setCreatetime(new Date());
-			store.setKind(2);
-			storeList.add(store);
+			if (componentInfo != null){
+				Collection store = new Collection();
+				store.setComponentid(componentInfo.getId());
+				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());
+				store.setKind(2);
+				storeList.add(store);
+			}
 		}
 		collectionService.save(storeList);
 		return "success";
@@ -160,15 +167,17 @@ public class CollectionController {
 		String result = "success";
 		if (StringUtils.hasText(str)) {
 			Collection store = FastjsonUtils.fromJson(str, Collection.class);
-			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());
+			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.setCreatetime(new Date());
-			result = collectionService.save(store);
 		}
 		System.out.println("result = " + result);
 		return result;

+ 11 - 0
src/main/java/com/uas/platform/b2c/trade/presale/dao/CollectionDao.java

@@ -85,4 +85,15 @@ public interface CollectionDao extends JpaRepository<Collection, Long>, JpaSpeci
 	 * List<Collection> 返回收藏记录列表
 	 */
 	List<Collection> findStoreByUseruuAndEnuuAndKindAndComponentid(Long useruu, Long enuu, int kind, Long componentid);
+
+	/**
+	 * 获取指定的store 判断器件是否存在
+	 *
+	 * @param useruu 个人uu
+	 * @param dissociative 是否为个人用户
+	 * @param kind 收藏类型,品牌或者器件
+	 * @param componentid 器件id
+	 * @return
+	 */
+	List<Collection> findStoreByUseruuAndDissociativeAndKindAndComponentid(Long useruu, Integer dissociative, int kind, Long componentid);
 }

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

@@ -79,9 +79,13 @@ public class CollectionServiceImpl implements CollectionService {
 				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) {
+			if (SystemSession.getUser().getEnterprise() != null){
+				storeList = collectionDao
+						.findStoreByUseruuAndEnuuAndKindAndComponentid(SystemSession.getUser().getUserUU(), SystemSession.getUser().getEnterprise().getUu(), 2, store.getComponentid());
+			} else {
+				storeList = collectionDao.findStoreByUseruuAndDissociativeAndKindAndComponentid(SystemSession.getUser().getUserUU(), Type.PERSONAL.value(), 2, store.getComponentid());
+			}
+			if (storeList.size() == 0) {
 				collectionDao.save(store);
 			}else {
 				return "repeat";