Commit 74dae690 authored by 赵啸非's avatar 赵啸非

添加海康接口同步数据

parent 805611b3
......@@ -28,6 +28,8 @@
<profiles.log.path>/mortals/app/logs</profiles.log.path>
<profiles.log.level>info</profiles.log.level>
<profiles.publish.path>/home/publish</profiles.publish.path>
<profiles.sms.smsSendUrl>http://127.0.0.1:8089/api/index/index</profiles.sms.smsSendUrl>
<profiles.sms.apiId>k6BVS1PEbyzcJAE4</profiles.sms.apiId>
<profiles.hik.host>8.136.255.30:8001</profiles.hik.host>
<profiles.hik.appKey>25128371</profiles.hik.appKey>
<profiles.hik.appSecret>2m9RcPJOKq5j2QPQM4v5</profiles.hik.appSecret>
......@@ -52,7 +54,6 @@
<profiles.log.level>INFO</profiles.log.level>
<profiles.sms.smsSendUrl>http://127.0.0.1:8089/api/index/index</profiles.sms.smsSendUrl>
<profiles.sms.apiId>k6BVS1PEbyzcJAE4</profiles.sms.apiId>
<profiles.sms.type>3</profiles.sms.type>
<profiles.hik.host>8.136.255.30:8001</profiles.hik.host>
<profiles.hik.appKey>25128371</profiles.hik.appKey>
<profiles.hik.appSecret>2m9RcPJOKq5j2QPQM4v5</profiles.hik.appSecret>
......@@ -74,8 +75,6 @@
<profiles.log.level>INFO</profiles.log.level>
<profiles.sms.smsSendUrl>http://127.0.0.1:8089/api/index/index</profiles.sms.smsSendUrl>
<profiles.sms.apiId>k6BVS1PEbyzcJAE4</profiles.sms.apiId>
<profiles.sms.type>3</profiles.sms.type>
<profiles.hik.host>8.136.255.30:8001</profiles.hik.host>
<profiles.hik.appKey>25128371</profiles.hik.appKey>
<profiles.hik.appSecret>2m9RcPJOKq5j2QPQM4v5</profiles.hik.appSecret>
......
......@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.busiz.hik.ArtemisPostTest;
import com.mortals.xhx.busiz.rsp.DeptHikData;
import com.mortals.xhx.busiz.rsp.ListDept;
import com.mortals.xhx.busiz.rsp.ListItem;
......@@ -16,6 +15,9 @@ import com.mortals.xhx.module.attendance.model.AttendanceVacationBalanceEntity;
import com.mortals.xhx.module.dept.dao.ibatis.DeptDaoImpl;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.hik.person.model.req.org.OrgListReq;
import com.mortals.xhx.module.hik.person.model.req.person.PersonReq;
import com.mortals.xhx.module.hik.person.service.IHikPersonService;
import com.mortals.xhx.module.staff.dao.ibatis.StaffDaoImpl;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.service.StaffService;
......@@ -51,22 +53,20 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
@Autowired
private AttendanceVacationBalanceDaoImpl balanceDao;
@Autowired
private AttendanceRecordDaoImpl attendanceRecordDao;
@Autowired
private AttendanceRecordDetailDaoImpl attendanceRecordDetailDao;
@Autowired
private AttendanceRecordErrorDaoImpl attendanceRecordErrorDao;
private IHikPersonService hikPersonService;
@Override
public void excuteTask(ITask task) throws AppException {
log.info("同步用户--部门");
try {
//部门同步
String resultDept = ArtemisPostTest.callPostApiGetDeptList();
//String resultDept = ArtemisPostTest.callPostApiGetDeptList();
OrgListReq orgListReq = new OrgListReq();
orgListReq.setPageNo(1);
orgListReq.setPageSize(1000);
String resultDept = hikPersonService.getOrgListTrans(orgListReq);
JSONObject jsonObjectDept = JSON.parseObject(resultDept);
JSONObject jsonObjectDept1 = jsonObjectDept.getJSONObject("data");
DeptHikData deptHikData = JSONObject.parseObject(jsonObjectDept1.toJSONString(), DeptHikData.class);
......@@ -109,7 +109,12 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
}
}
//同步员工
String resultPerson = ArtemisPostTest.callPostApiGetPersonList();
//String resultPerson = ArtemisPostTest.callPostApiGetPersonList();
PersonReq personReq = new PersonReq();
personReq.setPageNo(1);
personReq.setPageSize(1000);
String resultPerson = hikPersonService.getPersonListTrans(personReq);
JSONObject jsonObject = JSON.parseObject(resultPerson);
JSONObject jsonObject1 = jsonObject.getJSONObject("data");
PersonHikData personHikData = JSONObject.parseObject(jsonObject1.toJSONString(), PersonHikData.class);
......@@ -231,7 +236,7 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
staffEntity1.setPhoneNumber(String.valueOf(list.getPhoneNo()));
}
service.update(staffEntity1);
if (Objects.nonNull(statEntity)){
if (Objects.nonNull(statEntity)) {
statEntity.initAttrValue();
statEntity.setStaffId(staffEntity1.getId());
statEntity.setStaffName(staffEntity1.getName());
......
package com.mortals.xhx.module.hik;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.springframework.beans.factory.annotation.Value;
import java.util.HashMap;
import java.util.Map;
public abstract class AbstractHikService {
@Value("${hik.host:''}")
protected String host;
@Value("${hik.appKey:''}")
protected String appKey;
@Value("${hik.appSecret:''}")
protected String appSecret;
@Value("${hik.protocol:http://}")
protected String protocol;
public String ARTEMIS_PATH = "/artemis";
protected Map<String, String> path = new HashMap<>(2);
protected ArtemisConfig getArtemisConfig() {
ArtemisConfig config = new ArtemisConfig();
config.setHost(host);
config.setAppKey(appKey); // 秘钥appkey
config.setAppSecret(appSecret);// 秘钥appSecret
return config;
}
}
package com.mortals.xhx.module.hik;
import lombok.Data;
/**
* 海康请求基础类
* @author:
* @date: 2023/4/12 17:57
*/
@Data
public class BaseReq {
}
package com.mortals.xhx.module.hik;
public class HikApiRest<T> {
private T data;
private String code;
private String msg;
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
package com.mortals.xhx.module.hik.door.model.req.door;
import com.alibaba.fastjson.annotation.JSONField;
import com.mortals.xhx.module.hik.BaseReq;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Data
public class DoorEventReq extends BaseReq implements Serializable {
/**
* 当前页
*/
private Integer pageNo;
/**
* 每页大小
*/
private Integer pageSize;
private String doorName;
private String sort;
/**
* 事件类型,参考[附录D2.1 门禁事件]
* @[软件产品-综合安防管理平台-附录-附录D 事件列表-附录D2 一卡通事件-附录D2.1 门禁事件]
*/
private List<Integer> eventTypes;
private List<String> readerDevIndexCodes;
private String personName;
private String doorRegionIndexCode;
@JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Date receiveStartTime;
@JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Date receiveEndTime;
@JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Date startTime;
@JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Date endTime;
private List<String> doorIndexCodes;
private String order;
}
package com.mortals.xhx.module.hik.door.model.rsp.door;
import lombok.Data;
import java.util.List;
@Data
public class DoorEventDataInfo {
private List<DoorEventInfo> list;
private Integer total;
private Integer totalPage;
private Integer pageNo;
}
package com.mortals.xhx.module.hik.door.model.rsp.door;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.Date;
@Data
public class DoorEventInfo{
private String eventId;
private String orgName;
private String svrIndexCode;
private String doorName;
private String orgIndexCode;
private String doorIndexCode;
private int eventType;
private String devIndexCode;
private String identityCardUri;
private String readerDevName;
private String devName;
private String cardNo;
private String personName;
@JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Date receiveTime;
private String studentId;
private String readerDevIndexCode;
private String certNo;
private String doorRegionIndexCode;
private int inAndOutType;
private String picUri;
private String jobNo;
@JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Date eventTime;
private String eventName;
private String personId;
}
\ No newline at end of file
package com.mortals.xhx.module.hik.door.service;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq;
import com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo;
/**
* 海康门禁接口对接类
*
* @author:
* @date: 2023/4/12 17:47
*/
public interface IHikDoorService {
/**
* 获取门禁事件
*
* @author:
* @date: 2023/4/13 10:24
*/
Rest<DoorEventDataInfo> getDoorEvents(DoorEventReq doorEventReq);
}
package com.mortals.xhx.module.hik.door.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.module.hik.AbstractHikService;
import com.mortals.xhx.module.hik.HikApiRest;
import com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq;
import com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo;
import com.mortals.xhx.module.hik.door.service.IHikDoorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* 海康人员接口类
*
* @author: zxfei
* @date: 2023/4/12 17:51
*/
@Service("hikDoorService")
@Slf4j
public class HikDoorServiceImpl extends AbstractHikService implements IHikDoorService {
@Override
public Rest<DoorEventDataInfo> getDoorEvents(DoorEventReq doorEventReq) {
ArtemisConfig config = getArtemisConfig();
String getCamsApi = ARTEMIS_PATH + "/api/acs/v2/door/events";
Map<String, String> path = new HashMap<>(2);
path.put(protocol, getCamsApi);
try {
log.info("door events req=>{}", JSON.toJSONString(doorEventReq));
String respJson = ArtemisHttpUtil.doPostStringArtemis(config, path, JSON.toJSONString(doorEventReq), null, null, "application/json");
log.info("door events error resp=>{}", respJson);
HikApiRest<DoorEventDataInfo> rest = JSON.parseObject(respJson, new TypeReference<HikApiRest<DoorEventDataInfo>>() {
});
if(rest.getCode()=="0"){
return Rest.ok(rest.getData());
}else{
return Rest.fail(rest.getMsg());
}
} catch (Exception e) {
log.error("获取门禁事件异常", e);
return Rest.fail(e.getMessage());
}
}
}
package com.mortals.xhx.module.hik.person.model.req.org;
import lombok.Data;
@Data
public class OrgListReq{
private String orgName;
private String orgIndexCodes;
private int pageNo;
private int pageSize;
}
\ No newline at end of file
package com.mortals.xhx.module.hik.person.model.req.person;
import com.mortals.xhx.module.hik.BaseReq;
import lombok.Data;
import java.io.Serializable;
@Data
public class PersonReq extends BaseReq implements Serializable {
/**
* 当前页
*/
private Integer pageNo;
/**
* 每页大小
*/
private Integer pageSize;
}
package com.mortals.xhx.module.hik.person.model.rsp.org;
import lombok.Data;
import java.util.List;
@Data
public class OrgDataInfo {
private List<OrgInfo> list;
private Integer total;
private Integer totalPage;
private Integer pageNo;
}
package com.mortals.xhx.module.hik.person.model.rsp.org;
import lombok.Data;
@Data
public class OrgInfo {
private String orgName;
private String orgNo;
private String orgPath;
private String parentOrgIndexCode;
private String orgIndexCode;
private String updateTime;
private String parentOrgName;
}
\ No newline at end of file
package com.mortals.xhx.module.hik.person.model.rsp.person;
import lombok.Data;
import java.util.List;
@Data
public class PersonDataInfo {
private List<PersonInfo> list;
private Integer total;
private Integer totalPage;
private Integer pageNo;
}
package com.mortals.xhx.module.hik.person.model.rsp.person;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.Date;
@Data
public class PersonInfo{
private int gender;
private String orgPath;
private String orgPathName;
private String orgIndexCode;
@JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Date updateTime;
private String certificateNo;
private String phoneNo;
private String personName;
private PersonPhoto personPhoto;
@JSONField(format = "yyyy-MM-dd'T'HH:mm:ssXXX")
private Date createTime;
private String jobNo;
private String personId;
private int certificateType;
}
\ No newline at end of file
package com.mortals.xhx.module.hik.person.model.rsp.person;
import lombok.Data;
@Data
public class PersonPhoto{
private String personPhotoIndexCode;
private String picUri;
private String personId;
private String serverIndexCode;
}
\ No newline at end of file
package com.mortals.xhx.module.hik.person.service;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.module.hik.person.model.req.org.OrgListReq;
import com.mortals.xhx.module.hik.person.model.req.person.PersonReq;
import com.mortals.xhx.module.hik.person.model.rsp.org.OrgDataInfo;
import com.mortals.xhx.module.hik.person.model.rsp.person.PersonDataInfo;
/**
* 海康人员接口对接类
*
* @author:
* @date: 2023/4/12 17:47
*/
public interface IHikPersonService {
/**
* 获取人员接口
*
* @param personReq
* @return
*/
Rest<PersonDataInfo> getPersonList(PersonReq personReq);
/**
* 获取人员接口透传
*
* @param personReq
* @return
*/
String getPersonListTrans(PersonReq personReq);
/**
* 获取组织接口
*
* @param orgListReq
* @return
*/
Rest<OrgDataInfo> getOrgList(OrgListReq orgListReq);
/**
* 透传原始数据
*
* @param orgListReq
* @return
*/
String getOrgListTrans(OrgListReq orgListReq);
}
package com.mortals.xhx.module.hik.person.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.module.hik.AbstractHikService;
import com.mortals.xhx.module.hik.HikApiRest;
import com.mortals.xhx.module.hik.person.model.req.org.OrgListReq;
import com.mortals.xhx.module.hik.person.model.req.person.PersonReq;
import com.mortals.xhx.module.hik.person.model.rsp.org.OrgDataInfo;
import com.mortals.xhx.module.hik.person.model.rsp.person.PersonDataInfo;
import com.mortals.xhx.module.hik.person.service.IHikPersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* 海康人员接口类
*
* @author: zxfei
* @date: 2023/4/12 17:51
*/
@Service("hikPersonService")
@Slf4j
public class HikPersonServiceImpl extends AbstractHikService implements IHikPersonService {
@Override
public Rest<PersonDataInfo> getPersonList(PersonReq personReq) {
ArtemisConfig config = getArtemisConfig();
String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/person/personList";
Map<String, String> path = new HashMap<>(2);
path.put(protocol, getCamsApi);
try {
String respJson = ArtemisHttpUtil.doPostStringArtemis(config, path, JSON.toJSONString(personReq), null, null, "application/json");
HikApiRest<PersonDataInfo> rest = JSON.parseObject(respJson, new TypeReference<HikApiRest<PersonDataInfo>>() {
});
if (rest.getCode() == "0") {
return Rest.ok(rest.getData());
} else {
log.info("person error resp=>{}", respJson);
return Rest.fail(rest.getMsg());
}
} catch (Exception e) {
log.error("获取人员异常", e);
return Rest.fail(e.getMessage());
}
}
@Override
public String getPersonListTrans(PersonReq personReq) {
ArtemisConfig config = getArtemisConfig();
String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/person/personList";
Map<String, String> path = new HashMap<>(2);
path.put(protocol, getCamsApi);
try {
return ArtemisHttpUtil.doPostStringArtemis(config, path, JSON.toJSONString(personReq), null, null, "application/json");
} catch (Exception e) {
log.error("获取人员异常", e);
return JSON.toJSONString(Rest.fail(e.getMessage()));
}
}
@Override
public Rest<OrgDataInfo> getOrgList(OrgListReq orgListReq) {
ArtemisConfig config = getArtemisConfig();
String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/org/orgList";
Map<String, String> path = new HashMap<>(2);
path.put(protocol, getCamsApi);
try {
String respJson = ArtemisHttpUtil.doPostStringArtemis(config, path, JSON.toJSONString(orgListReq), null, null, "application/json");
HikApiRest<OrgDataInfo> rest = JSON.parseObject(respJson, new TypeReference<HikApiRest<OrgDataInfo>>() {
});
if (rest.getCode() == "0") {
return Rest.ok(rest.getData());
} else {
log.info("org list error resp=>{}", respJson);
return Rest.fail(rest.getMsg());
}
} catch (Exception e) {
log.error("org list error ", e);
return Rest.fail(e.getMessage());
}
}
@Override
public String getOrgListTrans(OrgListReq orgListReq) {
ArtemisConfig config = getArtemisConfig();
String getCamsApi = ARTEMIS_PATH + "/api/resource/v1/org/orgList";
Map<String, String> path = new HashMap<>(2);
path.put(protocol, getCamsApi);
try {
return ArtemisHttpUtil.doPostStringArtemis(config, path, JSON.toJSONString(orgListReq), null, null, "application/json");
} catch (Exception e) {
log.error("org list error ", e);
return JSON.toJSONString(Rest.fail(e.getMessage()));
}
}
}
......@@ -56,7 +56,6 @@ hystrix:
sms:
smsSendUrl: @profiles.sms.smsSendUrl@
apiId: @profiles.sms.apiId@
type: @profiles.sms.type@
hik:
host: @profiles.hik.host@
appKey: @profiles.hik.appKey@
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment