版本管理 和 版本文件上传
This commit is contained in:
parent
8c9926c1a7
commit
98145e92ec
|
|
@ -40,6 +40,14 @@ public class TbVersionController {
|
|||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@PutMapping("upSel")
|
||||
@ApiOperation("修改当前选中")
|
||||
public ResponseEntity<Object> updateSel(@Validated @RequestBody TbVersion resources){
|
||||
tbVersionService.updateSel(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping
|
||||
@ApiOperation("删除版本")
|
||||
public ResponseEntity<Object> deleteTbVersion(@RequestBody Integer[] ids) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class TbVersionDto implements Serializable {
|
|||
|
||||
private Integer id;
|
||||
|
||||
/** LDBL_APP;WX; */
|
||||
/** PC;APP; */
|
||||
private String source;
|
||||
|
||||
/** ios;android; */
|
||||
|
|
@ -22,9 +22,12 @@ public class TbVersionDto implements Serializable {
|
|||
|
||||
/** 版本号 */
|
||||
private String version;
|
||||
/** 下载地址 */
|
||||
private String url;
|
||||
|
||||
/** 0:不更新;1:更新 */
|
||||
/** 是否强制更新 0:否 1:是 */
|
||||
private Integer isUp;
|
||||
private Integer sel;
|
||||
|
||||
/** 更新提示内容 */
|
||||
private String message;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import lombok.Data;
|
|||
public class TbVersionQueryCriteria{
|
||||
|
||||
@Query
|
||||
/** LDBL-APP;WX; */
|
||||
/** PC;APP; */
|
||||
private String source;
|
||||
@Query
|
||||
/** ios;android; */
|
||||
|
|
@ -21,7 +21,7 @@ public class TbVersionQueryCriteria{
|
|||
/** 版本号 */
|
||||
private String version;
|
||||
@Query
|
||||
/** 0:不更新;1:更新 */
|
||||
/** 是否强制更新 0:否 1:是*/
|
||||
private Integer isUp;
|
||||
|
||||
private Integer pageSize;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class TbVersion implements Serializable {
|
|||
private Integer id;
|
||||
|
||||
@Column(name = "`source`")
|
||||
@ApiModelProperty(value = "LDBL-APP;WX;")
|
||||
@ApiModelProperty(value = "PC;APP;")
|
||||
private String source;
|
||||
|
||||
@Column(name = "`type`")
|
||||
|
|
@ -30,10 +30,17 @@ public class TbVersion implements Serializable {
|
|||
@ApiModelProperty(value = "版本号")
|
||||
private String version;
|
||||
|
||||
@Column(name = "`url`")
|
||||
@ApiModelProperty(value = "下载地址")
|
||||
private String url;
|
||||
|
||||
@Column(name = "`is_up`")
|
||||
@ApiModelProperty(value = "0:不更新;1:更新")
|
||||
@ApiModelProperty(value = "是否强制更新 0:否 1:是")
|
||||
private Integer isUp;
|
||||
|
||||
@ApiModelProperty(value = "选中 0:否 1:是")
|
||||
private Integer sel;
|
||||
|
||||
@Column(name = "`message`")
|
||||
@ApiModelProperty(value = "更新提示内容")
|
||||
private String message;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import cn.ysk.cashier.pojo.TbVersion;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
/**
|
||||
|
|
@ -15,4 +16,15 @@ public interface TbVersionRepository extends JpaRepository<TbVersion, Integer>,
|
|||
|
||||
@Query("SELECT count(1) FROM TbVersion WHERE source = :source AND type =:type AND version =:version")
|
||||
int isExist(@Param("source") String source, @Param("type") String type, @Param("version") String version);
|
||||
|
||||
@Query("SELECT count(1) FROM TbVersion WHERE source = :source AND version =:version")
|
||||
int isExist(@Param("source") String source, @Param("version") String version);
|
||||
|
||||
@Modifying
|
||||
@Query("update TbVersion version set version.sel=CASE" +
|
||||
" WHEN version.source=:source AND version.id=:id THEN 1 " +
|
||||
" WHEN version.source=:source AND version.id!=:id THEN 0 " +
|
||||
" ELSE version.sel END " +
|
||||
" WHERE version.source = :source")
|
||||
int updateSelBySource(@Param("source") String source, @Param("id") Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ public interface TbVersionService {
|
|||
*/
|
||||
void update(TbVersion resources);
|
||||
|
||||
void updateSel(TbVersion resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ import cn.ysk.cashier.mapper.TbVersionMapper;
|
|||
import cn.ysk.cashier.pojo.TbVersion;
|
||||
import cn.ysk.cashier.repository.TbVersionRepository;
|
||||
import cn.ysk.cashier.service.TbVersionService;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
import cn.ysk.cashier.utils.ValidationUtil;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
|
@ -61,17 +58,17 @@ public class TbVersionServiceImpl implements TbVersionService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TbVersionDto create(TbVersion resources) {
|
||||
int exist = tbVersionRepository.isExist(resources.getSource(), resources.getType(), resources.getVersion());
|
||||
int exist = tbVersionRepository.isExist(resources.getSource(), resources.getVersion());
|
||||
if (exist > 0) {
|
||||
throw new BadRequestException("该版本已存在。");
|
||||
}
|
||||
resources.setCreatedAt(Instant.now().toEpochMilli());
|
||||
TbVersionDto dto = tbVersionMapper.toDto(tbVersionRepository.save(resources));
|
||||
if (dto.getIsUp() == 1) {
|
||||
//产品标识:型号:版本
|
||||
//LDBL_APP_VERSION:ios:version 存在即需要强制更新
|
||||
redisUtils.set(dto.getSource() + "_VERSION:" + dto.getType() + ":" + dto.getVersion(), dto.getMessage());
|
||||
}
|
||||
// if (dto.getIsUp() == 1) {
|
||||
// //产品标识:型号:版本
|
||||
// //VERSION:PC::version 存在即需要强制更新
|
||||
// redisUtils.set(CacheKey.VERSION + dto.getSource() + ":" + dto.getVersion(), dto);
|
||||
// }
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
|
@ -80,17 +77,23 @@ public class TbVersionServiceImpl implements TbVersionService {
|
|||
public void update(TbVersion resources) {
|
||||
TbVersion tbVersion = tbVersionRepository.findById(resources.getId()).orElseGet(TbVersion::new);
|
||||
ValidationUtil.isNull(tbVersion.getId(), "TbVersion", "id", resources.getId());
|
||||
redisUtils.del(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
// redisUtils.del(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
tbVersion.copy(resources);
|
||||
tbVersion.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
tbVersionRepository.save(tbVersion);
|
||||
if (resources.getIsUp() == 1) {
|
||||
//产品标识:型号:版本
|
||||
//LDBL_APP_VERSION:ios:version 存在即需要强制更新
|
||||
redisUtils.set(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion(), tbVersion.getMessage());
|
||||
} else {
|
||||
redisUtils.del(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
}
|
||||
// if (resources.getIsUp() == 1) {
|
||||
// //产品标识:型号:版本
|
||||
// //LDBL_APP_VERSION:ios:version 存在即需要强制更新
|
||||
// redisUtils.set(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion(), tbVersion.getMessage());
|
||||
// } else {
|
||||
// redisUtils.del(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateSel(TbVersion resources) {
|
||||
tbVersionRepository.updateSelBySource(resources.getSource(),resources.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -99,9 +102,9 @@ public class TbVersionServiceImpl implements TbVersionService {
|
|||
TbVersion tbVersion = tbVersionRepository.findById(id).orElseGet(TbVersion::new);
|
||||
ValidationUtil.isNull(tbVersion.getId(), "TbVersion", "id", id);
|
||||
tbVersionRepository.deleteById(id);
|
||||
if (tbVersion.getIsUp() == 1) {
|
||||
redisUtils.del(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
}
|
||||
// if (tbVersion.getIsUp() == 1) {
|
||||
// redisUtils.del(tbVersion.getSource() + "_VERSION:" + tbVersion.getType() + ":" + tbVersion.getVersion());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,15 @@ public class QiniuController {
|
|||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("上传PC版本文件")
|
||||
@AnonymousPostMapping("uploadVersionFile")
|
||||
public ResponseEntity<Object> uploadVersionFile(@RequestParam MultipartFile file,@RequestParam String name){
|
||||
String url = qiNiuService.uploadVersionFile(file,qiNiuService.findCloud(),name);
|
||||
Map<String,Object> map = new HashMap<>(1);
|
||||
map.put("data",url);
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
// @Log("上传文件")
|
||||
@ApiOperation("上传文件")
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ public interface QiNiuService {
|
|||
*/
|
||||
List<QiniuContent> queryAll(QiniuQueryCriteria criteria);
|
||||
|
||||
String uploadVersionFile(MultipartFile file, CloudStorageConfig qiniuConfig,String fileName);
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param file 文件
|
||||
|
|
|
|||
|
|
@ -115,6 +115,22 @@ public class QiNiuServiceImpl implements QiNiuService {
|
|||
return qiniuContentRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String uploadVersionFile(MultipartFile file, CloudStorageConfig qiniuConfig,String fileName) {
|
||||
if(qiniuConfig== null){
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
// 构造一个带指定Zone对象的配置类
|
||||
try {
|
||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
|
||||
return OSSFactory.build(qiniuConfig).uploadFileName(file.getBytes(), extension,fileName);
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public QiniuContent upload(MultipartFile file, CloudStorageConfig qiniuConfig) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,25 @@ public abstract class AbstractCloudStorageService {
|
|||
return path + "." + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
* @param prefix 前缀
|
||||
* @param fileName 文件名
|
||||
* @param suffix 后缀
|
||||
* @return 返回上传路径
|
||||
*/
|
||||
public String getPath(String prefix,String suffix, String fileName) {
|
||||
//文件路径
|
||||
// String path = DateUtils.getDays() + "/" + fileName;
|
||||
String path = "version/" + fileName;
|
||||
|
||||
if(StringUtils.isNotBlank(prefix)){
|
||||
path = prefix + "/" + path;
|
||||
}
|
||||
|
||||
return path + "." + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param data 文件字节数组
|
||||
|
|
@ -58,6 +77,7 @@ public abstract class AbstractCloudStorageService {
|
|||
* @return 返回http地址
|
||||
*/
|
||||
public abstract String uploadSuffix(byte[] data, String suffix) throws Exception;
|
||||
public abstract String uploadFileName(byte[] data, String suffix,String fileName) throws Exception;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
|
|
|
|||
|
|
@ -49,6 +49,11 @@ public class AliyunCloudStorageService extends AbstractCloudStorageService {
|
|||
return upload(data, getPath(config.getPrefix(), suffix));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFileName(byte[] data, String suffix,String fileName) throws Exception {
|
||||
return upload(data, getPath(config.getPrefix(), suffix,fileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadSuffix(InputStream inputStream, String suffix) throws Exception {
|
||||
return upload(inputStream, getPath(config.getPrefix(), suffix));
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@ public class HuaweiCloudStorageService extends AbstractCloudStorageService {
|
|||
return config.getUrl() + "/" + path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFileName(byte[] data, String suffix,String fileName) throws Exception {
|
||||
return upload(data, getPath(config.getPrefix(), suffix,fileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadSuffix(InputStream inputStream, String suffix) throws Exception {
|
||||
return upload(inputStream, getPath(config.getPrefix(), suffix));
|
||||
|
|
|
|||
|
|
@ -82,4 +82,9 @@ public class QcloudCloudStorageService extends AbstractCloudStorageService {
|
|||
public String uploadSuffix(InputStream inputStream, String suffix) throws Exception {
|
||||
return upload(inputStream, getPath(config.getPrefix(), suffix));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFileName(byte[] data, String suffix,String fileName) throws Exception {
|
||||
return upload(data, getPath(config.getPrefix(), suffix,fileName));
|
||||
}
|
||||
}
|
||||
|
|
@ -75,4 +75,9 @@ public class QiniuCloudStorageService extends AbstractCloudStorageService {
|
|||
public String uploadSuffix(InputStream inputStream, String suffix) throws Exception {
|
||||
return upload(inputStream, getPath(config.getPrefix(), suffix));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFileName(byte[] data, String suffix,String fileName) throws Exception {
|
||||
return upload(data, getPath(config.getPrefix(), suffix,fileName));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue