From e2b582bbc895c76a4d79ba0b8d394fe7a10a6e55 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Fri, 31 Mar 2023 13:33:53 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.3.4=E3=80=91=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=96=87=E4=BB=B6=E4=B8=9A=E5=8A=A1=E7=9A=84=E7=BB=91?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/modular/entity/SysFileBusiness.java | 58 ++++++++++ .../enums/SysFileBusinessExceptionEnum.java | 36 ++++++ .../modular/mapper/SysFileBusinessMapper.java | 14 +++ .../mapper/mapping/SysFileBusinessMapper.xml | 7 ++ .../pojo/request/SysFileBusinessRequest.java | 51 +++++++++ .../service/SysFileBusinessService.java | 74 ++++++++++++ .../impl/SysFileBusinessServiceImpl.java | 106 ++++++++++++++++++ 7 files changed, 346 insertions(+) create mode 100644 kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/entity/SysFileBusiness.java create mode 100644 kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/enums/SysFileBusinessExceptionEnum.java create mode 100644 kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/mapper/SysFileBusinessMapper.java create mode 100644 kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/mapper/mapping/SysFileBusinessMapper.xml create mode 100644 kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/pojo/request/SysFileBusinessRequest.java create mode 100644 kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/SysFileBusinessService.java create mode 100644 kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileBusinessServiceImpl.java diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/entity/SysFileBusiness.java b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/entity/SysFileBusiness.java new file mode 100644 index 000000000..5b585a16d --- /dev/null +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/entity/SysFileBusiness.java @@ -0,0 +1,58 @@ +package cn.stylefeng.roses.kernel.file.modular.entity; + +import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity; +import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 业务关联的文件实例类 + * + * @author fengshuonan + * @date 2023/03/31 13:30 + */ +@TableName("sys_file_business") +@Data +@EqualsAndHashCode(callSuper = true) +public class SysFileBusiness extends BaseEntity { + + /** + * 主键id + */ + @TableId(value = "file_business_id", type = IdType.ASSIGN_ID) + @ChineseDescription("主键id") + private Long fileBusinessId; + + /** + * 业务主键id + */ + @TableField("business_id") + @ChineseDescription("业务主键id") + private Long businessId; + + /** + * 关联文件表的id + */ + @TableField("file_id") + @ChineseDescription("关联文件表的id") + private Long fileId; + + /** + * 下载次数 + */ + @TableField("download_count") + @ChineseDescription("下载次数") + private Integer downloadCount; + + /** + * 租户id + */ + @TableField("tenant_id") + @ChineseDescription("租户id") + private Long tenantId; + +} diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/enums/SysFileBusinessExceptionEnum.java b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/enums/SysFileBusinessExceptionEnum.java new file mode 100644 index 000000000..5879f4dae --- /dev/null +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/enums/SysFileBusinessExceptionEnum.java @@ -0,0 +1,36 @@ +package cn.stylefeng.roses.kernel.file.modular.enums; + +import cn.stylefeng.roses.kernel.rule.constants.RuleConstants; +import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; +import lombok.Getter; + +/** + * 业务关联的文件异常相关枚举 + * + * @author fengshuonan + * @date 2023/03/31 13:30 + */ +@Getter +public enum SysFileBusinessExceptionEnum implements AbstractExceptionEnum { + + /** + * 查询结果不存在 + */ + SYS_FILE_BUSINESS_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在"); + + /** + * 错误编码 + */ + private final String errorCode; + + /** + * 提示用户信息 + */ + private final String userTip; + + SysFileBusinessExceptionEnum(String errorCode, String userTip) { + this.errorCode = errorCode; + this.userTip = userTip; + } + +} \ No newline at end of file diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/mapper/SysFileBusinessMapper.java b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/mapper/SysFileBusinessMapper.java new file mode 100644 index 000000000..15f5baf55 --- /dev/null +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/mapper/SysFileBusinessMapper.java @@ -0,0 +1,14 @@ +package cn.stylefeng.roses.kernel.file.modular.mapper; + +import cn.stylefeng.roses.kernel.file.modular.entity.SysFileBusiness; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * 业务关联的文件 Mapper 接口 + * + * @author fengshuonan + * @date 2023/03/31 13:30 + */ +public interface SysFileBusinessMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/mapper/mapping/SysFileBusinessMapper.xml b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/mapper/mapping/SysFileBusinessMapper.xml new file mode 100644 index 000000000..4bbd55f49 --- /dev/null +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/mapper/mapping/SysFileBusinessMapper.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/pojo/request/SysFileBusinessRequest.java b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/pojo/request/SysFileBusinessRequest.java new file mode 100644 index 000000000..60127d89d --- /dev/null +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/pojo/request/SysFileBusinessRequest.java @@ -0,0 +1,51 @@ +package cn.stylefeng.roses.kernel.file.modular.pojo.request; + +import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription; +import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; + +/** + * 业务关联的文件封装类 + * + * @author fengshuonan + * @date 2023/03/31 13:30 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysFileBusinessRequest extends BaseRequest { + + /** + * 主键id + */ + @NotNull(message = "主键id不能为空", groups = {edit.class, delete.class}) + @ChineseDescription("主键id") + private Long fileBusinessId; + + /** + * 业务主键id + */ + @ChineseDescription("业务主键id") + private Long businessId; + + /** + * 关联文件表的id + */ + @ChineseDescription("关联文件表的id") + private Long fileId; + + /** + * 下载次数 + */ + @ChineseDescription("下载次数") + private Integer downloadCount; + + /** + * 租户id + */ + @ChineseDescription("租户id") + private Long tenantId; + +} diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/SysFileBusinessService.java b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/SysFileBusinessService.java new file mode 100644 index 000000000..eb346b8ee --- /dev/null +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/SysFileBusinessService.java @@ -0,0 +1,74 @@ +package cn.stylefeng.roses.kernel.file.modular.service; + +import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; +import cn.stylefeng.roses.kernel.file.modular.entity.SysFileBusiness; +import cn.stylefeng.roses.kernel.file.modular.pojo.request.SysFileBusinessRequest; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + * 业务关联的文件 服务类 + * + * @author fengshuonan + * @date 2023/03/31 13:30 + */ +public interface SysFileBusinessService extends IService { + + /** + * 新增 + * + * @param sysFileBusinessRequest 请求参数 + * @author fengshuonan + * @date 2023/03/31 13:30 + */ + void add(SysFileBusinessRequest sysFileBusinessRequest); + + /** + * 删除 + * + * @param sysFileBusinessRequest 请求参数 + * @author fengshuonan + * @date 2023/03/31 13:30 + */ + void del(SysFileBusinessRequest sysFileBusinessRequest); + + /** + * 编辑 + * + * @param sysFileBusinessRequest 请求参数 + * @author fengshuonan + * @date 2023/03/31 13:30 + */ + void edit(SysFileBusinessRequest sysFileBusinessRequest); + + /** + * 查询详情 + * + * @param sysFileBusinessRequest 请求参数 + * @author fengshuonan + * @date 2023/03/31 13:30 + */ + SysFileBusiness detail(SysFileBusinessRequest sysFileBusinessRequest); + + /** + * 获取列表 + * + * @param sysFileBusinessRequest 请求参数 + * @return List 返回结果 + * @author fengshuonan + * @date 2023/03/31 13:30 + */ + List findList(SysFileBusinessRequest sysFileBusinessRequest); + + /** + * 获取列表(带分页) + * + * @param sysFileBusinessRequest 请求参数 + * @return PageResult 返回结果 + * @author fengshuonan + * @date 2023/03/31 13:30 + */ + PageResult findPage(SysFileBusinessRequest sysFileBusinessRequest); + +} \ No newline at end of file diff --git a/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileBusinessServiceImpl.java b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileBusinessServiceImpl.java new file mode 100644 index 000000000..2ad134c46 --- /dev/null +++ b/kernel-d-file/file-business/src/main/java/cn/stylefeng/roses/kernel/file/modular/service/impl/SysFileBusinessServiceImpl.java @@ -0,0 +1,106 @@ +package cn.stylefeng.roses.kernel.file.modular.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; +import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; +import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; +import cn.stylefeng.roses.kernel.file.modular.entity.SysFileBusiness; +import cn.stylefeng.roses.kernel.file.modular.enums.SysFileBusinessExceptionEnum; +import cn.stylefeng.roses.kernel.file.modular.mapper.SysFileBusinessMapper; +import cn.stylefeng.roses.kernel.file.modular.pojo.request.SysFileBusinessRequest; +import cn.stylefeng.roses.kernel.file.modular.service.SysFileBusinessService; +import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 业务关联的文件业务实现层 + * + * @author fengshuonan + * @date 2023/03/31 13:30 + */ +@Service +public class SysFileBusinessServiceImpl extends ServiceImpl implements SysFileBusinessService { + + @Override + public void add(SysFileBusinessRequest sysFileBusinessRequest) { + SysFileBusiness sysFileBusiness = new SysFileBusiness(); + BeanUtil.copyProperties(sysFileBusinessRequest, sysFileBusiness); + this.save(sysFileBusiness); + } + + @Override + public void del(SysFileBusinessRequest sysFileBusinessRequest) { + SysFileBusiness sysFileBusiness = this.querySysFileBusiness(sysFileBusinessRequest); + this.removeById(sysFileBusiness.getFileBusinessId()); + } + + @Override + public void edit(SysFileBusinessRequest sysFileBusinessRequest) { + SysFileBusiness sysFileBusiness = this.querySysFileBusiness(sysFileBusinessRequest); + BeanUtil.copyProperties(sysFileBusinessRequest, sysFileBusiness); + this.updateById(sysFileBusiness); + } + + @Override + public SysFileBusiness detail(SysFileBusinessRequest sysFileBusinessRequest) { + return this.querySysFileBusiness(sysFileBusinessRequest); + } + + @Override + public PageResult findPage(SysFileBusinessRequest sysFileBusinessRequest) { + LambdaQueryWrapper wrapper = createWrapper(sysFileBusinessRequest); + Page sysRolePage = this.page(PageFactory.defaultPage(), wrapper); + return PageResultFactory.createPageResult(sysRolePage); + } + + @Override + public List findList(SysFileBusinessRequest sysFileBusinessRequest) { + LambdaQueryWrapper wrapper = this.createWrapper(sysFileBusinessRequest); + return this.list(wrapper); + } + + /** + * 获取信息 + * + * @author fengshuonan + * @date 2023/03/31 13:30 + */ + private SysFileBusiness querySysFileBusiness(SysFileBusinessRequest sysFileBusinessRequest) { + SysFileBusiness sysFileBusiness = this.getById(sysFileBusinessRequest.getFileBusinessId()); + if (ObjectUtil.isEmpty(sysFileBusiness)) { + throw new ServiceException(SysFileBusinessExceptionEnum.SYS_FILE_BUSINESS_NOT_EXISTED); + } + return sysFileBusiness; + } + + /** + * 创建查询wrapper + * + * @author fengshuonan + * @date 2023/03/31 13:30 + */ + private LambdaQueryWrapper createWrapper(SysFileBusinessRequest sysFileBusinessRequest) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + Long fileBusinessId = sysFileBusinessRequest.getFileBusinessId(); + Long businessId = sysFileBusinessRequest.getBusinessId(); + Long fileId = sysFileBusinessRequest.getFileId(); + Integer downloadCount = sysFileBusinessRequest.getDownloadCount(); + Long tenantId = sysFileBusinessRequest.getTenantId(); + + queryWrapper.eq(ObjectUtil.isNotNull(fileBusinessId), SysFileBusiness::getFileBusinessId, fileBusinessId); + queryWrapper.eq(ObjectUtil.isNotNull(businessId), SysFileBusiness::getBusinessId, businessId); + queryWrapper.eq(ObjectUtil.isNotNull(fileId), SysFileBusiness::getFileId, fileId); + queryWrapper.eq(ObjectUtil.isNotNull(downloadCount), SysFileBusiness::getDownloadCount, downloadCount); + queryWrapper.eq(ObjectUtil.isNotNull(tenantId), SysFileBusiness::getTenantId, tenantId); + + return queryWrapper; + } + +} \ No newline at end of file