徐新路代码
This commit is contained in:
parent
0ce77b3ea3
commit
2fbab4e853
|
@ -0,0 +1,99 @@
|
|||
package com.hzya.frame.plugin.kjs.plugin;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.base.PluginBaseEntity;
|
||||
import com.hzya.frame.plugin.kjs.service.IDingTalkBuService;
|
||||
import com.hzya.frame.web.entity.BaseResult;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
public class DingAttendancePluginInitializer extends PluginBaseEntity {
|
||||
Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
private IDingTalkBuService dingTalkBuService;
|
||||
/***
|
||||
* 插件初始化方法
|
||||
* @Author 👻👻👻👻👻👻👻👻 gjh
|
||||
* @Date 2023-08-02 10:48
|
||||
* @Param []
|
||||
* @return void
|
||||
**/
|
||||
@Override
|
||||
public void initialize() {
|
||||
logger.info(getPluginLabel() + "執行初始化方法initialize()");
|
||||
}
|
||||
|
||||
/****
|
||||
* 插件销毁方法
|
||||
* @author 👻👻👻👻👻👻👻👻 gjh
|
||||
* @date 2023-08-02 10:48
|
||||
* @return void
|
||||
**/
|
||||
@Override
|
||||
public void destroy() {
|
||||
logger.info(getPluginLabel() + "執行銷毀方法destroy()");
|
||||
}
|
||||
|
||||
/****
|
||||
* 插件的ID
|
||||
* @author 👻👻👻👻👻👻👻👻 gjh
|
||||
* @date 2023-08-02 10:48
|
||||
* @return void
|
||||
**/
|
||||
@Override
|
||||
public String getPluginId() {
|
||||
return "kjsDingAttendancePlugin";
|
||||
}
|
||||
|
||||
/****
|
||||
* 插件的名称
|
||||
* @author 👻👻👻👻👻👻👻👻 gjh
|
||||
* @date 2023-08-02 10:48
|
||||
* @return void
|
||||
**/
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "kjs钉钉考勤数据插件";
|
||||
}
|
||||
|
||||
/****
|
||||
* 插件的显示值
|
||||
* @author 👻👻👻👻👻👻👻👻 gjh
|
||||
* @date 2023-08-02 10:48
|
||||
* @return void
|
||||
**/
|
||||
@Override
|
||||
public String getPluginLabel() {
|
||||
return "kjs钉钉考勤数据插件";
|
||||
}
|
||||
|
||||
/***
|
||||
* 插件类型 1、场景插件
|
||||
* @Author 👻👻👻👻👻👻👻👻 gjh
|
||||
* @Date 2023-08-02 14:01
|
||||
* @Param []
|
||||
* @return java.lang.String
|
||||
**/
|
||||
@Override
|
||||
public String getPluginType() {
|
||||
return "1";
|
||||
}
|
||||
|
||||
/***
|
||||
* 执行业务代码
|
||||
* @Author 👻👻👻👻👻👻👻👻 gjh
|
||||
* @Date 2023-08-07 11:20
|
||||
* @param requestJson 执行业务代码的参数
|
||||
* @return void
|
||||
**/
|
||||
@Override
|
||||
public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception {
|
||||
logger.info("开始执行"+getPluginName()+requestJson.toString());
|
||||
String res = dingTalkBuService.getAttendanceList(requestJson);
|
||||
return BaseResult.getSuccessMessageEntity("操作成功");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.hzya.frame.plugin.kjs.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public interface IDingTalkBuService {
|
||||
/**
|
||||
* 获取考勤打卡信息
|
||||
* @return
|
||||
*/
|
||||
String getAttendanceList(JSONObject requestJso);
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package com.hzya.frame.plugin.kjs.service.impl;
|
||||
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.dingtalk.api.response.OapiAttendanceListRecordResponse;
|
||||
import com.hzya.frame.dingtalk.service.IDingTalkService;
|
||||
import com.hzya.frame.kjsData.attendance.entity.AttendanceEntity;
|
||||
import com.hzya.frame.plugin.kjs.service.IDingTalkBuService;
|
||||
import com.hzya.frame.sysnew.comparison.service.impl.ComparisonServiceImpl;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class DingTalkBuServiceImpl implements IDingTalkBuService {
|
||||
@Value("${dingtalk.appKey:}")
|
||||
private String appKey;
|
||||
@Value("${dingtalk.appSecret:}")
|
||||
private String appSecret;
|
||||
|
||||
@Autowired
|
||||
private IDingTalkService dingTalkService;
|
||||
@Autowired
|
||||
private ComparisonServiceImpl comparisonServiceimpl;
|
||||
|
||||
@Override
|
||||
public String getAttendanceList(JSONObject requestJson){
|
||||
//获取用户信息
|
||||
JSONObject jsonObjectUser = new JSONObject();
|
||||
JSONObject jsonStr = new JSONObject();
|
||||
jsonObjectUser.put("mdmCode", "10015");
|
||||
jsonStr.put("jsonStr", jsonObjectUser);
|
||||
//先查询编码和名称查询是否存在
|
||||
Object attribute = comparisonServiceimpl.queryEntityPage(jsonStr);
|
||||
JSONObject jsonObjectAttribute = (JSONObject) JSON.toJSON(attribute);
|
||||
JSONArray jsonArrayList = jsonObjectAttribute.getJSONObject("pageInfo").getJSONArray("list");
|
||||
List<String> userIds = new ArrayList<>();
|
||||
List<AttendanceEntity> userList = new ArrayList<>();
|
||||
for (int i = 0; i < jsonArrayList.size(); i++) {
|
||||
JSONObject item = jsonArrayList.getJSONObject(i).getJSONObject("mdm_dd_user");
|
||||
userIds.add(item.getString("userid"));
|
||||
AttendanceEntity user = new AttendanceEntity();
|
||||
user.setUserid(item.getString("userid"));
|
||||
user.setUsername(item.getString("name"));
|
||||
user.setUserjob(item.getString("job_number"));
|
||||
userList.add(user);
|
||||
}
|
||||
int groupSize = 50;
|
||||
String result = "";
|
||||
for (int i = 0; i < userIds.size(); i += groupSize) {
|
||||
List<String> subList = userIds.subList(i, Math.min(i + groupSize, userIds.size()));
|
||||
result = saveAttendanceList(subList, userList);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String saveAttendanceList(List<String> ids, List<AttendanceEntity> userList){
|
||||
//根据用户id去获取打卡记录
|
||||
List<OapiAttendanceListRecordResponse.Recordresult> attendanceList =
|
||||
dingTalkService.getAttendanceList(ids,"dingq3vbsswvyujiuwa7", "m4IRNcKQn-W9QBLERHWt0iW2hSirvxPS684xiNw-4QFMNg2gsBCur9T4QMvvAR4I");
|
||||
|
||||
List<AttendanceEntity> list = new ArrayList<>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
for (int i = 0; i < attendanceList.size(); i++) {
|
||||
OapiAttendanceListRecordResponse.Recordresult jsonObject = attendanceList.get(i);
|
||||
AttendanceEntity entity = new AttendanceEntity();
|
||||
entity.setUserid(jsonObject.getUserId());
|
||||
entity.setUserchecktime(jsonObject.getUserCheckTime() != null ? sdf.format(jsonObject.getUserCheckTime()): null);
|
||||
entity.setUserlongitude(jsonObject.getUserLongitude());
|
||||
entity.setUserlatitude(jsonObject.getUserLatitude());
|
||||
entity.setWorkdate(jsonObject.getWorkDate() != null ? sdf.format(jsonObject.getWorkDate()): null);
|
||||
entity.setUseraddress(jsonObject.getUserAddress());
|
||||
entity.setTimeresult(jsonObject.getTimeResult());
|
||||
entity.setSourcetype(jsonObject.getSourceType());
|
||||
entity.setOutsideremark(jsonObject.getOutsideRemark());
|
||||
entity.setLocationresult(jsonObject.getLocationResult());
|
||||
entity.setGmtmodified(jsonObject.getGmtModified() != null ? sdf.format(jsonObject.getGmtModified()): null);
|
||||
entity.setChecktype(jsonObject.getCheckType());
|
||||
entity.setBasechecktime(jsonObject.getBaseCheckTime() != null ? sdf.format(jsonObject.getBaseCheckTime()): null);
|
||||
|
||||
Optional<AttendanceEntity> userInfo = userList.stream().filter(s->s.getUserid().equals(entity.getUserid()))
|
||||
.findFirst();
|
||||
if (userInfo.isPresent()){
|
||||
entity.setUsername(userInfo.get().getUsername());
|
||||
entity.setUserjob(userInfo.get().getUserjob());
|
||||
}
|
||||
list.add(entity);
|
||||
}
|
||||
String body = "";
|
||||
int groupSize = 100;
|
||||
for (int i = 0; i < list.size(); i += groupSize) {
|
||||
List<AttendanceEntity> subList = list.subList(i, Math.min(i + groupSize, list.size()));
|
||||
String reqParams = JSONObject.toJSONString(subList);
|
||||
Map<String, String> headerMap = MapBuilder.<String, String>create(true)
|
||||
.put("apiCode", "8000100000")
|
||||
.put("publicKey","ZJYAn/EBWEhLUMezDLU4iZ1vTO9kc6pM6XrYLajnqnK60Q9Ce7eDIk+3zDUT+v578prj")
|
||||
.put("secretKey","ctMIYyauwoKSFeU4tg5gH1aWC/3OJK6HsKJrSR0oyDmdmdvRNgdoTzX0C1OQ+whrj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=")
|
||||
.put("appId","800010")
|
||||
.build();
|
||||
|
||||
body = HttpRequest.post("http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface").addHeaders(headerMap).body(reqParams).timeout(60000).execute().body();
|
||||
|
||||
}
|
||||
return body;
|
||||
|
||||
}
|
||||
}
|
|
@ -4,4 +4,5 @@
|
|||
<bean name="deliveryOrderPluginInitializer" class="com.hzya.frame.plugin.kjs.plugin.DeliveryOrderPluginInitializer" />
|
||||
<bean name="momOrderPluginInitializer" class="com.hzya.frame.plugin.kjs.plugin.MomOrderPluginInitializer" />
|
||||
<bean name="dingTalkInitPluginInitializer" class="com.hzya.frame.plugin.kjs.plugin.DingTalkInitPluginInitializer" />
|
||||
<bean name="DingAttendancePluginInitializer" class="com.hzya.frame.plugin.kjs.plugin.DingAttendancePluginInitializer" />
|
||||
</beans>
|
||||
|
|
|
@ -6,4 +6,5 @@
|
|||
<bean name="kjsPluginBaseService" class="com.hzya.frame.plugin.kjs.service.impl.KjsPluginBaseService" />
|
||||
<bean name="genericEventConsumer" class="com.hzya.frame.plugin.kjs.service.GenericEventConsumer" />
|
||||
<bean name="dingTalkInitServiceImpl" class="com.hzya.frame.plugin.kjs.service.impl.DingTalkInitServiceImpl" />
|
||||
<bean name="dingTalkBuServiceImpl" class="com.hzya.frame.plugin.kjs.service.impl.DingTalkBuServiceImpl" />
|
||||
</beans>
|
||||
|
|
Loading…
Reference in New Issue