123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package me.zhengjie.modules.quartz.task;
- import cn.hutool.http.HttpRequest;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import me.zhengjie.modules.dm.user.service.DmUserService;
- import me.zhengjie.modules.dm.user.service.dto.DmUserDto;
- import me.zhengjie.modules.dm.user.service.dto.DmUserQueryCriteria;
- import me.zhengjie.modules.system.service.DeptService;
- import me.zhengjie.modules.system.service.dto.DeptDto;
- import me.zhengjie.modules.system.service.dto.DeptQueryNoAuthCriteria;
- import me.zhengjie.utils.SecurityUtils;
- import me.zhengjie.utils.StringUtils;
- import org.springframework.stereotype.Component;
- import org.springframework.util.ObjectUtils;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- @Slf4j
- @RequiredArgsConstructor
- @Component
- public class ZkDataPushTask {
- private final String key = "DMERPYT!@#$QWER2021+{:>";
- private final String fpApi = "http://10.208.128.14:8069/";
- private final DmUserService dmUserService;
- private final DeptService deptService;
- public void run() {
- log.info("pushAttendanceData 执行开始");
- pushAttendanceData();
- log.info("pushAttendanceData 执行结束");
- }
- private void pushAttendanceData(){
- String yktAttendanceApi = "http://192.168.1.25:8000/api/thirdparty/v2/user/getAttendance";
- String erpAttendanceApi = "http://10.22.2.65:16000/attendance-api/device/identify/callback";
- Map<String,Object> newToken = SecurityUtils.getToken(key);
- JSONObject param = new JSONObject();
- param.put("timestamp",newToken.get("timestamp"));
- param.put("nonce",newToken.get("nonce"));
- String res = HttpRequest.get(yktAttendanceApi)
- .header("XYTACCESSTOKEN",newToken.get("token").toString() )
- .body(param.toJSONString()).execute().body();
- if(StringUtils.isNotEmpty(res)) {
- log.info("res:"+res);
- JSONArray attendanceArray = JSONArray.parseArray(res);
- for(int i = 0;i<attendanceArray.size();i++){
- JSONObject attendance = attendanceArray.getJSONObject(i);
- //组装返回数据
- JSONObject ertAttendanceJSON = new JSONObject();
- ertAttendanceJSON.put("deviceKey",attendance.getString("roomDevice"));
- ertAttendanceJSON.put("personId",attendance.getString("userNumber"));
- ertAttendanceJSON.put("time",attendance.getString("attendanceTime"));
- ertAttendanceJSON.put("type","face_0");
- HttpRequest.get(erpAttendanceApi).body(ertAttendanceJSON.toJSONString()).execute().body();
- }
- } else {
- log.info("res is null.");
- }
- }
- private void pushFeiPuDeptData() throws Exception {
- String api = "openapi/deptOperate";
- List<DeptDto> deptDtoList = deptService.queryAll(new DeptQueryNoAuthCriteria());
- if(!ObjectUtils.isEmpty(deptDtoList)){
- for(DeptDto deptDto: deptDtoList){
- JSONObject param = new JSONObject();
- param.put("deptId",deptDto.getId());
- param.put("deptName",deptDto.getName());
- param.put("pDeptId",deptDto.getPid());
- param.put("sort",deptDto.getDeptSort());
- param.put("operateType",1);
- String res = HttpRequest.post(fpApi+api)
- .form("dept",param.toJSONString()).execute().body();
- log.info("res:"+res);
- }
- }
- }
- private void pushFeiPuUserData(){
- String api = "openapi/personOperate";
- List<Map<String,String>> dmUserDtoList = dmUserService.queryAll();
- if(!ObjectUtils.isEmpty(dmUserDtoList)){
- for(Map<String,String> map: dmUserDtoList){
- JSONObject param = new JSONObject();
- param.put("userId",map.get("id"));
- param.put("userName",map.get("name"));
- param.put("deptId",map.get("deptId"));
- Integer sex = null;
- if(StringUtils.isNotBlank(map.get("sex"))){
- if(StringUtils.equals("男",map.get("sex"))){
- sex = 2;
- } else if(StringUtils.equals("女",map.get("sex"))) {
- sex = 1;
- }
- }
- param.put("sex",sex);
- param.put("cardId",map.get("cardId"));
- param.put("operateType",1);
- String res = HttpRequest.post(fpApi+api)
- .form("person",param.toJSONString()).execute().body();
- log.info("res:"+res);
- }
- }
- }
- }
|