|
@@ -8,6 +8,7 @@ import com.management.platform.entity.vo.UserVO;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.DepartmentService;
|
|
|
import com.management.platform.service.UserService;
|
|
|
+import com.management.platform.service.WxCorpInfoService;
|
|
|
import com.management.platform.util.*;
|
|
|
import com.qq.weixin.mp.aes.AesException;
|
|
|
import com.qq.weixin.mp.aes.WXBizMsgCrypt;
|
|
@@ -22,8 +23,8 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneOffset;
|
|
|
+import java.time.*;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
|
|
|
@RestController
|
|
@@ -48,7 +49,12 @@ public class WeiXinCorpController {
|
|
|
//网页获取企业用户信息
|
|
|
public static final String GET_CORP_USERINFO_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd?suite_access_token=SUITE_ACCESS_TOKEN&code=CODE";
|
|
|
|
|
|
+ //获取员工打卡日报统计信息
|
|
|
+ public static final String GET_CHECKIN_DAYDATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_daydata?access_token=ACCESS_TOKEN";
|
|
|
|
|
|
+ public static final String GET_CHECKINDATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=ACCESS_TOKEN";
|
|
|
+
|
|
|
+ public static final String GET_CHECKINOPTION = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinoption?access_token=ACCESS_TOKEN";
|
|
|
@Value("${suitId}")
|
|
|
private String suitId;
|
|
|
@Value("${suitSecret}")
|
|
@@ -68,6 +74,8 @@ public class WeiXinCorpController {
|
|
|
@Resource
|
|
|
ProjectMapper projectMapper;
|
|
|
@Resource
|
|
|
+ WxCorpInfoService wxCorpInfoService;
|
|
|
+ @Resource
|
|
|
ProjectBasecostSettingMapper projectBasecostSettingMapper;
|
|
|
|
|
|
public static String SUITE_ACCESS_TOKEN = null;
|
|
@@ -744,4 +752,114 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ //获取企业微信考勤打卡统计数据
|
|
|
+ @RequestMapping("/getUserCheckInDayData")
|
|
|
+ public HttpRespMsg getUserCheckInDayData(int companyId, String date) {
|
|
|
+ LocalDateTime localDate = LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ return wxCorpInfoService.getUserCheckInDayData(companyId, localDate);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/getUserCheckInData")
|
|
|
+ public HttpRespMsg getUserCheckInData(int companyId) {
|
|
|
+ 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_CHECKINDATA.replace("ACCESS_TOKEN", getCorpAccessToken(corpInfo));
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
+ 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);
|
|
|
+ reqParam.put("opencheckindatatype", 3);
|
|
|
+
|
|
|
+ //获取企业下的全部员工
|
|
|
+ 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");
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new Exception(json.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/getUserCheckOption")
|
|
|
+ public HttpRespMsg getUserCheckOption(int companyId) {
|
|
|
+ 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_CHECKINOPTION.replace("ACCESS_TOKEN", getCorpAccessToken(corpInfo));
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
+ 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"));
|
|
|
+
|
|
|
+ System.out.println("startTime="+startTime+",endTime="+startTime);
|
|
|
+ reqParam.put("datetime", startTime);
|
|
|
+
|
|
|
+ //获取企业下的全部员工
|
|
|
+ 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");
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new Exception(json.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|