数据推送
This commit is contained in:
@ -0,0 +1,49 @@
|
|||||||
|
package org.dromara.dataTransmission.clarityPm.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 违规行为实体类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ViolationRecord implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摄像头设备序列号
|
||||||
|
*/
|
||||||
|
private String deviceSerial;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摄像头名称
|
||||||
|
*/
|
||||||
|
private String deviceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 违规类型
|
||||||
|
* 1.未戴安全帽
|
||||||
|
* 2.未穿反光衣
|
||||||
|
* 3.吸烟
|
||||||
|
* 4.非授权人员闯入箱变/配电箱区域
|
||||||
|
*/
|
||||||
|
private String violationsType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 违规行为描述【几人未戴安全帽、几人抽烟 。。。】
|
||||||
|
*/
|
||||||
|
private String violationsInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 违规时间【yyyy-MM-dd HH:mm:ss】
|
||||||
|
*/
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 违规图片【http地址,1张图片】
|
||||||
|
*/
|
||||||
|
private String imgPath;
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,15 +1,23 @@
|
|||||||
package org.dromara.dataTransmission.clarityPm.method;
|
package org.dromara.dataTransmission.clarityPm.method;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
|
import cn.hutool.core.lang.TypeReference;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.dromara.common.core.utils.DateUtils;
|
||||||
import org.dromara.common.utils.IdCardEncryptorUtil;
|
import org.dromara.common.utils.IdCardEncryptorUtil;
|
||||||
import org.dromara.contractor.domain.SubConstructionUser;
|
import org.dromara.contractor.domain.SubConstructionUser;
|
||||||
import org.dromara.contractor.service.ISubConstructionUserFileService;
|
import org.dromara.contractor.service.ISubConstructionUserFileService;
|
||||||
import org.dromara.contractor.service.ISubConstructionUserService;
|
import org.dromara.contractor.service.ISubConstructionUserService;
|
||||||
import org.dromara.dataTransmission.clarityPm.dto.AttendanceRecord;
|
import org.dromara.dataTransmission.clarityPm.dto.AttendanceRecord;
|
||||||
import org.dromara.dataTransmission.clarityPm.dto.RealUser;
|
import org.dromara.dataTransmission.clarityPm.dto.RealUser;
|
||||||
|
import org.dromara.dataTransmission.clarityPm.dto.ViolationRecord;
|
||||||
|
import org.dromara.manager.recognizermanager.enums.RecognizerTypeEnum;
|
||||||
import org.dromara.project.domain.BusAttendance;
|
import org.dromara.project.domain.BusAttendance;
|
||||||
import org.dromara.project.service.IBusProjectTeamMemberService;
|
import org.dromara.project.service.IBusProjectTeamMemberService;
|
||||||
|
import org.dromara.safety.domain.HseRecognizeRecord;
|
||||||
import org.dromara.system.domain.vo.SysOssVo;
|
import org.dromara.system.domain.vo.SysOssVo;
|
||||||
import org.dromara.system.service.ISysOssService;
|
import org.dromara.system.service.ISysOssService;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
@ -17,6 +25,7 @@ import org.springframework.scheduling.annotation.Async;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -118,6 +127,49 @@ public class ClarityPmAsyncMethod {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void transmitAttendanceRecord(List<HseRecognizeRecord> recognizeRecords) {
|
||||||
|
List<ViolationRecord> records = new ArrayList<>();
|
||||||
|
for (HseRecognizeRecord record : recognizeRecords) {
|
||||||
|
String violationType = record.getViolationType();
|
||||||
|
String[] typeList = violationType.split(",");
|
||||||
|
for (String type : typeList) {
|
||||||
|
ViolationRecord violationRecord = new ViolationRecord();
|
||||||
|
violationRecord.setDeviceSerial(record.getDeviceSerial());
|
||||||
|
violationRecord.setDeviceName(record.getDeviceName());
|
||||||
|
String violationsType = null;
|
||||||
|
switch (type) {
|
||||||
|
case "2", "3":
|
||||||
|
violationsType = "1";
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
|
violationsType = "2";
|
||||||
|
break;
|
||||||
|
case "5":
|
||||||
|
violationsType = "3";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
if(StrUtil.isBlank(violationsType)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
violationRecord.setViolationsType(violationsType);
|
||||||
|
String description = RecognizerTypeEnum.fromCode(violationsType).getText();
|
||||||
|
violationRecord.setViolationsInfo(description);
|
||||||
|
violationRecord.setCreateTime(DateUtils.formatDateTime(record.getCreateTime()));
|
||||||
|
violationRecord.setImgPath(record.getPicture());
|
||||||
|
records.add(violationRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollectionUtil.isNotEmpty(records)) {
|
||||||
|
try {
|
||||||
|
ClarityPmClient.batchInsertViolationRecord(records);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import org.dromara.dataTransmission.TokenUtils;
|
import org.dromara.dataTransmission.TokenUtils;
|
||||||
import org.dromara.dataTransmission.clarityPm.dto.AttendanceRecord;
|
import org.dromara.dataTransmission.clarityPm.dto.AttendanceRecord;
|
||||||
import org.dromara.dataTransmission.clarityPm.dto.RealUser;
|
import org.dromara.dataTransmission.clarityPm.dto.RealUser;
|
||||||
|
import org.dromara.dataTransmission.clarityPm.dto.ViolationRecord;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
@ -24,9 +25,7 @@ public class ClarityPmClient {
|
|||||||
|
|
||||||
private static final String INSERT_ATTENDANCE_RECORD_URL = "https://claritypm.powerchina.cn/neSmartsite-api/realUser/tiandong/insertAttendance";
|
private static final String INSERT_ATTENDANCE_RECORD_URL = "https://claritypm.powerchina.cn/neSmartsite-api/realUser/tiandong/insertAttendance";
|
||||||
|
|
||||||
|
private static final String INSERT_VIOLATION_RECORD_URL = "https://claritypm.powerchina.cn/neSmartsite-api/remote/violations/info/add/tiandong";
|
||||||
@Autowired
|
|
||||||
private TokenUtils tokenUtils; // 依赖之前的Token获取服务
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量新增实名制用户信息
|
* 批量新增实名制用户信息
|
||||||
@ -129,4 +128,58 @@ public class ClarityPmClient {
|
|||||||
throw new RuntimeException("批量新增考勤失败:" + msg + "(状态码:" + code + ")");
|
throw new RuntimeException("批量新增考勤失败:" + msg + "(状态码:" + code + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量新增违规信息
|
||||||
|
* @param records 违规信息列表(建议单次不超过10条)
|
||||||
|
* @throws Exception 调用异常
|
||||||
|
*/
|
||||||
|
public static void batchInsertViolationRecord(List<ViolationRecord> 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_VIOLATION_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 + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user