|
|
@@ -1,6 +1,9 @@
|
|
|
package com.goafanti.admin.controller;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -13,9 +16,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import com.goafanti.achievement.bo.InputAchievement;
|
|
|
import com.goafanti.achievement.service.AchievementService;
|
|
|
+import com.goafanti.admin.service.AftFileService;
|
|
|
import com.goafanti.common.bo.Result;
|
|
|
import com.goafanti.common.constant.AFTConstants;
|
|
|
import com.goafanti.common.constant.ErrorConstants;
|
|
|
@@ -23,7 +28,10 @@ import com.goafanti.common.controller.CertifyApiController;
|
|
|
import com.goafanti.common.enums.AchievementAuditStatus;
|
|
|
import com.goafanti.common.enums.AchievementFields;
|
|
|
import com.goafanti.common.enums.AttachmentType;
|
|
|
+import com.goafanti.common.enums.DeleteStatus;
|
|
|
import com.goafanti.common.model.Achievement;
|
|
|
+import com.goafanti.common.model.AftFile;
|
|
|
+import com.goafanti.common.utils.LoggerUtils;
|
|
|
import com.goafanti.common.utils.StringUtils;
|
|
|
import com.goafanti.user.service.UserService;
|
|
|
|
|
|
@@ -34,6 +42,75 @@ public class AdminAchievementApiController extends CertifyApiController {
|
|
|
private AchievementService achievementService;
|
|
|
@Resource
|
|
|
private UserService userService;
|
|
|
+ @Resource
|
|
|
+ private AftFileService aftFileService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传技术需求批量导入Excel模板
|
|
|
+ *
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/uploadTemplate", method = RequestMethod.POST)
|
|
|
+ public Result uploadPatentTemplate(HttpServletRequest req, String sign) {
|
|
|
+ Result res = new Result();
|
|
|
+ String fileName = "";
|
|
|
+ List<MultipartFile> files = getFiles(req);
|
|
|
+ MultipartFile mf = files.get(0);
|
|
|
+ String suffix = mf.getOriginalFilename().substring(mf.getOriginalFilename().lastIndexOf("."));
|
|
|
+ if (suffix.equals(".xls") || suffix.equals(".xlsx")) {
|
|
|
+ AttachmentType attachmentType = AttachmentType.getField(sign);
|
|
|
+ if (attachmentType == AttachmentType.ACHIEVEMENT_TEMPLATE) {
|
|
|
+ fileName = sign + suffix;
|
|
|
+ } else {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ String name = handleFile(res, req, fileName, files, mf);
|
|
|
+ res.setData(name);
|
|
|
+ if (!StringUtils.isBlank(name) && null == aftFileService.selectAftFileBySign(sign)) {
|
|
|
+ AftFile f = new AftFile();
|
|
|
+ f.setId(UUID.randomUUID().toString());
|
|
|
+ f.setFileName(AttachmentType.ACHIEVEMENT_TEMPLATE.getDesc());
|
|
|
+ f.setSign(sign);
|
|
|
+ f.setFilePath("/admin/" + fileName);
|
|
|
+ f.setDeleletedSign(DeleteStatus.UNDELETE.getCode());
|
|
|
+ aftFileService.insert(f);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ res.getError().add(buildError(ErrorConstants.FILE_PATTERN_ERROR, "文件格式错误,请重新上传!"));
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载技术需求批量导入Excel模板
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/downloadTemplate", method = RequestMethod.GET)
|
|
|
+ public Result downloadTemplateFile(HttpServletResponse response, String sign) {
|
|
|
+ Result res = new Result();
|
|
|
+ AttachmentType attachmentType = AttachmentType.getField(sign);
|
|
|
+ if (attachmentType == AttachmentType.ACHIEVEMENT_TEMPLATE) {
|
|
|
+ String fileName = "";
|
|
|
+ AftFile af = aftFileService.selectAftFileBySign(sign);
|
|
|
+ if (null == af) {
|
|
|
+ res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT, "", "找不到文件!"));
|
|
|
+ } else {
|
|
|
+ String path = af.getFilePath();
|
|
|
+ String suffix = path.substring(path.lastIndexOf("."));
|
|
|
+ fileName = AttachmentType.ACHIEVEMENT_TEMPLATE.getDesc() + suffix;
|
|
|
+ downloadFile(response, fileName, path);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 个人成果所有人列表
|
|
|
@@ -341,5 +418,23 @@ public class AdminAchievementApiController extends CertifyApiController {
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
+
|
|
|
+ private String handleFile(Result res, HttpServletRequest req, String fileName, List<MultipartFile> files,
|
|
|
+ MultipartFile mf) {
|
|
|
+ if (!files.isEmpty()) {
|
|
|
+ try {
|
|
|
+ mf.transferTo(toAdminPrivateFile(fileName));
|
|
|
+ LoggerUtils.debug(getClass(), fileName + " 文件上传成功");
|
|
|
+ } catch (IllegalStateException | IOException e) {
|
|
|
+ LoggerUtils.error(getClass(), "文件上传失败", e);
|
|
|
+ res.getError().add(buildError("", "文件上传失败!"));
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ res.getError().add(buildError("", "文件上传失败!"));
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
|
|
|
}
|