1.add is publish conditon for app journal filter

main
Gary 11 months ago
parent 24fa4a5a42
commit b4b999b964

@ -0,0 +1,38 @@
package enums;
public enum JournalPublishEnum {
NOT_PUBLISH("0", "未发布"),
HAS_PUBLISH("1", "已发布");
private String status;
private String desc;
JournalPublishEnum(String status, String desc) {
this.status = status;
this.desc = desc;
}
public static JournalPublishEnum getByStatus(String status) {
for (JournalPublishEnum item : JournalPublishEnum.values()) {
if (item.getStatus().equals(status)) {
return item;
}
}
return null;
}
public String getStatus() {
return status;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}

@ -65,19 +65,19 @@ public interface JournalDao extends JpaRepository<Journal,String>,JpaSpecificati
@Query(value = "select * from tb_journal where id in ?1 and state='1' order by field(id,?1)", nativeQuery = true)
List<Journal> orderByField(List<String> objectIds);
@Query(value = "select 1 from tb_journal where ?1 in (select journal_no_tmp.journal_no from (select * from tb_journal where state='1' order by ABS(journal_no) desc limit 10) as journal_no_tmp) limit 1", nativeQuery = true)
@Query(value = "select 1 from tb_journal where ?1 in (select journal_no_tmp.journal_no from (select * from tb_journal where state='1' and is_publish='1' order by ABS(journal_no) desc limit 10) as journal_no_tmp) limit 1", nativeQuery = true)
Integer isLatest10ByJournalNo(String journalNo);
@Query(value = "select 1 from tb_journal where ?1 in (select journal_no_tmp.id from (select * from tb_journal where state='1' order by ABS(journal_no) desc limit 10) as journal_no_tmp) limit 1", nativeQuery = true)
@Query(value = "select 1 from tb_journal where ?1 in (select journal_no_tmp.id from (select * from tb_journal where state='1' and is_publish='1' order by ABS(journal_no) desc limit 10) as journal_no_tmp) limit 1", nativeQuery = true)
Integer isLatest10ByJournalId(String journalId);
@Query(value = "select max(ABS(journal_no)) FROM tb_journal where state='1'", nativeQuery = true)
@Query(value = "select max(ABS(journal_no)) FROM tb_journal where state='1' and is_publish='1'", nativeQuery = true)
int getMaxJournalNo();
@Query(value = "select id from tb_journal where id not in ?2 and state='1' order by rand() limit ?1", nativeQuery = true)
@Query(value = "select id from tb_journal where id not in ?2 and state='1' and is_publish='1' order by rand() limit ?1", nativeQuery = true)
List<String> random(int limit, List<String> recommendIds);
@Query(value = "select id from tb_journal where state='1' order by rand() limit ?1", nativeQuery = true)
@Query(value = "select id from tb_journal where state='1' and is_publish='1' order by rand() limit ?1", nativeQuery = true)
List<String> random(int limit);
}

@ -10,6 +10,7 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import api.Result;
import enums.JournalPublishEnum;
import enums.JournalStatusEnum;
import org.apache.commons.lang.StringUtils;
@ -191,7 +192,7 @@ public class JournalService {
}
predicateList.add(criteriaBuilder.equal(root.get("state").as(String.class), JournalStatusEnum.ENABLE.getStatus()));
predicateList.add(criteriaBuilder.equal(root.get("isPublish").as(String.class), JournalPublishEnum.HAS_PUBLISH.getStatus()));
query.orderBy(criteriaBuilder.desc(root.get("journalNo").as(Integer.class)));
return criteriaBuilder.and( predicateList.toArray(new Predicate[predicateList.size()]));
}

Loading…
Cancel
Save