<%_ if (position === 'import') { _%>
import cn.xuyanwu.spring.file.storage.FileInfo;
import cn.xuyanwu.spring.file.storage.FileStorageService;
import java.io.File;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import <%= packageName %>.web.rest.errors.BadRequestAlertException;
<%_ } _%>
<%_ if (position === 'extendsImport') { _%>
import cn.xuyanwu.spring.file.storage.FileInfo;
import cn.xuyanwu.spring.file.storage.FileStorageService;
<%_ } _%>
<%_ if (position === 'method') { _%>

     /**
     * Save a uploadImage.
     *
     * @param uploadImageDTO the entity to save
     * @return the persisted entity
     */
    <%_ if (databaseTypeSql && ormTool === 'mybatis') { _%>
    @Transactional
    <%_ } _%>
    public UploadImageDTO save(UploadImageDTO uploadImageDTO) {
        log.debug("Request to save UploadImage : {}", uploadImageDTO);
        if (!uploadImageDTO.getImage().isEmpty()) {
            final String yearAndMonth = ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM"));
            uploadImageDTO.setCreateAt(ZonedDateTime.now());
            uploadImageDTO.setFullName(uploadImageDTO.getImage().getOriginalFilename());
            uploadImageDTO.setName(uploadImageDTO.getImage().getName());
            uploadImageDTO.setFolder(yearAndMonth + File.separator);
            uploadImageDTO.setFileSize(uploadImageDTO.getImage().getSize());
            FileInfo upload = fileStorageService.of(uploadImageDTO.getImage()).setPlatform("local").upload();
            uploadImageDTO.setUrl(upload.getUrl());
            uploadImageDTO.setExt(upload.getExt());


        } else {
            throw new BadRequestAlertException("Invalid file", "UploadFile", "imagesnull");
        }
        UploadImage uploadImage = uploadImageMapper.toEntity(uploadImageDTO);
        <%_ if (ormTool === 'mybatis' && databaseTypeSql) { _%>
        this.saveOrUpdate(uploadImage);
        return uploadImageMapper.toDto(this.getById(uploadImage.getId()));
        <%_ } else { _%>
        uploadImage = uploadImageRepository.save(uploadImage);
        return uploadImageMapper.toDto(uploadImage);
        <%_ } _%>
    }
<%_ } _%>
