数据推送

This commit is contained in:
zt
2025-11-06 10:35:04 +08:00
parent dd970d200c
commit a6976aaac4
14 changed files with 507 additions and 119 deletions

View File

@ -4,6 +4,7 @@ import cn.hutool.core.map.MapUtil;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.common.sse.dto.SseMessageDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.io.IOException;
@ -22,7 +23,14 @@ public class SseEmitterManager {
/**
* 订阅的频道
*/
private final static String SSE_TOPIC = "global:sse";
// private final static String SSE_TOPIC = "global:sse";
private static String SSE_TOPIC;
@Value("${spring.data.redis.database:0}")
public void setDatabase(int database) {
SSE_TOPIC = "global:sse:db" + database;
}
private final static Map<Long, Map<String, SseEmitter>> USER_TOKEN_EMITTERS = new ConcurrentHashMap<>();

View File

@ -211,4 +211,9 @@ public class SubConstructionUser extends BaseEntity {
*/
@TableLogic
private String delFlag;
/**
* 公司名称(1-中国电建集团重庆工程有限公司、2-重庆工业设备安装集团有限公司)
*/
private String companyName;
}

View File

@ -12,6 +12,7 @@ import org.dromara.contractor.domain.vo.constructionuserfile.SubConstructionUser
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
/**
* 施工人员文件存储Service接口
@ -78,4 +79,7 @@ public interface ISubConstructionUserFileService extends IService<SubConstructio
*/
LambdaQueryWrapper<SubConstructionUser> buildTemplateQueryWrapper(SubConstructionUserFileTemplateReq req);
Map<String,String> getFileByUserId(Long userId);
}

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
@ -471,4 +472,27 @@ public class SubConstructionUserFileServiceImpl extends ServiceImpl<SubConstruct
return lqw;
}
@Override
public Map<String, String> getFileByUserId(Long userId) {
Map<String, String> resultMap = new HashMap<>();
List<SubConstructionUserFile> subConstructionUserFiles = baseMapper.selectList(Wrappers.<SubConstructionUserFile>lambdaQuery()
.eq(SubConstructionUserFile::getUserId, userId));
Map<String, String> fileMap = subConstructionUserFiles.stream().collect(Collectors.toMap(SubConstructionUserFile::getFileType, SubConstructionUserFile::getPath));
for (String type : fileMap.keySet()) {
String path = fileMap.get(type);
if (StringUtils.isNotBlank(path)) {
//转成Long
List<Long> list = Arrays.stream(path.split(",")).map(Long::valueOf).toList();
SysOssVo sysOssVo = ossService.getById(list.getFirst());
if (sysOssVo == null) {
continue;
}
resultMap.put(type, sysOssVo.getUrl());
}
}
return resultMap;
}
}

View File

@ -6,6 +6,7 @@ import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@ -47,6 +48,7 @@ import org.dromara.contractor.mapper.SubConstructionUserMapper;
import org.dromara.contractor.service.ISubConstructionUserFileService;
import org.dromara.contractor.service.ISubConstructionUserService;
import org.dromara.contractor.service.ISubContractorService;
import org.dromara.dataTransmission.clarityPm.method.ClarityPmAsyncMethod;
import org.dromara.mobileAttendanceMachine.DeviceMessageSender;
import org.dromara.project.domain.*;
import org.dromara.project.domain.enums.BusAttendanceClockStatusEnum;
@ -157,6 +159,9 @@ public class SubConstructionUserServiceImpl extends ServiceImpl<SubConstructionU
private AsyncUtil asyncUtil;
@Resource
private ClarityPmAsyncMethod clarityPmAsyncMethod;
/**
* 查询施工人员
@ -301,6 +306,7 @@ public class SubConstructionUserServiceImpl extends ServiceImpl<SubConstructionU
asyncUtil.sendPersonnel(dto.getTeamId(), constructionUser);
// clarityPmAsyncMethod.transmitUserData(constructionUser.getId());
return i > 0;
}
@ -504,6 +510,8 @@ public class SubConstructionUserServiceImpl extends ServiceImpl<SubConstructionU
sysUser.setUserType(UserType.APP_USER.getUserType());
Long sysUserId = userService.save(sysUser);
constructionUser.setSysUserId(sysUserId);
constructionUser.setCompanyName(String.valueOf(RandomUtil.randomInt(1, 2)));
// 操作数据库
boolean save = this.save(constructionUser);
if (!save) {
@ -1397,6 +1405,7 @@ public class SubConstructionUserServiceImpl extends ServiceImpl<SubConstructionU
throw new ServiceException("当前用户已关联施工人员信息");
}
user.setSysUserId(userId);
user.setCompanyName(String.valueOf(RandomUtil.randomInt(1, 2)));
// 保存施工人员信息
boolean save = this.save(user);
if (!save) {

View File

@ -3,26 +3,17 @@ package org.dromara.dataTransmission;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import org.dromara.common.redis.utils.RedisUtils;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import javax.crypto.Cipher;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.time.Duration;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.HttpHeaders;
import org.dromara.common.redis.utils.RedisUtils;
import org.springframework.stereotype.Component;
import java.io.ByteArrayOutputStream;
@Component
@ -72,21 +63,21 @@ public class TokenUtils {
*/
public static String getToken(String clientId) throws Exception {
// 1. 定义Redis中的Token键名
// String redisKey = "data_auth:token:" + clientId;
//
// // 2. 尝试从Redis获取Token
// String token = RedisUtils.getCacheObject(redisKey);
// if (token != null && !token.isBlank()) {
// // 缓存命中,直接返回
// return token;
// }
String redisKey = "data_auth:token:" + clientId;
// 2. 尝试从Redis获取Token
String token = RedisUtils.getCacheObject(redisKey);
if (token != null && !token.isBlank()) {
// 缓存命中,直接返回
return token;
}
// 3. 缓存未命中调用接口获取Token
Map<String, String> map = tokenMap.get(clientId);
String token = fetchTokenFromApi(clientId,map.get(URL), map.get(USER_NAME), rsaEncrypt(map.get(PASSWORD),map.get(PUBLIC_KEY)));
token = fetchTokenFromApi(clientId,map.get(URL), map.get(USER_NAME), rsaEncrypt(map.get(PASSWORD),map.get(PUBLIC_KEY)));
// 4. 存储到Redis设置25分钟过期
// RedisUtils.setCacheObject(redisKey, token,Duration.ofSeconds(TOKEN_EXPIRE_SECONDS) );
//4. 存储到Redis设置25分钟过期
RedisUtils.setCacheObject(redisKey, token,Duration.ofSeconds(TOKEN_EXPIRE_SECONDS) );
return token;
}
@ -106,25 +97,25 @@ public class TokenUtils {
// 2. 构建请求体(保持你的原有逻辑)
Map<String, String> map = paramMap.get(clientId);
JSONObject requestBody = new JSONObject();
requestBody.put(map.get(USER_NAME), username); // 从 map 中获取接口要求的用户名参数名
requestBody.put(map.get(PASSWORD), encryptedPassword); // 加密后的密码
String jsonBody = requestBody.toJSONString();
System.out.println("请求体:" + jsonBody);
HashMap<String, String> param = new HashMap<>();
param.put(map.get(USER_NAME), username); // 从 map 中获取接口要求的用户名参数名
param.put(map.get(PASSWORD), encryptedPassword); // 加密后的密码
String jsonStr = JSONUtil.toJsonStr(param);
System.out.println("请求体:" + jsonStr);
// 3. 带 Header 发送 POST 请求Hutool HttpUtil 重载方法)
String post = HttpUtil.createPost(authUrl)
// .addHeaders(headers) // 设置所有请求头
.body(jsonBody) // 设置请求体
.body(jsonStr) // 设置请求体
.execute() // 执行请求
.body(); // 获取响应体
System.out.println("响应结果:" + post);
// 3. 解析响应(核心解析逻辑)
JSONObject responseJson = JSONObject.parseObject(post);
int code = responseJson.getIntValue("code");
String msg = responseJson.getString("msg");
String token = responseJson.getString("token");
JSONObject responseJson = JSONUtil.parseObj(post);
int code = responseJson.getInt("code");
String msg = responseJson.getStr("msg");
String token = responseJson.getStr("token");
// 4. 校验响应有效性
if (code != 200) {

View File

@ -0,0 +1,71 @@
package org.dromara.dataTransmission.clarityPm.dto;
import lombok.Data;
/**
* 考勤打卡实体类
*/
@Data
public class AttendanceRecord {
/**
* 用户姓名(必填)
*/
private String userName;
/**
* 考勤人身份证号码(必填,与实名制用户保持一致)
*/
private String cardNumber;
/**
* 人员所属企业(必填)
*/
private String userCompanyName;
/**
* 考勤设备类型(必填)
* 0.考勤闸机
* 1.移动考勤机
* 2.APP打卡
*/
private String deviceType;
/**
* 考勤设备名称(非必填)
*/
private String deviceName;
/**
* 考勤打卡时间必填日期格式yyyy-MM-dd HH:mm:ss
*/
private String clockInTime;
/**
* 考勤类型(必填)
* 1.正常
* 2.外勤
* 3.出差
*/
private String clockInStatus;
/**
* 申请事由(非必填,外勤和出差填写)
*/
private String reason;
/**
* 维度(必填)
*/
private String lat;
/**
* 经度(必填)
*/
private String lng;
/**
* 打卡地点(必填)
*/
private String clockInAddress;
}

View File

@ -0,0 +1,92 @@
package org.dromara.dataTransmission.claritypm.dto;
import lombok.Data;
import java.time.LocalDate;
/**
* 实名制用户信息实体类(对应接口参数)
*/
@Data
public class RealUser {
// 人员姓名(必填)
private String userName;
// 是否班组长非必填0-否 1-是)
private String classManagerFlag;
// 手机号码(必填)
private String phone;
// 性别必填1.男 2.女 3.未知)
private String sex;
// 证件类型必填0.身份证)
private String cardType;
// 证件号码(必填,身份证号码)
private String cardNumber;
// 人员类型必填0.作业人员 1.管理人员)
private String userType;
// 发证机关(非必填)
private String cardDept;
// 民族(非必填)
private String nation;
// 生日非必填datetime格式
private LocalDate birthday;
// 住址(非必填)
private String address;
// 头像非必填http地址
private String avatar;
// 采集相片非必填http地址
private String pic;
// 安全教育表非必填http地址
private String safetyEdu;
// 技术交底表非必填http地址
private String technology;
// 证件有效期始非必填datetime格式
private LocalDate cardStartTime;
// 证件有效期至非必填datetime格式
private LocalDate cardEndTime;
// 学历非必填1-9对应小学至其他
private String studyLevel;
// 政治面貌非必填0-3对应党员至民主党派
private String politicsType;
// 购买保险非必填0-否 1-是)
private String insuranceFlag;
// 重大病史非必填0-否 1-是)
private String diseaseFlag;
// 劳动合同非必填0-未签订 1-已签订)
private String laborContractFlag;
// 紧急联系人(非必填)
private String contacts;
// 紧急联系人电话(非必填)
private String contactsPhone;
// 婚姻状况非必填0-3对应未婚至丧偶
private String marryRemark;
// 企业名称(非必填)
private String companyName;
}

View File

@ -0,0 +1,125 @@
package org.dromara.dataTransmission.clarityPm.method;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import jakarta.annotation.Resource;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.utils.IdCardEncryptorUtil;
import org.dromara.contractor.domain.SubConstructionUser;
import org.dromara.contractor.service.ISubConstructionUserFileService;
import org.dromara.contractor.service.ISubConstructionUserService;
import org.dromara.dataTransmission.clarityPm.dto.AttendanceRecord;
import org.dromara.dataTransmission.clarityPm.dto.RealUser;
import org.dromara.project.domain.BusAttendance;
import org.dromara.project.service.IBusProjectTeamMemberService;
import org.dromara.system.domain.vo.SysOssVo;
import org.dromara.system.service.ISysOssService;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class ClarityPmAsyncMethod {
// 2. 注入Service非静态字段
@Resource
@Lazy
private ISubConstructionUserService constructionUserService;
@Resource
@Lazy
private ISubConstructionUserFileService constructionUserFileService;
@Resource
@Lazy
private IBusProjectTeamMemberService teamMemberService;
@Resource
@Lazy
private IdCardEncryptorUtil idCardEncryptorUtil;
@Resource
@Lazy
private ISysOssService ossService;
@Async
public void transmitUserData(Long constructionId) {
SubConstructionUser constructionUser = constructionUserService.getById(constructionId);
Map<String, String> fileMap = constructionUserFileService.getFileByUserId(constructionUser.getSysUserId());
String post = teamMemberService.getPost(constructionUser.getSysUserId(), constructionUser.getProjectId());
// 安全教育-6 技术交底-5 合同-1
List<RealUser> userList = new ArrayList<>();
RealUser realUser = new RealUser();
realUser.setUserName(constructionUser.getUserName());
realUser.setClassManagerFlag(post);
realUser.setPhone(constructionUser.getPhone());
int sex = Integer.parseInt(constructionUser.getSex());
realUser.setSex(String.valueOf(sex + 1));
realUser.setCardType("0");
realUser.setCardNumber(idCardEncryptorUtil.decrypt(constructionUser.getSfzNumber()));
realUser.setUserType("0");
realUser.setNation(constructionUser.getNation());
realUser.setBirthday(constructionUser.getSfzBirth());
realUser.setAddress(constructionUser.getSfzSite());
SysOssVo sysOssVo = ossService.getById(Long.valueOf(constructionUser.getFacePic()));
if (sysOssVo != null) {
realUser.setPic(sysOssVo.getUrl());
}
realUser.setSafetyEdu(fileMap.get("6"));
realUser.setTechnology(fileMap.get("5"));
realUser.setCardStartTime(constructionUser.getSfzStart());
realUser.setCardEndTime(constructionUser.getSfzEnd());
realUser.setLaborContractFlag(fileMap.get("1") == null ? "0" : "1");
userList.add(realUser);
try {
ClarityPmClient.batchInsertRealUser(userList);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Async
public void transmitAttendanceRecord(BusAttendance busAttendance) {
ArrayList<AttendanceRecord> attendanceRecords = new ArrayList<>();
SubConstructionUser constructionUser = constructionUserService.getBySysUserId(busAttendance.getUserId());
AttendanceRecord attendanceRecord = new AttendanceRecord();
attendanceRecord.setUserName(busAttendance.getUserName());
attendanceRecord.setCardNumber(idCardEncryptorUtil.decrypt(constructionUser.getSfzNumber()));
attendanceRecord.setUserCompanyName(constructionUser.getCompanyName());
//0-app,1-考勤机
String source = busAttendance.getSource();
attendanceRecord.setDeviceType("1".equals(source)?"1":"2");
attendanceRecord.setDeviceName(busAttendance.getSn());
String format = LocalDateTimeUtil.format(busAttendance.getClockTime(), "yyyy-MM-dd HH:mm:ss");
attendanceRecord.setClockInTime(format);
attendanceRecord.setClockInStatus("1");
attendanceRecord.setLat(busAttendance.getLat());
attendanceRecord.setLng(busAttendance.getLng());
attendanceRecord.setClockInAddress(busAttendance.getClockLocation());
attendanceRecords.add(attendanceRecord);
try {
ClarityPmClient.batchInsertAttendanceRecord(attendanceRecords);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,132 @@
package org.dromara.dataTransmission.clarityPm.method;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.dromara.dataTransmission.TokenUtils;
import org.dromara.dataTransmission.clarityPm.dto.AttendanceRecord;
import org.dromara.dataTransmission.clarityPm.dto.RealUser;
import org.springframework.stereotype.Component;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
@Component
public class ClarityPmClient {
// 接口地址
private static final String INSERT_REAL_USER_URL = "https://claritypm.powerchina.cn/neSmartsite-api/realUser/tiandong/insertRealUser";
private static final String INSERT_ATTENDANCE_RECORD_URL = "https://claritypm.powerchina.cn/neSmartsite-api/realUser/tiandong/insertAttendance";
@Autowired
private TokenUtils tokenUtils; // 依赖之前的Token获取服务
/**
* 批量新增实名制用户信息
* @param userList 用户信息列表建议单次不超过10条
* @throws Exception 调用异常
*/
public static void batchInsertRealUser(List<RealUser> userList) throws Exception {
// 1. 校验列表大小建议不超过10条
if (userList == null || userList.isEmpty()) {
throw new IllegalArgumentException("用户列表不能为空");
}
if (userList.size() > 10) {
throw new IllegalArgumentException("单次批量新增不能超过10条数据");
}
// 2. 获取Token从之前的TokenService获取
String token = TokenUtils.getToken(TokenUtils.CLARITYPM);
if ( token.trim().isEmpty()) {
throw new RuntimeException("获取Token失败无法调用接口");
}
// 3. 构建请求头包含Token认证
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json; charset=UTF-8");
headers.put("User-Agent", "Mozilla/5.0");
headers.put("Accept", "application/json");
headers.put("Origin", "https://claritypm.powerchina.cn");
headers.put("Referer", "https://claritypm.powerchina.cn/");
headers.put("Authorization", "Bearer " + token); // 假设接口使用Bearer Token认证
// 4. 构建请求体JSONArray格式
JSONArray requestBody = JSONArray.parseArray(JSON.toJSONString(userList));
String jsonBody = requestBody.toJSONString();
System.out.println("批量新增用户请求体:" + jsonBody);
// 5. 发送POST请求
String response = HttpUtil.createPost(INSERT_REAL_USER_URL)
.addHeaders(headers)
.body(jsonBody)
.execute()
.body();
System.out.println("批量新增用户响应:" + response);
// 6. 解析响应(根据实际响应结构调整,此处假设与登录接口类似)
JSONObject responseJson = JSONUtil.parseObj(response);
int code = responseJson.getInt("code");
String msg = responseJson.getStr("msg");
if (code != 200) {
throw new RuntimeException("批量新增用户失败:" + msg + "(状态码:" + code + "");
}
}
/**
* 批量新增考勤信息
* @param records 考勤信息列表建议单次不超过10条
* @throws Exception 调用异常
*/
public static void batchInsertAttendanceRecord(List<AttendanceRecord> records) throws Exception {
// 1. 校验列表大小建议不超过10条
if (records == null || records.isEmpty()) {
throw new IllegalArgumentException("考勤列表不能为空");
}
if (records.size() > 10) {
throw new IllegalArgumentException("单次批量新增不能超过10条数据");
}
// 2. 获取Token从之前的TokenService获取
String token = TokenUtils.getToken(TokenUtils.CLARITYPM);
if ( token.trim().isEmpty()) {
throw new RuntimeException("获取Token失败无法调用接口");
}
// 3. 构建请求头包含Token认证
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json; charset=UTF-8");
headers.put("User-Agent", "Mozilla/5.0");
headers.put("Accept", "application/json");
headers.put("Origin", "https://claritypm.powerchina.cn");
headers.put("Referer", "https://claritypm.powerchina.cn/");
headers.put("Authorization", "Bearer " + token); // 假设接口使用Bearer Token认证
// 4. 构建请求体JSONArray格式
JSONArray requestBody = JSONArray.parseArray(JSON.toJSONString(records));
String jsonBody = requestBody.toJSONString();
System.out.println("批量新增考勤请求体:" + jsonBody);
// 5. 发送POST请求
String response = HttpUtil.createPost(INSERT_ATTENDANCE_RECORD_URL)
.addHeaders(headers)
.body(jsonBody)
.execute()
.body();
System.out.println("批量新增考勤响应:" + response);
// 6. 解析响应(根据实际响应结构调整,此处假设与登录接口类似)
JSONObject responseJson = JSONUtil.parseObj(response);
int code = responseJson.getInt("code");
String msg = responseJson.getStr("msg");
if (code != 200) {
throw new RuntimeException("批量新增考勤失败:" + msg + "(状态码:" + code + "");
}
}
}

View File

@ -1,79 +0,0 @@
package org.dromara.dataTransmission.claritypm;
import org.dromara.dataTransmission.TokenUtils;
import org.dromara.dataTransmission.claritypm.dto.RealUser;
import org.springframework.stereotype.Component;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
@Component
public class ClaritypmClient {
// 接口地址
private static final String INSERT_REAL_USER_URL = "https://claritypm.powerchina.cn/neSmartsite-api/realUser/tiandong/insertRealUser";
@Autowired
private TokenUtils tokenUtils; // 依赖之前的Token获取服务
/**
* 批量新增实名制用户信息
* @param userList 用户信息列表建议单次不超过10条
* @return 接口响应结果JSON格式
* @throws Exception 调用异常
*/
public static String batchInsertRealUser(List<RealUser> userList) throws Exception {
// 1. 校验列表大小建议不超过10条
if (userList == null || userList.isEmpty()) {
throw new IllegalArgumentException("用户列表不能为空");
}
if (userList.size() > 10) {
throw new IllegalArgumentException("单次批量新增不能超过10条数据");
}
// 2. 获取Token从之前的TokenService获取
String token = TokenUtils.getToken(TokenUtils.CLARITYPM);
if ( token.trim().isEmpty()) {
throw new RuntimeException("获取Token失败无法调用接口");
}
// 3. 构建请求头包含Token认证
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json; charset=UTF-8");
headers.put("User-Agent", "Mozilla/5.0");
headers.put("Accept", "application/json");
headers.put("Origin", "https://claritypm.powerchina.cn");
headers.put("Referer", "https://claritypm.powerchina.cn/");
headers.put("Authorization", "Bearer " + token); // 假设接口使用Bearer Token认证
// 4. 构建请求体JSONArray格式
JSONArray requestBody = JSONArray.parseArray(JSON.toJSONString(userList));
String jsonBody = requestBody.toJSONString();
System.out.println("批量新增用户请求体:" + jsonBody);
// 5. 发送POST请求
String response = HttpUtil.createPost(INSERT_REAL_USER_URL)
.addHeaders(headers)
.body(jsonBody)
.execute()
.body();
System.out.println("批量新增用户响应:" + response);
// 6. 解析响应(根据实际响应结构调整,此处假设与登录接口类似)
JSONObject responseJson = JSONObject.parseObject(response);
int code = responseJson.getIntValue("code");
String msg = responseJson.getString("msg");
if (code != 200) {
throw new RuntimeException("批量新增用户失败:" + msg + "(状态码:" + code + "");
}
return response;
}
}

View File

@ -1,5 +1,4 @@
package org.dromara.dataTransmission.claritypm.dto;
package org.dromara.dataTransmission.clarityPm.dto;
import lombok.Data;
import java.time.LocalDate;

View File

@ -50,7 +50,7 @@ public class BusAttendanceDeviceController extends BaseController {
@SaIgnore
public DeviceResult punchCardByFace(@RequestBody DeviceDto dto) {
//打印接收数据
log.info("接收数据:{}", dto);
// log.info("接收数据:{}", dto);
if (dto.getLogs().isEmpty()) {
return new DeviceResult(500, "没有数据");
}
@ -80,12 +80,12 @@ public class BusAttendanceDeviceController extends BaseController {
req.setSource("1");
req.setSn(dto.getSn());
//打印req
log.info("请求参数:{}", req);
// log.info("请求参数:{}", req);
//base64转MultipartFile
try {
// 假设first.getImage()返回base64字符串且你有一个文件名
MultipartFile file = convert(first.getPhoto(), "face.jpg");
log.info("开始打卡");
// log.info("开始打卡");
busAttendanceService.punchCardByFace(file, req);
return new DeviceResult(0, "打卡成功");
} catch (IOException e) {

View File

@ -21,6 +21,7 @@ import org.dromara.common.utils.AsyncUtil;
import org.dromara.common.utils.IdCardEncryptorUtil;
import org.dromara.contractor.domain.SubConstructionUser;
import org.dromara.contractor.service.ISubConstructionUserService;
import org.dromara.dataTransmission.clarityPm.method.ClarityPmAsyncMethod;
import org.dromara.project.domain.BusConstructionUserExit;
import org.dromara.project.domain.BusProjectTeam;
import org.dromara.project.domain.BusProjectTeamMember;
@ -94,6 +95,9 @@ public class BusProjectTeamMemberServiceImpl extends ServiceImpl<BusProjectTeamM
@Resource
private AsyncUtil asyncUtil;
@Resource
private ClarityPmAsyncMethod clarityPmAsyncMethod;
/**
* 查询项目班组下的成员
*
@ -224,6 +228,9 @@ public class BusProjectTeamMemberServiceImpl extends ServiceImpl<BusProjectTeamM
asyncUtil.sendPersonnel(req.getTeamId(), constructionUser);
// clarityPmAsyncMethod.transmitUserData(constructionUser.getId());
return projectTeamMember.getId();
}