#
Junjie
2024-04-03 026cce3b164616e7a43bee2bae66b5d9d2c48953
#
1个文件已修改
7个文件已添加
419 ■■■■■ 已修改文件
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/controller/DeviceDataLogController.java 101 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/entity/DeviceDataLog.java 238 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/mapper/DeviceDataLogMapper.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/service/DeviceDataLogService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/service/impl/DeviceDataLogServiceImpl.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/deviceDataLog.sql 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/resources/mapper/rcs/DeviceDataLogMapper.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/controller/DeviceDataLogController.java
New file
@@ -0,0 +1,101 @@
package com.zy.asrs.wcs.system.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.wcs.common.annotation.OperationLog;
import com.zy.asrs.wcs.common.domain.BaseParam;
import com.zy.asrs.wcs.common.domain.KeyValVo;
import com.zy.asrs.wcs.common.domain.PageParam;
import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
import com.zy.asrs.wcs.rcs.service.DeviceDataLogService;
import com.zy.asrs.wcs.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api")
public class DeviceDataLogController extends BaseController {
    @Autowired
    private DeviceDataLogService deviceDataLogService;
    @PreAuthorize("hasAuthority('rcs:deviceDataLog:list')")
    @PostMapping("/deviceDataLog/page")
    public R page(@RequestBody Map<String, Object> map) {
        BaseParam baseParam = buildParam(map, BaseParam.class);
        PageParam<DeviceDataLog, BaseParam> pageParam = new PageParam<>(baseParam, DeviceDataLog.class);
        return R.ok().add(deviceDataLogService.page(pageParam, pageParam.buildWrapper(true)));
    }
    @PreAuthorize("hasAuthority('rcs:deviceDataLog:list')")
    @PostMapping("/deviceDataLog/list")
    public R list(@RequestBody Map<String, Object> map) {
        return R.ok().add(deviceDataLogService.list());
    }
    @PreAuthorize("hasAuthority('rcs:deviceDataLog:list')")
    @GetMapping("/deviceDataLog/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.ok().add(deviceDataLogService.getById(id));
    }
    @PreAuthorize("hasAuthority('rcs:deviceDataLog:save')")
    @OperationLog("添加设备日志记录")
    @PostMapping("/deviceDataLog/save")
    public R save(@RequestBody DeviceDataLog deviceDataLog) {
        if (!deviceDataLogService.save(deviceDataLog)) {
            return R.error("添加失败");
        }
        return R.ok("添加成功");
    }
    @PreAuthorize("hasAuthority('rcs:deviceDataLog:update')")
    @OperationLog("修改设备日志记录")
    @PostMapping("/deviceDataLog/update")
    public R update(@RequestBody DeviceDataLog deviceDataLog) {
        if (!deviceDataLogService.updateById(deviceDataLog)) {
            return R.error("修改失败");
        }
        return R.ok("修改成功");
    }
    @PreAuthorize("hasAuthority('rcs:deviceDataLog:remove')")
    @OperationLog("删除设备日志记录")
    @PostMapping("/deviceDataLog/remove/{ids}")
    public R remove(@PathVariable Long[] ids) {
        if (!deviceDataLogService.removeByIds(Arrays.asList(ids))) {
            return R.error("删除失败");
        }
        return R.ok("删除成功");
    }
    @PreAuthorize("hasAuthority('rcs:deviceDataLog:list')")
    @PostMapping("/deviceDataLog/query")
    public R query(@RequestParam(required = false) String condition) {
        List<KeyValVo> vos = new ArrayList<>();
        LambdaQueryWrapper<DeviceDataLog> wrapper = new LambdaQueryWrapper<>();
        if (!Cools.isEmpty(condition)) {
            wrapper.like(DeviceDataLog::getName, condition);
        }
        deviceDataLogService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
                item -> vos.add(new KeyValVo(item.getId(), item.getName()))
        );
        return R.ok().add(vos);
    }
    @PreAuthorize("hasAuthority('rcs:deviceDataLog:list')")
    @PostMapping("/deviceDataLog/export")
    public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
        ExcelUtil.build(ExcelUtil.create(deviceDataLogService.list(), DeviceDataLog.class), response);
    }
}
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/entity/DeviceDataLog.java
New file
@@ -0,0 +1,238 @@
package com.zy.asrs.wcs.rcs.entity;
import com.baomidou.mybatisplus.annotation.TableLogic;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.zy.asrs.wcs.system.entity.Host;
import com.zy.asrs.wcs.system.entity.User;
import org.springframework.format.annotation.DateTimeFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.SpringUtils;
import com.zy.asrs.wcs.system.service.UserService;
import com.zy.asrs.wcs.system.service.HostService;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("rcs_device_data_log")
public class DeviceDataLog implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * ID
     */
    @ApiModelProperty(value= "ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    /**
     * 编号
     */
    @ApiModelProperty(value= "编号")
    private String uuid;
    /**
     * 名称
     */
    @ApiModelProperty(value= "名称")
    private String name;
    /**
     * 标识
     */
    @ApiModelProperty(value= "标识")
    private String flag;
    /**
     * 所属机构
     */
    @ApiModelProperty(value= "所属机构")
    private Long hostId;
    /**
     * 状态 1: 正常  0: 禁用
     */
    @ApiModelProperty(value= "状态 1: 正常  0: 禁用  ")
    private Integer status;
    /**
     * 是否删除 1: 是  0: 否
     */
    @ApiModelProperty(value= "是否删除 1: 是  0: 否  ")
    @TableLogic
    private Integer deleted;
    /**
     * 添加时间
     */
    @ApiModelProperty(value= "添加时间")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /**
     * 添加人员
     */
    @ApiModelProperty(value= "添加人员")
    private Long createBy;
    /**
     * 修改时间
     */
    @ApiModelProperty(value= "修改时间")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    /**
     * 修改人员
     */
    @ApiModelProperty(value= "修改人员")
    private Long updateBy;
    /**
     * 备注
     */
    @ApiModelProperty(value= "备注")
    private String memo;
    /**
     * 设备类型
     */
    @ApiModelProperty(value= "设备类型")
    private String type;
    /**
     * 设备号
     */
    @ApiModelProperty(value= "设备号")
    private String deviceNo;
    /**
     * 源数据
     */
    @ApiModelProperty(value= "源数据")
    private String originData;
    /**
     * 源数据解析后得到的wcs数据
     */
    @ApiModelProperty(value= "源数据解析后得到的wcs数据")
    private String wcsData;
    public DeviceDataLog() {}
    public DeviceDataLog(String uuid,String name,String flag,Long hostId,Integer status,Integer deleted,Date createTime,Long createBy,Date updateTime,Long updateBy,String memo,String type,String deviceNo,String originData,String wcsData) {
        this.uuid = uuid;
        this.name = name;
        this.flag = flag;
        this.hostId = hostId;
        this.status = status;
        this.deleted = deleted;
        this.createTime = createTime;
        this.createBy = createBy;
        this.updateTime = updateTime;
        this.updateBy = updateBy;
        this.memo = memo;
        this.type = type;
        this.deviceNo = deviceNo;
        this.originData = originData;
        this.wcsData = wcsData;
    }
//    DeviceDataLog deviceDataLog = new DeviceDataLog(
//            null,    // 编号
//            null,    // 名称
//            null,    // 标识
//            null,    // 所属机构
//            null,    // 状态
//            null,    // 是否删除
//            null,    // 添加时间
//            null,    // 添加人员
//            null,    // 修改时间
//            null,    // 修改人员
//            null,    // 备注
//            null,    // 设备类型
//            null,    // 设备号
//            null,    // 源数据
//            null    // 源数据解析后得到的wcs数据
//    );
    public String getHostId$(){
        HostService service = SpringUtils.getBean(HostService.class);
        Host host = service.getById(this.hostId);
        if (!Cools.isEmpty(host)){
            return String.valueOf(host.getName());
        }
        return null;
    }
    public String getStatus$(){
        if (null == this.status){ return null; }
        switch (this.status){
            case 1:
                return "正常";
            case 0:
                return "禁用";
            default:
                return String.valueOf(this.status);
        }
    }
    public String getDeleted$(){
        if (null == this.deleted){ return null; }
        switch (this.deleted){
            case 1:
                return "是";
            case 0:
                return "否";
            default:
                return String.valueOf(this.deleted);
        }
    }
    public String getCreateTime$(){
        if (Cools.isEmpty(this.createTime)){
            return "";
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.createTime);
    }
    public String getCreateBy$(){
        UserService service = SpringUtils.getBean(UserService.class);
        User user = service.getById(this.createBy);
        if (!Cools.isEmpty(user)){
            return String.valueOf(user.getNickname());
        }
        return null;
    }
    public String getUpdateTime$(){
        if (Cools.isEmpty(this.updateTime)){
            return "";
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.updateTime);
    }
    public String getUpdateBy$(){
        UserService service = SpringUtils.getBean(UserService.class);
        User user = service.getById(this.updateBy);
        if (!Cools.isEmpty(user)){
            return String.valueOf(user.getNickname());
        }
        return null;
    }
}
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/mapper/DeviceDataLogMapper.java
New file
@@ -0,0 +1,12 @@
package com.zy.asrs.wcs.rcs.mapper;
import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@Mapper
@Repository
public interface DeviceDataLogMapper extends BaseMapper<DeviceDataLog> {
}
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/service/DeviceDataLogService.java
New file
@@ -0,0 +1,8 @@
package com.zy.asrs.wcs.rcs.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
public interface DeviceDataLogService extends IService<DeviceDataLog> {
}
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/service/impl/DeviceDataLogServiceImpl.java
New file
@@ -0,0 +1,12 @@
package com.zy.asrs.wcs.rcs.service.impl;
import com.zy.asrs.wcs.rcs.mapper.DeviceDataLogMapper;
import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
import com.zy.asrs.wcs.rcs.service.DeviceDataLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service("deviceDataLogService")
public class DeviceDataLogServiceImpl extends ServiceImpl<DeviceDataLogMapper, DeviceDataLog> implements DeviceDataLogService {
}
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SurayShuttleThread.java
@@ -16,8 +16,11 @@
import com.zy.asrs.wcs.core.utils.NavigateUtils;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.OutputQueue;
import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
import com.zy.asrs.wcs.rcs.service.DeviceDataLogService;
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import com.zy.asrs.wcs.rcs.entity.Device;
@@ -130,21 +133,22 @@
//                    shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE);
//                }
//                if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) {
//                    //采集时间超过5s,保存一次数据记录
//                    //保存数据记录
//                    DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
//                    DeviceDataLog deviceDataLog = new DeviceDataLog();
//                    deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result.Content));
//                    deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol));
//                    deviceDataLog.setType("shuttle");
//                    deviceDataLog.setDeviceNo(shuttleProtocol.getShuttleNo().intValue());
//                    deviceDataLog.setCreateTime(new Date());
//                    deviceDataLogService.insert(deviceDataLog);
//
//                    //更新采集时间
//                    shuttleProtocol.setDeviceDataLog(System.currentTimeMillis());
//                }
                if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) {
                    //采集时间超过5s,保存一次数据记录
                    //保存数据记录
                    DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
                    DeviceDataLog deviceDataLog = new DeviceDataLog();
                    deviceDataLog.setOriginData(JSON.toJSONString(data));
                    deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol));
                    deviceDataLog.setType(String.valueOf(SlaveType.Shuttle));
                    deviceDataLog.setDeviceNo(String.valueOf(shuttleProtocol.getShuttleNo()));
                    deviceDataLog.setCreateTime(new Date());
                    deviceDataLog.setHostId(device.getHostId());
                    deviceDataLogService.save(deviceDataLog);
                    //更新采集时间
                    shuttleProtocol.setDeviceDataLog(System.currentTimeMillis());
                }
            } else {
                OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】{1}读取四向穿梭车状态信息失败", DateUtils.convert(new Date()), device.getDeviceNo()));
                throw new CoolException(MessageFormat.format("读取四向穿梭车状态信息失败 ===>> [id:{0}] [ip:{1}] [port:{2}]", device.getDeviceNo(), device.getIp(), device.getPort()));
zy-asrs-wcs/src/main/java/deviceDataLog.sql
New file
@@ -0,0 +1,9 @@
-- save deviceDataLog record
-- mysql
insert into `sys_menu` ( `name`, `parent_id`, `route`, `component`, `type`, `sort`, `host_id`, `status`) values ( '设备日志记录管理', '0', '/rcs/deviceDataLog', '/rcs/deviceDataLog', '0' , '0', '1' , '1');
insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '查询设备日志记录', '', '1', 'rcs:deviceDataLog:list', '0', '1', '1');
insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '添加设备日志记录', '', '1', 'rcs:deviceDataLog:save', '1', '1', '1');
insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '修改设备日志记录', '', '1', 'rcs:deviceDataLog:update', '2', '1', '1');
insert into `sys_menu` ( `name`, `parent_id`, `type`, `authority`, `sort`, `host_id`, `status`) values ( '删除设备日志记录', '', '1', 'rcs:deviceDataLog:remove', '3', '1', '1');
zy-asrs-wcs/src/main/resources/mapper/rcs/DeviceDataLogMapper.xml
New file
@@ -0,0 +1,5 @@
<?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.wcs.rcs.mapper.DeviceDataLogMapper">
</mapper>