package com.xkrs.microservice.controller;
import com.xkrs.microservice.common.encapsulation.PromptMessageEnum;
import com.xkrs.microservice.model.entity.ecology.DocumentEntity;
import com.xkrs.microservice.model.vo.FileVo;
import com.xkrs.microservice.model.vo.PageVo;
import com.xkrs.microservice.service.FileService;
import com.xkrs.microservice.service.ecology.DocumentService;
import com.xkrs.microservice.service.ecology.RemoteSenseingService;
import com.xkrs.microservice.service.ecology.RemoteService;
import com.xkrs.microservice.util.filestorage.FileFastDfs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static com.xkrs.microservice.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
import static com.xkrs.microservice.common.tool.TokenUtil.getTokenUserName;
import static com.xkrs.microservice.util.NumberUtil.isStrNumeric;
import static com.xkrs.microservice.util.filestorage.FileUtil.getUploadInfo;
/**
* @author dong
* @date 2020/12/30
*/
@RestController
@RequestMapping("/file")
public class FileController {
private static final Logger log = LoggerFactory.getLogger(FileController.class);
@Resource
private FileService fileService;
@Resource
private DocumentService documentService;
@Resource
private FileFastDfs fileFastDfs;
@Resource
private RemoteSenseingService remoteSenseingService;
@Resource
private RemoteService remoteService;
/**
* 接收上传文件信息
*
* 1:技术规范、
* 2:评价报告、
* 3:野外核查报告、
* 4:其他
*
* @param files
* @return
*/
@PreAuthorize("hasAnyRole('ROLE_PRO_USER', 'ROLE_ADMINISTOR', 'ROLE_SYSTEM_MANAGER')")
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addFile2FileService(MultipartFile[] files, @RequestParam("fileType") Integer fileType, @RequestHeader(value = "Authorization") String token) {
Locale locale = LocaleContextHolder.getLocale();
if (null == files || files.length == 0) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "result or fileType is null", locale);
}
String userName = getTokenUserName(token);
List