13 changed files with 189 additions and 0 deletions
@ -0,0 +1,16 @@ |
|||
package com.project.exam.controller; |
|||
|
|||
|
|||
import com.project.exam.application.ExamRecordApplicationService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@RestController |
|||
@RequestMapping("/api/admin/examRecord") |
|||
public class AdminExamRecordController { |
|||
|
|||
@Autowired |
|||
private ExamRecordApplicationService examRecordApplicationService; |
|||
|
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
package com.project.exam.domain.dto; |
|||
|
|||
import com.project.base.domain.dto.BaseDTO; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class ExamRecordPictureDTO extends BaseDTO { |
|||
private Long id; |
|||
private Long examRecordId; |
|||
private String name; |
|||
private String fileSuffix; |
|||
private String filePath; |
|||
|
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
package com.project.exam.domain.entity; |
|||
|
|||
|
|||
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 com.project.base.domain.entity.BaseEntity; |
|||
import jakarta.persistence.*; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
@Data |
|||
@Table(name = "evaluator_exam_record_picture" , |
|||
indexes = {@Index(name = "Idx_examRecordId", columnList = "exam_record_id")}) |
|||
@Entity |
|||
@TableName(value = "evaluator_exam_record_picture" , autoResultMap = true) |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class ExamRecordPictureEntity extends BaseEntity { |
|||
@TableId(type = IdType.ASSIGN_ID) |
|||
@Id |
|||
private Long id; |
|||
|
|||
@TableField("exam_record_id") |
|||
@Column(name = "exam_record_id" , columnDefinition="bigint(20) comment '关联ExamRecordEntity'") |
|||
private Long examRecordId; |
|||
|
|||
@Column(name = "name" , columnDefinition="varchar(550) comment '文件名称'") |
|||
private String name; |
|||
|
|||
@Column(name = "file_suffix" , columnDefinition="varchar(50) comment '文件后缀'") |
|||
@TableField("file_suffix") |
|||
private String fileSuffix; |
|||
|
|||
|
|||
@Column(name = "file_path" , columnDefinition="varchar(550) comment '文件存储路径'") |
|||
@TableField("file_path") |
|||
private String filePath; |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package com.project.exam.domain.service; |
|||
|
|||
import com.project.base.domain.service.IBaseService; |
|||
import com.project.exam.domain.entity.ExamRecordPictureEntity; |
|||
|
|||
public interface ExamRecordPictureBaseService extends IBaseService<ExamRecordPictureEntity> { |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
package com.project.exam.domain.service; |
|||
|
|||
import com.project.base.domain.result.Result; |
|||
import com.project.exam.domain.dto.ExamRecordPictureDTO; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
public interface SaveExamRecordPictureDomainService { |
|||
|
|||
Result<ExamRecordPictureDTO> savePicture(MultipartFile file, Long recordId) throws Exception; |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
package com.project.exam.domain.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.project.exam.domain.entity.ExamRecordPictureEntity; |
|||
import com.project.exam.domain.service.ExamRecordPictureBaseService; |
|||
import com.project.exam.mapper.ExamRecordPictureMapper; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
|
|||
@Service |
|||
public class ExamRecordPictureBaseServiceImpl extends ServiceImpl<ExamRecordPictureMapper, ExamRecordPictureEntity> implements ExamRecordPictureBaseService { |
|||
|
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
package com.project.exam.domain.service.impl; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.io.FileUtil; |
|||
import cn.hutool.core.io.file.FileNameUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import com.project.base.domain.exception.BusinessErrorException; |
|||
import com.project.base.domain.result.Result; |
|||
import com.project.exam.domain.dto.ExamRecordPictureDTO; |
|||
import com.project.exam.domain.entity.ExamRecordPictureEntity; |
|||
import com.project.exam.domain.service.ExamRecordPictureBaseService; |
|||
import com.project.exam.domain.service.SaveExamRecordPictureDomainService; |
|||
import com.project.information.utils.MinIoUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import java.util.Date; |
|||
import java.util.Objects; |
|||
|
|||
@Service |
|||
public class SaveExamRecordPictureDomainServiceImpl implements SaveExamRecordPictureDomainService { |
|||
@Autowired |
|||
private MinIoUtils minIoUtils; |
|||
|
|||
@Autowired |
|||
private ExamRecordPictureBaseService examRecordPictureBaseService; |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public Result<ExamRecordPictureDTO> savePicture(MultipartFile file, Long recordId) throws Exception { |
|||
if (Objects.isNull(recordId)) { |
|||
throw new BusinessErrorException("考试记录id不能为空"); |
|||
} |
|||
if (Objects.isNull(file)) { |
|||
throw new BusinessErrorException("上传图片不能为空"); |
|||
} |
|||
String fileName = file.getOriginalFilename(); |
|||
String filePath = String.format("%s/%s/%s.%s", |
|||
DateUtil.format(new Date(), "yyyyMMdd"), |
|||
recordId, |
|||
IdUtil.fastSimpleUUID(), |
|||
FileNameUtil.extName(fileName)); |
|||
minIoUtils.uploadFile(file.getInputStream() , filePath); |
|||
ExamRecordPictureDTO pictureDTO = new ExamRecordPictureDTO(); |
|||
pictureDTO.setName(fileName); |
|||
pictureDTO.setFilePath(filePath); |
|||
pictureDTO.setFileSuffix(FileUtil.getSuffix(fileName)); |
|||
pictureDTO.setExamRecordId(recordId); |
|||
|
|||
return Result.success(examRecordPictureBaseService.saveDTO(pictureDTO , ExamRecordPictureEntity::new , ExamRecordPictureDTO::new)); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
package com.project.exam.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.project.exam.domain.entity.ExamRecordPictureEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
@Mapper |
|||
public interface ExamRecordPictureMapper extends BaseMapper<ExamRecordPictureEntity> { |
|||
} |
|||
Loading…
Reference in new issue