修改对标报告的附件上传
This commit is contained in:
parent
835a1e7c00
commit
9683489c3a
@ -1,19 +1,22 @@
|
||||
package com.xdap.self_development.controller;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.definesys.mpaas.common.http.Response;
|
||||
import com.xdap.api.moudle.user.vo.LoginUserVo;
|
||||
import com.xdap.runtime.service.RuntimeAppContextService;
|
||||
import com.xdap.runtime.service.RuntimeUserService;
|
||||
import com.xdap.self_development.config.BusinessDatabase;
|
||||
import com.xdap.self_development.feign.ApaasMyTokenFeign;
|
||||
import com.xdap.self_development.feign.dto.AppTokenDTO;
|
||||
import com.xdap.self_development.feign.dto.FileUploadDTO;
|
||||
import com.xdap.self_development.feign.dto.UserTokenDT0;
|
||||
import com.xdap.self_development.pojo.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
@ -21,6 +24,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/custom/delete")
|
||||
public class DeleteController {
|
||||
@ -33,18 +37,50 @@ public class DeleteController {
|
||||
@Autowired
|
||||
private ApaasMyTokenFeign apaasMyTokenFeign;
|
||||
|
||||
@GetMapping("/loginVo")
|
||||
public Response loginVo(@RequestParam String userId) {
|
||||
@PostMapping("/uploadFile")
|
||||
public Response uploadFile(@RequestPart("file") MultipartFile file) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
AppTokenDTO token = apaasMyTokenFeign.getAppToken(
|
||||
"client_credentials",
|
||||
"2b5b3de8-e7fd-406a-a59a-d5568457b1f4",
|
||||
"94bddc6a-27a4-4204-885b-b075812ec535"
|
||||
);
|
||||
map.put("token", token);
|
||||
map.put("appToken", token);
|
||||
log.info("loginVo token:{}", token);
|
||||
|
||||
UserTokenDT0 userToken = apaasMyTokenFeign.getUserToken(
|
||||
token.getAccess_token(),
|
||||
"100771325212057665536"
|
||||
);
|
||||
map.put("userToken", userToken);
|
||||
log.info("loginVo userToken:{}", userToken);
|
||||
|
||||
String uploadId = new ObjectId().toHexString();
|
||||
FileUploadDTO fileUploadDTO = apaasMyTokenFeign.uploadFile(
|
||||
"Bearer " + userToken.getAccess_token(),
|
||||
"application/x-www-form-urlencoded",
|
||||
file,
|
||||
uploadId,
|
||||
"223770822127386625",
|
||||
"100771325212057665536"
|
||||
);
|
||||
map.put("fileUploadDTO", fileUploadDTO);
|
||||
log.info("loginVo fileUploadDTO:{}", fileUploadDTO);
|
||||
return Response.ok().data(map);
|
||||
}
|
||||
|
||||
@GetMapping("/downloadFile")
|
||||
public Response downloadFile(
|
||||
@RequestParam String url
|
||||
) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("xdaptenantid", "223770822127386625");
|
||||
cn.hutool.json.JSON json = JSONUtil.parse(map);
|
||||
String token = Base64.encode(json.toString());
|
||||
String realUrl = url +"&download=download&token="+token;
|
||||
return Response.ok().data(realUrl);
|
||||
}
|
||||
|
||||
@GetMapping("getAll")
|
||||
public Response getAll() {
|
||||
List<Template> templates = bd.getBusinessDatabase().doQuery(Template.class);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.xdap.self_development.controller.form;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
@ -35,7 +36,7 @@ public class SaveBenchmarkingReportForm {
|
||||
@NotBlank(message = "项目编号不能为空")
|
||||
private String projectNumber;
|
||||
|
||||
private String fileUrl;
|
||||
private MultipartFile file;
|
||||
|
||||
@NotEmpty(message = "校对人员不能为空")
|
||||
private List<String> proofreadUsers;
|
||||
|
||||
@ -1,13 +1,23 @@
|
||||
package com.xdap.self_development.feign;
|
||||
|
||||
import com.xdap.common.config.FeignConfig;
|
||||
import com.xdap.self_development.feign.dto.AppTokenDTO;
|
||||
import com.xdap.self_development.feign.dto.FileUploadDTO;
|
||||
import com.xdap.self_development.feign.dto.UserTokenDT0;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@FeignClient(name = "apaas-client", url = "${apaas.token.url}")
|
||||
import java.util.Map;
|
||||
|
||||
@FeignClient(
|
||||
name = "apaas-client",
|
||||
url = "${apaas.token.url}",
|
||||
configuration = FeignConfig.class
|
||||
)
|
||||
public interface ApaasMyTokenFeign {
|
||||
// 获取应用凭证
|
||||
@PostMapping("/xdap-open/token")
|
||||
AppTokenDTO getAppToken(
|
||||
@RequestParam("grant_type") String grant_type,
|
||||
@ -15,9 +25,23 @@ public interface ApaasMyTokenFeign {
|
||||
@RequestParam("client_secret")String client_secret
|
||||
);
|
||||
|
||||
@PostMapping("/xdap-open/token/userToken")
|
||||
// 获取用户凭证
|
||||
@GetMapping("/xdap-open/token/userToken")
|
||||
UserTokenDT0 getUserToken(
|
||||
@RequestParam("token") String token,
|
||||
@RequestParam("userid") String userid
|
||||
@RequestParam("userId") String userId
|
||||
);
|
||||
|
||||
// 上传文件
|
||||
@PostMapping(value = "/xdap-open/open/attachments/v1/simpleUploadFile",
|
||||
consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
FileUploadDTO uploadFile(
|
||||
@RequestHeader(value = "Authorization") String access_token,
|
||||
@RequestHeader("Content-Type") String type,
|
||||
|
||||
@RequestPart("file") MultipartFile file,
|
||||
@RequestPart("uploadId") String uploadId,
|
||||
@RequestPart("tenantId") String tenantId,
|
||||
@RequestPart("userId") String userId
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.xdap.self_development.feign.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FileDataDTO {
|
||||
private String id;
|
||||
private String userId;
|
||||
private String url;
|
||||
private String fileName;
|
||||
private String fileType;
|
||||
private String fileSize;
|
||||
private String fileSizeStr;
|
||||
private String ossBucketName;
|
||||
private String ossObjectName;
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.xdap.self_development.feign.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FileUploadDTO {
|
||||
private String code;
|
||||
private String message;
|
||||
private FileDataDTO data;
|
||||
}
|
||||
@ -9,6 +9,10 @@ import com.xdap.self_development.config.BusinessDatabase;
|
||||
import com.xdap.self_development.controller.form.BenchmarkingReportPageForm;
|
||||
import com.xdap.self_development.controller.form.HandleApprovalRequest;
|
||||
import com.xdap.self_development.controller.form.SaveBenchmarkingReportForm;
|
||||
import com.xdap.self_development.feign.ApaasMyTokenFeign;
|
||||
import com.xdap.self_development.feign.dto.AppTokenDTO;
|
||||
import com.xdap.self_development.feign.dto.FileUploadDTO;
|
||||
import com.xdap.self_development.feign.dto.UserTokenDT0;
|
||||
import com.xdap.self_development.pojo.ApprovalFlow;
|
||||
import com.xdap.self_development.pojo.ApprovalRecord;
|
||||
import com.xdap.self_development.pojo.ApprovalXdapUsers;
|
||||
@ -17,11 +21,14 @@ import com.xdap.self_development.pojo.view.ApprovalFlowView;
|
||||
import com.xdap.self_development.pojo.view.ApprovalNodeView;
|
||||
import com.xdap.self_development.pojo.view.TodoAndReportView;
|
||||
import com.xdap.self_development.service.BenchmarkingReportService;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Timestamp;
|
||||
@ -37,6 +44,14 @@ public class BenchmarkingReportServiceImpl implements BenchmarkingReportService
|
||||
private StringRedisTemplate redisTemplate;
|
||||
@Resource
|
||||
private RuntimeAppContextService runtimeAppContextService;
|
||||
@Autowired
|
||||
private ApaasMyTokenFeign apaasMyTokenFeign;
|
||||
|
||||
@Value("${apaas.token.clientId}")
|
||||
private String clientId;
|
||||
@Value("${apaas.token.clientSecred}")
|
||||
private String clientSecret;
|
||||
|
||||
|
||||
private static final String TODO_PREFIX = "report:todo:";
|
||||
private static final String NODE_PROCESSED_PREFIX = "report:node:processed:";
|
||||
@ -47,12 +62,14 @@ public class BenchmarkingReportServiceImpl implements BenchmarkingReportService
|
||||
@Transactional
|
||||
public void saveBenchmarkingReport(SaveBenchmarkingReportForm form) {
|
||||
// 1. 创建对标报告并保存
|
||||
String currentTenantId = runtimeAppContextService.getCurrentTenantId();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("xdaptenantid", currentTenantId);
|
||||
cn.hutool.json.JSON json = JSONUtil.parse(map);
|
||||
String token = Base64.encode(json.toString());
|
||||
String realUrl = form.getFileUrl()+"&download=download&token="+token;
|
||||
String realUrl = "";
|
||||
if (form.getFile() != null) {
|
||||
realUrl = uploadFile(form.getFile(), form.getCreateBy());
|
||||
if (realUrl.isEmpty()) {
|
||||
throw new MpaasBusinessException("附件上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
BenchmarkingReport report = new BenchmarkingReport();
|
||||
BeanUtils.copyProperties(form, report);
|
||||
report.setFilePath(realUrl);
|
||||
@ -81,6 +98,35 @@ public class BenchmarkingReportServiceImpl implements BenchmarkingReportService
|
||||
});
|
||||
}
|
||||
|
||||
private String uploadFile(MultipartFile file, String userId) {
|
||||
String currentTenantId = runtimeAppContextService.getCurrentTenantId();
|
||||
AppTokenDTO token = apaasMyTokenFeign.getAppToken(
|
||||
"client_credentials",
|
||||
clientId,
|
||||
clientSecret
|
||||
);
|
||||
|
||||
UserTokenDT0 userToken = apaasMyTokenFeign.getUserToken(
|
||||
token.getAccess_token(),
|
||||
userId
|
||||
);
|
||||
|
||||
String uploadId = new ObjectId().toHexString();
|
||||
FileUploadDTO fileUploadDTO = apaasMyTokenFeign.uploadFile(
|
||||
"Bearer " + userToken.getAccess_token(),
|
||||
"application/x-www-form-urlencoded",
|
||||
file,
|
||||
uploadId,
|
||||
currentTenantId,
|
||||
userId
|
||||
);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("xdaptenantid", currentTenantId);
|
||||
cn.hutool.json.JSON json = JSONUtil.parse(map);
|
||||
String tokenXdap = Base64.encode(json.toString());
|
||||
return fileUploadDTO.getData().getUrl() +"&download=download&token=" + tokenXdap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TodoAndReportView> getBenchmarkingReportByCondition(BenchmarkingReportPageForm form) {
|
||||
List<TodoAndReportView> approvalList = new ArrayList<>();
|
||||
|
||||
@ -51,13 +51,6 @@ public class ResponsiblePersonServiceImpl implements ResponsiblePersonService {
|
||||
|
||||
@Override
|
||||
public void updateResponsiblePerson(UpdateResponsiblePersonForm form) {
|
||||
List<ResponsiblePerson> responsiblePeople = bd.getBusinessDatabase()
|
||||
.eq("department_id", form.getDepartmentId())
|
||||
.doQuery(ResponsiblePerson.class);
|
||||
if (!responsiblePeople.isEmpty()) {
|
||||
throw new MpaasBusinessException("该部门已有责任人");
|
||||
}
|
||||
|
||||
bd.getBusinessDatabase()
|
||||
.rowid("id", form.getRowId())
|
||||
.update("department_id", form.getDepartmentId())
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
apaas.token.url=http://apaas-meim.app.yuchai.com/apaas/backend/a5e8e08/ycgf-yf-rddata
|
||||
apaas.token.clientId=2b5b3de8-e7fd-406a-a59a-d5568457b1f4
|
||||
apaas.token.clientSecred=94bddc6a-27a4-4204-885b-b075812ec535
|
||||
|
||||
feign.hystrix.enabled=false
|
||||
deploy.backend.platform.port=30607
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user