fix article and ad idempotent problem

main
Revers 9 months ago
parent a4161efdb2
commit daa8eeef2e

@ -11,6 +11,8 @@ import com.luoo.music.pojo.UserInfo;
import com.luoo.music.util.Constants; import com.luoo.music.util.Constants;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
@ -76,7 +78,19 @@ public class CMSAdvertisementService {
ad.setUserName(userInfo.getName()); ad.setUserName(userInfo.getName());
ad.setUserType(userInfo.getType()); ad.setUserType(userInfo.getType());
} }
Example<Advertisement> example = Example.of(ad, ExampleMatcher.matching()
.withIgnorePaths("id")
.withIgnorePaths("image")
.withIgnorePaths("pub_time")
.withIgnorePaths("createTime")
.withIgnorePaths("updateTime")
);
if(!adDao.exists(example)) {
adDao.save(ad); adDao.save(ad);
}
return Result.success(); return Result.success();
} }

@ -11,6 +11,8 @@ import com.luoo.music.pojo.UserInfo;
import com.luoo.music.util.Constants; import com.luoo.music.util.Constants;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
@ -101,7 +103,18 @@ public class CMSArticleService {
article.setPubTime(LocalDateTime.now()); article.setPubTime(LocalDateTime.now());
}*/ }*/
Example<Article> example = Example.of(article, ExampleMatcher.matching()
.withIgnorePaths("id")
.withIgnorePaths("image")
.withIgnorePaths("pubTime")
.withIgnorePaths("createTime")
.withIgnorePaths("updateTime")
);
if(!articleDao.exists(example)) {
articleDao.save(article); articleDao.save(article);
}
return Result.success(); return Result.success();
} }

Loading…
Cancel
Save