1\页面各种功能接口
This commit is contained in:
@@ -4,6 +4,7 @@ import com.bim.api.entity.ActAmtResponse;
|
|||||||
import com.bim.api.entity.PjDayListResponse;
|
import com.bim.api.entity.PjDayListResponse;
|
||||||
import com.bim.api.entity.WbsResponse;
|
import com.bim.api.entity.WbsResponse;
|
||||||
import com.bim.api.query.ProjectProgressParams;
|
import com.bim.api.query.ProjectProgressParams;
|
||||||
|
import com.bim.api.service.ProgressDataService;
|
||||||
import com.bim.api.util.ThirdPartyAuthUtil;
|
import com.bim.api.util.ThirdPartyAuthUtil;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -16,9 +17,11 @@ import java.util.Map;
|
|||||||
public class BimController {
|
public class BimController {
|
||||||
|
|
||||||
private final ThirdPartyAuthUtil authUtil;
|
private final ThirdPartyAuthUtil authUtil;
|
||||||
|
private final ProgressDataService progressDataService;
|
||||||
|
|
||||||
public BimController(ThirdPartyAuthUtil authUtil) {
|
public BimController(ThirdPartyAuthUtil authUtil, ProgressDataService progressDataService) {
|
||||||
this.authUtil = authUtil;
|
this.authUtil = authUtil;
|
||||||
|
this.progressDataService = progressDataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/wbs")
|
@GetMapping("/wbs")
|
||||||
@@ -43,6 +46,16 @@ public class BimController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/progressData")
|
||||||
|
public Map<String, Object> getProgressData() {
|
||||||
|
return progressDataService.getOrCreateTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/progressData/{taskId}")
|
||||||
|
public Map<String, Object> getProgressDataResult(@PathVariable String taskId) {
|
||||||
|
return progressDataService.getTaskResult(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/getPjDayListByPositionId")
|
@PostMapping("/getPjDayListByPositionId")
|
||||||
public Map<String, Object> getPjDayListByPositionId(@Valid @RequestBody ProjectProgressParams progressParams) {
|
public Map<String, Object> getPjDayListByPositionId(@Valid @RequestBody ProjectProgressParams progressParams) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
@@ -63,6 +76,7 @@ public class BimController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/findActAmtByPositiond")
|
@PostMapping("/findActAmtByPositiond")
|
||||||
public Map<String, Object> findActAmtByPositionId(@RequestBody Map<String, Object> params) {
|
public Map<String, Object> findActAmtByPositionId(@RequestBody Map<String, Object> params) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
@@ -86,5 +100,4 @@ public class BimController {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,20 @@ public class PartCodeController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/codeWbsMappings")
|
||||||
|
@ResponseBody
|
||||||
|
public Map<String, Object> getCodeWbsMappings() {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
result.put("code", 200);
|
||||||
|
result.put("data", service.findCodeWbsMappings());
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("code", 500);
|
||||||
|
result.put("message", e.getMessage());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/batch")
|
@PostMapping("/batch")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Map<String, Object> saveBatch(@RequestBody Map<String, Object> params) {
|
public Map<String, Object> saveBatch(@RequestBody Map<String, Object> params) {
|
||||||
@@ -112,16 +126,54 @@ public class PartCodeController {
|
|||||||
public Map<String, Object> deleteBatch(@RequestBody Map<String, Object> params) {
|
public Map<String, Object> deleteBatch(@RequestBody Map<String, Object> params) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
List<String> partIdsList = (List<String>) params.get("partIds");
|
Object partIdsObj = params.get("partIds");
|
||||||
List<String> codeIdsList = (List<String>) params.get("codeIds");
|
Object codeIdsObj = params.get("codeIds");
|
||||||
String[] partIds = partIdsList.toArray(new String[0]);
|
|
||||||
String[] codeIds = codeIdsList.toArray(new String[0]);
|
if (partIdsObj == null || codeIdsObj == null) {
|
||||||
service.deleteBatch(partIds, codeIds);
|
result.put("code", 500);
|
||||||
|
result.put("message", "鍙傛暟涓嶈兘涓虹┖");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<String, Object>> partInfoList;
|
||||||
|
List<Map<String, Object>> codeInfoList;
|
||||||
|
|
||||||
|
if (partIdsObj instanceof List) {
|
||||||
|
partInfoList = (List<Map<String, Object>>) partIdsObj;
|
||||||
|
} else {
|
||||||
|
partInfoList = List.of((Map<String, Object>) partIdsObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codeIdsObj instanceof List) {
|
||||||
|
codeInfoList = (List<Map<String, Object>>) codeIdsObj;
|
||||||
|
} else {
|
||||||
|
codeInfoList = List.of((Map<String, Object>) codeIdsObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] partIds = new String[partInfoList.size()];
|
||||||
|
String[] createDates = new String[partInfoList.size()];
|
||||||
|
for (int i = 0; i < partInfoList.size(); i++) {
|
||||||
|
Map<String, Object> partInfo = partInfoList.get(i);
|
||||||
|
partIds[i] = (String) partInfo.get("id");
|
||||||
|
createDates[i] = (String) partInfo.get("createDate");
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] codeIds = new String[codeInfoList.size()];
|
||||||
|
String[] codeDatas = new String[codeInfoList.size()];
|
||||||
|
for (int i = 0; i < codeInfoList.size(); i++) {
|
||||||
|
Map<String, Object> codeInfo = codeInfoList.get(i);
|
||||||
|
codeIds[i] = (String) codeInfo.get("code");
|
||||||
|
Map<String, Object> data = (Map<String, Object>) codeInfo.get("data");
|
||||||
|
codeDatas[i] = data != null ? data.toString() : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PartCodeRelation> list = service.deleteBatch(partIds, codeIds, codeDatas, createDates);
|
||||||
result.put("code", 200);
|
result.put("code", 200);
|
||||||
|
result.put("data", list);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result.put("code", 500);
|
result.put("code", 500);
|
||||||
result.put("message", e.getMessage());
|
result.put("message", e.getMessage());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PartCodeRelationService extends ServiceImpl<PartCodeRelationMapper, PartCodeRelation> {
|
public class PartCodeRelationService extends ServiceImpl<PartCodeRelationMapper, PartCodeRelation> {
|
||||||
@@ -31,6 +35,31 @@ public class PartCodeRelationService extends ServiceImpl<PartCodeRelationMapper,
|
|||||||
return list(new LambdaQueryWrapper<PartCodeRelation>().eq(PartCodeRelation::getPartId, partId));
|
return list(new LambdaQueryWrapper<PartCodeRelation>().eq(PartCodeRelation::getPartId, partId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Map<String, String>> findCodeWbsMappings() {
|
||||||
|
List<PartCodeRelation> relations = list(new LambdaQueryWrapper<PartCodeRelation>()
|
||||||
|
.orderByAsc(PartCodeRelation::getCodeId)
|
||||||
|
.orderByAsc(PartCodeRelation::getId));
|
||||||
|
|
||||||
|
Map<String, Set<String>> grouped = new LinkedHashMap<>();
|
||||||
|
for (PartCodeRelation relation : relations) {
|
||||||
|
String codeId = relation.getCodeId();
|
||||||
|
String partId = relation.getPartId();
|
||||||
|
if (codeId == null || codeId.isBlank() || partId == null || partId.isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
grouped.computeIfAbsent(codeId, key -> new LinkedHashSet<>()).add(partId);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Map<String, String>> result = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, Set<String>> entry : grouped.entrySet()) {
|
||||||
|
Map<String, String> item = new LinkedHashMap<>();
|
||||||
|
item.put("id", entry.getKey());
|
||||||
|
item.put("wbsCode", String.join(",", entry.getValue()));
|
||||||
|
result.add(item);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Object> findByCodeId(String codeId) {
|
public Map<String, Object> findByCodeId(String codeId) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
@@ -188,19 +217,14 @@ public class PartCodeRelationService extends ServiceImpl<PartCodeRelationMapper,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deleteBatch(String[] partIds, String[] codeIds) {
|
public List<PartCodeRelation> deleteBatch(String[] partIds, String[] codeIds, String[] codeDatas, String[] createDates) {
|
||||||
long count = count(new LambdaQueryWrapper<PartCodeRelation>()
|
if (partIds == null || partIds.length == 0) {
|
||||||
.eq(PartCodeRelation::getPartId, partIds[0]));
|
return List.of();
|
||||||
if (count !=0 ) {
|
|
||||||
remove(new LambdaQueryWrapper<PartCodeRelation>()
|
|
||||||
.eq(PartCodeRelation::getPartId, partIds[0]));
|
|
||||||
}
|
}
|
||||||
for (String codeId : codeIds) {
|
|
||||||
PartCodeRelation relation = new PartCodeRelation();
|
remove(new LambdaQueryWrapper<PartCodeRelation>()
|
||||||
relation.setPartId(partIds[0]);
|
.in(PartCodeRelation::getPartId, Arrays.asList(partIds)));
|
||||||
relation.setCodeId(codeId);
|
|
||||||
relation.setCreateTime(LocalDateTime.now());
|
return saveBatchWithData(partIds, codeIds, codeDatas, createDates);
|
||||||
save(relation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
180
src/main/java/com/bim/api/service/ProgressDataService.java
Normal file
180
src/main/java/com/bim/api/service/ProgressDataService.java
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
package com.bim.api.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.bim.api.entity.PartCodeRelation;
|
||||||
|
import com.bim.api.entity.PjDayListResponse;
|
||||||
|
import com.bim.api.query.ProjectProgressParams;
|
||||||
|
import com.bim.api.mapper.PartCodeRelationMapper;
|
||||||
|
import com.bim.api.util.ThirdPartyAuthUtil;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ProgressDataService extends ServiceImpl<PartCodeRelationMapper, PartCodeRelation> {
|
||||||
|
|
||||||
|
private static final String PROJECT_ID = "5e4bde33ec084f1a8673eb59b190dce7";
|
||||||
|
|
||||||
|
private static final String KEY_TASK_STATUS = "progress:task:";
|
||||||
|
private static final String KEY_TASK_TOTAL = ":total";
|
||||||
|
private static final String KEY_TASK_CURRENT = ":current";
|
||||||
|
private static final String KEY_TASK_RESULT = ":result";
|
||||||
|
private static final String KEY_PROCESSING = "progress:processing";
|
||||||
|
private static final String KEY_COMPLETED = "progress:completed";
|
||||||
|
private static final String KEY_LATEST_TASK = "progress:latest:taskId";
|
||||||
|
|
||||||
|
private static final Map<String, String> TASK_STATUS_CACHE = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private final ThirdPartyAuthUtil thirdPartyAuthUtil;
|
||||||
|
private final RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
public ProgressDataService(ThirdPartyAuthUtil thirdPartyAuthUtil, RedisTemplate<String, Object> redisTemplate) {
|
||||||
|
this.thirdPartyAuthUtil = thirdPartyAuthUtil;
|
||||||
|
this.redisTemplate = redisTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getOrCreateTask() {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
String latestTaskId = (String) redisTemplate.opsForValue().get(KEY_LATEST_TASK);
|
||||||
|
if (latestTaskId != null) {
|
||||||
|
String status = getTaskStatus(latestTaskId);
|
||||||
|
if ("COMPLETED".equals(status)) {
|
||||||
|
result.put("taskId", latestTaskId);
|
||||||
|
result.put("status", "COMPLETED");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String processingTaskId = (String) redisTemplate.opsForValue().get(KEY_PROCESSING);
|
||||||
|
if (processingTaskId != null) {
|
||||||
|
result.put("taskId", processingTaskId);
|
||||||
|
result.put("status", "PROCESSING");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String taskId = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
initTask(taskId);
|
||||||
|
calculateProgressAsync(taskId);
|
||||||
|
|
||||||
|
result.put("taskId", taskId);
|
||||||
|
result.put("status", "STARTED");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getTaskResult(String taskId) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
String status = getTaskStatus(taskId);
|
||||||
|
result.put("taskId", taskId);
|
||||||
|
result.put("status", status);
|
||||||
|
|
||||||
|
if (status == null) {
|
||||||
|
result.put("status", "NOT_FOUND");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer total = (Integer) redisTemplate.opsForValue().get(KEY_TASK_STATUS + taskId + KEY_TASK_TOTAL);
|
||||||
|
Integer current = (Integer) redisTemplate.opsForValue().get(KEY_TASK_STATUS + taskId + KEY_TASK_CURRENT);
|
||||||
|
|
||||||
|
result.put("total", total != null ? total : 0);
|
||||||
|
result.put("current", current != null ? current : 0);
|
||||||
|
|
||||||
|
double progress = 0;
|
||||||
|
if (total != null && total > 0 && current != null) {
|
||||||
|
progress = (double) current / total;
|
||||||
|
}
|
||||||
|
result.put("progress", progress);
|
||||||
|
|
||||||
|
if ("COMPLETED".equals(status)) {
|
||||||
|
Object data = redisTemplate.opsForValue().get(KEY_TASK_STATUS + taskId + KEY_TASK_RESULT);
|
||||||
|
result.put("data", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTaskStatus(String taskId) {
|
||||||
|
if (taskId == null) return null;
|
||||||
|
return TASK_STATUS_CACHE.get(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTask(String taskId) {
|
||||||
|
TASK_STATUS_CACHE.put(taskId, "STARTED");
|
||||||
|
redisTemplate.opsForValue().set(KEY_PROCESSING, taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateProgressAsync(String taskId) {
|
||||||
|
TASK_STATUS_CACHE.put(taskId, "PROCESSING");
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
List<PartCodeRelation> relations = list();
|
||||||
|
int total = relations.size();
|
||||||
|
|
||||||
|
redisTemplate.opsForValue().set(KEY_TASK_STATUS + taskId + KEY_TASK_TOTAL, total);
|
||||||
|
redisTemplate.opsForValue().set(KEY_TASK_STATUS + taskId + KEY_TASK_CURRENT, 0);
|
||||||
|
|
||||||
|
List<Map<String, Object>> results = new ArrayList<>();
|
||||||
|
|
||||||
|
for (PartCodeRelation relation : relations) {
|
||||||
|
Map<String, Object> item = new HashMap<>();
|
||||||
|
item.put("partId", relation.getPartId());
|
||||||
|
item.put("codeData", relation.getCodeData());
|
||||||
|
|
||||||
|
try {
|
||||||
|
LocalDateTime createTime = relation.getCreateTime();
|
||||||
|
String period = createTime != null ? createTime.toString().replace("T", " ") : null;
|
||||||
|
|
||||||
|
ProjectProgressParams params = new ProjectProgressParams();
|
||||||
|
params.setProjectId(PROJECT_ID);
|
||||||
|
params.setPositionIds(relation.getPartId());
|
||||||
|
params.setPeriod(period);
|
||||||
|
|
||||||
|
PjDayListResponse pjDayResponse = thirdPartyAuthUtil.findPjDayListByPositionId(params);
|
||||||
|
|
||||||
|
double progressData = 0;
|
||||||
|
if (pjDayResponse != null && pjDayResponse.getData() != null && !pjDayResponse.getData().isEmpty()) {
|
||||||
|
PjDayListResponse.PjDayData dayData = pjDayResponse.getData().get(0);
|
||||||
|
Double totalNum = dayData.getMeteringNum();
|
||||||
|
Double meteringNum = dayData.getMeteringAmt();
|
||||||
|
|
||||||
|
if (totalNum != null && meteringNum != null && meteringNum != 0) {
|
||||||
|
progressData = totalNum / meteringNum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.put("progressData", progressData);
|
||||||
|
} catch (Exception e) {
|
||||||
|
item.put("progressData", 0);
|
||||||
|
item.put("error", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
results.add(item);
|
||||||
|
|
||||||
|
Integer current = (Integer) redisTemplate.opsForValue().get(KEY_TASK_STATUS + taskId + KEY_TASK_CURRENT);
|
||||||
|
redisTemplate.opsForValue().set(KEY_TASK_STATUS + taskId + KEY_TASK_CURRENT, current + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
redisTemplate.opsForValue().set(KEY_TASK_STATUS + taskId + KEY_TASK_RESULT, results);
|
||||||
|
redisTemplate.opsForValue().set(KEY_TASK_STATUS + taskId + KEY_TASK_CURRENT, total);
|
||||||
|
|
||||||
|
redisTemplate.delete(KEY_PROCESSING);
|
||||||
|
redisTemplate.opsForValue().set(KEY_COMPLETED, taskId);
|
||||||
|
redisTemplate.opsForValue().set(KEY_LATEST_TASK, taskId);
|
||||||
|
|
||||||
|
TASK_STATUS_CACHE.put(taskId, "COMPLETED");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
TASK_STATUS_CACHE.put(taskId, "FAILED");
|
||||||
|
redisTemplate.delete(KEY_PROCESSING);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user