|
@@ -1,14 +1,21 @@
|
|
package com.management.platform.service.impl;
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.management.platform.controller.WeiXinCorpController;
|
|
import com.management.platform.controller.WeiXinCorpController;
|
|
import com.management.platform.entity.SysConfig;
|
|
import com.management.platform.entity.SysConfig;
|
|
|
|
+import com.management.platform.entity.User;
|
|
|
|
+import com.management.platform.entity.UserCorpwxTime;
|
|
import com.management.platform.entity.WxCorpInfo;
|
|
import com.management.platform.entity.WxCorpInfo;
|
|
import com.management.platform.mapper.SysConfigMapper;
|
|
import com.management.platform.mapper.SysConfigMapper;
|
|
|
|
+import com.management.platform.mapper.UserCorpwxTimeMapper;
|
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
import com.management.platform.mapper.WxCorpInfoMapper;
|
|
import com.management.platform.mapper.WxCorpInfoMapper;
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.management.platform.util.DateTimeUtil;
|
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -19,7 +26,8 @@ import org.springframework.web.client.RestTemplate;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
-import java.time.LocalDateTime;
|
|
|
|
|
|
+import java.time.*;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -35,6 +43,10 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
public static String URL_SEND_WXCORP_MSG = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN";
|
|
public static String URL_SEND_WXCORP_MSG = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN";
|
|
//获取临时素材url
|
|
//获取临时素材url
|
|
public static String URL_GET_MEDIA = "https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID";
|
|
public static String URL_GET_MEDIA = "https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID";
|
|
|
|
+
|
|
|
|
+ public static final String GET_CHECKIN_DAYDATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_daydata?access_token=ACCESS_TOKEN";
|
|
|
|
+
|
|
|
|
+
|
|
@Value("${suitId}")
|
|
@Value("${suitId}")
|
|
private String suitId;
|
|
private String suitId;
|
|
@Value("${suitSecret}")
|
|
@Value("${suitSecret}")
|
|
@@ -51,6 +63,10 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
SysConfigMapper sysConfigMapper;
|
|
SysConfigMapper sysConfigMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ UserMapper userMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ UserCorpwxTimeMapper userCorpwxTimeMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void sendWXCorpMsg(WxCorpInfo corpInfo, String corpUserid, String msg) {
|
|
public void sendWXCorpMsg(WxCorpInfo corpInfo, String corpUserid, String msg) {
|
|
@@ -148,6 +164,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
//获取第三方应用临时凭证
|
|
//获取第三方应用临时凭证
|
|
private String getSuiteAccessToken() {
|
|
private String getSuiteAccessToken() {
|
|
if (WeiXinCorpController.SUITE_ACCESS_TOKEN == null || WeiXinCorpController.suiteTokenExpireTime < System.currentTimeMillis()) {
|
|
if (WeiXinCorpController.SUITE_ACCESS_TOKEN == null || WeiXinCorpController.suiteTokenExpireTime < System.currentTimeMillis()) {
|
|
@@ -207,4 +224,84 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
return corpInfo.getAccessToken();
|
|
return corpInfo.getAccessToken();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getUserCheckInDayData(int companyId, LocalDateTime now) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ WxCorpInfo corpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
|
+ if (corpInfo == null) {
|
|
|
|
+ msg.setError("该企业未对接企业微信");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ String url = null;
|
|
|
|
+ try {
|
|
|
|
+ url = GET_CHECKIN_DAYDATA.replace("ACCESS_TOKEN", getCorpAccessToken(corpInfo));
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
|
+// LocalDate now = LocalDate.now();
|
|
|
|
+// LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ now = now.withHour(0).withMinute(0).withSecond(0).withNano(0);
|
|
|
|
+ System.out.println(now.toString());
|
|
|
|
+ long startTime = now.toEpochSecond(ZoneOffset.of("+8"));
|
|
|
|
+ now = now.plusDays(1);
|
|
|
|
+ System.out.println(now.toString());
|
|
|
|
+ long endTime = now.toEpochSecond(ZoneOffset.of("+8"));
|
|
|
|
+ System.out.println("startTime="+startTime+",endTime="+endTime);
|
|
|
|
+ reqParam.put("starttime", startTime);
|
|
|
|
+ reqParam.put("endtime", endTime);
|
|
|
|
+
|
|
|
|
+ //获取企业下的全部员工
|
|
|
|
+ List<User> users = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId).isNotNull("corpwx_userid").eq("is_active", 1));
|
|
|
|
+ System.out.println("users size=="+users.size());
|
|
|
|
+ Object[] objects = users.stream().map(User::getCorpwxUserid).toArray();
|
|
|
|
+ reqParam.put("useridlist", objects);
|
|
|
|
+ HttpEntity<String> requestEntity = new HttpEntity<String>(reqParam.toJSONString(), headers);
|
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
|
|
+ HttpMethod.POST, requestEntity, String.class);
|
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
|
+ System.out.println(resp);
|
|
|
|
+ JSONObject json = JSONObject.parseObject(resp);
|
|
|
|
+ if (json.getIntValue("errcode") == 0) {
|
|
|
|
+ JSONArray datas = json.getJSONArray("datas");
|
|
|
|
+ for (int i=0;i<datas.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = datas.getJSONObject(i);
|
|
|
|
+ JSONObject base_info = jsonObject.getJSONObject("base_info");
|
|
|
|
+ String curUserid = base_info.getString("acctid");
|
|
|
|
+ Long time = base_info.getLong("date");
|
|
|
|
+ LocalDate localDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()).toLocalDate();
|
|
|
|
+ UserCorpwxTime ct = new UserCorpwxTime();
|
|
|
|
+ ct.setCompanyId(companyId);
|
|
|
|
+ ct.setCorpwxUserid(curUserid);
|
|
|
|
+ ct.setCreateDate(localDate);
|
|
|
|
+ JSONObject summary_info = jsonObject.getJSONObject("summary_info");
|
|
|
|
+ int sTime = summary_info.getIntValue("earliest_time");//秒
|
|
|
|
+ int eTime = summary_info.getIntValue("lastest_time");//秒
|
|
|
|
+ int regular_work_sec = summary_info.getIntValue("regular_work_sec");//秒
|
|
|
|
+
|
|
|
|
+ ct.setStartTime(DateTimeUtil.getTimeFromSeconds(sTime));
|
|
|
|
+ ct.setEndTime(DateTimeUtil.getTimeFromSeconds(eTime));
|
|
|
|
+ ct.setWorkHours(DateTimeUtil.getHoursFromSeconds(regular_work_sec));
|
|
|
|
+ UserCorpwxTime item = userCorpwxTimeMapper.selectOne(new QueryWrapper<UserCorpwxTime>().eq("corpwx_userid", curUserid)
|
|
|
|
+ .eq("create_date", localDate));
|
|
|
|
+ if (item != null) {
|
|
|
|
+ ct.setId(item.getId());
|
|
|
|
+ //已存在记录,进行更新
|
|
|
|
+ userCorpwxTimeMapper.updateById(ct);
|
|
|
|
+ } else {
|
|
|
|
+ userCorpwxTimeMapper.insert(ct);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ throw new Exception(json.toJSONString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception exception) {
|
|
|
|
+ exception.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|