|
@@ -8,10 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.management.platform.controller.WeiXinCorpController;
|
|
|
import com.management.platform.entity.*;
|
|
|
-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.*;
|
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
|
import com.management.platform.util.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -87,6 +84,9 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
@Resource
|
|
|
UserCorpwxTimeMapper userCorpwxTimeMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ LeaveSheetMapper leaveSheetMapper;
|
|
|
+
|
|
|
|
|
|
//获取服务商provider_access_token
|
|
|
@Override
|
|
@@ -862,7 +862,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
|
|
|
//查询某时间段的微信请假审批单号及详情
|
|
|
@Override
|
|
|
- public List<LeaveSheet> WxLeaveNumber(String startTime,String endTime,List<WxCorpInfo> wxCorpInfos) throws Exception {
|
|
|
+ public List<LeaveSheet> WxLeaveNumber(String startTime,String endTime,List<WxCorpInfo> wxCorpInfos,List<LeaveSheet> ApprovalLeave) throws Exception {
|
|
|
//存储更新失败的公司名称
|
|
|
List<String> fail = new ArrayList<>();
|
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/oa/getapprovalinfo?access_token=ACCESS_TOKEN";
|
|
@@ -874,18 +874,82 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
headers.setContentType(type);
|
|
|
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
for (WxCorpInfo wxCorpInfo : wxCorpInfos) {
|
|
|
- //获取更新Access_token查询审批号
|
|
|
+ //更新Access_token
|
|
|
String accessToken = getCorpAccessToken(wxCorpInfo);
|
|
|
url = url.replace("ACCESS_TOKEN", accessToken);
|
|
|
+ //查询并更新审核中的审批单
|
|
|
+ if (ApprovalLeave.size()!=0){
|
|
|
+ for (LeaveSheet corpInfo : ApprovalLeave) {
|
|
|
+ if (corpInfo.getCompanyId()==wxCorpInfo.getCompanyId()&&corpInfo.getProcinstId()!=null&&corpInfo.getProcinstId()!=""){
|
|
|
+ detailUrl = detailUrl.replace("ACCESS_TOKEN", accessToken);
|
|
|
+ JSONObject detailMap = new JSONObject();
|
|
|
+ detailMap.put("sp_no",corpInfo.getProcinstId());
|
|
|
+ HttpEntity<JSONObject> detailEntity = new HttpEntity<>(detailMap, headers);
|
|
|
+ ResponseEntity<String> detailResponseEntity = restTemplate.postForEntity(detailUrl, detailEntity, String.class);
|
|
|
+ if (detailResponseEntity.getStatusCode() == HttpStatus.OK){
|
|
|
+ String detailResp = detailResponseEntity.getBody();
|
|
|
+ JSONObject info = JSONObject.parseObject(detailResp).getJSONObject("info");
|
|
|
+ Integer status = info.getInteger("sp_status");
|
|
|
+ switch (status){
|
|
|
+ //审批中
|
|
|
+ case 1:
|
|
|
+ status=1;
|
|
|
+ break;
|
|
|
+ //已通过
|
|
|
+ case 2:
|
|
|
+ status=0;
|
|
|
+ break;
|
|
|
+ //已驳回
|
|
|
+ case 3:
|
|
|
+ status=2;
|
|
|
+ break;
|
|
|
+ //已撤销
|
|
|
+ case 4:
|
|
|
+ status=3;
|
|
|
+ break;
|
|
|
+ //通过后撤销
|
|
|
+ case 5:
|
|
|
+ status=5;
|
|
|
+ break;
|
|
|
+ //通过后撤销
|
|
|
+ case 6:
|
|
|
+ status=6;
|
|
|
+ break;
|
|
|
+ //7-已删除
|
|
|
+ case 7:
|
|
|
+ status=7;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ status=8;
|
|
|
+ }
|
|
|
+ if (status!=1){
|
|
|
+ LeaveSheet leaveSheet = new LeaveSheet();
|
|
|
+ leaveSheet.setId(corpInfo.getId());
|
|
|
+ leaveSheet.setStatus(status);
|
|
|
+ //添加审核人信息
|
|
|
+ String approverUserId = info.getJSONArray("sp_record").getJSONObject(0)
|
|
|
+ .getJSONArray("details").getJSONObject(0)
|
|
|
+ .getJSONObject("approver").getString("userid");
|
|
|
+ User approverUser = new User();
|
|
|
+ if (approverUserId!=""&&approverUserId!=null){
|
|
|
+ approverUser= userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_real_userid", approverUserId));
|
|
|
+ }
|
|
|
+ leaveSheet.setAuditorName(approverUser==null?approverUserId:approverUser.getName());
|
|
|
+ leaveSheet.setAuditorId(approverUser==null?"":approverUser.getId());
|
|
|
+ leaveSheetMapper.updateById(leaveSheet);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ System.err.println("请假单号错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //批量获取审批单号
|
|
|
ArrayList<HashMap> list = new ArrayList<>();
|
|
|
HashMap<String, String> record_type = new HashMap<>();
|
|
|
- HashMap<String, String> sp_status = new HashMap<>();
|
|
|
list.add(record_type);
|
|
|
- list.add(sp_status);
|
|
|
record_type.put("key", "record_type");
|
|
|
record_type.put("value", "1");
|
|
|
- sp_status.put("key", "sp_status");
|
|
|
- sp_status.put("value", "2");
|
|
|
JSONObject requestMap = new JSONObject();
|
|
|
requestMap.put("starttime", startTime);
|
|
|
requestMap.put("endtime", endTime);
|
|
@@ -908,42 +972,69 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
if(ResponseEntity.getStatusCode() == HttpStatus.OK){
|
|
|
//封装请假单数据
|
|
|
String detailResp = detailResponseEntity.getBody();
|
|
|
- JSONObject detailJson = JSONObject.parseObject(detailResp);
|
|
|
- String info = detailJson.getString("info");
|
|
|
- JSONObject infoJson = JSONObject.parseObject(info);
|
|
|
+ JSONObject infoJson = JSONObject.parseObject(detailResp).getJSONObject("info");
|
|
|
+ //审核状态
|
|
|
+ Integer sp_status = infoJson.getInteger("sp_status");
|
|
|
+ switch (sp_status){
|
|
|
+ //审批中
|
|
|
+ case 1:
|
|
|
+ sp_status=1;
|
|
|
+ break;
|
|
|
+ //已通过
|
|
|
+ case 2:
|
|
|
+ sp_status=0;
|
|
|
+ break;
|
|
|
+ //已驳回
|
|
|
+ case 3:
|
|
|
+ sp_status=2;
|
|
|
+ break;
|
|
|
+ //已撤销
|
|
|
+ case 4:
|
|
|
+ sp_status=3;
|
|
|
+ break;
|
|
|
+ //通过后撤销
|
|
|
+ case 5:
|
|
|
+ sp_status=5;
|
|
|
+ break;
|
|
|
+ //通过后撤销
|
|
|
+ case 6:
|
|
|
+ sp_status=6;
|
|
|
+ break;
|
|
|
+ //7-已删除
|
|
|
+ case 7:
|
|
|
+ sp_status=7;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ sp_status=8;
|
|
|
+ }
|
|
|
//审批申请提交时间,Unix时间戳
|
|
|
LocalDateTime applyTime = LocalDateTime.ofEpochSecond(Long.parseLong(infoJson.getString("apply_time")), 0, ZoneOffset.ofHours(8));
|
|
|
//申请人姓名
|
|
|
String applyer = infoJson.getString("applyer");
|
|
|
String userId = JSONObject.parseObject(applyer).getString("userid");
|
|
|
- User user = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_userid", userId));
|
|
|
- if(user == null){
|
|
|
- System.out.println("申请人WxId查询不到");
|
|
|
- continue;
|
|
|
- }
|
|
|
- String name = user.getName();
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_real_userid", userId));
|
|
|
+ String name = user==null?userId:user.getName();
|
|
|
//审批人姓名
|
|
|
- Object[] sp_record = infoJson.getJSONArray("sp_record").toArray();
|
|
|
- Object[] details = JSONObject.parseObject(sp_record[0].toString()).getJSONArray("details").toArray();
|
|
|
- String approver = JSONObject.parseObject(details[0].toString()).getString("approver");
|
|
|
- String approverUserId = JSONObject.parseObject(approver).getString("userid");
|
|
|
- User approverUser = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_userid", approverUserId));
|
|
|
- if(approverUser == null){
|
|
|
- System.out.println("审批人WxId为空");
|
|
|
- continue;
|
|
|
+ String approverUserId = infoJson.getJSONArray("sp_record").getJSONObject(0)
|
|
|
+ .getJSONArray("details").getJSONObject(0)
|
|
|
+ .getJSONObject("approver").getString("userid");
|
|
|
+ User approverUser = new User();
|
|
|
+ if (approverUserId!=null&&approverUserId!=""){
|
|
|
+ approverUser = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_real_userid", approverUserId));
|
|
|
}
|
|
|
- String approverName = approverUser.getName();
|
|
|
+ String approverName = approverUser==null?approverUserId:approverUser.getName();
|
|
|
+ JSONArray contents = infoJson.getJSONObject("apply_data")
|
|
|
+ .getJSONArray("contents");
|
|
|
//请假类型
|
|
|
- String apply_data = infoJson.getString("apply_data");
|
|
|
- Object[] contents = JSONObject.parseObject(apply_data).getJSONArray("contents").toArray();
|
|
|
- String value = JSONObject.parseObject(contents[0].toString()).getString("value");
|
|
|
- String remarkValue = JSONObject.parseObject(contents[1].toString()).getString("value");
|
|
|
- String remark = JSONObject.parseObject(remarkValue).getString("text");
|
|
|
- String vacation = JSONObject.parseObject(value).getString("vacation");
|
|
|
- String selector = JSONObject.parseObject(vacation).getString("selector");
|
|
|
- Object[] options = JSONObject.parseObject(selector).getJSONArray("options").toArray();
|
|
|
- Object[] values = JSONObject.parseObject(options[0].toString()).getJSONArray("value").toArray();
|
|
|
- String text = JSONObject.parseObject(values[0].toString()).getString("text");
|
|
|
+ JSONObject vacation = contents.getJSONObject(0)
|
|
|
+ .getJSONObject("value")
|
|
|
+ .getJSONObject("vacation");
|
|
|
+ String text = vacation.getJSONObject("selector")
|
|
|
+ .getJSONArray("options").getJSONObject(0)
|
|
|
+ .getJSONArray("value").getJSONObject(0)
|
|
|
+ .getString("text");
|
|
|
+ //请假事由
|
|
|
+ String remark = contents.getJSONObject(1).getJSONObject("value").getString("text");
|
|
|
Integer leave_type = 0;
|
|
|
switch (text){
|
|
|
case "事假":
|
|
@@ -975,39 +1066,40 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
break;
|
|
|
}
|
|
|
//请假开始时间
|
|
|
- String attendance = JSONObject.parseObject(vacation).getString("attendance");
|
|
|
- String date_range = JSONObject.parseObject(attendance).getString("date_range");
|
|
|
- String startDate = JSONObject.parseObject(date_range).getString("new_begin");
|
|
|
+ JSONObject date_range = vacation.getJSONObject("attendance")
|
|
|
+ .getJSONObject("date_range");
|
|
|
+ String startDate =date_range.getString("new_begin");
|
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
|
|
long startDateTemp = Long.valueOf(startDate);
|
|
|
String startDateString = sdf.format(new Date(startDateTemp * 1000L));
|
|
|
DateTimeFormatter startfmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
LocalDate sDate = LocalDate.parse(startDateString, startfmt);
|
|
|
//请假结束时间
|
|
|
- String endDate = JSONObject.parseObject(date_range).getString("new_end");
|
|
|
+ String endDate = date_range.getString("new_end");
|
|
|
long endDatetemp = Long.valueOf(endDate);
|
|
|
String endDateString = sdf.format(new Date(endDatetemp * 1000L));
|
|
|
DateTimeFormatter endfmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
LocalDate eDate = LocalDate.parse(endDateString, endfmt);
|
|
|
//请假时长
|
|
|
- String timeHours = JSONObject.parseObject(date_range).getString("new_duration");
|
|
|
- String leaveType = JSONObject.parseObject(date_range).getString("type");
|
|
|
+ String timeHours = date_range.getString("new_duration");
|
|
|
+ String leaveType = date_range.getString("type");
|
|
|
LeaveSheet leaveSheet = new LeaveSheet();
|
|
|
+ leaveSheet.setProcinstId(sp_no_lists[i].toString());
|
|
|
leaveSheet.setIsFinalAudit(1);
|
|
|
leaveSheet.setIndate(applyTime);
|
|
|
leaveSheet.setOwnerName(name);
|
|
|
- leaveSheet.setOwnerId(user.getId());
|
|
|
+ leaveSheet.setOwnerId(user==null?"":user.getId());
|
|
|
leaveSheet.setCompanyId(user.getCompanyId());
|
|
|
leaveSheet.setTel(user.getPhone()==null?"":user.getPhone());
|
|
|
//审批人信息
|
|
|
leaveSheet.setAuditorName(approverName);
|
|
|
- leaveSheet.setAuditorId(approverUser.getId());
|
|
|
+ leaveSheet.setAuditorId(approverUser==null?"":approverUser.getId());
|
|
|
//请假日期
|
|
|
leaveSheet.setStartDate(sDate);
|
|
|
leaveSheet.setEndDate(eDate);
|
|
|
//请假类型
|
|
|
leaveSheet.setLeaveType(leave_type);
|
|
|
- leaveSheet.setStatus(0);
|
|
|
+ leaveSheet.setStatus(sp_status);
|
|
|
//请假说明
|
|
|
leaveSheet.setRemark(remark==null?"":remark);
|
|
|
//请假时长和天数
|
|
@@ -1020,24 +1112,21 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
|
|
|
leaveSheet.setTimeDays(time/3600/24);
|
|
|
}
|
|
|
result.add(leaveSheet);
|
|
|
- for (LeaveSheet sheet : result) {
|
|
|
- System.out.println(sheet);
|
|
|
- }
|
|
|
}else{
|
|
|
- System.out.println(sp_no_lists[i]+"审批单详情查询失败");
|
|
|
+ System.err.println(sp_no_lists[i]+"审批单详情查询失败");
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
fail.add(wxCorpInfo.getCorpFullName());
|
|
|
- System.out.println(wxCorpInfo.getCorpFullName()+"审批单查询失败");
|
|
|
+ System.err.println(wxCorpInfo.getCorpFullName()+"审批单查询失败");
|
|
|
}
|
|
|
}
|
|
|
if (fail.size() == 0){
|
|
|
- System.out.println("全部同步成功");
|
|
|
+ System.err.println("全部同步成功");
|
|
|
}else{
|
|
|
System.out.print("同步失败的公司有:");
|
|
|
for (String s : fail) {
|
|
|
- System.out.print(s+",");
|
|
|
+ System.err.print(s+",");
|
|
|
System.out.println();
|
|
|
}
|
|
|
}
|