| | |
| | | import com.zy.core.thread.NyShuttleThread; |
| | | import lombok.Data; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | buffer.append("超重"); |
| | | } |
| | | |
| | | if (liftProtocol.getErrorCode() > 0) { |
| | | buffer.append(liftProtocol.getErrCode$()); |
| | | } |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("deviceNo", liftProtocol.getLiftNo());//设备号-提升机号 |
| | | map.put("errorMsg", buffer.toString());//异常信息 |
| | |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | /** |
| | | * 获取设备运行异常统计 |
| | | */ |
| | | @GetMapping("/deviceRunErrorStatistic/{type}") |
| | | public R deviceRunErrorStatistic(@PathVariable("type") String type) { |
| | | int time = 1;//默认1天 |
| | | if (type.equals("day")) { |
| | | time = 1; |
| | | } else if (type.equals("week")) { |
| | | time = 7; |
| | | } else if (type.equals("month")) { |
| | | time = 30; |
| | | } |
| | | //获取提升机运行异常数据 |
| | | List<Map<String, Object>> liftList = basLiftOptMapper.selectRunErrorStatistic(time); |
| | | //获取小车运行异常数据 |
| | | List<Map<String, Object>> shuttleList = basShuttleOptMapper.selectRunErrorStatistic(time); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("lift", liftList); |
| | | map.put("shuttle", shuttleList); |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | |
| | | |
| | | |
New file |
| | |
| | | package com.zy.asrs.entity; |
| | | |
| | | import com.core.common.Cools;import com.baomidou.mybatisplus.annotations.TableId; |
| | | import com.baomidou.mybatisplus.enums.IdType; |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import java.io.Serializable; |
| | | |
| | | @Data |
| | | @TableName("wcs_device_data_log") |
| | | public class DeviceDataLog implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @ApiModelProperty(value= "") |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | /** |
| | | * 设备类型 |
| | | */ |
| | | @ApiModelProperty(value= "设备类型") |
| | | private String type; |
| | | |
| | | /** |
| | | * 设备号 |
| | | */ |
| | | @ApiModelProperty(value= "设备号") |
| | | @TableField("device_no") |
| | | private Integer deviceNo; |
| | | |
| | | /** |
| | | * 源数据 |
| | | */ |
| | | @ApiModelProperty(value= "源数据") |
| | | @TableField("origin_data") |
| | | private String originData; |
| | | |
| | | /** |
| | | * 源数据解析后得到的wcs数据 |
| | | */ |
| | | @ApiModelProperty(value= "源数据解析后得到的wcs数据") |
| | | @TableField("wcs_data") |
| | | private String wcsData; |
| | | |
| | | /** |
| | | * 采集时间 |
| | | */ |
| | | @ApiModelProperty(value= "采集时间") |
| | | @TableField("create_time") |
| | | @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") |
| | | private Date createTime; |
| | | |
| | | public DeviceDataLog() {} |
| | | |
| | | public DeviceDataLog(String type,Integer deviceNo,String originData,String wcsData,Date createTime) { |
| | | this.type = type; |
| | | this.deviceNo = deviceNo; |
| | | this.originData = originData; |
| | | this.wcsData = wcsData; |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | // DeviceDataLog deviceDataLog = new DeviceDataLog( |
| | | // null, // 设备类型 |
| | | // null, // 设备号 |
| | | // null, // 源数据 |
| | | // null, // 源数据解析后得到的wcs数据 |
| | | // null // 采集时间 |
| | | // ); |
| | | |
| | | public String getCreateTime$(){ |
| | | if (Cools.isEmpty(this.createTime)){ |
| | | return ""; |
| | | } |
| | | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.createTime); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | List<Map<String, Object>> selectRunStatistic();//获取提升机每天运行数据 |
| | | |
| | | List<Map<String, Object>> selectRunErrorStatistic(int time);//获取提升机每天运行异常数据 |
| | | |
| | | @Insert("insert into asr_bas_lift_opt_storage select * from asr_bas_lift_opt where id in (select id from asr_bas_lift_opt where DATEDIFF(day, send_time, GETDATE()) > #{day})") |
| | | int saveToStorage(Integer day); |
| | | |
| | |
| | | |
| | | List<Map<String, Object>> selectRunStatistic();//获取小车每天运行数据 |
| | | |
| | | List<Map<String, Object>> selectRunErrorStatistic(int time);//获取小车每天运行异常数据 |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.mapper; |
| | | |
| | | import com.zy.asrs.entity.DeviceDataLog; |
| | | import com.baomidou.mybatisplus.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Delete; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface DeviceDataLogMapper extends BaseMapper<DeviceDataLog> { |
| | | |
| | | @Delete("delete from wcs_device_data_log where create_time < DATEADD(HOUR, -24, GETDATE())") |
| | | int clearLog(); |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.service; |
| | | |
| | | import com.zy.asrs.entity.DeviceDataLog; |
| | | import com.baomidou.mybatisplus.service.IService; |
| | | |
| | | public interface DeviceDataLogService extends IService<DeviceDataLog> { |
| | | |
| | | int clearLog();//清理超过24小时日志数据 |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.zy.asrs.mapper.DeviceDataLogMapper; |
| | | import com.zy.asrs.entity.DeviceDataLog; |
| | | import com.zy.asrs.service.DeviceDataLogService; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service("deviceDataLogService") |
| | | public class DeviceDataLogServiceImpl extends ServiceImpl<DeviceDataLogMapper, DeviceDataLog> implements DeviceDataLogService { |
| | | |
| | | @Override |
| | | public int clearLog() { |
| | | return this.baseMapper.clearLog(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.zy.asrs.service.DeviceDataLogService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class ClearDeviceDataLogScheduler { |
| | | |
| | | @Autowired |
| | | private DeviceDataLogService deviceDataLogService; |
| | | |
| | | /** |
| | | * 每分钟清理24小时之前的日志 |
| | | */ |
| | | @Scheduled(cron = "1 * * * * ? ") |
| | | public void clear() { |
| | | deviceDataLogService.clearLog(); |
| | | } |
| | | |
| | | } |
| | |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.BasLift; |
| | | import com.zy.asrs.entity.BasLiftOpt; |
| | | import com.zy.asrs.entity.DeviceDataLog; |
| | | import com.zy.asrs.mapper.WrkMastMapper; |
| | | import com.zy.asrs.service.BasLiftOptService; |
| | | import com.zy.asrs.service.BasLiftService; |
| | | import com.zy.asrs.service.DeviceDataLogService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 提升机线程 |
| | |
| | | liftProtocol.setErrorCode(siemensS7Net.getByteTransform().TransInt16(result3.Content, 0));//错误码 |
| | | } |
| | | |
| | | //保存数据记录 |
| | | DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class); |
| | | DeviceDataLog deviceDataLog = new DeviceDataLog(); |
| | | deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result1.Content)); |
| | | deviceDataLog.setWcsData(JSON.toJSONString(liftProtocol)); |
| | | deviceDataLog.setType("lift"); |
| | | deviceDataLog.setDeviceNo(liftProtocol.getLiftNo().intValue()); |
| | | deviceDataLog.setCreateTime(new Date()); |
| | | deviceDataLogService.insert(deviceDataLog); |
| | | |
| | | } catch (Exception e) { |
| | | OutputQueue.LIFT.offer(MessageFormat.format("【{0}】提升机plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | } |
| | |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | // log.info(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | } |
| | | log.warn(JSON.toJSONString(shuttleProtocol));//输出小车状态 |
| | | // log.warn(JSON.toJSONString(shuttleProtocol));//输出小车状态 |
| | | |
| | | //保存数据记录 |
| | | DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class); |
| | | DeviceDataLog deviceDataLog = new DeviceDataLog(); |
| | | deviceDataLog.setOriginData(JSON.toJSONString(jsonObject)); |
| | | deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol)); |
| | | deviceDataLog.setType("shuttle"); |
| | | deviceDataLog.setDeviceNo(shuttleProtocol.getShuttleNo().intValue()); |
| | | deviceDataLog.setCreateTime(new Date()); |
| | | deviceDataLogService.insert(deviceDataLog); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | group by lift_no |
| | | </select> |
| | | |
| | | <select id="selectRunErrorStatistic" resultType="map"> |
| | | select lift_no,count(*) count from asr_bas_lift_err_log |
| | | where start_time > DATEADD(day, DATEDIFF(day, 0, GETDATE())-#{time}, 0) |
| | | and start_time < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0) |
| | | GROUP BY lift_no |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | group by shuttle_no |
| | | </select> |
| | | |
| | | <select id="selectRunErrorStatistic" resultType="map"> |
| | | select shuttle_no,count(*) count from asr_bas_shuttle_err_log |
| | | where start_time > DATEADD(day, DATEDIFF(day, 0, GETDATE())-#{time}, 0) |
| | | and start_time < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0) |
| | | GROUP BY shuttle_no |
| | | </select> |
| | | |
| | | </mapper> |
New file |
| | |
| | | <?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.zy.asrs.mapper.DeviceDataLogMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.zy.asrs.entity.DeviceDataLog"> |
| | | <id column="id" property="id" /> |
| | | <result column="type" property="type" /> |
| | | <result column="device_no" property="deviceNo" /> |
| | | <result column="origin_data" property="originData" /> |
| | | <result column="wcs_data" property="wcsData" /> |
| | | <result column="create_time" property="createTime" /> |
| | | |
| | | </resultMap> |
| | | |
| | | </mapper> |