This commit is contained in:
redkale
2024-01-09 23:22:12 +08:00
parent 4de3d3f505
commit ce630ee253
16 changed files with 963 additions and 95 deletions

View File

@@ -0,0 +1,25 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.redkale.test.source.parser;
import java.io.*;
import org.redkale.convert.json.*;
import org.redkale.persistence.*;
/**
*
* @author zhangjx
*/
@Entity
public abstract class BaseEntity implements Serializable {
@Override
public String toString() {
return JsonConvert.root().convertTo(this);
}
}

View File

@@ -0,0 +1,14 @@
/*
*
*/
package org.redkale.test.source.parser;
import org.redkale.source.DataSqlMapper;
/**
*
* @author zhangjx
*/
public interface BaseMapper<V> extends DataSqlMapper<V> {
}

View File

@@ -0,0 +1,39 @@
/*
*
*/
package org.redkale.test.source.parser;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import org.junit.jupiter.api.Test;
import org.redkale.source.DataSqlMapper;
import org.redkale.source.SourceException;
import org.redkale.util.TypeToken;
/**
*
* @author zhangjx
*/
public class DataSqlMapperTest {
public static void main(String[] args) throws Throwable {
DataSqlMapperTest test = new DataSqlMapperTest();
test.run();
System.out.println(entityType(ForumInfoMapper.class));
}
private static Class entityType(Class mapperType) {
for (Type t : mapperType.getGenericInterfaces()) {
if (DataSqlMapper.class.isAssignableFrom(TypeToken.typeToClass(t))) {
return TypeToken.typeToClass(((ParameterizedType) t).getActualTypeArguments()[0]);
}
}
throw new SourceException("Not found entity class from " + mapperType.getName());
}
@Test
public void run() throws Exception {
}
}

View File

@@ -0,0 +1,62 @@
/*
*
*/
package org.redkale.test.source.parser;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.redkale.source.DataSqlSource;
/**
*
* @author zhangjx
*/
public class DynForumInfoMapperImpl implements ForumInfoMapper {
private DataSqlSource source;
private Class type;
@Override
public ForumResult findForumResult(ForumBean bean) {
String sql = "SELECT f.forum_groupid, s.forum_section_color FROM forum_info f, forum_section s WHERE f.forumid = s.forumid";
Map<String, Object> params = new HashMap<>();
params.put("bean", bean);
return dataSource().nativeQueryOne(ForumResult.class, sql, params);
}
public CompletableFuture<ForumResult> findForumResultAsync(ForumBean bean) {
String sql = "SELECT f.forum_groupid, s.forum_section_color FROM forum_info f, forum_section s WHERE f.forumid = s.forumid";
Map<String, Object> params = new HashMap<>();
params.put("bean", bean);
return dataSource().nativeQueryOneAsync(ForumResult.class, sql, params);
}
@Override
public List<ForumResult> queryForumResult(ForumBean bean) {
String sql = "SELECT f.forum_groupid, s.forum_section_color FROM forum_info f, forum_section s WHERE f.forumid = s.forumid";
Map<String, Object> params = new HashMap<>();
params.put("bean", bean);
return dataSource().nativeQueryList(ForumResult.class, sql, params);
}
public CompletableFuture<List<ForumResult>> queryForumResultAsync(ForumBean bean) {
String sql = "SELECT f.forum_groupid, s.forum_section_color FROM forum_info f, forum_section s WHERE f.forumid = s.forumid";
Map<String, Object> params = new HashMap<>();
params.put("bean", bean);
return dataSource().nativeQueryListAsync(ForumResult.class, sql, params);
}
@Override
public DataSqlSource dataSource() {
return source;
}
@Override
public Class<ForumInfo> entityType() {
return type;
}
}

View File

@@ -0,0 +1,44 @@
/*
*
*/
package org.redkale.test.source.parser;
import java.io.Serializable;
/**
*
* @author zhangjx
*/
public class ForumBean implements Serializable {
private String forumSectionid;
private String forumSectionColor;
private String forumid;
public String getForumSectionid() {
return forumSectionid;
}
public void setForumSectionid(String forumSectionid) {
this.forumSectionid = forumSectionid;
}
public String getForumSectionColor() {
return forumSectionColor;
}
public void setForumSectionColor(String forumSectionColor) {
this.forumSectionColor = forumSectionColor;
}
public String getForumid() {
return forumid;
}
public void setForumid(String forumid) {
this.forumid = forumid;
}
}

View File

@@ -0,0 +1,259 @@
package org.redkale.test.source.parser;
import java.util.*;
import org.redkale.convert.*;
import org.redkale.persistence.*;
import org.redkale.util.Utility;
/**
*
* @author zhangjx
*/
@Table(name = "forum_info", comment = "论坛信息表")
public class ForumInfo extends BaseEntity implements Comparable<ForumInfo> {
@Id
@Column(name = "forum_id", length = 64, comment = "论坛ID")
private String forumid;
@Column(name = "forum_name", length = 128, comment = "论坛的名称")
private String forumName;
@Column(name = "forum_groupid", length = 64, comment = "论坛分类的ID")
private String forumGroupid;
@Column(name = "forum_sections", length = 1024, comment = "论坛小版块的ID集合")
private String[] forumSections;
@Column(name = "forum_managerids", length = 1024, comment = "论坛小版块的ID集合")
private Set<Integer> forumManagerids;
@Column(name = "forum_face_url", length = 255, comment = "论坛的图片url")
private String forumFaceUrl;
@Column(name = "forum_css_img_url", length = 255, comment = "论坛的背景图url")
private String forumCssImgUrl;
@Column(name = "forum_css_url", length = 255, comment = "论坛的样式url")
private String forumCssUrl;
@Column(name = "forum_css_content", length = 10240, comment = "论坛的css内容")
private String forumCssContent;
@Column(name = "forum_bar_html", length = 1024, comment = "版块的提示栏")
private String forumBarHtml;
@Column(name = "forum_desc", length = 255, comment = "论坛说明")
private String forumDesc;
@Column(name = "forum_notice", length = 1024, comment = "论坛公告")
private String forumNotice;
@Column(comment = "被关注的用户数")
private long followers;
@Column(name = "post_count", comment = "帖子数")
private long postCount;
@Column(name = "like_count", comment = "关注数")
private long likeCount;
@Column(comment = "排序顺序,值小靠前")
private int display = 1000;
@Transient
private Map<String, ForumSection> sections;
public ForumSection findForumSection(String forumSectionid) {
return sections == null ? null : sections.get(forumSectionid);
}
public synchronized void increLikeCount() {
this.likeCount++;
}
public synchronized void increPostCount(String sectionid) {
this.postCount++;
if (sections != null && sectionid != null && !sectionid.isEmpty()) {
ForumSection section = sections.get(sectionid);
if (section != null) {
section.increPostCount();
}
}
}
public synchronized void increFollowers() {
this.followers++;
}
public synchronized void decreFollowers() {
this.followers--;
}
public boolean containsManagerid(int userid) {
return forumManagerids != null && forumManagerids.contains(userid);
}
public boolean containsSection(String forumSectionid) {
return forumSections != null && forumSectionid != null && Utility.contains(forumSections, forumSectionid);
}
public boolean emptyForumNotice() {
return this.forumNotice == null || this.forumNotice.isEmpty();
}
public boolean emptyCssImgUrl() {
return this.forumCssImgUrl == null || this.forumCssImgUrl.isEmpty();
}
public boolean emptyCssUrl() {
return this.forumCssUrl == null || this.forumCssUrl.isEmpty();
}
public boolean emptyCssContent() {
return this.forumCssContent == null || this.forumCssContent.isEmpty();
}
public void setForumid(String forumid) {
this.forumid = forumid;
}
public String getForumid() {
return this.forumid;
}
public void setForumName(String forumName) {
this.forumName = forumName;
}
public String getForumName() {
return this.forumName;
}
public void setForumFaceUrl(String forumFaceUrl) {
this.forumFaceUrl = forumFaceUrl;
}
public String getForumFaceUrl() {
return this.forumFaceUrl;
}
public String getForumCssImgUrl() {
return forumCssImgUrl;
}
public void setForumCssImgUrl(String forumCssImgUrl) {
this.forumCssImgUrl = forumCssImgUrl;
}
public String getForumCssUrl() {
return forumCssUrl;
}
public void setForumCssUrl(String forumCssUrl) {
this.forumCssUrl = forumCssUrl;
}
public String getForumCssContent() {
return forumCssContent;
}
public void setForumCssContent(String forumCssContent) {
this.forumCssContent = forumCssContent;
}
public String[] getForumSections() {
return forumSections;
}
public void setForumSections(String[] forumSections) {
this.forumSections = forumSections;
}
public Set<Integer> getForumManagerids() {
return forumManagerids;
}
public void setForumManagerids(Set<Integer> forumManagerids) {
this.forumManagerids = forumManagerids;
}
public String getForumGroupid() {
return forumGroupid;
}
public void setForumGroupid(String forumGroupid) {
this.forumGroupid = forumGroupid;
}
public String getForumDesc() {
return forumDesc;
}
public void setForumDesc(String forumDesc) {
this.forumDesc = forumDesc;
}
public String getForumNotice() {
return forumNotice;
}
public void setForumNotice(String forumNotice) {
this.forumNotice = forumNotice;
}
public long getFollowers() {
return followers;
}
public void setFollowers(long followers) {
this.followers = followers;
}
public void setPostCount(long postCount) {
this.postCount = postCount;
}
public long getPostCount() {
return this.postCount;
}
public long getLikeCount() {
return likeCount;
}
public void setLikeCount(long likeCount) {
this.likeCount = likeCount;
}
public void setDisplay(int display) {
this.display = display;
}
@ConvertColumn(ignore = true, type = ConvertType.PROTOBUF_JSON)
public int getDisplay() {
return this.display;
}
@Override
public int compareTo(ForumInfo o) {
return this.display - o.display;
}
public Map<String, ForumSection> getSections() {
return sections;
}
public void setSections(Map<String, ForumSection> sections) {
this.sections = sections;
}
public String getForumBarHtml() {
return forumBarHtml;
}
public void setForumBarHtml(String forumBarHtml) {
this.forumBarHtml = forumBarHtml;
}
}

View File

@@ -0,0 +1,43 @@
/*
*
*/
package org.redkale.test.source.parser;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.redkale.persistence.Sql;
/**
*
* @author zhangjx
*/
public interface ForumInfoMapper extends BaseMapper<ForumInfo> {
@Sql("SELECT f.forum_groupid, s.forum_section_color "
+ "FROM forum_info f, forum_section s "
+ " WHERE f.forumid = s.forumid AND "
+ "s.forum_sectionid = ${bean.forumSectionid} AND "
+ "f.forumid = ${bean.forumid} AND s.forum_section_color = ${bean.forumSectionColor}")
public ForumResult findForumResult(ForumBean bean);
@Sql("SELECT f.forum_groupid, s.forum_section_color "
+ "FROM forum_info f, forum_section s "
+ " WHERE f.forumid = s.forumid AND "
+ "s.forum_sectionid = ${bean.forumSectionid} AND "
+ "f.forumid = ${bean.forumid} AND s.forum_section_color = ${bean.forumSectionColor}")
public CompletableFuture<ForumResult> findForumResultAsync(ForumBean bean);
@Sql("SELECT f.forum_groupid, s.forum_section_color "
+ "FROM forum_info f, forum_section s "
+ " WHERE f.forumid = s.forumid AND "
+ "s.forum_sectionid = ${bean.forumSectionid} AND "
+ "f.forumid = ${bean.forumid} AND s.forum_section_color = ${bean.forumSectionColor}")
public List<ForumResult> queryForumResult(ForumBean bean);
@Sql("SELECT f.forum_groupid, s.forum_section_color "
+ "FROM forum_info f, forum_section s "
+ " WHERE f.forumid = s.forumid AND "
+ "s.forum_sectionid = ${bean.forumSectionid} AND "
+ "f.forumid = ${bean.forumid} AND s.forum_section_color = ${bean.forumSectionColor}")
public CompletableFuture<List<ForumResult>> queryForumResultAsync(ForumBean bean);
}

View File

@@ -0,0 +1,39 @@
/*
*
*/
package org.redkale.test.source.parser;
import org.redkale.convert.json.JsonConvert;
/**
*
* @author zhangjx
*/
public class ForumResult {
private String forumGroupid;
private String forumSectionColor;
public String getForumGroupid() {
return forumGroupid;
}
public void setForumGroupid(String forumGroupid) {
this.forumGroupid = forumGroupid;
}
public String getForumSectionColor() {
return forumSectionColor;
}
public void setForumSectionColor(String forumSectionColor) {
this.forumSectionColor = forumSectionColor;
}
@Override
public String toString() {
return JsonConvert.root().convertTo(this);
}
}

View File

@@ -0,0 +1,134 @@
package org.redkale.test.source.parser;
import java.util.Set;
import org.redkale.convert.*;
import org.redkale.persistence.*;
/**
*
* @author zhangjx
*/
@Table(name = "forum_section", comment = "论坛小版块信息表")
public class ForumSection extends BaseEntity {
@Id
@Column(name = "forum_sectionid", length = 64, comment = "论坛小版块ID")
private String forumSectionid;
@Column(length = 64, comment = "论坛ID")
private String forumid;
@Column(name = "forum_section_name", length = 128, comment = "论坛小版块的名称")
private String forumSectionName;
@Column(name = "forum_section_face_url", length = 255, comment = "论坛小版块的图标url")
private String forumSectionFaceUrl;
@Column(name = "forum_section_managerids", length = 1024, comment = "论坛小版块的ID集合")
private Set<Integer> forumSectionManagerids;
@Column(name = "forum_section_desc", length = 32, comment = "论坛小版块说明")
private String forumSectionDesc;
@Column(name = "forum_section_color", length = 255, comment = "论坛小版块小标题的背景色")
private String forumSectionColor;
@Column(name = "forum_section_bar_html", length = 1024, comment = "版块的提示栏")
private String forumSectionBarHtml;
@Column(name = "post_count", comment = "帖子数")
private long postCount;
@Column(comment = "排序顺序,值小靠前")
private int display = 1000;
public void increPostCount() {
this.postCount++;
}
public boolean containsSectionManagerid(int userid) {
return forumSectionManagerids != null && forumSectionManagerids.contains(userid);
}
public void setForumSectionid(String forumSectionid) {
this.forumSectionid = forumSectionid;
}
public String getForumSectionid() {
return this.forumSectionid;
}
public String getForumid() {
return forumid;
}
public void setForumid(String forumid) {
this.forumid = forumid;
}
public void setForumSectionName(String forumSectionName) {
this.forumSectionName = forumSectionName;
}
public String getForumSectionName() {
return this.forumSectionName;
}
public void setForumSectionFaceUrl(String forumSectionFaceUrl) {
this.forumSectionFaceUrl = forumSectionFaceUrl;
}
public String getForumSectionFaceUrl() {
return this.forumSectionFaceUrl;
}
public String getForumSectionColor() {
return forumSectionColor;
}
public void setForumSectionColor(String forumSectionColor) {
this.forumSectionColor = forumSectionColor;
}
public void setForumSectionDesc(String forumSectionDesc) {
this.forumSectionDesc = forumSectionDesc;
}
public Set<Integer> getForumSectionManagerids() {
return forumSectionManagerids;
}
public void setForumSectionManagerids(Set<Integer> forumSectionManagerids) {
this.forumSectionManagerids = forumSectionManagerids;
}
public String getForumSectionDesc() {
return this.forumSectionDesc;
}
public void setPostCount(long postCount) {
this.postCount = postCount;
}
public long getPostCount() {
return this.postCount;
}
public void setDisplay(int display) {
this.display = display;
}
@ConvertColumn(ignore = true, type = ConvertType.PROTOBUF_JSON)
public int getDisplay() {
return this.display;
}
public String getForumSectionBarHtml() {
return forumSectionBarHtml;
}
public void setForumSectionBarHtml(String forumSectionBarHtml) {
this.forumSectionBarHtml = forumSectionBarHtml;
}
}