xiongzhu před 4 roky
rodič
revize
04eb503cc7

+ 40 - 0
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -95,4 +95,44 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
     List<User> findByPhoneInAndDelFalse(Iterable<String> phone);
 
     List<User> findByIdInAndDelFalse(Iterable<Long> userId);
+
+    @Query(value = "update asset join user on asset.minter_id = user.id " +
+            "set asset.minter        = user.nickname, " +
+            "    asset.minter_avatar = user.avatar " +
+            "where user.id = ?1;", nativeQuery = true)
+    @Modifying
+    @Transactional
+    void updateAssetMinter(Long userId);
+
+    @Query(value = "update asset join user on asset.owner_id = user.id " +
+            "set asset.owner        = user.nickname, " +
+            "    asset.owner_avatar = user.avatar " +
+            "where user.id = ?1;", nativeQuery = true)
+    @Modifying
+    @Transactional
+    void updateAssetOwner(Long userId);
+
+    @Query(value = "update collection_info join user on collection_info.minter_id = user.id " +
+            "set collection_info.minter        = user.nickname, " +
+            "    collection_info.minter_avatar = user.avatar " +
+            "where user.id = ?1;", nativeQuery = true)
+    @Modifying
+    @Transactional
+    void updateCollectionMinter(Long userId);
+
+    @Query(value = "update collection_info join user on collection_info.owner_id = user.id " +
+            "set collection_info.owner        = user.nickname, " +
+            "    collection_info.owner_avatar = user.avatar " +
+            "where user.id = ?1;", nativeQuery = true)
+    @Modifying
+    @Transactional
+    void updateCollectionOwner(Long userId);
+
+    @Query(value = "update order_info join user on order_info.minter_id = user.id " +
+            "set order_info.minter        = user.nickname, " +
+            "    order_info.minter_avatar = user.avatar " +
+            "where user.id = ?1;", nativeQuery = true)
+    @Modifying
+    @Transactional
+    void updateOrderMinter(Long userId);
 }

+ 5 - 0
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -16,6 +16,7 @@ import org.apache.commons.lang3.RandomUtils;
 import org.apache.commons.lang3.Range;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
@@ -43,6 +44,10 @@ public class CollectionService {
     private AssetService                  assetService;
     private RedisTemplate<String, Object> redisTemplate;
 
+    @CacheEvict(value = "collection", allEntries = true)
+    public void clearCache() {
+    }
+
     public Page<Collection> all(PageQuery pageQuery) {
         pageQuery.getQuery().put("del", false);
         String type = MapUtils.getString(pageQuery.getQuery(), "type", "DEFAULT");

+ 18 - 15
src/main/java/com/izouma/nineth/service/UserService.java

@@ -49,27 +49,30 @@ import java.util.stream.Collectors;
 @Slf4j
 @AllArgsConstructor
 public class UserService {
-    private UserRepo         userRepo;
-    private WxMaService      wxMaService;
-    private WxMpService      wxMpService;
-    private SmsService       smsService;
-    private StorageService   storageService;
-    private JwtTokenUtil     jwtTokenUtil;
-    private CaptchaService   captchaService;
-    private FollowService    followService;
-    private FollowRepo       followRepo;
-    private IdentityAuthRepo identityAuthRepo;
-    private SysConfigService sysConfigService;
+    private UserRepo          userRepo;
+    private WxMaService       wxMaService;
+    private WxMpService       wxMpService;
+    private SmsService        smsService;
+    private StorageService    storageService;
+    private JwtTokenUtil      jwtTokenUtil;
+    private CaptchaService    captchaService;
+    private FollowService     followService;
+    private FollowRepo        followRepo;
+    private IdentityAuthRepo  identityAuthRepo;
+    private SysConfigService  sysConfigService;
+    private CollectionService collectionService;
 
     @CacheEvict(value = "user", key = "#user.username")
     public User update(User user) {
         User orig = userRepo.findById(user.getId()).orElseThrow(new BusinessException("无记录"));
         ObjUtils.merge(orig, user);
         orig = userRepo.save(orig);
-        userRepo.updateMinterForCollection(orig.getId());
-        userRepo.updateOwnerForCollection(orig.getId());
-        userRepo.updateMinterForOrder(orig.getId());
-        userRepo.updateMinterForAsset(orig.getId());
+        userRepo.updateAssetMinter(orig.getId());
+        userRepo.updateAssetOwner(orig.getId());
+        userRepo.updateCollectionMinter(orig.getId());
+        userRepo.updateCollectionOwner(orig.getId());
+        userRepo.updateOrderMinter(orig.getId());
+        collectionService.clearCache();
         return orig;
     }