diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/pom.xml b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/pom.xml index ff5bcced015333e35c867a3a955b0fe36cdf9a8d..947e3929b291be474768510bdb58a59948fd6fa0 100644 --- a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/pom.xml +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/pom.xml @@ -13,6 +13,20 @@ nutzboot-starter-dubbo provided + + org.nutz + nutzboot-starter-jdbc + + + mysql + mysql-connector-java + 8.0.15 + + + com.h2database + h2 + 1.4.193 + com.alibaba dubbo diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/page/TableDataInfo.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/page/TableDataInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..f361b7cca77c01b2cd61197746ca4ae09ad6997b --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/page/TableDataInfo.java @@ -0,0 +1,69 @@ +package io.nutz.nutzsite.common.page; + +import java.io.Serializable; +import java.util.List; + +/** + * 表格分页数据对象 + * + * @author ruoyi + */ +public class TableDataInfo implements Serializable +{ + private static final long serialVersionUID = 1L; + /** 总记录数 */ + private long total; + /** 列表数据 */ + private List rows; + /** 消息状态码 */ + private int code; + + /** + * 表格数据对象 + */ + public TableDataInfo() + { + } + + /** + * 分页 + * + * @param list 列表数据 + * @param total 总记录数 + */ + public TableDataInfo(List list, int total) + { + this.rows = list; + this.total = total; + } + + public long getTotal() + { + return total; + } + + public void setTotal(long total) + { + this.total = total; + } + + public List getRows() + { + return rows; + } + + public void setRows(List rows) + { + this.rows = rows; + } + + public int getCode() + { + return code; + } + + public void setCode(int code) + { + this.code = code; + } +} diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/service/BaseService.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/service/BaseService.java new file mode 100644 index 0000000000000000000000000000000000000000..790e6a6e1be74e86522e7b483547e8acb3655081 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/service/BaseService.java @@ -0,0 +1,246 @@ +package io.nutz.nutzsite.common.service; + +import io.nutz.nutzsite.common.page.TableDataInfo; +import org.nutz.dao.*; +import org.nutz.dao.pager.Pager; + +import java.util.List; + +/** + * @Author: Haimming + * @Date: 2019-10-17 14:51 + * @Version 1.0 + */ +public interface BaseService { + Dao dao(); + + public int count(Condition cnd); + + public int count(); + + public int count(String tableName, Condition cnd); + + public int count(String tableName); + + public T fetch(long id); + + public T fetch(String name); + + public T fetchLinks(T t, String name); + + public List fetchLinks(List t, String name); + + public T fetchLinks(T t, String name, Condition cnd); + + public T insert(T t); + + public void insert(String tableName, Chain chain); + + public T fastInsert(T t); + + /** + * 查询获取部分字段 + * + * @param fieldName 支持通配符 ^(a|b)$ + * @param cnd + * @return + */ + List query(String fieldName, Condition cnd); + + /** + * 查询一组对象。你可以为这次查询设定条件 + * + * @param cnd WHERE 条件。如果为 null,将获取全部数据,顺序为数据库原生顺序
+ * 只有在调用这个函数的时候, cnd.limit 才会生效 + * @return 对象列表 + */ + List query(Condition cnd); + + /** + * 获取全部数据 + * + * @return + */ + List query(); + + /** + * @param cnd 查询条件 + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @return + */ + List query(Condition cnd, String linkName); + + /** + * 获取表及关联表全部数据(支持子查询) + * + * @param cnd 查询条件 + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @param linkCnd 关联条件 + * @return + */ + List query(Condition cnd, String linkName, Condition linkCnd); + + /** + * 获取表及关联表全部数据 + * + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @return + */ + List query(String linkName); + + /** + * 分页关联字段查询 + * + * @param cnd 查询条件 + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @param pager 分页对象 + * @return + */ + List query(Condition cnd, String linkName, Pager pager); + + /** + * 分页关联字段查询(支持关联条件) + * + * @param cnd 查询条件 + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @param linkCnd 关联条件 + * @param pager 分页对象 + * @return + */ + List query(Condition cnd, String linkName, Condition linkCnd, Pager pager); + + /** + * 分页查询 + * + * @param cnd 查询条件 + * @param pager 分页对象 + * @return + */ + List query(Condition cnd, Pager pager); + + + /** + * 更新 + * @param obj + * @return + */ + public int update(Object obj); + + /** + * 忽略值为null的字段 + * + * @param obj + * @return + */ + public int updateIgnoreNull(Object obj); + + /** + * 部分更新实体表 + * + * @param chain + * @param cnd + * @return + */ + public int update(Chain chain, Condition cnd); + /** + * 部分更新表 + * + * @param tableName + * @param chain + * @param cnd + * @return + */ + public int update(String tableName, Chain chain, Condition cnd); + + public int delete(long id); + + public int delete(int id); + + public int delete(String name); + + /** + * 批量删除 + * + * @param ids + */ + public void delete(Integer[] ids); + + /** + * 批量删除 + * + * @param ids + */ + public void delete(Long[] ids); + + /** + * 批量删除 + * + * @param ids + */ + public void delete(String[] ids); + + + /** + * 伪删除 + * + * @param id + * @return + */ + public int vDelete(String id); + + /** + * 批量伪删除 + * + * @param ids + * @return + */ + public int vDelete(String[] ids); + + + /** + * 分页查询 + * @param pageNumber + * @param pageSize + * @return + */ + public QueryResult listPage(int pageNumber, int pageSize); + + /** + * 分页查询 + * @param pageNumber + * @param pageSize + * @param cnd + * @return + */ + public QueryResult listPage(int pageNumber, int pageSize, Condition cnd); + + public QueryResult listPage(int pageNumber, int pageSize, Cnd cnd, String orderByColumn, String isAsc, String linkname); + + /** + * 分页查询数据封装 + * @param pageNumber + * @param pageSize + * @return + */ + public TableDataInfo tableList(int pageNumber, int pageSize); + + /** + * 分页查询数据封装 + * @param pageNumber + * @param pageSize + * @param cnd + * @return + */ + public TableDataInfo tableList(int pageNumber, int pageSize, Cnd cnd); + + /** + * 分页查询数据封装 查询关联数据 + * @param pageNumber + * @param pageSize + * @param cnd + * @param linkname + * @return + */ + public TableDataInfo tableList(int pageNumber, int pageSize, Cnd cnd, String orderByColumn, String isAsc, String linkname); + +} diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/service/BaseServiceImpl.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/service/BaseServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..6e0b488e05a9ba0f959cfe45a55608fe3cb1c8d4 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-common/src/main/java/io/nutz/nutzsite/common/service/BaseServiceImpl.java @@ -0,0 +1,472 @@ +package io.nutz.nutzsite.common.service; + +import io.nutz.nutzsite.common.page.TableDataInfo; +import org.nutz.dao.*; +import org.nutz.dao.entity.MappingField; +import org.nutz.dao.pager.Pager; +import org.nutz.dao.util.Daos; +import org.nutz.lang.Lang; +import org.nutz.lang.Strings; +import org.nutz.service.EntityService; + +import java.util.List; + +/** + * @author Hamming_Yu on 2018/12/31. + */ +public class BaseServiceImpl extends EntityService implements BaseService { + protected final static int DEFAULT_PAGE_NUMBER = 10; + + public BaseServiceImpl() { + super(); + } + + public BaseServiceImpl(Dao dao) { + super(dao); + } + + /** + * 统计符合条件的对象表条数 + * + * @param cnd + * @return + */ + @Override + public int count(Condition cnd) { + return this.dao().count(this.getEntityClass(), cnd); + } + + /** + * 统计对象表条数 + * + * @return + */ + @Override + public int count() { + return this.dao().count(this.getEntityClass()); + } + + /** + * 统计符合条件的记录条数 + * + * @param tableName + * @param cnd + * @return + */ + @Override + public int count(String tableName, Condition cnd) { + return this.dao().count(tableName, cnd); + } + + /** + * 统计表记录条数 + * + * @param tableName + * @return + */ + @Override + public int count(String tableName) { + return this.dao().count(tableName); + } + + @Override + public T fetch(long id) { + return this.dao().fetch(this.getEntityClass(), id); + } + + @Override + public T fetch(String name) { + return this.dao().fetch(this.getEntityClass(), name); + } + + @Override + public T fetchLinks(T t, String name) { + return this.dao().fetchLinks(t, name); + } + + @Override + public List fetchLinks(List t, String name) { + return this.dao().fetchLinks(t, name); + } + + @Override + public T fetchLinks(T t, String name, Condition cnd) { + return this.dao().fetchLinks(t, name, cnd); + } + + @Override + public T insert(T t) { + return this.dao().insert(t); + } + + @Override + public void insert(String tableName, Chain chain) { + this.dao().insert(tableName, chain); + } + + @Override + public T fastInsert(T t) { + return this.dao().fastInsert(t); + } + + + /** + * 查询获取部分字段 + * + * @param fieldName 支持通配符 ^(a|b)$ + * @param cnd + * @return + */ + @Override + public List query(String fieldName, Condition cnd) { + return Daos.ext(this.dao(), FieldFilter.create(this.getEntityClass(), fieldName)) + .query(this.getEntityClass(), cnd); + } + + /** + * 查询一组对象。你可以为这次查询设定条件 + * + * @param cnd WHERE 条件。如果为 null,将获取全部数据,顺序为数据库原生顺序
+ * 只有在调用这个函数的时候, cnd.limit 才会生效 + * @return 对象列表 + */ + @Override + public List query(Condition cnd) { + return dao().query(getEntityClass(), cnd); + } + + + /** + * 获取全部数据 + * + * @return + */ + @Override + public List query() { + return dao().query(getEntityClass(), null); + } + + + /** + * 获取表及关联表全部数据 + * + * @param cnd 查询条件 + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @return + */ + @Override + public List query(Condition cnd, String linkName) { + List list = this.dao().query(this.getEntityClass(), cnd); + if (!Strings.isBlank(linkName)) { + this.dao().fetchLinks(list, linkName); + } + return list; + } + + /** + * 获取表及关联表全部数据(支持子查询) + * + * @param cnd 查询条件 + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @param linkCnd 关联条件 + * @return + */ + @Override + public List query(Condition cnd, String linkName, Condition linkCnd) { + List list = this.dao().query(this.getEntityClass(), cnd); + if (!Strings.isBlank(linkName)) { + this.dao().fetchLinks(list, linkName, linkCnd); + } + return list; + } + + /** + * 获取表及关联表全部数据 + * + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @return + */ + @Override + public List query(String linkName) { + return this.query(null, linkName); + } + + + /** + * 分页关联字段查询 + * + * @param cnd 查询条件 + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @param pager 分页对象 + * @return + */ + @Override + public List query(Condition cnd, String linkName, Pager pager) { + List list = this.dao().query(this.getEntityClass(), cnd, pager); + if (!Strings.isBlank(linkName)) { + this.dao().fetchLinks(list, linkName); + } + return list; + } + + /** + * 分页关联字段查询(支持关联条件) + * + * @param cnd 查询条件 + * @param linkName 关联字段,支持正则 ^(a|b)$ + * @param linkCnd 关联条件 + * @param pager 分页对象 + * @return + */ + @Override + public List query(Condition cnd, String linkName, Condition linkCnd, Pager pager) { + List list = this.dao().query(this.getEntityClass(), cnd, pager); + if (!Strings.isBlank(linkName)) { + this.dao().fetchLinks(list, linkName, linkCnd); + } + return list; + } + + /** + * 分页查询 + * + * @param cnd 查询条件 + * @param pager 分页对象 + * @return + */ + @Override + public List query(Condition cnd, Pager pager) { + return dao().query(getEntityClass(), cnd, pager); + } + + /** + * 更新 + * @param obj + * @return + */ + @Override + public int update(Object obj) { + return this.dao().update(obj); + } + + /** + * 忽略值为null的字段 + * + * @param obj + * @return + */ + @Override + public int updateIgnoreNull(Object obj) { + return this.dao().updateIgnoreNull(obj); + } + + /** + * 部分更新实体表 + * + * @param chain + * @param cnd + * @return + */ + @Override + public int update(Chain chain, Condition cnd) { + return this.dao().update(this.getEntityClass(), chain, cnd); + } + + /** + * 部分更新表 + * + * @param tableName + * @param chain + * @param cnd + * @return + */ + @Override + public int update(String tableName, Chain chain, Condition cnd) { + return this.dao().update(tableName, chain, cnd); + } + + + @Override + public int delete(long id) { + return this.dao().delete(this.getEntityClass(), id); + } + + @Override + public int delete(int id) { + return this.dao().delete(this.getEntityClass(), id); + } + + @Override + public int delete(String name) { + return this.dao().delete(this.getEntityClass(), name); + } + + /** + * 批量删除 + * + * @param ids + */ + @Override + public void delete(Integer[] ids) { + this.dao().clear(getEntityClass(), Cnd.where("id", "in", ids)); + } + + /** + * 批量删除 + * + * @param ids + */ + @Override + public void delete(Long[] ids) { + this.dao().clear(getEntityClass(), Cnd.where("id", "in", ids)); + } + + /** + * 批量删除 + * + * @param ids + */ + @Override + public void delete(String[] ids) { + this.dao().clear(getEntityClass(), Cnd.where("id", "in", ids)); + } + + /** + * 伪删除 + * + * @param id + * @return + */ + @Override + public int vDelete(String id) { + return this.dao().update(this.getEntityClass(), Chain.make("delFlag", true), Cnd.where("id", "=", id)); + } + + /** + * 批量伪删除 + * + * @param ids + * @return + */ + @Override + public int vDelete(String[] ids) { + return this.dao().update(this.getEntityClass(), Chain.make("delFlag", true), Cnd.where("id", "in", ids)); + } + + /** + * 默认页码 + * + * @param pageNumber + * @return + */ + protected int getPageNumber(Integer pageNumber) { + return Lang.isEmpty(pageNumber) ? 1 : pageNumber; + } + + /** + * 默认页大小 + * + * @param pageSize + * @return + */ + protected int getPageSize(int pageSize) { + return pageSize == 0 ? DEFAULT_PAGE_NUMBER : pageSize; + } + + /** + * 分页查询 + * @param pageNumber + * @param pageSize + * @return + */ + @Override + public QueryResult listPage(int pageNumber, int pageSize){ + Pager pager = this.dao().createPager(pageNumber, pageSize); + List list = this.dao().query(this.getEntityClass(), null, pager); + pager.setRecordCount(this.dao().count(this.getEntityClass())); + return new QueryResult(list, pager); + } + + /** + * 分页查询 + * @param pageNumber + * @param pageSize + * @param cnd + * @return + */ + @Override + public QueryResult listPage(int pageNumber, int pageSize, Condition cnd){ + Pager pager = this.dao().createPager(pageNumber, pageSize); + List list = this.dao().query(this.getEntityClass(), cnd, pager); + pager.setRecordCount(this.dao().count(getEntityClass(), cnd)); + return new QueryResult(list, pager); + } + + @Override + public QueryResult listPage(int pageNumber, int pageSize, Cnd cnd, String orderByColumn, String isAsc, String linkname){ + Pager pager = this.dao().createPager(pageNumber, pageSize); + if (Strings.isNotBlank(orderByColumn) && Strings.isNotBlank(isAsc)) { + MappingField field =dao().getEntity(this.getEntityClass()).getField(orderByColumn); + if(Lang.isNotEmpty(field)){ + cnd.orderBy(field.getColumnName(),isAsc); + } + } + List list = this.dao().query(this.getEntityClass(), cnd, pager); + if (!Strings.isBlank(linkname)) { + this.dao().fetchLinks(list, linkname); + } + pager.setRecordCount(this.dao().count(getEntityClass(), cnd)); + return new QueryResult(list, pager); + } + + /** + * 分页查询数据封装 + * @param pageNumber + * @param pageSize + * @return + */ + @Override + public TableDataInfo tableList(int pageNumber, int pageSize){ + Pager pager = this.dao().createPager(pageNumber, pageSize); + List list = this.dao().query(this.getEntityClass(), null, pager); + return new TableDataInfo(list, this.dao().count(this.getEntityClass())); + } + + /** + * 分页查询数据封装 + * @param pageNumber + * @param pageSize + * @param cnd + * @return + */ + @Override + public TableDataInfo tableList(int pageNumber, int pageSize, Cnd cnd){ + Pager pager = this.dao().createPager(pageNumber, pageSize); + List list = this.dao().query(this.getEntityClass(), cnd, pager); + return new TableDataInfo(list, this.dao().count(this.getEntityClass(),cnd)); + } + + /** + * 分页查询数据封装 查询关联数据 + * @param pageNumber + * @param pageSize + * @param cnd + * @param linkname + * @return + */ + @Override + public TableDataInfo tableList(int pageNumber, int pageSize, Cnd cnd, String orderByColumn, String isAsc, String linkname){ + Pager pager = this.dao().createPager(pageNumber, pageSize); + if (Strings.isNotBlank(orderByColumn) && Strings.isNotBlank(isAsc)) { + MappingField field =dao().getEntity(this.getEntityClass()).getField(orderByColumn); + if(Lang.isNotEmpty(field)){ + cnd.orderBy(field.getColumnName(),isAsc); + } + } + List list = this.dao().query(this.getEntityClass(), cnd, pager); + if (!Strings.isBlank(linkname)) { + this.dao().fetchLinks(list, linkname); + } + return new TableDataInfo(list, this.dao().count(this.getEntityClass(),cnd)); + } +} diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/pom.xml b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/pom.xml index c39513cb490b2bda6bc84522a6c31354ee7fdca0..c7c67269fb10f9029aaa31e270d30d308de8c540 100644 --- a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/pom.xml +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/pom.xml @@ -25,6 +25,7 @@ nutzboot-demo-dubbo-common ${project.version}
+ org.nutz nutzboot-starter-dubbo @@ -48,6 +49,11 @@ log4j - + + org.nutz + nutzboot-demo-dubbo-rpc-service + 2.3.9-SNAPSHOT + compile + \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/src/main/java/io/nutz/demo/dubbo/rpc/DubboRpcTimeClientLauncher.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/src/main/java/io/nutz/demo/dubbo/rpc/DubboRpcTimeClientLauncher.java index 265dd37c38068442f900974b84231ebcee33b5a9..1482a22f39ed8764c5d4715c1e9640567eb1bcd2 100644 --- a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/src/main/java/io/nutz/demo/dubbo/rpc/DubboRpcTimeClientLauncher.java +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/src/main/java/io/nutz/demo/dubbo/rpc/DubboRpcTimeClientLauncher.java @@ -1,5 +1,6 @@ package io.nutz.demo.dubbo.rpc; +import io.nutz.nutzsite.module.sys.services.DictService; import org.nutz.boot.NbApp; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; @@ -16,6 +17,10 @@ public class DubboRpcTimeClientLauncher { @Inject @Reference protected TimeService timeService; + + @Inject + @Reference + protected DictService dictService; @Ok("raw") @At("/time/now") @@ -23,6 +28,12 @@ public class DubboRpcTimeClientLauncher { return timeService.now(); } + @Ok("json") + @At + public Object dict() { + return dictService.query(); + } + public static void main(String[] args) throws Exception { new NbApp().run(); } diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/src/main/resources/application.properties b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/src/main/resources/application.properties index 228e1a04698966c00f8f068a484b8a96dbaace29..53b3e77b2a4ebab1d2773fa22ced42b496839b4c 100644 --- a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/src/main/resources/application.properties +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/src/main/resources/application.properties @@ -1,7 +1,22 @@ -server.port=8080 +jetty.port=8080 +server.port=0 server.host=0.0.0.0 dubbo.application.name=dubbo-rpc-client dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.protocol.name=dubbo -dubbo.application.qos.enable=false \ No newline at end of file +dubbo.application.qos.enable=false + +jdbc.url=jdbc:h2:mem:~ + +#jdbc.type=druid +#jdbc.url=jdbc:mysql://127.0.0.1:3306/nutzsite?useUnicode=true&allowPublicKeyRetrieval=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai +#jdbc.username=root +##jdbc.password=gptrbrt5683RR +#jdbc.password=ikmcy2O1904 +#jdbc.validationQuery=select 1 +#jdbc.maxActive=50 +#jdbc.testWhileIdle=true +#jdbc.filters=mergeStat +#jdbc.connectionProperties=druid.stat.slowSqlMillis=2000 +#jdbc.defaultAutoCommit=true \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/pom.xml b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/pom.xml index 02a2d4b9abe6bc4726ba06c3d26440034b6297cb..f7685f24076a2b7f4bfa3e36deac756435084eb0 100644 --- a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/pom.xml +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/pom.xml @@ -22,6 +22,10 @@ nutzboot-demo-dubbo-common ${project.version} + + org.nutz + nutzboot-starter-nutz-dao + io.netty netty-all diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/demo/dubbo/rpc/DubboRpcTimeServiceLauncher.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/DubboRpcTimeServiceLauncher.java similarity index 37% rename from nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/demo/dubbo/rpc/DubboRpcTimeServiceLauncher.java rename to nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/DubboRpcTimeServiceLauncher.java index 8bdbae5eb6cdec157e49017901af08ad058ed4c0..27b0a2a9f3900948dba9e348fb90d5aea1ef3074 100644 --- a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/demo/dubbo/rpc/DubboRpcTimeServiceLauncher.java +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/DubboRpcTimeServiceLauncher.java @@ -1,13 +1,26 @@ -package io.nutz.demo.dubbo.rpc; +package io.nutz; import org.nutz.boot.NbApp; +import org.nutz.dao.Dao; +import org.nutz.dao.util.Daos; +import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; -@IocBean +@IocBean(create = "init", depose = "depose") public class DubboRpcTimeServiceLauncher { + @Inject + private Dao dao; public static void main(String[] args) throws Exception { new NbApp().run(); } + public void init() { + // 创建数据库 + Daos.createTablesInPackage(dao, "io.nutz.nutzsite", false); + } + + public void depose() { + + } } diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/common/base/BaseModel.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/common/base/BaseModel.java new file mode 100644 index 0000000000000000000000000000000000000000..ab571aa6c272dc34f34278757bf8b694cd380d4d --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/common/base/BaseModel.java @@ -0,0 +1,87 @@ +package io.nutz.nutzsite.common.base; + + +import org.nutz.dao.entity.annotation.*; +import org.nutz.lang.random.R; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author Hamming_Yu on 2018/12/29. + */ +public abstract class BaseModel implements Serializable { + private static final long serialVersionUID = 1L; + + @Column("create_by") + @Comment("创建者") + @Prev(els = @EL("$me.uid()")) + @ColDefine(type = ColType.VARCHAR, width = 32) + protected String createBy; + + @Column("create_time") + @Prev(els = {@EL("$me.now()")}) + protected Date createTime; + + @Column("update_by") + @Comment("更新者") + @Prev(els = @EL("$me.uid()")) + @ColDefine(type = ColType.VARCHAR, width = 32) + protected String updateBy; + + @Prev(els=@EL("$me.now()")) + @Column("update_time") + protected Date updateTime; + + public String uuid() { + return R.UU32().toLowerCase(); + } + + public String uid() { + try { +// Subject subject = SecurityUtils.getSubject(); +// User user = (User) subject.getPrincipal(); +// return user == null ? "" : user.getId(); + return ""; + } catch (Exception e) { + return ""; + } + } + + public Date now() { + return new Date(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public String getCreateBy() { + return createBy; + } + + public void setCreateBy(String createBy) { + this.createBy = createBy; + } + + public String getUpdateBy() { + return updateBy; + } + + public void setUpdateBy(String updateBy) { + this.updateBy = updateBy; + } + +} diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/models/Dict.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/models/Dict.java new file mode 100755 index 0000000000000000000000000000000000000000..04cba3b88ca7ff66254dfd49dfcaa021eb064214 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/models/Dict.java @@ -0,0 +1,240 @@ +package io.nutz.nutzsite.module.sys.models; + +import io.nutz.nutzsite.common.base.BaseModel; +import org.nutz.dao.entity.annotation.*; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * 字典表 sys_dict + * + * @author haiming + * @date 2019-04-16 + */ +@Table("sys_dict") +public class Dict extends BaseModel implements Serializable { + private static final long serialVersionUID = 1L; + + @Name + @Column("id") + @Comment("编号 ") + @ColDefine(type = ColType.VARCHAR, width = 64) + @Prev(els = {@EL("uuid()")}) + private String id; + + /** + * 数据值 + */ + @Column("value") + @Comment("数据值 ") + private String value; + /** + * 标签名 + */ + @Column("label") + @Comment("标签名 ") + private String label; + /** + * 类型 + */ + @Column("type") + @Comment("类型 ") + private String type; + /** + * 描述 + */ + @Column("description") + @Comment("描述 ") + private String description; + /** + * 排序(升序) + */ + @Column("sort") + @Comment("排序(升序) ") + private BigDecimal sort; + /** + * 父级编号 + */ + @Column("parent_id") + @Comment("父级编号 ") + private String parentId; + + /** + * 备注信息 + */ + @Column("remarks") + @Comment("备注信息 ") + private String remarks; + /** + * 删除标记 + */ + @Column("del_flag") + @Comment("删除标记 ") + private boolean delFlag; + + /** + * 创建者 + */ + @Column("create_by") + @Comment("创建者 ") + @Prev(els = @EL("$me.uid()")) + private String createBy; + + /** + * 创建时间 + */ + @Column("create_time") + @Comment("创建时间 ") + @Prev(els = {@EL("$me.now()")}) + private Date createTime; + + /** + * 更新者 + */ + @Column("update_by") + @Comment("更新者 ") + @Prev(els = @EL("$me.uid()")) + private String updateBy; + + /** + * 更新时间 + */ + @Column("update_time") + @Comment("更新时间 ") + @Prev(els = {@EL("$me.now()")}) + private Date updateTime; + + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setValue(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + + public void setSort(BigDecimal sort) { + this.sort = sort; + } + + public BigDecimal getSort() { + return sort; + } + + public void setParentId(String parentId) { + this.parentId = parentId; + } + + public String getParentId() { + return parentId; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public String getRemarks() { + return remarks; + } + + public boolean isDelFlag() { + return delFlag; + } + + public void setDelFlag(boolean delFlag) { + this.delFlag = delFlag; + } + + @Override + public String getCreateBy() { + return createBy; + } + + @Override + public void setCreateBy(String createBy) { + this.createBy = createBy; + } + + @Override + public Date getCreateTime() { + return createTime; + } + + @Override + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + @Override + public String getUpdateBy() { + return updateBy; + } + + @Override + public void setUpdateBy(String updateBy) { + this.updateBy = updateBy; + } + + @Override + public Date getUpdateTime() { + return updateTime; + } + + @Override + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + @Override + public String toString() { + return "Dict{" + + "id='" + id + '\'' + + ", value='" + value + '\'' + + ", label='" + label + '\'' + + ", type='" + type + '\'' + + ", description='" + description + '\'' + + ", sort=" + sort + + ", parentId='" + parentId + '\'' + + ", remarks='" + remarks + '\'' + + ", delFlag=" + delFlag + + ", createBy='" + createBy + '\'' + + ", createTime=" + createTime + + ", updateBy='" + updateBy + '\'' + + ", updateTime=" + updateTime + + '}'; + } +} diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/services/DictService.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/services/DictService.java new file mode 100644 index 0000000000000000000000000000000000000000..82de33f58035ccd8ee1213887db5298ccc55b173 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/services/DictService.java @@ -0,0 +1,13 @@ +package io.nutz.nutzsite.module.sys.services; + +import io.nutz.nutzsite.common.service.BaseService; +import io.nutz.nutzsite.module.sys.models.Dict; + +/** + * @Author: Haimming + * @Date: 2019-10-18 17:53 + * @Version 1.0 + */ +public interface DictService extends BaseService { + +} diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/services/impl/DictServiceImpl.java b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/services/impl/DictServiceImpl.java new file mode 100755 index 0000000000000000000000000000000000000000..f3a48a6a96f239ec52da54ba62ffaaf90afff8e1 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/java/io/nutz/nutzsite/module/sys/services/impl/DictServiceImpl.java @@ -0,0 +1,23 @@ +package io.nutz.nutzsite.module.sys.services.impl; + +import com.alibaba.dubbo.config.annotation.Service; +import io.nutz.nutzsite.common.service.BaseServiceImpl; +import io.nutz.nutzsite.module.sys.models.Dict; +import io.nutz.nutzsite.module.sys.services.DictService; +import org.nutz.dao.Dao; +import org.nutz.ioc.loader.annotation.IocBean; + +/** + * 字典 服务层实现 + * + * @author haiming + * @date 2019-04-16 + */ +@IocBean(args = {"refer:dao"}) +@Service(interfaceClass = DictService.class) +public class DictServiceImpl extends BaseServiceImpl implements DictService { + public DictServiceImpl(Dao dao) { + super(dao); + } + +} diff --git a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/resources/application.properties b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/resources/application.properties index 2639544ee198f4559ad087e0b563c969f3665663..2141cd2c36764e47e97f41852c503c5936d0c69f 100644 --- a/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/resources/application.properties +++ b/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-service/src/main/resources/application.properties @@ -1,6 +1,21 @@ server.port=0 +server.host=0.0.0.0 dubbo.application.name=dubbo-rpc-service dubbo.registry.address=zookeeper://127.0.0.1:2181 dubbo.protocol.name=dubbo -dubbo.application.qos.enable=false \ No newline at end of file +dubbo.application.qos.enable=false + +jdbc.url=jdbc:h2:mem:~ + +#jdbc.type=druid +#jdbc.url=jdbc:mysql://127.0.0.1:3306/nutzsite?useUnicode=true&allowPublicKeyRetrieval=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai +#jdbc.username=root +##jdbc.password=gptrbrt5683RR +#jdbc.password=ikmcy2O1904 +#jdbc.validationQuery=select 1 +#jdbc.maxActive=50 +#jdbc.testWhileIdle=true +#jdbc.filters=mergeStat +#jdbc.connectionProperties=druid.stat.slowSqlMillis=2000 +#jdbc.defaultAutoCommit=true \ No newline at end of file diff --git a/pom.xml b/pom.xml index d875e80ae5eef5965b450c998babd91a447985a2..38c59138716f0a0954a7b53f10b59248120ed6c9 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 1.5.0 9.4.22.v20191022 8.5.46 - 1.3.2 + 1.4.2 2.1.8 3.1.15 4.3.21.RELEASE