forked from Gitlink/microservices
Compare commits
216 Commits
master
...
dev_monito
| Author | SHA1 | Date |
|---|---|---|
|
|
855dca9d84 | |
|
|
d43988239c | |
|
|
02791388bd | |
|
|
5d14d5e56a | |
|
|
e3ddab5ceb | |
|
|
587a2707a7 | |
|
|
992c17b4c8 | |
|
|
0aa96e853a | |
|
|
34ab56eb8a | |
|
|
bdbd2da88d | |
|
|
30f8ce8184 | |
|
|
7fbfbdaf8d | |
|
|
93ed7838e6 | |
|
|
68988926b9 | |
|
|
5485d39894 | |
|
|
2516ba038e | |
|
|
bb9b4f05da | |
|
|
4bbf3c91e2 | |
|
|
00bde1ad9a | |
|
|
092d566de4 | |
|
|
27c5e64e1a | |
|
|
71f4e4bc8f | |
|
|
8c8e13a5e1 | |
|
|
82c74b9184 | |
|
|
290fc64c88 | |
|
|
b0aede3f93 | |
|
|
902f961469 | |
|
|
e904d854f6 | |
|
|
3dbdef7ab8 | |
|
|
072e85de82 | |
|
|
8f48c1030a | |
|
|
9380081443 | |
|
|
0646a3b773 | |
|
|
43e75440d5 | |
|
|
0ca345d200 | |
|
|
83c1457c50 | |
|
|
3f208de48a | |
|
|
bce79534bd | |
|
|
f402ec1748 | |
|
|
7de259d088 | |
|
|
1c9bc630d8 | |
|
|
c13748d494 | |
|
|
69e789d856 | |
|
|
02f215c2e4 | |
|
|
d1076e48d5 | |
|
|
b25411e35c | |
|
|
1f3d65fd39 | |
|
|
3f155f2270 | |
|
|
ee77bdb8a1 | |
|
|
631f6752a6 | |
|
|
39a8dde543 | |
|
|
0f0a639bf4 | |
|
|
cf2c5cffa3 | |
|
|
b89c235df3 | |
|
|
2d5d43b37e | |
|
|
32b58df5d1 | |
|
|
555ef0fc80 | |
|
|
46cbaccf64 | |
|
|
ebf1dc53cf | |
|
|
e6dadf2ccd | |
|
|
71cf4fb6fc | |
|
|
eed4b9d9eb | |
|
|
cad9ea1247 | |
|
|
02e369849d | |
|
|
f7e9d9350e | |
|
|
356b85fd35 | |
|
|
19a32e2f7c | |
|
|
b2f9921664 | |
|
|
2567386baa | |
|
|
8e10fee65f | |
|
|
310b423ec9 | |
|
|
705823ec3f | |
|
|
172e0ee92e | |
|
|
726ece8af9 | |
|
|
82f180d31c | |
|
|
e91ee14d63 | |
|
|
10a1b3f5cf | |
|
|
7f22a2c6ec | |
|
|
9c76980bdc | |
|
|
a861d69061 | |
|
|
53274c3b0e | |
|
|
32ded69b77 | |
|
|
36e9d84dd8 | |
|
|
4e0d281bf7 | |
|
|
fbcbe63ad4 | |
|
|
48e0510bb3 | |
|
|
3726e4b294 | |
|
|
335d05d2c3 | |
|
|
fa4ee4526b | |
|
|
405b2e07c1 | |
|
|
c6fd9a1c9d | |
|
|
bfbaa3491d | |
|
|
c97b64f3bc | |
|
|
83c8d5fe3e | |
|
|
7cff154598 | |
|
|
d0fcf1fbce | |
|
|
3cf7ced976 | |
|
|
ddb1a06acc | |
|
|
0c94e636e1 | |
|
|
0f2d37babe | |
|
|
6e72d6f762 | |
|
|
d330e7a56d | |
|
|
29dbc84989 | |
|
|
f055d0f28e | |
|
|
20ce451a9a | |
|
|
629822dcb9 | |
|
|
e7ca96f280 | |
|
|
f9956c305e | |
|
|
d13b38e980 | |
|
|
45c84d17b6 | |
|
|
71ec75c3e5 | |
|
|
0d0b0072c3 | |
|
|
8f84d425c8 | |
|
|
1cb6c3e758 | |
|
|
17a911c54e | |
|
|
adc86b04c9 | |
|
|
cd19bd94cc | |
|
|
dc814cffff | |
|
|
92bfd2c7f2 | |
|
|
6a71629784 | |
|
|
1e016300c7 | |
|
|
fdf61667f7 | |
|
|
22f350510c | |
|
|
2566f119d3 | |
|
|
19718b6123 | |
|
|
3fa2daac28 | |
|
|
2d304cfae0 | |
|
|
1f2f48c120 | |
|
|
19e298b67a | |
|
|
f70681d783 | |
|
|
8abb5a38bd | |
|
|
9eb10143f7 | |
|
|
9865c8bad9 | |
|
|
bc92fb8419 | |
|
|
a25048faad | |
|
|
8c068c4b79 | |
|
|
735d7fd9e9 | |
|
|
705a9241b6 | |
|
|
03b7c170e4 | |
|
|
0c0f27810e | |
|
|
4fd5c1cc4d | |
|
|
65a5b5d081 | |
|
|
e97b972f31 | |
|
|
828901d322 | |
|
|
33185a1d0c | |
|
|
29b6b2bbae | |
|
|
2883029641 | |
|
|
5eed69522c | |
|
|
c5d99153b8 | |
|
|
6f4a10f1cb | |
|
|
c6f58972a6 | |
|
|
53795b1b88 | |
|
|
1f653894cd | |
|
|
5af3df62ee | |
|
|
fde9893840 | |
|
|
e44f63a4c6 | |
|
|
6d47364cca | |
|
|
128a107f8f | |
|
|
65aaa7df5b | |
|
|
b1da0ba006 | |
|
|
ad3625a823 | |
|
|
115a3cbe12 | |
|
|
c9d08ef3d5 | |
|
|
3f795fadb5 | |
|
|
672476ba53 | |
|
|
1f55a7835e | |
|
|
0b16dbf195 | |
|
|
8111f6db61 | |
|
|
ae073b68bc | |
|
|
14072b1dff | |
|
|
12eecde9c4 | |
|
|
66e1b9aca6 | |
|
|
93e56ed555 | |
|
|
13d5e7aa46 | |
|
|
dc9a537feb | |
|
|
3d5d6bfc6e | |
|
|
bac9eeda5f | |
|
|
18f89d1b8e | |
|
|
c3b5dcafba | |
|
|
a0aec9bf88 | |
|
|
a511f39a13 | |
|
|
75f828b76c | |
|
|
4b1042c25d | |
|
|
e9c41768e1 | |
|
|
15aa7016b9 | |
|
|
f96cee3f4a | |
|
|
055b26ee29 | |
|
|
368a45e8b2 | |
|
|
2c5f0518ca | |
|
|
06fbbf7208 | |
|
|
6613950ff8 | |
|
|
8184eb2401 | |
|
|
213aee5587 | |
|
|
274af358dd | |
|
|
58bf8326c5 | |
|
|
5e19e53b94 | |
|
|
2be36ca12e | |
|
|
ad405c912e | |
|
|
6ef1fafac8 | |
|
|
39d43e3d68 | |
|
|
1eefa65c32 | |
|
|
c6b4a1bd80 | |
|
|
21ba1ce6bd | |
|
|
dd870b3cd3 | |
|
|
417d440549 | |
|
|
67b2e9ce7c | |
|
|
32b83749e2 | |
|
|
010d5e5354 | |
|
|
94e0be0e71 | |
|
|
2845d19aae | |
|
|
97b1c9437c | |
|
|
b0f9e06e18 | |
|
|
f58af4b0b5 | |
|
|
78cbd4b0ee | |
|
|
fca8490bdd | |
|
|
616bf1229f |
|
|
@ -9,8 +9,6 @@ import com.microservices.system.api.factory.RemoteCmsFallbackFactory;
|
|||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
|
|
@ -160,22 +158,4 @@ public interface RemoteCmsService {
|
|||
@GetMapping("/doc/getJSONObject/{cmsDocId}")
|
||||
R<JSONObject> selectCmsDocJSONObjectById(@PathVariable(value = "cmsDocId") Long cmsDocId
|
||||
, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
@PutMapping("/project/changeOrgRole/user/{userId}/operate/{operate}")
|
||||
R<Boolean> changeUserOrgRole(@PathVariable("userId") Long userId, @PathVariable("operate") int operate
|
||||
, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 首页文章合并列表(接收置顶文章 docId 有序列表,返回合并去重后的结果)
|
||||
* 供 Zone 服务 /open/getTopDoc 改造后调用
|
||||
*
|
||||
* @param zoneId 专区ID
|
||||
* @param topDocIds 置顶文章 docId 有序列表
|
||||
* @param source 来源
|
||||
* @return 合并后的首页文章 JSONObject 列表
|
||||
*/
|
||||
@PostMapping("/doc/homePageDocMergeList/{zoneId}")
|
||||
R<List<JSONObject>> selectHomePageDocMergeList(@PathVariable("zoneId") Long zoneId,
|
||||
@RequestBody List<Long> topDocIds,
|
||||
@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public interface RemoteDeptService {
|
|||
* 根据组织id删除部门
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @param source 请求来源
|
||||
* @param source 请求来源
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/dept/deleteDeptByDeptId")
|
||||
|
|
@ -105,7 +105,7 @@ public interface RemoteDeptService {
|
|||
* 通过用户名查询用户下组织及组织对应角色列表
|
||||
*
|
||||
* @param deptId 组织ID
|
||||
* @param source 请求来源
|
||||
* @param source 请求来源
|
||||
* @return 用户下组织及组织对应角色列表
|
||||
*/
|
||||
@GetMapping("/SysUserDeptRole/userByDeptId/{deptId}/list")
|
||||
|
|
@ -115,7 +115,7 @@ public interface RemoteDeptService {
|
|||
/**
|
||||
* 查询组织编号下拥有传入角色权限字符串的用户名
|
||||
*
|
||||
* @param deptId 组织编号
|
||||
* @param deptId 组织编号
|
||||
* @param roleKeys 角色权限字符串
|
||||
* @return 组织下拥有传入角色权限字符串的用户名列表
|
||||
*/
|
||||
|
|
@ -126,7 +126,7 @@ public interface RemoteDeptService {
|
|||
* 检查用户是否在指定部门下具有指定角色
|
||||
*
|
||||
* @param currentDeptId 组织编号
|
||||
* @param roleKey 角色权限字符串
|
||||
* @param roleKey 角色权限字符串
|
||||
* @return 组织下拥有传入角色权限字符串的用户名列表
|
||||
*/
|
||||
@GetMapping("/SysUserDeptRole/checkUserInDeptHasRole")
|
||||
|
|
@ -143,17 +143,6 @@ public interface RemoteDeptService {
|
|||
@GetMapping("/SysUserDeptRole/checkUserInDeptHasPerms")
|
||||
R<Boolean> checkUserInDeptHasPerms(@RequestParam("currentDeptId") Long currentDeptId, @RequestParam("userId") Long userId, @RequestParam("perms") String perms, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 检查用户是否在指定部门或指定部门的父级部门下具有指定菜单权限
|
||||
*
|
||||
* @param deptId 指定组织id
|
||||
* @param userId 用户id
|
||||
* @param perms 菜单权限
|
||||
* @return 用户是否在指定部门下具有菜单权限 是true 否false
|
||||
*/
|
||||
@GetMapping("/SysUserDeptRole/checkUserInDeptOrParentDeptHasPerms")
|
||||
R<Boolean> checkUserInDeptOrParentDeptHasPerms(@RequestParam("deptId") Long deptId, @RequestParam("userId") Long userId, @RequestParam("perms") String perms, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 检查用户是否在指定部门下
|
||||
*
|
||||
|
|
@ -163,7 +152,4 @@ public interface RemoteDeptService {
|
|||
*/
|
||||
@GetMapping("/SysUserDeptRole/checkUserInDept")
|
||||
R<Boolean> checkUserInDept(@RequestParam("currentDeptId") Long currentDeptId, @RequestParam("userId") Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
@GetMapping("/SysUserDeptRole/getSysUserDeptRoleByDeptIdAndUserId")
|
||||
R<SysUserDeptRole> getSysUserDeptRoleByDeptIdAndUserId(@RequestParam("deptId") Long deptId, @RequestParam("userId") Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ package com.microservices.system.api;
|
|||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.constant.ServiceNameConstants;
|
||||
import com.microservices.common.core.constant.TokenConstants;
|
||||
import com.microservices.system.api.factory.RemoteGatewayFallbackFactory;
|
||||
import com.microservices.system.api.model.GraphqlQueryVo;
|
||||
import feign.Response;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -28,6 +28,14 @@ public interface RemoteGatewayService {
|
|||
@PostMapping("/sentinel/auth/login")
|
||||
Response loginSentinel(@RequestParam("username") String username, @RequestParam("password") String password);
|
||||
|
||||
/**
|
||||
* 登录Rancher
|
||||
*
|
||||
* @return 响应
|
||||
*/
|
||||
@PostMapping("/rancher/v3-public/localProviders/local?action=login")
|
||||
Response loginRancher(@RequestBody JSONObject loginBody);
|
||||
|
||||
/**
|
||||
* 登录Nacos
|
||||
*
|
||||
|
|
@ -43,4 +51,45 @@ public interface RemoteGatewayService {
|
|||
*/
|
||||
@PostMapping("/portainer/api/auth")
|
||||
Response loginPortainer(@RequestBody JSONObject loginBody);
|
||||
|
||||
@GetMapping("/prometheus/api/v1/query")
|
||||
JSONObject getPrometheusQueryRes(@RequestParam("query") String query,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/prometheus/api/v1/query_range")
|
||||
JSONObject getPrometheusQueryRangeRes(@RequestParam("query") String query,
|
||||
@RequestParam("step") Long step,
|
||||
@RequestParam("start") Long start,
|
||||
@RequestParam("end") Long end,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@PostMapping("/skywalking/graphql")
|
||||
JSONObject executeSkywalkingGql(@RequestBody GraphqlQueryVo gqlBody);
|
||||
|
||||
@GetMapping("/sentinel/app/briefinfos.json")
|
||||
JSONObject getSentinelAppList(@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/nacos/v1/ns/catalog/services?pageNo=1&pageSize=999")
|
||||
JSONObject getNacosServiceList(@RequestParam("serviceNameParam") String serviceNameParam, @RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/nacos/v1/cs/configs?types=yaml&search=blur&group=&pageNo=1&pageSize=10")
|
||||
JSONObject getGatewayNacosConfigList(@RequestParam("dataId") String dataId, @RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/nacos/v1/cs/listener")
|
||||
JSONObject getNacosConfigList(@RequestParam("ip") String ip, @RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/nacos/v1/cs/configs")
|
||||
String getNacosConfigDetail(@RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@PostMapping(value = "/nacos/v1/cs/configs", consumes = {"application/x-www-form-urlencoded"})
|
||||
Response updateNacosConfig(Map<String, ?> formParams, @RequestHeader(TokenConstants.AUTHENTICATION) String userKey);
|
||||
|
||||
@PostMapping("/es/{esIndex}/_search")
|
||||
JSONObject executeElasticsearchQuery(@PathVariable("esIndex") String esIndex, @RequestBody JSONObject esBody);
|
||||
|
||||
@PostMapping("/es/{esIndex}/_doc/{docId}/_update")
|
||||
JSONObject executeElasticsearchUpdate(@PathVariable("esIndex") String esIndex,@PathVariable("docId") String docId, @RequestBody JSONObject esBody);
|
||||
|
||||
@PostMapping("/gns/notification/gitlink")
|
||||
JSONObject sendNotification(@RequestBody JSONObject body);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,127 @@
|
|||
package com.microservices.system.api;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.constant.Constants;
|
||||
import com.microservices.common.core.constant.SecurityConstants;
|
||||
import com.microservices.common.core.constant.ServiceNameConstants;
|
||||
import com.microservices.common.core.constant.TokenConstants;
|
||||
import com.microservices.system.api.factory.RemoteGatewayFallbackFactory;
|
||||
import com.microservices.system.api.factory.RemoteRancherFallbackFactory;
|
||||
import feign.Response;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 网关
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Component
|
||||
@FeignClient(contextId = "RemoteRancherService", value = ServiceNameConstants.GATEWAY_SERVICE, fallbackFactory = RemoteRancherFallbackFactory.class)
|
||||
public interface RemoteRancherService {
|
||||
@GetMapping("/rancher/v3/clusters/{cluster_id}/namespaces")
|
||||
Response getK8sNamespaceList(@PathVariable("cluster_id") String cluster_id,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/api/v1/namespaces")
|
||||
Response getK8sNamespaceListNative(@PathVariable("cluster_id") String cluster_id,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/apps.daemonsets?exclude=metadata.managedFields")
|
||||
Response getK8sDaemonsetsList(@PathVariable("cluster_id") String cluster_id,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/apps.deployments?exclude=metadata.managedFields")
|
||||
Response getK8sDeployList(@PathVariable("cluster_id") String cluster_id,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/apps.statefulsets?exclude=metadata.managedFields")
|
||||
Response getK8sStatefulList(@PathVariable("cluster_id") String cluster_id,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/nodes?exclude=metadata.managedFields")
|
||||
Response getK8sClusterNodeList(@PathVariable("cluster_id") String cluster_id,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/{fullKind}/{namespace}/{applicationName}")
|
||||
Response getK8sApplicationDetail(@PathVariable("cluster_id") String cluster_id,
|
||||
@PathVariable("fullKind") String fullKind,
|
||||
@PathVariable("namespace") String namespace,
|
||||
@PathVariable("applicationName") String applicationName,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/pods/{namespace}")
|
||||
Response getK8sPodListByNamespace(@PathVariable("cluster_id") String cluster_id,
|
||||
@PathVariable("namespace") String namespace,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/pods")
|
||||
Response getK8sPodList(@PathVariable("cluster_id") String cluster_id,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/services/{nginxApplicationId}")
|
||||
Response getK8sServiceByApplicationId(@PathVariable("cluster_id") String cluster_id,
|
||||
@PathVariable("nginxApplicationId") String nginxApplicationId,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@DeleteMapping("/rancher/v1/pods/{namespace}/{podName}")
|
||||
Response deletePod(@PathVariable("namespace") String namespace,
|
||||
@PathVariable("podName") String podName,
|
||||
@RequestBody JSONObject deletePodBody,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@PutMapping("/rancher/v1/{fullKind}/{namespace}/{applicationName}")
|
||||
Response updateK8sApplication(@PathVariable("fullKind") String fullKind,
|
||||
@PathVariable("namespace") String namespace,
|
||||
@PathVariable("applicationName") String applicationName,
|
||||
@RequestBody JSONObject applicationDetail,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String userKey);
|
||||
|
||||
@PostMapping(value = "/rancher/v1/{fullKind}", consumes = {Constants.YAML_CONTENT_TYPE})
|
||||
Response createK8sApplication(@PathVariable("fullKind") String fullName,
|
||||
@RequestBody String yamlContent,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String userKey);
|
||||
|
||||
@PostMapping(value = "/rancher/v1/management.cattle.io.clusters/{cluster_id}?action=apply")
|
||||
Response applyK8sYaml(@PathVariable("cluster_id") String cluster_id,
|
||||
@RequestBody JSONObject yamlContent,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String userKey);
|
||||
|
||||
@GetMapping("/rancher/apis/apps/v1/namespaces/{namespace}/{kindName}/{applicationName}")
|
||||
Response getApplicationYamlFile(@PathVariable("kindName") String kindName,
|
||||
@PathVariable("namespace") String namespace,
|
||||
@PathVariable("applicationName") String applicationName,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@PutMapping(value = "/rancher/v1/{fullKind}/{namespace}/{applicationName}", consumes = {Constants.YAML_CONTENT_TYPE})
|
||||
Response editK8sApplication(@PathVariable("fullKind") String fullKind,
|
||||
@PathVariable("namespace") String namespace,
|
||||
@PathVariable("applicationName") String applicationName,
|
||||
@RequestBody String yamlContent,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@DeleteMapping("/rancher/v1/{fullKind}/{namespace}/{applicationName}")
|
||||
Response deleteApplication(@PathVariable("fullKind") String fullKind,
|
||||
@PathVariable("namespace") String namespace,
|
||||
@PathVariable("applicationName") String applicationName,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/v1/configmaps/{namespace}")
|
||||
Response getK8sConfigmapByNamespace(@PathVariable("namespace") String namespace,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/v1/secrets/{namespace}")
|
||||
Response getK8sSecretByNamespace(@PathVariable("namespace") String namespace,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/rancher/k8s/clusters/{cluster_id}/v1/services/{namespace}")
|
||||
Response getK8sServiceByNamespace(@PathVariable("cluster_id") String cluster_id,
|
||||
@PathVariable("namespace") String namespace,
|
||||
@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
|
||||
|
||||
@DeleteMapping("/rancher/v1/services/{serviceId}")
|
||||
Response deleteK8sService(@PathVariable("serviceId") String serviceId,@RequestHeader(TokenConstants.AUTHENTICATION) String token);
|
||||
}
|
||||
|
|
@ -57,15 +57,6 @@ public interface RemoteUserService {
|
|||
@GetMapping("/user/getSysUserByUserId/{userId}")
|
||||
public R<SysUser> getSysUserByUserId(@PathVariable("userId") Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 通过用户ID数组批量获取用户信息(POST方法,解决URL长度限制)
|
||||
*
|
||||
* @param userIds 用户ID数组
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/user/getSysUserListByUserIds")
|
||||
R<List<SysUser>> postSysUserListByUserIds(@RequestBody Long[] userIds, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 组织下新增用户身份
|
||||
|
|
@ -73,7 +64,7 @@ public interface RemoteUserService {
|
|||
* @param deptId
|
||||
* @param userId
|
||||
* @param roleKey
|
||||
* @param source 请求来源
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/SysUserDeptRole/dept/{deptId}/user/{userId}/role/{roleKey}")
|
||||
|
|
@ -83,13 +74,14 @@ public interface RemoteUserService {
|
|||
, @PathVariable("roleKey") String roleKey
|
||||
, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
|
||||
/**
|
||||
* 组织下删除用户身份
|
||||
*
|
||||
* @param deptId
|
||||
* @param userId
|
||||
* @param roleKey
|
||||
* @param source 请求来源
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@DeleteMapping("/SysUserDeptRole/dept/{deptId}/user/{userId}/role/{roleKey}")
|
||||
|
|
@ -99,16 +91,18 @@ public interface RemoteUserService {
|
|||
@PathVariable("roleKey") String roleKey,
|
||||
@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
|
||||
/**
|
||||
* 注册用户信息
|
||||
*
|
||||
* @param sysUser 用户信息
|
||||
* @param source 请求来源
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/user/register")
|
||||
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
|
||||
/**
|
||||
* 通过GitLinkToken获取本系统Token
|
||||
*
|
||||
|
|
@ -129,6 +123,7 @@ public interface RemoteUserService {
|
|||
@GetMapping("/SysUserDeptRole/userByUserName/{userName}/list")
|
||||
public R<List<SysUserDeptRole>> getSysUserDeptRoleListByUserName(@PathVariable("userName") String userName, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户下第一个身份
|
||||
*
|
||||
|
|
@ -200,7 +195,7 @@ public interface RemoteUserService {
|
|||
/**
|
||||
* 通过GitLink用户Id创建用户
|
||||
*
|
||||
* @param gitLinkUserId GitLinkUserId
|
||||
* @param gitLinkUserId GitLink用户Id
|
||||
* @param source 请求来源
|
||||
* @return 系统用户
|
||||
*/
|
||||
|
|
@ -211,7 +206,7 @@ public interface RemoteUserService {
|
|||
* 根据角色Key获取菜单权限集合
|
||||
*
|
||||
* @param roleKey 角色Key
|
||||
* @param source 请求来源
|
||||
* @param source 请求来源
|
||||
* @return 菜单权限集合
|
||||
*/
|
||||
@GetMapping("/menu/roleMenuPermissionByRoleKey/{roleKey}")
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 内容管理服务降级处理
|
||||
*
|
||||
|
|
@ -85,16 +83,6 @@ public class RemoteCmsFallbackFactory implements FallbackFactory<RemoteCmsServic
|
|||
public R<JSONObject> selectCmsDocJSONObjectById(Long cmsDocId, String source) {
|
||||
return R.fail("获取文章JSON对象失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> changeUserOrgRole(Long userId, int operate, String source) {
|
||||
return R.fail("更新组织权限失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<JSONObject>> selectHomePageDocMergeList(Long zoneId, List<Long> topDocIds, String source) {
|
||||
return R.fail("获取首页文章合并列表失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,20 +83,10 @@ public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptServ
|
|||
return R.fail("检查用户是否在指定部门下具有指定菜单权限失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> checkUserInDeptOrParentDeptHasPerms(Long deptId, Long userId, String perms, String source) {
|
||||
return R.fail("检查用户是否在指定部门或指定部门的父级部门下具有指定菜单权限失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> checkUserInDept(Long currentDeptId, Long userId, String source) {
|
||||
return R.fail("检查用户是否在指定部门下失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<SysUserDeptRole> getSysUserDeptRoleByDeptIdAndUserId(Long deptId, Long userId, String source) {
|
||||
return R.fail("获取用户在指定部门下的角色失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.microservices.system.api.factory;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.system.api.RemoteGatewayService;
|
||||
import com.microservices.system.api.model.GraphqlQueryVo;
|
||||
import feign.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -25,7 +27,12 @@ public class RemoteGatewayFallbackFactory implements FallbackFactory<RemoteGatew
|
|||
return new RemoteGatewayService() {
|
||||
|
||||
@Override
|
||||
public Response loginSentinel(String password, String username) {
|
||||
public Response loginSentinel(String username, String password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response loginRancher(JSONObject loginBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +43,66 @@ public class RemoteGatewayFallbackFactory implements FallbackFactory<RemoteGatew
|
|||
|
||||
@Override
|
||||
public Response loginPortainer(JSONObject loginBody) {
|
||||
System.out.println(throwable.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getPrometheusQueryRes(String query, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getPrometheusQueryRangeRes(String query, Long step, Long start, Long end, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject executeSkywalkingGql(GraphqlQueryVo gqlBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getSentinelAppList(String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNacosServiceList(String serviceNameParam, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getGatewayNacosConfigList(String dataId, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNacosConfigList(String ip, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNacosConfigDetail(String dataId, String group, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response updateNacosConfig(Map<String, ?> formParams, String userKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject executeElasticsearchQuery(String esIndex, JSONObject esBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject executeElasticsearchUpdate(String esIndex, String docId, JSONObject esBody) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject sendNotification(JSONObject body) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,138 @@
|
|||
package com.microservices.system.api.factory;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.system.api.RemoteGatewayService;
|
||||
import com.microservices.system.api.RemoteRancherService;
|
||||
import com.microservices.system.api.utils.FeignUtils;
|
||||
import feign.FeignException;
|
||||
import feign.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Component
|
||||
public class RemoteRancherFallbackFactory implements FallbackFactory<RemoteRancherService> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteRancherFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteRancherService create(Throwable throwable) {
|
||||
log.error("Rancher服务调用失败:{}", throwable.getMessage());
|
||||
|
||||
return new RemoteRancherService() {
|
||||
@Override
|
||||
public Response getK8sNamespaceList(String cluster_id, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sNamespaceListNative(String cluster_id, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sDaemonsetsList(String cluster_id, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sDeployList(String cluster_id, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sStatefulList(String cluster_id, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sClusterNodeList(String cluster_id, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sApplicationDetail(String cluster_id, String fullKind, String namespace, String applicationName, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sPodListByNamespace(String cluster_id, String namespace, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sPodList(String cluster_id, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sServiceByApplicationId(String cluster_id, String nginxApplicationId, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response deletePod(String namespace, String podName, JSONObject deletePodBody, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response updateK8sApplication(String fullKind, String namespace, String applicationName, JSONObject applicationDetail, String userKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response createK8sApplication(String fullName, String yamlContent, String userKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response applyK8sYaml(String cluster_id, JSONObject yamlContent, String userKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getApplicationYamlFile(String kindName, String namespace, String applicationName, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response editK8sApplication(String fullKind, String namespace, String applicationName, String yamlContent, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response deleteApplication(String fullKind, String namespace, String applicationName, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sConfigmapByNamespace(String namespace, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sSecretByNamespace(String namespace, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getK8sServiceByNamespace(String cluster_id, String namespace, String token) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response deleteK8sService(String serviceId, String token) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -52,12 +52,6 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
return R.fail("获取用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<SysUser>> postSysUserListByUserIds(Long[] userIds, String source) {
|
||||
|
||||
return R.fail("批量获取用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Boolean> addUserIdentify(Long deptId, Long userId, String roleKey, String source) {
|
||||
return R.fail("组织下新增用户身份失败:" + throwable.getMessage());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package com.microservices.system.api.model;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GraphqlQueryVo {
|
||||
String operationName;
|
||||
String query;
|
||||
JSONObject variables;
|
||||
}
|
||||
|
|
@ -3,20 +3,24 @@ package com.microservices.system.api.utils;
|
|||
import com.microservices.common.core.domain.R;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import feign.Response;
|
||||
|
||||
/**
|
||||
* @author otto
|
||||
*/
|
||||
public class FeignUtils {
|
||||
public static <T> T getReturnData(R<T> result){
|
||||
public static <T> T getReturnData(R<T> result) {
|
||||
if (StringUtils.isNull(result)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (R.FAIL == result.getCode())
|
||||
{
|
||||
if (R.FAIL == result.getCode()) {
|
||||
throw new ServiceException(result.getMsg());
|
||||
}
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
public static Boolean isSuccess(Response response) {
|
||||
return response != null && response.status() >= 200 && response.status() < 300;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,3 +6,4 @@ com.microservices.system.api.factory.RemoteCmsFallbackFactory
|
|||
com.microservices.system.api.factory.RemoteZoneFallbackFactory
|
||||
com.microservices.system.api.factory.RemotePmsFallbackFactory
|
||||
com.microservices.system.api.factory.RemoteGatewayFallbackFactory
|
||||
com.microservices.system.api.factory.RemoteRancherFallbackFactory
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9110
|
||||
port: 8080
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
|||
|
|
@ -80,10 +80,6 @@ public class CacheConstants {
|
|||
* 通过组织Id获取专区详情JSON对象
|
||||
*/
|
||||
public final static String ZONE_JSON_OF_DEPT_ID_KEY = "zoneJSONOfDeptId:";
|
||||
/**
|
||||
* 积分发放部门
|
||||
*/
|
||||
public final static String ZONE_POINTS_DEPT_ID_KEY = "zonePointsDeptId";
|
||||
/**
|
||||
* 内容管理同步缓存前缀
|
||||
*/
|
||||
|
|
@ -217,6 +213,11 @@ public class CacheConstants {
|
|||
*/
|
||||
public final static String SENTINEL_TOKEN = "sentinel_token";
|
||||
|
||||
/**
|
||||
* Rancher Token缓存Key
|
||||
*/
|
||||
public final static String RANCHER_TOKEN = "rancher_token";
|
||||
|
||||
|
||||
/**
|
||||
* Nacos Token缓存Key
|
||||
|
|
@ -249,18 +250,6 @@ public class CacheConstants {
|
|||
return ZONE_PROJECT_SORT_BY_SCORE + "*:" + zoneId + ":*";
|
||||
}
|
||||
|
||||
/**
|
||||
* 专区统计数据缓存前缀
|
||||
*/
|
||||
private final static String ZONE_STATISTICS_KEY = "zone:statistics:";
|
||||
|
||||
/**
|
||||
* 获取专区统计数据缓存key
|
||||
*/
|
||||
public static String getZoneStatisticsKey(Long zoneId) {
|
||||
return ZONE_STATISTICS_KEY + zoneId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件打包是否完成(0:代表未完成;1:代表已完成;-1:代表打包失败,需要重新打包)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ package com.microservices.common.core.constant;
|
|||
*
|
||||
* @author microservices
|
||||
*/
|
||||
public class Constants
|
||||
{
|
||||
public class Constants {
|
||||
/**
|
||||
* UTF-8 字符集
|
||||
*/
|
||||
|
|
@ -125,6 +124,10 @@ public class Constants
|
|||
* JSON类型
|
||||
*/
|
||||
public static final String JSON_CONTENT_TYPE = "application/json";
|
||||
/**
|
||||
* Yaml类型
|
||||
*/
|
||||
public static final String YAML_CONTENT_TYPE = "application/yaml";
|
||||
/**
|
||||
* 文本类型
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ public class SecurityConstants
|
|||
*/
|
||||
public static final String USER_KEY = "user_key";
|
||||
|
||||
/**
|
||||
* 用户Token
|
||||
*/
|
||||
public static final String TOKEN = "token";
|
||||
|
||||
/**
|
||||
* 组织ID
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -22,9 +22,16 @@ public class TokenConstants {
|
|||
* Sentinel令牌标识
|
||||
*/
|
||||
public static final String Sentinel_Token_Key = "sentinel_dashboard_cookie";
|
||||
/**
|
||||
* Rancher令牌标识
|
||||
*/
|
||||
public static final String Rancher_Cookie_Token_Key = "R_SESS";
|
||||
/**
|
||||
* Portainer令牌标识
|
||||
*/
|
||||
public static final String Portainer_Token_Key = "portainer_api_key";
|
||||
/**
|
||||
* Sentinel令牌标识
|
||||
* Nacos令牌标识
|
||||
*/
|
||||
public static final String Nacos_Token_Key = "Accesstoken";
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ package com.microservices.common.core.constant;
|
|||
*
|
||||
* @author microservices
|
||||
*/
|
||||
public class UserConstants {
|
||||
public class UserConstants
|
||||
{
|
||||
/**
|
||||
* 平台内系统用户的唯一标志
|
||||
*/
|
||||
|
|
@ -27,89 +28,55 @@ public class UserConstants {
|
|||
*/
|
||||
public static final String DEL_FLAG_FALSE = "0";
|
||||
|
||||
/**
|
||||
* 正常状态
|
||||
*/
|
||||
/** 正常状态 */
|
||||
public static final String NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 异常状态
|
||||
*/
|
||||
/** 异常状态 */
|
||||
public static final String EXCEPTION = "1";
|
||||
|
||||
/**
|
||||
* 用户封禁状态
|
||||
*/
|
||||
/** 用户封禁状态 */
|
||||
public static final String USER_DISABLE = "1";
|
||||
|
||||
/**
|
||||
* 角色封禁状态
|
||||
*/
|
||||
/** 角色封禁状态 */
|
||||
public static final String ROLE_DISABLE = "1";
|
||||
|
||||
/**
|
||||
* 部门正常状态
|
||||
*/
|
||||
/** 部门正常状态 */
|
||||
public static final String DEPT_NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 部门停用状态
|
||||
*/
|
||||
/** 部门停用状态 */
|
||||
public static final String DEPT_DISABLE = "1";
|
||||
|
||||
/**
|
||||
* 字典正常状态
|
||||
*/
|
||||
/** 字典正常状态 */
|
||||
public static final String DICT_NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 是否为系统默认(是)
|
||||
*/
|
||||
/** 是否为系统默认(是) */
|
||||
public static final String YES = "Y";
|
||||
|
||||
/**
|
||||
* 是否菜单外链(是)
|
||||
*/
|
||||
/** 是否菜单外链(是) */
|
||||
public static final String YES_FRAME = "0";
|
||||
|
||||
/**
|
||||
* 是否菜单外链(否)
|
||||
*/
|
||||
/** 是否菜单外链(否) */
|
||||
public static final String NO_FRAME = "1";
|
||||
|
||||
/**
|
||||
* 菜单类型(目录)
|
||||
*/
|
||||
/** 菜单类型(目录) */
|
||||
public static final String TYPE_DIR = "M";
|
||||
|
||||
/**
|
||||
* 菜单类型(菜单)
|
||||
*/
|
||||
/** 菜单类型(菜单) */
|
||||
public static final String TYPE_MENU = "C";
|
||||
|
||||
/**
|
||||
* 菜单类型(按钮)
|
||||
*/
|
||||
/** 菜单类型(按钮) */
|
||||
public static final String TYPE_BUTTON = "F";
|
||||
|
||||
/**
|
||||
* Layout组件标识
|
||||
*/
|
||||
/** Layout组件标识 */
|
||||
public final static String LAYOUT = "Layout";
|
||||
|
||||
/**
|
||||
* ParentView组件标识
|
||||
*/
|
||||
/** ParentView组件标识 */
|
||||
public final static String PARENT_VIEW = "ParentView";
|
||||
|
||||
/**
|
||||
* InnerLink组件标识
|
||||
*/
|
||||
/** InnerLink组件标识 */
|
||||
public final static String INNER_LINK = "InnerLink";
|
||||
|
||||
/**
|
||||
* 校验是否唯一的返回标识
|
||||
*/
|
||||
/** 校验是否唯一的返回标识 */
|
||||
public final static boolean UNIQUE = true;
|
||||
public final static boolean NOT_UNIQUE = false;
|
||||
|
||||
|
|
@ -155,28 +122,4 @@ public class UserConstants {
|
|||
* 项目管理-知识库管理权限
|
||||
*/
|
||||
public static final String PMS_PERMS_DOCS_MANAGE = "pms:docs:manage";
|
||||
/**
|
||||
* 文章管理-文章删除权限
|
||||
*/
|
||||
public static final String CMS_PERMS_DOCS_DELETE = "cms:doc:remove";
|
||||
/**
|
||||
* 文章管理-新增文章权限
|
||||
*/
|
||||
public static final String CMS_PERMS_DOCS_ADD = "cms:doc:add";
|
||||
/**
|
||||
* 文章管理-编辑文章权限
|
||||
*/
|
||||
public static final String CMS_PERMS_DOCS_EDIT = "cms:doc:edit";
|
||||
/**
|
||||
* 文章管理-审核文章权限
|
||||
*/
|
||||
public static final String CMS_PERMS_DOCS_AUDIT = "cms:doc:audit";
|
||||
/**
|
||||
* 专区管理-审核项目权限
|
||||
*/
|
||||
public static final String ZONE_PERMS_PROJECT_AUDIT = "zone:project:audit";
|
||||
/**
|
||||
* 专区管理-审核资源权限
|
||||
*/
|
||||
public static final String ZONE_PERMS_RESOURCE_AUDIT = "zone:resource:audit";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ package com.microservices.common.core.enums;
|
|||
public enum DocAndZoneOperation
|
||||
{
|
||||
OPERATION_CREATE("创建", "create"), OPERATION_UPDATE("更新", "update"),
|
||||
OPERATION_DELETE("删除", "delete"), OPERATION_NON_REPO_UPDATE("非仓库更新", "nonRepoUpdate");
|
||||
OPERATION_DELETE("删除", "delete");
|
||||
|
||||
private final String operationName;
|
||||
private final String operationCode;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.microservices.common.core.threadPool;
|
||||
|
||||
import com.microservices.common.core.constant.TokenConstants;
|
||||
import com.microservices.common.core.context.SecurityContextHolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -37,6 +38,9 @@ public class ThreadPoolExecutorWrap extends ThreadPoolExecutor {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if(contextValue != null&&contextValue.containsKey("user_key")){
|
||||
contextValue.put(TokenConstants.AUTHENTICATION, contextValue.get("user_key"));
|
||||
}
|
||||
SecurityContextHolder.setLocalMap(contextValue);
|
||||
// 用户任务逻辑
|
||||
task.run();
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class GenericsTableDataInfo<T> implements Serializable {
|
|||
/**
|
||||
* 面包屑数据
|
||||
*/
|
||||
@ApiModelProperty("面包屑数据")
|
||||
@ApiModelProperty(value = "面包屑数据",hidden = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) //为空时隐藏
|
||||
private List<Breadcrumb> breadcrumb;
|
||||
|
||||
|
|
|
|||
|
|
@ -211,17 +211,6 @@ public class HttpAPIService {
|
|||
return doRequest(httpDelete, headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 不带Header的get请求
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public JSONObject doGet(String url) throws Exception {
|
||||
return doGet(url, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 带Header的get请求
|
||||
*
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class GitLinkRequestHelper {
|
|||
HashMap<String, String> headers = prepareAuthenticationHeaders(gitLinkRequestUrl);
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
String path = gitLinkRequestUrl.getPath();
|
||||
logger.info("[{}]通过HttpClient向平台发起请求,请求方法为:{},请求网站为:{},请求路由为:{},请求载体为:{},请求头为:{}"
|
||||
logger.debug("[{}]通过HttpClient向平台发起请求,请求方法为:{},请求网站为:{},请求路由为:{},请求载体为:{},请求头为:{}"
|
||||
, requestId
|
||||
, requestType
|
||||
, gitLinkUrl
|
||||
|
|
@ -111,7 +111,7 @@ public class GitLinkRequestHelper {
|
|||
default:
|
||||
throw new ServiceException("不支持该请求方式:" + requestType.name());
|
||||
}
|
||||
logger.info("[{}]请求响应为:{}"
|
||||
logger.debug("[{}]请求响应为:{}"
|
||||
, requestId
|
||||
, result);
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@
|
|||
<artifactId>microservices-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -115,7 +115,8 @@ public class AuthLogic {
|
|||
* @param permission 权限字符串
|
||||
* @return 用户是否具备某权限
|
||||
*/
|
||||
public boolean hasPermi(String permission) {
|
||||
public boolean hasPermi(String permission)
|
||||
{
|
||||
return hasPermi(tokenService.getMenuPermissions(), permission);
|
||||
}
|
||||
|
||||
|
|
@ -125,8 +126,10 @@ public class AuthLogic {
|
|||
* @param permission 权限字符串
|
||||
* @return 用户是否具备某权限
|
||||
*/
|
||||
public void checkPermi(String permission) {
|
||||
if (!hasPermi(tokenService.getMenuPermissions(), permission)) {
|
||||
public void checkPermi(String permission)
|
||||
{
|
||||
if (!hasPermi(tokenService.getMenuPermissions(), permission))
|
||||
{
|
||||
throw new NotPermissionException(permission);
|
||||
}
|
||||
}
|
||||
|
|
@ -150,10 +153,13 @@ public class AuthLogic {
|
|||
*
|
||||
* @param permissions 权限列表
|
||||
*/
|
||||
public void checkPermiAnd(String... permissions) {
|
||||
public void checkPermiAnd(String... permissions)
|
||||
{
|
||||
Set<String> permissionList = tokenService.getMenuPermissions();
|
||||
for (String permission : permissions) {
|
||||
if (!hasPermi(permissionList, permission)) {
|
||||
for (String permission : permissions)
|
||||
{
|
||||
if (!hasPermi(permissionList, permission))
|
||||
{
|
||||
throw new NotPermissionException(permission);
|
||||
}
|
||||
}
|
||||
|
|
@ -164,10 +170,13 @@ public class AuthLogic {
|
|||
*
|
||||
* @param permissions 权限码数组
|
||||
*/
|
||||
public void checkPermiOr(String... permissions) {
|
||||
public void checkPermiOr(String... permissions)
|
||||
{
|
||||
Set<String> permissionList = tokenService.getMenuPermissions();
|
||||
for (String permission : permissions) {
|
||||
if (hasPermi(permissionList, permission)) {
|
||||
for (String permission : permissions)
|
||||
{
|
||||
if (hasPermi(permissionList, permission))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -182,7 +191,8 @@ public class AuthLogic {
|
|||
* @param role 角色标识
|
||||
* @return 用户是否具备某角色
|
||||
*/
|
||||
public boolean hasRole(String role) {
|
||||
public boolean hasRole(String role)
|
||||
{
|
||||
return hasRole(tokenService.getRolePermissions(), role);
|
||||
}
|
||||
|
||||
|
|
@ -215,10 +225,13 @@ public class AuthLogic {
|
|||
*
|
||||
* @param roles 角色标识数组
|
||||
*/
|
||||
public void checkRoleAnd(String... roles) {
|
||||
public void checkRoleAnd(String... roles)
|
||||
{
|
||||
Set<String> roleList = tokenService.getRolePermissions();
|
||||
for (String role : roles) {
|
||||
if (!hasRole(roleList, role)) {
|
||||
for (String role : roles)
|
||||
{
|
||||
if (!hasRole(roleList, role))
|
||||
{
|
||||
throw new NotRoleException(role);
|
||||
}
|
||||
}
|
||||
|
|
@ -229,14 +242,18 @@ public class AuthLogic {
|
|||
*
|
||||
* @param roles 角色标识数组
|
||||
*/
|
||||
public void checkRoleOr(String... roles) {
|
||||
public void checkRoleOr(String... roles)
|
||||
{
|
||||
Set<String> roleList = tokenService.getRolePermissions();
|
||||
for (String role : roles) {
|
||||
if (hasRole(roleList, role)) {
|
||||
for (String role : roles)
|
||||
{
|
||||
if (hasRole(roleList, role))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (roles.length > 0) {
|
||||
if (roles.length > 0)
|
||||
{
|
||||
throw new NotRoleException(roles);
|
||||
}
|
||||
}
|
||||
|
|
@ -306,9 +323,6 @@ public class AuthLogic {
|
|||
public boolean hasUserIdentity(Long deptId, String roleKey) {
|
||||
LoginUser loginUser = getLoginUser();
|
||||
List<SysUserDeptRole> sysUserDeptRoleList = tokenService.getAllUserIdentity(loginUser.getUsername());
|
||||
if (sysUserDeptRoleList == null) {
|
||||
return false;
|
||||
}
|
||||
return sysUserDeptRoleList.stream()
|
||||
.anyMatch(x -> {
|
||||
if (x.getDeptId() != null && x.getSysRole() != null && x.getDeptId().equals(deptId)) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.microservices.common.security.handler;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
|
||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
|
||||
import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.domain.R;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@Component
|
||||
public class SentinelBlockExceptionHandler implements BlockExceptionHandler {
|
||||
|
||||
@Override
|
||||
public void handle(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
BlockException ex) throws Exception {
|
||||
|
||||
R<?> body;
|
||||
if (ex instanceof FlowException) { // 限流
|
||||
body = R.fail(429, "请求过于频繁,请稍后重试");
|
||||
} else if (ex instanceof DegradeException) { // 熔断
|
||||
body = R.fail(500, "服务暂时不可用,请稍后重试");
|
||||
} else if (ex instanceof ParamFlowException) { // 热点参数限流
|
||||
body = R.fail(400, "热点参数限流");
|
||||
} else if (ex instanceof AuthorityException) { // 授权规则
|
||||
body = R.fail(403, "无权限访问该资源");
|
||||
} else if (ex instanceof SystemBlockException) { // 系统规则
|
||||
body = R.fail(500, "系统规则限制,无法访问");
|
||||
} else { // 兜底
|
||||
body = R.fail(500, "服务繁忙,请稍后重试");
|
||||
}
|
||||
|
||||
response.setStatus(HttpStatus.OK.value());
|
||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.getWriter().write(JSONObject.toJSONString(body));
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@ import com.microservices.common.core.utils.uuid.IdUtils;
|
|||
import com.microservices.common.redis.service.RedisService;
|
||||
import com.microservices.common.security.interceptor.HeaderInterceptor;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.system.api.RemoteDeptService;
|
||||
import com.microservices.system.api.RemoteUserService;
|
||||
import com.microservices.system.api.domain.SysRole;
|
||||
import com.microservices.system.api.domain.SysUser;
|
||||
|
|
@ -39,8 +38,6 @@ public class TokenService {
|
|||
private RedisService redisService;
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
@Autowired
|
||||
private RemoteDeptService remoteDeptService;
|
||||
|
||||
protected static final long MILLIS_SECOND = 1000;
|
||||
|
||||
|
|
@ -332,16 +329,4 @@ public class TokenService {
|
|||
}
|
||||
return loginUser.getSysUser();
|
||||
}
|
||||
|
||||
public Boolean hasDeptPerms(Long deptId, String perms) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
Boolean hasPerms = FeignUtils.getReturnData(
|
||||
remoteDeptService.checkUserInDeptOrParentDeptHasPerms(deptId, loginUser.getUserId(), perms, SecurityConstants.INNER)
|
||||
);
|
||||
|
||||
if (hasPerms == null) {
|
||||
hasPerms = false;
|
||||
}
|
||||
return hasPerms;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,3 +4,4 @@ com.microservices.common.security.service.impl.RequestCustomServiceImpl
|
|||
com.microservices.common.security.aspect.PreAuthorizeAspect
|
||||
com.microservices.common.security.aspect.InnerAuthAspect
|
||||
com.microservices.common.security.handler.GlobalExceptionHandler
|
||||
com.microservices.common.security.handler.SentinelBlockExceptionHandler
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||
try {
|
||||
claims = JwtUtils.parseToken(token);
|
||||
} catch (Exception e) {
|
||||
log.error("令牌解析失败:{}", e.getMessage());
|
||||
log.error("[鉴权异常处理]令牌解析失败:{}", e.getMessage());
|
||||
return unauthorizedResponse(exchange, "令牌格式不正确!");
|
||||
}
|
||||
if (claims == null) {
|
||||
|
|
@ -139,7 +139,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||
);
|
||||
redisService.setCacheObject(redisKey, feignResult);
|
||||
} catch (Exception e) {
|
||||
log.error("获取用户【{}】身份列表时发生异常:{}", username, e.getMessage());
|
||||
log.error("[鉴权异常处理]获取用户【{}】身份列表时发生异常:{}", username, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||
}
|
||||
return genCookieByToken(token);
|
||||
} catch (Exception e) {
|
||||
log.error("检查该gitlink token【{}】是否登录时发生异常:{}", token, e.getMessage());
|
||||
log.error("[鉴权异常处理]检查该token【{}】是否登录时发生异常:{}", token, e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -215,11 +215,11 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
|||
try {
|
||||
feignResult = future.get();
|
||||
} catch (Exception e) {
|
||||
log.error("异步请求获取本系统Token出错:{}", e.getMessage());
|
||||
log.error("[鉴权异常处理]异步请求获取本系统Token出错:{}", e.getMessage());
|
||||
throw new ServiceException("内部服务错误");
|
||||
}
|
||||
if (StringUtils.isNull(feignResult) || R.FAIL == feignResult.getCode()) {
|
||||
log.error("Token获取出错:{}", feignResult.getMsg());
|
||||
log.error("[鉴权异常处理]Token获取出错:{}", feignResult.getMsg());
|
||||
throw new ServiceException("内部服务错误");
|
||||
}
|
||||
if (R.SUCCESS == feignResult.getCode()) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public class GlobalResponseFilter implements GlobalFilter, Ordered {
|
|||
String lowerUrl = request.getURI().getPath().toLowerCase();
|
||||
ServerHttpResponse originalResponse = exchange.getResponse();
|
||||
DataBufferFactory bufferFactory = originalResponse.bufferFactory();
|
||||
|
||||
// 当请求为Nacos时,Nacos返回的所有非JSON响应都会被自动转换为结构化的错误信息,同时将HTTP状态码设置为200,适合用于规范化微服务架构的响应格式。
|
||||
if (lowerUrl.startsWith("/nacos")) {
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ public class GlobalResponseFilter implements GlobalFilter, Ordered {
|
|||
return super.writeWith(body);
|
||||
}
|
||||
if (status == HttpStatus.FORBIDDEN) {
|
||||
log.error("nacos鉴权异常,已清理redis中nacos token");
|
||||
log.error("[网关转发异常处理]nacos鉴权异常,已清理redis中nacos token");
|
||||
// 设置新的状态码为 200
|
||||
setStatusCode(HttpStatus.OK);
|
||||
// 设置响应内容类型为 JSON
|
||||
|
|
@ -125,7 +126,7 @@ public class GlobalResponseFilter implements GlobalFilter, Ordered {
|
|||
}
|
||||
synchronousSink.complete();
|
||||
}).flatMap(resStr -> {
|
||||
log.error("Portainer响应处理异常,异常信息:{}", resStr);
|
||||
log.error("[网关转发异常处理]Portainer响应处理异常,异常信息:{}", resStr);
|
||||
originalResponse.setStatusCode(HttpStatus.OK);
|
||||
byte[] bytes;
|
||||
if (JSON.isValid(resStr)) {
|
||||
|
|
@ -133,7 +134,7 @@ public class GlobalResponseFilter implements GlobalFilter, Ordered {
|
|||
if (resJson.containsKey("message")) {
|
||||
String message = resJson.getString("message");
|
||||
if (StringUtils.isNotBlank(message) && message.contains("A valid authorisation token is missing")) {
|
||||
log.error("Portainer鉴权异常,已清理redis中Portainer token");
|
||||
log.error("[网关转发异常处理]Portainer鉴权异常,已清理redis中Portainer token");
|
||||
//token失效清除redis缓存
|
||||
redisService.deleteObject(CacheConstants.PORTAINER_TOKEN);
|
||||
bytes = JSON.toJSONBytes(AjaxResult.error(ExceptionMsgConstants.RETRY_ERROR));
|
||||
|
|
@ -160,12 +161,12 @@ public class GlobalResponseFilter implements GlobalFilter, Ordered {
|
|||
ServerHttpResponseDecorator decoratedResponse = new ServerHttpResponseDecorator(originalResponse) {
|
||||
@Override
|
||||
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
|
||||
HttpStatus status = getStatusCode() != null ? getStatusCode() : HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
HttpStatus status = getStatusCode();
|
||||
if (!status.isError()) {
|
||||
return super.writeWith(body);
|
||||
}
|
||||
if (status == HttpStatus.UNAUTHORIZED) {
|
||||
log.error("sentinel鉴权异常,已清理redis中sentinel token");
|
||||
log.error("[网关转发异常处理]sentinel鉴权异常,已清理redis中sentinel token");
|
||||
// 设置新的状态码为 200
|
||||
setStatusCode(HttpStatus.OK);
|
||||
// 设置响应内容类型为 JSON
|
||||
|
|
@ -192,7 +193,7 @@ public class GlobalResponseFilter implements GlobalFilter, Ordered {
|
|||
}
|
||||
synchronousSink.complete();
|
||||
}).flatMap(resStr -> {
|
||||
log.error("Sentinel响应处理异常,异常信息:{}", resStr);
|
||||
log.error("[网关转发异常处理]Sentinel响应处理异常,异常信息:{}", resStr);
|
||||
byte[] bytes;
|
||||
bytes = JSON.toJSONBytes(AjaxResult.error(ExceptionMsgConstants.SYSTEM_EXEC_ERROR));
|
||||
setStatusCode(HttpStatus.OK);
|
||||
|
|
|
|||
|
|
@ -53,8 +53,14 @@ public class ThirdPartyToolServiceImpl implements ThirdPartyToolService {
|
|||
public String portainerUsername;
|
||||
@Value("${thirdPartyTools.portainer.auth.password:}")
|
||||
public String portainerPassword;
|
||||
@Value("${thirdPartyTools.rancher.auth.username:}")
|
||||
public String rancherUsername;
|
||||
@Value("${thirdPartyTools.rancher.auth.password:}")
|
||||
public String rancherPassword;
|
||||
@Value("${thirdPartyTools.portainer.endpoints:}")
|
||||
public Integer portainerEndpoints;
|
||||
@Value("${thirdPartyTools.retryTimes:1}")
|
||||
public Integer retryTimes;
|
||||
ThreadPoolExecutor threadPoolExecutor = CustomExecutorFactory.threadPoolExecutor;
|
||||
@Lazy
|
||||
@Autowired
|
||||
|
|
@ -83,27 +89,81 @@ public class ThirdPartyToolServiceImpl implements ThirdPartyToolService {
|
|||
if (redisService.hasKey(CacheConstants.SENTINEL_TOKEN)) {
|
||||
sentinelCookie = redisService.getCacheObject(CacheConstants.SENTINEL_TOKEN);
|
||||
} else {
|
||||
// 网关采用异步架构,所以此处需要通过异步请求获取Sentinel Token
|
||||
Future<Response> future = threadPoolExecutor.submit(() -> remoteGatewayService.loginSentinel(sentinelUsername, sentinelPassword));
|
||||
try {
|
||||
Response response = future.get(1, TimeUnit.SECONDS);
|
||||
Map<String, Collection<String>> header = response.headers();
|
||||
if (header != null && header.containsKey("set-cookie")) {
|
||||
sentinelCookie = header.get("set-cookie").iterator().next();
|
||||
//Sentinel登录状态默认30分钟失效,将Sentinel Token缓存过期时间调整为28分钟
|
||||
redisService.setCacheObject(CacheConstants.SENTINEL_TOKEN, sentinelCookie, 28L, TimeUnit.MINUTES);
|
||||
for (int i = 0; i < retryTimes; i++) {
|
||||
// 网关采用异步架构,所以此处需要通过异步请求获取Sentinel Token
|
||||
Future<Response> future = threadPoolExecutor.submit(() -> remoteGatewayService.loginSentinel(sentinelUsername, sentinelPassword));
|
||||
try {
|
||||
Response response = future.get(3, TimeUnit.SECONDS);
|
||||
Map<String, Collection<String>> header = response.headers();
|
||||
if (header != null && header.containsKey("set-cookie")) {
|
||||
sentinelCookie = header.get("set-cookie").iterator().next();
|
||||
//Sentinel登录状态默认30分钟失效,将Sentinel Token缓存过期时间调整为28分钟
|
||||
redisService.setCacheObject(CacheConstants.SENTINEL_TOKEN, sentinelCookie, 28L, TimeUnit.MINUTES);
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
log.error("[网关转发异常处理]获取Sentinel Token超时");
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error("[网关转发异常处理]获取Sentinel Token失败:{}", e.getMessage());
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
log.error("获取Sentinel Token超时");
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error("获取Sentinel Token失败:{}", e.getMessage());
|
||||
|
||||
if (StringUtils.isNotEmpty(sentinelCookie)) {
|
||||
break;
|
||||
}
|
||||
|
||||
log.warn("[网关转发异常处理]获取Sentinel Token失败,进行第{}次重试中", i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(sentinelCookie)) {
|
||||
ServletUtils.removeHeader(mutate, TokenConstants.Cookie);
|
||||
mutate.header(TokenConstants.Cookie, String.format("%s;%s;", cookie, sentinelCookie));
|
||||
} else {
|
||||
throw new ServiceException("Sentinel服务获取Token失败");
|
||||
throw new ServiceException("[网关转发异常处理]Sentinel服务获取Token失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 处理Rancher请求
|
||||
if (lowerUrl.startsWith("/rancher")) {
|
||||
String rancherToken = null;
|
||||
if (redisService.hasKey(CacheConstants.RANCHER_TOKEN)) {
|
||||
rancherToken = redisService.getCacheObject(CacheConstants.RANCHER_TOKEN);
|
||||
} else {
|
||||
for (int i = 0; i < retryTimes; i++) {
|
||||
JSONObject loginRancherBody = new JSONObject();
|
||||
loginRancherBody.put("description", "api session");
|
||||
loginRancherBody.put("responseType", "cookie");
|
||||
loginRancherBody.put("username", rancherUsername);
|
||||
loginRancherBody.put("password", rancherPassword);
|
||||
|
||||
// 网关采用异步架构,所以此处需要通过异步请求获取Rancher Token
|
||||
Future<Response> future = threadPoolExecutor.submit(() -> remoteGatewayService.loginRancher(loginRancherBody));
|
||||
try {
|
||||
Response response = future.get(3, TimeUnit.SECONDS);
|
||||
Map<String, Collection<String>> header = response.headers();
|
||||
if (header != null && header.containsKey("set-cookie")) {
|
||||
String rancherCookie = header.get("set-cookie").iterator().next();
|
||||
rancherToken = getValueByCookieKey(rancherCookie, TokenConstants.Rancher_Cookie_Token_Key);
|
||||
//Rancher登录状态默认15小时失效,将Rancher Token缓存过期时间调整为14分钟
|
||||
redisService.setCacheObject(CacheConstants.RANCHER_TOKEN, rancherToken, 14L, TimeUnit.HOURS);
|
||||
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
log.error("[网关转发异常处理]获取Rancher Token超时");
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
log.error("[网关转发异常处理]获取Rancher Token失败:{}", e.getMessage());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(rancherToken)) {
|
||||
break;
|
||||
}
|
||||
|
||||
log.warn("[网关转发异常处理]获取Rancher Token失败,进行第{}次重试中", i + 1);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotEmpty(rancherToken)) {
|
||||
ServletUtils.removeHeader(mutate, TokenConstants.AUTHENTICATION);
|
||||
mutate.header(TokenConstants.AUTHENTICATION, TokenConstants.PREFIX + rancherToken);
|
||||
} else {
|
||||
throw new ServiceException("[网关转发异常处理]Rancher服务获取Token失败");
|
||||
}
|
||||
}
|
||||
// 处理Nacos请求
|
||||
|
|
@ -112,38 +172,44 @@ public class ThirdPartyToolServiceImpl implements ThirdPartyToolService {
|
|||
if (redisService.hasKey(CacheConstants.NACOS_TOKEN)) {
|
||||
nacosToken = redisService.getCacheObject(CacheConstants.NACOS_TOKEN);
|
||||
} else {
|
||||
Map<String, String> nacosMap = new HashMap<>();
|
||||
nacosMap.put("username", nacosUsername);
|
||||
nacosMap.put("password", nacosPassword);
|
||||
// 网关采用异步架构,所以此处需要通过异步请求获取Nacos Token
|
||||
Future<Response> future = threadPoolExecutor.submit(() -> remoteGatewayService.loginNacos(nacosMap));
|
||||
try {
|
||||
Response res = future.get(1, TimeUnit.SECONDS);
|
||||
StringWriter writer = new StringWriter();
|
||||
IOUtils.copy(res.body().asInputStream(), writer, StandardCharsets.UTF_8.name());
|
||||
String str = writer.toString();
|
||||
if (!JSON.isValid(str)) {
|
||||
return exceptionResponse(exchange, str, res.status());
|
||||
for (int i = 0; i < retryTimes; i++) {
|
||||
Map<String, String> nacosMap = new HashMap<>();
|
||||
nacosMap.put("username", nacosUsername);
|
||||
nacosMap.put("password", nacosPassword);
|
||||
// 网关采用异步架构,所以此处需要通过异步请求获取Nacos Token
|
||||
Future<Response> future = threadPoolExecutor.submit(() -> remoteGatewayService.loginNacos(nacosMap));
|
||||
try {
|
||||
Response res = future.get(3, TimeUnit.SECONDS);
|
||||
StringWriter writer = new StringWriter();
|
||||
IOUtils.copy(res.body().asInputStream(), writer, StandardCharsets.UTF_8.name());
|
||||
String str = writer.toString();
|
||||
if (!JSON.isValid(str)) {
|
||||
return exceptionResponse(exchange, str, res.status());
|
||||
}
|
||||
JSONObject resJsonObject = JSONObject.parseObject(str);
|
||||
if (resJsonObject == null) {
|
||||
return exceptionResponse(exchange, str, res.status());
|
||||
}
|
||||
nacosToken = resJsonObject.getString("accessToken");
|
||||
Long tokenTtl = resJsonObject.getLong("tokenTtl");
|
||||
if (nacosToken != null && tokenTtl != null) {
|
||||
redisService.setCacheObject(CacheConstants.NACOS_TOKEN, nacosToken, tokenTtl - 10, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
log.error("[网关转发异常处理]获取Nacos Token超时");
|
||||
} catch (InterruptedException | ExecutionException | IOException | NullPointerException e) {
|
||||
log.error("[网关转发异常处理]获取Nacos Token失败:{}", e.getMessage());
|
||||
}
|
||||
JSONObject resJsonObject = JSONObject.parseObject(str);
|
||||
if (resJsonObject == null) {
|
||||
return exceptionResponse(exchange, str, res.status());
|
||||
if (StringUtils.isNotEmpty(nacosToken)) {
|
||||
break;
|
||||
}
|
||||
nacosToken = resJsonObject.getString("accessToken");
|
||||
Long tokenTtl = resJsonObject.getLong("tokenTtl");
|
||||
if (nacosToken != null && tokenTtl != null) {
|
||||
redisService.setCacheObject(CacheConstants.NACOS_TOKEN, nacosToken, tokenTtl - 10, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
log.error("获取Nacos Token超时");
|
||||
} catch (InterruptedException | ExecutionException | IOException | NullPointerException e) {
|
||||
log.error("获取Nacos Token失败:{}", e.getMessage());
|
||||
log.warn("[网关转发异常处理]获取Nacos Token失败,进行第{}次重试中", i + 1);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotEmpty(nacosToken)) {
|
||||
mutate.header(TokenConstants.Nacos_Token_Key, nacosToken);
|
||||
} else {
|
||||
throw new ServiceException("Nacos服务获取Token失败");
|
||||
throw new ServiceException("[网关转发异常处理]Nacos服务获取Token失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +229,7 @@ public class ThirdPartyToolServiceImpl implements ThirdPartyToolService {
|
|||
try {
|
||||
mutate.uri(new URI(url));
|
||||
} catch (URISyntaxException e) {
|
||||
log.error("替换Portainer请求中Endpoints时发生异常:{}", e.getMessage());
|
||||
log.error("[网关转发异常处理]替换Portainer请求中Endpoints时发生异常:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -178,38 +244,44 @@ public class ThirdPartyToolServiceImpl implements ThirdPartyToolService {
|
|||
if (redisService.hasKey(CacheConstants.PORTAINER_TOKEN)) {
|
||||
portainerToken = redisService.getCacheObject(CacheConstants.PORTAINER_TOKEN);
|
||||
} else {
|
||||
// 网关采用异步架构,所以此处需要通过异步请求获取Portainer Token
|
||||
JSONObject loginPortainerBody = new JSONObject();
|
||||
loginPortainerBody.put("username", portainerUsername);
|
||||
loginPortainerBody.put("password", portainerPassword);
|
||||
Future<Response> future = threadPoolExecutor.submit(() -> remoteGatewayService.loginPortainer(loginPortainerBody));
|
||||
try {
|
||||
Response res = future.get(1, TimeUnit.SECONDS);
|
||||
StringWriter writer = new StringWriter();
|
||||
IOUtils.copy(res.body().asInputStream(), writer, StandardCharsets.UTF_8.name());
|
||||
String str = writer.toString();
|
||||
if (!JSON.isValid(str)) {
|
||||
return exceptionResponse(exchange, str, res.status());
|
||||
}
|
||||
JSONObject resJsonObject = JSONObject.parseObject(str);
|
||||
portainerToken = resJsonObject.getString("jwt");
|
||||
if (portainerToken == null) {
|
||||
return exceptionResponse(exchange, str, res.status());
|
||||
}
|
||||
String[] tokenSplit = portainerToken.split("\\.");
|
||||
String tokenBodyStr = new String(Base64.getDecoder().decode(tokenSplit[1]), StandardCharsets.UTF_8);
|
||||
JSONObject tokenBody = JSONObject.parseObject(tokenBodyStr);
|
||||
Long expiration = tokenBody.getLong("exp");
|
||||
Long now = new Date().getTime() / 1000;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// 网关采用异步架构,所以此处需要通过异步请求获取Portainer Token
|
||||
JSONObject loginPortainerBody = new JSONObject();
|
||||
loginPortainerBody.put("username", portainerUsername);
|
||||
loginPortainerBody.put("password", portainerPassword);
|
||||
Future<Response> future = threadPoolExecutor.submit(() -> remoteGatewayService.loginPortainer(loginPortainerBody));
|
||||
try {
|
||||
Response res = future.get(1, TimeUnit.SECONDS);
|
||||
StringWriter writer = new StringWriter();
|
||||
IOUtils.copy(res.body().asInputStream(), writer, StandardCharsets.UTF_8.name());
|
||||
String str = writer.toString();
|
||||
if (!JSON.isValid(str)) {
|
||||
return exceptionResponse(exchange, str, res.status());
|
||||
}
|
||||
JSONObject resJsonObject = JSONObject.parseObject(str);
|
||||
portainerToken = resJsonObject.getString("jwt");
|
||||
if (portainerToken == null) {
|
||||
return exceptionResponse(exchange, str, res.status());
|
||||
}
|
||||
String[] tokenSplit = portainerToken.split("\\.");
|
||||
String tokenBodyStr = new String(Base64.getDecoder().decode(tokenSplit[1]), StandardCharsets.UTF_8);
|
||||
JSONObject tokenBody = JSONObject.parseObject(tokenBodyStr);
|
||||
Long expiration = tokenBody.getLong("exp");
|
||||
Long now = new Date().getTime() / 1000;
|
||||
|
||||
long portainerTokenTtl = expiration - now;
|
||||
if (portainerTokenTtl > 20) {
|
||||
redisService.setCacheObject(CacheConstants.PORTAINER_TOKEN, portainerToken, portainerTokenTtl - 10, TimeUnit.SECONDS);
|
||||
long portainerTokenTtl = expiration - now;
|
||||
if (portainerTokenTtl > 20) {
|
||||
redisService.setCacheObject(CacheConstants.PORTAINER_TOKEN, portainerToken, portainerTokenTtl - 10, TimeUnit.SECONDS);
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
log.error("[网关转发异常处理]获取Portainer Token超时");
|
||||
} catch (InterruptedException | ExecutionException | IOException | NullPointerException e) {
|
||||
log.error("[网关转发异常处理]获取Portainer Token失败:{}", e.getMessage());
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
log.error("获取Portainer Token超时");
|
||||
} catch (InterruptedException | ExecutionException | IOException | NullPointerException e) {
|
||||
log.error("获取Portainer Token失败:{}", e.getMessage());
|
||||
if (StringUtils.isNotEmpty(portainerToken)) {
|
||||
break;
|
||||
}
|
||||
log.warn("[网关转发异常处理]获取Portainer Token失败,进行第{}次重试中", i + 1);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotEmpty(portainerToken)) {
|
||||
|
|
@ -218,7 +290,7 @@ public class ThirdPartyToolServiceImpl implements ThirdPartyToolService {
|
|||
mutate.header(TokenConstants.AUTHENTICATION, TokenConstants.PREFIX + portainerToken);
|
||||
mutate.header(TokenConstants.Cookie, String.format("%s;%s;", cookie, portainerToken));
|
||||
} else {
|
||||
throw new ServiceException("Portainer服务获取Token失败");
|
||||
throw new ServiceException("[网关转发异常处理]Portainer服务获取Token失败");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -226,7 +298,23 @@ public class ThirdPartyToolServiceImpl implements ThirdPartyToolService {
|
|||
|
||||
|
||||
private Mono<Void> exceptionResponse(ServerWebExchange exchange, String msg, int code) {
|
||||
log.error("[第三方工具请求处理异常]请求路径:{},异常信息:{}", exchange.getRequest().getPath(), msg);
|
||||
log.error("[网关转发异常处理]请求路径:{},异常信息:{}", exchange.getRequest().getPath(), msg);
|
||||
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), ExceptionMsgConstants.SYSTEM_EXEC_ERROR, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过指定Key获取Cookie中指定值
|
||||
*/
|
||||
private static String getValueByCookieKey(String cookie, String key) {
|
||||
if (cookie != null) {
|
||||
String[] cookies = StringUtils.split(cookie, ';');
|
||||
for (String cookieItem : cookies) {
|
||||
if (cookieItem.contains(key)) {
|
||||
String token = StringUtils.remove(cookieItem, key + "=");
|
||||
return StringUtils.remove(token, " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.microservices.cms.doc.controller;
|
|||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.cms.doc.domain.*;
|
||||
import com.microservices.cms.doc.service.ICmsDocService;
|
||||
import com.microservices.common.core.constant.UserConstants;
|
||||
import com.microservices.common.core.domain.R;
|
||||
import com.microservices.common.core.web.controller.BaseController;
|
||||
import com.microservices.common.core.web.domain.AjaxResult;
|
||||
|
|
@ -18,7 +17,6 @@ import io.swagger.annotations.*;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -108,13 +106,23 @@ public class CmsDocController extends BaseController {
|
|||
@ApiImplicitParam(name = "pageNum", value = "当前记录起始索引", paramType = "query", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "Integer"),
|
||||
})
|
||||
public GenericsTableDataInfo<CmsDocAllDto> docListByZone(
|
||||
public TableDataInfo docListByZone(
|
||||
@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId
|
||||
, CmsDocSearchVo cmsDocSearchVo) {
|
||||
Long deptId = cmsDocService.getDeptIdByZoneId(zoneId);
|
||||
cmsDocSearchVo.setIsOpen(true);
|
||||
cmsDocSearchVo.setIsOpen(false);
|
||||
startPage();
|
||||
return cmsDocService.selectAllDocList(deptId, cmsDocSearchVo);
|
||||
List<CmsDocAllDto> list = cmsDocService.selectCmsDocListByDept(deptId, cmsDocSearchVo);
|
||||
list.forEach(x -> {
|
||||
String docDetailUrl = cmsDocService.getDocDetailUrl(x.getDeptId(), x.getId());
|
||||
x.setDocDetailUrl(docDetailUrl);
|
||||
|
||||
Boolean editable = cmsDocService.isCmsDocEditable(x);
|
||||
x.setEditable(editable);
|
||||
|
||||
});
|
||||
int count = cmsDocService.selectCmsDocCountByDept(deptId, cmsDocSearchVo);
|
||||
return getDataTable(list, count);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -156,7 +164,7 @@ public class CmsDocController extends BaseController {
|
|||
/**
|
||||
* 新增文章信息
|
||||
*/
|
||||
@RequiresPermissions(UserConstants.CMS_PERMS_DOCS_ADD)
|
||||
@RequiresPermissions("cms:doc:add")
|
||||
@Log(title = "文章信息", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/dir/{dirId}")
|
||||
@ApiOperation("在栏目下创建文章")
|
||||
|
|
@ -193,7 +201,7 @@ public class CmsDocController extends BaseController {
|
|||
/**
|
||||
* 删除文章
|
||||
*/
|
||||
@RequiresPermissions(UserConstants.CMS_PERMS_DOCS_DELETE)
|
||||
@RequiresPermissions("cms:doc:remove")
|
||||
@Log(title = "文章信息", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
@ApiOperation("删除文章/栏目")
|
||||
|
|
@ -204,13 +212,13 @@ public class CmsDocController extends BaseController {
|
|||
/**
|
||||
* 修改文章信息
|
||||
*/
|
||||
@RequiresPermissions(UserConstants.CMS_PERMS_DOCS_EDIT)
|
||||
@RequiresPermissions("cms:doc:edit")
|
||||
@Log(title = "文章信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}")
|
||||
@ApiOperation("更新文章")
|
||||
public AjaxResult edit(@ApiParam(name = "id", value = "文章Id") @PathVariable Long id,
|
||||
@ApiParam(name = "cmsDoc", value = "文章实体对象") @RequestBody CmsDocDto cmsDocDto) {
|
||||
return success(cmsDocService.updateCmsDoc(id, cmsDocDto));
|
||||
return toAjax(cmsDocService.updateCmsDoc(id, cmsDocDto));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -223,18 +231,18 @@ public class CmsDocController extends BaseController {
|
|||
public AjaxResult editCmsDIr(@ApiParam(name = "id", value = "栏目Id") @PathVariable Long id,
|
||||
@ApiParam(name = "cmsDirUpdateVo", value = "栏目更新对象") @RequestBody CmsDirUpdateVo cmsDirUpdateVo) {
|
||||
cmsDocService.updateCmsDir(id, cmsDirUpdateVo);
|
||||
return success("栏目信息更新成功");
|
||||
return success("异步更新栏目信息");
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核文章信息
|
||||
*/
|
||||
@RequiresPermissions(UserConstants.CMS_PERMS_DOCS_AUDIT)
|
||||
@RequiresPermissions("cms:doc:audit")
|
||||
@Log(title = "文章信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/{id}/audit")
|
||||
@ApiOperation("审核文章")
|
||||
public AjaxResult audit(@ApiParam(name = "id", value = "文章Id") @PathVariable Long id,
|
||||
@ApiParam(name = "cmsDocAuditVo", value = "文章审核对象") @RequestBody CmsDocAuditVo cmsDocAuditVo) {
|
||||
@ApiParam(name = "cmsDocAuditVo", value = "文章审核对象") @RequestBody CmsDocAuditVo cmsDocAuditVo) {
|
||||
return toAjax(cmsDocService.auditCmsDoc(id, cmsDocAuditVo));
|
||||
}
|
||||
|
||||
|
|
@ -307,24 +315,6 @@ public class CmsDocController extends BaseController {
|
|||
return R.ok(cmsDocJSONObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部接口:首页文章合并列表(接收置顶文章 docId 有序列表,返回合并去重后的结果)
|
||||
* 供 Zone 服务 Feign 调用,用于 /open/getTopDoc 改造
|
||||
*/
|
||||
@InnerAuth
|
||||
@PostMapping("/homePageDocMergeList/{zoneId}")
|
||||
@ApiOperation(value = "首页文章合并列表", hidden = true)
|
||||
public R<List<JSONObject>> selectHomePageDocMergeList(
|
||||
@PathVariable("zoneId") Long zoneId,
|
||||
@RequestBody List<Long> topDocIds) {
|
||||
List<CmsDocBaseDto> list = cmsDocService.selectHomePageDocMergeList(zoneId, topDocIds);
|
||||
List<JSONObject> result = new ArrayList<>();
|
||||
for (CmsDocBaseDto dto : list) {
|
||||
result.add(JSONObject.from(dto));
|
||||
}
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过组织Id获取专区下文章阅读数量
|
||||
*
|
||||
|
|
|
|||
|
|
@ -5,17 +5,12 @@ import com.microservices.cms.doc.domain.*;
|
|||
import com.microservices.cms.doc.service.ICmsDocCommentService;
|
||||
import com.microservices.cms.doc.service.ICmsDocService;
|
||||
import com.microservices.cms.doc.service.ICmsWechatService;
|
||||
import com.microservices.cms.search.dto.DocSearchResult;
|
||||
import com.microservices.common.core.web.controller.BaseController;
|
||||
import com.microservices.common.core.web.domain.AjaxResult;
|
||||
import com.microservices.common.core.web.domain.GenericsAjaxResult;
|
||||
import com.microservices.common.core.web.page.GenericsTableDataInfo;
|
||||
import com.microservices.common.core.web.page.TableDataInfo;
|
||||
import com.microservices.common.log.annotation.Log;
|
||||
import com.microservices.common.log.enums.BusinessType;
|
||||
import com.microservices.cms.search.dto.DocSearchRequest;
|
||||
import com.microservices.cms.search.dto.DocSearchResponse;
|
||||
import com.microservices.cms.search.service.IGlobalSearchService;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -40,22 +35,6 @@ public class OpenController extends BaseController {
|
|||
@Autowired
|
||||
private ICmsWechatService cmsWechatService;
|
||||
|
||||
@Autowired
|
||||
private IGlobalSearchService globalSearchService;
|
||||
|
||||
/**
|
||||
* 文章搜索接口
|
||||
*
|
||||
* @return 搜索结果
|
||||
*/
|
||||
@ApiOperation("文章搜索")
|
||||
@PostMapping("/search")
|
||||
public GenericsTableDataInfo<DocSearchResult> docSearch(@RequestBody DocSearchRequest docSearchRequest) {
|
||||
logger.info("文章搜索请求: keyword={}", docSearchRequest.getKeyword());
|
||||
DocSearchResponse response = globalSearchService.docSearch(docSearchRequest);
|
||||
return new GenericsTableDataInfo<>(response.getResults(), response.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询栏目列表
|
||||
*/
|
||||
|
|
@ -89,7 +68,7 @@ public class OpenController extends BaseController {
|
|||
public GenericsTableDataInfo<CmsDocBaseDto> docList(@ApiParam(name = "dirId", value = "栏目Id") @PathVariable("dirId") Long dirId
|
||||
, CmsDocSearchVo cmsDocSearchVo) {
|
||||
cmsDocSearchVo.setIsOpen(true);
|
||||
List<CmsDocBaseDto> list = cmsDocService.selectSetDefaultHeadImgCmsDocList(dirId, cmsDocSearchVo);
|
||||
List<CmsDocBaseDto> list = cmsDocService.selectCmsDocList(dirId, cmsDocSearchVo);
|
||||
return getAllGenericsDataTableToPage(list);
|
||||
}
|
||||
|
||||
|
|
@ -121,19 +100,6 @@ public class OpenController extends BaseController {
|
|||
return getAllGenericsDataTableToPage(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文章列表(不区分栏目)
|
||||
*/
|
||||
@GetMapping("/zone/{zoneId}/allDocList")
|
||||
@ApiOperation("查询文章列表(不区分栏目)")
|
||||
public GenericsTableDataInfo<CmsDocAllDto> allDocList(@ApiParam(name = "zoneId", value = "专区Id") @PathVariable("zoneId") Long zoneId,
|
||||
CmsDocSearchVo cmsDocSearchVo) {
|
||||
Long deptId = cmsDocService.getDeptIdByZoneId(zoneId);
|
||||
cmsDocSearchVo.setIsOpen(true);
|
||||
startPage();
|
||||
return cmsDocService.selectAllDocList(deptId, cmsDocSearchVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询首页文章列表
|
||||
*/
|
||||
|
|
@ -209,9 +175,9 @@ public class OpenController extends BaseController {
|
|||
@Log(title = "同步文章数据", businessType = BusinessType.UPDATE)
|
||||
public AjaxResult syncDocData(
|
||||
@ApiParam(name = "deptId", value = "组织Id", required = true) @PathVariable("deptId") Long deptId
|
||||
, @RequestBody() String bodyStr
|
||||
,@RequestBody() String bodyStr
|
||||
, HttpServletRequest request) {
|
||||
cmsDocService.syncDocData(deptId, bodyStr);
|
||||
cmsDocService.syncDocData(deptId,bodyStr);
|
||||
return AjaxResult.success("同步消息发送成功");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,6 @@ public class CmsDir implements Comparable<CmsDir> {
|
|||
@ApiModelProperty(value = "排序", hidden = true)
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "文章头图")
|
||||
private String headImg;
|
||||
|
||||
public String getName() {
|
||||
if (name != null) {
|
||||
name = name.replaceAll(CmsConstants.DIR_SEPARATOR,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ public class CmsDirUpdateVo {
|
|||
@ApiModelProperty(value = "顺序")
|
||||
private Integer order;
|
||||
|
||||
@ApiModelProperty(value = "文章头图")
|
||||
private String headImg;
|
||||
public CmsDir toCmsDir() {
|
||||
CmsDir cmsDir = new CmsDir();
|
||||
cmsDir.setName(name);
|
||||
return cmsDir;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.microservices.cms.doc.domain;
|
|||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.microservices.cms.utils.CmsConstants;
|
||||
import com.microservices.common.core.annotation.Excel;
|
||||
import com.microservices.common.core.utils.bean.BeanUtils;
|
||||
import com.microservices.common.core.web.domain.BaseSortEntity;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
|
@ -37,27 +36,19 @@ public class CmsDoc extends BaseSortEntity {
|
|||
@Excel(name = "文件名称")
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
*/
|
||||
/** 文件路径 */
|
||||
@Excel(name = "文件路径")
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* 文件SHA
|
||||
*/
|
||||
/** 文件SHA */
|
||||
@Excel(name = "文件SHA")
|
||||
private String fileSha;
|
||||
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
/** 文件大小 */
|
||||
@Excel(name = "文件大小")
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
* 文件URL
|
||||
*/
|
||||
/** 文件URL */
|
||||
@Excel(name = "文件URL")
|
||||
private String fileUrl;
|
||||
|
||||
|
|
@ -171,16 +162,10 @@ public class CmsDoc extends BaseSortEntity {
|
|||
*/
|
||||
private String keywords;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
public CmsDir copyToCmsDir() {
|
||||
CmsDir cmsDir = new CmsDir();
|
||||
cmsDir.setId(id);
|
||||
cmsDir.setName(name);
|
||||
cmsDir.setHeadImg(headImg);
|
||||
cmsDir.setSort(this.getSort());
|
||||
cmsDir.setCreatedAt(getCreateTime());
|
||||
return cmsDir;
|
||||
|
|
@ -201,8 +186,6 @@ public class CmsDoc extends BaseSortEntity {
|
|||
HotCmsDocDto hotCmsDocDto = new HotCmsDocDto();
|
||||
hotCmsDocDto.setId(id);
|
||||
hotCmsDocDto.setName(name);
|
||||
hotCmsDocDto.setSummary(summary);
|
||||
hotCmsDocDto.setPublishTime(publishTime);
|
||||
return hotCmsDocDto;
|
||||
}
|
||||
|
||||
|
|
@ -224,12 +207,30 @@ public class CmsDoc extends BaseSortEntity {
|
|||
}
|
||||
|
||||
private CmsDocBaseDto getCmsDocBaseDto(CmsDocBaseDto cmsDocDto) {
|
||||
BeanUtils.copyProperties(this, cmsDocDto);
|
||||
cmsDocDto.setId(id);
|
||||
cmsDocDto.setName(name);
|
||||
cmsDocDto.setHeadImg(headImg);
|
||||
cmsDocDto.setIsHomepage(isHomepage);
|
||||
cmsDocDto.setSummary(summary);
|
||||
cmsDocDto.setEditorType(editorType);
|
||||
cmsDocDto.setDeptId(deptId);
|
||||
|
||||
if (visits == null) {
|
||||
cmsDocDto.setVisits(0L);
|
||||
} else {
|
||||
cmsDocDto.setVisits(visits);
|
||||
}
|
||||
|
||||
cmsDocDto.setPublishTime(publishTime);
|
||||
cmsDocDto.setPublishUser(publishUser);
|
||||
cmsDocDto.setPublishUserUrl(publishUserUrl);
|
||||
cmsDocDto.setPublishUserImage(publishUserImage);
|
||||
cmsDocDto.setPublishUserNickname(publishUserNickname);
|
||||
cmsDocDto.setAuditStatus(auditStatus);
|
||||
cmsDocDto.setAuditType(auditType);
|
||||
cmsDocDto.setCreateBy(createBy);
|
||||
cmsDocDto.setKeywords(keywords);
|
||||
|
||||
return cmsDocDto;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,4 @@ public class CmsDocAuditVo {
|
|||
*/
|
||||
@ApiModelProperty(value = "是否重新编辑: 0不允许重新编辑 1允许重新编辑")
|
||||
private Integer reedit;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ApiModelProperty(value = "审核备注")
|
||||
private String remark;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,10 +101,6 @@ public class CmsDocBaseDto {
|
|||
*/
|
||||
@ApiModelProperty("关键词")
|
||||
private String keywords;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
public void setPublishTime(Date publishTime) {
|
||||
if (publishTime != null) {
|
||||
|
|
|
|||
|
|
@ -83,10 +83,4 @@ public class CmsDocSearchVo {
|
|||
*/
|
||||
@ApiModelProperty("关键词")
|
||||
private String keywords;
|
||||
|
||||
/**
|
||||
* 排除文章Id
|
||||
*/
|
||||
@ApiModelProperty(value = "排除文章Id", hidden = true)
|
||||
private Long excludeId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
package com.microservices.cms.doc.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* CmsDoc with full-text search score
|
||||
* 用于全局搜索结果,包含全文搜索相关度评分
|
||||
*
|
||||
* @author otto
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CmsDocWithScore extends CmsDoc implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 全文搜索相关度评分(来自 MySQL MATCH...AGAINST)
|
||||
*/
|
||||
private Double searchScore;
|
||||
}
|
||||
|
|
@ -1,13 +1,10 @@
|
|||
package com.microservices.cms.doc.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.microservices.common.core.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author otto
|
||||
*/
|
||||
|
|
@ -26,11 +23,4 @@ public class HotCmsDocDto {
|
|||
@Excel(name = "文章名称")
|
||||
@ApiModelProperty("文章名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("文章概要")
|
||||
private String summary;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@ApiModelProperty("发布时间")
|
||||
private Date publishTime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package com.microservices.cms.doc.domain.gitlink;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
@ -24,12 +22,4 @@ public class EntryDto implements Comparable<EntryDto> {
|
|||
// 重写Comparable接口的compareTo方法,根据年龄升序排列,降序修改相减顺序即可
|
||||
return Math.toIntExact(entryDto.getCommit().getCreated_at_unix() - this.commit.getCreated_at_unix());
|
||||
}
|
||||
|
||||
public static EntryDto getEntryDtoFromJson(JSONObject subEntriesResult) {
|
||||
FileEntryDto fileEntryDto = subEntriesResult.toJavaObject(FileEntryDto.class);
|
||||
if (fileEntryDto == null || fileEntryDto.getEntries() == null) {
|
||||
throw new ServiceException("该文章不存在");
|
||||
}
|
||||
return fileEntryDto.getEntries();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.microservices.cms.doc.mapper;
|
|||
|
||||
import com.microservices.cms.doc.domain.CmsDoc;
|
||||
import com.microservices.cms.doc.domain.CmsDocSearchVo;
|
||||
import com.microservices.cms.doc.domain.CmsDocWithScore;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
|
@ -24,14 +23,6 @@ public interface CmsDocMapper {
|
|||
*/
|
||||
public CmsDoc selectCmsDocById(Long id);
|
||||
|
||||
/**
|
||||
* 批量查询文章信息
|
||||
*
|
||||
* @param ids 文章ID列表
|
||||
* @return 文章信息列表
|
||||
*/
|
||||
List<CmsDoc> selectCmsDocByIds(@Param("ids") List<Long> ids);
|
||||
|
||||
/**
|
||||
* 查询文章信息列表
|
||||
*
|
||||
|
|
@ -40,17 +31,6 @@ public interface CmsDocMapper {
|
|||
*/
|
||||
public List<CmsDoc> selectCmsDocList(CmsDocSearchVo cmsDocSearchVo);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询文章信息列表(设置默认头图为栏目头图)
|
||||
*
|
||||
* @param cmsDocSearchVo 文章信息
|
||||
* @return 文章信息集合
|
||||
*/
|
||||
List<CmsDoc> selectCmsDocListSetDefaultHeadImg(CmsDocSearchVo cmsDocSearchVo);
|
||||
|
||||
|
||||
/**
|
||||
* 新增文章信息
|
||||
*
|
||||
|
|
@ -91,11 +71,6 @@ public interface CmsDocMapper {
|
|||
|
||||
CmsDoc selectCmsDocByFilePathAndDeptId(@Param("filePath") String filePath, @Param("deptId") Long deptId);
|
||||
|
||||
/**
|
||||
* 按文章名+deptId查询(忽略dirName),用于Webhook防重判断
|
||||
*/
|
||||
CmsDoc selectCmsDocByNameAndDeptIdIgnoreDirName(@Param("name") String name, @Param("deptId") Long deptId);
|
||||
|
||||
List<CmsDoc> selectHotCmsDocList(CmsDoc cmsDocInput);
|
||||
|
||||
List<CmsDoc> selectCmsDocDirByDeptIdAndInName(@Param("deptId") Long deptId, @Param("cmsDirNameList") List<String> cmsDirNameList);
|
||||
|
|
@ -197,50 +172,4 @@ public interface CmsDocMapper {
|
|||
Long getNotAuditCmsCountByDeptId(Long deptId);
|
||||
|
||||
Long getCmsDocVisitsByDeptId(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据组织id获取专区下所有文章和栏目
|
||||
* @param deptId 组织id
|
||||
* @return 文章和栏目列表
|
||||
*/
|
||||
List<CmsDoc> selectCmsDocAndDirListByDept(Long deptId);
|
||||
|
||||
void updateCmsDocShaByPathAndDeptId(@Param("sha") String sha, @Param("filePath") String filePath, @Param("deptId") Long deptId);
|
||||
|
||||
/**
|
||||
* 全局搜索 - 全文索引查询
|
||||
*
|
||||
* @param keyword 搜索关键词
|
||||
* @param deptId 组织ID(可选)
|
||||
* @param offset 偏移量
|
||||
* @param pageSize 每页数量
|
||||
* @return 搜索结果列表
|
||||
*/
|
||||
List<CmsDoc> globalSearch(@Param("keyword") String keyword, @Param("deptId") Long deptId,
|
||||
@Param("offset") int offset, @Param("pageSize") int pageSize);
|
||||
|
||||
/**
|
||||
* 全局搜索结果计数
|
||||
*
|
||||
* @param keyword 搜索关键词
|
||||
* @param deptId 组织ID(可选)
|
||||
* @return 结果数量
|
||||
*/
|
||||
Long globalSearchCount(@Param("keyword") String keyword, @Param("deptId") Long deptId);
|
||||
|
||||
/**
|
||||
* 全局搜索 - 全文索引查询(含评分)
|
||||
*
|
||||
* @param keyword 搜索关键词
|
||||
* @param deptId 组织ID(可选)
|
||||
* @param offset 偏移量
|
||||
* @param pageSize 每页数量
|
||||
* @return 搜索结果列表(含评分)
|
||||
*/
|
||||
List<CmsDocWithScore> globalSearchWithScore(
|
||||
@Param("keyword") String keyword,
|
||||
@Param("deptId") Long deptId,
|
||||
@Param("offset") int offset,
|
||||
@Param("pageSize") int pageSize
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public interface ICmsAsyncService {
|
|||
|
||||
void asyncCreateBranchAndDeleteFileAndCreatePR(CmsDoc newDocWithAudit, CmsProject cmsProject);
|
||||
|
||||
void asyncMoveFileToNewDir(CmsProject cmsProject, CmsDoc oldCmsDir, String newCmsDirName);
|
||||
void asyncMoveFileToNewDir(CmsProject cmsProject, CmsDoc oldCmsDir, CmsDoc newCmsDir);
|
||||
|
||||
/**
|
||||
* 推送文章数据到搜索引擎
|
||||
|
|
@ -99,38 +99,4 @@ public interface ICmsAsyncService {
|
|||
* @param cmsDoc 文章
|
||||
*/
|
||||
void pushDocDataSearchEngine(CmsDoc cmsDoc);
|
||||
|
||||
void clearTmpDoc(CmsProject cmsProject,List<CmsDoc> tmpDocList);
|
||||
|
||||
/**
|
||||
* 异步增加文章发布积分
|
||||
*
|
||||
* @param deptId 组织ID
|
||||
* @param createBy 创建人用户名
|
||||
* @param docId 文章ID
|
||||
* @param subjectDesc 文章标题
|
||||
*/
|
||||
void addPublishDocPointsAsync(Long deptId, String createBy, Long docId, String subjectDesc);
|
||||
|
||||
/**
|
||||
* 异步增加文章浏览积分(每满100次+2,上限50)
|
||||
*
|
||||
* @param deptId 组织ID
|
||||
* @param createBy 创建人用户名
|
||||
* @param docId 文章ID
|
||||
* @param docName 文章名称
|
||||
* @param totalVisits 累计阅读次数
|
||||
* @param pointsTriggerCount 当前第几次增加积分
|
||||
*/
|
||||
void addVisitsDocPointsAsync(Long deptId, String createBy, Long docId, String docName, Long totalVisits);
|
||||
|
||||
/**
|
||||
* 异步增加文章被设为精选的积分
|
||||
*
|
||||
* @param deptId 组织ID
|
||||
* @param createBy 创建人用户名
|
||||
* @param docId 文章ID
|
||||
* @param subjectDesc 文章标题
|
||||
*/
|
||||
void addFeaturedDocPointsAsync(Long deptId, String createBy, Long docId, String subjectDesc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import com.microservices.cms.doc.domain.*;
|
|||
import com.microservices.cms.doc.domain.gitlink.EntryDto;
|
||||
import com.microservices.cms.doc.domain.gitlink.FileEntryDto;
|
||||
import com.microservices.cms.project.domain.CmsProject;
|
||||
import com.microservices.common.core.web.page.GenericsTableDataInfo;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
|
@ -57,9 +56,9 @@ public interface ICmsDocService {
|
|||
*
|
||||
* @param id
|
||||
* @param cmsDocDto 文章信息
|
||||
* @return 结果 文章id
|
||||
* @return 结果
|
||||
*/
|
||||
public Long updateCmsDoc(Long id, CmsDocDto cmsDocDto);
|
||||
public boolean updateCmsDoc(Long id, CmsDocDto cmsDocDto);
|
||||
|
||||
/**
|
||||
* 批量删除文章信息
|
||||
|
|
@ -145,15 +144,6 @@ public interface ICmsDocService {
|
|||
*/
|
||||
List<CmsDocBaseDto> selectHomePageDocList(Long deptId);
|
||||
|
||||
/**
|
||||
* 查询首页文章合并列表(积分置顶文章 + 首页推荐文章,自动去重,置顶在前)
|
||||
*
|
||||
* @param zoneId 专区ID
|
||||
* @param topDocIds 置顶文章 docId 有序列表(前端按此顺序排列)
|
||||
* @return 合并后的首页文章列表(isTop=true 标识置顶文章)
|
||||
*/
|
||||
List<CmsDocBaseDto> selectHomePageDocMergeList(Long zoneId, List<Long> topDocIds);
|
||||
|
||||
/**
|
||||
* 初始化栏目
|
||||
*
|
||||
|
|
@ -208,8 +198,6 @@ public interface ICmsDocService {
|
|||
*/
|
||||
List<CmsDocAllDto> selectCmsDocListByDept(Long deptId, CmsDocSearchVo cmsDocSearchVo);
|
||||
|
||||
GenericsTableDataInfo<CmsDocAllDto> selectAllDocList(Long deptId, CmsDocSearchVo cmsDocSearchVo);
|
||||
|
||||
/**
|
||||
* 查询专区下文章数量
|
||||
*
|
||||
|
|
@ -300,12 +288,4 @@ public interface ICmsDocService {
|
|||
CmsDocBaseDto selectCmsDocBaseInfoById(Long id);
|
||||
|
||||
Long getCmsDocVisitsByDeptId(Long deptId);
|
||||
|
||||
List<CmsDocBaseDto> selectSetDefaultHeadImgCmsDocList(Long dirId, CmsDocSearchVo cmsDocSearchVo);
|
||||
|
||||
List<CmsDoc> selectCmsDocAndDirListByDept(Long deptId);
|
||||
|
||||
void updateCmsDocShaByPathAndDeptId(String sha, String filePath, Long deptId);
|
||||
|
||||
List<CmsDoc> getTmpDocList(CmsDoc cmsDoc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,18 +16,14 @@ import com.microservices.cms.project.service.ICmsProjectService;
|
|||
import com.microservices.cms.utils.CmsConstants;
|
||||
import com.microservices.cms.utils.CmsGitLinkRequestUrl;
|
||||
import com.microservices.cms.utils.CmsUtils;
|
||||
import com.microservices.cms.utils.CustomExecutorFactory;
|
||||
import com.microservices.common.core.constant.CacheConstants;
|
||||
import com.microservices.common.core.constant.Constants;
|
||||
import com.microservices.common.core.constant.SecurityConstants;
|
||||
import com.microservices.common.core.enums.DocAndZoneOperation;
|
||||
import com.microservices.common.core.enums.DocAuditStatus;
|
||||
import com.microservices.common.core.enums.SystemRole;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.DateUtils;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.core.utils.html.EscapeUtil;
|
||||
import com.microservices.common.core.utils.sign.Base64;
|
||||
import com.microservices.common.core.utils.uuid.IdUtils;
|
||||
import com.microservices.common.httpClient.constant.GitLinkConstants;
|
||||
import com.microservices.common.httpClient.service.HttpAPIService;
|
||||
|
|
@ -35,7 +31,6 @@ import com.microservices.common.httpClient.util.GitLinkRequestHelper;
|
|||
import com.microservices.common.redis.service.RedisService;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.system.api.RemoteDeptService;
|
||||
import com.microservices.system.api.RemoteUserService;
|
||||
import com.microservices.system.api.RemoteZoneService;
|
||||
import com.microservices.system.api.utils.FeignUtils;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
|
|
@ -52,7 +47,6 @@ import org.springframework.util.DigestUtils;
|
|||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -98,10 +92,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
@Autowired
|
||||
private RemoteZoneService remoteZoneService;
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
@Autowired
|
||||
private RequestConfig config;
|
||||
|
||||
/**
|
||||
* 异步设置文章更新时间
|
||||
*
|
||||
|
|
@ -118,7 +109,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
} else {
|
||||
redisService.setCacheObject(updateDocIntervalKey, cmsProject.getName(), 1L, TimeUnit.MINUTES);
|
||||
}
|
||||
CmsDocSearchVo cmsDocSearch = new CmsDocSearchVo();
|
||||
CmsDocSearchVo cmsDocSearch=new CmsDocSearchVo();
|
||||
cmsDocSearch.setDeptId(cmsProject.getDeptId());
|
||||
List<CmsDoc> cmsDocList = cmsDocMapper.selectCmsDocList(cmsDocSearch);
|
||||
for (EntryDto entryDto : entryDtoList) {
|
||||
|
|
@ -159,7 +150,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
webhook.put("eventCondition", "push");
|
||||
webhook.put("http_method", "POST");
|
||||
webhook.put("secret", "");
|
||||
webhook.put("url", gatewayUrl + "/cms/doc/open/dept/" + cmsProject.getDeptId());
|
||||
webhook.put("url", gatewayUrl+"/cms/doc/open/dept/"+cmsProject.getDeptId());
|
||||
webhook.put("events", new String[]{"push"});
|
||||
jsonObject.put("webhook", webhook);
|
||||
//增加Webhook
|
||||
|
|
@ -240,7 +231,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
|
||||
private void syncDocAddedData(CmsProject cmsProject, List<String> addedList) {
|
||||
for (String addedFilePath : addedList) {
|
||||
for (String addedFilePath:addedList) {
|
||||
try {
|
||||
String[] filePathList = addedFilePath.split("/");
|
||||
if (filePathList.length != 2) {
|
||||
|
|
@ -256,27 +247,18 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
CmsDoc cmsDoc = cmsDocMapper.selectCmsDocByNameAndDeptId(CmsUtils.getFileNameNoSuffix(entry.getName()), cmsProject.getDeptId(), dirName);
|
||||
if (cmsDoc == null) {
|
||||
// 防重:按文章名+deptId查一次,排除正在移动栏目的已有记录
|
||||
String docName = CmsUtils.getFileNameNoSuffix(entry.getName());
|
||||
CmsDoc existingDoc = cmsDocMapper.selectCmsDocByNameAndDeptIdIgnoreDirName(docName, cmsProject.getDeptId());
|
||||
if (existingDoc != null) {
|
||||
existingDoc.setDirName(dirName);
|
||||
existingDoc.setFilePath(dirName + "/" + existingDoc.getFileName());
|
||||
cmsDocMapper.updateCmsDoc(existingDoc);
|
||||
} else {
|
||||
syncCreateDoc(entry, dirName, cmsProject.getDeptId(), fileEntry.getLast_commit());
|
||||
}
|
||||
syncCreateDoc(entry, dirName, cmsProject.getDeptId(), fileEntry.getLast_commit());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}catch (Exception e){
|
||||
logger.error("[{}]同步新增文章发生异常:{}"
|
||||
, cmsProject.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void syncDocRemovedData(CmsProject cmsProject, List<String> removedList) {
|
||||
for (String removedFilePath : removedList) {
|
||||
private void syncDocRemovedData(CmsProject cmsProject,List<String> removedList) {
|
||||
for (String removedFilePath:removedList) {
|
||||
try {
|
||||
String[] filePathList = removedFilePath.split("/");
|
||||
if (filePathList.length != 2) {
|
||||
|
|
@ -375,7 +357,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
cmsDocSearch.setDeptId(cmsDir.getDeptId());
|
||||
cmsDocSearch.setDirName(cmsDir.getName());
|
||||
cmsDocSearch.setIsDir(false);
|
||||
List<CmsDoc> cmsDocList = cmsDocMapper.selectCmsDocList(cmsDocSearch);
|
||||
List<CmsDoc> cmsDocList=cmsDocMapper.selectCmsDocList(cmsDocSearch);
|
||||
//获取数据库所有文件的filePath
|
||||
List<String> databaseFilePathList = cmsDocList.stream().map(CmsDoc::getFilePath).collect(Collectors.toList());
|
||||
//获取需要新增的文章
|
||||
|
|
@ -401,16 +383,16 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
@Override
|
||||
public void asyncDocData(Long deptId, String bodyStr) {
|
||||
//防止多次操作同时执行,将同步内容放入队列,根据先后时间执行同步动作
|
||||
String cmsSyncDeptIdKey = CacheConstants.CMS_SYNC_DEPT_ID_KEY + deptId;
|
||||
String cmsSyncDeptIdKey=CacheConstants.CMS_SYNC_DEPT_ID_KEY+deptId;
|
||||
//为当前同步操作生成UUID,若拿到的UUID为自身,则执行本次同步动作
|
||||
String UUID = IdUtils.fastSimpleUUID();
|
||||
String UUID= IdUtils.fastSimpleUUID();
|
||||
redisService.leftPush(cmsSyncDeptIdKey, UUID);
|
||||
//设置缓存过期时间,防止异常情况导致同步无法继续执行
|
||||
redisService.expire(cmsSyncDeptIdKey, 3600, TimeUnit.SECONDS);
|
||||
String currentUUID = String.valueOf(redisService.listIndexOf(cmsSyncDeptIdKey, -1));
|
||||
//设置最大循环阈值,防止意外情况导致死循环(7200次,约1小时左右)
|
||||
int threshold = 7200;
|
||||
while (!UUID.equals(currentUUID) && threshold != 0) {
|
||||
int threshold=7200;
|
||||
while (!UUID.equals(currentUUID)&&threshold!=0){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
|
|
@ -420,41 +402,41 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
threshold--;
|
||||
}
|
||||
|
||||
try {
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(deptId);
|
||||
JSONObject body = JSONObject.parseObject(bodyStr);
|
||||
try{
|
||||
CmsProject cmsProject=cmsProjectService.selectCmsProjectByDeptId(deptId);
|
||||
JSONObject body=JSONObject.parseObject(bodyStr);
|
||||
//获取本次推送中Commit总数
|
||||
Integer totalCommits = body.getInteger("total_commits");
|
||||
Integer totalCommits=body.getInteger("total_commits");
|
||||
//从webhook请求中获取本次提交内容
|
||||
JSONArray commits = body.getJSONArray("commits");
|
||||
JSONArray commits=body.getJSONArray("commits");
|
||||
//当commit总数大于提交的列表数量时,代表此次PUSH未携带所有commit,此时进行一次全量同步
|
||||
if (totalCommits != null
|
||||
&& commits != null
|
||||
&& totalCommits > commits.size()) {
|
||||
if(totalCommits!=null
|
||||
&&commits!=null
|
||||
&&totalCommits>commits.size()){
|
||||
fullSyncDocData(cmsProject);
|
||||
} else {
|
||||
for (int i = commits.size() - 1; i >= 0; i--) {
|
||||
JSONObject commit = commits.getJSONObject(i);
|
||||
}else{
|
||||
for (int i = commits.size()-1; i >=0 ; i--) {
|
||||
JSONObject commit=commits.getJSONObject(i);
|
||||
//获取新增的文件列表
|
||||
JSONArray addedList = commit.getJSONArray("added");
|
||||
if (addedList != null) {
|
||||
syncDocAddedData(cmsProject, addedList.toJavaList(String.class));
|
||||
JSONArray addedList=commit.getJSONArray("added");
|
||||
if(addedList!=null){
|
||||
syncDocAddedData(cmsProject,addedList.toJavaList(String.class));
|
||||
}
|
||||
//获取删除的文件列表
|
||||
JSONArray removedList = commit.getJSONArray("removed");
|
||||
if (removedList != null) {
|
||||
syncDocRemovedData(cmsProject, removedList.toJavaList(String.class));
|
||||
JSONArray removedList=commit.getJSONArray("removed");
|
||||
if(removedList!=null){
|
||||
syncDocRemovedData(cmsProject,removedList.toJavaList(String.class));
|
||||
}
|
||||
//获取更新的文件列表
|
||||
JSONArray modifiedList = commit.getJSONArray("modified");
|
||||
if (modifiedList != null) {
|
||||
JSONArray modifiedList=commit.getJSONArray("modified");
|
||||
if(modifiedList!=null){
|
||||
syncDocModifiedData(cmsProject, modifiedList.toJavaList(String.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}catch (Exception e) {
|
||||
logger.error("同步文章时发送异常:{}", e.getMessage());
|
||||
} finally {
|
||||
}finally {
|
||||
//本次同步执行完成后,再弹出该UUID
|
||||
redisService.rightPop(cmsSyncDeptIdKey, 500, TimeUnit.MICROSECONDS);
|
||||
}
|
||||
|
|
@ -487,12 +469,12 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void syncCreateDir(String dirName, EntryDto entry, CmsProject cmsProject, boolean isCreateKeep) {
|
||||
public void syncCreateDir(String dirName,EntryDto entry,CmsProject cmsProject,boolean isCreateKeep){
|
||||
CmsDoc cmsDir = new CmsDoc();
|
||||
cmsDir.setName(dirName);
|
||||
cmsDir.setCreateTime(entry.getCommit().getCreated_at());
|
||||
boolean insertResult;
|
||||
if (isCreateKeep) {
|
||||
if(isCreateKeep){
|
||||
//若该栏目不存在,检查文件夹中是否存在.keep文件
|
||||
JSONObject subEntriesResult = gitLinkRequestHelper.doGet(
|
||||
CmsGitLinkRequestUrl.GET_FILE_SUB_ENTRIES(cmsProject, cmsDir.getName(), CmsConstants.BRANCH_MASTER));
|
||||
|
|
@ -502,14 +484,14 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
|
||||
if (keepEntry != null) {
|
||||
//若存在,则在数据库中创建该栏目
|
||||
insertResult = createCmsDir(cmsDir, cmsProject.getDeptId(), keepEntry);
|
||||
insertResult=createCmsDir(cmsDir,cmsProject.getDeptId(),keepEntry);
|
||||
} else {
|
||||
//若不存在,则在数据库中创建该栏目,同时在仓库的该文件夹下创建.keep文件
|
||||
insertResult = cmsDocService.insertCmsDocDir(cmsProject.getDeptId(), cmsDir.copyToCmsDir());
|
||||
}
|
||||
} else {
|
||||
}else{
|
||||
//若不自动创建,则在数据库中创建根据文件名该栏目
|
||||
insertResult = createCmsDir(cmsDir, cmsProject.getDeptId(), entry);
|
||||
insertResult=createCmsDir(cmsDir,cmsProject.getDeptId(),entry);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -518,7 +500,7 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean createCmsDir(CmsDoc cmsDir, Long deptId, EntryDto entry) {
|
||||
private boolean createCmsDir(CmsDoc cmsDir,Long deptId,EntryDto entry){
|
||||
cmsDir.setIsDir(true);
|
||||
cmsDir.setFilePath(cmsDir.getDirPath());
|
||||
cmsDir.setDeptId(deptId);
|
||||
|
|
@ -632,12 +614,11 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
100, "..."), tmpBranchName);
|
||||
} catch (ServiceException e) {
|
||||
//忽略重复创建PR异常
|
||||
if (!e.getMessage().contains("合并请求已存在")) {
|
||||
if (!"请求GitLink失败(合并请求已存在)".equals(e.getMessage())) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cmsDocService.updateCmsCommonDatabase(cmsDoc, tmpBranchName);
|
||||
}
|
||||
|
||||
|
|
@ -697,7 +678,6 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
requestBody);
|
||||
cmsDoc.setAuditPrNumber(result.getString("pull_request_number") + "-" + result.getString("pull_request_id"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CmsDoc updateCmsDocDatabaseAndUpdateForGitLink(CmsDoc oldCmsDoc, CmsDocDto cmsDocDto, String branchName) {
|
||||
if (oldCmsDoc == null) {
|
||||
|
|
@ -738,8 +718,8 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
|
||||
if (isChangeName || isChangeDir) {
|
||||
oldCmsDoc = renameAndChangeDirCmsDoc(oldCmsDoc, cmsProject, newName, newDirName, branchName);
|
||||
// 立即更新数据库中的dirName/filePath,避免GitLink Webhook回调时查不到记录导致重复INSERT
|
||||
cmsDocMapper.updateCmsDoc(oldCmsDoc);
|
||||
//todo 此处是否需要更新数据库待讨论
|
||||
//updateCmsCommonDatabase(oldCmsDoc);
|
||||
}
|
||||
|
||||
boolean isChangeContent = false;
|
||||
|
|
@ -891,87 +871,27 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void asyncMoveFileToNewDir(CmsProject cmsProject, CmsDoc oldCmsDir, String newCmsDirName) {
|
||||
@Async
|
||||
public void asyncMoveFileToNewDir(CmsProject cmsProject, CmsDoc oldCmsDir, CmsDoc newCmsDir) {
|
||||
try {
|
||||
JSONObject dirFilesJson = gitLinkRequestHelper.doGet(CmsGitLinkRequestUrl.GET_DIR_SUB_ENTRIES(
|
||||
cmsProject,
|
||||
oldCmsDir.getName(),
|
||||
CmsConstants.BRANCH_MASTER));
|
||||
List<EntryDto> entryDtoList = cmsDocService.getEntriesFromRequestResult(dirFilesJson, cmsProject, false);
|
||||
CountDownLatch countDownLatch = new CountDownLatch(entryDtoList.size());
|
||||
// 异步获取每篇文章内容
|
||||
entryDtoList.forEach(entryDto -> {
|
||||
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
|
||||
try {
|
||||
JSONObject fileSubEntriesResult = gitLinkRequestHelper.doGet(
|
||||
CmsGitLinkRequestUrl.GET_FILE_SUB_ENTRIES(
|
||||
cmsProject,
|
||||
entryDto.getPath(),
|
||||
CmsConstants.BRANCH_MASTER));
|
||||
EntryDto cmsDocEntryDto = EntryDto.getEntryDtoFromJson(fileSubEntriesResult);
|
||||
entryDto.setContent(cmsDocEntryDto.getContent());
|
||||
} finally {
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
try {
|
||||
countDownLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("栏目重命名失败(将对应代码库中文章移动至新文件夹失败):{}", e.getMessage());
|
||||
throw new ServiceException("栏目重命名失败");
|
||||
}
|
||||
|
||||
for (EntryDto entryDto : entryDtoList) {
|
||||
JSONObject updateFileBody = new JSONObject();
|
||||
updateFileBody.put("branch", CmsConstants.BRANCH_MASTER);
|
||||
updateFileBody.put("message", "移动文章至新栏目");
|
||||
updateFileBody.put("from_path", entryDto.getPath());
|
||||
String newFilePath = newCmsDirName + "/" + entryDto.getName();
|
||||
updateFileBody.put("filepath", newFilePath);
|
||||
updateFileBody.put("base64_filepath", Base64.contentToBase64(newFilePath));
|
||||
updateFileBody.put("sha", entryDto.getSha());
|
||||
String content = entryDto.getContent();
|
||||
if (content == null) {
|
||||
content = "";
|
||||
}
|
||||
updateFileBody.put("content", content);
|
||||
gitLinkRequestHelper.doPut(CmsGitLinkRequestUrl.UPDATE_FILE(cmsProject), updateFileBody);
|
||||
}
|
||||
CmsDoc newCmsDoc = oldCmsDir.copyToRenameCmsDir(newCmsDirName);
|
||||
//在数据库中重命名该栏目
|
||||
cmsDocService.updateCmsCommonDatabase(newCmsDoc, CmsConstants.BRANCH_MASTER);
|
||||
remoteZoneService.lockCmsByDeptId(cmsProject.getDeptId(), 1, SecurityConstants.INNER);
|
||||
//创建新栏目
|
||||
String message = String.format("重命名栏目:由[%s]重命名为[%s]", oldCmsDir.getName(), newCmsDir.getName());
|
||||
cmsDocService.createFileByGitLink(newCmsDir, message, "");
|
||||
//在数据库中重命名该栏目,防止后续操作推送的WebHook重复创建栏目
|
||||
cmsDocService.updateCmsCommonDatabase(newCmsDir, CmsConstants.BRANCH_MASTER);
|
||||
//将原栏目中所有文章移动到新栏目中
|
||||
moveCmsDocToNewCmsDir(cmsProject, oldCmsDir.getName(), newCmsDir.getName(), message);
|
||||
//删除旧栏目
|
||||
deleteCmsDocByGitLink(cmsProject, oldCmsDir);
|
||||
} catch (Exception e) {
|
||||
logger.error("重命名栏目失败(原栏目名称[{}],新栏目名称[{}]):{}", oldCmsDir.getName(), newCmsDirName, e.getMessage());
|
||||
throw new ServiceException("重命名栏目失败(原栏目名称[" + oldCmsDir.getName() + "],新栏目名称[" + newCmsDirName + "])");
|
||||
logger.error("重命名栏目失败(原栏目名称[{}],新栏目名称[{}]):{}", oldCmsDir.getName(), newCmsDir.getName(), e.getMessage());
|
||||
throw new ServiceException("重命名栏目失败(原栏目名称[" + oldCmsDir.getName() + "],新栏目名称[" + newCmsDir.getName() + "])");
|
||||
} finally {
|
||||
remoteZoneService.lockCmsByDeptId(cmsProject.getDeptId(), 0, SecurityConstants.INNER);
|
||||
}
|
||||
// finally {
|
||||
// remoteZoneService.lockCmsByDeptId(cmsProject.getDeptId(), 0, SecurityConstants.INNER);
|
||||
// }
|
||||
}
|
||||
|
||||
// @Override
|
||||
// @Async
|
||||
// public void asyncMoveFileToNewDir(CmsProject cmsProject, CmsDoc oldCmsDir, CmsDoc newCmsDir) {
|
||||
// try {
|
||||
// remoteZoneService.lockCmsByDeptId(cmsProject.getDeptId(), 1, SecurityConstants.INNER);
|
||||
// //创建新栏目
|
||||
// String message = String.format("重命名栏目:由[%s]重命名为[%s]", oldCmsDir.getName(), newCmsDir.getName());
|
||||
// cmsDocService.createFileByGitLink(newCmsDir, message, "");
|
||||
// //在数据库中重命名该栏目,防止后续操作推送的WebHook重复创建栏目
|
||||
// cmsDocService.updateCmsCommonDatabase(newCmsDir, CmsConstants.BRANCH_MASTER);
|
||||
// //将原栏目中所有文章移动到新栏目中
|
||||
// moveCmsDocToNewCmsDir(cmsProject, oldCmsDir.getName(), newCmsDir.getName(), message);
|
||||
// //删除旧栏目
|
||||
// deleteCmsDocByGitLink(cmsProject, oldCmsDir);
|
||||
// } catch (Exception e) {
|
||||
// logger.error("重命名栏目失败(原栏目名称[{}],新栏目名称[{}]):{}", oldCmsDir.getName(), newCmsDir.getName(), e.getMessage());
|
||||
// throw new ServiceException("重命名栏目失败(原栏目名称[" + oldCmsDir.getName() + "],新栏目名称[" + newCmsDir.getName() + "])");
|
||||
// } finally {
|
||||
// remoteZoneService.lockCmsByDeptId(cmsProject.getDeptId(), 0, SecurityConstants.INNER);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void pushDocDataSearchEngine(CmsDoc cmsDoc) {
|
||||
|
|
@ -1018,23 +938,6 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearTmpDoc(CmsProject cmsProject, List<CmsDoc> tmpDocList) {
|
||||
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
|
||||
for (CmsDoc tmpDoc : tmpDocList) {
|
||||
//拒绝GitLink合并请求
|
||||
String gitLinkPullRequestNumber = tmpDoc.getAuditPrNumber().split("-")[0];
|
||||
gitLinkRequestHelper.doPost(
|
||||
CmsGitLinkRequestUrl.REFUSE_MERGE_PULL_REQUEST(cmsProject, gitLinkPullRequestNumber), null);
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, tmpDoc.getAuditTmpBranchName()), null);
|
||||
// 所有删除操作调整为将审核状态设置为已拒绝
|
||||
tmpDoc.setAuditStatus(DocAuditStatus.AUDIT_FAIL.getAuditCode());
|
||||
tmpDoc.setRemark("管理员删除");
|
||||
cmsDocMapper.updateCmsDoc(tmpDoc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void moveCmsDocToNewCmsDir(CmsProject cmsProject, String oldDirName, String newDirName, String message) {
|
||||
CmsDocSearchVo cmsDocSearch = new CmsDocSearchVo();
|
||||
cmsDocSearch.setIsDir(false);
|
||||
|
|
@ -1087,127 +990,4 @@ public class CmsAsyncServiceImpl implements ICmsAsyncService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为积分部门
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 是否为积分部门
|
||||
*/
|
||||
private boolean isPointsDept(Long deptId) {
|
||||
Long cachedPointsDeptId = redisService.getCacheObject(CacheConstants.ZONE_POINTS_DEPT_ID_KEY);
|
||||
return cachedPointsDeptId != null && cachedPointsDeptId > 0 && cachedPointsDeptId.equals(deptId);
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void addPublishDocPointsAsync(Long deptId, String createBy, Long docId, String subjectDesc) {
|
||||
try {
|
||||
if (deptId == null || createBy == null) {
|
||||
logger.warn("文章审核通过增加积分失败,deptId或createBy为空,docId={}", docId);
|
||||
return;
|
||||
}
|
||||
// 检查是否为积分部门
|
||||
if (!isPointsDept(deptId)) {
|
||||
logger.info("文章审核通过增加积分跳过,非积分部门,deptId={},docId={}", deptId, docId);
|
||||
return;
|
||||
}
|
||||
// 获取用户ID
|
||||
com.microservices.system.api.domain.SysUser sysUser = FeignUtils.getReturnData(
|
||||
remoteUserService.getSysUserByUserName(createBy, SecurityConstants.INNER));
|
||||
if (sysUser == null || sysUser.getUserId() == null) {
|
||||
logger.warn("文章审核通过增加积分失败,未找到用户信息,createBy={},docId={}", createBy, docId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 直接写入 Redis 积分队列,由 Zone 模块定时任务消费
|
||||
JSONObject task = new JSONObject();
|
||||
task.put("sourceType", CmsConstants.PUBLISH_DOC);
|
||||
task.put("userId", sysUser.getUserId());
|
||||
task.put("deptId", deptId);
|
||||
task.put("sourceId", docId);
|
||||
task.put("subjectDesc", subjectDesc);
|
||||
task.put("operatorId", sysUser.getUserId());
|
||||
redisService.leftPush(CmsConstants.ZONE_POINTS_ASYNC_QUEUE_KEY, task.toJSONString());
|
||||
logger.info("文章审核通过增加积分任务已写入队列,docId={},userId={},deptId={}", docId, sysUser.getUserId(), deptId);
|
||||
} catch (Exception e) {
|
||||
// 捕获异常,确保不影响主事务
|
||||
logger.error("文章审核通过增加积分异常,docId={}", docId, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void addVisitsDocPointsAsync(Long deptId, String createBy, Long docId, String docName, Long totalVisits) {
|
||||
try {
|
||||
if (deptId == null || createBy == null) {
|
||||
logger.warn("文章浏览增加积分失败,参数不合法,deptId={},createBy={}", deptId, createBy);
|
||||
return;
|
||||
}
|
||||
// 检查是否为积分部门
|
||||
if (!isPointsDept(deptId)) {
|
||||
logger.info("文章浏览增加积分跳过,非积分部门,deptId={},docId={}", deptId, docId);
|
||||
return;
|
||||
}
|
||||
// 获取用户ID
|
||||
com.microservices.system.api.domain.SysUser sysUser = FeignUtils.getReturnData(
|
||||
remoteUserService.getSysUserByUserName(createBy, SecurityConstants.INNER));
|
||||
if (sysUser == null || sysUser.getUserId() == null) {
|
||||
logger.warn("文章浏览增加积分失败,未找到用户信息,createBy={},docId={}", createBy, docId);
|
||||
return;
|
||||
}
|
||||
// 直接写入 Redis 积分队列,由 Zone 模块定时任务消费
|
||||
JSONObject task = new JSONObject();
|
||||
task.put("sourceType", CmsConstants.VISITS_DOC);
|
||||
task.put("userId", sysUser.getUserId());
|
||||
task.put("deptId", deptId);
|
||||
task.put("sourceId", docId);
|
||||
// JSONObject sourceData = new JSONObject();
|
||||
// sourceData.put("totalVisits", totalVisits);
|
||||
// sourceData.put("currentIncrement", pointsTriggerCount);
|
||||
task.put("sourceData", totalVisits);
|
||||
task.put("subjectDesc", docName);
|
||||
task.put("operatorId", SecurityUtils.getUserId());
|
||||
redisService.leftPush(CmsConstants.ZONE_POINTS_ASYNC_QUEUE_KEY, task.toJSONString());
|
||||
logger.info("文章浏览增加积分任务已写入队列,docId={},userId={},deptId={},totalVisits={}", docId, sysUser.getUserId(), deptId, totalVisits);
|
||||
} catch (Exception e) {
|
||||
// 捕获异常,确保不影响主事务
|
||||
logger.error("文章浏览增加积分异常,docId={}", docId, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void addFeaturedDocPointsAsync(Long deptId, String createBy, Long docId, String subjectDesc) {
|
||||
try {
|
||||
if (deptId == null || createBy == null) {
|
||||
logger.warn("积分-文章精选:参数不合法,deptId={},createBy={}", deptId, createBy);
|
||||
return;
|
||||
}
|
||||
// 检查是否为积分部门
|
||||
if (!isPointsDept(deptId)) {
|
||||
logger.info("积分-文章精选:非积分部门,deptId={},docId={}", deptId, docId);
|
||||
return;
|
||||
}
|
||||
// 获取用户ID
|
||||
com.microservices.system.api.domain.SysUser sysUser = FeignUtils.getReturnData(
|
||||
remoteUserService.getSysUserByUserName(createBy, SecurityConstants.INNER));
|
||||
if (sysUser == null || sysUser.getUserId() == null) {
|
||||
logger.warn("积分-文章精选:未找到用户信息,createBy={},docId={}", createBy, docId);
|
||||
return;
|
||||
}
|
||||
// 直接写入 Redis 积分队列,由 Zone 模块定时任务消费
|
||||
JSONObject task = new JSONObject();
|
||||
task.put("sourceType", CmsConstants.FEATURED_DOC);
|
||||
task.put("userId", sysUser.getUserId());
|
||||
task.put("deptId", deptId);
|
||||
task.put("sourceId", docId);
|
||||
task.put("subjectDesc", "《" + subjectDesc + "》管理员标记");
|
||||
task.put("operatorId", SecurityUtils.getUserId());
|
||||
redisService.leftPush(CmsConstants.ZONE_POINTS_ASYNC_QUEUE_KEY, task.toJSONString());
|
||||
logger.info("文章被设为精选增加积分任务已写入队列,docId={},userId={},deptId={}", docId, sysUser.getUserId(), deptId);
|
||||
} catch (Exception e) {
|
||||
// 捕获异常,确保不影响主事务
|
||||
logger.error("文章被设为精选增加积分异常,docId={}", docId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import com.microservices.cms.utils.CmsGitLinkRequestUrl;
|
|||
import com.microservices.common.core.constant.CacheConstants;
|
||||
import com.microservices.common.core.constant.HttpStatus;
|
||||
import com.microservices.common.core.constant.SecurityConstants;
|
||||
import com.microservices.common.core.constant.UserConstants;
|
||||
import com.microservices.common.core.enums.DocAndZoneOperation;
|
||||
import com.microservices.common.core.enums.DocAuditStatus;
|
||||
import com.microservices.common.core.enums.SystemRole;
|
||||
|
|
@ -24,12 +23,10 @@ import com.microservices.common.core.utils.DateUtils;
|
|||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.core.utils.bean.BeanUtils;
|
||||
import com.microservices.common.core.utils.html.EscapeUtil;
|
||||
import com.microservices.common.core.web.page.GenericsTableDataInfo;
|
||||
import com.microservices.common.httpClient.constant.GitLinkConstants;
|
||||
import com.microservices.common.httpClient.util.GitLinkRequestHelper;
|
||||
import com.microservices.common.redis.service.RedisService;
|
||||
import com.microservices.common.security.auth.AuthUtil;
|
||||
import com.microservices.common.security.service.TokenService;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.system.api.RemoteDeptService;
|
||||
import com.microservices.system.api.RemoteUserService;
|
||||
|
|
@ -50,11 +47,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -86,8 +79,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
@Autowired
|
||||
private RemoteDeptService remoteDeptService;
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private ICmsDocCommentService cmsDocCommentService;
|
||||
@Value("${cms.detailPath:/newdetail}")
|
||||
|
|
@ -97,7 +88,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
* 查询文章信息
|
||||
*
|
||||
* @param id 文章信息主键
|
||||
* @param isOpen 是否公开访问
|
||||
* @param isOpen
|
||||
* @return 文章信息
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -112,14 +103,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(cmsDoc.getDeptId());
|
||||
|
||||
// 确定查询文件的分支:已发布文章或非仓库改动使用 master,其他使用临时分支
|
||||
String branchName;
|
||||
if (DocAuditStatus.AUDIT_PASS.getAuditCode().equals(cmsDoc.getAuditStatus())
|
||||
|| (cmsDoc.getAuditType() != null && cmsDoc.getAuditType().contains(DocAndZoneOperation.OPERATION_NON_REPO_UPDATE.getOperationCode()))) {
|
||||
branchName = CmsConstants.BRANCH_MASTER;
|
||||
} else {
|
||||
branchName = cmsDoc.getAuditTmpBranchName();
|
||||
}
|
||||
String branchName = DocAuditStatus.AUDIT_PASS.getAuditCode().equals(cmsDoc.getAuditStatus()) ? CmsConstants.BRANCH_MASTER : cmsDoc.getAuditTmpBranchName();
|
||||
FileEntryDto fileEntryDto = getFileEntryDto(cmsProject, cmsDoc.getFilePath(), branchName);
|
||||
EntryDto entryDto = fileEntryDto.getEntries();
|
||||
|
||||
|
|
@ -130,7 +114,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
if (cmsDoc.getPublishTime() != null && cmsDoc.getPublishTime().after(cmsDoc.getCreateTime())) {
|
||||
cmsDocDto.setIsFirstPublish(false);
|
||||
}
|
||||
if (isOpen && DocAuditStatus.AUDIT_PASS.getAuditCode().equals(cmsDoc.getAuditStatus())) {
|
||||
if (isOpen) {
|
||||
updateVisits(cmsDocDto.getId());
|
||||
}
|
||||
return cmsDocDto;
|
||||
|
|
@ -186,21 +170,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
return cmsDocList.stream().map(CmsDoc::copyToCmsDocAllDto).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenericsTableDataInfo<CmsDocAllDto> selectAllDocList(Long deptId, CmsDocSearchVo cmsDocSearchVo) {
|
||||
List<CmsDocAllDto> list = selectCmsDocListByDept(deptId, cmsDocSearchVo);
|
||||
list.forEach(x -> {
|
||||
String docDetailUrl = getDocDetailUrl(x.getDeptId(), x.getId());
|
||||
x.setDocDetailUrl(docDetailUrl);
|
||||
|
||||
Boolean editable = isCmsDocEditable(x);
|
||||
x.setEditable(editable);
|
||||
|
||||
});
|
||||
int count = selectCmsDocCountByDept(deptId, cmsDocSearchVo);
|
||||
return new GenericsTableDataInfo<>(list, Long.valueOf(count));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int selectCmsDocCountByDept(Long deptId, CmsDocSearchVo cmsDocSearchVo) {
|
||||
cmsDocSearchVo.setDeptId(deptId);
|
||||
|
|
@ -228,21 +197,20 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
@Override
|
||||
public void updateCmsDir(Long id, CmsDirUpdateVo cmsDirUpdateVo) {
|
||||
CmsDoc oldCmsDir = selectCmsDir(id);
|
||||
checkCmsLockStatus(oldCmsDir.getDeptId());
|
||||
//设置栏目排序
|
||||
setCmsSort(cmsDirUpdateVo.getOrder(), oldCmsDir, false, null);
|
||||
oldCmsDir.setHeadImg(cmsDirUpdateVo.getHeadImg());
|
||||
updateCmsCommonDatabase(oldCmsDir, CmsConstants.BRANCH_MASTER);
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(oldCmsDir.getDeptId());
|
||||
String newCmsDirName = cmsDirUpdateVo.getName();
|
||||
CmsDoc newCmsDir = oldCmsDir.copyToRenameCmsDir(cmsDirUpdateVo.getName());
|
||||
|
||||
if (StringUtils.isNotEmpty(newCmsDirName) && !newCmsDirName.equals(oldCmsDir.getName())) {
|
||||
CmsDoc cmsDir = cmsDocMapper.selectCmsDocDirByNameAndDeptId(newCmsDirName, oldCmsDir.getDeptId());
|
||||
if (StringUtils.isNotEmpty(newCmsDir.getName()) && !newCmsDir.getName().equals(oldCmsDir.getName())) {
|
||||
CmsDoc cmsDir = cmsDocMapper.selectCmsDocDirByNameAndDeptId(newCmsDir.getName(), oldCmsDir.getDeptId());
|
||||
if (cmsDir != null) {
|
||||
throw new ServiceException("栏目名称已存在,不允许进行重命名(新栏目名称[" + newCmsDirName + "])");
|
||||
throw new ServiceException("栏目名称已存在,不允许进行重命名(新栏目名称[" + newCmsDir.getName() + "])");
|
||||
}
|
||||
cmsAsyncService.asyncMoveFileToNewDir(cmsProject, oldCmsDir, newCmsDir);
|
||||
}
|
||||
// 异步修改栏目名称(将仓库内原文件夹下所有文章移动到新文件夹下)
|
||||
cmsAsyncService.asyncMoveFileToNewDir(cmsProject, oldCmsDir, newCmsDirName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -263,14 +231,14 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
@Override
|
||||
public List<CmsDocDetailDto> selectCmsDocDetailList(Long dirId) {
|
||||
List<CmsDocDetailDto> cmsDocDetailDtoList = new ArrayList<>();
|
||||
CmsDoc cmsDir = selectCmsDir(dirId);
|
||||
CmsDoc cmsDir = cmsDocMapper.selectCmsDocDirById(dirId);
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(cmsDir.getDeptId());
|
||||
CmsDocSearchVo cmsDocSearchVo = new CmsDocSearchVo();
|
||||
cmsDocSearchVo.setDirName(cmsDir.getName());
|
||||
cmsDocSearchVo.setDeptId(cmsDir.getDeptId());
|
||||
cmsDocSearchVo.setIsDir(false);
|
||||
List<CmsDoc> cmsDocList = cmsDocMapper.selectCmsDocListSetDefaultHeadImg(cmsDocSearchVo);
|
||||
List<CompletableFuture<CmsDocDetailDto>> futures = new ArrayList<>();
|
||||
List<CmsDoc> cmsDocList = cmsDocMapper.selectCmsDocList(cmsDocSearchVo);
|
||||
List<CompletableFuture<CmsDocDetailDto>> futures = new ArrayList();
|
||||
for (CmsDoc cmsDoc : cmsDocList) {
|
||||
CompletableFuture<CmsDocDetailDto> future = CompletableFuture.supplyAsync(() -> {
|
||||
CmsDocDetailDto cmsDocDetailDto = cmsDoc.copyToCmsDocDetailDto();
|
||||
|
|
@ -315,21 +283,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
return selectCmsDocListByDatabase(dirId, cmsDocSearchVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsDocBaseDto> selectSetDefaultHeadImgCmsDocList(Long dirId, CmsDocSearchVo cmsDocSearchVo) {
|
||||
return selectCmsDocListSetDefaultHeadImgByDatabase(dirId, cmsDocSearchVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsDoc> selectCmsDocAndDirListByDept(Long deptId) {
|
||||
return cmsDocMapper.selectCmsDocAndDirListByDept(deptId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCmsDocShaByPathAndDeptId(String sha, String filePath, Long deptId) {
|
||||
cmsDocMapper.updateCmsDocShaByPathAndDeptId(sha, filePath, deptId);
|
||||
}
|
||||
|
||||
private List<CmsDocBaseDto> selectCmsDocListByDatabase(Long dirId, CmsDocSearchVo cmsDocSearchVo) {
|
||||
CmsDoc cmsDocDir = selectCmsDir(dirId);
|
||||
|
||||
|
|
@ -342,25 +295,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
return cmsDocList.stream().map(CmsDoc::copyToCmsDocBaseDto).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文章默认头图为栏目头图
|
||||
*
|
||||
* @param dirId 栏目id
|
||||
* @param cmsDocSearchVo 文章查询条件
|
||||
* @return 文章列表
|
||||
*/
|
||||
private List<CmsDocBaseDto> selectCmsDocListSetDefaultHeadImgByDatabase(Long dirId, CmsDocSearchVo cmsDocSearchVo) {
|
||||
CmsDoc cmsDocDir = selectCmsDir(dirId);
|
||||
|
||||
cmsDocSearchVo.setDeptId(cmsDocDir.getDeptId());
|
||||
cmsDocSearchVo.setDirName(cmsDocDir.getName());
|
||||
List<CmsDoc> cmsDocList = cmsDocMapper.selectCmsDocListSetDefaultHeadImg(cmsDocSearchVo);
|
||||
if (cmsDocList == null || cmsDocList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return cmsDocList.stream().map(CmsDoc::copyToCmsDocBaseDto).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查专区资讯是否处于锁定状态,若处于则抛出异常
|
||||
*
|
||||
|
|
@ -390,16 +324,12 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
checkCmsLockStatus(dirDoc.getDeptId());
|
||||
CmsDoc cmsDoc = cmsDocInputDto.toCmsDoc(dirDoc);
|
||||
|
||||
if (isNoAuditRequired(dirDoc.getDeptId()) || tokenService.hasDeptPerms(dirDoc.getDeptId(), UserConstants.CMS_PERMS_DOCS_AUDIT)) {
|
||||
if (isNoAuditRequired(dirDoc.getDeptId()) || isCurrentUserZoneAdmin(dirDoc.getDeptId())) {
|
||||
//文章自动置为审核通过状态值
|
||||
cmsDoc.setAuditStatus(DocAuditStatus.AUDIT_PASS.getAuditCode());
|
||||
boolean success = insertCommonCmsDoc(cmsDoc,
|
||||
"创建文章:" + StringUtils.truncateStringAndConcatenatingSpecifiedString(cmsDoc.getName(), 100, "..."),
|
||||
cmsDocInputDto.getContent());
|
||||
if (success) {
|
||||
// 自动审核通过时也需要增加积分
|
||||
cmsAsyncService.addPublishDocPointsAsync(cmsDoc.getDeptId(), cmsDoc.getCreateBy(), cmsDoc.getId(), cmsDoc.getName());
|
||||
}
|
||||
return success ? cmsDoc.getId().intValue() : null;
|
||||
} else {
|
||||
//创建临时分支,创建文件,创建PR
|
||||
|
|
@ -437,9 +367,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
public String getCmsDocFileContent(CmsProject cmsProject, CmsDoc cmsDoc) {
|
||||
String branchName = CmsConstants.BRANCH_MASTER;
|
||||
if (!DocAuditStatus.AUDIT_PASS.getAuditCode().equals(cmsDoc.getAuditStatus())) {
|
||||
if (StringUtils.isNotEmpty(cmsDoc.getAuditTmpBranchName())) {
|
||||
branchName = cmsDoc.getAuditTmpBranchName();
|
||||
}
|
||||
branchName = cmsDoc.getAuditTmpBranchName();
|
||||
}
|
||||
//当删除文章为文件夹时,判断该文件夹下是否存在文章,若存在需先删除所有文章
|
||||
JSONObject getSubEntriesResult = gitLinkRequestHelper.doGet(
|
||||
|
|
@ -459,34 +387,9 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean auditCmsDoc(Long docId, CmsDocAuditVo cmsDocAuditVo) {
|
||||
CmsDoc cmsDoc = cmsDocMapper.selectCmsDocById(docId);
|
||||
if (cmsDoc == null) {
|
||||
throw new ServiceException("该文章不存在");
|
||||
}
|
||||
checkCmsLockStatus(cmsDoc.getDeptId());
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(cmsDoc.getDeptId());
|
||||
|
||||
// 设置审核备注
|
||||
cmsDoc.setRemark(cmsDocAuditVo.getRemark());
|
||||
|
||||
if (cmsDocAuditVo.getPass() == 1) {
|
||||
// 处理非仓库改动的审核通过
|
||||
if (cmsDoc.getAuditType() != null
|
||||
&& cmsDoc.getAuditType().contains(DocAndZoneOperation.OPERATION_NON_REPO_UPDATE.getOperationCode())) {
|
||||
Long oldCmsDocId = Long.parseLong(cmsDoc.getAuditType().split("-")[1]);
|
||||
CmsDoc oldCmsDoc = cmsDocMapper.selectCmsDocById(oldCmsDocId);
|
||||
|
||||
// 用新文章的非仓库字段更新旧文章
|
||||
oldCmsDoc.setHeadImg(cmsDoc.getHeadImg());
|
||||
oldCmsDoc.setSummary(cmsDoc.getSummary());
|
||||
oldCmsDoc.setKeywords(cmsDoc.getKeywords());
|
||||
oldCmsDoc.setRemark(cmsDoc.getRemark());
|
||||
cmsDocMapper.updateCmsDoc(oldCmsDoc);
|
||||
|
||||
// 删除待审核记录
|
||||
cmsDocMapper.deleteCmsDocById(cmsDoc.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
//同意合并请求
|
||||
JSONObject result = mergePullRequestByGitLink(cmsProject, cmsDoc);
|
||||
if (result.containsKey(GitLinkConstants.STATUS_KEY)) {
|
||||
|
|
@ -508,16 +411,8 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
}
|
||||
}
|
||||
if (cmsDocAuditVo.getPass() == 0) {
|
||||
// 处理非仓库改动的审核拒绝
|
||||
if (cmsDoc.getAuditType().contains(DocAndZoneOperation.OPERATION_NON_REPO_UPDATE.getOperationCode())) {
|
||||
handleCmsDocWithNoPassByReedit(cmsDocAuditVo, cmsDoc, cmsProject);
|
||||
return true;
|
||||
}
|
||||
|
||||
//拒绝GitLink合并请求
|
||||
String gitLinkPullRequestNumber = cmsDoc.getAuditPrNumber().split("-")[0];
|
||||
JSONObject result = gitLinkRequestHelper.doPost(
|
||||
CmsGitLinkRequestUrl.REFUSE_MERGE_PULL_REQUEST(cmsProject, gitLinkPullRequestNumber), null);
|
||||
JSONObject result = refuseMergePullRequestByGitLink(cmsDoc, cmsProject);
|
||||
if (result.containsKey(GitLinkConstants.STATUS_KEY)) {
|
||||
//2.若拒绝GitLink合并请求操作返回正确的状态值,更新数据库
|
||||
if (result.getInteger(GitLinkConstants.STATUS_KEY).equals(1)) {
|
||||
|
|
@ -564,10 +459,8 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
if (cmsDocAuditVo.getReedit().equals(0)) {
|
||||
//删除待审核文章
|
||||
cmsDocMapper.deleteCmsDocById(cmsDoc.getId());
|
||||
// 删除分支(如果有)
|
||||
if (StringUtils.isNotEmpty(cmsDoc.getAuditTmpBranchName())) {
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()), null);
|
||||
}
|
||||
//删除分支
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -579,7 +472,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
int success = deleteCmsDocDatabaseById(ids);
|
||||
if (success == ids.length) {
|
||||
//删除临时分支
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()), null);
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -599,7 +492,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
int success = cmsDocMapper.deleteCmsDocById(newDocId);
|
||||
if (success > 0) {
|
||||
//删除临时分支
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()), null);
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -613,13 +506,11 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
int success = cmsDocMapper.updateCmsDoc(cmsDoc);
|
||||
if (success > 0) {
|
||||
//删除临时分支
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()), null);
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()));
|
||||
}
|
||||
|
||||
// 推送文章地址到搜索引擎
|
||||
cmsAsyncService.pushDocDataSearchEngine(cmsDoc);
|
||||
// 文章审核通过后,给作者增加积分(异步执行,不影响主事务)
|
||||
cmsAsyncService.addPublishDocPointsAsync(cmsDoc.getDeptId(), cmsDoc.getCreateBy(), cmsDoc.getId(), cmsDoc.getName());
|
||||
}
|
||||
|
||||
private JSONObject mergePullRequestByGitLink(CmsProject cmsProject, CmsDoc cmsDoc) {
|
||||
|
|
@ -634,6 +525,12 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
CmsGitLinkRequestUrl.MERGE_PULL_REQUEST(cmsProject, gitLinkPullRequestId), requestBody);
|
||||
}
|
||||
|
||||
private JSONObject refuseMergePullRequestByGitLink(CmsDoc cmsDoc, CmsProject cmsProject) {
|
||||
//1.调用gitlink拒绝合并请求接口
|
||||
return gitLinkRequestHelper.doPost(
|
||||
CmsGitLinkRequestUrl.REFUSE_MERGE_PULL_REQUEST(cmsProject, cmsDoc.getAuditPrNumber()), null);
|
||||
}
|
||||
|
||||
public static String sha1(String data) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA1");
|
||||
|
|
@ -655,7 +552,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
throw new ServiceException("计算字符串Sha出错");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCmsSort(Integer order, CmsDoc oldCmsDoc, boolean isChangeOnDir, String isHomePage) {
|
||||
//调整文章/栏目顺序
|
||||
|
|
@ -775,47 +671,11 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long updateCmsDoc(Long id, CmsDocDto cmsDocDto) {
|
||||
public boolean updateCmsDoc(Long id, CmsDocDto cmsDocDto) {
|
||||
CmsDoc oldCmsDoc = cmsDocMapper.selectCmsDocById(id);
|
||||
checkCmsLockStatus(oldCmsDoc.getDeptId());
|
||||
if (!hasRepoRelatedChanged(oldCmsDoc, cmsDocDto)) {
|
||||
// 更新非仓库字段到原文章对象
|
||||
if (StringUtils.isNotEmpty(cmsDocDto.getHeadImg())) {
|
||||
oldCmsDoc.setHeadImg(cmsDocDto.getHeadImg());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(cmsDocDto.getSummary())) {
|
||||
oldCmsDoc.setSummary(cmsDocDto.getSummary());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(cmsDocDto.getKeywords())) {
|
||||
oldCmsDoc.setKeywords(cmsDocDto.getKeywords());
|
||||
}
|
||||
|
||||
// 管理员或免审核:直接更新原记录
|
||||
if (tokenService.hasDeptPerms(oldCmsDoc.getDeptId(), UserConstants.CMS_PERMS_DOCS_AUDIT)
|
||||
|| isNoAuditRequired(oldCmsDoc.getDeptId())) {
|
||||
cmsDocMapper.updateCmsDoc(oldCmsDoc);
|
||||
return oldCmsDoc.getId();
|
||||
}
|
||||
|
||||
// 需要审核:创建新的待审核记录(与仓库改动逻辑一致)
|
||||
if (oldCmsDoc.getAuditStatus().equals(DocAuditStatus.AUDIT_PASS.getAuditCode())) {
|
||||
CmsDoc newDocWithAudit = insertDocWithAudit(oldCmsDoc,
|
||||
DocAndZoneOperation.OPERATION_NON_REPO_UPDATE.getOperationCode() + "-" + oldCmsDoc.getId(),
|
||||
DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
return newDocWithAudit.getId();
|
||||
}
|
||||
oldCmsDoc.setAuditStatus(DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
if (oldCmsDoc.getAuditType().contains(DocAndZoneOperation.OPERATION_CREATE.getOperationCode())
|
||||
|| oldCmsDoc.getAuditType().contains(DocAndZoneOperation.OPERATION_UPDATE.getOperationCode())) {
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(oldCmsDoc.getDeptId());
|
||||
// 重新开启PR
|
||||
String gitLinkPullRequestNumber = oldCmsDoc.getAuditPrNumber().split("-")[0];
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.REOPEN_PULL_REQUEST(cmsProject, gitLinkPullRequestNumber), null);
|
||||
}
|
||||
// 待审核/未通过文章重新编辑
|
||||
cmsDocMapper.updateCmsDoc(oldCmsDoc);
|
||||
return oldCmsDoc.getId();
|
||||
return cmsDocMapper.updateCmsDoc(oldCmsDoc) > 0;
|
||||
}
|
||||
// 当文章名称发生更改时,判断文章名是否在当前栏目下已存在
|
||||
if (StringUtils.isNotEmpty(cmsDocDto.getName()) && !cmsDocDto.getName().equals(oldCmsDoc.getName())) {
|
||||
|
|
@ -828,16 +688,8 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
}
|
||||
checkDocName(cmsDocDto.getName(), oldCmsDoc.getDeptId(), dirName);
|
||||
}
|
||||
|
||||
// 当用户更新栏目时,需检查新栏目下是否已存在相同文章名
|
||||
if (cmsDocDto.getDirId() != null) {
|
||||
CmsDir cmsDir = selectCmsDirById(cmsDocDto.getDirId(), false);
|
||||
if (cmsDir != null && !cmsDir.getName().equals(oldCmsDoc.getDirName())) {
|
||||
checkDocName(cmsDocDto.getName(), oldCmsDoc.getDeptId(), cmsDir.getName());
|
||||
}
|
||||
}
|
||||
//用户为专区管理员或专区无审核机制时,直接更新文章及仓库主分支
|
||||
if (tokenService.hasDeptPerms(oldCmsDoc.getDeptId(), UserConstants.CMS_PERMS_DOCS_AUDIT) || isNoAuditRequired(oldCmsDoc.getDeptId())) {
|
||||
if (isCurrentUserZoneAdmin(oldCmsDoc.getDeptId()) || isNoAuditRequired(oldCmsDoc.getDeptId())) {
|
||||
//专区管理员重新编辑并提交审核未通过文章 或 重新编辑并提交待审核文章时专区不需审核机制
|
||||
if (!oldCmsDoc.getAuditStatus().equals(DocAuditStatus.AUDIT_PASS.getAuditCode())) {
|
||||
//文章审核类型:update-原文章id 取出原文章id直接更新,删除待审核更新类型文章
|
||||
|
|
@ -845,15 +697,14 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
Long originCmsDocId = Long.parseLong(oldCmsDoc.getAuditType().split("-")[1]);
|
||||
CmsDoc originCmsDoc = cmsDocMapper.selectCmsDocById(originCmsDocId);
|
||||
deleteTmpBranchIfBranchExist(oldCmsDoc);
|
||||
BeanUtils.copyProperties(originCmsDoc, oldCmsDoc);
|
||||
BeanUtils.copyProperties(originCmsDoc,oldCmsDoc);
|
||||
cmsDocMapper.deleteCmsDocById(id);
|
||||
} else
|
||||
//文章审核类型:create 直接新增文章
|
||||
if (oldCmsDoc.getAuditType() != null && oldCmsDoc.getAuditType().contains(DocAndZoneOperation.OPERATION_CREATE.getOperationCode())) {
|
||||
deleteTmpBranchIfBranchExist(oldCmsDoc);
|
||||
cmsDocMapper.deleteCmsDocById(id);
|
||||
directlyInsertAuditedCmsDocWhenZoneHasNoAuditRequired(cmsDocDto, oldCmsDoc);
|
||||
return oldCmsDoc.getId();
|
||||
return directlyInsertAuditedCmsDocWhenZoneHasNoAuditRequired(cmsDocDto, oldCmsDoc);
|
||||
}
|
||||
}
|
||||
String branchName = CmsConstants.BRANCH_MASTER;
|
||||
|
|
@ -861,62 +712,25 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
oldCmsDoc.setAuditStatus(DocAuditStatus.AUDIT_PASS.getAuditCode());
|
||||
oldCmsDoc.setAuditTmpBranchName(null);
|
||||
oldCmsDoc.setKeywords(cmsDocDto.getKeywords());
|
||||
updateCmsCommonDatabase(oldCmsDoc, CmsConstants.BRANCH_MASTER);
|
||||
return oldCmsDoc.getId();
|
||||
return updateCmsCommonDatabase(oldCmsDoc, CmsConstants.BRANCH_MASTER) > 0;
|
||||
} else {
|
||||
|
||||
CmsDoc newDocWithAudit = new CmsDoc();
|
||||
//待审核、未通过文章重新编辑并提交
|
||||
if (DocAuditStatus.AUDIT_FAIL.getAuditCode().equals(oldCmsDoc.getAuditStatus())
|
||||
|| DocAuditStatus.TO_BE_AUDIT.getAuditCode().equals(oldCmsDoc.getAuditStatus())) {
|
||||
|
||||
// 非仓库改动待审核记录:检查是否有仓库改动
|
||||
if (oldCmsDoc.getAuditType() != null
|
||||
&& oldCmsDoc.getAuditType().contains(DocAndZoneOperation.OPERATION_NON_REPO_UPDATE.getOperationCode())) {
|
||||
|
||||
if (!hasRepoRelatedChanged(oldCmsDoc, cmsDocDto)) {
|
||||
// 纯非仓库改动:继续在当前记录上更新
|
||||
oldCmsDoc.setAuditStatus(DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
if (StringUtils.isNotEmpty(cmsDocDto.getHeadImg())) {
|
||||
oldCmsDoc.setHeadImg(cmsDocDto.getHeadImg());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(cmsDocDto.getSummary())) {
|
||||
oldCmsDoc.setSummary(cmsDocDto.getSummary());
|
||||
}
|
||||
if (StringUtils.isNotEmpty(cmsDocDto.getKeywords())) {
|
||||
oldCmsDoc.setKeywords(cmsDocDto.getKeywords());
|
||||
}
|
||||
cmsDocMapper.updateCmsDoc(oldCmsDoc);
|
||||
return oldCmsDoc.getId();
|
||||
} else {
|
||||
// 有仓库改动:转为仓库改动类型,删除当前记录,重新创建
|
||||
Long oldCmsDocId = Long.parseLong(oldCmsDoc.getAuditType().split("-")[1]);
|
||||
CmsDoc originCmsDoc = cmsDocMapper.selectCmsDocById(oldCmsDocId);
|
||||
cmsDocMapper.deleteCmsDocById(oldCmsDoc.getId());
|
||||
|
||||
// 按照仓库改动逻辑重新创建
|
||||
newDocWithAudit = insertDocWithAudit(originCmsDoc,
|
||||
DocAndZoneOperation.OPERATION_UPDATE.getOperationCode() + "-" + oldCmsDocId,
|
||||
DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
cmsAsyncService.asyncUpdateBranchAndFileAndCreatePR(newDocWithAudit, cmsDocDto);
|
||||
return newDocWithAudit.getId();
|
||||
}
|
||||
}
|
||||
|
||||
// 仓库改动待审核记录:继续在当前记录上更新
|
||||
oldCmsDoc.setAuditStatus(DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
newDocWithAudit = oldCmsDoc;
|
||||
} else {
|
||||
} else
|
||||
//更新已发布文章
|
||||
if (oldCmsDoc.getAuditStatus().equals(DocAuditStatus.AUDIT_PASS.getAuditCode())) {
|
||||
//1.创建一条auditType="update-原文章id",audit_status为2,其余字段与待更新文章一致的新文章数据
|
||||
newDocWithAudit = insertDocWithAudit(oldCmsDoc,
|
||||
DocAndZoneOperation.OPERATION_UPDATE.getOperationCode() + "-" + id,
|
||||
DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
}
|
||||
//1.创建一条auditType="update-原文章id",audit_status为2,其余字段与待更新文章一致的新文章数据
|
||||
newDocWithAudit = insertDocWithAudit(oldCmsDoc,
|
||||
DocAndZoneOperation.OPERATION_UPDATE.getOperationCode() + "-" + id,
|
||||
DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
}
|
||||
cmsAsyncService.asyncUpdateBranchAndFileAndCreatePR(newDocWithAudit, cmsDocDto);
|
||||
return newDocWithAudit.getId();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -968,10 +782,10 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
private void deleteTmpBranchIfBranchExist(CmsDoc cmsDoc) {
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(cmsDoc.getDeptId());
|
||||
try {
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()), null);
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()));
|
||||
} catch (ServiceException e) {
|
||||
//忽略分支不存在异常
|
||||
if (!"分支不存在!".equals(e.getMessage())) {
|
||||
if(!"分支不存在!".equals(e.getMessage())) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -999,29 +813,15 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
}
|
||||
|
||||
private CmsDoc insertDocWithAudit(CmsDoc oldCmsDoc, String auditType, String auditStatus) {
|
||||
List<CmsDoc> tmpDocList = getTmpDocList(oldCmsDoc);
|
||||
if (!tmpDocList.isEmpty()) {
|
||||
throw new ServiceException("已存在待审核操作,请等待审核完成后再进行操作");
|
||||
}
|
||||
oldCmsDoc.setId(null);
|
||||
oldCmsDoc.setAuditType(auditType);
|
||||
oldCmsDoc.setAuditStatus(auditStatus);
|
||||
oldCmsDoc.setCreateBy(SecurityUtils.getUsername());
|
||||
|
||||
// 非 repo 改动:显式设置 auditTmpBranchName 为 null(没有对应的分支)
|
||||
if (auditType != null && auditType.contains(DocAndZoneOperation.OPERATION_NON_REPO_UPDATE.getOperationCode())) {
|
||||
oldCmsDoc.setAuditTmpBranchName(null);
|
||||
}
|
||||
|
||||
cmsDocMapper.insertCmsDoc(oldCmsDoc);
|
||||
return oldCmsDoc;
|
||||
}
|
||||
|
||||
private CmsDoc insertDeletedDocWithAudit(CmsDoc oldCmsDoc, Long oldCmsDocId) {
|
||||
List<CmsDoc> tmpDocList = getTmpDocList(oldCmsDoc);
|
||||
if (!tmpDocList.isEmpty()) {
|
||||
throw new ServiceException("已存在待审核操作,请等待审核完成后再进行操作");
|
||||
}
|
||||
oldCmsDoc.setId(null);
|
||||
oldCmsDoc.setAuditType(DocAndZoneOperation.OPERATION_DELETE.getOperationCode() + "-" + oldCmsDocId);
|
||||
oldCmsDoc.setAuditStatus(DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
|
|
@ -1063,7 +863,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
cmsDoc.setIsDir(true);
|
||||
cmsDoc.setFilePath(cmsDoc.getDirPath(cmsDir.getName()));
|
||||
cmsDoc.setDeptId(deptId);
|
||||
cmsDoc.setHeadImg(cmsDir.getHeadImg());
|
||||
cmsDoc.setName(cmsDir.getName());
|
||||
return insertCommonCmsDoc(cmsDoc, "创建栏目:" + cmsDir.getName(), "");
|
||||
}
|
||||
|
|
@ -1150,7 +949,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
List<CmsDoc> cmsDocList = cmsDocMapper.selectHotCmsDocList(cmsDocInput);
|
||||
if (cmsDocList != null) {
|
||||
//todo:需检查该文章是否在GitLink中存在
|
||||
return cmsDocList.stream().map(CmsDoc::copyToHotCmsDocDto).collect(Collectors.toList());
|
||||
return cmsDocList.stream().map(x -> x.copyToHotCmsDocDto()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
|
|
@ -1167,13 +966,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
visits = visits + cmsDoc.getVisits();
|
||||
}
|
||||
cmsDoc.setVisits(visits);
|
||||
int rows = cmsDocMapper.updateCmsDoc(cmsDoc);
|
||||
if (rows > 0) {
|
||||
cmsAsyncService.addVisitsDocPointsAsync(cmsDoc.getDeptId(), cmsDoc.getCreateBy(),
|
||||
cmsDoc.getId(), cmsDoc.getName(), cmsDoc.getVisits());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return cmsDocMapper.updateCmsDoc(cmsDoc) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1197,7 +990,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
for (CmsDoc cmsDir : cmsDirList) {
|
||||
CmsDocSearchVo cmsDocSearchVo = new CmsDocSearchVo();
|
||||
cmsDocSearchVo.setIsOpen(isOpen);
|
||||
List<CmsDocBaseDto> cmsDocBaseDtoList = selectSetDefaultHeadImgCmsDocList(cmsDir.getId(), cmsDocSearchVo);
|
||||
List<CmsDocBaseDto> cmsDocBaseDtoList = selectCmsDocList(cmsDir.getId(), cmsDocSearchVo);
|
||||
CmsDocOverviewDto cmsDocOverviewDto = new CmsDocOverviewDto();
|
||||
cmsDocOverviewDto.setId(cmsDir.getId());
|
||||
cmsDocOverviewDto.setName(cmsDir.getName());
|
||||
|
|
@ -1297,9 +1090,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
//首页推荐时,需将顺序设置为1
|
||||
setCmsSort(1, cmsDoc, false, null);
|
||||
cmsDoc.setIsHomepage(CmsConstants.TRUE);
|
||||
// 文章被设为精选,异步增加作者积分
|
||||
cmsAsyncService.addFeaturedDocPointsAsync(cmsDoc.getDeptId(), cmsDoc.getCreateBy(),
|
||||
cmsDoc.getId(), cmsDoc.getName());
|
||||
}
|
||||
return cmsDocMapper.updateCmsDoc(cmsDoc);
|
||||
}
|
||||
|
|
@ -1314,7 +1104,7 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
CmsDocSearchVo cmsDocSearch = new CmsDocSearchVo();
|
||||
cmsDocSearch.setDeptId(deptId);
|
||||
cmsDocSearch.setIsHomepage(CmsConstants.TRUE);
|
||||
List<CmsDoc> cmsDocList = cmsDocMapper.selectCmsDocListSetDefaultHeadImg(cmsDocSearch);
|
||||
List<CmsDoc> cmsDocList = cmsDocMapper.selectCmsDocList(cmsDocSearch);
|
||||
List<CmsDocBaseDto> cmsDocBaseDtoList = new ArrayList<>();
|
||||
for (CmsDoc cmsDoc : cmsDocList) {
|
||||
CmsDocBaseDto cmsDocBaseDto = cmsDoc.copyToCmsDocBaseDto();
|
||||
|
|
@ -1323,41 +1113,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
return cmsDocBaseDtoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsDocBaseDto> selectHomePageDocMergeList(Long zoneId, List<Long> topDocIds) {
|
||||
Long deptId = getDeptIdByZoneId(zoneId);
|
||||
Set<Long> addedDocIds = new HashSet<>();
|
||||
|
||||
// 1. 获取首页推荐文章列表
|
||||
List<CmsDocBaseDto> homePageDocs = selectHomePageDocList(deptId);
|
||||
List<CmsDocBaseDto> result = new ArrayList<>();
|
||||
|
||||
// 2. 批量查询置顶文章完整数据,按传入顺序放入结果头部
|
||||
if (topDocIds != null && !topDocIds.isEmpty()) {
|
||||
List<CmsDoc> topCmsDocs = cmsDocMapper.selectCmsDocByIds(topDocIds);
|
||||
Map<Long, CmsDoc> topDocMap = new HashMap<>();
|
||||
for (CmsDoc doc : topCmsDocs) {
|
||||
topDocMap.put(doc.getId(), doc);
|
||||
}
|
||||
for (Long docId : topDocIds) {
|
||||
CmsDoc doc = topDocMap.get(docId);
|
||||
if (doc != null) {
|
||||
result.add(doc.copyToCmsDocBaseDto());
|
||||
addedDocIds.add(docId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 追加首页推荐文章(跳过已在置顶列表中的)
|
||||
for (CmsDocBaseDto doc : homePageDocs) {
|
||||
if (!addedDocIds.contains(doc.getId())) {
|
||||
result.add(doc);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CmsDir initCmsDir(Long deptId, CmsDir cmsDirInput) {
|
||||
|
|
@ -1504,17 +1259,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
cmsAsyncService.updateCmsPublishDataByGitLink(cmsProject, cmsDoc, branchName);
|
||||
}
|
||||
|
||||
private int deleteCmsDir(CmsProject cmsProject, CmsDoc cmsDir) {
|
||||
if (!isNoAuditRequired(cmsDir.getDeptId()) || tokenService.hasDeptPerms(cmsDir.getDeptId(), UserConstants.CMS_PERMS_DOCS_AUDIT)) {
|
||||
boolean deleteResult = cmsAsyncService.deleteCmsDocForGitLink(cmsDir, cmsProject, CmsConstants.BRANCH_MASTER);
|
||||
if (deleteResult) {
|
||||
return cmsDocMapper.deleteCmsDocById(cmsDir.getId());
|
||||
}
|
||||
throw new ServiceException("栏目删除失败");
|
||||
}
|
||||
throw new ServiceException("无权限删除栏目");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteCmsDocById(Long id) {
|
||||
CmsDoc cmsDoc = cmsDocMapper.selectCmsDocById(id);
|
||||
|
|
@ -1524,42 +1268,22 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
checkCmsLockStatus(cmsDoc.getDeptId());
|
||||
//2、获取专区项目
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(cmsDoc.getDeptId());
|
||||
if (cmsDoc.getIsDir()) {
|
||||
return deleteCmsDir(cmsProject, cmsDoc);
|
||||
}
|
||||
|
||||
//删除待审核、审核未通过文章——删除临时分支,拒绝合并请求
|
||||
if (DocAuditStatus.TO_BE_AUDIT.getAuditCode().equals(cmsDoc.getAuditStatus())) {
|
||||
// 非仓库改动类型直接删除
|
||||
if (cmsDoc.getAuditType().contains(DocAndZoneOperation.OPERATION_NON_REPO_UPDATE.getOperationCode())) {
|
||||
return cmsDocMapper.deleteCmsDocById(cmsDoc.getId());
|
||||
}
|
||||
|
||||
//拒绝GitLink合并请求
|
||||
String gitLinkPullRequestNumber = cmsDoc.getAuditPrNumber().split("-")[0];
|
||||
gitLinkRequestHelper.doPost(
|
||||
CmsGitLinkRequestUrl.REFUSE_MERGE_PULL_REQUEST(cmsProject, gitLinkPullRequestNumber), null);
|
||||
gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()), null);
|
||||
return cmsDocMapper.deleteCmsDocById(cmsDoc.getId());
|
||||
if (DocAuditStatus.TO_BE_AUDIT.getAuditCode().equals(cmsDoc.getAuditStatus())
|
||||
|| DocAuditStatus.AUDIT_FAIL.getAuditCode().equals(cmsDoc.getAuditStatus())) {
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.DELETE_BRANCH(cmsProject, cmsDoc.getAuditTmpBranchName()));
|
||||
cmsDocMapper.deleteCmsDocById(id);
|
||||
return 1;
|
||||
}
|
||||
if (DocAuditStatus.AUDIT_FAIL.getAuditCode().equals(cmsDoc.getAuditStatus())) {
|
||||
return cmsDocMapper.deleteCmsDocById(cmsDoc.getId());
|
||||
}
|
||||
// 判读当前用户是否拥有文章直接删除权限
|
||||
if (tokenService.hasDeptPerms(cmsDoc.getDeptId(), UserConstants.CMS_PERMS_DOCS_AUDIT) //当前用户为专区管理员
|
||||
if (isCurrentUserZoneAdmin(cmsDoc.getDeptId()) //当前用户为专区管理员
|
||||
|| isNoAuditRequired(cmsDoc.getDeptId()) //当前专区文章发布无需审核机制
|
||||
) {
|
||||
String branchName = CmsConstants.BRANCH_MASTER;
|
||||
boolean deleteResult = cmsAsyncService.deleteCmsDocForGitLink(cmsDoc, cmsProject, branchName);
|
||||
if (deleteResult) {
|
||||
// 拒绝相关合并请求并清理所有临时分支,同时删除所有临时申请
|
||||
List<CmsDoc> tmpDocList = getTmpDocList(cmsDoc);
|
||||
cmsAsyncService.clearTmpDoc(cmsProject, tmpDocList);
|
||||
cmsDoc.setAuditStatus(DocAuditStatus.AUDIT_FAIL.getAuditCode());
|
||||
cmsDoc.setRemark("管理员删除");
|
||||
return cmsDocMapper.updateCmsDoc(cmsDoc);
|
||||
return deleteCmsDocDatabaseById(cmsDoc.getId());
|
||||
}
|
||||
|
||||
} else {
|
||||
//1.创建一条auditType="delete-原文章id",audit_status=2,其余字段与待删除文章一致的新文章数据
|
||||
CmsDoc newDocWithAudit = insertDeletedDocWithAudit(cmsDoc, id);
|
||||
|
|
@ -1569,18 +1293,6 @@ public class CmsDocServiceImpl implements ICmsDocService {
|
|||
throw new ServiceException("文件删除失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsDoc> getTmpDocList(CmsDoc cmsDoc) {
|
||||
CmsDocSearchVo cmsDocSearchVo = new CmsDocSearchVo();
|
||||
cmsDocSearchVo.setName(cmsDoc.getName());
|
||||
cmsDocSearchVo.setDeptId(cmsDoc.getDeptId());
|
||||
cmsDocSearchVo.setIsDir(false);
|
||||
cmsDocSearchVo.setDirName(cmsDoc.getDirName());
|
||||
cmsDocSearchVo.setAuditStatus(DocAuditStatus.TO_BE_AUDIT.getAuditCode());
|
||||
// 拒绝相关合并请求并清理所有临时分支,同时删除所有临时申请
|
||||
return cmsDocMapper.selectCmsDocList(cmsDocSearchVo);
|
||||
}
|
||||
|
||||
public int deleteCmsDocDatabaseById(Long id) {
|
||||
CmsDoc cmsDoc = cmsDocMapper.selectCmsDocById(id);
|
||||
if (cmsDoc != null && !cmsDoc.getIsDir()) {
|
||||
|
|
|
|||
|
|
@ -49,16 +49,6 @@ public class CmsProjectController extends BaseController {
|
|||
return R.ok(changeRoleResult);
|
||||
}
|
||||
|
||||
@InnerAuth
|
||||
@PutMapping("/changeOrgRole/user/{userId}/operate/{operate}")
|
||||
@ApiOperation(value = "修改用户所在GItLink组织中的权限", hidden = true)
|
||||
public R<Boolean> changeUserOrgRole(@PathVariable("userId") Long userId, @PathVariable("operate") Long operate
|
||||
) {
|
||||
Boolean changeRoleResult = cmsProjectService.changeUserOrgRole(userId, operate);
|
||||
return R.ok(changeRoleResult);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询专区对应项目列表
|
||||
*/
|
||||
|
|
@ -105,12 +95,8 @@ public class CmsProjectController extends BaseController {
|
|||
@GetMapping("/getProjectByDeptId/{deptId}")
|
||||
public R<String> getProjectByDeptId(
|
||||
@ApiParam(name = "deptId", value = "组织Id") @PathVariable(value = "deptId") Long deptId) {
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptIdAndNoException(deptId);
|
||||
if (cmsProject == null) {
|
||||
return R.ok(null);
|
||||
} else {
|
||||
return R.ok(JSONObject.toJSONString(cmsProject));
|
||||
}
|
||||
CmsProject cmsProject = cmsProjectService.selectCmsProjectByDeptId(deptId);
|
||||
return R.ok(JSONObject.toJSONString(cmsProject));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -184,16 +170,4 @@ public class CmsProjectController extends BaseController {
|
|||
public R<Boolean> removeByDeptId(@PathVariable(value = "deptId") Long deptId) {
|
||||
return R.ok(cmsProjectService.deleteCmsProjectByDeptId(deptId) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化专区对应项目
|
||||
*/
|
||||
@RequiresPermissions("zone:project:add")
|
||||
@ApiOperation("初始化专区对应项目")
|
||||
@Log(title = "初始化专区对应项目", businessType = BusinessType.INSERT)
|
||||
@PostMapping("initCmsProject/dept/{deptId}")
|
||||
public AjaxResult initCmsProject(
|
||||
@ApiParam(name = "deptId", value = "组织Id") @PathVariable(value = "deptId") Long deptId) {
|
||||
return toAjax(cmsProjectService.initZoneCmsProjectByDept(deptId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
package com.microservices.cms.project.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author otto
|
||||
*/
|
||||
@Data
|
||||
public class GitlinkOrganizationTeamVo implements Serializable {
|
||||
@ApiModelProperty(value = "团队权限")
|
||||
private String authorize;
|
||||
@ApiModelProperty(value = "团队Id")
|
||||
private Long id;
|
||||
@ApiModelProperty(value = "团队名称")
|
||||
private String name;
|
||||
@ApiModelProperty(value = "团队昵称")
|
||||
private String nickname;
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ package com.microservices.cms.project.mapper;
|
|||
|
||||
import com.microservices.cms.project.domain.CmsProject;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -65,25 +64,4 @@ public interface CmsProjectMapper {
|
|||
CmsProject selectCmsProjectByDeptId(Long deptId);
|
||||
|
||||
CmsProject selectCmsProjectByIdentifier(String identifier);
|
||||
|
||||
/**
|
||||
* 全局搜索 - 全文索引查询
|
||||
*
|
||||
* @param keyword 搜索关键词
|
||||
* @param deptId 组织ID(可选)
|
||||
* @param offset 偏移量
|
||||
* @param pageSize 每页数量
|
||||
* @return 搜索结果列表
|
||||
*/
|
||||
List<CmsProject> globalSearch(@Param("keyword") String keyword, @Param("deptId") Long deptId,
|
||||
@Param("offset") int offset, @Param("pageSize") int pageSize);
|
||||
|
||||
/**
|
||||
* 全局搜索结果计数
|
||||
*
|
||||
* @param keyword 搜索关键词
|
||||
* @param deptId 组织ID(可选)
|
||||
* @return 结果数量
|
||||
*/
|
||||
Long globalSearchCount(@Param("keyword") String keyword, @Param("deptId") Long deptId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,10 +78,4 @@ public interface ICmsProjectService {
|
|||
Boolean updateCmsProjectByDept(SysDept dept);
|
||||
|
||||
boolean operateProtectedBranchByZoneAuditSetting(String userName, String identifier, Long deptId, String operationType);
|
||||
|
||||
boolean initZoneCmsProjectByDept(Long deptId);
|
||||
|
||||
CmsProject selectCmsProjectByDeptIdAndNoException(Long deptId);
|
||||
|
||||
Boolean changeUserOrgRole(Long userId, Long operate);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,21 @@
|
|||
package com.microservices.cms.project.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.cms.doc.domain.*;
|
||||
import com.microservices.cms.doc.domain.CmsDir;
|
||||
import com.microservices.cms.doc.domain.CmsDocBaseDto;
|
||||
import com.microservices.cms.doc.domain.CmsDocSearchVo;
|
||||
import com.microservices.cms.doc.service.ICmsAsyncService;
|
||||
import com.microservices.cms.doc.service.ICmsDocService;
|
||||
import com.microservices.cms.project.domain.CmsProject;
|
||||
import com.microservices.cms.project.domain.GitlinkOrganizationTeamVo;
|
||||
import com.microservices.cms.project.mapper.CmsProjectMapper;
|
||||
import com.microservices.cms.project.service.ICmsProjectService;
|
||||
import com.microservices.cms.utils.CmsConstants;
|
||||
import com.microservices.cms.utils.CmsGitLinkRequestUrl;
|
||||
import com.microservices.common.core.constant.HttpStatus;
|
||||
import com.microservices.common.core.constant.SecurityConstants;
|
||||
import com.microservices.common.core.enums.SystemRole;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.PinYinStringUtils;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.datascope.annotation.DataScope;
|
||||
import com.microservices.common.httpClient.domain.GitLinkRequestUrl;
|
||||
import com.microservices.common.httpClient.util.GitLinkRequestHelper;
|
||||
import com.microservices.system.api.RemoteDeptService;
|
||||
import com.microservices.system.api.RemoteUserService;
|
||||
|
|
@ -26,7 +23,6 @@ import com.microservices.system.api.domain.SysDept;
|
|||
import com.microservices.system.api.domain.SysRole;
|
||||
import com.microservices.system.api.domain.SysUser;
|
||||
import com.microservices.system.api.utils.FeignUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
|
@ -41,7 +37,6 @@ import java.util.List;
|
|||
* @author otto
|
||||
* @date 2023-03-27
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CmsProjectServiceImpl implements ICmsProjectService {
|
||||
@Autowired
|
||||
|
|
@ -233,75 +228,6 @@ public class CmsProjectServiceImpl implements ICmsProjectService {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initZoneCmsProjectByDept(Long deptId) {
|
||||
boolean initResult = false;
|
||||
CmsProject cmsProject = cmsProjectMapper.selectCmsProjectByDeptId(deptId);
|
||||
if (cmsProject != null) {
|
||||
JSONObject project = null;
|
||||
try {
|
||||
project = gitLinkRequestHelper.doGet(CmsGitLinkRequestUrl.GET_PROJECT_DETAIL(cmsProject.getUsername(), cmsProject.getIdentifier()));
|
||||
} catch (ServiceException e) {
|
||||
if (!e.getCode().equals(HttpStatus.NOT_FOUND)) {
|
||||
throw new ServiceException(e.getCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
if (project != null) {
|
||||
throw new ServiceException("专区对应项目已存在,不能重复初始化");
|
||||
} else {
|
||||
Long organizationId = getOrganizationId();
|
||||
// 创建专区对应项目
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("user_id", organizationId);
|
||||
jsonObject.put("name", cmsProject.getName());
|
||||
jsonObject.put("repository_name", cmsProject.getIdentifier());
|
||||
jsonObject.put("description", cmsProject.getDescription());
|
||||
jsonObject.put("private", false);
|
||||
//调用GitLink接口创建项目
|
||||
JSONObject result = gitLinkRequestHelper.doPost(CmsGitLinkRequestUrl.CREATE_PROJECT(), jsonObject);
|
||||
initResult = result != null && cmsProject.getIdentifier().equals(result.getString("identifier"));
|
||||
}
|
||||
} else {
|
||||
Long projectId = insertZoneCmsProjectByDept(deptId);
|
||||
if (projectId != null && projectId > 0) {
|
||||
cmsProject = cmsProjectMapper.selectCmsProjectById(projectId);
|
||||
initResult = true;
|
||||
}
|
||||
}
|
||||
if (initResult) {
|
||||
// 批量创建文章对应代码库文件
|
||||
List<CmsDoc> cmsDocAndDirList = cmsDocService.selectCmsDocAndDirListByDept(deptId);
|
||||
if (cmsDocAndDirList == null || cmsDocAndDirList.isEmpty()) {
|
||||
return initResult;
|
||||
}
|
||||
JSONObject docCommitJson = new JSONObject();
|
||||
docCommitJson.put("branch", CmsConstants.BRANCH_MASTER);
|
||||
docCommitJson.put("message", "初始化专区文章对应代码库文件");
|
||||
JSONArray docFiles = new JSONArray();
|
||||
for (CmsDoc cmsDoc : cmsDocAndDirList) {
|
||||
JSONObject docFile = new JSONObject();
|
||||
docFile.put("action_type", "create");
|
||||
docFile.put("content", "");
|
||||
docFile.put("encoding", "text");
|
||||
docFile.put("file_path", cmsDoc.getFilePath());
|
||||
docFiles.add(docFile);
|
||||
}
|
||||
docCommitJson.put("files", docFiles);
|
||||
JSONObject result = gitLinkRequestHelper.doPost(
|
||||
CmsGitLinkRequestUrl.BATCH_COMMIT(cmsProject.getUsername(), cmsProject.getIdentifier())
|
||||
, docCommitJson);
|
||||
if (result == null) {
|
||||
throw new ServiceException("专区对应项目初始化成功,但专区文章在项目中创建失败");
|
||||
}
|
||||
JSONArray resultContents = result.getJSONArray("contents");
|
||||
for (int i = 0; i < resultContents.size(); i++) {
|
||||
JSONObject contentJson = resultContents.getJSONObject(i);
|
||||
cmsDocService.updateCmsDocShaByPathAndDeptId(contentJson.getString("sha"), contentJson.getString("path"), deptId);
|
||||
}
|
||||
}
|
||||
return initResult;
|
||||
}
|
||||
|
||||
|
||||
private String handleSpecialCharacters(String name) {
|
||||
return StringUtils.replace(name, " ", "-");
|
||||
|
|
@ -316,45 +242,6 @@ public class CmsProjectServiceImpl implements ICmsProjectService {
|
|||
return cmsProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CmsProject selectCmsProjectByDeptIdAndNoException(Long deptId) {
|
||||
return cmsProjectMapper.selectCmsProjectByDeptId(deptId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean changeUserOrgRole(Long userId, Long operate) {
|
||||
Long gitlinkOrgId = getOrganizationId();
|
||||
SysUser sysUser = FeignUtils.getReturnData(remoteUserService.getSysUserByUserId(userId, SecurityConstants.INNER));
|
||||
if (sysUser == null) {
|
||||
return false;
|
||||
}
|
||||
List<GitlinkOrganizationTeamVo> gitlinkOrganizationTeamVoList = gitLinkRequestHelper.getAllDataByPage(
|
||||
CmsGitLinkRequestUrl.TEAMS_BY_ORGANIZATION_URL(gitlinkOrgId), "teams", GitlinkOrganizationTeamVo.class
|
||||
);
|
||||
GitlinkOrganizationTeamVo ownerTeam = gitlinkOrganizationTeamVoList.stream().filter(x -> "owner".equals(x.getAuthorize())).findFirst().orElse(null);
|
||||
if (ownerTeam == null) {
|
||||
return false;
|
||||
}
|
||||
if (operate == 1) {
|
||||
JSONObject addUserToTeam = new JSONObject();
|
||||
addUserToTeam.put("username", sysUser.getUserName());
|
||||
gitLinkRequestHelper.doPost(
|
||||
CmsGitLinkRequestUrl.ADD_USER_TO_ORGANIZATION_TEAM(gitLinkOrganization, ownerTeam.getId()), addUserToTeam);
|
||||
}
|
||||
if (operate == 3) {
|
||||
try {
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.DELETE_USER_FROM_ORGANIZATION_TEAM(
|
||||
gitLinkOrganization,
|
||||
ownerTeam.getId(),
|
||||
sysUser.getUserName()
|
||||
));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean changeUserRole(Long userId, Long oldDeptId, Long newDeptId, Long oldRoleId, Long newRoleId) {
|
||||
SysUser sysUser = FeignUtils.getReturnData(remoteUserService.getSysUserByUserId(userId, SecurityConstants.INNER));
|
||||
|
|
@ -373,10 +260,9 @@ public class CmsProjectServiceImpl implements ICmsProjectService {
|
|||
try {
|
||||
gitLinkRequestHelper.doDelete(CmsGitLinkRequestUrl.REMOVE_USER_FROM_PROJECT(oldCmsProject), requestBody);
|
||||
} catch (ServiceException e) {
|
||||
log.error("将用户从原项目中移除发生异常:{}", e.getMessage());
|
||||
// if (!e.getMessage().contains("用户为组织成员,请到组织下操作")||!e.getMessage().contains("还不是项目成员")) {
|
||||
// throw new ServiceException(e.getMessage());
|
||||
// }
|
||||
if (!e.getMessage().contains("用户为组织成员,请到组织下操作")) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
//将用户加入新的项目
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
package com.microservices.cms.search.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 文章搜索请求对象
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("文章搜索请求对象")
|
||||
public class DocSearchRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 搜索关键词
|
||||
*/
|
||||
@ApiModelProperty(value = "搜索关键词", required = true)
|
||||
private String keyword;
|
||||
|
||||
/**
|
||||
* 专区ID
|
||||
*/
|
||||
@ApiModelProperty(value = "专区ID")
|
||||
private Long zoneId;
|
||||
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
@ApiModelProperty(value = "页码")
|
||||
private Integer pageNum = 1;
|
||||
|
||||
/**
|
||||
* 每页数量
|
||||
*/
|
||||
@ApiModelProperty(value = "每页数量")
|
||||
private Integer pageSize = 20;
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
package com.microservices.cms.search.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 全局搜索响应对象
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("文章搜索响应对象")
|
||||
public class DocSearchResponse implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 总结果数
|
||||
*/
|
||||
@ApiModelProperty(value = "总结果数")
|
||||
private Long total;
|
||||
|
||||
/**
|
||||
* 搜索结果列表
|
||||
*/
|
||||
@ApiModelProperty(value = "搜索结果列表")
|
||||
private List<DocSearchResult> results;
|
||||
|
||||
/**
|
||||
* 各类型结果数量统计
|
||||
*/
|
||||
@ApiModelProperty(value = "各类型结果数量统计")
|
||||
private Map<String, Long> typeCounts;
|
||||
|
||||
/**
|
||||
* 搜索耗时(毫秒)
|
||||
*/
|
||||
@ApiModelProperty(value = "搜索耗时(毫秒)")
|
||||
private Long searchTime;
|
||||
|
||||
/**
|
||||
* 搜索关键词
|
||||
*/
|
||||
@ApiModelProperty(value = "搜索关键词")
|
||||
private String keyword;
|
||||
|
||||
/**
|
||||
* 当前页码
|
||||
*/
|
||||
@ApiModelProperty(value = "当前页码")
|
||||
private Integer pageNum;
|
||||
|
||||
/**
|
||||
* 每页数量
|
||||
*/
|
||||
@ApiModelProperty(value = "每页数量")
|
||||
private Integer pageSize;
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
package com.microservices.cms.search.dto;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 文章搜索结果对象
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("文章搜索结果对象")
|
||||
public class DocSearchResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容摘要
|
||||
*/
|
||||
@ApiModelProperty(value = "内容摘要")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 组织ID
|
||||
*/
|
||||
@ApiModelProperty(value = "组织ID")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 相关度评分
|
||||
*/
|
||||
@ApiModelProperty(value = "相关度评分")
|
||||
private Double score;
|
||||
|
||||
/**
|
||||
* 扩展数据(JSON格式)
|
||||
*/
|
||||
@ApiModelProperty(value = "扩展数据")
|
||||
private JSONObject extendData;
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package com.microservices.cms.search.service;
|
||||
|
||||
import com.microservices.cms.search.dto.DocSearchRequest;
|
||||
import com.microservices.cms.search.dto.DocSearchResponse;
|
||||
|
||||
/**
|
||||
* 全局搜索服务接口
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
public interface IGlobalSearchService {
|
||||
|
||||
/**
|
||||
* 全局搜索
|
||||
*
|
||||
* @param request 搜索请求
|
||||
* @return 搜索响应
|
||||
*/
|
||||
DocSearchResponse docSearch(DocSearchRequest request);
|
||||
}
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
package com.microservices.cms.search.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.microservices.cms.doc.domain.CmsDoc;
|
||||
import com.microservices.cms.doc.domain.CmsDocWithScore;
|
||||
import com.microservices.cms.doc.mapper.CmsDocMapper;
|
||||
import com.microservices.cms.doc.service.ICmsDocService;
|
||||
import com.microservices.cms.search.service.IGlobalSearchService;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.redis.service.RedisService;
|
||||
import com.microservices.cms.search.dto.DocSearchRequest;
|
||||
import com.microservices.cms.search.dto.DocSearchResponse;
|
||||
import com.microservices.cms.search.dto.DocSearchResult;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.system.api.model.LoginUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 全局搜索服务实现
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Service
|
||||
public class GlobalSearchServiceImpl implements IGlobalSearchService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GlobalSearchServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private CmsDocMapper cmsDocMapper;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
@Autowired
|
||||
private ICmsDocService cmsDocService;
|
||||
|
||||
private static final String SEARCH_CACHE_PREFIX = "search:cache:";
|
||||
private static final Long CACHE_EXPIRE_SECONDS = 300L; // 5分钟
|
||||
|
||||
@Override
|
||||
public DocSearchResponse docSearch(DocSearchRequest request) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// 参数校验
|
||||
if (StringUtils.isEmpty(request.getKeyword())) {
|
||||
return buildEmptyResponse(request);
|
||||
}
|
||||
|
||||
// 1. 尝试从缓存获取(仅第一页)
|
||||
if (request.getPageNum() == 1) {
|
||||
String cacheKey = buildCacheKey(request);
|
||||
|
||||
DocSearchResponse cached = redisService.getCacheObject(SEARCH_CACHE_PREFIX + cacheKey);
|
||||
if (cached != null) {
|
||||
cached.setSearchTime(System.currentTimeMillis() - startTime);
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 并行搜索各类型
|
||||
List<DocSearchResult> allResults = new ArrayList<>();
|
||||
Map<String, Long> typeCounts = new HashMap<>();
|
||||
|
||||
// 获取当前用户信息
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
|
||||
// 搜索CMS文章
|
||||
List<DocSearchResult> docResults = searchDocs(request);
|
||||
allResults.addAll(docResults);
|
||||
typeCounts.put("doc", (long) docResults.size());
|
||||
|
||||
// 3. 按相关度评分排序
|
||||
allResults.sort((a, b) -> {
|
||||
if (b.getScore() != null && a.getScore() != null) {
|
||||
return b.getScore().compareTo(a.getScore());
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
// 4. 分页
|
||||
int total = allResults.size();
|
||||
int start = (request.getPageNum() - 1) * request.getPageSize();
|
||||
int end = Math.min(start + request.getPageSize(), total);
|
||||
List<DocSearchResult> pagedResults = start < total ?
|
||||
allResults.subList(start, end) : new ArrayList<>();
|
||||
|
||||
// 5. 构建响应
|
||||
DocSearchResponse response = new DocSearchResponse();
|
||||
response.setTotal((long) total);
|
||||
response.setResults(pagedResults);
|
||||
response.setTypeCounts(typeCounts);
|
||||
response.setKeyword(request.getKeyword());
|
||||
response.setPageNum(request.getPageNum());
|
||||
response.setPageSize(request.getPageSize());
|
||||
response.setSearchTime(System.currentTimeMillis() - startTime);
|
||||
|
||||
// 6. 缓存结果(仅第一页)
|
||||
if (request.getPageNum() == 1) {
|
||||
String cacheKey = buildCacheKey(request);
|
||||
redisService.setCacheObject(SEARCH_CACHE_PREFIX + cacheKey, response, CACHE_EXPIRE_SECONDS, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
// 7. 记录搜索日志
|
||||
recordSearchLog(request, response, loginUser);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录搜索日志
|
||||
*/
|
||||
private void recordSearchLog(DocSearchRequest request, DocSearchResponse response, LoginUser loginUser) {
|
||||
Long userId = loginUser != null ? loginUser.getUserId() : null;
|
||||
String searchTypes = "文章";
|
||||
Long deptId = cmsDocService.getDeptIdByZoneId(request.getZoneId());
|
||||
logger.info("全局搜索 - 关键词: {}, 用户ID: {}, 耗时: {}ms, 结果数: {}, 类型: {}, 专区Id: {}, 组织ID: {}",
|
||||
request.getKeyword(),
|
||||
userId,
|
||||
response.getSearchTime(),
|
||||
response.getTotal(),
|
||||
searchTypes,
|
||||
request.getZoneId(),
|
||||
deptId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索CMS文章
|
||||
*/
|
||||
private List<DocSearchResult> searchDocs(DocSearchRequest request) {
|
||||
List<DocSearchResult> results = new ArrayList<>();
|
||||
try {
|
||||
// 使用部门ID参数
|
||||
Long deptId = cmsDocService.getDeptIdByZoneId(request.getZoneId());
|
||||
|
||||
// 使用新的带评分的查询方法
|
||||
List<CmsDocWithScore> docs = cmsDocMapper.globalSearchWithScore(
|
||||
request.getKeyword(),
|
||||
deptId,
|
||||
(request.getPageNum() - 1) * request.getPageSize(),
|
||||
request.getPageSize()
|
||||
);
|
||||
|
||||
for (CmsDocWithScore doc : docs) {
|
||||
DocSearchResult result = new DocSearchResult();
|
||||
result.setId(doc.getId());
|
||||
result.setTitle(highlightKeyword(doc.getName(), request.getKeyword()));
|
||||
result.setContent(highlightKeyword(doc.getSummary(), request.getKeyword()));
|
||||
result.setDeptId(doc.getDeptId());
|
||||
result.setCreateTime(doc.getCreateTime());
|
||||
|
||||
// 使用数据库返回的实际搜索评分
|
||||
Double score = doc.getSearchScore();
|
||||
if (score == null || score == 0.0) {
|
||||
// 对于 LIKE 匹配(无全文评分),赋予最小评分
|
||||
score = 0.1;
|
||||
}
|
||||
result.setScore(score);
|
||||
|
||||
JSONObject extendData = new JSONObject();
|
||||
extendData.put("visits", doc.getVisits());
|
||||
extendData.put("publishTime", doc.getPublishTime());
|
||||
result.setExtendData(extendData);
|
||||
results.add(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 记录错误但继续处理其他类型
|
||||
System.err.println("搜索CMS文章失败: " + e.getMessage());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建缓存键
|
||||
*/
|
||||
private String buildCacheKey(DocSearchRequest request) {
|
||||
Long deptId = cmsDocService.getDeptIdByZoneId(request.getZoneId());
|
||||
StringBuilder key = new StringBuilder(request.getKeyword());
|
||||
key.append(":").append(String.join(",", "Doc"));
|
||||
if (deptId != null) {
|
||||
key.append(":dept=").append(deptId);
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建空响应
|
||||
*/
|
||||
private DocSearchResponse buildEmptyResponse(DocSearchRequest request) {
|
||||
DocSearchResponse response = new DocSearchResponse();
|
||||
response.setTotal(0L);
|
||||
response.setResults(new ArrayList<>());
|
||||
response.setTypeCounts(new HashMap<>());
|
||||
response.setKeyword(request.getKeyword());
|
||||
response.setPageNum(request.getPageNum());
|
||||
response.setPageSize(request.getPageSize());
|
||||
response.setSearchTime(0L);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文本中的关键词用 <em> 标签包裹(不区分大小写)
|
||||
*/
|
||||
private String highlightKeyword(String text, String keyword) {
|
||||
if (StringUtils.isEmpty(text) || StringUtils.isEmpty(keyword)) {
|
||||
return text;
|
||||
}
|
||||
return text.replaceAll("(?i)(" + Pattern.quote(keyword) + ")", "<em>$1</em>");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.microservices.cms.service.impl;
|
||||
package com.microservices.cms.common.service.impl;
|
||||
|
||||
import com.microservices.cms.common.service.ISysUserService;
|
||||
import com.microservices.common.core.constant.SecurityConstants;
|
||||
|
|
|
|||
|
|
@ -25,24 +25,4 @@ public class CmsConstants {
|
|||
* 是
|
||||
*/
|
||||
public final static String TRUE = "1";
|
||||
|
||||
/**
|
||||
* 专区积分异步队列 Redis Key(与 Zone 模块保持一致)
|
||||
*/
|
||||
public final static String ZONE_POINTS_ASYNC_QUEUE_KEY = "zone:points:async:queue";
|
||||
|
||||
/**
|
||||
* 发布文章积分类型
|
||||
*/
|
||||
public final static String PUBLISH_DOC = "publishDoc";
|
||||
|
||||
/**
|
||||
* 浏览文章积分类型
|
||||
*/
|
||||
public final static String VISITS_DOC = "visitsDoc";
|
||||
|
||||
/**
|
||||
* 精选文章积分类型
|
||||
*/
|
||||
public final static String FEATURED_DOC = "featuredDoc";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,6 @@ import java.util.Map;
|
|||
|
||||
public class CmsGitLinkRequestUrl extends GitLinkRequestUrl {
|
||||
|
||||
public static GitLinkRequestUrl ADD_USER_TO_ORGANIZATION_TEAM(String orgIdentifier, Long teamId) {
|
||||
return getAdminGitLinkRequestUrl(String.format("/api/organizations/%s/teams/%d/team_users.json", orgIdentifier, teamId));
|
||||
}
|
||||
|
||||
public static String TEAMS_BY_ORGANIZATION_URL(Long orgId) {
|
||||
return String.format("/api/organizations/%s/teams.json", orgId);
|
||||
}
|
||||
|
||||
public static GitLinkRequestUrl DELETE_USER_FROM_ORGANIZATION_TEAM(String orgIdentifier, Long teamId, String username) {
|
||||
return getAdminGitLinkRequestUrl(String.format("/api/organizations/%s/teams/%d/team_users/%s.json", orgIdentifier, teamId, username));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建项目
|
||||
*/
|
||||
|
|
@ -78,7 +66,7 @@ public class CmsGitLinkRequestUrl extends GitLinkRequestUrl {
|
|||
|
||||
public static GitLinkRequestUrl DELETE_BRANCH(CmsProject cmsProject, String branchName) {
|
||||
return getGitLinkRequestUrl(
|
||||
String.format("/api/v1/%s/%s/branches/delete.json?branch_name=%s", cmsProject.getUsername(), cmsProject.getIdentifier(), branchName)
|
||||
String.format("/api/v1/%s/%s/branches/%s.json", cmsProject.getUsername(), cmsProject.getIdentifier(), branchName)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -88,12 +76,6 @@ public class CmsGitLinkRequestUrl extends GitLinkRequestUrl {
|
|||
);
|
||||
}
|
||||
|
||||
public static GitLinkRequestUrl REOPEN_PULL_REQUEST(CmsProject cmsProject, String giteaPrNumber) {
|
||||
return getGitLinkRequestUrl(
|
||||
String.format("/api/v1/%s/%s/pulls/%s/reopen", cmsProject.getUsername(), cmsProject.getIdentifier(), giteaPrNumber)
|
||||
);
|
||||
}
|
||||
|
||||
public static GitLinkRequestUrl GET_PULL_REQUEST_DETAILS(CmsProject cmsProject, String giteaPrNumber) {
|
||||
return getGitLinkRequestUrl(
|
||||
String.format("/api/%s/%s/pulls/%s.json", cmsProject.getUsername(), cmsProject.getIdentifier(), giteaPrNumber)
|
||||
|
|
@ -119,7 +101,7 @@ public class CmsGitLinkRequestUrl extends GitLinkRequestUrl {
|
|||
}
|
||||
|
||||
public static GitLinkRequestUrl ADD_USER_FROM_PROJECT(CmsProject cmsProject) {
|
||||
return getAdminGitLinkRequestUrl(
|
||||
return getGitLinkRequestUrl(
|
||||
String.format("/api/%s/%s/collaborators.json", cmsProject.getUsername(), cmsProject.getIdentifier())
|
||||
);
|
||||
}
|
||||
|
|
@ -166,19 +148,19 @@ public class CmsGitLinkRequestUrl extends GitLinkRequestUrl {
|
|||
);
|
||||
}
|
||||
|
||||
public static GitLinkRequestUrl CREATE_PROTECTED_BRANCHES(String username, String identifier, Map<String, String> params, List<String> pushWhitelistUsernames) throws URISyntaxException {
|
||||
public static GitLinkRequestUrl CREATE_PROTECTED_BRANCHES(String username, String identifier, Map<String,String> params, List<String> pushWhitelistUsernames) throws URISyntaxException {
|
||||
String path = buildUri(String.format("/api/%s/%s/protected_branches.json", username, identifier), params);
|
||||
path = concatenateParametersAfterUrl(path, "push_whitelist_usernames[]", pushWhitelistUsernames);
|
||||
return getGitLinkRequestUrl(path);
|
||||
}
|
||||
|
||||
public static GitLinkRequestUrl UPDATE_PROTECTED_BRANCHES(String username, String identifier, Map<String, String> params, List<String> pushWhitelistUsernames) throws URISyntaxException {
|
||||
public static GitLinkRequestUrl UPDATE_PROTECTED_BRANCHES(String username, String identifier, Map<String,String> params, List<String> pushWhitelistUsernames) throws URISyntaxException {
|
||||
String path = buildUri(String.format("/api/%s/%s/protected_branches/master.json", username, identifier), params);
|
||||
path = concatenateParametersAfterUrl(path, "push_whitelist_usernames[]", pushWhitelistUsernames);
|
||||
return getGitLinkRequestUrl(path);
|
||||
}
|
||||
|
||||
public static GitLinkRequestUrl DELETE_PROTECTED_BRANCHES(String username, String identifier, Map<String, String> params, List<String> pushWhitelistUsernames) throws URISyntaxException {
|
||||
public static GitLinkRequestUrl DELETE_PROTECTED_BRANCHES(String username, String identifier, Map<String,String> params, List<String> pushWhitelistUsernames) throws URISyntaxException {
|
||||
String path = buildUri(String.format("/api/%s/%s/protected_branches/master.json", username, identifier), params);
|
||||
path = concatenateParametersAfterUrl(path, "push_whitelist_usernames[]", pushWhitelistUsernames);
|
||||
return getGitLinkRequestUrl(path);
|
||||
|
|
@ -215,12 +197,4 @@ public class CmsGitLinkRequestUrl extends GitLinkRequestUrl {
|
|||
public static String ZONE_DOC_URL(String gitlinkUrl, String zoneKey, Long docId) {
|
||||
return EscapeUtil.removeExtraSlashOfUrl(String.format("%s/zone/%s/newdetail/%d", gitlinkUrl, zoneKey, docId));
|
||||
}
|
||||
|
||||
public static GitLinkRequestUrl GET_PROJECT_DETAIL(String username, String identifier) {
|
||||
return getAdminGitLinkRequestUrl(String.format("/api/%s/%s/detail.json", username, identifier));
|
||||
}
|
||||
|
||||
public static GitLinkRequestUrl BATCH_COMMIT(String username, String identifier) {
|
||||
return getAdminGitLinkRequestUrl(String.format("/api/v1/%s/%s/contents/batch.json", username, identifier));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9116
|
||||
port: 8080
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
<result property="auditTmpBranchName" column="audit_tmp_branch_name"/>
|
||||
<result property="auditPrNumber" column="audit_pr_number"/>
|
||||
<result property="keywords" column="keywords"/>
|
||||
<result property="remark" column="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectCmsDocVo">
|
||||
|
|
@ -72,8 +71,7 @@
|
|||
audit_type,
|
||||
audit_tmp_branch_name,
|
||||
keywords,
|
||||
audit_pr_number,
|
||||
remark
|
||||
audit_pr_number
|
||||
from cms_doc
|
||||
</sql>
|
||||
|
||||
|
|
@ -105,103 +103,10 @@
|
|||
cd.is_homepage,
|
||||
cd.editor_type,
|
||||
cd.keywords,
|
||||
cd.is_dir,
|
||||
cd.audit_status,
|
||||
cd.audit_type,
|
||||
cd.audit_tmp_branch_name,
|
||||
cd.audit_pr_number,
|
||||
cd.remark
|
||||
cd.is_dir
|
||||
from cms_doc cd
|
||||
</sql>
|
||||
|
||||
<sql id="selectCmsDocWithScoreVo">
|
||||
select cd.id,
|
||||
cd.create_by,
|
||||
cd.create_time,
|
||||
cd.update_by,
|
||||
cd.update_time,
|
||||
cd.name,
|
||||
cd.file_name,
|
||||
cd.file_path,
|
||||
cd.file_sha,
|
||||
cd.file_size,
|
||||
cd.file_url,
|
||||
cd.html_url,
|
||||
cd.visits,
|
||||
cd.sort,
|
||||
cd.publish_time,
|
||||
cd.publish_user,
|
||||
cd.publish_user_image,
|
||||
cd.publish_user_url,
|
||||
cd.publish_user_nickname,
|
||||
cd.summary,
|
||||
cd.head_img,
|
||||
cd.dir_name,
|
||||
cd.dept_id,
|
||||
cd.issue_id,
|
||||
cd.is_homepage,
|
||||
cd.editor_type,
|
||||
cd.keywords,
|
||||
cd.is_dir,
|
||||
cd.audit_status,
|
||||
cd.audit_type,
|
||||
cd.audit_tmp_branch_name,
|
||||
cd.audit_pr_number,
|
||||
-- 计算全文搜索相关度评分
|
||||
MATCH(cd.name, cd.summary) AGAINST(#{keyword} IN NATURAL LANGUAGE MODE) AS search_score,
|
||||
cd.remark
|
||||
from cms_doc cd
|
||||
</sql>
|
||||
|
||||
<sql id="selectCmsDocAliasSetDefaultHeadImgVo">
|
||||
select cd.id,
|
||||
cd.create_by,
|
||||
cd.create_time,
|
||||
cd.update_by,
|
||||
cd.update_time,
|
||||
cd.name,
|
||||
cd.file_name,
|
||||
cd.file_path,
|
||||
cd.file_sha,
|
||||
cd.file_size,
|
||||
cd.file_url,
|
||||
cd.html_url,
|
||||
cd.visits,
|
||||
cd.sort,
|
||||
cd.publish_time,
|
||||
cd.publish_user,
|
||||
cd.publish_user_image,
|
||||
cd.publish_user_url,
|
||||
cd.publish_user_nickname,
|
||||
cd.summary,
|
||||
-- 处理文章和栏目头图为NULL或空字符串的情况
|
||||
CASE
|
||||
-- 文章头图不为空(非NULL且非空字符串)
|
||||
WHEN cd.head_img IS NOT NULL AND TRIM(cd.head_img) != '' THEN cd.head_img
|
||||
-- 栏目存在且头图不为空
|
||||
WHEN dir.head_img IS NOT NULL AND TRIM(dir.head_img) != '' THEN dir.head_img
|
||||
END AS head_img,
|
||||
cd.dir_name,
|
||||
cd.dept_id,
|
||||
cd.issue_id,
|
||||
cd.is_homepage,
|
||||
cd.editor_type,
|
||||
cd.keywords,
|
||||
cd.is_dir,
|
||||
cd.audit_status,
|
||||
cd.audit_type,
|
||||
cd.audit_tmp_branch_name,
|
||||
cd.audit_pr_number,
|
||||
cd.remark
|
||||
from cms_doc cd
|
||||
left join cms_doc dir on cd.dir_name = dir.name and cd.dept_id = dir.dept_id and dir.is_dir=1
|
||||
</sql>
|
||||
|
||||
<select id="selectCmsDocAndDirListByDept" resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocVo"/>
|
||||
where dept_id=#{deptId}
|
||||
</select>
|
||||
|
||||
<select id="selectCmsDocList" parameterType="com.microservices.cms.doc.domain.CmsDocSearchVo"
|
||||
resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocVo"/>
|
||||
|
|
@ -217,20 +122,10 @@
|
|||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectCmsDocByIds" resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocVo"/>
|
||||
where id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
and audit_status = '1'
|
||||
</select>
|
||||
|
||||
<select id="selectCmsDocByNameAndDeptId" resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocVo"/>
|
||||
<where>
|
||||
and name = #{name}
|
||||
and audit_status != 0
|
||||
and dept_id = #{deptId}
|
||||
<choose>
|
||||
<when test="dirName != null">
|
||||
|
|
@ -242,10 +137,6 @@
|
|||
</choose>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectCmsDocByNameAndDeptIdIgnoreDirName" resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocVo"/>
|
||||
where name = #{name} and dept_id = #{deptId} and is_dir = 0
|
||||
</select>
|
||||
<select id="selectCmsDocDirByNameAndDeptId" resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocVo"/>
|
||||
where name = #{name} and dept_id = #{deptId} and is_dir = 1
|
||||
|
|
@ -259,13 +150,13 @@
|
|||
where file_path = #{filePath} and dept_id = #{deptId} and is_dir = 0
|
||||
</select>
|
||||
<select id="selectHotCmsDocList" parameterType="com.microservices.cms.doc.domain.CmsDoc" resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocAliasSetDefaultHeadImgVo"/>
|
||||
<include refid="selectListWhereAlias"/>
|
||||
<include refid="selectCmsDocVo"/>
|
||||
<include refid="selectListWhere"/>
|
||||
ORDER BY
|
||||
cd.visits DESC,
|
||||
cd.sort DESC,
|
||||
cd.update_time DESC,
|
||||
cd.create_time DESC
|
||||
visits DESC,
|
||||
sort DESC,
|
||||
update_time DESC,
|
||||
create_time DESC
|
||||
|
||||
</select>
|
||||
<select id="selectCmsDocCount" resultType="java.lang.Integer">
|
||||
|
|
@ -286,24 +177,6 @@
|
|||
<if test="auditStatus != null and auditStatus != '-1' ">and audit_status = #{auditStatus}</if>
|
||||
<if test="auditStatus == null ">and audit_status = '1'</if>
|
||||
<if test="createBy != null and createBy != '' ">and create_by = #{createBy}</if>
|
||||
<if test="excludeId != null ">and id != #{excludeId}</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<sql id="selectListWhereAlias">
|
||||
<where>
|
||||
<if test="name != null and name != ''">and cd.name like concat('%', #{name}, '%')</if>
|
||||
<if test="keywords != null and keywords != ''">and cd.keywords like concat('%', #{keywords}, '%')</if>
|
||||
<if test="fileName != null and fileName != ''">and cd.file_name like concat('%', #{fileName}, '%')</if>
|
||||
<if test="filePath != null and filePath != ''">and cd.file_path = #{filePath}</if>
|
||||
<if test="publishTime != null ">and cd.publish_time = #{publishTime}</if>
|
||||
<if test="isDir != null ">and cd.is_dir = #{isDir}</if>
|
||||
<if test="dirName != null ">and cd.dir_name = #{dirName}</if>
|
||||
<if test="deptId != null ">and cd.dept_id = #{deptId}</if>
|
||||
<if test="isHomepage != null ">and cd.is_homepage = #{isHomepage}</if>
|
||||
<if test="auditStatus != null and auditStatus != '-1' ">and cd.audit_status = #{auditStatus}</if>
|
||||
<if test="auditStatus == null ">and cd.audit_status = '1'</if>
|
||||
<if test="createBy != null and createBy != '' ">and cd.create_by = #{createBy}</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
|
|
@ -410,15 +283,6 @@
|
|||
from cms_doc
|
||||
where dept_id = #{deptId};
|
||||
</select>
|
||||
<select id="selectCmsDocListSetDefaultHeadImg" parameterType="com.microservices.cms.doc.domain.CmsDocSearchVo"
|
||||
resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocAliasSetDefaultHeadImgVo"/>
|
||||
<include refid="selectListWhereAlias"/>
|
||||
ORDER BY
|
||||
cd.sort DESC,
|
||||
cd.update_time DESC,
|
||||
cd.create_time DESC
|
||||
</select>
|
||||
|
||||
<insert id="insertCmsDoc" parameterType="com.microservices.cms.doc.domain.CmsDoc" useGeneratedKeys="true"
|
||||
keyProperty="id">
|
||||
|
|
@ -524,7 +388,6 @@
|
|||
<if test="auditTmpBranchName != null">audit_tmp_branch_name = #{auditTmpBranchName},</if>
|
||||
<if test="auditPrNumber != null">audit_pr_number = #{auditPrNumber},</if>
|
||||
<if test="keywords != null">keywords = #{keywords},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
|
@ -542,12 +405,6 @@
|
|||
and dept_id = #{deptId}
|
||||
and is_dir = #{isDir};
|
||||
</update>
|
||||
<update id="updateCmsDocShaByPathAndDeptId">
|
||||
update cms_doc
|
||||
set file_sha=#{sha}
|
||||
where file_path=#{filePath}
|
||||
and dept_id=#{deptId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteCmsDocById" parameterType="Long">
|
||||
delete
|
||||
|
|
@ -561,70 +418,4 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 全局搜索 - 全文索引查询(含 LIKE 后备搜索) -->
|
||||
<select id="globalSearch" resultMap="CmsDocResult">
|
||||
<include refid="selectCmsDocAliasVo"/>
|
||||
WHERE
|
||||
cd.is_dir = 0
|
||||
AND cd.audit_status = '1'
|
||||
AND (
|
||||
MATCH(cd.name, cd.summary) AGAINST(#{keyword} IN BOOLEAN MODE)
|
||||
OR cd.name LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR cd.summary LIKE CONCAT('%', #{keyword}, '%')
|
||||
)
|
||||
<if test="deptId != null">
|
||||
AND cd.dept_id = #{deptId}
|
||||
</if>
|
||||
ORDER BY
|
||||
CASE
|
||||
WHEN MATCH(cd.name, cd.summary) AGAINST(#{keyword} IN BOOLEAN MODE) > 0 THEN 1
|
||||
ELSE 2
|
||||
END,
|
||||
cd.update_time DESC
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</select>
|
||||
|
||||
<select id="globalSearchCount" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM cms_doc cd
|
||||
WHERE
|
||||
cd.is_dir = 0
|
||||
AND cd.audit_status = '1'
|
||||
AND (
|
||||
MATCH(cd.name, cd.summary) AGAINST(#{keyword} IN BOOLEAN MODE)
|
||||
OR cd.name LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR cd.summary LIKE CONCAT('%', #{keyword}, '%')
|
||||
)
|
||||
<if test="deptId != null">
|
||||
AND cd.dept_id = #{deptId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- ResultMap for CmsDocWithScore -->
|
||||
<resultMap type="com.microservices.cms.doc.domain.CmsDocWithScore" id="CmsDocWithScoreResult" extends="CmsDocResult">
|
||||
<result property="searchScore" column="search_score"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 全局搜索 - 带评分的全文索引查询 -->
|
||||
<select id="globalSearchWithScore" resultMap="CmsDocWithScoreResult">
|
||||
<include refid="selectCmsDocWithScoreVo"/>
|
||||
WHERE
|
||||
cd.is_dir = 0
|
||||
AND cd.audit_status = '1'
|
||||
AND (
|
||||
MATCH(cd.name, cd.summary) AGAINST(#{keyword} IN BOOLEAN MODE)
|
||||
OR cd.name LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR cd.summary LIKE CONCAT('%', #{keyword}, '%')
|
||||
)
|
||||
<if test="deptId != null">
|
||||
AND cd.dept_id = #{deptId}
|
||||
</if>
|
||||
ORDER BY
|
||||
-- 主要排序:按相关度评分降序
|
||||
search_score DESC,
|
||||
-- 次要排序:更新时间降序
|
||||
cd.update_time DESC
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -159,38 +159,4 @@
|
|||
item="id" collection="array" open="(" separator="," close=")">#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 全局搜索 - 全文索引查询 -->
|
||||
<select id="globalSearch" resultMap="CmsProjectResult">
|
||||
SELECT id,
|
||||
name,
|
||||
description,
|
||||
user_id,
|
||||
dept_id,
|
||||
identifier,
|
||||
username,
|
||||
create_by,
|
||||
create_time,
|
||||
update_time
|
||||
FROM cms_project cp
|
||||
WHERE
|
||||
MATCH(cp.name) AGAINST(#{keyword} IN NATURAL LANGUAGE MODE)
|
||||
<if test="deptId != null">
|
||||
AND cp.dept_id = #{deptId}
|
||||
</if>
|
||||
ORDER BY
|
||||
MATCH(cp.name) AGAINST(#{keyword} IN NATURAL LANGUAGE MODE) DESC,
|
||||
cp.update_time DESC
|
||||
LIMIT #{offset}, #{pageSize}
|
||||
</select>
|
||||
|
||||
<select id="globalSearchCount" resultType="java.lang.Long">
|
||||
SELECT COUNT(*)
|
||||
FROM cms_project cp
|
||||
WHERE
|
||||
MATCH(cp.name) AGAINST(#{keyword} IN NATURAL LANGUAGE MODE)
|
||||
<if test="deptId != null">
|
||||
AND cp.dept_id = #{deptId}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -87,10 +87,18 @@
|
|||
<groupId>com.microservices</groupId>
|
||||
<artifactId>microservices-common-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microservices</groupId>
|
||||
<artifactId>microservices-common-swagger</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microservices</groupId>
|
||||
<artifactId>microservices-common-log</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microservices</groupId>
|
||||
<artifactId>microservices-common-core</artifactId>
|
||||
|
|
@ -125,7 +133,7 @@
|
|||
<dependency>
|
||||
<groupId>com.hankcs</groupId>
|
||||
<artifactId>hanlp</artifactId>
|
||||
<version>portable-1.8.4</version>
|
||||
<version>portable-1.3.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -59,8 +59,8 @@ public class AchievementsServiceImpl implements IAchievementsService {
|
|||
@Autowired
|
||||
private IBehaviorImageService behaviorImageService;
|
||||
|
||||
@Value("${makerSpaceUrl}")
|
||||
public String makerSpaceUrl;
|
||||
@Value("${markerSpaceUrl}")
|
||||
public String markerSpaceUrl;
|
||||
|
||||
@Value("${http.gitLinkUrl}")
|
||||
public String gitLinkUrl;
|
||||
|
|
@ -217,7 +217,7 @@ public class AchievementsServiceImpl implements IAchievementsService {
|
|||
}
|
||||
|
||||
if (Objects.equals(source, "2")) {
|
||||
concatUrl(list, makerSpaceUrl);
|
||||
concatUrl(list, markerSpaceUrl);
|
||||
}
|
||||
|
||||
if (Objects.equals(source, "4")) {
|
||||
|
|
|
|||
|
|
@ -377,9 +377,6 @@ public class TalentReferralService {
|
|||
*/
|
||||
public Object competitionExpertTalentReferral(Long competitionId) {
|
||||
TaskVo task = talentReferralMapper.selectCompetitionById(competitionId);
|
||||
if (task == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<KeyValueVo> categories = new ArrayList<>();
|
||||
List<TaskVo> completedTasks = talentReferralMapper.selectCompetitionIdByStatus();
|
||||
List<ExpertVo> allExperts = talentReferralMapper.selectExpertsBy(new ExpertVo());
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ import static com.microservices.dms.constant.TaskConstant.MARKER_SPACE_DOWNLOAD_
|
|||
public class TaskResourceLibraryService {
|
||||
private final TaskResourceLibraryMapper taskResourceLibraryMapper;
|
||||
|
||||
@Value("${makerSpaceUrl}")
|
||||
public String makerSpaceUrl;
|
||||
@Value("${markerSpaceUrl}")
|
||||
public String markerSpaceUrl;
|
||||
|
||||
public int addClick(Clicker click) {
|
||||
click.setCreatedAt(DateUtils.getNowDate());
|
||||
|
|
@ -104,7 +104,7 @@ public class TaskResourceLibraryService {
|
|||
List<KeyValVo<String, String>> attachments = taskResourceLibraryMapper.getAttachments(l.getPaperId());
|
||||
for (KeyValVo<String, String> a : attachments) {
|
||||
Object v = a.getV();
|
||||
a.setV(String.format(MARKER_SPACE_DOWNLOAD_API_BY_ID, makerSpaceUrl, v));
|
||||
a.setV(String.format(MARKER_SPACE_DOWNLOAD_API_BY_ID, markerSpaceUrl, v));
|
||||
}
|
||||
l.setAttachmentList(attachments);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ public class ExpertResourceLibraryServiceImpl implements IExpertResourceLibraryS
|
|||
@Autowired
|
||||
private ExpertResourceLibraryMapper expertResourceLibraryMapper;
|
||||
|
||||
@Value("${makerSpaceUrl}")
|
||||
public String makerSpaceUrl;
|
||||
@Value("${markerSpaceUrl}")
|
||||
public String markerSpaceUrl;
|
||||
/**
|
||||
* 查询专家资源库
|
||||
*
|
||||
|
|
@ -77,7 +77,7 @@ public class ExpertResourceLibraryServiceImpl implements IExpertResourceLibraryS
|
|||
private void buildFullUrl(Map<String, Object> map) {
|
||||
if (map != null && map.containsKey("id") && map.get("id") != null) {
|
||||
String id = map.get("id").toString();
|
||||
map.put("url", String.format(MARKER_SPACE_DOWNLOAD_API_BY_ID, makerSpaceUrl, id));
|
||||
map.put("url", String.format(MARKER_SPACE_DOWNLOAD_API_BY_ID, markerSpaceUrl, id));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9119
|
||||
port: 8080
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
|||
|
|
@ -140,55 +140,24 @@
|
|||
</select>
|
||||
|
||||
<select id="selectActivityUserLibraryListAll" resultType="com.microservices.dms.behaviorImage.domain.ActivityUserLibrary" parameterType="com.microservices.dms.behaviorImage.domain.ActivityUserLibrary">
|
||||
SELECT
|
||||
u.id AS userId,
|
||||
u.login AS loginName,
|
||||
u.nickname AS userName,
|
||||
u.is_expert AS isExpert,
|
||||
u.authentication AS isAuth,
|
||||
IFNULL(t.relatedTask, 0) AS relatedTask,
|
||||
IFNULL(c.relatedCompetition, 0) AS relatedCompetition,
|
||||
IFNULL(p1.p1,0) + IFNULL(p2.p2,0) + IFNULL(p3.p3,0) AS relatedProject
|
||||
FROM users u
|
||||
LEFT JOIN (
|
||||
SELECT user_id, COUNT(*) AS relatedTask
|
||||
FROM tasks
|
||||
WHERE is_delete = '0' AND status BETWEEN 3 AND 8
|
||||
GROUP BY user_id
|
||||
) t ON u.id = t.user_id
|
||||
LEFT JOIN (
|
||||
SELECT cu.user_id, COUNT(*) AS relatedCompetition
|
||||
FROM competition_users cu
|
||||
INNER JOIN competition_infos ci ON ci.id = cu.competition_info_id
|
||||
GROUP BY cu.user_id
|
||||
) c ON u.id = c.user_id
|
||||
LEFT JOIN (
|
||||
SELECT user_id, COUNT(*) AS p1
|
||||
FROM projects
|
||||
GROUP BY user_id
|
||||
) p1 ON u.id = p1.user_id
|
||||
LEFT JOIN (
|
||||
SELECT m.user_id, COUNT(*) AS p2
|
||||
FROM members m
|
||||
INNER JOIN projects p ON m.project_id = p.id AND p.user_id != m.user_id
|
||||
GROUP BY m.user_id
|
||||
) p2 ON u.id = p2.user_id
|
||||
LEFT JOIN (
|
||||
SELECT tu.user_id, COUNT(DISTINCT tp.project_id) AS p3
|
||||
FROM team_users tu
|
||||
INNER JOIN teams tm ON tu.team_id = tm.id
|
||||
INNER JOIN team_projects tp ON tm.id = tp.team_id
|
||||
INNER JOIN projects p ON tp.project_id = p.id
|
||||
GROUP BY tu.user_id
|
||||
) p3 ON u.id = p3.user_id
|
||||
WHERE (
|
||||
IFNULL(c.relatedCompetition, 0) > 0
|
||||
OR IFNULL(t.relatedTask, 0) > 0
|
||||
OR (IFNULL(p1.p1,0) + IFNULL(p2.p2,0) + IFNULL(p3.p3,0)) > 0
|
||||
)
|
||||
<if test="userName != null and userName != ''">
|
||||
AND u.nickname like concat('%', #{userName}, '%')
|
||||
</if>
|
||||
select res.userId,res.loginName,res.userName,res.isExpert,res.isAuth,res.relatedCompetition,res.relatedTask,res.p1+res.p2+res.p3 as "relatedProject" from (
|
||||
select u.id as "userId",u.login as "loginName",u.nickname as "userName",u.is_expert as "isExpert",u.authentication as "isAuth",
|
||||
(select count(1) as "value" from tasks where is_delete='0' and status between 3 and 8 and user_id =u.id) as "relatedTask",
|
||||
(select count(1) from competition_infos ci inner join competition_users cu on ci.id = cu.competition_info_id where cu.user_id =u.id) as "relatedCompetition",
|
||||
(SELECT count(1) as "pCount" FROM `projects` WHERE id != 0 AND user_id =u.id) as p1,
|
||||
( SELECT count(1) as "pCount"
|
||||
FROM `projects`
|
||||
INNER JOIN `members` ON `members`.`project_id` = `projects`.`id`
|
||||
WHERE `projects`.`id` != 0 AND `projects`.`user_id` !=u.id AND `members`.`user_id` =u.id) as p2,
|
||||
(SELECT count(1) as "pCount"
|
||||
FROM `projects`
|
||||
INNER JOIN `team_projects` ON `team_projects`.`project_id` = `projects`.`id`
|
||||
INNER JOIN `teams` ON `teams`.`id` = `team_projects`.`team_id`
|
||||
INNER JOIN `team_users` ON `team_users`.`team_id` = `teams`.`id`
|
||||
WHERE `projects`.`id` != 0 AND `team_users`.`user_id` =u.id) as p3
|
||||
from users u) res
|
||||
where (res.relatedCompetition >0 or res.relatedTask >0 or res.p1+res.p2+res.p3>0)
|
||||
<if test="userName != null and userName != ''"> and res.userName like concat('%', #{userName}, '%')</if>
|
||||
</select>
|
||||
|
||||
<select id="getrelatedProjectCount" resultType="long">
|
||||
|
|
@ -339,47 +308,23 @@
|
|||
</select>
|
||||
|
||||
<select id="getActivityStatistic" resultType="com.microservices.dms.behaviorImage.domain.ActivityUserTotal">
|
||||
SELECT
|
||||
COUNT(*) AS totalUser,
|
||||
SUM(u.is_expert) AS totalExpert,
|
||||
SUM(u.authentication + u.enterprise_certification) AS authTotal
|
||||
FROM users u
|
||||
LEFT JOIN (
|
||||
SELECT user_id, COUNT(*) AS relatedTask
|
||||
FROM tasks
|
||||
WHERE is_delete = '0' AND status BETWEEN 3 AND 8
|
||||
GROUP BY user_id
|
||||
) t ON u.id = t.user_id
|
||||
LEFT JOIN (
|
||||
SELECT cu.user_id, COUNT(*) AS relatedCompetition
|
||||
FROM competition_users cu
|
||||
INNER JOIN competition_infos ci ON ci.id = cu.competition_info_id
|
||||
GROUP BY cu.user_id
|
||||
) c ON u.id = c.user_id
|
||||
LEFT JOIN (
|
||||
SELECT user_id, COUNT(*) AS p1
|
||||
FROM projects
|
||||
GROUP BY user_id
|
||||
) p1 ON u.id = p1.user_id
|
||||
LEFT JOIN (
|
||||
SELECT m.user_id, COUNT(*) AS p2
|
||||
FROM members m
|
||||
INNER JOIN projects p ON m.project_id = p.id AND p.user_id != m.user_id
|
||||
GROUP BY m.user_id
|
||||
) p2 ON u.id = p2.user_id
|
||||
LEFT JOIN (
|
||||
SELECT tu.user_id, COUNT(DISTINCT tp.project_id) AS p3
|
||||
FROM team_users tu
|
||||
INNER JOIN teams tm ON tu.team_id = tm.id
|
||||
INNER JOIN team_projects tp ON tm.id = tp.team_id
|
||||
INNER JOIN projects p ON tp.project_id = p.id
|
||||
GROUP BY tu.user_id
|
||||
) p3 ON u.id = p3.user_id
|
||||
WHERE (
|
||||
IFNULL(c.relatedCompetition, 0) > 0
|
||||
OR IFNULL(t.relatedTask, 0) > 0
|
||||
OR (IFNULL(p1.p1, 0) + IFNULL(p2.p2, 0) + IFNULL(p3.p3, 0)) > 0
|
||||
)
|
||||
select count(1) as "totalUser",sum(r.isExpert) as "totalExpert",sum(r.enterprise_certification+r.authentication) as "authTotal" from (
|
||||
select res.userId,res.loginName,res.userName,res.isExpert,res.authentication,res.enterprise_certification,res.relatedCompetition,res.relatedTask,res.p1+res.p2+res.p3 as "relatedProject" from (
|
||||
select u.id as "userId",u.login as "loginName",u.nickname as "userName",u.is_expert as "isExpert",u.authentication,u.enterprise_certification,
|
||||
(select count(1) as "value" from tasks where is_delete='0' and status between 3 and 8 and user_id =u.id) as "relatedTask",
|
||||
(select count(1) from competition_infos ci inner join competition_users cu on ci.id = cu.competition_info_id where cu.user_id =u.id) as "relatedCompetition",
|
||||
(SELECT count(1) as "pCount" FROM `projects` WHERE id != 0 AND user_id =u.id) as p1,
|
||||
( SELECT count(1) as "pCount"
|
||||
FROM `projects` INNER JOIN `members` ON `members`.`project_id` = `projects`.`id`
|
||||
WHERE `projects`.`id` != 0 AND `projects`.`user_id` !=u.id AND `members`.`user_id` =u.id) as p2,
|
||||
(SELECT count(1) as "pCount"
|
||||
FROM `projects`
|
||||
INNER JOIN `team_projects` ON `team_projects`.`project_id` = `projects`.`id`
|
||||
INNER JOIN `teams` ON `teams`.`id` = `team_projects`.`team_id`
|
||||
INNER JOIN `team_users` ON `team_users`.`team_id` = `teams`.`id`
|
||||
WHERE `projects`.`id` != 0 AND `team_users`.`user_id` =u.id) as p3
|
||||
from users u) res
|
||||
where res.relatedCompetition >0 or res.relatedTask >0 or res.p1+res.p2+res.p3>0 )r
|
||||
</select>
|
||||
|
||||
<select id="getUserBehaviorSum" resultType="com.microservices.dms.behaviorImage.domain.UserTypeTotalVo">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9198
|
||||
port: 8080
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import com.microservices.common.security.annotation.EnableRyFeignClients;
|
|||
import com.microservices.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 文件服务
|
||||
|
|
@ -16,7 +15,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
@EnableCustomConfig
|
||||
@SpringBootApplication
|
||||
@EnableRyFeignClients
|
||||
@EnableScheduling
|
||||
public class MicroservicesFileApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MicroservicesFileApplication.class, args);
|
||||
|
|
|
|||
|
|
@ -1,176 +0,0 @@
|
|||
package com.microservices.file.controller;
|
||||
|
||||
import com.microservices.common.core.web.controller.BaseController;
|
||||
import com.microservices.common.core.web.domain.AjaxResult;
|
||||
import com.microservices.common.core.web.domain.GenericsAjaxResult;
|
||||
import com.microservices.file.domain.vo.CheckChunkVo;
|
||||
import com.microservices.file.domain.vo.CheckInstantUploadVo;
|
||||
import com.microservices.file.domain.vo.InitChunkedUploadVo;
|
||||
import com.microservices.file.domain.vo.UploadProgressVo;
|
||||
import com.microservices.file.domain.vo.input.CheckInstantUploadInputVo;
|
||||
import com.microservices.file.domain.vo.input.InitChunkedUploadInputVo;
|
||||
import com.microservices.file.domain.vo.response.*;
|
||||
import com.microservices.file.service.IChunkedUploadService;
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 分片上传控制器
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/chunked")
|
||||
@Api(tags = "分片上传接口")
|
||||
public class ChunkedUploadController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IChunkedUploadService chunkedUploadService;
|
||||
|
||||
/**
|
||||
* 初始化分片上传
|
||||
* <p>
|
||||
* 功能:
|
||||
* 1. 创建上传会话
|
||||
* 2. 根据文件大小判断哈希类型(FULL/SAMPLE)
|
||||
* 3. 返回采样点信息(SAMPLE类型)
|
||||
*
|
||||
* @param input 初始化上传请求参数
|
||||
* @return 初始化结果,包含 uploadId、totalChunks、chunkSize、hashType、sampleChunks
|
||||
*/
|
||||
@PostMapping("/init")
|
||||
@ApiOperation("初始化分片上传")
|
||||
public GenericsAjaxResult<InitChunkedUploadResponseVo> initChunkedUpload(@Validated @RequestBody InitChunkedUploadInputVo input) {
|
||||
InitChunkedUploadVo result = chunkedUploadService.initChunkedUpload(input);
|
||||
return genericsSuccess(InitChunkedUploadResponseVo.from(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查秒传(简化版)
|
||||
* <p>
|
||||
* 功能:
|
||||
* 1. 校验上传会话和时间窗口
|
||||
* 2. 查询是否存在相同的 file_hash 且状态为已完成
|
||||
* 3. 秒传成功:删除当前会话,返回已存在文件信息
|
||||
* 4. 不能秒传:返回继续上传
|
||||
*
|
||||
* @param input 检查秒传请求参数
|
||||
* @return 检查结果
|
||||
*/
|
||||
@PostMapping("/checkInstantUpload")
|
||||
@ApiOperation("检查秒传")
|
||||
public GenericsAjaxResult<CheckInstantUploadResponseVo> checkInstantUpload(@Validated @RequestBody CheckInstantUploadInputVo input) {
|
||||
CheckInstantUploadVo result = chunkedUploadService.checkInstantUpload(input.getUploadId(), input.getFileSignature());
|
||||
return genericsSuccess(CheckInstantUploadResponseVo.from(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查分片是否已上传(断点续传)
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param chunkNumber 分片序号
|
||||
* @return 分片检查结果
|
||||
*/
|
||||
@GetMapping("/check/{uploadId}/{chunkNumber}")
|
||||
@ApiOperation("检查分片是否已上传")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "uploadId", value = "上传ID", paramType = "path", dataType = "String", required = true),
|
||||
@ApiImplicitParam(name = "chunkNumber", value = "分片序号", paramType = "path", dataType = "Integer", required = true)
|
||||
})
|
||||
public GenericsAjaxResult<CheckChunkResponseVo> checkChunk(@PathVariable("uploadId") String uploadId, @PathVariable("chunkNumber") Integer chunkNumber) {
|
||||
CheckChunkVo result = chunkedUploadService.checkChunk(uploadId, chunkNumber);
|
||||
return genericsSuccess(CheckChunkResponseVo.from(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传分片
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param chunkNumber 分片序号
|
||||
* @param chunk 分片文件
|
||||
* @return 上传结果
|
||||
*/
|
||||
@PostMapping("/upload/{uploadId}/{chunkNumber}")
|
||||
@ApiOperation("上传分片")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "uploadId", value = "上传ID", paramType = "path", dataType = "String", required = true),
|
||||
@ApiImplicitParam(name = "chunkNumber", value = "分片序号", paramType = "path", dataType = "Integer", required = true),
|
||||
@ApiImplicitParam(name = "chunk", value = "分片文件", paramType = "form", dataType = "_file", required = true)
|
||||
})
|
||||
public GenericsAjaxResult<UploadChunkResponseVo> uploadChunk(
|
||||
@PathVariable("uploadId") String uploadId,
|
||||
@PathVariable("chunkNumber") Integer chunkNumber,
|
||||
@RequestPart("chunk") MultipartFile chunk) {
|
||||
chunkedUploadService.uploadChunk(uploadId, chunkNumber, chunk);
|
||||
return genericsSuccess(UploadChunkResponseVo.success(chunkNumber));
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并分片(异步)
|
||||
* <p>
|
||||
* 功能:
|
||||
* 1. 提交合并任务,立即返回
|
||||
* 2. 客户端通过轮询进度接口获取合并结果
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 合并任务提交结果
|
||||
*/
|
||||
@PostMapping("/merge/{uploadId}")
|
||||
@ApiOperation("合并分片")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "uploadId", value = "上传ID", paramType = "path", dataType = "String", required = true)
|
||||
})
|
||||
public GenericsAjaxResult<Map<String, String>> mergeChunks(@PathVariable("uploadId") String uploadId) {
|
||||
chunkedUploadService.mergeChunks(uploadId);
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("uploadId", uploadId);
|
||||
result.put("message", "合并任务已提交,请通过进度接口查询结果");
|
||||
return genericsSuccess(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消上传
|
||||
* <p>
|
||||
* 功能:
|
||||
* 1. 删除上传会话记录
|
||||
* 2. 清理已上传的分片文件
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 取消结果
|
||||
*/
|
||||
@DeleteMapping("/cancel/{uploadId}")
|
||||
@ApiOperation("取消上传")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "uploadId", value = "上传ID", paramType = "path", dataType = "String", required = true)
|
||||
})
|
||||
public GenericsAjaxResult<CancelUploadResponseVo> cancelUpload(@PathVariable("uploadId") String uploadId) {
|
||||
boolean result = chunkedUploadService.cancelUpload(uploadId);
|
||||
return genericsSuccess(result ? CancelUploadResponseVo.success() : CancelUploadResponseVo.failed("取消上传失败"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传进度
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 上传进度
|
||||
*/
|
||||
@GetMapping("/progress/{uploadId}")
|
||||
@ApiOperation("获取上传进度")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "uploadId", value = "上传ID", paramType = "path", dataType = "String", required = true)
|
||||
})
|
||||
public GenericsAjaxResult<UploadProgressResponseVo> getProgress(@PathVariable("uploadId") String uploadId) {
|
||||
UploadProgressVo progress = chunkedUploadService.getProgress(uploadId);
|
||||
return genericsSuccess(UploadProgressResponseVo.from(progress));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package com.microservices.file.controller;
|
||||
|
||||
import com.microservices.common.core.domain.R;
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.web.domain.AjaxResult;
|
||||
import com.microservices.file.service.ISysFileInfoService;
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
|
|
@ -121,20 +120,19 @@ public class OpenController {
|
|||
@ApiImplicitParam(name = "hierarchy", value = "层级结构(eg: pms项目管理中{enterpriseIdentifier}/products,{enterpriseIdentifier}/projects,{enterpriseIdentifier}/docs/{projectId})", paramType = "query", dataType = "String")
|
||||
})
|
||||
public AjaxResult uploadFile(@RequestPart("file") MultipartFile file, String type, String hierarchy) {
|
||||
throw new ServiceException("该接口已弃用!");
|
||||
// SysFileInfo sysFileInfo = sysFileInfoService.upload(file, type, hierarchy);
|
||||
// AjaxResult ajax = AjaxResult.success();
|
||||
// ajax.put("url", sysFileInfo.getDownloadUrl());
|
||||
// if (sysFileInfo.getFileIdentifier() != null) {
|
||||
// ajax.put("fileIdentifier", sysFileInfo.getFileIdentifier());
|
||||
// }
|
||||
// ajax.put("fileName", sysFileInfo.getFilePath());
|
||||
// if (sysFileInfo.getFileId() != null) {
|
||||
// ajax.put("fileId", sysFileInfo.getFileId());
|
||||
// }
|
||||
// ajax.put("fileOriginName", sysFileInfo.getFileOriginName());
|
||||
// ajax.put("fileSuffix", sysFileInfo.getFileSuffix());
|
||||
// ajax.put("fileSize", sysFileInfo.getFileSizeInfo());
|
||||
// return ajax;
|
||||
SysFileInfo sysFileInfo = sysFileInfoService.upload(file, type, hierarchy);
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("url", sysFileInfo.getDownloadUrl());
|
||||
if (sysFileInfo.getFileIdentifier() != null) {
|
||||
ajax.put("fileIdentifier", sysFileInfo.getFileIdentifier());
|
||||
}
|
||||
ajax.put("fileName", sysFileInfo.getFilePath());
|
||||
if (sysFileInfo.getFileId() != null) {
|
||||
ajax.put("fileId", sysFileInfo.getFileId());
|
||||
}
|
||||
ajax.put("fileOriginName", sysFileInfo.getFileOriginName());
|
||||
ajax.put("fileSuffix", sysFileInfo.getFileSuffix());
|
||||
ajax.put("fileSize", sysFileInfo.getFileSizeInfo());
|
||||
return ajax;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
package com.microservices.file.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.microservices.common.core.web.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 文件分片记录对象 sys_file_upload_chunk
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel("文件分片记录")
|
||||
public class FileUploadChunk extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 分片ID
|
||||
*/
|
||||
@ApiModelProperty(value = "分片ID")
|
||||
private Long chunkId;
|
||||
|
||||
/**
|
||||
* 上传ID
|
||||
*/
|
||||
@ApiModelProperty(value = "上传ID")
|
||||
private String uploadId;
|
||||
|
||||
/**
|
||||
* 分片序号(从0开始)
|
||||
*/
|
||||
@ApiModelProperty(value = "分片序号(从0开始)")
|
||||
private Integer chunkNumber;
|
||||
|
||||
/**
|
||||
* 分片大小(字节)
|
||||
*/
|
||||
@ApiModelProperty(value = "分片大小(字节)")
|
||||
private Long chunkSize;
|
||||
|
||||
/**
|
||||
* 分片文件存储路径
|
||||
*/
|
||||
@ApiModelProperty(value = "分片文件存储路径")
|
||||
private String chunkPath;
|
||||
|
||||
/**
|
||||
* 状态:PENDING-待上传,UPLOADED-已上传,MERGED-已合并
|
||||
*/
|
||||
@ApiModelProperty(value = "状态:PENDING-待上传,UPLOADED-已上传,MERGED-已合并")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 上传时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "上传时间")
|
||||
private Date uploadTime;
|
||||
|
||||
/**
|
||||
* 分片状态枚举
|
||||
*/
|
||||
public enum Status {
|
||||
PENDING("PENDING", "待上传"),
|
||||
UPLOADED("UPLOADED", "已上传"),
|
||||
MERGED("MERGED", "已合并");
|
||||
|
||||
private final String code;
|
||||
private final String desc;
|
||||
|
||||
Status(String code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
package com.microservices.file.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.microservices.common.core.web.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 文件分片上传会话对象 sys_file_upload_session
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel("文件分片上传会话")
|
||||
public class FileUploadSession extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 会话ID
|
||||
*/
|
||||
@ApiModelProperty(value = "会话ID")
|
||||
private Long sessionId;
|
||||
|
||||
/**
|
||||
* 上传ID(唯一标识)
|
||||
*/
|
||||
@ApiModelProperty(value = "上传ID(唯一标识)")
|
||||
private String uploadId;
|
||||
|
||||
/**
|
||||
* 文件ID(关联sys_file_info表)
|
||||
*/
|
||||
@ApiModelProperty(value = "文件ID(关联sys_file_info表)")
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
* 原始文件名
|
||||
*/
|
||||
@ApiModelProperty(value = "原始文件名")
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 文件总大小(字节)
|
||||
*/
|
||||
@ApiModelProperty(value = "文件总大小(字节)")
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
* 文件签名(用于秒传校验)
|
||||
* - FULL 类型:完整文件的 MD5 值
|
||||
* - SAMPLE 类型:采样点哈希值
|
||||
*/
|
||||
@ApiModelProperty(value = "文件签名(用于秒传校验,可能是完整MD5或采样点哈希)")
|
||||
private String fileSignature;
|
||||
|
||||
/**
|
||||
* 分片大小(字节)
|
||||
*/
|
||||
@ApiModelProperty(value = "分片大小(字节)")
|
||||
private Long chunkSize;
|
||||
|
||||
/**
|
||||
* 总分片数
|
||||
*/
|
||||
@ApiModelProperty(value = "总分片数")
|
||||
private Integer totalChunks;
|
||||
|
||||
/**
|
||||
* 已上传分片数
|
||||
*/
|
||||
@ApiModelProperty(value = "已上传分片数")
|
||||
private Integer uploadedChunks;
|
||||
|
||||
/**
|
||||
* 上传类型(cms/dms/resource/pms等)
|
||||
*/
|
||||
@ApiModelProperty(value = "上传类型(cms/dms/resource/pms等)")
|
||||
private String uploadType;
|
||||
|
||||
/**
|
||||
* 层级路径
|
||||
*/
|
||||
@ApiModelProperty(value = "层级路径")
|
||||
private String hierarchy;
|
||||
|
||||
/**
|
||||
* 状态:INIT-初始化,UPLOADING-上传中,MERGING-合并中,COMPLETED-已完成,FAILED-失败,MERGE_FAILED-合并失败
|
||||
*/
|
||||
@ApiModelProperty(value = "状态:INIT-初始化,UPLOADING-上传中,MERGING-合并中,COMPLETED-已完成,FAILED-失败,MERGE_FAILED-合并失败")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 临时文件存储路径
|
||||
*/
|
||||
@ApiModelProperty(value = "临时文件存储路径")
|
||||
private String tempFilePath;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
@ApiModelProperty(value = "错误信息")
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* 过期时间(24小时)
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "过期时间(24小时)")
|
||||
private Date expireTime;
|
||||
|
||||
/**
|
||||
* 哈希类型:FULL=完整文件MD5, SAMPLE=采样点哈希
|
||||
*/
|
||||
@ApiModelProperty(value = "哈希类型:FULL=完整文件MD5, SAMPLE=采样点哈希")
|
||||
private String hashType;
|
||||
|
||||
/**
|
||||
* 采样点分片序号列表(逗号分隔,仅SAMPLE类型)
|
||||
*/
|
||||
@ApiModelProperty(value = "采样点分片序号列表")
|
||||
private String sampleChunks;
|
||||
|
||||
/**
|
||||
* 上传状态枚举
|
||||
*/
|
||||
public enum Status {
|
||||
INIT("INIT", "初始化"),
|
||||
UPLOADING("UPLOADING", "上传中"),
|
||||
MERGING("MERGING", "合并中"),
|
||||
COMPLETED("COMPLETED", "已完成"),
|
||||
FAILED("FAILED", "失败"),
|
||||
MERGE_FAILED("MERGE_FAILED", "合并失败");
|
||||
|
||||
private final String code;
|
||||
private final String desc;
|
||||
|
||||
Status(String code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
package com.microservices.file.domain.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 分片检查返回VO
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("分片检查返回")
|
||||
public class CheckChunkVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 分片是否存在
|
||||
*/
|
||||
@ApiModelProperty(value = "分片是否存在")
|
||||
private Boolean exists;
|
||||
|
||||
/**
|
||||
* 分片序号
|
||||
*/
|
||||
@ApiModelProperty(value = "分片序号")
|
||||
private Integer chunkNumber;
|
||||
|
||||
/**
|
||||
* 分片大小(字节)
|
||||
*/
|
||||
@ApiModelProperty(value = "分片大小(字节)")
|
||||
private Long chunkSize;
|
||||
|
||||
public static CheckChunkVo exists(Integer chunkNumber, Long chunkSize) {
|
||||
CheckChunkVo vo = new CheckChunkVo();
|
||||
vo.setExists(true);
|
||||
vo.setChunkNumber(chunkNumber);
|
||||
vo.setChunkSize(chunkSize);
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static CheckChunkVo notExists(Integer chunkNumber) {
|
||||
CheckChunkVo vo = new CheckChunkVo();
|
||||
vo.setExists(false);
|
||||
vo.setChunkNumber(chunkNumber);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
package com.microservices.file.domain.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel("检查秒传返回")
|
||||
public class CheckInstantUploadVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("是否可以秒传")
|
||||
private Boolean canInstantUpload = false;
|
||||
|
||||
@ApiModelProperty("是否可以断点续传")
|
||||
private Boolean canResumingUpload = false;
|
||||
|
||||
@ApiModelProperty("已存在文件ID(秒传时)")
|
||||
private Long existingFileId;
|
||||
|
||||
@ApiModelProperty("已存在文件名(秒传时)")
|
||||
private String existingFileName;
|
||||
|
||||
@ApiModelProperty("已存在文件路径(秒传时)")
|
||||
private String existingFilePath;
|
||||
|
||||
@ApiModelProperty("已存在文件下载地址(秒传时)")
|
||||
private String existingFileUrl;
|
||||
|
||||
@ApiModelProperty("已存在文件大小(秒传时)")
|
||||
private String existingFileSize;
|
||||
|
||||
@ApiModelProperty("已存在未上传完成的上传Id(断点续传时)")
|
||||
private String resumingUploadId;
|
||||
|
||||
@ApiModelProperty("已上传的分片Id列表(断点续传时)-当状态为合并中时该值为null,请直接调用进度接口查看进度")
|
||||
private List<Integer> completedUploadChunkedNumberList;
|
||||
|
||||
@ApiModelProperty("已存在未上传完成的上传状态(断点续传时)")
|
||||
private String resumingUploadStatus;
|
||||
|
||||
@ApiModelProperty("消息")
|
||||
private String message;
|
||||
|
||||
public static CheckInstantUploadVo instantSuccess(Long fileId, String fileName, String filePath, String fileUrl, String fileSize) {
|
||||
CheckInstantUploadVo vo = new CheckInstantUploadVo();
|
||||
vo.setCanInstantUpload(true);
|
||||
vo.setExistingFileId(fileId);
|
||||
vo.setExistingFileName(fileName);
|
||||
vo.setExistingFilePath(filePath);
|
||||
vo.setExistingFileUrl(fileUrl);
|
||||
vo.setExistingFileSize(fileSize);
|
||||
vo.setMessage("秒传成功");
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static CheckInstantUploadVo resumingSuccess(String uploadId, List<Integer> completedUploadChunkedIdList,String resumingUploadStatus) {
|
||||
CheckInstantUploadVo vo = new CheckInstantUploadVo();
|
||||
vo.setCanResumingUpload(true);
|
||||
vo.setResumingUploadId(uploadId);
|
||||
vo.setCompletedUploadChunkedNumberList(completedUploadChunkedIdList);
|
||||
vo.setResumingUploadStatus(resumingUploadStatus);
|
||||
vo.setMessage("断点续传成功");
|
||||
return vo;
|
||||
}
|
||||
|
||||
public static CheckInstantUploadVo needUpload(String message) {
|
||||
CheckInstantUploadVo vo = new CheckInstantUploadVo();
|
||||
vo.setCanInstantUpload(false);
|
||||
vo.setMessage(message);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
package com.microservices.file.domain.vo;
|
||||
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分片上传初始化返回VO
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("分片上传初始化返回")
|
||||
public class InitChunkedUploadVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 上传ID
|
||||
*/
|
||||
@ApiModelProperty(value = "上传ID")
|
||||
private String uploadId;
|
||||
|
||||
/**
|
||||
* 总分片数
|
||||
*/
|
||||
@ApiModelProperty(value = "总分片数")
|
||||
private Integer totalChunks;
|
||||
|
||||
/**
|
||||
* 分片大小(字节)
|
||||
*/
|
||||
@ApiModelProperty(value = "分片大小(字节)")
|
||||
private Long chunkSize;
|
||||
|
||||
|
||||
/**
|
||||
* 上传分片的并发数
|
||||
*/
|
||||
@ApiModelProperty(value = "上传分片的并发数")
|
||||
private Integer concurrent;
|
||||
|
||||
/**
|
||||
* 哈希类型:FULL=完整文件MD5, SAMPLE=采样点哈希
|
||||
*/
|
||||
@ApiModelProperty(value = "哈希类型(FULL=完整文件MD5, SAMPLE=采样点哈希)")
|
||||
private String hashType;
|
||||
|
||||
/**
|
||||
* 采样点分片序号列表(仅SAMPLE类型有值)
|
||||
*/
|
||||
@ApiModelProperty(value = "采样点分片序号列表")
|
||||
private List<Integer> sampleChunks;
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package com.microservices.file.domain.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 上传进度返回VO
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("上传进度返回")
|
||||
public class UploadProgressVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 上传ID
|
||||
*/
|
||||
@ApiModelProperty(value = "上传ID")
|
||||
private String uploadId;
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
@ApiModelProperty(value = "文件名")
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 文件总大小(字节)
|
||||
*/
|
||||
@ApiModelProperty(value = "文件总大小(字节)")
|
||||
private Long fileSize;
|
||||
|
||||
/**
|
||||
* 总分片数
|
||||
*/
|
||||
@ApiModelProperty(value = "总分片数")
|
||||
private Integer totalChunks;
|
||||
|
||||
/**
|
||||
* 已上传分片数
|
||||
*/
|
||||
@ApiModelProperty(value = "已上传分片数")
|
||||
private Integer uploadedChunks;
|
||||
|
||||
/**
|
||||
* 上传进度(百分比)
|
||||
*/
|
||||
@ApiModelProperty(value = "上传进度(百分比)")
|
||||
private Integer progress;
|
||||
|
||||
/**
|
||||
* 上传状态
|
||||
*/
|
||||
@ApiModelProperty(value = "上传状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 上传速度(字节/秒)
|
||||
*/
|
||||
@ApiModelProperty(value = "上传速度(字节/秒)")
|
||||
private Long uploadSpeed;
|
||||
|
||||
/**
|
||||
* 预计剩余时间(秒)
|
||||
*/
|
||||
@ApiModelProperty(value = "预计剩余时间(秒)")
|
||||
private Long remainingSeconds;
|
||||
|
||||
/**
|
||||
* 合并进度(0-100,仅在MERGING状态时有效)
|
||||
*/
|
||||
@ApiModelProperty(value = "合并进度")
|
||||
private Integer mergeProgress;
|
||||
|
||||
/**
|
||||
* 文件ID(合并完成后返回)
|
||||
*/
|
||||
@ApiModelProperty(value = "文件ID")
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
* 文件下载地址(合并完成后返回)
|
||||
*/
|
||||
@ApiModelProperty(value = "文件下载地址")
|
||||
private String downloadUrl;
|
||||
|
||||
/**
|
||||
* 文件路径(合并完成后返回)
|
||||
*/
|
||||
@ApiModelProperty(value = "文件路径")
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* 错误信息(合并失败时返回)
|
||||
*/
|
||||
@ApiModelProperty(value = "错误信息")
|
||||
private String errorMessage;
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package com.microservices.file.domain.vo.input;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 检查分片请求
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("检查分片请求")
|
||||
public class CheckChunkInputVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "上传ID", required = true)
|
||||
@NotBlank(message = "上传ID不能为空")
|
||||
private String uploadId;
|
||||
|
||||
@ApiModelProperty(value = "分片序号", required = true)
|
||||
@NotNull(message = "分片序号不能为空")
|
||||
private Integer chunkNumber;
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package com.microservices.file.domain.vo.input;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("检查秒传请求")
|
||||
public class CheckInstantUploadInputVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "上传ID", required = true)
|
||||
@NotBlank(message = "上传ID不能为空")
|
||||
private String uploadId;
|
||||
|
||||
@NotBlank(message = "文件签名不能为空")
|
||||
@ApiModelProperty(value = "文件签名(用于秒传校验,可能是完整MD5或采样点哈希)", required = true)
|
||||
private String fileSignature;
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package com.microservices.file.domain.vo.input;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 初始化分片上传请求
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("初始化分片上传请求")
|
||||
public class InitChunkedUploadInputVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "文件名", required = true)
|
||||
@NotBlank(message = "文件名不能为空")
|
||||
private String fileName;
|
||||
|
||||
@ApiModelProperty(value = "文件大小(字节)", required = true)
|
||||
@NotNull(message = "文件大小不能为空")
|
||||
private Long fileSize;
|
||||
|
||||
@ApiModelProperty(value = "文件类型(cms/dms/resource/pms等)")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "层级结构")
|
||||
private String hierarchy;
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package com.microservices.file.domain.vo.input;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 合并分片请求
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("合并分片请求")
|
||||
public class MergeChunksInputVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "上传ID", required = true)
|
||||
@NotBlank(message = "上传ID不能为空")
|
||||
private String uploadId;
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
package com.microservices.file.domain.vo.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 取消上传响应
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("取消上传响应")
|
||||
public class CancelUploadResponseVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("是否取消成功")
|
||||
private Boolean success;
|
||||
|
||||
@ApiModelProperty("消息")
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 创建成功响应
|
||||
*/
|
||||
public static CancelUploadResponseVo success() {
|
||||
CancelUploadResponseVo response = new CancelUploadResponseVo();
|
||||
response.setSuccess(true);
|
||||
response.setMessage("上传已取消");
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败响应
|
||||
*/
|
||||
public static CancelUploadResponseVo failed(String message) {
|
||||
CancelUploadResponseVo response = new CancelUploadResponseVo();
|
||||
response.setSuccess(false);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package com.microservices.file.domain.vo.response;
|
||||
|
||||
import com.microservices.file.domain.vo.CheckChunkVo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 检查分片响应
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("检查分片响应")
|
||||
public class CheckChunkResponseVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("分片是否存在")
|
||||
private Boolean exists;
|
||||
|
||||
@ApiModelProperty("分片序号")
|
||||
private Integer chunkNumber;
|
||||
|
||||
@ApiModelProperty("分片大小(字节)")
|
||||
private Long chunkSize;
|
||||
|
||||
/**
|
||||
* 从CheckChunkVo转换
|
||||
*/
|
||||
public static CheckChunkResponseVo from(CheckChunkVo vo) {
|
||||
CheckChunkResponseVo response = new CheckChunkResponseVo();
|
||||
response.setExists(vo.getExists());
|
||||
response.setChunkNumber(vo.getChunkNumber());
|
||||
response.setChunkSize(vo.getChunkSize());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
package com.microservices.file.domain.vo.response;
|
||||
|
||||
import com.microservices.file.domain.vo.CheckInstantUploadVo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel("检查秒传响应")
|
||||
public class CheckInstantUploadResponseVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("是否可以秒传")
|
||||
private Boolean canInstantUpload;
|
||||
|
||||
@ApiModelProperty("是否可以断点续传")
|
||||
private Boolean canResumingUpload;
|
||||
|
||||
@ApiModelProperty("已存在文件ID")
|
||||
private Long existingFileId;
|
||||
|
||||
@ApiModelProperty("已存在文件名")
|
||||
private String existingFileName;
|
||||
|
||||
@ApiModelProperty("已存在文件路径")
|
||||
private String existingFilePath;
|
||||
|
||||
@ApiModelProperty("已存在文件下载地址")
|
||||
private String existingFileUrl;
|
||||
|
||||
@ApiModelProperty("已存在文件大小")
|
||||
private String existingFileSize;
|
||||
|
||||
@ApiModelProperty("已存在未上传完成的上传Id(断点续传时)")
|
||||
private String resumingUploadId;
|
||||
|
||||
@ApiModelProperty("已上传的分片Id列表(断点续传时)-当状态为合并中时该值为null,请直接调用进度接口查看进度")
|
||||
private List<Integer> completedUploadChunkedNumberList;
|
||||
|
||||
@ApiModelProperty("已存在未上传完成的上传状态,UPLOADING-上传中,MERGING-合并中(断点续传时)")
|
||||
private String resumingUploadStatus;
|
||||
|
||||
@ApiModelProperty("消息")
|
||||
private String message;
|
||||
|
||||
public static CheckInstantUploadResponseVo from(CheckInstantUploadVo vo) {
|
||||
CheckInstantUploadResponseVo response = new CheckInstantUploadResponseVo();
|
||||
response.setCanInstantUpload(vo.getCanInstantUpload());
|
||||
response.setCanResumingUpload(vo.getCanResumingUpload());
|
||||
response.setExistingFileId(vo.getExistingFileId());
|
||||
response.setExistingFileName(vo.getExistingFileName());
|
||||
response.setExistingFilePath(vo.getExistingFilePath());
|
||||
response.setExistingFileUrl(vo.getExistingFileUrl());
|
||||
response.setExistingFileSize(vo.getExistingFileSize());
|
||||
response.setResumingUploadId(vo.getResumingUploadId());
|
||||
response.setCompletedUploadChunkedNumberList(vo.getCompletedUploadChunkedNumberList());
|
||||
response.setResumingUploadStatus(vo.getResumingUploadStatus());
|
||||
response.setMessage(vo.getMessage());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package com.microservices.file.domain.vo.response;
|
||||
|
||||
import com.microservices.file.domain.vo.InitChunkedUploadVo;
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 初始化分片上传响应
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("初始化分片上传响应")
|
||||
public class InitChunkedUploadResponseVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("上传ID")
|
||||
private String uploadId;
|
||||
|
||||
@ApiModelProperty("总分片数")
|
||||
private Integer totalChunks;
|
||||
|
||||
@ApiModelProperty("分片大小(字节)")
|
||||
private Long chunkSize;
|
||||
|
||||
@ApiModelProperty("上传分片的并发数")
|
||||
private Integer concurrent;
|
||||
|
||||
|
||||
@ApiModelProperty("哈希类型(FULL=完整文件MD5, SAMPLE=采样点哈希)")
|
||||
private String hashType;
|
||||
|
||||
@ApiModelProperty("采样点分片序号列表")
|
||||
private List<Integer> sampleChunks;
|
||||
|
||||
/**
|
||||
* 从InitChunkedUploadVo转换
|
||||
*/
|
||||
public static InitChunkedUploadResponseVo from(InitChunkedUploadVo vo) {
|
||||
InitChunkedUploadResponseVo response = new InitChunkedUploadResponseVo();
|
||||
response.setUploadId(vo.getUploadId());
|
||||
response.setTotalChunks(vo.getTotalChunks());
|
||||
response.setChunkSize(vo.getChunkSize());
|
||||
response.setConcurrent(vo.getConcurrent());
|
||||
response.setHashType(vo.getHashType());
|
||||
response.setSampleChunks(vo.getSampleChunks());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
package com.microservices.file.domain.vo.response;
|
||||
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 合并分片响应
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("合并分片响应")
|
||||
public class MergeChunksResponseVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("文件下载地址")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty("文件标识")
|
||||
private String fileIdentifier;
|
||||
|
||||
@ApiModelProperty("文件路径")
|
||||
private String fileName;
|
||||
|
||||
@ApiModelProperty("文件ID")
|
||||
private Long fileId;
|
||||
|
||||
@ApiModelProperty("文件原始名称")
|
||||
private String fileOriginName;
|
||||
|
||||
@ApiModelProperty("文件后缀")
|
||||
private String fileSuffix;
|
||||
|
||||
@ApiModelProperty("文件大小")
|
||||
private String fileSize;
|
||||
|
||||
/**
|
||||
* 从SysFileInfo转换
|
||||
*/
|
||||
public static MergeChunksResponseVo from(SysFileInfo fileInfo) {
|
||||
MergeChunksResponseVo response = new MergeChunksResponseVo();
|
||||
response.setUrl(fileInfo.getDownloadUrl());
|
||||
response.setFileIdentifier(fileInfo.getFileIdentifier());
|
||||
response.setFileName(fileInfo.getFilePath());
|
||||
response.setFileId(fileInfo.getFileId());
|
||||
response.setFileOriginName(fileInfo.getFileOriginName());
|
||||
response.setFileSuffix(fileInfo.getFileSuffix());
|
||||
response.setFileSize(fileInfo.getFileSizeInfo());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
package com.microservices.file.domain.vo.response;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 上传分片响应
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("上传分片响应")
|
||||
public class UploadChunkResponseVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("分片序号")
|
||||
private Integer chunkNumber;
|
||||
|
||||
@ApiModelProperty("是否上传成功")
|
||||
private Boolean success;
|
||||
|
||||
@ApiModelProperty("消息")
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 创建成功响应
|
||||
*/
|
||||
public static UploadChunkResponseVo success(Integer chunkNumber) {
|
||||
UploadChunkResponseVo response = new UploadChunkResponseVo();
|
||||
response.setChunkNumber(chunkNumber);
|
||||
response.setSuccess(true);
|
||||
response.setMessage("分片上传成功");
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败响应
|
||||
*/
|
||||
public static UploadChunkResponseVo failed(Integer chunkNumber, String message) {
|
||||
UploadChunkResponseVo response = new UploadChunkResponseVo();
|
||||
response.setChunkNumber(chunkNumber);
|
||||
response.setSuccess(false);
|
||||
response.setMessage(message);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
package com.microservices.file.domain.vo.response;
|
||||
|
||||
import com.microservices.file.domain.vo.UploadProgressVo;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 上传进度响应
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("上传进度响应")
|
||||
public class UploadProgressResponseVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("上传ID")
|
||||
private String uploadId;
|
||||
|
||||
@ApiModelProperty("文件名")
|
||||
private String fileName;
|
||||
|
||||
@ApiModelProperty("文件总大小(字节)")
|
||||
private Long fileSize;
|
||||
|
||||
@ApiModelProperty("总分片数")
|
||||
private Integer totalChunks;
|
||||
|
||||
@ApiModelProperty("已上传分片数")
|
||||
private Integer uploadedChunks;
|
||||
|
||||
@ApiModelProperty("上传进度(百分比)")
|
||||
private Integer progress;
|
||||
|
||||
@ApiModelProperty("上传状态")
|
||||
private String status;
|
||||
|
||||
@ApiModelProperty("上传速度(字节/秒)")
|
||||
private Long uploadSpeed;
|
||||
|
||||
@ApiModelProperty("预计剩余时间(秒)")
|
||||
private Long remainingSeconds;
|
||||
|
||||
@ApiModelProperty("合并进度(0-100,仅在MERGING状态时有效)")
|
||||
private Integer mergeProgress;
|
||||
|
||||
@ApiModelProperty("文件ID(合并完成后返回)")
|
||||
private Long fileId;
|
||||
|
||||
@ApiModelProperty("文件下载地址(合并完成后返回)")
|
||||
private String downloadUrl;
|
||||
|
||||
@ApiModelProperty("文件路径(合并完成后返回)")
|
||||
private String filePath;
|
||||
|
||||
@ApiModelProperty("错误信息(合并失败时返回)")
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* 从UploadProgressVo转换
|
||||
*/
|
||||
public static UploadProgressResponseVo from(UploadProgressVo vo) {
|
||||
UploadProgressResponseVo response = new UploadProgressResponseVo();
|
||||
response.setUploadId(vo.getUploadId());
|
||||
response.setFileName(vo.getFileName());
|
||||
response.setFileSize(vo.getFileSize());
|
||||
response.setTotalChunks(vo.getTotalChunks());
|
||||
response.setUploadedChunks(vo.getUploadedChunks());
|
||||
response.setProgress(vo.getProgress());
|
||||
response.setStatus(vo.getStatus());
|
||||
response.setUploadSpeed(vo.getUploadSpeed());
|
||||
response.setRemainingSeconds(vo.getRemainingSeconds());
|
||||
response.setMergeProgress(vo.getMergeProgress());
|
||||
response.setFileId(vo.getFileId());
|
||||
response.setDownloadUrl(vo.getDownloadUrl());
|
||||
response.setFilePath(vo.getFilePath());
|
||||
response.setErrorMessage(vo.getErrorMessage());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
package com.microservices.file.mapper;
|
||||
|
||||
import com.microservices.file.domain.FileUploadChunk;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件分片记录Mapper接口
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Mapper
|
||||
public interface FileUploadChunkMapper {
|
||||
|
||||
/**
|
||||
* 查询文件分片记录
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param chunkNumber 分片序号
|
||||
* @return 文件分片记录
|
||||
*/
|
||||
FileUploadChunk selectByUploadIdAndChunkNumber(@Param("uploadId") String uploadId, @Param("chunkNumber") Integer chunkNumber);
|
||||
|
||||
/**
|
||||
* 查询文件分片记录列表
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 文件分片记录集合
|
||||
*/
|
||||
List<FileUploadChunk> selectByUploadId(String uploadId);
|
||||
|
||||
/**
|
||||
* 查询文件分片记录列表
|
||||
*
|
||||
* @param fileUploadChunk 文件分片记录
|
||||
* @return 文件分片记录集合
|
||||
*/
|
||||
List<FileUploadChunk> selectChunkList(FileUploadChunk fileUploadChunk);
|
||||
|
||||
/**
|
||||
* 新增文件分片记录
|
||||
*
|
||||
* @param fileUploadChunk 文件分片记录
|
||||
* @return 结果
|
||||
*/
|
||||
int insertChunk(FileUploadChunk fileUploadChunk);
|
||||
|
||||
/**
|
||||
* 批量新增文件分片记录
|
||||
*
|
||||
* @param chunks 文件分片记录集合
|
||||
* @return 结果
|
||||
*/
|
||||
int batchInsertChunks(List<FileUploadChunk> chunks);
|
||||
|
||||
/**
|
||||
* 修改文件分片记录
|
||||
*
|
||||
* @param fileUploadChunk 文件分片记录
|
||||
* @return 结果
|
||||
*/
|
||||
int updateChunk(FileUploadChunk fileUploadChunk);
|
||||
|
||||
/**
|
||||
* 删除文件分片记录
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteByUploadId(String uploadId);
|
||||
|
||||
/**
|
||||
* 批量删除文件分片记录
|
||||
*
|
||||
* @param uploadIds 需要删除的上传ID集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteByUploadIds(String[] uploadIds);
|
||||
|
||||
/**
|
||||
* 统计已上传的分片数
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 已上传分片数
|
||||
*/
|
||||
int countUploadedChunks(String uploadId);
|
||||
|
||||
/**
|
||||
* 查询指定状态的分片列表
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param status 状态
|
||||
* @return 文件分片记录集合
|
||||
*/
|
||||
List<FileUploadChunk> selectByUploadIdAndStatus(@Param("uploadId") String uploadId, @Param("status") String status);
|
||||
|
||||
/**
|
||||
* 批量更新分片状态
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param status 状态
|
||||
* @return 结果
|
||||
*/
|
||||
int updateStatusByUploadId(@Param("uploadId") String uploadId, @Param("status") String status);
|
||||
}
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
package com.microservices.file.mapper;
|
||||
|
||||
import com.microservices.file.domain.FileUploadSession;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件分片上传会话Mapper接口
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Mapper
|
||||
public interface FileUploadSessionMapper {
|
||||
|
||||
/**
|
||||
* 查询文件分片上传会话
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 文件分片上传会话
|
||||
*/
|
||||
FileUploadSession selectByUploadId(String uploadId);
|
||||
|
||||
/**
|
||||
* 查询文件分片上传会话列表
|
||||
*
|
||||
* @param fileUploadSession 文件分片上传会话
|
||||
* @return 文件分片上传会话集合
|
||||
*/
|
||||
List<FileUploadSession> selectSessionList(FileUploadSession fileUploadSession);
|
||||
|
||||
/**
|
||||
* 新增文件分片上传会话
|
||||
*
|
||||
* @param fileUploadSession 文件分片上传会话
|
||||
* @return 结果
|
||||
*/
|
||||
int insertSession(FileUploadSession fileUploadSession);
|
||||
|
||||
/**
|
||||
* 修改文件分片上传会话
|
||||
*
|
||||
* @param fileUploadSession 文件分片上传会话
|
||||
* @return 结果
|
||||
*/
|
||||
int updateSession(FileUploadSession fileUploadSession);
|
||||
|
||||
/**
|
||||
* 删除文件分片上传会话
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteByUploadId(String uploadId);
|
||||
|
||||
/**
|
||||
* 批量删除文件分片上传会话
|
||||
*
|
||||
* @param uploadIds 需要删除的上传ID集合
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteByUploadIds(String[] uploadIds);
|
||||
|
||||
/**
|
||||
* 查询过期的会话
|
||||
*
|
||||
* @return 过期的会话列表
|
||||
*/
|
||||
List<FileUploadSession> selectExpiredSessions();
|
||||
|
||||
/**
|
||||
* 根据文件签名查询已完成的会话
|
||||
*
|
||||
* @param fileSignature 文件签名(可能是完整MD5或采样点哈希)
|
||||
* @return 文件分片上传会话
|
||||
*/
|
||||
FileUploadSession selectCompletedByFileSignature(String fileSignature);
|
||||
|
||||
/**
|
||||
* 根据文件哈希和哈希类型查询已完成的会话
|
||||
*
|
||||
* @param fileSignature 文件哈希
|
||||
* @param hashType 哈希类型
|
||||
* @return 文件分片上传会话
|
||||
*/
|
||||
FileUploadSession selectCompletedByFileSignatureAndType(@Param("fileSignature") String fileSignature, @Param("hashType") String hashType);
|
||||
|
||||
/**
|
||||
* 更新会话状态
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param status 状态
|
||||
* @return 结果
|
||||
*/
|
||||
int updateStatus(@Param("uploadId") String uploadId, @Param("status") String status);
|
||||
|
||||
/**
|
||||
* 增加已上传分片数
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 结果
|
||||
*/
|
||||
int incrementUploadedChunks(String uploadId);
|
||||
|
||||
FileUploadSession selectUploadingOrMergingByFileSignatureAndType(@Param("fileSignature") String fileSignature, @Param("hashType") String hashType);
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
package com.microservices.file.service;
|
||||
|
||||
import com.microservices.file.domain.FileUploadSession;
|
||||
import com.microservices.file.domain.vo.CheckChunkVo;
|
||||
import com.microservices.file.domain.vo.CheckInstantUploadVo;
|
||||
import com.microservices.file.domain.vo.InitChunkedUploadVo;
|
||||
import com.microservices.file.domain.vo.UploadProgressVo;
|
||||
import com.microservices.file.domain.vo.input.InitChunkedUploadInputVo;
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 分片上传服务接口
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
public interface IChunkedUploadService {
|
||||
|
||||
/**
|
||||
* 初始化分片上传
|
||||
* <p>
|
||||
* 功能:
|
||||
* 1. 创建上传会话
|
||||
* 2. 根据文件大小判断哈希类型(FULL/SAMPLE)
|
||||
* 3. 返回采样点信息(SAMPLE类型)
|
||||
*
|
||||
* @param input 初始化分片输入对象
|
||||
* @return 初始化结果,包含 uploadId、totalChunks、chunkSize、hashType、sampleChunks
|
||||
*/
|
||||
InitChunkedUploadVo initChunkedUpload(InitChunkedUploadInputVo input);
|
||||
|
||||
/**
|
||||
* 检查秒传(简化版)
|
||||
* <p>
|
||||
* 功能:
|
||||
* 1. 校验上传会话和时间窗口
|
||||
* 2. 查询是否存在相同的 file_hash 且状态为已完成
|
||||
* 3. 秒传成功:删除当前会话,返回已存在文件信息
|
||||
* 4. 不能秒传:存储 fileHash,返回继续上传
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param fileHash 文件哈希(完整文件MD5或采样点哈希)
|
||||
* @return 检查结果
|
||||
*/
|
||||
CheckInstantUploadVo checkInstantUpload(String uploadId, String fileHash);
|
||||
|
||||
/**
|
||||
* 检查分片是否已上传(断点续传)
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param chunkNumber 分片序号
|
||||
* @return 分片检查结果
|
||||
*/
|
||||
CheckChunkVo checkChunk(String uploadId, Integer chunkNumber);
|
||||
|
||||
/**
|
||||
* 上传分片
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @param chunkNumber 分片序号
|
||||
* @param chunk 分片文件
|
||||
* @return 上传结果
|
||||
*/
|
||||
Map<String, Object> uploadChunk(String uploadId, Integer chunkNumber, MultipartFile chunk);
|
||||
|
||||
/**
|
||||
* 合并分片
|
||||
* <p>
|
||||
* 功能:
|
||||
* 1. 合并所有分片为完整文件
|
||||
* 2. 根据哈希类型校验文件完整性(FULL-完整MD5,SAMPLE-采样点哈希)
|
||||
* 3. 调用现有文件服务保存文件
|
||||
* 4. 清理临时分片文件
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 合并后的文件信息
|
||||
*/
|
||||
SysFileInfo mergeChunks(String uploadId);
|
||||
|
||||
/**
|
||||
* 取消上传
|
||||
* <p>
|
||||
* 功能:
|
||||
* 1. 删除上传会话记录
|
||||
* 2. 清理已上传的分片文件
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 取消结果
|
||||
*/
|
||||
boolean cancelUpload(String uploadId);
|
||||
|
||||
/**
|
||||
* 获取上传进度
|
||||
*
|
||||
* @param uploadId 上传ID
|
||||
* @return 上传进度
|
||||
*/
|
||||
UploadProgressVo getProgress(String uploadId);
|
||||
|
||||
/**
|
||||
* 清理过期的上传会话
|
||||
* <p>
|
||||
* 定时任务调用,清理:
|
||||
* 1. 过期未完成的会话
|
||||
* 2. 对应的临时分片文件
|
||||
*
|
||||
* @return 清理的会话数量
|
||||
*/
|
||||
int cleanExpiredSessions();
|
||||
void cleanupTempFiles(FileUploadSession session);
|
||||
List<Integer> parseSampleChunks(String sampleChunksStr);
|
||||
String calculateSampleHashFromChunks(String tempPath, List<Integer> sampleChunks);
|
||||
String mergeChunkFiles(String baseFilePath,FileUploadSession session);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package com.microservices.file.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件Service异步接口
|
||||
*
|
||||
* @author otto
|
||||
*/
|
||||
public interface IFileCommonAsyncService {
|
||||
public void executeMergeAsync(String uploadId);
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.microservices.file.service;
|
||||
|
||||
import com.microservices.file.domain.FileUploadSession;
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
|
@ -105,7 +104,6 @@ public interface ISysFileInfoService {
|
|||
* @return 返回上传成功的文件名
|
||||
*/
|
||||
SysFileInfo upload(MultipartFile file, String type, String hierarchy);
|
||||
SysFileInfo uploadChunkedFile(FileUploadSession session, String type, String hierarchy);
|
||||
|
||||
/**
|
||||
* 根据文件标识获取文件详情
|
||||
|
|
|
|||
|
|
@ -1,745 +0,0 @@
|
|||
package com.microservices.file.service.impl;
|
||||
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.DateUtils;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
import com.microservices.common.core.utils.file.FileUtils;
|
||||
import com.microservices.common.core.utils.uuid.IdUtils;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.file.domain.FileUploadChunk;
|
||||
import com.microservices.file.domain.FileUploadSession;
|
||||
import com.microservices.file.domain.vo.CheckChunkVo;
|
||||
import com.microservices.file.domain.vo.CheckInstantUploadVo;
|
||||
import com.microservices.file.domain.vo.InitChunkedUploadVo;
|
||||
import com.microservices.file.domain.vo.UploadProgressVo;
|
||||
import com.microservices.file.domain.vo.input.InitChunkedUploadInputVo;
|
||||
import com.microservices.file.mapper.FileUploadChunkMapper;
|
||||
import com.microservices.file.mapper.FileUploadSessionMapper;
|
||||
import com.microservices.file.service.IChunkedUploadService;
|
||||
import com.microservices.file.service.IFileCommonAsyncService;
|
||||
import com.microservices.file.service.ISysFileInfoService;
|
||||
import com.microservices.file.utils.FileUploadUtils;
|
||||
import com.microservices.file.utils.Md5Utils;
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 分片上传服务实现
|
||||
*
|
||||
* @author microservices
|
||||
*/
|
||||
@Service
|
||||
public class ChunkedUploadServiceImpl implements IChunkedUploadService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ChunkedUploadServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private FileUploadSessionMapper sessionMapper;
|
||||
|
||||
@Autowired
|
||||
private FileUploadChunkMapper chunkMapper;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private ISysFileInfoService fileInfoService;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private IFileCommonAsyncService fileCommonAsyncService;
|
||||
|
||||
/**
|
||||
* 文件存储根路径
|
||||
*/
|
||||
@Value("${file.path}")
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* 最小分片大小(默认:1MB)- 安全校验边界
|
||||
*/
|
||||
@Value("${chunked.upload.minChunkSize:1048576}")
|
||||
private Long minChunkSize;
|
||||
|
||||
/**
|
||||
* 最大分片大小(默认:50MB)- 安全校验边界
|
||||
*/
|
||||
@Value("${chunked.upload.maxChunkSize:52428800}")
|
||||
private Long maxChunkSize;
|
||||
|
||||
/**
|
||||
* 会话过期时间(默认:24小时)
|
||||
*/
|
||||
@Value("${chunked.upload.sessionExpireHours:24}")
|
||||
private Integer sessionExpireHours = 24;
|
||||
|
||||
/**
|
||||
* 最大并发上传分片数(安全边界)
|
||||
*/
|
||||
@Value("${chunked.upload.maxConcurrentChunks:10}")
|
||||
private Integer maxConcurrentChunks = 10;
|
||||
|
||||
/**
|
||||
* 最大文件大小(字节,默认50GB = 1024 * 50MB)
|
||||
*/
|
||||
@Value("${chunked.upload.maxFileSize:53687091200}")
|
||||
private Long maxFileSize;
|
||||
|
||||
/**
|
||||
* 完整哈希文件大小阈值(小于此值使用完整文件MD5,默认100MB)
|
||||
*
|
||||
*/
|
||||
@Value("${chunked.upload.fullHashThreshold:104857600}")
|
||||
private Long fullHashThreshold;
|
||||
|
||||
/**
|
||||
* 哈希采样点数量
|
||||
*/
|
||||
@Value("${chunked.upload.sampleCount:5}")
|
||||
private Integer sampleCount;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public InitChunkedUploadVo initChunkedUpload(InitChunkedUploadInputVo input) {
|
||||
// 1. 参数校验
|
||||
if (StringUtils.isEmpty(input.getFileName())) {
|
||||
throw new ServiceException("文件名不能为空");
|
||||
}
|
||||
if (input.getFileSize() == null || input.getFileSize() <= 0) {
|
||||
throw new ServiceException("文件大小无效");
|
||||
}
|
||||
|
||||
// 校验文件大小
|
||||
if (input.getFileSize() > maxFileSize) {
|
||||
throw new ServiceException("文件大小超过限制: %s(%d字节) ", FileUtils.calcFileSize(maxFileSize), maxFileSize);
|
||||
}
|
||||
|
||||
// 2. 计算分片信息(使用服务端动态计算的分片大小)
|
||||
Long chunkSize = calculateRecommendedChunkSize(input.getFileSize());
|
||||
int totalChunks = (int) Math.ceil((double) input.getFileSize() / chunkSize);
|
||||
Integer concurrent = calculateRecommendedConcurrent(totalChunks);
|
||||
|
||||
// 3. 根据文件大小判断哈希类型
|
||||
String hashType = (input.getFileSize() < fullHashThreshold) ? "FULL" : "SAMPLE";
|
||||
List<Integer> sampleChunks = null;
|
||||
|
||||
if ("SAMPLE".equals(hashType)) {
|
||||
// 计算采样点
|
||||
sampleChunks = calculateSampleChunks(totalChunks, sampleCount);
|
||||
}
|
||||
|
||||
// 4. 创建上传会话
|
||||
String uploadId = IdUtils.fastSimpleUUID();
|
||||
FileUploadSession session = new FileUploadSession();
|
||||
session.setUploadId(uploadId);
|
||||
session.setFileName(input.getFileName());
|
||||
session.setFileSize(input.getFileSize());
|
||||
session.setChunkSize(chunkSize);
|
||||
session.setTotalChunks(totalChunks);
|
||||
session.setUploadedChunks(0);
|
||||
session.setUploadType(input.getType());
|
||||
session.setHierarchy(input.getHierarchy());
|
||||
session.setStatus(FileUploadSession.Status.INIT.getCode());
|
||||
session.setTempFilePath(getTempSessionPath(uploadId));
|
||||
session.setCreateBy(SecurityUtils.getUsername());
|
||||
session.setCreateTime(DateUtils.getNowDate());
|
||||
session.setExpireTime(DateUtils.addHours(DateUtils.getNowDate(), sessionExpireHours));
|
||||
session.setHashType(hashType);
|
||||
if (sampleChunks != null && !sampleChunks.isEmpty()) {
|
||||
session.setSampleChunks(sampleChunks.stream().map(String::valueOf).reduce((a, b) -> a + "," + b).orElse(""));
|
||||
}
|
||||
|
||||
sessionMapper.insertSession(session);
|
||||
|
||||
// 5. 创建分片记录
|
||||
List<FileUploadChunk> chunks = new ArrayList<>();
|
||||
for (int i = 0; i < totalChunks; i++) {
|
||||
FileUploadChunk chunk = new FileUploadChunk();
|
||||
chunk.setUploadId(uploadId);
|
||||
chunk.setChunkNumber(i);
|
||||
chunk.setChunkSize(chunkSize);
|
||||
chunk.setStatus(FileUploadChunk.Status.PENDING.getCode());
|
||||
chunks.add(chunk);
|
||||
}
|
||||
chunkMapper.batchInsertChunks(chunks);
|
||||
|
||||
// 6. 创建临时目录
|
||||
createTempDirectory(session.getTempFilePath());
|
||||
|
||||
// 7. 返回结果
|
||||
InitChunkedUploadVo result = new InitChunkedUploadVo();
|
||||
result.setUploadId(uploadId);
|
||||
result.setTotalChunks(totalChunks);
|
||||
result.setChunkSize(chunkSize);
|
||||
result.setConcurrent(concurrent);
|
||||
result.setHashType(hashType);
|
||||
result.setSampleChunks(sampleChunks);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CheckInstantUploadVo checkInstantUpload(String uploadId, String fileSignature) {
|
||||
// 1. 校验上传会话
|
||||
FileUploadSession session = sessionMapper.selectByUploadId(uploadId);
|
||||
if (session == null) {
|
||||
throw new ServiceException("上传会话不存在");
|
||||
}
|
||||
|
||||
// 2. 查询数据库是否存在相同的 file_hash 且状态为已完成
|
||||
FileUploadSession completedSession = sessionMapper.selectCompletedByFileSignatureAndType(fileSignature, session.getHashType());
|
||||
|
||||
if (completedSession != null && completedSession.getFileId() != null) {
|
||||
// ========== 秒传成功 ==========
|
||||
SysFileInfo fileInfo = fileInfoService.selectSysFileInfoByFileId(completedSession.getFileId());
|
||||
|
||||
if (fileInfo != null) {
|
||||
// 删除当前会话及其分片记录
|
||||
chunkMapper.deleteByUploadId(uploadId);
|
||||
sessionMapper.deleteByUploadId(uploadId);
|
||||
|
||||
// 清理临时文件
|
||||
cleanupTempFiles(session);
|
||||
|
||||
// 返回已存在文件信息
|
||||
return CheckInstantUploadVo.instantSuccess(
|
||||
fileInfo.getFileId(),
|
||||
fileInfo.getFileOriginName(),
|
||||
fileInfo.getFilePath(),
|
||||
fileInfo.getDownloadUrl(),
|
||||
fileInfo.getFileSizeInfo()
|
||||
);
|
||||
}
|
||||
}
|
||||
// 3. 检查断点续传:查询数据库是否存在相同的 fileSignature 且状态为上传中或者合并中
|
||||
FileUploadSession uploadingOrMergingSession = sessionMapper.selectUploadingOrMergingByFileSignatureAndType(fileSignature, session.getHashType());
|
||||
if (uploadingOrMergingSession != null && uploadingOrMergingSession.getFileSignature() != null) {
|
||||
// ========== 断点续传成功 ==========
|
||||
// 删除当前会话及其分片记录
|
||||
chunkMapper.deleteByUploadId(uploadId);
|
||||
sessionMapper.deleteByUploadId(uploadId);
|
||||
// 清理临时文件
|
||||
cleanupTempFiles(session);
|
||||
List<Integer> completedUploadChunkedIdList = null;
|
||||
if (FileUploadSession.Status.UPLOADING.getCode().equals(uploadingOrMergingSession.getStatus())) {
|
||||
List<FileUploadChunk> chunkList = chunkMapper.selectByUploadId(uploadingOrMergingSession.getUploadId());
|
||||
completedUploadChunkedIdList = chunkList.stream()
|
||||
.filter(x -> FileUploadChunk.Status.UPLOADED.getCode().equals(x.getStatus()))
|
||||
.map(FileUploadChunk::getChunkNumber).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 返回已存在文件信息
|
||||
return CheckInstantUploadVo.resumingSuccess(
|
||||
uploadingOrMergingSession.getUploadId(),
|
||||
completedUploadChunkedIdList,
|
||||
uploadingOrMergingSession.getStatus());
|
||||
}
|
||||
|
||||
// ========== 不能秒传,存储哈希值 ==========
|
||||
session.setFileSignature(fileSignature);
|
||||
sessionMapper.updateSession(session);
|
||||
|
||||
return CheckInstantUploadVo.needUpload("未找到相同文件,请继续上传分片");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckChunkVo checkChunk(String uploadId, Integer chunkNumber) {
|
||||
// 1. 校验上传会话
|
||||
FileUploadSession session = sessionMapper.selectByUploadId(uploadId);
|
||||
if (session == null) {
|
||||
throw new ServiceException("上传会话不存在");
|
||||
}
|
||||
|
||||
// 2. 校验分片序号
|
||||
if (chunkNumber == null || chunkNumber < 0 || chunkNumber >= session.getTotalChunks()) {
|
||||
throw new ServiceException("分片序号无效");
|
||||
}
|
||||
|
||||
// 3. 查询分片记录
|
||||
FileUploadChunk chunk = chunkMapper.selectByUploadIdAndChunkNumber(uploadId, chunkNumber);
|
||||
if (chunk == null) {
|
||||
return CheckChunkVo.notExists(chunkNumber);
|
||||
}
|
||||
|
||||
// 4. 检查分片文件是否存在
|
||||
if (FileUploadChunk.Status.UPLOADED.getCode().equals(chunk.getStatus())) {
|
||||
File chunkFile = new File(chunk.getChunkPath());
|
||||
if (chunkFile.exists()) {
|
||||
return CheckChunkVo.exists(chunkNumber, chunk.getChunkSize());
|
||||
}
|
||||
}
|
||||
|
||||
return CheckChunkVo.notExists(chunkNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Map<String, Object> uploadChunk(String uploadId, Integer chunkNumber, MultipartFile chunk) {
|
||||
// 1. 校验上传会话
|
||||
FileUploadSession session = sessionMapper.selectByUploadId(uploadId);
|
||||
if (session == null) {
|
||||
throw new ServiceException("上传会话不存在");
|
||||
}
|
||||
|
||||
// 2. 校验分片序号
|
||||
if (chunkNumber == null || chunkNumber < 0 || chunkNumber >= session.getTotalChunks()) {
|
||||
throw new ServiceException("分片序号无效");
|
||||
}
|
||||
|
||||
// 3. 校验文件
|
||||
if (chunk == null || chunk.isEmpty()) {
|
||||
throw new ServiceException("分片文件不能为空");
|
||||
}
|
||||
|
||||
// 4. 更新会话状态
|
||||
if (FileUploadSession.Status.INIT.getCode().equals(session.getStatus())) {
|
||||
sessionMapper.updateStatus(uploadId, FileUploadSession.Status.UPLOADING.getCode());
|
||||
}
|
||||
|
||||
// 5. 查询分片记录
|
||||
FileUploadChunk chunkRecord = chunkMapper.selectByUploadIdAndChunkNumber(uploadId, chunkNumber);
|
||||
if (chunkRecord == null) {
|
||||
throw new ServiceException("分片记录不存在");
|
||||
}
|
||||
|
||||
// 6. 检查是否已上传
|
||||
if (FileUploadChunk.Status.UPLOADED.getCode().equals(chunkRecord.getStatus())) {
|
||||
File existingFile = new File(chunkRecord.getChunkPath());
|
||||
if (existingFile.exists()) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("success", true);
|
||||
result.put("message", "分片已存在");
|
||||
result.put("chunkNumber", chunkNumber);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// 7. 保存分片文件
|
||||
String chunkFilePath = getChunkFilePath(session.getTempFilePath(), chunkNumber);
|
||||
File chunkFile = new File(chunkFilePath);
|
||||
|
||||
try {
|
||||
chunk.transferTo(chunkFile);
|
||||
} catch (IOException e) {
|
||||
logger.error("保存分片文件失败: uploadId={}, chunkNumber={}", uploadId, chunkNumber, e);
|
||||
throw new ServiceException("保存分片文件失败");
|
||||
}
|
||||
|
||||
// 8. 更新分片记录
|
||||
chunkRecord.setChunkPath(chunkFilePath);
|
||||
chunkRecord.setStatus(FileUploadChunk.Status.UPLOADED.getCode());
|
||||
chunkRecord.setUploadTime(DateUtils.getNowDate());
|
||||
chunkMapper.updateChunk(chunkRecord);
|
||||
|
||||
// 9. 更新会话已上传分片数
|
||||
sessionMapper.incrementUploadedChunks(uploadId);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("success", true);
|
||||
result.put("message", "分片上传成功");
|
||||
result.put("chunkNumber", chunkNumber);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public SysFileInfo mergeChunks(String uploadId) {
|
||||
// 1. 校验上传会话
|
||||
FileUploadSession session = sessionMapper.selectByUploadId(uploadId);
|
||||
if (session == null) {
|
||||
throw new ServiceException("上传会话不存在");
|
||||
}
|
||||
|
||||
// 2. 幂等性:已完成的直接返回
|
||||
if (FileUploadSession.Status.COMPLETED.getCode().equals(session.getStatus())
|
||||
&& session.getFileId() != null) {
|
||||
SysFileInfo fileInfo = fileInfoService.selectSysFileInfoByFileId(session.getFileId());
|
||||
if (fileInfo != null) {
|
||||
return fileInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检查所有分片是否已上传
|
||||
int uploadedCount = chunkMapper.countUploadedChunks(uploadId);
|
||||
if (uploadedCount < session.getTotalChunks()) {
|
||||
throw new ServiceException("还有分片未上传,无法合并");
|
||||
}
|
||||
|
||||
// 4. 状态检查:防止重复提交
|
||||
String currentStatus = session.getStatus();
|
||||
if (FileUploadSession.Status.MERGING.getCode().equals(currentStatus)) {
|
||||
// 已在合并中,直接返回 null
|
||||
return null;
|
||||
}
|
||||
if (FileUploadSession.Status.MERGE_FAILED.getCode().equals(currentStatus)) {
|
||||
throw new ServiceException("上次合并失败:" + session.getErrorMessage());
|
||||
}
|
||||
|
||||
// 5. 更新状态为 MERGING
|
||||
session.setStatus(FileUploadSession.Status.MERGING.getCode());
|
||||
sessionMapper.updateSession(session);
|
||||
|
||||
// 6. 异步执行合并
|
||||
fileCommonAsyncService.executeMergeAsync(uploadId);
|
||||
|
||||
// 7. 立即返回
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并分片文件
|
||||
*/
|
||||
@Override
|
||||
public String mergeChunkFiles(String baseFilePath, FileUploadSession session) {
|
||||
String fileName = FileUploadUtils.extractFilename(session.getFileName());
|
||||
String mergedFilePath = FileUploadUtils.getAbsoluteFile(baseFilePath, fileName).getAbsolutePath();
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(mergedFilePath)) {
|
||||
List<FileUploadChunk> chunks = chunkMapper.selectByUploadId(session.getUploadId());
|
||||
for (FileUploadChunk chunk : chunks) {
|
||||
File chunkFile = new File(chunk.getChunkPath());
|
||||
if (!chunkFile.exists()) {
|
||||
throw new ServiceException("分片文件不存在: " + chunk.getChunkPath());
|
||||
}
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(chunkFile)) {
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead;
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
fos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("合并分片文件失败: uploadId={}", session.getUploadId(), e);
|
||||
throw new ServiceException("合并分片文件失败");
|
||||
}
|
||||
// 哈希校验(FULL类型进行后置校验)
|
||||
validateFullFileHash(mergedFilePath, session);
|
||||
|
||||
return FileUploadUtils.getPathFileName(fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean cancelUpload(String uploadId) {
|
||||
// 1. 查询会话
|
||||
FileUploadSession session = sessionMapper.selectByUploadId(uploadId);
|
||||
if (session == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 删除分片记录
|
||||
chunkMapper.deleteByUploadId(uploadId);
|
||||
|
||||
// 3. 删除会话记录
|
||||
sessionMapper.deleteByUploadId(uploadId);
|
||||
|
||||
// 4. 清理临时文件
|
||||
cleanupTempFiles(session);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadProgressVo getProgress(String uploadId) {
|
||||
FileUploadSession session = sessionMapper.selectByUploadId(uploadId);
|
||||
if (session == null) {
|
||||
throw new ServiceException("上传会话不存在");
|
||||
}
|
||||
|
||||
UploadProgressVo progress = new UploadProgressVo();
|
||||
progress.setUploadId(uploadId);
|
||||
progress.setFileName(session.getFileName());
|
||||
progress.setFileSize(session.getFileSize());
|
||||
progress.setTotalChunks(session.getTotalChunks());
|
||||
progress.setUploadedChunks(session.getUploadedChunks());
|
||||
progress.setStatus(session.getStatus());
|
||||
|
||||
// 计算上传进度
|
||||
if (session.getTotalChunks() > 0) {
|
||||
int progressPercent = (int) ((session.getUploadedChunks() * 100) / session.getTotalChunks());
|
||||
progress.setProgress(progressPercent);
|
||||
} else {
|
||||
progress.setProgress(0);
|
||||
}
|
||||
|
||||
// 合并状态下的额外信息
|
||||
if (FileUploadSession.Status.COMPLETED.getCode().equals(session.getStatus())
|
||||
&& session.getFileId() != null) {
|
||||
// 获取文件信息
|
||||
SysFileInfo fileInfo = fileInfoService.selectSysFileInfoByFileId(session.getFileId());
|
||||
if (fileInfo != null) {
|
||||
progress.setFileId(fileInfo.getFileId());
|
||||
progress.setDownloadUrl(fileInfo.getDownloadUrl());
|
||||
progress.setFilePath(fileInfo.getFilePath());
|
||||
}
|
||||
progress.setMergeProgress(100);
|
||||
} else if (FileUploadSession.Status.MERGING.getCode().equals(session.getStatus())) {
|
||||
// 合并中
|
||||
progress.setMergeProgress(50); // 简化处理,可以后续细化
|
||||
} else if (FileUploadSession.Status.MERGE_FAILED.getCode().equals(session.getStatus())) {
|
||||
// 合并失败
|
||||
progress.setErrorMessage(session.getErrorMessage());
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int cleanExpiredSessions() {
|
||||
// 1. 查询过期会话
|
||||
List<FileUploadSession> expiredSessions = sessionMapper.selectExpiredSessions();
|
||||
|
||||
if (expiredSessions.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
logger.info("开始清理过期会话,共{}个", expiredSessions.size());
|
||||
|
||||
int cleanedCount = 0;
|
||||
for (FileUploadSession session : expiredSessions) {
|
||||
try {
|
||||
// 删除分片记录
|
||||
chunkMapper.deleteByUploadId(session.getUploadId());
|
||||
|
||||
// 删除会话记录
|
||||
sessionMapper.deleteByUploadId(session.getUploadId());
|
||||
|
||||
// 清理临时文件
|
||||
cleanupTempFiles(session);
|
||||
|
||||
cleanedCount++;
|
||||
} catch (Exception e) {
|
||||
logger.error("清理过期会话失败: uploadId={}", session.getUploadId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("清理过期会话完成,成功清理{}个", cleanedCount);
|
||||
return cleanedCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建临时目录
|
||||
*/
|
||||
private void createTempDirectory(String tempPath) {
|
||||
try {
|
||||
Path path = Paths.get(tempPath);
|
||||
if (!Files.exists(path)) {
|
||||
Files.createDirectories(path);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("创建临时目录失败: {}", tempPath, e);
|
||||
throw new ServiceException("创建临时目录失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时文件
|
||||
*/
|
||||
public void cleanupTempFiles(FileUploadSession session) {
|
||||
if (StringUtils.isNotEmpty(session.getTempFilePath())) {
|
||||
File tempDir = new File(session.getTempFilePath());
|
||||
if (tempDir.exists()) {
|
||||
deleteDirectory(tempDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归删除目录
|
||||
*/
|
||||
private void deleteDirectory(File directory) {
|
||||
if (directory.isDirectory()) {
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
deleteDirectory(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
directory.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取临时会话路径
|
||||
*/
|
||||
private String getTempSessionPath(String uploadId) {
|
||||
return filePath + "/chunks/" + uploadId + "/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分片文件路径
|
||||
*/
|
||||
private String getChunkFilePath(String tempPath, Integer chunkNumber) {
|
||||
return tempPath + "chunk_" + chunkNumber;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据文件大小动态计算推荐的分片大小
|
||||
* 使用对数插值算法,基于配置的 minChunkSize 和 maxChunkSize
|
||||
*
|
||||
* @param fileSize 文件大小(字节)
|
||||
* @return 推荐的分片大小(字节)
|
||||
*/
|
||||
private Long calculateRecommendedChunkSize(long fileSize) {
|
||||
long minChunk = minChunkSize;
|
||||
long maxChunk = maxChunkSize;
|
||||
long maxFile = maxFileSize;
|
||||
|
||||
// 小于最小分片大小,直接返回最小值
|
||||
if (fileSize <= minChunk) {
|
||||
return minChunk;
|
||||
}
|
||||
|
||||
// 对数比例:小文件敏感度高,大文件敏感度低
|
||||
double ratio = Math.log((double) fileSize / minChunk) /
|
||||
Math.log((double) maxFile / minChunk);
|
||||
ratio = Math.max(0.0, Math.min(1.0, ratio));
|
||||
|
||||
// 线性插值
|
||||
long recommendedChunk = (long) (minChunk + ratio * (maxChunk - minChunk));
|
||||
recommendedChunk = Math.max(minChunk, Math.min(maxChunk, recommendedChunk));
|
||||
|
||||
// 向上取整到 1MB 边界
|
||||
long mb = 1024 * 1024L;
|
||||
recommendedChunk = ((recommendedChunk + mb - 1) / mb) * mb;
|
||||
|
||||
return Math.max(minChunk, Math.min(maxChunk, recommendedChunk));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分片数量动态计算推荐的并发数
|
||||
* 使用平方根缩放算法,基于配置的 maxConcurrentChunks
|
||||
*
|
||||
* @param totalChunks 分片数量
|
||||
* @return 推荐的并发数
|
||||
*/
|
||||
private Integer calculateRecommendedConcurrent(int totalChunks) {
|
||||
int maxConcurrent = maxConcurrentChunks;
|
||||
int minConcurrent = 2;
|
||||
|
||||
// 分片数量少时,使用最小并发
|
||||
if (totalChunks <= minConcurrent) {
|
||||
return minConcurrent;
|
||||
}
|
||||
|
||||
// 平方根缩放:避免过度并发
|
||||
int recommendedConcurrent = (int) Math.ceil(Math.sqrt(totalChunks));
|
||||
recommendedConcurrent = Math.max(minConcurrent, Math.min(maxConcurrent, recommendedConcurrent));
|
||||
|
||||
return recommendedConcurrent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算采样点分片序号
|
||||
*
|
||||
* @param totalChunks 总分片数
|
||||
* @param sampleCount 采样点数量
|
||||
* @return 采样点分片序号列表
|
||||
*/
|
||||
private List<Integer> calculateSampleChunks(int totalChunks, int sampleCount) {
|
||||
List<Integer> samples = new ArrayList<>();
|
||||
if (totalChunks <= sampleCount) {
|
||||
for (int i = 0; i < totalChunks; i++) {
|
||||
samples.add(i);
|
||||
}
|
||||
} else {
|
||||
int interval = totalChunks / sampleCount;
|
||||
for (int i = 0; i < sampleCount; i++) {
|
||||
if (i == sampleCount - 1) {
|
||||
samples.add(totalChunks - 1);
|
||||
} else {
|
||||
samples.add(i * interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析采样点字符串
|
||||
*
|
||||
* @param sampleChunksStr 采样点字符串(逗号分隔)
|
||||
* @return 采样点分片序号列表
|
||||
*/
|
||||
public List<Integer> parseSampleChunks(String sampleChunksStr) {
|
||||
if (StringUtils.isEmpty(sampleChunksStr)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return Arrays.stream(sampleChunksStr.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从已上传的分片中计算采样点哈希
|
||||
* <p>
|
||||
* 计算方式:
|
||||
* 1. 对采样点分片序号进行排序
|
||||
* 2. 逐个计算每个采样分片的 MD5 值
|
||||
* 3. 将所有 MD5 值拼接成一个字符串
|
||||
* 4. 计算拼接字符串的 MD5 值作为最终签名
|
||||
*
|
||||
* @param tempPath 临时文件路径
|
||||
* @param sampleChunks 采样点分片序号列表
|
||||
* @return 采样点哈希值
|
||||
*/
|
||||
public String calculateSampleHashFromChunks(String tempPath, List<Integer> sampleChunks) {
|
||||
// 1. 对采样点排序
|
||||
Collections.sort(sampleChunks);
|
||||
|
||||
// 2. 逐个计算每个采样分片的 MD5
|
||||
StringBuilder md5Concat = new StringBuilder();
|
||||
for (Integer chunkNumber : sampleChunks) {
|
||||
String chunkPath = getChunkFilePath(tempPath, chunkNumber);
|
||||
File chunkFile = new File(chunkPath);
|
||||
if (!chunkFile.exists()) {
|
||||
throw new ServiceException("采样分片不存在: " + chunkNumber);
|
||||
}
|
||||
String chunkMd5 = Md5Utils.calculateMd5(chunkFile);
|
||||
md5Concat.append(chunkMd5);
|
||||
}
|
||||
|
||||
// 3. 计算拼接后的 MD5 值作为最终签名
|
||||
return Md5Utils.calculateMd5(md5Concat.toString().getBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验文件哈希
|
||||
*
|
||||
* @param filePath 合并后的文件路径
|
||||
* @param session 上传会话
|
||||
* @throws ServiceException 校验失败时抛出异常
|
||||
*/
|
||||
private void validateFullFileHash(String filePath, FileUploadSession session) {
|
||||
File mergedFile = new File(filePath);
|
||||
String hashType = session.getHashType();
|
||||
String expectedHash = session.getFileSignature();
|
||||
|
||||
if ("FULL".equals(hashType) || hashType == null) {
|
||||
String actualMd5 = Md5Utils.calculateMd5(mergedFile);
|
||||
if (!actualMd5.equalsIgnoreCase(expectedHash)) {
|
||||
mergedFile.delete();
|
||||
throw new ServiceException("文件MD5校验失败:期望=" + expectedHash + ",实际=" + actualMd5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
package com.microservices.file.service.impl;
|
||||
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.file.domain.FileUploadChunk;
|
||||
import com.microservices.file.domain.FileUploadSession;
|
||||
import com.microservices.file.mapper.FileUploadChunkMapper;
|
||||
import com.microservices.file.mapper.FileUploadSessionMapper;
|
||||
import com.microservices.file.service.IChunkedUploadService;
|
||||
import com.microservices.file.service.IFileCommonAsyncService;
|
||||
import com.microservices.file.service.ISysFileInfoService;
|
||||
import com.microservices.file.utils.CustomExecutorFactory;
|
||||
import com.microservices.file.utils.Md5Utils;
|
||||
import com.microservices.system.api.domain.SysFileInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件Service业务层处理
|
||||
*
|
||||
* @author otto
|
||||
*/
|
||||
@Service
|
||||
public class FileCommonAsyncServiceImpl implements IFileCommonAsyncService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FileCommonAsyncServiceImpl.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private FileUploadSessionMapper sessionMapper;
|
||||
|
||||
@Autowired
|
||||
private FileUploadChunkMapper chunkMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysFileInfoService fileInfoService;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private IChunkedUploadService chunkedUploadService;
|
||||
|
||||
public void executeMergeAsync(String uploadId) {
|
||||
CustomExecutorFactory.threadPoolExecutor.execute(() -> {
|
||||
FileUploadSession session = null;
|
||||
try {
|
||||
// 1. 获取会话
|
||||
session = sessionMapper.selectByUploadId(uploadId);
|
||||
if (session == null) {
|
||||
logger.error("合并任务失败:会话不存在, uploadId={}", uploadId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 状态校验
|
||||
if (!FileUploadSession.Status.MERGING.getCode().equals(session.getStatus())) {
|
||||
logger.warn("合并任务跳过:状态不是MERGING, uploadId={}, status={}",
|
||||
uploadId, session.getStatus());
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 检查所有分片是否已上传
|
||||
int uploadedCount = chunkMapper.countUploadedChunks(uploadId);
|
||||
if (uploadedCount < session.getTotalChunks()) {
|
||||
throw new ServiceException("还有分片未上传,无法合并");
|
||||
}
|
||||
// 4. 哈希校验(SAMPLE类型进行前置哈希校验,FULL类型进行合并后校验)
|
||||
validateSampleFileHash( session);
|
||||
|
||||
// 5. 执行合并
|
||||
SysFileInfo fileInfo = fileInfoService.uploadChunkedFile(session, session.getUploadType(), session.getHierarchy());
|
||||
|
||||
|
||||
// // 6. 保存文件
|
||||
// MultipartFile mergedMultipartFile = createMultipartFile(
|
||||
// new File(mergedFilePath), session.getFileName());
|
||||
// SysFileInfo fileInfo = fileInfoService.upload(
|
||||
// mergedMultipartFile, session.getUploadType(), session.getHierarchy());
|
||||
|
||||
// 7. 更新会话状态
|
||||
session.setStatus(FileUploadSession.Status.COMPLETED.getCode());
|
||||
session.setFileId(fileInfo.getFileId());
|
||||
sessionMapper.updateSession(session);
|
||||
|
||||
// 8. 更新分片状态
|
||||
chunkMapper.updateStatusByUploadId(uploadId,
|
||||
FileUploadChunk.Status.MERGED.getCode());
|
||||
|
||||
// 9. 清理临时文件
|
||||
cleanupTempFilesAsync(session);
|
||||
|
||||
logger.info("文件合并成功: uploadId={}, fileId={}", uploadId, fileInfo.getFileId());
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("文件合并失败: uploadId={}", uploadId, e);
|
||||
|
||||
// 更新状态为合并失败
|
||||
if (session != null) {
|
||||
session.setStatus(FileUploadSession.Status.MERGE_FAILED.getCode());
|
||||
session.setErrorMessage(e.getMessage());
|
||||
sessionMapper.updateSession(session);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步清理临时文件
|
||||
*/
|
||||
private void cleanupTempFilesAsync(FileUploadSession session) {
|
||||
new Thread(() -> chunkedUploadService.cleanupTempFiles(session)).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验文件哈希
|
||||
*
|
||||
* @param session 上传会话
|
||||
* @throws ServiceException 校验失败时抛出异常
|
||||
*/
|
||||
private void validateSampleFileHash(FileUploadSession session) {
|
||||
String hashType = session.getHashType();
|
||||
String expectedHash = session.getFileSignature();
|
||||
|
||||
if ("SAMPLE".equals(hashType)) {
|
||||
List<Integer> sampleChunks = chunkedUploadService.parseSampleChunks(session.getSampleChunks());
|
||||
String actualSampleHash = chunkedUploadService.calculateSampleHashFromChunks(
|
||||
session.getTempFilePath(), sampleChunks);
|
||||
if (!actualSampleHash.equalsIgnoreCase(expectedHash)) {
|
||||
throw new ServiceException("采样点哈希校验失败:期望=" + expectedHash + ",实际=" + actualSampleHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建MultipartFile对象
|
||||
*/
|
||||
private MultipartFile createMultipartFile(File file, String originalFilename) {
|
||||
return new MultipartFile() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "file";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalFilename() {
|
||||
return originalFilename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return file.length() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() throws IOException {
|
||||
return Files.readAllBytes(file.toPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferTo(File dest) throws IOException, IllegalStateException {
|
||||
Files.copy(file.toPath(), dest.toPath());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -17,10 +17,7 @@ import com.microservices.common.httpClient.domain.GitLinkRequestUrl;
|
|||
import com.microservices.common.httpClient.util.GitLinkRequestHelper;
|
||||
import com.microservices.common.redis.service.RedisService;
|
||||
import com.microservices.common.security.utils.SecurityUtils;
|
||||
import com.microservices.file.domain.FileUploadSession;
|
||||
import com.microservices.file.mapper.SysFileInfoMapper;
|
||||
import com.microservices.file.service.IChunkedUploadService;
|
||||
import com.microservices.file.service.IFileCommonAsyncService;
|
||||
import com.microservices.file.service.ISysFileInfoAsyncService;
|
||||
import com.microservices.file.service.ISysFileInfoService;
|
||||
import com.microservices.file.utils.FileUploadUtils;
|
||||
|
|
@ -60,8 +57,6 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
private GitLinkRequestHelper gitLinkRequestHelper;
|
||||
@Autowired
|
||||
private ISysFileInfoAsyncService fileInfoAsyncService;
|
||||
@Autowired
|
||||
private IChunkedUploadService chunkedUploadService;
|
||||
/**
|
||||
* 上传文件存储在本地的根路径
|
||||
*/
|
||||
|
|
@ -96,11 +91,6 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/** 积分异步任务 Redis 队列 Key */
|
||||
private static final String ZONE_POINTS_ASYNC_QUEUE_KEY = "zone:points:async:queue";
|
||||
/** 资源下载积分任务 sourceType */
|
||||
private static final String DOWNLOAD_RESOURCE_SOURCE_TYPE = "downloadResource";
|
||||
|
||||
@Override
|
||||
public SysFileInfo selectSysFileInfoByFileObjectName(String fileObjectName) {
|
||||
return sysFileInfoMapper.selectSysFileInfoByFileObjectName(fileObjectName);
|
||||
|
|
@ -118,12 +108,6 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
if (sysFileInfo == null) {
|
||||
throw new ServiceException("该文件不存在(文件Id[%d])", fileId);
|
||||
}
|
||||
// 设置下载URL
|
||||
if (StringUtils.isNotEmpty(sysFileInfo.getFileIdentifier())) {
|
||||
sysFileInfo.setDownloadUrl(EscapeUtil.removeExtraSlashOfUrl(domain + "/common/downloadByIdentifier/" + sysFileInfo.getFileIdentifier()));
|
||||
} else {
|
||||
sysFileInfo.setDownloadUrl(EscapeUtil.removeExtraSlashOfUrl(domain + "/open/download/" + fileId));
|
||||
}
|
||||
return sysFileInfo;
|
||||
}
|
||||
|
||||
|
|
@ -374,19 +358,8 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
|
||||
@Override
|
||||
public SysFileInfo upload(MultipartFile file, String fileType, String hierarchy) {
|
||||
return commonUpload(false, file, null, fileType, hierarchy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysFileInfo uploadChunkedFile(FileUploadSession session, String fileType, String hierarchy) {
|
||||
return commonUpload(true, null, session, fileType, hierarchy);
|
||||
}
|
||||
|
||||
public SysFileInfo commonUpload(Boolean isChunkedUpload, MultipartFile file, FileUploadSession session, String fileType, String hierarchy) {
|
||||
if (!isChunkedUpload) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new ServiceException("不允许上传空文件");
|
||||
}
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new ServiceException("不允许上传空文件");
|
||||
}
|
||||
SysFileInfo sysFileInfo = new SysFileInfo();
|
||||
// 上传文件路径
|
||||
|
|
@ -406,9 +379,6 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
switch (fileType) {
|
||||
case "pms-gitlink":
|
||||
case "gitlink": {
|
||||
if (isChunkedUpload) {
|
||||
throw new ServiceException("当前平台不支持分片上传");
|
||||
}
|
||||
isLocalUpload = false;
|
||||
JSONObject uploadRes = gitLinkRequestHelper.doPostFile(GitLinkRequestUrl.UPLOAD_ATTACHMENTS(), file);
|
||||
sysFileInfo.setFilePath(uploadRes.getString("title"));
|
||||
|
|
@ -463,9 +433,7 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
if (StringUtils.isNotEmpty(cmsAllowedExtension)) {
|
||||
allowedExtensions = cmsAllowedExtension.split(",");
|
||||
}
|
||||
if (!isChunkedUpload) {
|
||||
assertAllowed(file, allowedExtensions);
|
||||
}
|
||||
assertAllowed(file, allowedExtensions);
|
||||
|
||||
baseFilePath += "/" + fileType + "/";
|
||||
isCommonFileType = false;
|
||||
|
|
@ -477,40 +445,13 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
if (StringUtils.isNotEmpty(allowedExtension)) {
|
||||
allowedExtensions = allowedExtension.split(",");
|
||||
}
|
||||
if (!isChunkedUpload) {
|
||||
assertAllowed(file, allowedExtensions);
|
||||
}
|
||||
assertAllowed(file, allowedExtensions);
|
||||
}
|
||||
}
|
||||
|
||||
if (isLocalUpload) {
|
||||
String filePath;
|
||||
|
||||
// 上传并返回新文件名称
|
||||
if (!isChunkedUpload) {
|
||||
filePath = upload(baseFilePath, file);
|
||||
sysFileInfo.setFileSizeInfo(FileUtils.calcFileSize(file.getSize()));
|
||||
sysFileInfo.setFileOriginName(file.getOriginalFilename());
|
||||
// 获取文件内容信息
|
||||
try {
|
||||
ContentInfoUtil util = new ContentInfoUtil();
|
||||
ContentInfo contentInfo = util.findMatch(file.getInputStream());
|
||||
if (contentInfo != null) {
|
||||
sysFileInfo.setContentType(contentInfo.getContentType().name());
|
||||
sysFileInfo.setContentTypeName(contentInfo.getName());
|
||||
sysFileInfo.setContentTypeMessage(contentInfo.getMessage());
|
||||
sysFileInfo.setMimeType(contentInfo.getMimeType());
|
||||
sysFileInfo.setIsPartialMatch(contentInfo.isPartial() ? 1 : 0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("获取文件内容信息出现异常:{0}", e);
|
||||
throw new ServiceException("获取文件内容信息出现异常(文件名[%s])", filePath);
|
||||
}
|
||||
} else {
|
||||
filePath = chunkedUploadService.mergeChunkFiles(baseFilePath, session);
|
||||
sysFileInfo.setFileSizeInfo(FileUtils.calcFileSize(session.getFileSize()));
|
||||
sysFileInfo.setFileOriginName(session.getFileName());
|
||||
}
|
||||
String filePath = upload(baseFilePath, file);
|
||||
if (!isCommonFileType) {
|
||||
if ("pms".equals(fileType)) {
|
||||
filePath = EscapeUtil.removeExtraSlashOfUrl("/" + fileType + "/" + hierarchy + "/" + filePath);
|
||||
|
|
@ -526,6 +467,23 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
sysFileInfo.setFileObjectName(newFileName);
|
||||
sysFileInfo.setFileSuffix(newFileName.substring(separatorIndex + 1).toLowerCase());
|
||||
|
||||
sysFileInfo.setFileSizeInfo(FileUtils.calcFileSize(file.getSize()));
|
||||
// 获取文件内容信息
|
||||
try {
|
||||
ContentInfoUtil util = new ContentInfoUtil();
|
||||
ContentInfo contentInfo = util.findMatch(file.getInputStream());
|
||||
if (contentInfo != null) {
|
||||
sysFileInfo.setContentType(contentInfo.getContentType().name());
|
||||
sysFileInfo.setContentTypeName(contentInfo.getName());
|
||||
sysFileInfo.setContentTypeMessage(contentInfo.getMessage());
|
||||
sysFileInfo.setMimeType(contentInfo.getMimeType());
|
||||
sysFileInfo.setIsPartialMatch(contentInfo.isPartial() ? 1 : 0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("获取文件内容信息出现异常:{0}", e);
|
||||
throw new ServiceException("获取文件内容信息出现异常(文件名[%s])", filePath);
|
||||
}
|
||||
sysFileInfo.setFileOriginName(file.getOriginalFilename());
|
||||
sysFileInfo.setDelFlag("N");
|
||||
insertSysFileInfo(sysFileInfo);
|
||||
fileId = sysFileInfo.getFileId();
|
||||
|
|
@ -621,15 +579,6 @@ public class SysFileInfoServiceImpl implements ISysFileInfoService {
|
|||
sysFileInfo.setDownloadCount(downloadCount);
|
||||
updateSysFileInfo(sysFileInfo);
|
||||
|
||||
// 触发资源下载积分任务(直接写入 Redis 异步队列)
|
||||
try {
|
||||
JSONObject task = new JSONObject();
|
||||
task.put("sourceType", DOWNLOAD_RESOURCE_SOURCE_TYPE);
|
||||
task.put("sourceId", sysFileInfo.getFileId());
|
||||
redisService.leftPush(ZONE_POINTS_ASYNC_QUEUE_KEY, JSONObject.toJSONString(task));
|
||||
} catch (Exception e) {
|
||||
logger.warn("触发资源下载积分任务失败 fileId={} error={}", sysFileInfo.getFileId(), e.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("文件下载异常:%s", e.getMessage());
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue