Commit d726ac9c authored by liqin's avatar liqin 💬

bug fixed

parent 2fc94169
......@@ -4,6 +4,7 @@ import org.apache.commons.io.FilenameUtils;
import org.csource.common.MyException;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
......@@ -16,6 +17,13 @@ import java.util.Properties;
*/
public class FastDFSUtils {
private static String dfsFileAccessBasePath;
@Value("${dfsFileAccessBasePath:#{null}}")
public static void setDfsFileAccessBasePath(String dfsFileAccessBasePath) {
FastDFSUtils.dfsFileAccessBasePath = dfsFileAccessBasePath;
}
static {
try {
Properties props = new Properties();
......@@ -53,8 +61,8 @@ public class FastDFSUtils {
return fileIds;
}
public static String[] uploadPic(InputStream inStream, String fileName, long size) {
String[] fileIds = null;
public static String uploadInputStream(InputStream inStream, String fileName, long size) {
String[] fileIds;
try {
// ClientGloble 读配置文件
// 老大客户端
......@@ -64,19 +72,16 @@ public class FastDFSUtils {
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
String extName = FilenameUtils.getExtension(fileName);
NameValuePair[] meta_list = new NameValuePair[3];
meta_list[0] = new NameValuePair("fileName", fileName);
meta_list[1] = new NameValuePair("fileExt", extName);
meta_list[2] = new NameValuePair("fileSize", String.valueOf(size));
// http://172.16.15.244:8081/group1/M00/00/00/rBAP9FfFG62AZsuBAADeW7MfEHA287.png
// group1/M00/00/01/wKjIgFWOYc6APpjAAAD-qk29i78248.jpg
fileIds = storageClient.upload_file(null, size, new UploadFileSender(inStream), extName, meta_list);
return dfsFileAccessBasePath + "/" + fileIds[0] + "/" + fileIds[1];
} catch (Exception e) {
e.printStackTrace();
}
return fileIds;
return null;
}
public static String uploadPic(byte[] pic, String fileName, long size) {
......@@ -137,16 +142,19 @@ public class FastDFSUtils {
}
private static class UploadFileSender implements UploadCallback {
private InputStream inStream;
public UploadFileSender(InputStream inStream) {
this.inStream = inStream;
private InputStream is;
public UploadFileSender(InputStream is) {
this.is = is;
}
@Override
public int send(OutputStream out) throws IOException {
byte[] b = new byte[1024];
int readBytes;
while ((readBytes = inStream.read()) > 0) {
out.write(readBytes);
while ((readBytes = is.read(b)) != -1) {
out.write(b, 0, readBytes);
}
return 0;
}
......
......@@ -7,7 +7,7 @@ public enum AuditStatusEnum {
TBC("1", "待审核"),
REFUSED("2", "已驳回"),
APPROVED("3", "已通过");
APPROVED_FIRST("3", "初审通过");
// 错误编码
private String code;
......
package cn.wisenergy.chnmuseum.party.model;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......@@ -7,6 +9,7 @@ import lombok.*;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;
......@@ -25,33 +28,34 @@ import java.time.LocalDateTime;
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@TableName("asset")
@ApiModel(value = "Asset对象", description = "视频")
@ApiModel(value = "视频", description = "视频")
public class Asset implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("视频ID")
@TableId(value = "id", type = IdType.ASSIGN_ID)
@NotNull(message = "视频ID不能为空", groups = {Update.class})
private String id;
@ApiModelProperty("视频名称")
@TableField("name")
@NotBlank(message = "视频名称不能为空")
@NotBlank(message = "视频名称不能为空", groups = {Add.class, Update.class})
private String name;
@ApiModelProperty("视频版权方ID")
@TableField("asset_copyright_owner_id")
@NotBlank(message = "视频版权方ID不能为空")
@NotBlank(message = "视频版权方ID不能为空", groups = {Add.class, Update.class})
private String assetCopyrightOwnerId;
@ApiModelProperty("视频类别ID")
@TableField("asset_type_id")
@NotBlank(message = "视频类别ID不能为空")
@NotBlank(message = "视频类别ID不能为空", groups = {Add.class, Update.class})
private String assetTypeId;
@ApiModelProperty("视频缩略图")
@TableField("thumbnail")
@NotBlank(message = "视频缩略图不能为空")
@NotBlank(message = "视频缩略图不能为空", groups = {Add.class, Update.class})
private String thumbnail;
@ApiModelProperty("视频链接")
......@@ -70,4 +74,12 @@ public class Asset implements Serializable {
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
@ApiModelProperty("视频分类")
@TableField(exist = false)
private String assetTypeName;
@ApiModelProperty("版权方")
@TableField(exist = false)
private String assetCopyrightOwnerName;
}
package cn.wisenergy.chnmuseum.party.web.controller;
import cn.wisenergy.chnmuseum.party.common.dfs.FastDFSUtils;
import cn.wisenergy.chnmuseum.party.common.enums.AuditStatusEnum;
import cn.wisenergy.chnmuseum.party.common.enums.RESPONSE_CODE_ENUM;
import cn.wisenergy.chnmuseum.party.common.mvc.InterfaceException;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
import cn.wisenergy.chnmuseum.party.model.Asset;
import cn.wisenergy.chnmuseum.party.model.AssetType;
import cn.wisenergy.chnmuseum.party.model.CopyrightOwner;
import cn.wisenergy.chnmuseum.party.service.AssetService;
import cn.wisenergy.chnmuseum.party.service.AssetTypeService;
import cn.wisenergy.chnmuseum.party.service.CopyrightOwnerService;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.baidu.ueditor.extend.MultipartFile;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
......@@ -17,11 +26,14 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -42,25 +54,27 @@ public class AssetController extends BaseController {
@Resource
private AssetService assetService;
@PostMapping("/batchSave")
@RequiresPermissions("asset:batch:save")
@ApiOperation(value = "批量添加视频", notes = "批量添加视频")
public Map<String, Object> batchSaveAsset(@Validated(value = {Add.class}) List<Asset> assetList) {
// 保存业务节点信息
boolean result = assetService.saveBatch(assetList);
// 返回操作结果
if (result) {
return getSuccessResult();
} else {
// 保存失败
return getFailResult();
}
}
@Resource
private CopyrightOwnerService copyrightOwnerService;
@Resource
private AssetTypeService assetTypeService;
@PostMapping("/save")
@PostMapping(value = "/save", headers = "content-type=multipart/form-data", produces = MediaType.MULTIPART_FORM_DATA_VALUE)
@RequiresPermissions("asset:save")
@ApiOperation(value = "添加视频", notes = "添加视频")
public Map<String, Object> saveAsset(@Validated(value = {Add.class}) Asset asset) {
public Map<String, Object> saveAsset(@Validated(value = {Add.class}) Asset asset, @RequestParam(value = "files") MultipartFile[] files) throws IOException {
if (files.length == 0) {
throw new InterfaceException(RESPONSE_CODE_ENUM.REQUEST_PARAMS_ERROR.getCode(), "视频必须上传");
}
final Map<String, String> filesMetadata = new LinkedHashMap<>(2);
for (MultipartFile file : files) {
// 原始文件名
String originalFilename = file.getOriginalFilename();
String url = FastDFSUtils.uploadInputStream(file.getInputStream(), originalFilename, file.getSize());
filesMetadata.put(originalFilename.trim(), url);
}
asset.setAuditStatus(AuditStatusEnum.TBC.name());
// 保存业务节点信息
boolean result = assetService.save(asset);
// 返回操作结果
......@@ -75,7 +89,18 @@ public class AssetController extends BaseController {
@PutMapping("/update")
@RequiresPermissions("asset:update")
@ApiOperation(value = "修改视频信息", notes = "修改视频信息")
public Map<String, Object> updateAsset(@Validated Asset asset) {
public Map<String, Object> updateAsset(@Validated(value = {Update.class}) Asset asset, @RequestParam(value = "files") MultipartFile[] files) throws IOException {
if (files.length > 0) {
final Map<String, String> filesMetadata = new LinkedHashMap<>(2);
for (MultipartFile file : files) {
// 上传简单文件名
String originalFilename = file.getOriginalFilename();
String url = FastDFSUtils.uploadInputStream(file.getInputStream(), originalFilename, file.getSize());
filesMetadata.put(originalFilename.trim(), url);
}
asset.setAuditStatus(AuditStatusEnum.TBC.name());
}
asset.setAuditStatus(AuditStatusEnum.TBC.name());
boolean flag = assetService.updateById(asset);
if (flag) {
return getSuccessResult();
......@@ -121,7 +146,7 @@ public class AssetController extends BaseController {
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "auditStatus", value = "审核状态", paramType = "query", dataType = "String")
})
public Map<String, Object> getAssetList(@RequestParam(value = "auditStatus", defaultValue = "APPROVED", required = false) AuditStatusEnum auditStatus) {
public Map<String, Object> getAssetList(@RequestParam(value = "auditStatus", defaultValue = "APPROVED_FIRST", required = false) AuditStatusEnum auditStatus) {
List<Asset> assetList = assetService.list(Wrappers.<Asset>lambdaQuery().eq(Asset::getAuditStatus, auditStatus.name()));
return getResult(assetList);
}
......@@ -163,7 +188,11 @@ public class AssetController extends BaseController {
Asset::getUpdateTime);
Page<Asset> page = this.assetService.page(getPage(), queryWrapper);
for (Asset asset : page.getRecords()) {
AssetType assetType = this.assetTypeService.getById(asset.getAssetTypeId());
asset.setAssetTypeName(assetType.getName());
CopyrightOwner copyrightOwner = this.copyrightOwnerService.getById(asset.getAssetCopyrightOwnerId());
asset.setAssetCopyrightOwnerName(copyrightOwner.getName());
}
return getResult(page);
}
......@@ -173,9 +202,15 @@ public class AssetController extends BaseController {
@ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path")
})
@GetMapping("/get/{id}")
@RequiresPermissions("asset:getById")
@RequiresPermissions("asset:get:id")
public Map<String, Object> getById(@PathVariable("id") String id) {
Asset asset = assetService.getById(id);
AssetType assetType = this.assetTypeService.getById(asset.getAssetTypeId());
asset.setAssetTypeName(assetType.getName());
CopyrightOwner copyrightOwner = this.copyrightOwnerService.getById(asset.getAssetCopyrightOwnerId());
asset.setAssetCopyrightOwnerName(copyrightOwner.getName());
return getResult(asset);
}
......
......@@ -207,7 +207,7 @@ public class ${table.controllerName} {
})
@GetMapping("/get/{id}")
#if(${cfg.requiresPermissions})
@RequiresPermissions("$!{cfg.colonTableName}:getById")
@RequiresPermissions("$!{cfg.colonTableName}:get:id")
#end
public Map<String, Object> getById(@PathVariable("id") String id) {
${entity} ${table.entityPath} = ${table.entityPath}Service.getById(id);
......
......@@ -52,7 +52,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
@TableName("${table.name}")
#end
#if(${swagger2})
@ApiModel(value = "${entity}对象", description = "$!{table.comment}")
@ApiModel(value = "$!{table.comment}", description = "$!{table.comment}")
#end
#if(${superEntityClass})
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
......@@ -87,6 +87,7 @@ public class ${entity} implements Serializable {
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
## 设置主键注解
@TableId(value = "${field.name}", type = IdType.${idType})
@NotNull(message = "${field.propertyName}不能为空", groups = {Update.class})
## 是主键类型
#set($custom_is_pk=true)
#elseif(${field.convert})
......@@ -119,9 +120,9 @@ public class ${entity} implements Serializable {
#if(${field.keyIdentityFlag})
@NotNull(message = "${field.propertyName}不能为空", groups = {Update.class})
#elseif(${field.propertyType} == 'String')
@NotBlank(message = "${field.comment}不能为空")
@NotBlank(message = "${field.comment}不能为空", groups = {Add.class, Update.class})
#else
@NotNull(message = "${field.comment}不能为空")
@NotNull(message = "${field.comment}不能为空", groups = {Add.class, Update.class})
#end
private ${field.propertyType} ${field.propertyName};
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment