diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteUserService.java b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteUserService.java index 06377cb3..ba4efd25 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/RemoteUserService.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/RemoteUserService.java @@ -69,4 +69,8 @@ public interface RemoteUserService { /**部门基础数据数据**/ @PostMapping("/dept/sysDeptInfoTask") public R sysDeptInfoTask(); + + /**员工打卡数据**/ + @PostMapping("/user/clockInRecord") + public R sysClockInRecord(); } diff --git a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteUserFallbackFactory.java b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteUserFallbackFactory.java index 268de31e..c545a8e4 100644 --- a/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteUserFallbackFactory.java +++ b/op-api/op-api-system/src/main/java/com/op/system/api/factory/RemoteUserFallbackFactory.java @@ -61,6 +61,11 @@ public class RemoteUserFallbackFactory implements FallbackFactoryop-common-swagger + + + org.springframework.boot + spring-boot-starter-websocket + + + diff --git a/op-modules/op-device/src/main/java/com/op/device/DeviceApplication.java b/op-modules/op-device/src/main/java/com/op/device/DeviceApplication.java index dd898098..4509ade6 100644 --- a/op-modules/op-device/src/main/java/com/op/device/DeviceApplication.java +++ b/op-modules/op-device/src/main/java/com/op/device/DeviceApplication.java @@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import com.op.common.security.annotation.EnableCustomConfig; import com.op.common.security.annotation.EnableRyFeignClients; import com.op.common.swagger.annotation.EnableCustomSwagger2; +import org.springframework.scheduling.annotation.EnableScheduling; /** * 系统模块 @@ -14,6 +15,7 @@ import com.op.common.swagger.annotation.EnableCustomSwagger2; @EnableCustomConfig @EnableCustomSwagger2 @EnableRyFeignClients +@EnableScheduling @SpringBootApplication public class DeviceApplication { public static void main(String[] args) { diff --git a/op-modules/op-device/src/main/java/com/op/device/domain/EquRepairOrder.java b/op-modules/op-device/src/main/java/com/op/device/domain/EquRepairOrder.java index 5e584ed7..7cd6a312 100644 --- a/op-modules/op-device/src/main/java/com/op/device/domain/EquRepairOrder.java +++ b/op-modules/op-device/src/main/java/com/op/device/domain/EquRepairOrder.java @@ -182,6 +182,7 @@ public class EquRepairOrder extends BaseEntity { @Excel(name = "审核意见") private String auditOpinion; + /** * 计划维修时间 */ @@ -268,6 +269,16 @@ public class EquRepairOrder extends BaseEntity { private String orderTimeStart; private String orderTimeEnd; + private Equipment equipment; + + public Equipment getEquipment() { + return equipment; + } + + public void setEquipment(Equipment equipment) { + this.equipment = equipment; + } + //图片文件 public String getFileList() { return fileList; diff --git a/op-modules/op-device/src/main/java/com/op/device/mapper/EquRepairOrderMapper.java b/op-modules/op-device/src/main/java/com/op/device/mapper/EquRepairOrderMapper.java index 9c075237..55ca833a 100644 --- a/op-modules/op-device/src/main/java/com/op/device/mapper/EquRepairOrderMapper.java +++ b/op-modules/op-device/src/main/java/com/op/device/mapper/EquRepairOrderMapper.java @@ -4,10 +4,7 @@ import java.util.List; import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.domain.BaseFileData; -import com.op.device.domain.EquEquipment; -import com.op.device.domain.EquFile; -import com.op.device.domain.EquRepairOrder; -import com.op.device.domain.EquTeamUser; +import com.op.device.domain.*; import com.op.system.api.domain.SysNoticeGroup; import org.apache.ibatis.annotations.Param; @@ -113,4 +110,6 @@ public interface EquRepairOrderMapper { //查询公告绑定的班组 List getNoticesGroup(SysNoticeGroup noticeQo); + + Equipment selectEquInfoByequCode(Equipment equipment); } diff --git a/op-modules/op-device/src/main/java/com/op/device/schedul/MyWebSocketHandler.java b/op-modules/op-device/src/main/java/com/op/device/schedul/MyWebSocketHandler.java new file mode 100644 index 00000000..5dfb0e92 --- /dev/null +++ b/op-modules/op-device/src/main/java/com/op/device/schedul/MyWebSocketHandler.java @@ -0,0 +1,48 @@ +package com.op.device.schedul; + +import com.alibaba.fastjson2.JSON; +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import com.op.device.domain.EquRepairOrder; +import com.op.device.domain.Equipment; +import com.op.device.mapper.EquRepairOrderMapper; +import com.op.device.service.IEquRepairOrderService; +import com.op.device.websocket.WebSocketUsers; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +@EnableScheduling +public class MyWebSocketHandler extends TextWebSocketHandler { + + @Autowired + private EquRepairOrderMapper equRepairOrderMapper; + + + @Scheduled(fixedRate = 10000) // 每60秒执行一次 + @DS("ds_1000") + public void sendPeriodicMessages() { + EquRepairOrder equRepairOrder=new EquRepairOrder(); + equRepairOrder.setOrderStatus("2"); + List equRepairOrderList=equRepairOrderMapper.selectEquRepairOrderList(equRepairOrder); + Equipment equipment=new Equipment(); + List equRepairOrders=new ArrayList<>(); + for (EquRepairOrder repairOrder : equRepairOrderList) { + equipment.setEquipmentCode(repairOrder.getEquipmentCode()); + equipment=equRepairOrderMapper.selectEquInfoByequCode(equipment); + repairOrder.setEquipment(equipment); + equRepairOrders.add(repairOrder); + } + String jsonResult = JSON.toJSONString(equRepairOrders); + WebSocketUsers.sendMessageToUsersByText(jsonResult); + + } +} diff --git a/op-modules/op-device/src/main/java/com/op/device/service/impl/EquRepairOrderServiceImpl.java b/op-modules/op-device/src/main/java/com/op/device/service/impl/EquRepairOrderServiceImpl.java index 23528ba1..50b64e9f 100644 --- a/op-modules/op-device/src/main/java/com/op/device/service/impl/EquRepairOrderServiceImpl.java +++ b/op-modules/op-device/src/main/java/com/op/device/service/impl/EquRepairOrderServiceImpl.java @@ -603,4 +603,5 @@ public class EquRepairOrderServiceImpl implements IEquRepairOrderService { public List selectGroupLineList() { return equEquipmentMapper.selectEquipmentGroupLine(); } + } diff --git a/op-modules/op-device/src/main/java/com/op/device/websocket/SemaphoreUtils.java b/op-modules/op-device/src/main/java/com/op/device/websocket/SemaphoreUtils.java new file mode 100644 index 00000000..7d02c092 --- /dev/null +++ b/op-modules/op-device/src/main/java/com/op/device/websocket/SemaphoreUtils.java @@ -0,0 +1,58 @@ +package com.op.device.websocket; + +import java.util.concurrent.Semaphore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 信号量相关处理 + * + * @author ruoyi + */ +public class SemaphoreUtils +{ + /** + * SemaphoreUtils 日志控制器 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(SemaphoreUtils.class); + + /** + * 获取信号量 + * + * @param semaphore + * @return + */ + public static boolean tryAcquire(Semaphore semaphore) + { + boolean flag = false; + + try + { + flag = semaphore.tryAcquire(); + } + catch (Exception e) + { + LOGGER.error("获取信号量异常", e); + } + + return flag; + } + + /** + * 释放信号量 + * + * @param semaphore + */ + public static void release(Semaphore semaphore) + { + + try + { + semaphore.release(); + } + catch (Exception e) + { + LOGGER.error("释放信号量异常", e); + } + } +} diff --git a/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketConfig.java b/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketConfig.java new file mode 100644 index 00000000..84e173a8 --- /dev/null +++ b/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketConfig.java @@ -0,0 +1,20 @@ +package com.op.device.websocket; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +/** + * websocket 配置 + * + * @author ruoyi + */ +@Configuration +public class WebSocketConfig +{ + @Bean + public ServerEndpointExporter serverEndpointExporter() + { + return new ServerEndpointExporter(); + } +} diff --git a/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketServer.java b/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketServer.java new file mode 100644 index 00000000..1063d89d --- /dev/null +++ b/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketServer.java @@ -0,0 +1,106 @@ +package com.op.device.websocket; + +import java.util.concurrent.Semaphore; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * websocket 消息处理 + * + * @author ruoyi + */ +@Component +@ServerEndpoint("/websocket/message") +public class WebSocketServer +{ + /** + * WebSocketServer 日志控制器 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer.class); + + /** + * 默认最多允许同时在线人数100 + */ + public static int socketMaxOnlineCount = 100; + + private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount); + + /** + * 连接建立成功调用的方法 + */ + @OnOpen + public void onOpen(Session session) throws Exception + { + boolean semaphoreFlag = false; + // 尝试获取信号量 + semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore); + if (!semaphoreFlag) + { + // 未获取到信号量 + LOGGER.error("\n 当前在线人数超过限制数- {}", socketMaxOnlineCount); + WebSocketUsers.sendMessageToUserByText(session, "当前在线人数超过限制数:" + socketMaxOnlineCount); + session.close(); + } + else + { + // 添加用户 + WebSocketUsers.put(session.getId(), session); + LOGGER.info("\n 建立连接 - {}", session); + LOGGER.info("\n 当前人数 - {}", WebSocketUsers.getUsers().size()); + WebSocketUsers.sendMessageToUserByText(session, "连接成功"); + } + } + + /** + * 连接关闭时处理 + */ + @OnClose + public void onClose(Session session) + { + LOGGER.info("\n 关闭连接 - {}", session); + // 移除用户 + boolean removeFlag = WebSocketUsers.remove(session.getId()); + if (!removeFlag) + { + // 获取到信号量则需释放 + SemaphoreUtils.release(socketSemaphore); + } + } + + /** + * 抛出异常时处理 + */ + @OnError + public void onError(Session session, Throwable exception) throws Exception + { + if (session.isOpen()) + { + // 关闭连接 + session.close(); + } + String sessionId = session.getId(); + LOGGER.info("\n 连接异常 - {}", sessionId); + LOGGER.info("\n 异常信息 - {}", exception); + // 移出用户 + WebSocketUsers.remove(sessionId); + // 获取到信号量则需释放 + SemaphoreUtils.release(socketSemaphore); + } + + /** + * 服务器接收到客户端消息时调用的方法 + */ + @OnMessage + public void onMessage(String message, Session session) + { + String msg = message.replace("你", "我").replace("吗", ""); + WebSocketUsers.sendMessageToUserByText(session, msg); + } +} diff --git a/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketUsers.java b/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketUsers.java new file mode 100644 index 00000000..f21be112 --- /dev/null +++ b/op-modules/op-device/src/main/java/com/op/device/websocket/WebSocketUsers.java @@ -0,0 +1,140 @@ +package com.op.device.websocket; + +import java.io.IOException; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import javax.websocket.Session; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * websocket 客户端用户集 + * + * @author ruoyi + */ +public class WebSocketUsers +{ + /** + * WebSocketUsers 日志控制器 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketUsers.class); + + /** + * 用户集 + */ + private static Map USERS = new ConcurrentHashMap(); + + /** + * 存储用户 + * + * @param key 唯一键 + * @param session 用户信息 + */ + public static void put(String key, Session session) + { + USERS.put(key, session); + } + + /** + * 移除用户 + * + * @param session 用户信息 + * + * @return 移除结果 + */ + public static boolean remove(Session session) + { + String key = null; + boolean flag = USERS.containsValue(session); + if (flag) + { + Set> entries = USERS.entrySet(); + for (Map.Entry entry : entries) + { + Session value = entry.getValue(); + if (value.equals(session)) + { + key = entry.getKey(); + break; + } + } + } + else + { + return true; + } + return remove(key); + } + + /** + * 移出用户 + * + * @param key 键 + */ + public static boolean remove(String key) + { + LOGGER.info("\n 正在移出用户 - {}", key); + Session remove = USERS.remove(key); + if (remove != null) + { + boolean containsValue = USERS.containsValue(remove); + LOGGER.info("\n 移出结果 - {}", containsValue ? "失败" : "成功"); + return containsValue; + } + else + { + return true; + } + } + + /** + * 获取在线用户列表 + * + * @return 返回用户集合 + */ + public static Map getUsers() + { + return USERS; + } + + /** + * 群发消息文本消息 + * + * @param message 消息内容 + */ + public static void sendMessageToUsersByText(String message) + { + Collection values = USERS.values(); + for (Session value : values) + { + sendMessageToUserByText(value, message); + } + } + + /** + * 发送文本消息 + * + * @param userName 自己的用户名 + * @param message 消息内容 + */ + public static void sendMessageToUserByText(Session session, String message) + { + if (session != null) + { + try + { + session.getBasicRemote().sendText(message); + } + catch (IOException e) + { + LOGGER.error("\n[发送消息异常]", e); + } + } + else + { + LOGGER.info("\n[你已离线]"); + } + } +} diff --git a/op-modules/op-device/src/main/resources/mapper/device/EquRepairOrderMapper.xml b/op-modules/op-device/src/main/resources/mapper/device/EquRepairOrderMapper.xml index f6f3b019..0d958237 100644 --- a/op-modules/op-device/src/main/resources/mapper/device/EquRepairOrderMapper.xml +++ b/op-modules/op-device/src/main/resources/mapper/device/EquRepairOrderMapper.xml @@ -345,5 +345,15 @@ left join base_team_user btu on sng.group_code = btu.team_code where sng.notice_id = #{noticeId} and sng.del_flag = '0' + diff --git a/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java b/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java index caf74f71..797dd8ba 100644 --- a/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java +++ b/op-modules/op-job/src/main/java/com/op/job/task/RyTask.java @@ -221,6 +221,11 @@ public class RyTask { logger.info("++hr部门基础数据同步+开始++sysPostInfoTask+++++"); remoteUserService.sysDeptInfoTask(); } + //同步每天的员工打卡信息 + public void sysClockInRecord(){ + logger.info("++hr部门员工打卡信息数据同步+开始++sysClockInRecord+++++"); + remoteUserService.sysClockInRecord(); + } /************部门基础数据定时任务开始*****************/ /************装运单同步定时任务*********************/ public void SynchronizationOfShippingDocuments(){ diff --git a/op-modules/op-system/pom.xml b/op-modules/op-system/pom.xml index faca5d25..292ed4da 100644 --- a/op-modules/op-system/pom.xml +++ b/op-modules/op-system/pom.xml @@ -82,6 +82,14 @@ com.op op-common-swagger + + org.springframework.boot + spring-boot-starter-websocket + + + org.springframework.boot + spring-boot-starter-websocket + diff --git a/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java b/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java index f48236be..28a79966 100644 --- a/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java +++ b/op-modules/op-system/src/main/java/com/op/system/controller/SysUserController.java @@ -382,5 +382,9 @@ public class SysUserController extends BaseController { public R syncUserInfoTask() { return R.ok(userService.syncUserInfoTask()); } - + /**人员考勤打卡信息**/ + @PostMapping("/clockInRecord") + public R syncClockInRecord() { + return R.ok(userService.syncClockInRecord()); + } } diff --git a/op-modules/op-system/src/main/java/com/op/system/domain/MesClockRecord.java b/op-modules/op-system/src/main/java/com/op/system/domain/MesClockRecord.java new file mode 100644 index 00000000..45a33292 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/domain/MesClockRecord.java @@ -0,0 +1,94 @@ +package com.op.system.domain; + +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.op.common.core.annotation.Excel; +import com.op.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + + +/** + * 员工考勤记录对象 mes_clock_record + * + * @author yangwl + * @date 2025-03-21 + */ +public class MesClockRecord extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + private String day; + private String time; + + /** 打卡时间 */ + @Excel(name = "打卡时间", width = 30, dateFormat = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date clockTime; + + /** 工号 */ + @Excel(name = "工号") + private String workNo; + + /** 姓名 */ + @Excel(name = "姓名") + private String name; + + + + public void setClockTime(Date clockTime) + { + this.clockTime = clockTime; + } + + public Date getClockTime() + { + return clockTime; + } + + public String getDay() { + return day; + } + + public void setDay(String day) { + this.day = day; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getWorkNo() { + return workNo; + } + + public void setWorkNo(String workNo) { + this.workNo = workNo; + } + + public void setName(String name) + { + this.name = name; + } + + public String getName() + { + return name; + } + + @Override + public String toString() { + return "MesClockRecord{" + + "day='" + day + '\'' + + ", time='" + time + '\'' + + ", clockTime=" + clockTime + + ", workNo='" + workNo + '\'' + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/op-modules/op-system/src/main/java/com/op/system/mapper/MesClockRecordMapper.java b/op-modules/op-system/src/main/java/com/op/system/mapper/MesClockRecordMapper.java new file mode 100644 index 00000000..7f05e556 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/mapper/MesClockRecordMapper.java @@ -0,0 +1,66 @@ +package com.op.system.mapper; + +import java.util.Date; +import java.util.List; +import com.op.system.domain.MesClockRecord; +import feign.Param; + +/** + * 员工考勤记录Mapper接口 + * + * @author yangwl + * @date 2025-03-21 + */ +public interface MesClockRecordMapper +{ + /** + * 查询员工考勤记录 + * + * @param clockTime 员工考勤记录ID + * @return 员工考勤记录 + */ + public MesClockRecord selectMesClockRecordById(Date clockTime); + + /** + * 查询员工考勤记录列表 + * + * @param mesClockRecord 员工考勤记录 + * @return 员工考勤记录集合 + */ + public List selectMesClockRecordList(MesClockRecord mesClockRecord); + + /** + * 新增员工考勤记录 + * + * @param mesClockRecord 员工考勤记录 + * @return 结果 + */ + public int insertMesClockRecord(MesClockRecord mesClockRecord); + + /** + * 修改员工考勤记录 + * + * @param mesClockRecord 员工考勤记录 + * @return 结果 + */ + public int updateMesClockRecord(MesClockRecord mesClockRecord); + + /** + * 删除员工考勤记录 + * + * @param clockTime 员工考勤记录ID + * @return 结果 + */ + public int deleteMesClockRecordById(Date clockTime); + + /** + * 批量删除员工考勤记录 + * + * @param clockTimes 需要删除的数据ID + * @return 结果 + */ + public int deleteMesClockRecordByIds(String[] clockTimes); + + + void insertMesClockRecordList(List list); +} diff --git a/op-modules/op-system/src/main/java/com/op/system/service/IMesClockRecordService.java b/op-modules/op-system/src/main/java/com/op/system/service/IMesClockRecordService.java new file mode 100644 index 00000000..bbc80611 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/service/IMesClockRecordService.java @@ -0,0 +1,62 @@ +package com.op.system.service; + +import java.util.Date; +import java.util.List; +import com.op.system.domain.MesClockRecord; + +/** + * 员工考勤记录Service接口 + * + * @author yangwl + * @date 2025-03-21 + */ +public interface IMesClockRecordService +{ + /** + * 查询员工考勤记录 + * + * @param clockTime 员工考勤记录ID + * @return 员工考勤记录 + */ + public MesClockRecord selectMesClockRecordById(Date clockTime); + + /** + * 查询员工考勤记录列表 + * + * @param mesClockRecord 员工考勤记录 + * @return 员工考勤记录集合 + */ + public List selectMesClockRecordList(MesClockRecord mesClockRecord); + + /** + * 新增员工考勤记录 + * + * @param mesClockRecord 员工考勤记录 + * @return 结果 + */ + public int insertMesClockRecord(MesClockRecord mesClockRecord); + + /** + * 修改员工考勤记录 + * + * @param mesClockRecord 员工考勤记录 + * @return 结果 + */ + public int updateMesClockRecord(MesClockRecord mesClockRecord); + + /** + * 批量删除员工考勤记录 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteMesClockRecordByIds(String ids); + + /** + * 删除员工考勤记录信息 + * + * @param clockTime 员工考勤记录ID + * @return 结果 + */ + public int deleteMesClockRecordById(Date clockTime); +} diff --git a/op-modules/op-system/src/main/java/com/op/system/service/ISysUserService.java b/op-modules/op-system/src/main/java/com/op/system/service/ISysUserService.java index 4d57f54f..6030bb82 100644 --- a/op-modules/op-system/src/main/java/com/op/system/service/ISysUserService.java +++ b/op-modules/op-system/src/main/java/com/op/system/service/ISysUserService.java @@ -210,4 +210,6 @@ public interface ISysUserService { public List> getPoolNameList(SysUser user); public R syncUserInfoTask(); + + public R syncClockInRecord(); } diff --git a/op-modules/op-system/src/main/java/com/op/system/service/impl/MesClockRecordServiceImpl.java b/op-modules/op-system/src/main/java/com/op/system/service/impl/MesClockRecordServiceImpl.java new file mode 100644 index 00000000..259a1045 --- /dev/null +++ b/op-modules/op-system/src/main/java/com/op/system/service/impl/MesClockRecordServiceImpl.java @@ -0,0 +1,101 @@ +package com.op.system.service.impl; + +import java.util.Date; +import java.util.List; + +import com.op.common.core.text.Convert; +import com.op.common.core.utils.DateUtils; +import com.op.system.mapper.MesClockRecordMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.op.system.domain.MesClockRecord; +import com.op.system.service.IMesClockRecordService; + + +/** + * 员工考勤记录Service业务层处理 + * + * @author yangwl + * @date 2025-03-21 + */ +@Service +public class MesClockRecordServiceImpl implements IMesClockRecordService +{ + @Autowired + private MesClockRecordMapper mesClockRecordMapper; + + /** + * 查询员工考勤记录 + * + * @param clockTime 员工考勤记录ID + * @return 员工考勤记录 + */ + @Override + public MesClockRecord selectMesClockRecordById(Date clockTime) + { + return mesClockRecordMapper.selectMesClockRecordById(clockTime); + } + + /** + * 查询员工考勤记录列表 + * + * @param mesClockRecord 员工考勤记录 + * @return 员工考勤记录 + */ + @Override + public List selectMesClockRecordList(MesClockRecord mesClockRecord) + { + return mesClockRecordMapper.selectMesClockRecordList(mesClockRecord); + } + + /** + * 新增员工考勤记录 + * + * @param mesClockRecord 员工考勤记录 + * @return 结果 + */ + @Override + public int insertMesClockRecord(MesClockRecord mesClockRecord) + { + mesClockRecord.setCreateTime(DateUtils.getNowDate()); + return mesClockRecordMapper.insertMesClockRecord(mesClockRecord); + } + + /** + * 修改员工考勤记录 + * + * @param mesClockRecord 员工考勤记录 + * @return 结果 + */ + @Override + public int updateMesClockRecord(MesClockRecord mesClockRecord) + { + mesClockRecord.setUpdateTime(DateUtils.getNowDate()); + return mesClockRecordMapper.updateMesClockRecord(mesClockRecord); + } + + /** + * 删除员工考勤记录对象 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + @Override + public int deleteMesClockRecordByIds(String ids) + { + return mesClockRecordMapper.deleteMesClockRecordByIds(Convert.toStrArray(ids)); + } + + /** + * 删除员工考勤记录信息 + * + * @param clockTime 员工考勤记录ID + * @return 结果 + */ + @Override + public int deleteMesClockRecordById(Date clockTime) + { + return mesClockRecordMapper.deleteMesClockRecordById(clockTime); + } +} diff --git a/op-modules/op-system/src/main/java/com/op/system/service/impl/SysUserServiceImpl.java b/op-modules/op-system/src/main/java/com/op/system/service/impl/SysUserServiceImpl.java index bad7b2c9..1357fc5c 100644 --- a/op-modules/op-system/src/main/java/com/op/system/service/impl/SysUserServiceImpl.java +++ b/op-modules/op-system/src/main/java/com/op/system/service/impl/SysUserServiceImpl.java @@ -1,5 +1,6 @@ package com.op.system.service.impl; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -8,17 +9,22 @@ import javax.validation.Validator; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.op.common.core.domain.R; import com.op.common.core.utils.DateUtils; +import com.op.common.core.utils.http.HttpUtils; import com.op.common.core.web.domain.AjaxResult; import com.op.system.api.RemoteOpenService; import com.op.system.api.domain.quality.HRInfo; import com.op.system.api.domain.quality.OAInfo; import com.op.system.api.domain.sap.SapWorkCenter; -import com.op.system.domain.SysDatasource; +import com.op.system.domain.*; import com.op.system.mapper.*; import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,9 +40,6 @@ import com.op.common.datascope.annotation.DataScope; import com.op.common.security.utils.SecurityUtils; import com.op.system.api.domain.SysRole; import com.op.system.api.domain.SysUser; -import com.op.system.domain.SysPost; -import com.op.system.domain.SysUserPost; -import com.op.system.domain.SysUserRole; import com.op.system.service.ISysConfigService; import com.op.system.service.ISysUserService; import org.springframework.web.context.request.RequestContextHolder; @@ -74,6 +77,9 @@ public class SysUserServiceImpl implements ISysUserService { @Autowired private SysDatasourceMapper sysDatasourceMapper; + @Autowired + private MesClockRecordMapper mesClockRecordMapper; + @Autowired private RemoteOpenService remoteOpenService; @@ -569,7 +575,9 @@ public class SysUserServiceImpl implements ISysUserService { return R.ok(); } - protected int syncUserInfoFunc(List dtos){ + + + protected int syncUserInfoFunc(List dtos){ log.info("人力信息同步:"+ JSONObject.toJSONString(dtos)); Date nowDate = DateUtils.getNowDate(); String createBy = "job"; @@ -651,6 +659,75 @@ public class SysUserServiceImpl implements ISysUserService { return 1; } + @Override + public R syncClockInRecord() { + DynamicDataSourceContextHolder.push("ds_1000");// 这是数据源的key + + try { + /*从接口获取人员打卡信息*/ + // 获取当前日期 + Calendar calendar = Calendar.getInstance(); + + // 定义日期格式 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + // 格式化日期 + String formattedDate = sdf.format(calendar.getTime()); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("day", formattedDate); + + // 将 JSON 对象转换为字符串 + String jsonString = jsonObject.toString(); + + // 调用 sendPost 方法(确保此方法内部使用 POST 方法发送数据) + String url = "http://lj.lanju.cn:8801/outside/api/mes/attendanceRecord/today/list.do"; + String result = HttpUtils.sendPostWechart(url, jsonString); + List mesClockRecordList =JSONArray.parseArray(result,MesClockRecord.class); + + SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + List clockRecordList = mesClockRecordList.stream().map(mesClockRecord -> { + String ClockTime=mesClockRecord.getDay()+ " " +mesClockRecord.getTime(); + try { + Date clockTime = sdfs.parse(ClockTime); + mesClockRecord.setClockTime(clockTime); + } catch (ParseException e) { + e.printStackTrace(); + } + return mesClockRecord; + }).collect(Collectors.toList()); + // 处理响应结果 + batchInsert(clockRecordList); + + System.out.println("服务器响应: " + clockRecordList); + return R.ok(result); + }catch (Exception e) { + e.printStackTrace(); + return R.fail(e.getMessage()); + } + + } + @Autowired // 关键:注入 SqlSessionFactory + private SqlSessionFactory sqlSessionFactory; + + public void batchInsert(List records) { + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + try { + MesClockRecordMapper mapper = sqlSession.getMapper(MesClockRecordMapper.class); + int batchSize = 500; + for (int i = 0; i < records.size(); i += batchSize) { + int end = Math.min(i + batchSize, records.size()); + List subList = records.subList(i, end); + mapper.insertMesClockRecordList(subList); + sqlSession.flushStatements(); // 批处理执行 + } + sqlSession.commit(); // 提交事务 + } catch (Exception e) { + sqlSession.rollback(); + throw new RuntimeException("批量插入失败", e); + } finally { + sqlSession.close(); + } + } } diff --git a/op-modules/op-system/src/main/resources/mapper/system/MesClockRecordMapper.xml b/op-modules/op-system/src/main/resources/mapper/system/MesClockRecordMapper.xml new file mode 100644 index 00000000..009c6259 --- /dev/null +++ b/op-modules/op-system/src/main/resources/mapper/system/MesClockRecordMapper.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + select clock_time, workno, name, create_by, create_time, update_by, update_time from mes_clock_record + + + + + + + + insert into mes_clock_record + + clock_time, + workno, + name, + create_by, + create_time, + update_by, + update_time, + + + #{clockTime}, + #{workNo}, + #{name}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + INSERT INTO mes_clock_record (clock_time,workno, name) VALUES + + (#{item.clockTime}, #{item.workNo}, #{item.name}) + + + + + update mes_clock_record + + workno = #{workno}, + name = #{name}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where clock_time = #{clockTime} + + + + delete from mes_clock_record where clock_time = #{clockTime} + + + + delete from mes_clock_record where clock_time in + + #{clockTime} + + + +