同步考勤数据到黔送

This commit is contained in:
fl 2024-12-06 23:01:30 +08:00
parent bbce2e5a2b
commit 471762750e
6 changed files with 224 additions and 21 deletions

File diff suppressed because one or more lines are too long

View File

@ -32,7 +32,7 @@ public class BaseEntity implements Serializable
private String updateBy;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
private Date updateTime;
/** 备注 */

View File

@ -60,7 +60,7 @@ public class AttTasks {
private volatile boolean executed = false; // 标志位表示任务是否已经执行过
// @Scheduled(cron = "0 0/10 * * * ?")
// @Scheduled(fixedDelay = 60000 * 10)
@Scheduled(initialDelay = 60000 * 5,fixedDelay = 60000 * 10)
@Async
public void getAttTasks() {
log.info("--------考勤定时器开启------");

View File

@ -4,11 +4,15 @@ import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.bonus.common.core.utils.DateTimeHelper;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.FastJsonHelper;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.utils.encryption.AESCBCUtil;
import com.bonus.common.core.utils.encryption.AesCbcUtils;
import com.bonus.system.api.domain.SysUser;
import com.bonus.system.att.dao.AttGroupDao;
import com.bonus.system.att.dao.AttSourceDataDao;
@ -23,6 +27,7 @@ import com.bonus.system.evection.entity.EvectionBean;
import com.bonus.system.holiday.entity.HolidayBean;
import com.bonus.system.index.entity.MapBean;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.MappedPropertyDescriptor;
import org.mybatis.spring.SqlSessionTemplate;
@ -33,6 +38,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import javax.annotation.Resource;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -62,17 +68,14 @@ public class WechatTasks {
@Resource(name = "WechatPushDao")
private WechatPushDao dao;
@Resource(name = "sqlSessionTemplate")
private SqlSessionTemplate sqlSessionTemplate;
@Resource(name = "attGroupDao")
private AttGroupDao attGroupDao;
private String token;
/**
* 人员基础数据同步定时器
*/
// @Scheduled(cron = "0 0/10 * * * ?")
// @Scheduled(initialDelay = 1000 * 6,fixedDelay = 60000 * 10)
@Scheduled(initialDelay = 60000 * 1,fixedDelay = 60000 * 1)
@Async
public void pushPersonTask() {
log.info("--------人员基础数据同步定时器开启------");
@ -100,7 +103,7 @@ public class WechatTasks {
/**
* 休假出差数据同步定时器
*/
// @Scheduled(fixedDelay = 60000 * 10)
@Scheduled(initialDelay = 60000 * 2,fixedDelay = 60000 * 1)
@Async
public void leaveTask() {
log.info("--------休假出差数据定时器开启------");
@ -179,12 +182,11 @@ public class WechatTasks {
/**
* 考勤数据同步定时器
*/
@Scheduled(fixedDelay = 60000 * 10)
@Scheduled(initialDelay = 60000 * 3,fixedDelay = 60000 * 1)
@Async
public void wechatAttTask() {
log.info("--------考勤数据定时器开启------");
// //小程序库人员考勤
// List<AttSourceDataBean> attSourceList = dao.getWechatAttList();
String jsonStr = "{}";
String method = "getWechatAttList";
String string = httpPost(method, jsonStr);
@ -238,8 +240,10 @@ public class WechatTasks {
attSourceList.forEach(c -> {
if(c.getIdNumber() != null){
MapBean mapBean= dao.getProOrgToQsy(c);
c.setProId(mapBean.getProId());
c.setOrgId(String.valueOf(mapBean.getOrgId()));
if(mapBean != null){
c.setProId(mapBean.getProId());
c.setOrgId(String.valueOf(mapBean.getOrgId()));
}
}
});
//2.推送到人员考勤表
@ -329,16 +333,17 @@ public class WechatTasks {
private String httpPost(String method, String jsonStr) {
try {
HttpResponse response = HttpRequest.post(IpAndPathConfig.getWechatUrl() + "/" + method)
.header("Content-Type", "application/json")
.body(jsonStr)
.execute();
// HttpResponse response = HttpRequest.post(IpAndPathConfig.getWechatUrl() + "/" + method)
// HttpResponse response = HttpRequest.post(IpAndPathConfig.getWechatUrl() + "/wechatData/" + method)
// .header("Content-Type", "application/json")
// .header("Authorization",token) // 添加Token到请求头
// .body(jsonStr)
// .execute();
HttpResponse response = HttpRequest.post(IpAndPathConfig.getWechatUrl() + "/wechatData/" + method)
.header("Content-Type", "application/json")
.header("token",token) // 添加Token到请求头
.body(jsonStr)
.execute();
int statusCode = response.getStatus();
System.out.println(response.body());
JSONObject jsonObject = FastJsonHelper.jsonStrToJsonObj(response.body());
return jsonObject.getString("obj");
} catch (Exception e) {
@ -381,4 +386,47 @@ public class WechatTasks {
}
@Scheduled(initialDelay = 1000,fixedDelay = 60000 * 10)
@Async
public void login() {
wechatLogin();
}
public void wechatLogin() {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = null;
try {
// body = RequestBody.create(mediaType, "username=15240004260&password=GZkq@123456!");
body = RequestBody.create(mediaType, "username="+ AESCBCUtil.encrypt("15240004260")+"&password="+AESCBCUtil.encrypt("GZkq@123456!"));
} catch (Exception e) {
throw new RuntimeException(e);
}
Request request = new Request.Builder()
.url(IpAndPathConfig.getWechatUrl() + "/login")
.method("POST", body)
.addHeader("Connection", "keep-alive")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
// 读取响应体为字符串
String responseBody = response.body().string();
// 使用FastJSON2解析JSON并映射到JSONObject
JSONObject jsonObject = JSON.parseObject(responseBody);
// 提取token字段
this.token = jsonObject.getString("token");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
String encrypt = AESCBCUtil.encrypt("GZkq@123456!");
System.out.println(encrypt);
}
}

View File

@ -277,10 +277,10 @@ public class SysUserController extends BaseController {
}
/**
* 审批项目部角色配置
* 配置
*/
@PostMapping("checkPersonAssignment")
@Log(title = "项目部管理->项目部角色管理->项目部角色审批", businessType = BusinessType.UPDATE)
@Log(title = "人员管理->人员管理->人脸审批", businessType = BusinessType.UPDATE)
public AjaxResult checkPersonAssignment(@RequestBody SysUser bean) {
try{
wechatTasks.checkWechatIsFace(bean);

View File

@ -74,7 +74,13 @@
</update>
<update id="checkPersonAssignment">
UPDATE sys_user_face SET `is_check` = #{isCheck}, `examine_opinion` = #{examineOpinion} WHERE `user_id` = #{userId}
UPDATE sys_user_face SET
`is_check` = #{isCheck},
`examine_opinion` = #{examineOpinion}
WHERE `user_id` = #{userId};
<if test='isCheck == 1'>
update sys_user set is_face = 0 where user_id = #{userId}
</if>
</update>
<select id="selectUserByUserName" resultType="com.bonus.system.api.domain.SysUser">