【7.3.4】初始化文件业务的绑定

pull/54/MERGE
fengshuonan 2023-03-31 13:33:53 +08:00
parent fbb09a170c
commit e2b582bbc8
7 changed files with 346 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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<SysFileBusiness> {
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.stylefeng.roses.kernel.file.modular.mapper.SysFileBusinessMapper">
</mapper>

View File

@ -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;
}

View File

@ -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<SysFileBusiness> {
/**
*
*
* @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<SysFileBusiness>
* @author fengshuonan
* @date 2023/03/31 13:30
*/
List<SysFileBusiness> findList(SysFileBusinessRequest sysFileBusinessRequest);
/**
*
*
* @param sysFileBusinessRequest
* @return PageResult<SysFileBusiness>
* @author fengshuonan
* @date 2023/03/31 13:30
*/
PageResult<SysFileBusiness> findPage(SysFileBusinessRequest sysFileBusinessRequest);
}

View File

@ -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<SysFileBusinessMapper, SysFileBusiness> 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<SysFileBusiness> findPage(SysFileBusinessRequest sysFileBusinessRequest) {
LambdaQueryWrapper<SysFileBusiness> wrapper = createWrapper(sysFileBusinessRequest);
Page<SysFileBusiness> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(sysRolePage);
}
@Override
public List<SysFileBusiness> findList(SysFileBusinessRequest sysFileBusinessRequest) {
LambdaQueryWrapper<SysFileBusiness> 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<SysFileBusiness> createWrapper(SysFileBusinessRequest sysFileBusinessRequest) {
LambdaQueryWrapper<SysFileBusiness> 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;
}
}