jhprjv2/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/AttendanceJgwTask.java

1182 lines
48 KiB
Java

package com.ruoyi.quartz.task;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.sign.Md5Utils;
import com.ruoyi.quartz.domain.*;
import com.ruoyi.quartz.service.*;
import okhttp3.*;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Component("attendanceJgwTask")
public class AttendanceJgwTask {
@Autowired
private RedisCache redisCache;
@Autowired
private ISysNativeService sysNativeService;
@Autowired
IQuartzProjectAttendanceUserService attendanceUserService;
@Autowired
IQuartzProjectAttendanceCfgService attendanceCfgService;
@Autowired
IQuartzProjectAttendanceDataService attendanceDataService;
@Autowired
IQuartzProjectAttendanceGroupService attendanceGroupService;
private String getNative(long id){
String ckey="attendance_jgw_native_"+id;
Object obj=redisCache.getCacheObject(ckey);
String tmp="";
if(obj!=null){
tmp=obj.toString();
if(StrUtil.isNotEmpty(tmp)){
return tmp;
}
}
List<SysNative> list=sysNativeService.selectSysNativeListById(id);
if(list.size()==0){
id=id/100*100;
list=sysNativeService.selectSysNativeListById(id);
if(list.size()==0){
id=id/10000*10000;
list=sysNativeService.selectSysNativeListById(id);
}
}
if(list.size()==0){
tmp="";
}else{
tmp= list.get(0).getAddress();
}
redisCache.setCacheObject(ckey, tmp, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.DAYS);
return tmp;
}
private String getWorkTypeName(String appid,String token,String type,String key){
String ckey="attendance_jgw_work_type_"+type;
Object obj=redisCache.getCacheObject(ckey);
HashMap<String,String> map=null;
if(obj==null){
map=getJobTypeData(appid,token,type);
if(map!=null){
redisCache.setCacheObject(ckey, map, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.DAYS);
}else{
return "未知";
}
}else{
map=(HashMap<String,String>)obj;
}
if(map.containsKey(key)){
return map.get(key);
}
return "未知";
}
static String host="http://api.gongyoumishu.com:80/gomeetapi/";
//sign/photo/20240101/E24E76-C9A5CB-0000FF/1741751233297383424_8848.JPG
public static String getToken(String appid,String secret){
String grantType="client_credential";
String path="/webapi/credential";
Map<String, Object> params = new HashMap<>();
params.put("appId",appid);
params.put("secret",secret);
params.put("grantType",grantType);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject jo= JSON.parseObject(data);
JSONObject joData= jo.getJSONObject("data");
if(joData!=null){
return joData.getString("token");
}
return null;
}
private static RequestBody toFormBody(Map<String, Object> params ){
FormBody.Builder builder=new FormBody.Builder();
for(String key :params.keySet()){
builder.add(key,params.get(key).toString());
}
return builder.build();
}
public void clearAlllPhoto(){
String filePath= RuoYiConfig.getUploadPath();
String path=filePath+"/jgw";
long endTime=DateUtil.current();
for(int i=365;i>=0;i--) {
Date dt = DateUtil.date(endTime - 3600l * 1000 * 24 * i);
String clearPath=path +"/" + DateUtil.format(dt, "YYYY/MM/dd");
String url="/jgw/"+DateUtil.format(dt, "YYYY/MM/dd");
clearDatePhone(clearPath,url);
}
}
public void clear3DayPhoto(){
String filePath= RuoYiConfig.getUploadPath();
String path=filePath+"/jgw";
long endTime=DateUtil.current();
for(int i=3;i>=0;i--) {
Date dt = DateUtil.date(endTime - 3600l * 1000 * 24 * i);
String clearPath=path +"/" + DateUtil.format(dt, "YYYY/MM/dd");
String url="/jgw/"+DateUtil.format(dt, "YYYY/MM/dd");
clearDatePhone(clearPath,url);
}
}
public void clearToDayPhoto(){
String filePath= RuoYiConfig.getUploadPath();
String path=filePath+"/jgw";
long endTime=DateUtil.current();
Date dt = new Date();
String clearPath=path +"/" + DateUtil.format(dt, "YYYY/MM/dd");
String url="/jgw/"+DateUtil.format(dt, "YYYY/MM/dd");
clearDatePhone(clearPath,url);
}
private void clearDatePhone(String path,String url){
File file=new File(path);
if(file.isDirectory()){
QuartzProjectAttendanceData where=new QuartzProjectAttendanceData();
where.setScanPhoto(url);
List<QuartzProjectAttendanceData> list=attendanceDataService.selectSurProjectAttendanceDataList(where);
List<String> names=new ArrayList<>();
for(QuartzProjectAttendanceData it:list){
names.add(it.getScanPhoto());
}
for(String f : file.list()){
try{
String name= FileUtils.getName(f);
if(!findInNames(names,name)){
FileUtil.del(path+"/"+f);
}
}catch (Exception ex){
}
}
}
}
private boolean findInNames(List<String> names, String name) {
for(String it :names){
if(it.indexOf(name)>=0){
return true;
}
}
return false;
}
public static void main(String[] args){
String d="sxyzxx2024suc";
System.out.println(Base64.encode(d));
System.out.println(DateTime.now().year());
String appid="6a6f24fe35b04ee0bcf31cfb46ed1051";
String secret="c3h5enh4MjAyNHN1Yw==";
//String prjId="db955e11ef774e63968a47c3dc2acc15";//"b67f1baa6dca4558a16bf90a4681b82e";//
//String prjId="cace2f676371427e8f6da20d2924f64e";//泾河新城荟锦坊二期
String prjId="209aa0c01d8248b6a56a0921d1b88c83";//泾河新城锦樾坊项目
String phone="15619028761";
String token= getToken(appid,secret);
if(token==null || token.length()==0){
return;
}
System.out.println(token);
System.out.println(DateUtil.format(DateTime.now(),"yyyy-MM-dd"));
String subcontractorId=new AttendanceJgwTask().getSubcontractor(appid,token,phone);
String leaderTeamId="b3774a8cd04c418dabf36bffbf276661";
System.out.println(subcontractorId);
//findWorkerByLeader(appid,token,leaderTeamId);
findDirectlyUnderTeam(appid,token,prjId,subcontractorId,0);
//queryProject(appid,token,phone,0);;
//findAddWorkerByProject(appid,token,prjId,0);
//findUpdateWorkerByProject(appid,token,prjId,0);
//findAttendanceByProject(appid,token,prjId,"0");
//findTeamByProjectId(appid,token,prjId);
//findProContractorByProjectId(appid,token,prjId);
//getJobTypeData(appid,token,"0");
//findDirectlyUnderTeam(appid,token,prjId);
}
public static void findDirectlyUnderTeam(String appId,String token,String projectId,String subcontractorId,int rowId){
String path="/webapi/project/findDirectlyUnderTeam";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
System.out.println(url);
String tokenSign = Md5Utils.hash(url);
System.out.println(tokenSign);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("subcontractorId",subcontractorId);
params.put("rowId",rowId);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
System.out.println(data);
JSONObject j= JSON.parseObject(data);
JSONObject jd=j.getJSONObject("data");
JSONArray arr=jd.getJSONArray("teamList");
if(arr.size()>0){
for(int i=0;i<arr.size();i++){
JSONObject jo=arr.getJSONObject(i);
System.out.println("-->"+jo.getString("teamName"));
}
}
}
public static void queryProject(String appId,String token,String phone,int rowId){
String path="/webapi/project/queryProject";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
System.out.println(url);
String tokenSign = Md5Utils.hash(url);
System.out.println(tokenSign);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("account",phone);
params.put("rowId",rowId);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
System.out.println(data);
JSONObject j= JSON.parseObject(data);
JSONObject jd=j.getJSONObject("data");
JSONArray arr=jd.getJSONArray("projectList");
if(arr.size()>0){
JSONObject jo=arr.getJSONObject(0);
}
}
public String getSubcontractor(String appId,String token,String phone){
String ckey = "attendance_jgw_Subcontractor_" + phone;
if(redisCache!=null) {
Object obj = redisCache.getCacheObject(ckey);
if(obj!=null){
String str=(String)obj;
if(StrUtil.isNotEmpty(str)){
return str;
}
}
}
String path="/webapi/project/querySubcontractorByPhone";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
System.out.println(url);
String tokenSign = Md5Utils.hash(url);
System.out.println(tokenSign);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("phone",phone);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
System.out.println(data);
JSONObject j= JSON.parseObject(data);
JSONObject jd=j.getJSONObject("data");
JSONArray arr=jd.getJSONArray("subcontractorList");
if(arr.size()>0){
JSONObject jo=arr.getJSONObject(0);
String tmp=jo.getString("subcontractorId");
if(StrUtil.isNotEmpty(tmp) && redisCache!=null){
redisCache.setCacheObject(ckey, tmp, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.DAYS);
return tmp;
}else{
return tmp;
}
}
return "";
}
public static HashMap<String,String> getJobTypeData(String appId,String token,String type){
String path="/webapi/dictInfo/getJobTypeData";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
System.out.println(url);
String tokenSign = Md5Utils.hash(url);
System.out.println(tokenSign);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("type",type);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
System.out.println(data);
JSONObject j= JSON.parseObject(data);
JSONObject jd=j.getJSONObject("data");
JSONArray arr=jd.getJSONArray("jobTypes");
HashMap<String,String> map=new HashMap<>();
for(int i=0;i<arr.size();i++){
JSONObject jo=arr.getJSONObject(i);
String code=jo.getString("dictCode");
String value=jo.getString("dictValue");
map.put(code,value);
}
return map;
}
public static void findAttendanceByProject(String appId,String token,String projectId,String startId){
String path="/webapi/project/findAttendanceByProject";
String time = System.currentTimeMillis() + "";
//String startId="0";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
System.out.println(url);
String tokenSign = Md5Utils.hash(url);
System.out.println(tokenSign);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("startId",startId);
params.put("startTime",DateUtil.format(DateTime.now(),"yyyy-MM-dd"));
params.put("endTime",DateUtil.format(DateUtil.offsetDay(DateTime.now(),0),"yyyy-MM-dd"));
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
System.out.println(data);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
String endId= joData.getString("endId");
JSONArray arr=joData.getJSONArray("workerAttList");
if(arr!=null && arr.size()>0){
for(int i=0;i<arr.size();i++) {
JSONObject json = arr.getJSONObject(i);
String photo=json.getString("signimg");
System.out.println(json.getString("machineType"));
String photoUrl=getPhoto(appId,token,photo);
QuartzProjectAttendanceData sdata = QuartzProjectAttendanceData.createFromJgw(json);
if(sdata.getWorkerId().equals("63e0e09858624979b97291977afe352b")){
System.out.println("--->"+sdata.getRemark());
}
//sdata.setScanPhoto(photoUrl);
}
findAttendanceByProject(appId,token,projectId,endId);
}
}
private static String getPhoto(String appId,String token, String photo) {
String path="/webapi/dictInfo/getPhoyoAllPaths";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("filePath",photo);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
String purl=joData.getString("result");
byte[] buffer= HttpUtil.downloadBytes(purl);
String filePath= RuoYiConfig.getUploadPath();
try {
String name=FileUtil.getName(photo);
return FileUtils.writeBytes(buffer, filePath+"/jgw",name);
}catch (Exception ex){
return "";
}
}
public static void findWorkerByLeader(String appId,String token,String leaderTeamId){
String path="/webapi/project/findWorkerByLeader";
String time = System.currentTimeMillis() + "";
String startId="0";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("leaderTeamId",leaderTeamId);
url=host+path;
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject jd=j.getJSONObject("data");
JSONArray arr=jd.getJSONArray("recordList");
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
if(json.getString("workerid").equals("56141214ea304fcc95a8098d3bafed0d")){
System.out.println("---1--");
}
}
}
public static void findProContractorByProjectId(String appId,String token,String projectId){
String path="/webapi/project/findProContractorByProjectId";
String time = System.currentTimeMillis() + "";
String startId="0";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("rowId",startId);
url=host+path+"?appId="+appId+"&tokenSign="+tokenSign+"&projectId="+projectId+"&timestamp="+time+"&rowId="+startId;
Request request = new Request.Builder()
.url(url)
.get()
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
JSONArray arr=joData.getJSONArray("proContractorList");
if(arr.size()>0){
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
System.out.println("-->"+json.getString("teamName"));
}
}
}
public static void findTeamByProjectId(String appId,String token,String projectId){
String path="webapi/project/findTeamByProjectId";
String time = System.currentTimeMillis() + "";
String startId="0";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("rowId",startId);
url=host+path+"?appId="+appId+"&tokenSign="+tokenSign+"&projectId="+projectId+"&timestamp="+time+"&rowId="+startId;
Request request = new Request.Builder()
.url(url)
.get()
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
JSONArray arr=joData.getJSONArray("teamList");
if(arr.size()>0){
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
QuartzProjectAttendanceGroup group= QuartzProjectAttendanceGroup.createJgw(json,false);
group.setBizLicense(json.getString("corpCode"));
String type=json.getString("corpType");
if("009".equals(type)){ //总包人员
group.setCompanyTypeId("1");
}else if("007".equals(type)){//监理人员
group.setCompanyTypeId("8");
}else if("006".equals(type)){//劳务人员
group.setCompanyTypeId("2");
}
if(StrUtil.isNotEmpty(group.getCompanyTypeId())){
}
}
}
}
public static void querySubcontractorByPhone(String appId,String token,String projectId){
String path="webapi/project/querySubcontractorByPhone";
String time = System.currentTimeMillis() + "";
String startId="100";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
String phone = "18171295380";
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("phone",phone);
url=host+path+"?appId="+appId+"&tokenSign="+tokenSign+"&phone="+phone+"&timestamp="+time;
Request request = new Request.Builder()
.url(url)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
JSONArray arr=joData.getJSONArray("teamList");
if(arr.size()>0){
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
QuartzProjectAttendanceGroup group= QuartzProjectAttendanceGroup.createJgw(json,true);
group.setBizLicense(json.getString("corpCode"));
String type=json.getString("corpType");
if("009".equals(type)){ //总包人员
group.setCompanyTypeId("1");
}else if("007".equals(type)){//监理人员
group.setCompanyTypeId("8");
}else if("006".equals(type)){//劳务人员
group.setCompanyTypeId("2");
}
if(StrUtil.isNotEmpty(group.getCompanyTypeId())){
}
}
}
}
public static void findDirectlyUnderTeam(String appId,String token,String projectId){
String path="webapi/project/findDirectlyUnderTeam";
String time = System.currentTimeMillis() + "";
String startId="0";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("subcontractorld","ddcffe48c6a7413a91bbf6eafbf037a9");
params.put("rowId",0);
url=host+path+"?appId="+appId+"&tokenSign="+tokenSign+"&projectId="+projectId+"&timestamp="+time+"&subcontractorld="+params.get("subcontractorld").toString()+"&rowId="+startId;
Request request = new Request.Builder()
.url(url)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
JSONArray arr=joData.getJSONArray("teamList");
if(arr.size()>0){
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
QuartzProjectAttendanceGroup group= QuartzProjectAttendanceGroup.createJgw(json,true);
group.setBizLicense(json.getString("corpCode"));
String type=json.getString("corpType");
if("009".equals(type)){ //总包人员
group.setCompanyTypeId("1");
}else if("007".equals(type)){//监理人员
group.setCompanyTypeId("8");
}else if("006".equals(type)){//劳务人员
group.setCompanyTypeId("2");
}
if(StrUtil.isNotEmpty(group.getCompanyTypeId())){
}
}
}
}
public static void findAddWorkerByProject(String appId,String token,String projectId,int startId){
String path="/webapi/project/findAddWorkerByProject";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("startId",startId);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject jo= JSON.parseObject(data);
JSONObject joData= jo.getJSONObject("data");
int endId= joData.getInteger("endId");
JSONArray arr=joData.getJSONArray("workerList");
if(arr.size()>0) {
int cnt=0;
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
String idNumber=json.getString("idNumber");
if(StrUtil.isEmpty(idNumber)){
String a="xx";
}else{
}
String workerStatus= json.getString("workerStatus");
if("02".equals(workerStatus)){
cnt++;
}
QuartzProjectAttendanceUser user= QuartzProjectAttendanceUser.createFromJgw(json);
if(user.getName().equals("唐红吉")){
String k=user.getName();
JSONArray arr2= json.getJSONArray("corpName");
Object o=arr2.get(0);
}
}
System.out.println("cnt:"+cnt+","+arr.size());
findAddWorkerByProject(appId, token, projectId, endId);
}
}
public static void findUpdateWorkerByProject(String appId,String token,String projectId,int startId){
String path="/webapi/project/findUpdateWorkerByProject";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("updateTime","2024-01-01 00:00:00");
//params.put("startId",startId);
params.put("startId","32150708");
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject jo= JSON.parseObject(data);
JSONObject joData= jo.getJSONObject("data");
//int endId= joData.getInteger("endId");
JSONArray arr=joData.getJSONArray("workerList");
if(arr.size()>0) {
int cnt=0;
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
String workerStatus= json.getString("workerStatus");
if("02".equals(workerStatus)){
cnt++;
}
QuartzProjectAttendanceUser user= QuartzProjectAttendanceUser.createFromJgw(json);
if(user.getName().equals("李文国")){
String k=user.getName();
JSONArray arr2= json.getJSONArray("corpName");
Object o=arr2.get(0);
}
}
System.out.println("cnt:"+cnt+","+arr.size());
//findAddWorkerByProject(appId, token, projectId, endId);
}
}
/**
* 同步人员信息
*/
public void syncWorker(){
QuartzProjectAttendanceCfg where =new QuartzProjectAttendanceCfg();
where.setEnabled(1l);
where.setIsDel(0l);
where.setVendorsCode("jgw");
List<QuartzProjectAttendanceCfg> list=attendanceCfgService.selectSurProjectAttendanceCfgList(where);
for(QuartzProjectAttendanceCfg it :list){
String param= it.getVendorsParameter();
if(Strings.isNotEmpty(param)){
try{
JSONObject jo=JSON.parseObject(param);
String appId=jo.getString("appId");
String secret=jo.getString("secret");
secret=Base64.encode(secret);
jo.put("secret",secret);
String token= getToken(appId,secret);
jo.put("token",token);
doSyncWorker(jo,0l,it);
}catch (Exception ex){
ex.printStackTrace();
}
}
}
syncWorkerByLeader();
}
/**
* 同步群组和人的关系
*/
public void syncWorkerByLeader(){
QuartzProjectAttendanceCfg where =new QuartzProjectAttendanceCfg();
where.setEnabled(1l);
where.setIsDel(0l);
where.setVendorsCode("jgw");
List<QuartzProjectAttendanceCfg> list=attendanceCfgService.selectSurProjectAttendanceCfgList(where);
for(QuartzProjectAttendanceCfg it :list){
String param= it.getVendorsParameter();
if(Strings.isNotEmpty(param)){
try{
JSONObject jo=JSON.parseObject(param);
String appId=jo.getString("appId");
String secret=jo.getString("secret");
secret=Base64.encode(secret);
jo.put("secret",secret);
String token= getToken(appId,secret);
jo.put("token",token);
QuartzProjectAttendanceGroup groupWhere=new QuartzProjectAttendanceGroup();
groupWhere.setCfgid(it.getId());
groupWhere.setLeaderPhone("directly");
List<QuartzProjectAttendanceGroup> groupList=attendanceGroupService.selectSurProjectAttendanceGroupList(groupWhere);
for(QuartzProjectAttendanceGroup g:groupList) {
if(StrUtil.isNotEmpty(g.getLeaderName()) && StrUtil.isNotEmpty(g.getCompanyId())) {
jo.put("subcontractorId", g.getLeaderName());
jo.put("leaderTeamId", g.getCompanyId());
jo.put("companyName", g.getCompanyName());
dosyncWorkerByLeader(jo, 0l, it);
}
}
}catch (Exception ex){
ex.printStackTrace();
}
}
}
}
private void dosyncWorkerByLeader(JSONObject jo, long startId, QuartzProjectAttendanceCfg it){
String appId=jo.getString("appId");
String token=jo.getString("token");
String path="/webapi/project/findWorkerByLeader";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String leaderTeamId=jo.getString("leaderTeamId");
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("leaderTeamId",leaderTeamId);
params.put("subcontractorId",jo.getString("subcontractorId"));
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject jd=j.getJSONObject("data");
JSONArray arr=jd.getJSONArray("recordList");
if(arr!=null && arr.size()>0){
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
String workerId=json.getString("workerId");
QuartzProjectAttendanceUser userWhere=new QuartzProjectAttendanceUser();
userWhere.setWorkerId(workerId);
userWhere.setCfgid(it.getId());
List<QuartzProjectAttendanceUser> userList=attendanceUserService.selectSurProjectAttendanceUserList(userWhere);
if(userList.size()>0){
QuartzProjectAttendanceUser upUser=userList.get(0);
upUser.setCompanyId(json.getString("leaderTeamId"));
upUser.setWorkTypeName(json.getString("jobType"));
upUser.setCompanyName(jo.getString("companyName"));
attendanceUserService.updateSurProjectAttendanceUser(upUser);
}
}
}
}
private void doSyncWorker(JSONObject jo, long startId, QuartzProjectAttendanceCfg it) {
String appId=jo.getString("appId");
String token=jo.getString("token");
String projectId=jo.getString("projectId");
String path="/webapi/project/findAddWorkerByProject";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("startId",startId);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
long endId= joData.getLong("endId");
JSONArray arr=joData.getJSONArray("workerList");
if(arr.size()>0) {
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
QuartzProjectAttendanceUser user= QuartzProjectAttendanceUser.createFromJgw(json);
user.setVendorsCode(it.getVendorsCode());
user.setCfgid(it.getId());
user.setAppId(appId);
String idNumber=json.getString("idNumber");//身份证
if(StrUtil.isNotEmpty(idNumber) && idNumber.length()>6){
try {
long idStr = Long.parseLong(idNumber.substring(0, 6));
String natstr=getNative(idStr);
if(StrUtil.isNotEmpty(natstr)){
user.setNativePlace(natstr);
}
}catch (Exception ex){
}
}
attendanceUserService.add(user);
}
doSyncWorker(jo,endId,it);
}
}
/**
* 同步群组信息
*/
public void syncGroup(){
QuartzProjectAttendanceCfg where =new QuartzProjectAttendanceCfg();
where.setEnabled(1l);
where.setIsDel(0l);
where.setVendorsCode("jgw");
List<QuartzProjectAttendanceCfg> list=attendanceCfgService.selectSurProjectAttendanceCfgList(where);
for(QuartzProjectAttendanceCfg it :list){
String param= it.getVendorsParameter();
if(Strings.isNotEmpty(param)){
try{
JSONObject jo=JSON.parseObject(param);
String appId=jo.getString("appId");
String secret=jo.getString("secret");
secret=Base64.encode(secret);
jo.put("secret",secret);
String token= getToken(appId,secret);
jo.put("token",token);
//doSyncGroup(jo,0l,it);
doSyncDirectlyUnderGroup(jo,0l,it);
doSyncProContractor(jo,0l,it);
}catch (Exception ex){
ex.printStackTrace();
}
}
}
}
/**
* 查询参建单位
* @param jo
* @param startId
* @param it
*/
private void doSyncProContractor(JSONObject jo, long startId, QuartzProjectAttendanceCfg it) {
String appId=jo.getString("appId");
String token=jo.getString("token");
String projectId=jo.getString("projectId");
String path="/webapi/project/findProContractorByProjectId";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("rowId",startId);
url=host+path+"?appId="+appId+"&tokenSign="+tokenSign+"&projectId="+projectId+"&timestamp="+time+"&rowId="+startId;
Request request = new Request.Builder()
.url(url)
.get()
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
JSONArray arr=joData.getJSONArray("proContractorList");
if(arr.size()>0){
long rowId=0;
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
rowId=json.getLong("id");
QuartzProjectAttendanceGroup group= QuartzProjectAttendanceGroup.createJgw(json,true);
group.setBizLicense(json.getString("corpCode"));
String type=json.getString("corpType");
if("009".equals(type)){ //总包人员
group.setCompanyTypeId("1");
}else if("007".equals(type)){//监理人员
group.setCompanyTypeId("8");
}else if("006".equals(type)){//劳务人员
group.setCompanyTypeId("2");
}else{
group.setCompanyTypeId("0");
}
if(StrUtil.isNotEmpty(group.getCompanyTypeId())){
attendanceGroupService.updateJgw(group);
}
}
if(rowId>0){
doSyncProContractor(jo,rowId+1,it);
}
}
}
/**
* 查询班组直隶
* @param jo
* @param startId
* @param it
*/
private void doSyncDirectlyUnderGroup(JSONObject jo, long startId, QuartzProjectAttendanceCfg it) {
String appId=jo.getString("appId");
String token=jo.getString("token");
String projectId=jo.getString("projectId");
String phone=jo.getString("phone");
String subcontractorId=getSubcontractor(appId,token,phone);
String path="/webapi/project/findDirectlyUnderTeam";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("subcontractorId",subcontractorId);
params.put("rowId",startId);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
JSONArray arr=joData.getJSONArray("teamList");
if(arr.size()>0){
long rowId=0;
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
QuartzProjectAttendanceGroup group= QuartzProjectAttendanceGroup.createJgw(json,true);
group.setCfgid(it.getId());
group.setAppId(appId);
rowId=json.getLong("id");
QuartzProjectAttendanceGroup where=new QuartzProjectAttendanceGroup();
where.setCompanyId(group.getCompanyId());
where.setCfgid(group.getCfgid());
List<QuartzProjectAttendanceGroup> list=attendanceGroupService.selectSurProjectAttendanceGroupList(where);
if(list.size()==0){
attendanceGroupService.add(group);
}else{
group.setId(list.get(0).getId());
attendanceGroupService.updateSurProjectAttendanceGroup(group);
}
}
if(rowId>0){
doSyncDirectlyUnderGroup(jo,rowId+1,it);
}
}
}
/**
* 查询班组
* @param jo
* @param startId
* @param it
*/
private void doSyncGroup(JSONObject jo, long startId, QuartzProjectAttendanceCfg it) {
String appId=jo.getString("appId");
String token=jo.getString("token");
String projectId=jo.getString("projectId");
String path="/webapi/project/findTeamByProjectId";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("rowId",startId);
url=host+path+"?appId="+appId+"&tokenSign="+tokenSign+"&projectId="+projectId+"&timestamp="+time+"&rowId="+startId;
Request request = new Request.Builder()
.url(url)
.get()
.build();
String data=AttendanceTask.getResult(request);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
JSONArray arr=joData.getJSONArray("teamList");
if(arr.size()>0){
long rowId=0;
for(int i=0;i<arr.size();i++){
JSONObject json=arr.getJSONObject(i);
QuartzProjectAttendanceGroup group= QuartzProjectAttendanceGroup.createJgw(json,false);
group.setCfgid(it.getId());
group.setAppId(appId);
rowId=json.getLong("id");
QuartzProjectAttendanceGroup where=new QuartzProjectAttendanceGroup();
where.setCompanyId(group.getCompanyId());
where.setCfgid(group.getCfgid());
List<QuartzProjectAttendanceGroup> list=attendanceGroupService.selectSurProjectAttendanceGroupList(where);
if(list.size()==0){
attendanceGroupService.add(group);
}
}
if(rowId>0){
doSyncGroup(jo,rowId+1,it);
}
}
}
/**
* 同步当天数据
*/
public void syncAttendanceData(){
String dtStart=DateUtil.format(DateTime.now(),"yyyy-MM-dd");
String dtEnd=dtStart;
syncAttendanceData(dtStart,dtEnd);
clearToDayPhoto();
}
/**
* 同步7天之内数据
*/
public void syncLastWeekAttendanceData(){
String dtEnd=DateUtil.format(DateTime.now(),"yyyy-MM-dd");
String dtStart=DateUtil.format(DateUtil.offsetDay(DateTime.now(),-7),"yyyy-MM-dd");
syncAttendanceData(dtStart,dtEnd);
}
/**
* 同步30天内数据
*/
public void syncLast30DayAttendanceData(){
String dtEnd=DateUtil.format(DateTime.now(),"yyyy-MM-dd");
String dtStart=DateUtil.format(DateUtil.offsetDay(DateTime.now(),-30),"yyyy-MM-dd");
syncAttendanceData(dtStart,dtEnd);
syncAttendanceData(dtStart,dtEnd);
}
private void syncAttendanceData(String dtStart,String dtEnd){
QuartzProjectAttendanceCfg where =new QuartzProjectAttendanceCfg();
where.setEnabled(1l);
where.setIsDel(0l);
where.setVendorsCode("jgw");
List<QuartzProjectAttendanceCfg> list=attendanceCfgService.selectSurProjectAttendanceCfgList(where);
for(QuartzProjectAttendanceCfg it :list){
String param= it.getVendorsParameter();
if(Strings.isNotEmpty(param)){
try{
JSONObject jo=JSON.parseObject(param);
String appId=jo.getString("appId");
String secret=jo.getString("secret");
secret=Base64.encode(secret);
jo.put("secret",secret);
String token= getToken(appId,secret);
jo.put("token",token);
jo.put("startTime",dtStart);
jo.put("endTime",dtEnd);
doSyncAttendanceData(jo,"0",it);
}catch (Exception ex){
ex.printStackTrace();
}
}
}
}
private void doSyncAttendanceData(JSONObject jo, String startId, QuartzProjectAttendanceCfg it) {
String appId=jo.getString("appId");
String token=jo.getString("token");
String projectId=jo.getString("projectId");
String startTime=jo.getString("startTime");
String endTime=jo.getString("endTime");
String path="/webapi/project/findAttendanceByProject";
String time = System.currentTimeMillis() + "";
String url=host+path+"?appId=" + appId + "&tokenSign=" + token +"&timestamp=" + time;
String tokenSign = Md5Utils.hash(url);
Map<String, Object> params = new HashMap<>();
params.put("appId",appId);
params.put("timestamp",time);
params.put("tokenSign",tokenSign);
params.put("projectId",projectId);
params.put("startId",startId);
params.put("startTime",startTime);
params.put("endTime",endTime);
Request request = new Request.Builder()
.url(host+path)
.post(toFormBody(params))
.build();
String data=AttendanceTask.getResult(request);
System.out.println(data);
JSONObject j= JSON.parseObject(data);
JSONObject joData= j.getJSONObject("data");
String endId= joData.getString("endId");
JSONArray arr=joData.getJSONArray("workerAttList");
//List<SurProjectAttendanceData> addList=new ArrayList<>();
if(arr!=null && arr.size()>0){
for(int i=0;i<arr.size();i++) {
JSONObject json = arr.getJSONObject(i);
String photo=json.getString("signimg");
String photoUrl=getPhoto(appId,token,photo);
QuartzProjectAttendanceData sdata = QuartzProjectAttendanceData.createFromJgw(json);
sdata.setScanPhoto(photoUrl);
sdata.setCfgid(it.getId());
sdata.setAppId(appId);
if(sdata.getWorkerId().equals("63e0e09858624979b97291977afe352b")){
System.out.println("--->"+sdata.getRemark());
}
sdata.setVendorsCode(it.getVendorsCode());
attendanceDataService.add(sdata);
//addList.add(sdata);
}
//attendanceDataService.addList(addList);
doSyncAttendanceData(jo,endId,it);
}
}
}