1\页面各种功能接口

This commit is contained in:
2026-05-06 10:45:44 +08:00
parent 70aa383c9c
commit f50dd02b7b
4 changed files with 291 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ import com.bim.api.entity.ActAmtResponse;
import com.bim.api.entity.PjDayListResponse;
import com.bim.api.entity.WbsResponse;
import com.bim.api.query.ProjectProgressParams;
import com.bim.api.service.ProgressDataService;
import com.bim.api.util.ThirdPartyAuthUtil;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
@@ -16,9 +17,11 @@ import java.util.Map;
public class BimController {
private final ThirdPartyAuthUtil authUtil;
private final ProgressDataService progressDataService;
public BimController(ThirdPartyAuthUtil authUtil) {
public BimController(ThirdPartyAuthUtil authUtil, ProgressDataService progressDataService) {
this.authUtil = authUtil;
this.progressDataService = progressDataService;
}
@GetMapping("/wbs")
@@ -43,6 +46,16 @@ public class BimController {
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")
public Map<String, Object> getPjDayListByPositionId(@Valid @RequestBody ProjectProgressParams progressParams) {
Map<String, Object> result = new HashMap<>();
@@ -63,6 +76,7 @@ public class BimController {
return result;
}
@PostMapping("/findActAmtByPositiond")
public Map<String, Object> findActAmtByPositionId(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
@@ -86,5 +100,4 @@ public class BimController {
}
return result;
}
}

View File

@@ -48,6 +48,20 @@ public class PartCodeController {
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")
@ResponseBody
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) {
Map<String, Object> result = new HashMap<>();
try {
List<String> partIdsList = (List<String>) params.get("partIds");
List<String> codeIdsList = (List<String>) params.get("codeIds");
String[] partIds = partIdsList.toArray(new String[0]);
String[] codeIds = codeIdsList.toArray(new String[0]);
service.deleteBatch(partIds, codeIds);
Object partIdsObj = params.get("partIds");
Object codeIdsObj = params.get("codeIds");
if (partIdsObj == null || codeIdsObj == null) {
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("data", list);
} catch (Exception e) {
result.put("code", 500);
result.put("message", e.getMessage());
}
return result;
}
}
}

View File

@@ -12,9 +12,13 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Service
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));
}
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) {
Map<String, Object> result = new HashMap<>();
@@ -188,19 +217,14 @@ public class PartCodeRelationService extends ServiceImpl<PartCodeRelationMapper,
}
@Transactional
public void deleteBatch(String[] partIds, String[] codeIds) {
long count = count(new LambdaQueryWrapper<PartCodeRelation>()
.eq(PartCodeRelation::getPartId, partIds[0]));
if (count !=0 ) {
remove(new LambdaQueryWrapper<PartCodeRelation>()
.eq(PartCodeRelation::getPartId, partIds[0]));
public List<PartCodeRelation> deleteBatch(String[] partIds, String[] codeIds, String[] codeDatas, String[] createDates) {
if (partIds == null || partIds.length == 0) {
return List.of();
}
for (String codeId : codeIds) {
PartCodeRelation relation = new PartCodeRelation();
relation.setPartId(partIds[0]);
relation.setCodeId(codeId);
relation.setCreateTime(LocalDateTime.now());
save(relation);
}
remove(new LambdaQueryWrapper<PartCodeRelation>()
.in(PartCodeRelation::getPartId, Arrays.asList(partIds)));
return saveBatchWithData(partIds, codeIds, codeDatas, createDates);
}
}
}

View 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();
}
}