| | |
| | | <artifactId>lxzn-system-collect</artifactId> |
| | | <version>1.0.0</version> |
| | | <url>http://maven.apache.org</url> |
| | | <name>LXZN-SYSTEM-COLLECT ${project.version}</name> |
| | | <name>LXZN-SYSTEM-COLLECT ${project.version}</name> |
| | | |
| | | <parent> |
| | | <groupId>org.springframework.boot</groupId> |
| | |
| | | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; |
| | | import org.springframework.context.ConfigurableApplicationContext; |
| | | import org.springframework.core.env.Environment; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | |
| | | * åä½å¯å¨ç±» |
| | | * æ¥éæé: æªéæmongoæ¥éï¼å¯ä»¥æå¼å¯å¨ç±»ä¸é¢ç注é exclude={MongoAutoConfiguration.class} |
| | | */ |
| | | @EnableScheduling |
| | | @Slf4j |
| | | @SpringBootApplication(scanBasePackages = "com.lxzn", exclude = { DataSourceAutoConfiguration.class }) |
| | | @MapperScan(value={"com.lxzn.modules.**.mapper*"}) |
| | |
| | | |
| | | import java.util.List; |
| | | |
| | | @Api(tags = "2#è£
é
线éé") |
| | | @Api(tags = "2å·è£
é
线éé") |
| | | @RestController |
| | | @RequestMapping("/assembly2/job") |
| | | public class AssemblyCollectionJobController { |
| | |
| | | package com.lxzn.modules.assembly2.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import java.io.Serializable; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @TableId(value = "RecordID", type = IdType.AUTO) |
| | | private Integer recordID; |
| | | |
| | | private LocalDateTime recordTime; |
| | | |
| | | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss.SSS") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") |
| | | @TableField(value = "RecordTime") |
| | | private Date recordTime; |
| | | @TableField(value = "ModelID") |
| | | private Integer modelID; |
| | | |
| | | @TableField(value = "Length") |
| | | private Double length; |
| | | |
| | | @TableField(value = "LengthUL") |
| | | private Double lengthUL; |
| | | |
| | | @TableField(value = "LengthLL") |
| | | private Double lengthLL; |
| | | |
| | | @TableField(value = "PitchMAX") |
| | | private Double pitchMAX; |
| | | |
| | | @TableField(value = "PitchMIN") |
| | | private Double pitchMIN; |
| | | |
| | | @TableField(value = "PitchUL") |
| | | private Double pitchUL; |
| | | |
| | | @TableField(value = "PitchLL") |
| | | private Double pitchLL; |
| | | |
| | | @TableField(value = "Result") |
| | | private String result; |
| | | } |
| | |
| | | package com.lxzn.modules.assembly2.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import java.io.Serializable; |
| | | import java.time.LocalDateTime; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private LocalDateTime recordTime; |
| | | |
| | | @TableId(value = "OPName", type = IdType.AUTO) |
| | | private String oPName; |
| | | |
| | | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss.SSS") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") |
| | | @TableField(value = "RecordTime") |
| | | private Date recordTime; |
| | | |
| | | @TableField(value = "State") |
| | | private String state; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * <p> |
| | | * |
| | | * </p> |
| | | * |
| | | * @author baomidou |
| | | * @since 2025-09-03 |
| | | */ |
| | | @Getter |
| | | @Setter |
| | | @TableName("Assembly2_TC_OPState") |
| | | public class Assembly2TcOpstate implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @TableId(value = "OPName", type = IdType.AUTO) |
| | | private String oPName; |
| | | |
| | | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss.SSS") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") |
| | | @TableField(value = "RecordTime") |
| | | private Date recordTime; |
| | | |
| | | @TableField(value = "State") |
| | | private String state; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.entity; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | @Data |
| | | public class EquipmentLog implements Serializable { |
| | | private static final long serialVersionUID = 6978749606363390023L; |
| | | /** |
| | | * 设å¤ç¼å· |
| | | */ |
| | | private String equipmentId; |
| | | /** |
| | | * 设å¤åç§° |
| | | */ |
| | | private String equipmentName; |
| | | |
| | | /** |
| | | * ééæ¶é´ |
| | | */ |
| | | private Date collectTime; |
| | | /** |
| | | * ç¶æ |
| | | * 0 å
³æº |
| | | * 1 弿º |
| | | * 2 å¾
æº |
| | | * 3 è¿è¡ |
| | | * 22 æ¥è¦å¼å§ |
| | | * 23 æ¥è¦ç»æ |
| | | */ |
| | | private Integer oporation; |
| | | /** |
| | | * æ¥è¦å· |
| | | */ |
| | | private String alarm; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.enums; |
| | | |
| | | public enum Assembly2EquipmentMappingEnum { |
| | | OP020(new String[]{"", "", ""}), //OP020æµéåéæ£æµæº |
| | | OP030(new String[]{"", "", ""}), //OP030æåº |
| | | OP040(new String[]{"", ""}), //OP040åå¥å ç1 |
| | | OP050(new String[]{"", ""}), //OP050åå¥å ç2 |
| | | OP090(new String[]{"", ""}), //OP090éæ¥æ£æµæº |
| | | OP100(new String[]{"", ""}), //OP100æ¯å¨æ£æ¥æº |
| | | OP110(new String[]{"", ""}), //OP110å¯å°ä»¶&端çåè£
æ£æµæº |
| | | OP120(new String[]{"", ""}), //OP120æç©&ABSä¿¡å·æ£æµæº |
| | | OP150(new String[]{"", ""}), //OP150è±é®æ£æµæº |
| | | OP160(new String[]{"", ""}), //OP160端å¾è·³æ£æµæº |
| | | OP170(new String[]{"", ""}), //OP170æ¿å
ææ &é¾åæ¶æ²¹ |
| | | ; |
| | | |
| | | /** |
| | | * code:name |
| | | */ |
| | | private final String[] equipmentCodes; |
| | | |
| | | private Assembly2EquipmentMappingEnum(String[] equipmentCodes) { |
| | | this.equipmentCodes = equipmentCodes; |
| | | } |
| | | |
| | | public String[] getEquipmentCodes() { |
| | | return equipmentCodes; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.enums; |
| | | |
| | | public enum EquipmentStatusEnum { |
| | | Running(3), //è¿è¡ |
| | | Standby(2), //å¾
æ |
| | | Error(22), //æ¥è¦ |
| | | Stop(2), //忢 |
| | | Disconnected(0), //æªè¿æ¥ |
| | | ; |
| | | |
| | | private final Integer operation; |
| | | |
| | | private EquipmentStatusEnum(Integer operation) { |
| | | this.operation = operation; |
| | | } |
| | | |
| | | public Integer getOperation() { |
| | | return operation; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.job; |
| | | |
| | | import com.lxzn.modules.assembly2.entity.TcOpstate; |
| | | import com.lxzn.modules.assembly2.service.ITcOpstateService; |
| | | import com.lxzn.modules.master.entity.Assembly2TcOpstate; |
| | | import com.lxzn.modules.master.service.IAssembly2TcOpstateService; |
| | | import com.lxzn.modules.master.service.IEquipmentLogService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class EquipmentLogCollectJob { |
| | | @Autowired |
| | | private IAssembly2TcOpstateService assembly2TcOpstateService; |
| | | @Autowired |
| | | private ITcOpstateService tcOpstateService; |
| | | @Autowired |
| | | private IEquipmentLogService equipmentLogService; |
| | | |
| | | @Scheduled(initialDelay = 10000, fixedDelay = 15000) |
| | | public void equipmentLogCollect() { |
| | | log.info("------------2#è£
é
线éé设å¤ç¶æå¼å§------------"); |
| | | long startTime = System.currentTimeMillis(); |
| | | try { |
| | | //䏿¬¡ééæ°æ® |
| | | Map<String, Assembly2TcOpstate> oldStateMap = assembly2TcOpstateService.listStateMap(); |
| | | //æ¬æ¬¡è¯»å |
| | | List<TcOpstate> nevStateList = tcOpstateService.list(); |
| | | if (CollectionUtils.isEmpty(nevStateList)) { |
| | | return; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | long endTime = System.currentTimeMillis(); |
| | | long duration = (endTime - startTime) / 1000; |
| | | log.info("------------2#è£
é
线éé设å¤ç¶æç»æï¼æ¶èæ¶é¿ï¼{}S------------", duration); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.lxzn.modules.master.entity.Assembly2TcOpstate; |
| | | |
| | | /** |
| | | * <p> |
| | | * Mapper æ¥å£ |
| | | * </p> |
| | | * |
| | | * @author baomidou |
| | | * @since 2025-09-03 |
| | | */ |
| | | public interface Assembly2TcOpstateMapper extends BaseMapper<Assembly2TcOpstate> { |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.mapper; |
| | | |
| | | import com.lxzn.modules.master.entity.EquipmentLog; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | public interface EquipmentLogMapper { |
| | | /** |
| | | * æ¥å¿æå
¥ |
| | | * @param logs |
| | | */ |
| | | void insertBatch(@Param("log") List<EquipmentLog> logs); |
| | | /** |
| | | * æ´æ°è®¾å¤ä¸è²ç¯ç¶æ |
| | | * @param equipmentCode 设å¤ç¼å· |
| | | * @param operation ä¸è²ç¯ç¶æ |
| | | */ |
| | | void updateEquipmentStatus(@Param("id") String equipmentCode, @Param("operation") int operation, @Param("collectTime") Date collectTime); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.lxzn.modules.master.mapper.Assembly2TcOpstateMapper"> |
| | | |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.lxzn.modules.master.mapper.EquipmentLogMapper"> |
| | | <insert id="insertBatch"> |
| | | INSERT INTO EquipmentLog(EquipmentID, EquipmentName, CollectTime, Oporation, Alarm) |
| | | VALUES |
| | | <foreach collection="logs" item="log" separator=","> |
| | | (#{log.equipmentId}, #{log.equipmentName}, #{log.collectTime}, #{log.oporation}, #{log.alarm}) |
| | | </foreach> |
| | | </insert> |
| | | |
| | | <update id="updateEquipmentStatus"> |
| | | UPDATE Equipment |
| | | set oporation = #{operation} |
| | | , collectTime = #{collectTime} |
| | | where EquipmentID = #{equipmentCode} |
| | | </update> |
| | | </mapper> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.lxzn.modules.master.entity.Assembly2TcOpstate; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | | * æå¡ç±» |
| | | * </p> |
| | | * |
| | | * @author baomidou |
| | | * @since 2025-09-03 |
| | | */ |
| | | public interface IAssembly2TcOpstateService extends IService<Assembly2TcOpstate> { |
| | | /** |
| | | * æ¥è¯¢ä¸æ¬¡ééç设å¤ç¶æ |
| | | * @return |
| | | */ |
| | | Map<String, Assembly2TcOpstate> listStateMap(); |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.service; |
| | | |
| | | import com.lxzn.modules.master.entity.EquipmentLog; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | public interface IEquipmentLogService { |
| | | /** |
| | | * æ¥å¿æå
¥ |
| | | * @param logs |
| | | */ |
| | | void insertBatch(List<EquipmentLog> logs); |
| | | |
| | | /** |
| | | * æ´æ°è®¾å¤ä¸è²ç¯ç¶æ |
| | | * @param equipmentCode 设å¤ç¼å· |
| | | * @param operation ä¸è²ç¯ç¶æ |
| | | * @param collectTime ééæ¶é´ |
| | | */ |
| | | void updateEquipmentStatus(String equipmentCode, int operation, Date collectTime); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.service.impl; |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.lxzn.modules.master.entity.Assembly2TcOpstate; |
| | | import com.lxzn.modules.master.mapper.Assembly2TcOpstateMapper; |
| | | import com.lxzn.modules.master.service.IAssembly2TcOpstateService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | | * æå¡å®ç°ç±» |
| | | * </p> |
| | | * |
| | | * @author baomidou |
| | | * @since 2025-09-03 |
| | | */ |
| | | @Service |
| | | @DS("master") |
| | | public class Assembly2TcOpstateServiceImpl extends ServiceImpl<Assembly2TcOpstateMapper, Assembly2TcOpstate> implements IAssembly2TcOpstateService { |
| | | |
| | | @Override |
| | | public Map<String, Assembly2TcOpstate> listStateMap() { |
| | | List<Assembly2TcOpstate> list = super.list(); |
| | | if(CollectionUtils.isEmpty(list)){ |
| | | return Collections.emptyMap(); |
| | | } |
| | | return list.stream().collect(Collectors.toMap(Assembly2TcOpstate::getOPName, |
| | | state -> state, |
| | | (oldVal, newVal) -> oldVal, |
| | | HashMap::new)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lxzn.modules.master.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.lxzn.modules.master.entity.EquipmentLog; |
| | | import com.lxzn.modules.master.mapper.EquipmentLogMapper; |
| | | import com.lxzn.modules.master.service.IEquipmentLogService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class EquipmentLogServiceImpl implements IEquipmentLogService { |
| | | @Resource |
| | | private EquipmentLogMapper equipmentLogMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void insertBatch(List<EquipmentLog> logs) { |
| | | if(CollectionUtils.isEmpty(logs)){ |
| | | return; |
| | | } |
| | | equipmentLogMapper.insertBatch(logs); |
| | | log.info("æåæå
¥æ¥å¿æ°æ®EquipmentLog:{}æ¡", logs.size()); |
| | | } |
| | | |
| | | @Override |
| | | public void updateEquipmentStatus(String equipmentCode, int operation, Date collectTime) { |
| | | equipmentLogMapper.updateEquipmentStatus(equipmentCode, operation, collectTime); |
| | | } |
| | | } |