diff --git a/biz/pom.xml b/biz/pom.xml index 451da6bc5972c3b4d7dcb069deb56a4aca79a2f9..cda891e6b791fa1f211277b1340ec013a9ae0b0b 100644 --- a/biz/pom.xml +++ b/biz/pom.xml @@ -22,5 +22,30 @@ bic-dal ${parent.version} + + org.mapstruct + mapstruct + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + + + + + + \ No newline at end of file diff --git a/biz/src/main/java/cn/loopstack/bic/biz/mapper/BaseMapper.java b/biz/src/main/java/cn/loopstack/bic/biz/mapper/BaseMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..6a5dd9f77fb9102dc9c64689c61b9227413cfc98 --- /dev/null +++ b/biz/src/main/java/cn/loopstack/bic/biz/mapper/BaseMapper.java @@ -0,0 +1,19 @@ +package cn.loopstack.bic.biz.mapper; + +import java.util.Collection; +import java.util.List; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 18:15 + */ +public interface BaseMapper { + + R do2vo(T t); + + List dos2vos(Collection ts); + + T vo2do(R r); + + List vos2dos(List rs); +} diff --git a/biz/src/main/java/cn/loopstack/bic/biz/mapper/BuryingMapper.java b/biz/src/main/java/cn/loopstack/bic/biz/mapper/BuryingMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..0df58944fd959b2c909457ef2467b7703756ae7d --- /dev/null +++ b/biz/src/main/java/cn/loopstack/bic/biz/mapper/BuryingMapper.java @@ -0,0 +1,15 @@ +package cn.loopstack.bic.biz.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.NullValueMappingStrategy; + +import cn.loopstack.bic.common.model.BuryingVO; +import cn.loopstack.bic.dal.mongo.dateobject.BuryingDO; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 18:15 + */ +@Mapper(componentModel = "spring", uses = {}, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL) +public interface BuryingMapper extends BaseMapper { +} diff --git a/biz/src/main/java/cn/loopstack/bic/biz/service/BuryingService.java b/biz/src/main/java/cn/loopstack/bic/biz/service/BuryingService.java index 5035c7aff2fb92af4936d380f9976decdf5f1926..f24d6306163c453eb7d38bca009585f5701d4fae 100644 --- a/biz/src/main/java/cn/loopstack/bic/biz/service/BuryingService.java +++ b/biz/src/main/java/cn/loopstack/bic/biz/service/BuryingService.java @@ -1,9 +1,25 @@ package cn.loopstack.bic.biz.service; +import java.util.List; + +import cn.loopstack.bic.common.model.BuryingVO; + /** * @author icanci * @since 1.0 Created in 2023/08/19 15:40 */ public interface BuryingService { + /** + * 批量插入 + * + * @param buryingList buryingList + */ + void batchInsert(List buryingList); + /** + * 查询所有数据 + * + * @return 返回所有数据 + */ + List queryAll(); } diff --git a/biz/src/main/java/cn/loopstack/bic/biz/service/BuryingServiceImpl.java b/biz/src/main/java/cn/loopstack/bic/biz/service/BuryingServiceImpl.java deleted file mode 100644 index 4ef88406df628f9a5ad45401b97d52a2070401b3..0000000000000000000000000000000000000000 --- a/biz/src/main/java/cn/loopstack/bic/biz/service/BuryingServiceImpl.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.loopstack.bic.biz.service; - -import org.springframework.stereotype.Service; - -/** - * @author icanci - * @since 1.0 Created in 2023/08/19 15:40 - */ -@Service -public class BuryingServiceImpl implements BuryingService { - -} diff --git a/biz/src/main/java/cn/loopstack/bic/biz/service/impl/BuryingServiceImpl.java b/biz/src/main/java/cn/loopstack/bic/biz/service/impl/BuryingServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..4f870ebf44289ba6101eb93a42f75173b5e21acc --- /dev/null +++ b/biz/src/main/java/cn/loopstack/bic/biz/service/impl/BuryingServiceImpl.java @@ -0,0 +1,38 @@ +package cn.loopstack.bic.biz.service.impl; + +import java.util.List; + +import javax.annotation.Resource; + +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; + +import cn.loopstack.bic.biz.mapper.BuryingMapper; +import cn.loopstack.bic.biz.service.BuryingService; +import cn.loopstack.bic.common.model.BuryingVO; +import cn.loopstack.bic.dal.mongo.daointerface.BuryingDAO; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 15:40 + */ +@Service +public class BuryingServiceImpl implements BuryingService { + @Resource + private BuryingDAO buryingDAO; + @Resource + private BuryingMapper buryingMapper; + + @Override + public void batchInsert(List buryingList) { + if (CollectionUtils.isEmpty(buryingList)) { + return; + } + buryingDAO.batchInsert(buryingMapper.vos2dos(buryingList)); + } + + @Override + public List queryAll() { + return buryingMapper.dos2vos(buryingDAO.queryAll()); + } +} diff --git a/common/src/main/java/cn/loopstack/bic/common/result/R.java b/common/src/main/java/cn/loopstack/bic/common/result/R.java new file mode 100644 index 0000000000000000000000000000000000000000..005cb70d98b4f82d725918766757e2704194bd60 --- /dev/null +++ b/common/src/main/java/cn/loopstack/bic/common/result/R.java @@ -0,0 +1,154 @@ +package cn.loopstack.bic.common.result; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import java.util.StringJoiner; + +/** + * 通用返回结果 + * + * @author icanci + * @since 1.0 Created in 2022/04/04 19:11 + */ +public class R implements Serializable { + private static final long serialVersionUID = -1343013883236338104L; + /** 是否成功 */ + private boolean ok; + /** 错误码 */ + private int code; + /** 错误信息 */ + private String message; + /** 返回前端数据 */ + private Map data = new HashMap<>(); + + public R() { + } + + /** + * Builder + * + * @return Builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * BuilderOK + * + * @return Builder + */ + public static Builder builderOk() { + return new Builder().BuilderOK(); + } + + /** + * BuilderFail + * + * @return Builder + */ + public static Builder builderFail() { + return new Builder().BuilderFail(); + } + + public static class Builder { + /** 是否成功 */ + private boolean ok; + /** 错误码 */ + private int code; + /** 错误信息 */ + private String message; + /** 返回前端数据 */ + private Map data = new HashMap(); + + private Builder() { + + } + + public Builder(boolean ok, int code) { + this.ok = ok; + this.code = code; + } + + private Builder BuilderOK() { + this.ok = true; + this.code = ResultCodes.SUCCESS; + return this; + } + + private Builder BuilderFail() { + this.ok = false; + this.code = ResultCodes.FAIL_SYSTEM; + return this; + } + + public Builder message(String val) { + message = val; + return this; + } + + public Builder code(Integer val) { + code = val; + return this; + } + + public Builder data(String key, Object value) { + data.put(key, value); + return this; + } + + public Builder data(Map map) { + data = map; + return this; + } + + public R build() { + return new R(this); + } + } + + private R(Builder builder) { + this.ok = builder.ok; + this.code = builder.code; + this.message = builder.message; + this.data = builder.data; + } + + public boolean isOk() { + return ok; + } + + public void setOk(boolean ok) { + this.ok = ok; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Map getData() { + return data; + } + + public void setData(Map data) { + this.data = data; + } + + @Override + public String toString() { + return new StringJoiner(",").add("ok=" + ok).add("code=" + code).add("message=" + message).add("data=" + data).toString(); + } +} diff --git a/common/src/main/java/cn/loopstack/bic/common/result/ResultCodes.java b/common/src/main/java/cn/loopstack/bic/common/result/ResultCodes.java new file mode 100644 index 0000000000000000000000000000000000000000..ec01ffd35b016b83069c4c754db4510408fbe0d6 --- /dev/null +++ b/common/src/main/java/cn/loopstack/bic/common/result/ResultCodes.java @@ -0,0 +1,22 @@ +package cn.loopstack.bic.common.result; + +/** + * code集合 + * + * @author icanci + * @since 1.0 Created in 2022/04/04 20:09 + */ +public interface ResultCodes { + /** 成功 */ + int SUCCESS = 200; + /** 400异常 */ + int FAIL_404 = 404; + /** 500异常 */ + int FAIL_500 = 500; + /** 账号异常 */ + int ACCOUNT_ERROR_CODE = 1000; + /** 账号登录超时 */ + int LOGIN_TIME_OUT = 1001; + /** 默认失败原因 */ + int FAIL_SYSTEM = 9999; +} diff --git a/common/src/main/java/cn/loopstack/bic/common/result/ResultMessages.java b/common/src/main/java/cn/loopstack/bic/common/result/ResultMessages.java new file mode 100644 index 0000000000000000000000000000000000000000..37fe3588db7e7458f7d8f7a6cf5a5c9b2a460b27 --- /dev/null +++ b/common/src/main/java/cn/loopstack/bic/common/result/ResultMessages.java @@ -0,0 +1,11 @@ +package cn.loopstack.bic.common.result; + +/** + * message集合 + * + * @author icanci + * @since 1.0 Created in 2022/04/04 20:09 + */ +public interface ResultMessages { + String ACCOUNT_ERROR_MESSAGE = "账号%s异常,请重新登录"; +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/common/PageList.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/common/PageList.java new file mode 100644 index 0000000000000000000000000000000000000000..8a5f9170a4fc9b719de69d807ddc28db748c1713 --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/common/PageList.java @@ -0,0 +1,84 @@ +package cn.loopstack.bic.dal.mongo.common; + +import java.io.Serializable; +import java.util.Collection; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 17:51 + */ +public class PageList implements Serializable { + /** */ + private static final long serialVersionUID = 1L; + + /** 分页器 */ + private Paginator paginator; + + /** 数据集 */ + private Collection data; + + /** + * 默认构造函数 + */ + public PageList() { + paginator = new Paginator(); + } + + /** + * 构造函数 + * + * @param data 数据集 + */ + public PageList(Collection data) { + this.data = data; + } + + /** + * 构造函数 + * + * @param data 数据集 + * @param paginator 分页器 + */ + public PageList(Collection data, Paginator paginator) { + this.data = data; + this.paginator = (paginator == null) ? new Paginator() : paginator; + } + + /** + * 获取分页器 + * + * @return 分页器 + */ + public Paginator getPaginator() { + return paginator; + } + + /** + * 设置分页器 + * + * @param paginator 分页器 + */ + public void setPaginator(Paginator paginator) { + if (paginator != null) { + this.paginator = paginator; + } + } + + /** + * 获取数据集 + * + * @return 数据集 + */ + public Collection getData() { + return data; + } + + /** + * 集数据 + * + * @param data 数据 + */ + public void setData(Collection data) { + this.data = data; + } +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/common/Paginator.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/common/Paginator.java new file mode 100644 index 0000000000000000000000000000000000000000..0eae499bbc4ddbdf558612032254d3f008b23474 --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/common/Paginator.java @@ -0,0 +1,194 @@ +package cn.loopstack.bic.dal.mongo.common; + +import java.io.Serializable; + +/** + * @author icanci + * @since 1.0 Created in 2022/10/24 22:42 + */ +public class Paginator implements Serializable { + + /** */ + private static final long serialVersionUID = 1L; + + /** 默认每页数据条目20 */ + private static final int DEFAULT_PAGE_SIZE = 20; + + /** 数据总量 */ + private int totalCount; + + /** 总页数 */ + private int totalPage; + + /** 每页条目数 */ + private int pageSize = DEFAULT_PAGE_SIZE; + + /** 查询起始条目编号,默认从0开始 */ + private int startIndex; + + /** 当前页页码 */ + private int currentPage; + + /** 上一页页码 */ + private int nextPage; + + /** 下一页页码 */ + private int priviousPage; + + /** + * 默认构造函数 + */ + protected Paginator() { + super(); + } + + /** + * 构造函数 + * + * @param totalCount 数据总条目数 + * @param pageSize 每页条目数 + * @param currentPage 当前页码 + */ + protected Paginator(int totalCount, int pageSize, int currentPage) { + this.totalCount = totalCount; + this.pageSize = pageSize; + this.currentPage = currentPage; + } + + /** + * 获取数据总条目数 + * + * @return 数据总条目数 + */ + public int getTotalCount() { + return totalCount; + } + + /** + * 设置数据总条目数 + * + * @param totalCount 数据总条目数 + */ + public void setTotalCount(int totalCount) { + this.totalCount = totalCount; + } + + /** + * 获取每页数据条目数 + * + * @return 每页数据条目数 + */ + public int getPageSize() { + if (pageSize <= 0) { + pageSize = DEFAULT_PAGE_SIZE; + } + return pageSize; + } + + /** + * 设置每页条目数 + * + * @param pageSize 每页条目数 + */ + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + /** + * 获取当前页码 + * + * @return 当前页面 + */ + public int getCurrentPage() { + if (currentPage <= 0) { + return 1; + } else if (currentPage > getTotalPage()) { + return getTotalPage(); + } + return currentPage; + } + + /** + * 设置当前页码 + * + * @param currentPage 当前页码 + */ + public void setCurrentPage(int currentPage) { + this.currentPage = currentPage; + } + + /** + * 获取总页数 + * + * @return 总页数 + */ + public int getTotalPage() { + if (totalCount > 0) { + if (getPageSize() > 0) { + totalPage = totalCount / getPageSize(); + if ((totalCount % getPageSize()) > 0) { + totalPage++; + } + } else { + totalPage = 1; + } + } else { + totalPage = 0; + } + return totalPage; + } + + /** + * 获取查询起始条目编号 + * + * @return 查询起始条目编号 + */ + public int getStartIndex() { + if (getCurrentPage() > 0) { + if (getPageSize() > 0) { + startIndex = (getCurrentPage() - 1) * getPageSize(); + } else { + startIndex = 0; + } + } else { + startIndex = 0; + } + return startIndex; + } + + /** + * 获取下一页页码 + * + * @return 下一页页码 + */ + public int getNextPage() { + if (getCurrentPage() >= getTotalPage()) { + nextPage = getTotalPage(); + } else { + if (getTotalPage() == 0) { + nextPage = 1; + } else { + nextPage = getCurrentPage() + 1; + } + + } + return nextPage; + } + + /** + * 获取上一页页码 + * + * @return 上一页页码 + */ + public int getPriviousPage() { + if (getCurrentPage() <= 1) { + priviousPage = 1; + } else if (getCurrentPage() > getTotalPage()) { + priviousPage = getTotalPage() - 1; + } else { + priviousPage = getCurrentPage() - 1; + } + return priviousPage; + } + +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/daointerface/BaseDAO.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/daointerface/BaseDAO.java new file mode 100644 index 0000000000000000000000000000000000000000..a03b6a3da61a140c7eeee8b646238dd2c35605fe --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/daointerface/BaseDAO.java @@ -0,0 +1,71 @@ +package cn.loopstack.bic.dal.mongo.daointerface; + +import java.util.List; + +import cn.loopstack.bic.dal.mongo.common.PageList; +import cn.loopstack.bic.dal.mongo.dateobject.BaseDO; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 17:53 + */ +public interface BaseDAO { + + /** 文档对应的名字 */ + String BASE_COLLECTION_NAME = "bic-"; + + /** + * 插入文档一条记录 + * + * @param t t + */ + void insert(T t); + + /** + * 更新文档一条记录 + * + * @param t t + */ + void update(T t); + + /** + * 查询文档所有记录 + * + * @return 返回查询的结果 + */ + List queryAll(); + + /** + * 查询文档所有记录 + * + * @param t 请求参数 + * @param pageNum pageNum + * @param pageSize pageSize + * @return 返回查询的结果 + */ + PageList pageQuery(T t, int pageNum, int pageSize); + + /** + * 根据 _id 查询一条信息 + * + * @param _id _id + * @return 返回查询的结果 + */ + T queryOneById(String _id); + + /** 基本表 */ + interface BaseColumn { + /** 文档id */ + String _ID = "_id"; + /** uuid */ + String UUID = "uuid"; + /** createTime */ + String CREATE_TIME = "createTime"; + /** updateTime */ + String UPDATE_TIME = "updateTime"; + /** 状态,是否删除 */ + String DELETED = "deleted"; + /** 操作环境 */ + String ENV = "env"; + } +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/daointerface/BuryingDAO.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/daointerface/BuryingDAO.java new file mode 100644 index 0000000000000000000000000000000000000000..fdf41c5e3eaee06d93b050d77582b145f8af656f --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/daointerface/BuryingDAO.java @@ -0,0 +1,40 @@ +package cn.loopstack.bic.dal.mongo.daointerface; + +import java.util.List; + +import cn.loopstack.bic.dal.mongo.dateobject.BuryingDO; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 17:55 + */ +public interface BuryingDAO extends BaseDAO { + /** 文档对应的名字 */ + String COLLECTION_NAME = BASE_COLLECTION_NAME + "burying"; + /** 文档对应的Class */ + Class COLLECTION_CLASS = BuryingDO.class; + + /** + * 批量插入 + * + * @param buryingList buryingList + */ + void batchInsert(List buryingList); + + /** 列 */ + interface BuryingColumn extends BaseColumn { + /** TraceId */ + String TRACE_ID = "traceId"; + /** 业务标识 */ + String BUSINESS_NO = "businessNo"; + /** 系统应用唯一标识 */ + String SYSTEM_KEY = "systemKey"; + /** 模块 */ + String MODULE = "module"; + /** 时间 */ + String TIME = "time"; + /** 执行数据 */ + String MESSAGE = "message"; + } + +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/dateobject/BaseDO.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/dateobject/BaseDO.java new file mode 100644 index 0000000000000000000000000000000000000000..d0d34e7ad93845c1c5589cff1859e80f3fdf00f8 --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/dateobject/BaseDO.java @@ -0,0 +1,84 @@ +package cn.loopstack.bic.dal.mongo.dateobject; + +import java.util.Date; +import java.util.StringJoiner; + +import org.springframework.data.annotation.Id; + +import com.fasterxml.jackson.annotation.JsonFormat; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 17:52 + */ +public class BaseDO { + /** mongodb id */ + @Id + private String id; + /** 雪花算法随机UUID */ + private String uuid; + /** 创建时间 */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + /** 更新时间 */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + private Date updateTime; + /** 状态 false 有效,true 无效 */ + private boolean deleted; + /** 环境 */ + private String env; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + 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 boolean isDeleted() { + return deleted; + } + + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + public String getEnv() { + return env; + } + + public void setEnv(String env) { + this.env = env; + } + + @Override + public String toString() { + return new StringJoiner(",").add("id=" + id).add("uuid=" + uuid).add("createTime=" + createTime).add("updateTime=" + updateTime).add("deleted=" + deleted).add("env=" + env) + .toString(); + } +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/dateobject/BuryingDO.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/dateobject/BuryingDO.java new file mode 100644 index 0000000000000000000000000000000000000000..7d1973f951e7f94b312e892adab71d0f990a15a9 --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/dateobject/BuryingDO.java @@ -0,0 +1,76 @@ +package cn.loopstack.bic.dal.mongo.dateobject; + +import java.util.StringJoiner; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 17:52 + */ +public class BuryingDO extends BaseDO { + /** TraceId */ + private String traceId; + /** 业务标识 */ + private String businessNo; + /** 系统应用唯一标识 */ + private String systemKey; + /** 模块 */ + private String module; + /** 时间 */ + private long time; + /** 执行数据 */ + private String message; + + public String getTraceId() { + return traceId; + } + + public void setTraceId(String traceId) { + this.traceId = traceId; + } + + public String getBusinessNo() { + return businessNo; + } + + public void setBusinessNo(String businessNo) { + this.businessNo = businessNo; + } + + public String getSystemKey() { + return systemKey; + } + + public void setSystemKey(String systemKey) { + this.systemKey = systemKey; + } + + public String getModule() { + return module; + } + + public void setModule(String module) { + this.module = module; + } + + public long getTime() { + return time; + } + + public void setTime(long time) { + this.time = time; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return new StringJoiner(",").add("traceId=" + traceId).add("businessNo=" + businessNo).add("systemKey=" + systemKey).add("module=" + module).add("time=" + time) + .add("message=" + message).toString(); + } +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/AbstractBaseDAO.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/AbstractBaseDAO.java new file mode 100644 index 0000000000000000000000000000000000000000..1babd22ddc8bb8e49ebb9fb38517b0ea56647140 --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/AbstractBaseDAO.java @@ -0,0 +1,50 @@ +package cn.loopstack.bic.dal.mongo.mongo; + +import java.util.Date; +import java.util.List; + +import org.springframework.beans.factory.InitializingBean; + +import cn.loopstack.bic.dal.mongo.daointerface.BaseDAO; +import cn.loopstack.bic.dal.mongo.dateobject.BaseDO; +import cn.loopstack.bic.dal.mongo.utils.EnvUtils; +import cn.loopstack.bic.dal.mongo.utils.IDHolder; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 18:00 + */ +public abstract class AbstractBaseDAO extends MongoPageHelper implements BaseDAO, InitializingBean { + + protected String DEFAULT_ENV; + + @Override + public void insert(T t) { + // 处理插入数据 + doInsert(t); + } + + @Override + public void update(T t) { + t.setUpdateTime(new Date()); + } + + @Override + public void afterPropertiesSet() throws Exception { + DEFAULT_ENV = EnvUtils.getEnv(); + } + + public void batchInsert(List list) { + // 处理插入数据 + list.forEach(this::doInsert); + } + + private void doInsert(T t) { + t.setId(null); + t.setDeleted(false); + t.setCreateTime(new Date()); + t.setUpdateTime(new Date()); + t.setEnv(DEFAULT_ENV); + t.setUuid(IDHolder.generateNoBySnowFlakeDefaultPrefix()); + } +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/MongoBuryingDAO.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/MongoBuryingDAO.java new file mode 100644 index 0000000000000000000000000000000000000000..1426a197a003826d99544491f44245f9ffe52fea --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/MongoBuryingDAO.java @@ -0,0 +1,66 @@ +package cn.loopstack.bic.dal.mongo.mongo; + +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.data.domain.Sort; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Service; + +import cn.loopstack.bic.dal.mongo.common.PageList; +import cn.loopstack.bic.dal.mongo.daointerface.BuryingDAO; +import cn.loopstack.bic.dal.mongo.dateobject.BuryingDO; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 18:00 + */ +@Service("buryingDAO") +public class MongoBuryingDAO extends AbstractBaseDAO implements BuryingDAO { + + @Override + public void insert(BuryingDO burying) { + super.insert(burying); + mongoTemplate.insert(burying, COLLECTION_NAME); + } + + @Override + public void update(BuryingDO burying) { + super.update(burying); + mongoTemplate.save(burying, COLLECTION_NAME); + } + + @Override + public List queryAll() { + Criteria criteria = Criteria.where(BuryingColumn.ENV).is(DEFAULT_ENV); + Query query = new Query(criteria); + return mongoTemplate.find(query, COLLECTION_CLASS, COLLECTION_NAME); + } + + @Override + public PageList pageQuery(BuryingDO burying, int pageNum, int pageSize) { + Criteria criteria = Criteria.where(BuryingColumn.ENV).is(DEFAULT_ENV); + if (StringUtils.isNotBlank(burying.getSystemKey())) { + // 不分区大小写查询,其中操作符"i":表示不分区大小写 + criteria.and(BuryingColumn.SYSTEM_KEY).regex("^.*" + burying.getSystemKey() + ".*$", "i"); + } + Query query = new Query(criteria); + query.with(Sort.by(Sort.Direction.DESC, BuryingColumn.CREATE_TIME)); + return pageQuery(query, COLLECTION_CLASS, pageSize, pageNum, COLLECTION_NAME); + } + + @Override + public BuryingDO queryOneById(String _id) { + Criteria criteria = Criteria.where(BuryingColumn._ID).is(_id); + criteria.and(BuryingColumn.ENV).is(DEFAULT_ENV); + Query query = new Query(criteria); + return mongoTemplate.findOne(query, COLLECTION_CLASS, COLLECTION_NAME); + } + + @Override + public void batchInsert(List buryingList) { + super.batchInsert(buryingList); + mongoTemplate.insert(buryingList, COLLECTION_NAME); + } +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/MongoPageHelper.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/MongoPageHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..ea0ba086034456a7655867928ea2af9ee394dbd9 --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/mongo/MongoPageHelper.java @@ -0,0 +1,114 @@ +package cn.loopstack.bic.dal.mongo.mongo; + +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +import javax.annotation.Resource; + +import org.apache.commons.lang3.StringUtils; +import org.bson.types.ObjectId; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Order; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; + +import com.google.common.collect.Lists; + +import cn.loopstack.bic.dal.mongo.common.PageList; +import cn.loopstack.bic.dal.mongo.common.Paginator; + +/** + * 分页插件 + * + * @author icanci(1205068) + * @version Id: MongoPageHelper, v 0.1 2022/10/24 16:44 icanci Exp $ + */ +public class MongoPageHelper { + @Resource + protected MongoTemplate mongoTemplate; + + public static final int FIRST_PAGE_NUM = 1; + + public static final String ID = "_id"; + + /** + * 分页查询,直接返回集合类型的结果. + * + * @param query 查询 + * @param entityClass class + * @param pageSize pageSize + * @param pageNum pageNum + * @param collectionName collectionName + * @param T + * @return PageResult + */ + public PageList pageQuery(Query query, Class entityClass, Integer pageSize, Integer pageNum, String collectionName) { + return pageQuery(query, entityClass, Function.identity(), pageSize, pageNum, null, collectionName); + } + + /** + * 分页查询,不考虑条件分页,直接使用skip-limit来分页. + * + * @param query 查询 + * @param entityClass class + * @param pageSize pageSize + * @param pageNum pageNum + * @param collectionName collectionName + * @param T + * @param R + * @param mapper mapper + * @return PageResult + */ + public PageList pageQuery(Query query, Class entityClass, Function mapper, Integer pageSize, Integer pageNum, String collectionName) { + return pageQuery(query, entityClass, mapper, pageSize, pageNum, null, collectionName); + } + + /** + * 分页查询. + * + * @param query Mongo Query对象,构造你自己的查询条件 + * @param entityClass Mongo collection定义的entity class,用来确定查询哪个集合 + * @param mapper 映射器,从db查出来的list的元素类型是entityClass, 如果你想要转换成另一个对象,比如去掉敏感字段等,可以使用mapper来决定如何转换 + * @param pageSize 分页的大小 + * @param pageNum 当前页 + * @param lastId 条件分页参数, 区别于skip-limit,采用find(_id>lastId).limit分页 + * @param collection定义的class类型 + * @param 最终返回时,展现给页面时的一条记录的类型 + * @return PageResult,一个封装page信息的对象 + */ + public PageList pageQuery(Query query, Class entityClass, Function mapper, Integer pageSize, Integer pageNum, String lastId, String collectionName) { + //分页逻辑 + long total = mongoTemplate.count(query, entityClass, collectionName); + + final int pages = (int) Math.ceil(total / (double) pageSize); + + if (pageNum <= 0 || pageNum > pages) { + pageNum = FIRST_PAGE_NUM; + } + + final Criteria criteria = new Criteria(); + + if (StringUtils.isNotBlank(lastId)) { + if (pageNum != FIRST_PAGE_NUM) { + criteria.and(ID).gt(new ObjectId(lastId)); + } + query.limit(pageSize); + } else { + int skip = pageSize * (pageNum - 1); + query.skip(skip).limit(pageSize); + } + + final List entityList = mongoTemplate.find(query.addCriteria(criteria).with(Sort.by(Lists.newArrayList(new Order(Sort.Direction.ASC, ID)))), entityClass, + collectionName); + + final PageList pageResult = new PageList<>(); + Paginator paginator = pageResult.getPaginator(); + paginator.setTotalCount((int) total); + paginator.setPageSize(pageSize); + paginator.setCurrentPage(pageNum); + pageResult.setData(entityList.stream().map(mapper).collect(Collectors.toList())); + return pageResult; + } +} \ No newline at end of file diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/EnvUtils.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/EnvUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..533a4d1a5ef1a37bb80ed58554e6daf21d69a0eb --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/EnvUtils.java @@ -0,0 +1,33 @@ +package cn.loopstack.bic.dal.mongo.utils; + +import org.apache.commons.lang3.StringUtils; + +import cn.loopstack.bic.dal.mongo.utils.service.EnvService; +import cn.loopstack.bic.dal.mongo.utils.service.impl.EnvServiceImpl; + +/** + * 环境标识 + * + * @author icanci + * @since 1.0 Created in 2022/11/12 08:26 + */ +public class EnvUtils { + + private static final String DEFAULT_ENV = "test"; + + private static EnvService envService; + + private static String currEnv; + + public static String getEnv() { + if (StringUtils.isBlank(currEnv)) { + String env = envService.getEnv(); + currEnv = StringUtils.isBlank(env) ? DEFAULT_ENV : env; + } + return currEnv; + } + + public static void setEnvService(EnvServiceImpl envService) { + EnvUtils.envService = envService; + } +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/IDHolder.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/IDHolder.java new file mode 100644 index 0000000000000000000000000000000000000000..8c56a19c9a2b8d7235b2f9e561b9a8414177869c --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/IDHolder.java @@ -0,0 +1,40 @@ +package cn.loopstack.bic.dal.mongo.utils; + +import cn.loopstack.bic.dal.mongo.utils.service.IDGeneratorService; + +/** + * Id 生成器 + * + * @author icanci + * @since 1.0 Created in 2022/11/11 14:18 + */ +public class IDHolder { + /** 分布式id服务 */ + private static IDGeneratorService idGeneratorService; + + private static final String DEFAULT_PREFIX = "BIC"; + + public static void setIdGeneratorService(IDGeneratorService idGeneratorService) { + IDHolder.idGeneratorService = idGeneratorService; + } + + /** + * 通过雪花算法生成唯一id + * + * @param prefix 前缀 + * @return id + */ + public static String generateNoBySnowFlake(String prefix) { + return idGeneratorService.generateBySnowFlake(prefix); + } + + /** + * 通过雪花算法生成唯一id,默认 BIC + * + * @return id + */ + public static String generateNoBySnowFlakeDefaultPrefix() { + return idGeneratorService.generateBySnowFlake(DEFAULT_PREFIX); + } + +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/EnvService.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/EnvService.java new file mode 100644 index 0000000000000000000000000000000000000000..8ed685e49db81f961763329aff631e7292db113a --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/EnvService.java @@ -0,0 +1,14 @@ +package cn.loopstack.bic.dal.mongo.utils.service; + +/** + * @author icanci + * @since 1.0 Created in 2022/11/12 08:28 + */ +public interface EnvService { + /** + * 获取当前的环境信息 + * + * @return 返回当前的环境信息 + */ + String getEnv(); +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/IDGeneratorService.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/IDGeneratorService.java new file mode 100644 index 0000000000000000000000000000000000000000..5738826ef2ef4ea4621a6d15afe06055156f4cd6 --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/IDGeneratorService.java @@ -0,0 +1,15 @@ +package cn.loopstack.bic.dal.mongo.utils.service; + +/** + * @author icanci + * @since 1.0 Created in 2022/10/30 08:43 + */ +public interface IDGeneratorService { + /** + * 生成唯一id + * + * @param prefix 前缀 + * @return id + */ + String generateBySnowFlake(String prefix); +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/impl/EnvServiceImpl.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/impl/EnvServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..bf75da67877e55854d54b90c8a2622b4ea3d8284 --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/impl/EnvServiceImpl.java @@ -0,0 +1,30 @@ +package cn.loopstack.bic.dal.mongo.utils.service.impl; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.stereotype.Service; + +import cn.loopstack.bic.dal.mongo.utils.EnvUtils; +import cn.loopstack.bic.dal.mongo.utils.service.EnvService; + +/** + * @author icanci + * @since 1.0 Created in 2022/11/12 08:29 + */ +@Service("envService") +public class EnvServiceImpl implements EnvService, BeanPostProcessor { + @Value("${bic.env}") + private String env; + + @Override + public String getEnv() { + return env; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + EnvUtils.setEnvService(this); + return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName); + } +} diff --git a/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/impl/IDGeneratorServiceImpl.java b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/impl/IDGeneratorServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..7d9d9460df54b0ad7da1ff28b290e0751cdf53ac --- /dev/null +++ b/dal/src/main/java/cn/loopstack/bic/dal/mongo/utils/service/impl/IDGeneratorServiceImpl.java @@ -0,0 +1,31 @@ +package cn.loopstack.bic.dal.mongo.utils.service.impl; + +import org.apache.commons.lang3.RandomUtils; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.stereotype.Service; + +import cn.hutool.core.lang.Snowflake; +import cn.loopstack.bic.dal.mongo.utils.IDHolder; +import cn.loopstack.bic.dal.mongo.utils.service.IDGeneratorService; + +/** + * 分布式ID生成器 + * + * @author icanci + * @since 1.0 Created in 2022/10/30 08:43 + */ +@Service +public class IDGeneratorServiceImpl implements IDGeneratorService, InitializingBean { + /** 雪花序列号生成算法 */ + private static final Snowflake SNOW_FLAKE = new Snowflake(RandomUtils.nextInt(1, 9), RandomUtils.nextInt(1, 9)); + + @Override + public String generateBySnowFlake(String prefix) { + return prefix + SNOW_FLAKE.nextId(); + } + + @Override + public void afterPropertiesSet() throws Exception { + IDHolder.setIdGeneratorService(this); + } +} diff --git a/sdk/pom.xml b/sdk/pom.xml index 9e700093c3ddc0198a108092d1095e6a0f2de639..3f6bd2188574e3d19e40ff444e06aa5790c82a75 100644 --- a/sdk/pom.xml +++ b/sdk/pom.xml @@ -21,12 +21,6 @@ - - - org.springframework.boot - spring-boot-configuration-processor - true - org.springframework.boot spring-boot-starter @@ -35,15 +29,5 @@ org.springframework.boot spring-boot-autoconfigure - - org.springframework.boot - spring-boot-configuration-processor - compile - true - - - org.openjdk.jol - jol-core - \ No newline at end of file diff --git a/views/pom.xml b/views/pom.xml index 6d3cac785dfa2e2af157ad30136dfedbc20561bc..3dff19b0c5d8f6c61266c338e6f9c46309796f40 100644 --- a/views/pom.xml +++ b/views/pom.xml @@ -39,43 +39,43 @@ - - org.codehaus.mojo - exec-maven-plugin - - - - exec-npm-install - package - - exec - - - npm - - install - - src/main/resources/vueboot - - - - - exec-npm-run-build - package - - exec - - - npm - - run - build:stage - - src/main/resources/vueboot - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins diff --git a/views/src/main/java/cn/loopstack/bic/views/BicApplication.java b/views/src/main/java/cn/loopstack/bic/views/BicApplication.java index 075c80f1dfc780ab296937b48fcd06ab1059a77e..211a7f065ecf97b24a17e98b1a557d793eac3e1b 100644 --- a/views/src/main/java/cn/loopstack/bic/views/BicApplication.java +++ b/views/src/main/java/cn/loopstack/bic/views/BicApplication.java @@ -2,12 +2,13 @@ package cn.loopstack.bic.views; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; /** * @author icanci * @since 1.0 Created in 2023/08/19 09:42 */ -//@ComponentScan(basePackages = { "cn.icanci.loopstack.bic" }) +@ComponentScan(basePackages = { "cn.loopstack.bic" }) @SpringBootApplication public class BicApplication { public static void main(String[] args) { diff --git a/views/src/main/resources/application.yml b/views/src/main/resources/application.yml index 9c32df210344b63949ba4b687410d6201a555b00..6c3d1f902e081c88868f1d9fbf2f91e35046fd22 100644 --- a/views/src/main/resources/application.yml +++ b/views/src/main/resources/application.yml @@ -1,3 +1,8 @@ +# 项目配置 +bic: + env: test + +# 服务配置 server: tomcat: uri-encoding: UTF-8 @@ -5,6 +10,7 @@ server: servlet: context-path: / +# 日志 logging: config: classpath:log4j2.xml diff --git a/web/pom.xml b/web/pom.xml index 00da1834e33e747e782481859b9c3fb39becf762..4075f1790ae8e0cd8bdd4a288a70f4a25ca64a28 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -17,6 +17,16 @@ + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + cn.loopstack.bic bic-biz diff --git a/web/src/main/java/cn/loopstack/bic/web/api/BuryingApi.java b/web/src/main/java/cn/loopstack/bic/web/api/BuryingApi.java new file mode 100644 index 0000000000000000000000000000000000000000..995ab7eb714f7d34161621980a27842c29c25252 --- /dev/null +++ b/web/src/main/java/cn/loopstack/bic/web/api/BuryingApi.java @@ -0,0 +1,29 @@ +package cn.loopstack.bic.web.api; + +import javax.annotation.Resource; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import cn.loopstack.bic.biz.service.BuryingService; +import cn.loopstack.bic.common.result.R; +import cn.loopstack.bic.web.model.BuryingModelVO; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 18:18 + */ +@RestController +@RequestMapping("/bicApi/burying") +public class BuryingApi { + @Resource + private BuryingService buryingService; + + @PostMapping("/batchSubmit") + public R batchSubmit(@RequestBody BuryingModelVO buryingModel) { + buryingService.batchInsert(buryingModel.getBuryingList()); + return R.builderOk().build(); + } +} diff --git a/web/src/main/java/cn/loopstack/bic/web/controller/BuryingController.java b/web/src/main/java/cn/loopstack/bic/web/controller/BuryingController.java new file mode 100644 index 0000000000000000000000000000000000000000..ee09cd4c487f0b8a33dc17a4a637e50dcf9aaa95 --- /dev/null +++ b/web/src/main/java/cn/loopstack/bic/web/controller/BuryingController.java @@ -0,0 +1,26 @@ +package cn.loopstack.bic.web.controller; + +import javax.annotation.Resource; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import cn.loopstack.bic.biz.service.BuryingService; +import cn.loopstack.bic.common.result.R; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 18:34 + */ +@RestController +@RequestMapping("/bicAdmin/burying") +public class BuryingController { + @Resource + private BuryingService buryingService; + + @GetMapping("queryAll") + public R queryAll() { + return R.builderOk().data("list", buryingService.queryAll()).build(); + } +} diff --git a/web/src/main/java/cn/loopstack/bic/web/model/BuryingModelVO.java b/web/src/main/java/cn/loopstack/bic/web/model/BuryingModelVO.java new file mode 100644 index 0000000000000000000000000000000000000000..888ad81e566f1a7ccb163ae0fa17bd223f0a5615 --- /dev/null +++ b/web/src/main/java/cn/loopstack/bic/web/model/BuryingModelVO.java @@ -0,0 +1,29 @@ +package cn.loopstack.bic.web.model; + +import java.io.Serializable; +import java.util.List; +import java.util.StringJoiner; + +import cn.loopstack.bic.common.model.BuryingVO; + +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 18:20 + */ +public class BuryingModelVO implements Serializable { + + private List buryingList; + + public List getBuryingList() { + return buryingList; + } + + public void setBuryingList(List buryingList) { + this.buryingList = buryingList; + } + + @Override + public String toString() { + return new StringJoiner(",").add("buryingList=" + buryingList).toString(); + } +} diff --git a/web/src/main/java/cn/loopstack/bic/web/package-info.java b/web/src/main/java/cn/loopstack/bic/web/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..42ecd6a8e135eea5553e36531fb3b7b046911ad7 --- /dev/null +++ b/web/src/main/java/cn/loopstack/bic/web/package-info.java @@ -0,0 +1,5 @@ +/** + * @author icanci + * @since 1.0 Created in 2023/08/19 18:17 + */ +package cn.loopstack.bic.web; \ No newline at end of file