Commit 7d01a27b by qwmqiuwenmin

fix

parent 149e8033
package com.gic.haoban.manage.web.controller;
import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DateUtil;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import com.gic.qcloud.BucketNameEnum;
import com.gic.qcloud.FileUploadUtil;
@RestController
public class UploadController extends WebBaseController{
private static Set<String> FILE_TYPE = new HashSet<>( );
static {
for(BucketNameEnum value: BucketNameEnum.values()){
FILE_TYPE.add( value.getName() );
}
}
@RequestMapping("/upload-file")
@ResponseBody
public HaobanResponse upload(@RequestParam MultipartFile file,@RequestParam String fileType) throws Exception{
if(file == null || file.isEmpty()){
return resultResponse(HaoBanErrCode.ERR_2);
}
String name = file.getOriginalFilename();
String suffix = name.substring(name.lastIndexOf(".") + 1);
String location = System.getProperty( "user.dir" )+"/data/tmp/";
//b
long len = file.getSize();
File templateFile = new File( location+name );
FileUtils.copyInputStreamToFile( file.getInputStream(),templateFile );
// 2.上传腾讯云
String dayFilePath = LocalDateTime.now().format( DateTimeFormatter.ofPattern( DateUtil.FORMAT_DATETIME_14 ) );
String key = "haoban/"+dayFilePath+"/"+name;
fileType = FILE_TYPE.contains( fileType )?fileType:BucketNameEnum.OTHER_90000.getName();
String url = FileUploadUtil.simpleUploadFileFromLocal( templateFile,key,fileType);
if(templateFile != null){
templateFile.delete();
}
JSONObject res = new JSONObject( );
res.put( "name",name );
res.put( "ext", suffix );
res.put( "size",len );
res.put( "key",key );
res.put( "url", "https://"+url );
return resultResponse(HaoBanErrCode.ERR_1, res);
}
}
......@@ -11,8 +11,10 @@ import org.springframework.web.bind.annotation.RestController;
import com.gic.api.base.commons.Page;
import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.base.api.common.PageResult2;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.service.MaterialApiService;
......@@ -31,7 +33,9 @@ public class MaterialController extends WebBaseController{
@RequestMapping("/material-list")
public HaobanResponse materialList(String wxEnterpriseId,String keyword,String categoryId,Integer materialType,BasePageInfo pageInfo) {
Page<MaterialDTO> page = materialApiService.listMaterial(wxEnterpriseId,keyword,categoryId,materialType,pageInfo);
return resultResponse(HaoBanErrCode.ERR_1,page);
//暂时转换
PageResult2 pageResult2 = PageUtil.getPageInfo(page);
return resultResponse(HaoBanErrCode.ERR_1, pageResult2);
}
/**
......
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