新增附件管理

This commit is contained in:
阿沐 2022-08-24 00:10:59 +08:00
parent a4cda32272
commit b89d91c32b
9 changed files with 292 additions and 0 deletions

View File

@ -0,0 +1,55 @@
package net.maku.system.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.page.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.system.query.SysAttachmentQuery;
import net.maku.system.service.SysAttachmentService;
import net.maku.system.vo.SysAttachmentVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* 附件管理
*
* @author 阿沐 babamu@126.com
*/
@RestController
@RequestMapping("sys/attachment")
@Tag(name = "附件管理")
@AllArgsConstructor
public class SysAttachmentController {
private final SysAttachmentService sysAttachmentService;
@GetMapping("page")
@Operation(summary = "分页")
@PreAuthorize("hasAuthority('sys:attachment:page')")
public Result<PageResult<SysAttachmentVO>> page(@Valid SysAttachmentQuery query) {
PageResult<SysAttachmentVO> page = sysAttachmentService.page(query);
return Result.ok(page);
}
@PostMapping
@Operation(summary = "保存")
@PreAuthorize("hasAuthority('sys:attachment:save')")
public Result<String> save(@RequestBody SysAttachmentVO vo) {
sysAttachmentService.save(vo);
return Result.ok();
}
@DeleteMapping
@Operation(summary = "删除")
@PreAuthorize("hasAuthority('sys:attachment:delete')")
public Result<String> delete(@RequestBody List<Long> idList) {
sysAttachmentService.delete(idList);
return Result.ok();
}
}

View File

@ -0,0 +1,25 @@
package net.maku.system.convert;
import net.maku.system.entity.SysAttachmentEntity;
import net.maku.system.vo.SysAttachmentVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 附件管理
*
* @author 阿沐 babamu@126.com
*/
@Mapper
public interface SysAttachmentConvert {
SysAttachmentConvert INSTANCE = Mappers.getMapper(SysAttachmentConvert.class);
SysAttachmentEntity convert(SysAttachmentVO vo);
SysAttachmentVO convert(SysAttachmentEntity entity);
List<SysAttachmentVO> convertList(List<SysAttachmentEntity> list);
}

View File

@ -0,0 +1,15 @@
package net.maku.system.dao;
import net.maku.framework.common.dao.BaseDao;
import net.maku.system.entity.SysAttachmentEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 附件管理
*
* @author 阿沐 babamu@126.com
*/
@Mapper
public interface SysAttachmentDao extends BaseDao<SysAttachmentEntity> {
}

View File

@ -0,0 +1,37 @@
package net.maku.system.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.maku.framework.common.entity.BaseEntity;
/**
* 附件管理
*
* @author 阿沐 babamu@126.com
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_attachment")
public class SysAttachmentEntity extends BaseEntity {
/**
* 附件名称
*/
private String name;
/**
* 附件地址
*/
private String url;
/**
* 附件大小
*/
private Long size;
/**
* 存储平台
*/
private String platform;
}

View File

@ -0,0 +1,23 @@
package net.maku.system.query;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.maku.framework.common.query.Query;
/**
* 附件管理查询
*
* @author 阿沐 babamu@126.com
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(description = "附件管理查询")
public class SysAttachmentQuery extends Query {
@Schema(description = "附件名称")
private String name;
@Schema(description = "存储平台")
private String platform;
}

View File

@ -0,0 +1,25 @@
package net.maku.system.service;
import net.maku.framework.common.page.PageResult;
import net.maku.framework.common.service.BaseService;
import net.maku.system.entity.SysAttachmentEntity;
import net.maku.system.query.SysAttachmentQuery;
import net.maku.system.vo.SysAttachmentVO;
import java.util.List;
/**
* 附件管理
*
* @author 阿沐 babamu@126.com
*/
public interface SysAttachmentService extends BaseService<SysAttachmentEntity> {
PageResult<SysAttachmentVO> page(SysAttachmentQuery query);
void save(SysAttachmentVO vo);
void update(SysAttachmentVO vo);
void delete(List<Long> idList);
}

View File

@ -0,0 +1,65 @@
package net.maku.system.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import net.maku.framework.common.page.PageResult;
import net.maku.framework.common.service.impl.BaseServiceImpl;
import net.maku.system.convert.SysAttachmentConvert;
import net.maku.system.dao.SysAttachmentDao;
import net.maku.system.entity.SysAttachmentEntity;
import net.maku.system.query.SysAttachmentQuery;
import net.maku.system.service.SysAttachmentService;
import net.maku.system.vo.SysAttachmentVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 附件管理
*
* @author 阿沐 babamu@126.com
*/
@Service
@AllArgsConstructor
public class SysAttachmentServiceImpl extends BaseServiceImpl<SysAttachmentDao, SysAttachmentEntity> implements SysAttachmentService {
@Override
public PageResult<SysAttachmentVO> page(SysAttachmentQuery query) {
IPage<SysAttachmentEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
return new PageResult<>(SysAttachmentConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
}
private LambdaQueryWrapper<SysAttachmentEntity> getWrapper(SysAttachmentQuery query) {
LambdaQueryWrapper<SysAttachmentEntity> wrapper = Wrappers.lambdaQuery();
wrapper.eq(StrUtil.isNotBlank(query.getPlatform()), SysAttachmentEntity::getPlatform, query.getPlatform());
wrapper.like(StrUtil.isNotBlank(query.getName()), SysAttachmentEntity::getName, query.getName());
wrapper.orderByDesc(SysAttachmentEntity::getId);
return wrapper;
}
@Override
public void save(SysAttachmentVO vo) {
SysAttachmentEntity entity = SysAttachmentConvert.INSTANCE.convert(vo);
baseMapper.insert(entity);
}
@Override
public void update(SysAttachmentVO vo) {
SysAttachmentEntity entity = SysAttachmentConvert.INSTANCE.convert(vo);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(List<Long> idList) {
removeByIds(idList);
}
}

View File

@ -0,0 +1,40 @@
package net.maku.system.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import net.maku.framework.common.utils.DateUtils;
import java.io.Serializable;
import java.util.Date;
/**
* 附件管理
*
* @author 阿沐 babamu@126.com
*/
@Data
@Schema(description = "附件管理")
public class SysAttachmentVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
private Long id;
@Schema(description = "附件名称")
private String name;
@Schema(description = "附件地址")
private String url;
@Schema(description = "附件大小")
private Long size;
@Schema(description = "存储平台")
private String platform;
@Schema(description = "创建时间")
@JsonFormat(pattern = DateUtils.DATE_TIME_PATTERN)
private Date createTime;
}

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="net.maku.system.dao.SysAttachmentDao">
</mapper>