页面各种功能接口

This commit is contained in:
2026-04-29 18:19:58 +08:00
parent 0440330226
commit 70aa383c9c
13 changed files with 479 additions and 12 deletions

11
pom.xml
View File

@@ -77,6 +77,17 @@
<artifactId>hutool-all</artifactId>
<version>5.8.25</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.5</version>
</dependency>
<!-- FastJSON2 最新稳定版 -->
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.32</version>
</dependency>
</dependencies>
<build>

View File

@@ -1,9 +1,11 @@
package com.bim.api;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.bim.api.mapper")
public class BimApiApplication {
public static void main(String[] args) {

View File

@@ -1,5 +1,6 @@
package com.bim.api.controller;
import com.bim.api.entity.ActAmtResponse;
import com.bim.api.entity.PjDayListResponse;
import com.bim.api.entity.WbsResponse;
import com.bim.api.query.ProjectProgressParams;
@@ -61,4 +62,29 @@ public class BimController {
}
return result;
}
@PostMapping("/findActAmtByPositiond")
public Map<String, Object> findActAmtByPositionId(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
String projectId = (String) params.get("projectId");
String positionId = (String) params.get("positionId");
String period = (String) params.get("period");
ActAmtResponse response = authUtil.findActAmtByPositionId(projectId, positionId, period);
if ("0".equals(response.getCode())) {
result.put("code", 200);
result.put("message", "success");
result.put("data", response);
} else {
result.put("code", 500);
result.put("message", response.getMsg());
}
} catch (Exception e) {
result.put("code", 500);
result.put("message", e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,127 @@
package com.bim.api.controller;
import com.bim.api.entity.PartCodeRelation;
import com.bim.api.service.PartCodeRelationService;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/partCode")
public class PartCodeController {
private final PartCodeRelationService service;
public PartCodeController(PartCodeRelationService service) {
this.service = service;
}
@GetMapping("/byPart/{partId}")
@ResponseBody
public Map<String, Object> getByPartId(@PathVariable String partId) {
Map<String, Object> result = new HashMap<>();
try {
List<PartCodeRelation> list = service.findByPartId(partId);
result.put("code", 200);
result.put("data", list);
} catch (Exception e) {
result.put("code", 500);
result.put("message", e.getMessage());
}
return result;
}
@GetMapping("/byCode/{codeId}")
@ResponseBody
public Map<String, Object> getByCodeId(@PathVariable String codeId) {
Map<String, Object> result = new HashMap<>();
try {
Map<String, Object> list = service.findByCodeId(codeId);
result.put("code", 200);
result.put("data", list);
} 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) {
Map<String, Object> result = new HashMap<>();
try {
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);
}
// 从partInfos中提取id和createDate
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");
}
// 从codeInfos中提取code和data
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.saveBatchWithData(partIds, codeIds, codeDatas, createDates);
result.put("code", 200);
result.put("data", list);
} catch (Exception e) {
e.printStackTrace();
result.put("code", 500);
result.put("message", e.getMessage());
}
return result;
}
@DeleteMapping("/batch")
@ResponseBody
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);
result.put("code", 200);
} catch (Exception e) {
result.put("code", 500);
result.put("message", e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,27 @@
package com.bim.api.entity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import java.util.List;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ActAmtResponse {
private String msg;
private String code;
private List<ActAmtData> data;
private Integer count;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class ActAmtData {
private Boolean isNewRecord;
private String positionId;
private String positionName;
private Double meteringAmt;
private Double meteringNotaxAmt;
private Double actAmt;
private Double actNotaxAmt;
}
}

View File

@@ -0,0 +1,23 @@
package com.bim.api.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("part_code_relation")
public class PartCodeRelation {
@TableId(type = IdType.AUTO)
private Long id;
private String partId;
private String codeId;
private String codeData;
private String createDate;
private LocalDateTime createTime;
}

View File

@@ -25,6 +25,11 @@ public class PjDayListResponse {
private Double meteringAmt;
private Double meteringNotaxAmt;
private Double meteringNum;
private Double totalNum;
private Double totalAmt;
private Double totalNotaxAmt;
private Double thisNum;
private Double thisAmt;
private String name;
}
}

View File

@@ -0,0 +1,9 @@
package com.bim.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bim.api.entity.PartCodeRelation;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PartCodeRelationMapper extends BaseMapper<PartCodeRelation> {
}

View File

@@ -0,0 +1,206 @@
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class PartCodeRelationService extends ServiceImpl<PartCodeRelationMapper, PartCodeRelation> {
private final ThirdPartyAuthUtil thirdPartyAuthUtil;
private static final String PROJECT_ID = "5e4bde33ec084f1a8673eb59b190dce7";
public PartCodeRelationService(ThirdPartyAuthUtil thirdPartyAuthUtil) {
this.thirdPartyAuthUtil = thirdPartyAuthUtil;
}
public List<PartCodeRelation> findByPartId(String partId) {
return list(new LambdaQueryWrapper<PartCodeRelation>().eq(PartCodeRelation::getPartId, partId));
}
public Map<String, Object> findByCodeId(String codeId) {
Map<String, Object> result = new HashMap<>();
List<PartCodeRelation> relations = list(new LambdaQueryWrapper<PartCodeRelation>().eq(PartCodeRelation::getCodeId, codeId));
if (relations.isEmpty()) {
result.put("code", 200);
result.put("data", List.of());
return result;
}
List<Map<String, Object>> pjDayDataList = new ArrayList<>();
for (PartCodeRelation relation : relations) {
String partId = relation.getPartId();
String codeData = relation.getCodeData();
LocalDateTime createTime = relation.getCreateTime();
String period = createTime != null ? createTime.toString().replace("T", " ") : null;
try {
ProjectProgressParams params = new ProjectProgressParams();
params.setProjectId(PROJECT_ID);
params.setPositionIds(partId);
params.setPeriod(period);
PjDayListResponse pjDayResponse = thirdPartyAuthUtil.findPjDayListByPositionId(params);
Map<String, Object> pjDayMap = new HashMap<>();
pjDayMap.put("partId", partId);
pjDayMap.put("createDate", period);
pjDayMap.put("codeData", codeData);
pjDayMap.put("pjDayData", pjDayResponse.getData());
pjDayDataList.add(pjDayMap);
} catch (Exception e) {
Map<String, Object> errorMap = new HashMap<>();
errorMap.put("partId", partId);
errorMap.put("error", e.getMessage());
pjDayDataList.add(errorMap);
}
}
result.put("code", 200);
result.put("data", pjDayDataList);
return result;
}
@Transactional
public List<PartCodeRelation> saveOneToMany(String partId, String[] codeIds) {
List<PartCodeRelation> result = new ArrayList<>();
for (String codeId : codeIds) {
long count = count(new LambdaQueryWrapper<PartCodeRelation>()
.eq(PartCodeRelation::getPartId, partId)
.eq(PartCodeRelation::getCodeId, codeId));
if (count == 0) {
PartCodeRelation relation = new PartCodeRelation();
relation.setPartId(partId);
relation.setCodeId(codeId);
relation.setCreateTime(LocalDateTime.now());
save(relation);
result.add(relation);
}
}
return result;
}
@Transactional
public List<PartCodeRelation> saveManyToOne(String[] partIds, String codeId) {
List<PartCodeRelation> result = new ArrayList<>();
for (String partId : partIds) {
long count = count(new LambdaQueryWrapper<PartCodeRelation>()
.eq(PartCodeRelation::getPartId, partId)
.eq(PartCodeRelation::getCodeId, codeId));
if (count == 0) {
PartCodeRelation relation = new PartCodeRelation();
relation.setPartId(partId);
relation.setCodeId(codeId);
relation.setCreateTime(LocalDateTime.now());
save(relation);
result.add(relation);
}
}
return result;
}
@Transactional
public void deleteOneToMany(String partId, String[] codeIds) {
for (String codeId : codeIds) {
remove(new LambdaQueryWrapper<PartCodeRelation>()
.eq(PartCodeRelation::getPartId, partId)
.eq(PartCodeRelation::getCodeId, codeId));
}
}
@Transactional
public void deleteManyToOne(String[] partIds, String codeId) {
for (String partId : partIds) {
remove(new LambdaQueryWrapper<PartCodeRelation>()
.eq(PartCodeRelation::getPartId, partId)
.eq(PartCodeRelation::getCodeId, codeId));
}
}
@Transactional
public List<PartCodeRelation> saveBatch(String[] partIds, String[] codeIds) {
List<PartCodeRelation> result = new ArrayList<>();
for (String partId : partIds) {
for (String codeId : codeIds) {
long count = count(new LambdaQueryWrapper<PartCodeRelation>()
.eq(PartCodeRelation::getPartId, partId)
.eq(PartCodeRelation::getCodeId, codeId));
if (count == 0) {
PartCodeRelation relation = new PartCodeRelation();
relation.setPartId(partId);
relation.setCodeId(codeId);
relation.setCreateTime(LocalDateTime.now());
save(relation);
result.add(relation);
}
}
}
return result;
}
@Transactional
public List<PartCodeRelation> saveBatchWithData(String[] partIds, String[] codeIds, String[] codeDatas) {
return saveBatchWithData(partIds, codeIds, codeDatas, null);
}
@Transactional
public List<PartCodeRelation> saveBatchWithData(String[] partIds, String[] codeIds, String[] codeDatas, String[] createDates) {
List<PartCodeRelation> result = new ArrayList<>();
for (int i = 0; i < codeIds.length; i++) {
String codeId = codeIds[i];
String codeData = codeDatas[i];
for (int j = 0; j < partIds.length; j++) {
String partId = partIds[j];
long cnt = count(new LambdaQueryWrapper<PartCodeRelation>()
.eq(PartCodeRelation::getPartId, partId)
.eq(PartCodeRelation::getCodeId, codeId));
if (cnt == 0) {
PartCodeRelation relation = new PartCodeRelation();
relation.setPartId(partId);
relation.setCodeId(codeId);
relation.setCodeData(codeData);
relation.setCreateTime(LocalDateTime.now());
if (createDates != null && createDates[j] != null && !createDates[j].isEmpty()) {
relation.setCreateDate(createDates[j].replaceAll("^(\\d{4}-\\d{2}-\\d{2}).*", "$1"));
} else {
relation.setCreateDate("");
}
save(relation);
result.add(relation);
}
}
}
return result;
}
@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]));
}
for (String codeId : codeIds) {
PartCodeRelation relation = new PartCodeRelation();
relation.setPartId(partIds[0]);
relation.setCodeId(codeId);
relation.setCreateTime(LocalDateTime.now());
save(relation);
}
}
}

View File

@@ -4,9 +4,7 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.bim.api.entity.*;
import com.bim.api.query.ProjectProgressParams;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@@ -190,4 +188,31 @@ public class ThirdPartyAuthUtil {
return objectMapper.readValue(responseBody, PjDayListResponse.class);
}
public ActAmtResponse findActAmtByPositionId(String projectId, String positionId, String period) throws Exception {
String accessToken = getAccessToken();
String url = baseUrl + "/bim/bimPjData/findActAmtByPositiond?access_token=" + accessToken;
Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("projectId", projectId);
bodyMap.put("positionId", positionId);
String p = period;
if (p != null) {
p = p.replaceAll("^(\\d{4}-\\d{2}-\\d{2}).*", "$1");
}
bodyMap.put("period", p);
String body = objectMapper.writeValueAsString(bodyMap);
HttpResponse httpResponse = HttpRequest.post(url)
.body(body)
.execute();
String responseBody = httpResponse.body();
log.info("获取实际产值响应: {}", responseBody);
return objectMapper.readValue(responseBody, ActAmtResponse.class);
}
}

View File

@@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/bim_dev?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
url: jdbc:mysql://localhost:3306/bim_project?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
username: root
password: root
data:
@@ -9,6 +9,10 @@ spring:
port: 6379
database: 0
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
third-party:
api:
base-url: https://uat-xmgl.ccccltd.cn/a

View File

@@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306/bim_prod?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
url: jdbc:mysql://localhost:3306/bim_project?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
username: root
password: root
data:

View File

@@ -15,18 +15,20 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
format_sql: true
ddl-auto: none
show-sql: false
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
type-aliases-package: com.bim.api.entity
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
logging:
level:
com.bim.api: debug
org.hibernate.SQL: debug