Переглянути джерело

对接PLC及编写叠包机空托移动任务生成逻辑

zhifei 1 рік тому
батько
коміт
373d3245d1

+ 71 - 0
ruoyi-dongfangyaiye/src/main/java/com/ruoyi/taiye/controller/DeviceLogController.java

@@ -0,0 +1,71 @@
+package com.ruoyi.taiye.controller;
+
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.taiye.domain.DeviceLog;
+import com.ruoyi.taiye.service.IDeviceLogService;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 设备日志Controller
+ *
+ * @author zhifei
+ * @date 2023-11-27
+ */
+@RestController
+@RequestMapping("/device/log")
+public class DeviceLogController extends BaseController
+{
+    @Autowired
+    private IDeviceLogService deviceLogService;
+
+    /**
+     * 查询设备日志列表
+     */
+    @GetMapping("/list")
+    public TableDataInfo list(DeviceLog deviceLog)
+    {
+        startPage();
+        List<DeviceLog> list = deviceLogService.selectDeviceLogList(deviceLog);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出设备日志列表
+     */
+    @Log(title = "设备日志", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, DeviceLog deviceLog)
+    {
+        List<DeviceLog> list = deviceLogService.selectDeviceLogList(deviceLog);
+        ExcelUtil<DeviceLog> util = new ExcelUtil<DeviceLog>(DeviceLog.class);
+        util.exportExcel(response, list, "设备日志数据");
+    }
+
+    /**
+     * 获取设备日志详细信息
+     */
+    @GetMapping(value = "/{deviceLogId}")
+    public AjaxResult getInfo(@PathVariable("deviceLogId") Long deviceLogId)
+    {
+        return AjaxResult.success(deviceLogService.selectDeviceLogByDeviceLogId(deviceLogId));
+    }
+
+
+}

+ 107 - 0
ruoyi-dongfangyaiye/src/main/java/com/ruoyi/taiye/domain/DeviceLog.java

@@ -0,0 +1,107 @@
+package com.ruoyi.taiye.domain;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+
+/**
+ * 设备日志对象 device_log
+ *
+ * @author zhifei
+ * @date 2023-11-27
+ */
+public class DeviceLog extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 日志编号 */
+    private Long deviceLogId;
+
+    /** 设备id */
+    private String deviceId;
+
+    /** 设备名称 */
+    @Excel(name = "设备名称")
+    private String deviceName;
+
+    /** 日志内容 */
+    @Excel(name = "日志内容")
+    private String content;
+
+    /** 状态(1:信息:2报警) */
+    @Excel(name = "状态", readConverterExp = "1=信息,2报警")
+    private String status;
+
+    public void setDeviceLogId(Long deviceLogId)
+    {
+        this.deviceLogId = deviceLogId;
+    }
+
+    public Long getDeviceLogId()
+    {
+        return deviceLogId;
+    }
+    public void setDeviceId(String deviceId)
+    {
+        this.deviceId = deviceId;
+    }
+
+    public String getDeviceId()
+    {
+        return deviceId;
+    }
+    public void setDeviceName(String deviceName)
+    {
+        this.deviceName = deviceName;
+    }
+
+    public String getDeviceName()
+    {
+        return deviceName;
+    }
+    public void setContent(String content)
+    {
+        this.content = content;
+    }
+
+    public String getContent()
+    {
+        return content;
+    }
+    public void setStatus(String status)
+    {
+        this.status = status;
+    }
+
+    public String getStatus()
+    {
+        return status;
+    }
+
+    public DeviceLog() {
+    }
+
+    public DeviceLog(String deviceId, String deviceName, String content, String status) {
+        this.deviceId = deviceId;
+        this.deviceName = deviceName;
+        this.content = content;
+        this.status = status;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("deviceLogId", getDeviceLogId())
+            .append("deviceId", getDeviceId())
+            .append("deviceName", getDeviceName())
+            .append("content", getContent())
+            .append("status", getStatus())
+            .append("createBy", getCreateBy())
+            .append("createTime", getCreateTime())
+            .append("updateBy", getUpdateBy())
+            .append("updateTime", getUpdateTime())
+            .append("remark", getRemark())
+            .toString();
+    }
+}

+ 117 - 0
ruoyi-dongfangyaiye/src/main/java/com/ruoyi/taiye/job/AMSJob.java

@@ -0,0 +1,117 @@
+package com.ruoyi.taiye.job;
+
+import com.ruoyi.system.init.PlcConnectServiceRunner;
+import com.ruoyi.taiye.domain.DeviceLog;
+import com.ruoyi.system.enums.PLCConnectNameEnum;
+import com.ruoyi.system.enums.PLCEnum;
+import com.ruoyi.taiye.service.IDeviceLogService;
+import com.ruoyi.taiye.service.ProcessService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component("AMSJob")
+@Slf4j
+public class AMSJob {
+    @Autowired
+    PlcConnectServiceRunner plcConnectServiceRunner;
+
+    @Autowired
+    private ProcessService processService;
+
+    @Autowired
+    private IDeviceLogService deviceLogService;
+
+    public void test() {
+
+    }
+
+    /**
+     * 一号包装机下料任务
+     */
+    public void onePackingMachineUnloading() {
+        boolean b = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.PACKING_MACHINE_1.getMetadata()).readBoolean(PLCEnum.PACKING_MACHINE_UNLOADING_1.getMetadata());
+        deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.PACKING_MACHINE_1.getMetadata(),PLCConnectNameEnum.PACKING_MACHINE_1.getMetaName(),"获取到下料信号:"+b,"1"));
+        if (b) {
+            boolean b1 = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.STACKING_MACHINE.getMetadata()).readBoolean(PLCEnum.STACKING_MACHINE_FEEDING.getMetadata());
+            deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.STACKING_MACHINE.getMetadata(),PLCConnectNameEnum.STACKING_MACHINE.getMetaName(),"获取到上料信号:"+b1,"1"));
+            if (b1) {
+                processService.createPackingMachineUnloadingTask("PM_L_1", 001);
+            }
+        }
+    }
+
+    /**
+     * 二号包装机下料任务
+     */
+    public void twoPackingMachineUnloading() {
+        boolean b = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.PACKING_MACHINE_2.getMetadata()).readBoolean(PLCEnum.PACKING_MACHINE_UNLOADING_2.getMetadata());
+        deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.PACKING_MACHINE_2.getMetadata(),PLCConnectNameEnum.PACKING_MACHINE_2.getMetaName(),"获取到下料信号:"+b,"1"));
+        if (b) {
+            boolean b1 = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.STACKING_MACHINE.getMetadata()).readBoolean(PLCEnum.STACKING_MACHINE_FEEDING.getMetadata());
+            deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.STACKING_MACHINE.getMetadata(),PLCConnectNameEnum.STACKING_MACHINE.getMetaName(),"获取到上料信号:"+b1,"1"));
+            if (b1) {
+                processService.createPackingMachineUnloadingTask("PM_L_3", 001);
+            }
+        }
+    }
+
+    /**
+     * 三号包装机下料任务
+     */
+    public void threePackingMachineUnloading() {
+        boolean b = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.PACKING_MACHINE_3.getMetadata()).readBoolean(PLCEnum.PACKING_MACHINE_UNLOADING_3.getMetadata());
+        deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.PACKING_MACHINE_3.getMetadata(),PLCConnectNameEnum.PACKING_MACHINE_3.getMetaName(),"获取到下料信号:"+b,"1"));
+        if (b) {
+            boolean b1 = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.STACKING_MACHINE.getMetadata()).readBoolean(PLCEnum.STACKING_MACHINE_FEEDING.getMetadata());
+            deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.STACKING_MACHINE.getMetadata(),PLCConnectNameEnum.STACKING_MACHINE.getMetaName(),"获取到上料信号:"+b1,"1"));
+            if (b1) {
+                processService.createPackingMachineUnloadingTask("PM_L_3", 001);
+            }
+        }
+
+    }
+
+    /**
+     * 一号包装机上空
+     */
+    public void onePackingMachineUpEmptyPallets() {
+        boolean b = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.PACKING_MACHINE_1.getMetadata()).readBoolean(PLCEnum.PACKING_MACHINE_UP_EMPTY_PALLETS_1.getMetadata());
+        deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.PACKING_MACHINE_1.getMetadata(),PLCConnectNameEnum.PACKING_MACHINE_1.getMetaName(),"获取到上空信号:"+b,"1"));
+        if (b) {
+            processService.createPackingMachineUpEmptyPallets("PM_UP_1",001);
+        }
+
+    }
+
+    /**
+     * 二号包装机上空
+     */
+    public void twoPackingMachineUpEmptyPallets() {
+        boolean b = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.PACKING_MACHINE_2.getMetadata()).readBoolean(PLCEnum.PACKING_MACHINE_UP_EMPTY_PALLETS_2.getMetadata());
+        deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.PACKING_MACHINE_2.getMetadata(),PLCConnectNameEnum.PACKING_MACHINE_2.getMetaName(),"获取到上空信号:"+b,"1"));
+        if (b) {
+            processService.createPackingMachineUpEmptyPallets("PM_UP_2",001);
+        }
+    }
+
+    /**
+     * 三号包装机上空
+     */
+    public void threePackingMachineUpEmptyPallets() {
+        boolean b = plcConnectServiceRunner.getPlcServer(PLCConnectNameEnum.PACKING_MACHINE_3.getMetadata()).readBoolean(PLCEnum.PACKING_MACHINE_UP_EMPTY_PALLETS_3.getMetadata());
+        deviceLogService.insertDeviceLog(new DeviceLog(PLCConnectNameEnum.PACKING_MACHINE_3.getMetadata(),PLCConnectNameEnum.PACKING_MACHINE_3.getMetaName(),"获取到上空信号:"+b,"1"));
+        if (b) {
+            processService.createPackingMachineUpEmptyPallets("PM_UP_3",001);
+        }
+    }
+
+    /**
+     * 清空PLC信号日志
+     */
+    public void cleanPLCDeviceLog() {
+        int i = deviceLogService.cleanUpDataFromAWeekAgo();
+        log.info("已清除一周前的数据,数量:{}",i);
+    }
+
+}

+ 64 - 0
ruoyi-dongfangyaiye/src/main/java/com/ruoyi/taiye/mapper/DeviceLogMapper.java

@@ -0,0 +1,64 @@
+package com.ruoyi.taiye.mapper;
+
+import com.ruoyi.taiye.domain.DeviceLog;
+
+import java.util.List;
+
+/**
+ * 设备日志Mapper接口
+ *
+ * @author zhifei
+ * @date 2023-11-27
+ */
+public interface DeviceLogMapper
+{
+    /**
+     * 查询设备日志
+     *
+     * @param deviceLogId 设备日志主键
+     * @return 设备日志
+     */
+     DeviceLog selectDeviceLogByDeviceLogId(Long deviceLogId);
+
+    /**
+     * 查询设备日志列表
+     *
+     * @param deviceLog 设备日志
+     * @return 设备日志集合
+     */
+     List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog);
+
+    /**
+     * 新增设备日志
+     *
+     * @param deviceLog 设备日志
+     * @return 结果
+     */
+     int insertDeviceLog(DeviceLog deviceLog);
+
+    /**
+     * 修改设备日志
+     *
+     * @param deviceLog 设备日志
+     * @return 结果
+     */
+     int updateDeviceLog(DeviceLog deviceLog);
+
+    /**
+     * 删除设备日志
+     *
+     * @param deviceLogId 设备日志主键
+     * @return 结果
+     */
+     int deleteDeviceLogByDeviceLogId(Long deviceLogId);
+
+    /**
+     * 批量删除设备日志
+     *
+     * @param deviceLogIds 需要删除的数据主键集合
+     * @return 结果
+     */
+     int deleteDeviceLogByDeviceLogIds(Long[] deviceLogIds);
+
+     int cleanUpDataFromAWeekAgo();
+}

+ 72 - 0
ruoyi-dongfangyaiye/src/main/java/com/ruoyi/taiye/service/IDeviceLogService.java

@@ -0,0 +1,72 @@
+package com.ruoyi.taiye.service;
+
+import com.ruoyi.taiye.domain.DeviceLog;
+
+import java.util.List;
+
+/**
+ * 设备日志Service接口
+ *
+ * @author zhifei
+ * @date 2023-11-27
+ */
+public interface IDeviceLogService
+{
+    /**
+     * 查询设备日志
+     *
+     * @param deviceLogId 设备日志主键
+     * @return 设备日志
+     */
+     DeviceLog selectDeviceLogByDeviceLogId(Long deviceLogId);
+
+    /**
+     * 查询设备日志列表
+     *
+     * @param deviceLog 设备日志
+     * @return 设备日志集合
+     */
+     List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog);
+
+    /**
+     * 查询设备日志
+     *
+     * @param deviceLog 设备日志
+     * @return 设备日志集合
+     */
+    DeviceLog selectDeviceLogByModel(DeviceLog deviceLog);
+
+    /**
+     * 新增设备日志
+     *
+     * @param deviceLog 设备日志
+     * @return 结果
+     */
+     int insertDeviceLog(DeviceLog deviceLog);
+
+    /**
+     * 修改设备日志
+     *
+     * @param deviceLog 设备日志
+     * @return 结果
+     */
+     int updateDeviceLog(DeviceLog deviceLog);
+
+    /**
+     * 批量删除设备日志
+     *
+     * @param deviceLogIds 需要删除的设备日志主键集合
+     * @return 结果
+     */
+     int deleteDeviceLogByDeviceLogIds(Long[] deviceLogIds);
+
+    /**
+     * 删除设备日志信息
+     *
+     * @param deviceLogId 设备日志主键
+     * @return 结果
+     */
+     int deleteDeviceLogByDeviceLogId(Long deviceLogId);
+
+     int cleanUpDataFromAWeekAgo();
+}

+ 17 - 0
ruoyi-dongfangyaiye/src/main/java/com/ruoyi/taiye/service/ProcessService.java

@@ -0,0 +1,17 @@
+package com.ruoyi.taiye.service;
+
+public interface ProcessService {
+    /**
+     * 创建包装机下料及打包机下料任务
+     * @param taskType
+     * @param from
+     */
+    void createPackingMachineUnloadingTask(String taskType, Integer from);
+
+    /**
+     * 创建包装机上空托任务
+     * @param taskType 上空任务类型
+     * @param to 上空库位ID
+     */
+    void createPackingMachineUpEmptyPallets(String taskType, Integer to);
+}

+ 120 - 0
ruoyi-dongfangyaiye/src/main/java/com/ruoyi/taiye/service/impl/DeviceLogServiceImpl.java

@@ -0,0 +1,120 @@
+package com.ruoyi.taiye.service.impl;
+
+import java.util.List;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.taiye.domain.DeviceLog;
+import com.ruoyi.taiye.mapper.DeviceLogMapper;
+import com.ruoyi.taiye.service.IDeviceLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * 设备日志Service业务层处理
+ *
+ * @author zhifei
+ * @date 2023-11-27
+ */
+@Service
+public class DeviceLogServiceImpl implements IDeviceLogService
+{
+    @Autowired
+    private DeviceLogMapper deviceLogMapper;
+
+    /**
+     * 查询设备日志
+     *
+     * @param deviceLogId 设备日志主键
+     * @return 设备日志
+     */
+    @Override
+    public DeviceLog selectDeviceLogByDeviceLogId(Long deviceLogId)
+    {
+        return deviceLogMapper.selectDeviceLogByDeviceLogId(deviceLogId);
+    }
+
+    /**
+     * 查询设备日志列表
+     *
+     * @param deviceLog 设备日志
+     * @return 设备日志
+     */
+    @Override
+    public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog)
+    {
+        return deviceLogMapper.selectDeviceLogList(deviceLog);
+    }
+
+    /**
+     * 查询设备日志
+     *
+     * @param deviceLog 设备日志
+     * @return 设备日志
+     */
+    @Override
+    public DeviceLog selectDeviceLogByModel(DeviceLog deviceLog)
+    {
+        List<DeviceLog> list = deviceLogMapper.selectDeviceLogList(deviceLog);
+        if (list!=null && list.size()>0) {
+            return list.get(0);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * 新增设备日志
+     *
+     * @param deviceLog 设备日志
+     * @return 结果
+     */
+    @Override
+    public int insertDeviceLog(DeviceLog deviceLog)
+    {
+        deviceLog.setCreateTime(DateUtils.getNowDate());
+        return deviceLogMapper.insertDeviceLog(deviceLog);
+    }
+
+    /**
+     * 修改设备日志
+     *
+     * @param deviceLog 设备日志
+     * @return 结果
+     */
+    @Override
+    public int updateDeviceLog(DeviceLog deviceLog)
+    {
+        deviceLog.setUpdateTime(DateUtils.getNowDate());
+        return deviceLogMapper.updateDeviceLog(deviceLog);
+    }
+
+    /**
+     * 批量删除设备日志
+     *
+     * @param deviceLogIds 需要删除的设备日志主键
+     * @return 结果
+     */
+    @Override
+    public int deleteDeviceLogByDeviceLogIds(Long[] deviceLogIds)
+    {
+        return deviceLogMapper.deleteDeviceLogByDeviceLogIds(deviceLogIds);
+    }
+
+    /**
+     * 删除设备日志信息
+     *
+     * @param deviceLogId 设备日志主键
+     * @return 结果
+     */
+    @Override
+    public int deleteDeviceLogByDeviceLogId(Long deviceLogId)
+    {
+        return deviceLogMapper.deleteDeviceLogByDeviceLogId(deviceLogId);
+    }
+
+    @Override
+    public int cleanUpDataFromAWeekAgo() {
+        return  deviceLogMapper.cleanUpDataFromAWeekAgo();
+    }
+
+
+}

+ 70 - 0
ruoyi-dongfangyaiye/src/main/java/com/ruoyi/taiye/service/impl/ProcessServiceImpl.java

@@ -0,0 +1,70 @@
+package com.ruoyi.taiye.service.impl;
+
+import com.ruoyi.ams.business.IBusinessService;
+import com.ruoyi.ams.config.domain.dto.AgvCallDTO;
+import com.ruoyi.ams.config.domain.dto.AgvCallItemDTO;
+import com.ruoyi.ams.config.domain.dto.LotattDTO;
+import com.ruoyi.ams.task.domain.WcsTask;
+import com.ruoyi.ams.task.mapper.WcsTaskMapper;
+import com.ruoyi.base.constant.Constant;
+import com.ruoyi.base.domain.BaseLocationInfo;
+import com.ruoyi.base.service.IBaseLocationInfoService;
+import com.ruoyi.taiye.service.ProcessService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+@Slf4j
+public class ProcessServiceImpl implements ProcessService {
+
+    @Autowired
+    WcsTaskMapper wcsTaskMapper;
+
+    private final String SMID = "";
+
+    @Autowired
+    private IBusinessService iBusinessService;
+
+    @Autowired
+    private IBaseLocationInfoService iBaseLocationInfoService;
+
+    @Override
+    public void createPackingMachineUnloadingTask(String taskType, Integer from) {
+        WcsTask wcsTask = new WcsTask();
+        wcsTask.setLocationTo(SMID);
+        List<WcsTask> tasking = wcsTaskMapper.getTasking(wcsTask);
+        if (!tasking.isEmpty()){
+            return;
+        }
+        BaseLocationInfo fromLocation = iBaseLocationInfoService.selectBaseLocationInfoByIdOrNo(SMID, Constant.WAREHOUSE_ID);
+        fromLocation.setIsEmpty("N");
+        iBaseLocationInfoService.updateBaseLocationInfo(fromLocation);
+        AgvCallDTO agvCallDTO = new AgvCallDTO();
+        agvCallDTO.setLocationFrom(from+"");
+        agvCallDTO.setLocationTo(SMID);
+        iBusinessService.agvCall(Constant.FLOW_CONFIG_ID.valueOf(taskType).getValue(),agvCallDTO);
+    }
+
+    @Override
+    public void createPackingMachineUpEmptyPallets(String taskType, Integer to) {
+        WcsTask wcsTask = new WcsTask();
+        wcsTask.setLocationTo(to+"");
+        List<WcsTask> tasking = wcsTaskMapper.getTasking(wcsTask);
+        if (!tasking.isEmpty()){
+            return;
+        }
+        List<AgvCallItemDTO> agvCallItemDTOList = new ArrayList<>();
+        AgvCallItemDTO agvCallItemDTO = new AgvCallItemDTO();
+        agvCallItemDTO.setSku("EMPTY_TRAY"); // 空托
+        agvCallItemDTO.setQty(1.0);
+        agvCallItemDTOList.add(agvCallItemDTO);
+        AgvCallDTO agvCallDTO = new AgvCallDTO();
+        agvCallDTO.setLocationTo(to+"");
+        agvCallDTO.setAgvCallItemDTOList(agvCallItemDTOList);
+        iBusinessService.agvCall(Constant.FLOW_CONFIG_ID.valueOf(taskType).getValue(),agvCallDTO);
+    }
+}

+ 95 - 0
ruoyi-dongfangyaiye/src/main/resources/mapper/taiye/DeviceLogMapper.xml

@@ -0,0 +1,95 @@
+<?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.ruoyi.taiye.mapper.DeviceLogMapper">
+
+    <resultMap type="DeviceLog" id="DeviceLogResult">
+        <result property="deviceLogId"    column="device_log_id"    />
+        <result property="deviceId"    column="device_id"    />
+        <result property="deviceName"    column="device_name"    />
+        <result property="content"    column="content"    />
+        <result property="status"    column="status"    />
+        <result property="createBy"    column="create_by"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateBy"    column="update_by"    />
+        <result property="updateTime"    column="update_time"    />
+        <result property="remark"    column="remark"    />
+    </resultMap>
+
+    <sql id="selectDeviceLogVo">
+        select device_log_id, device_id, device_name, content, status, create_by, create_time, update_by, update_time, remark from device_log
+    </sql>
+
+    <select id="selectDeviceLogList" parameterType="DeviceLog" resultMap="DeviceLogResult">
+        <include refid="selectDeviceLogVo"/>
+        <where>
+            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
+            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
+        </where>
+    </select>
+
+    <select id="selectDeviceLogByDeviceLogId" parameterType="Long" resultMap="DeviceLogResult">
+        <include refid="selectDeviceLogVo"/>
+        where device_log_id = #{deviceLogId}
+    </select>
+
+    <insert id="insertDeviceLog" parameterType="DeviceLog">
+        insert into device_log
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="deviceLogId != null">device_log_id,</if>
+            <if test="deviceId != null and deviceId != ''">device_id,</if>
+            <if test="deviceName != null and deviceName != ''">device_name,</if>
+            <if test="content != null and content != ''">content,</if>
+            <if test="status != null and status != ''">status,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+            <if test="remark != null">remark,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="deviceLogId != null">#{deviceLogId},</if>
+            <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
+            <if test="deviceName != null and deviceName != ''">#{deviceName},</if>
+            <if test="content != null and content != ''">#{content},</if>
+            <if test="status != null and status != ''">#{status},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+            <if test="remark != null">#{remark},</if>
+         </trim>
+    </insert>
+
+    <update id="updateDeviceLog" parameterType="DeviceLog">
+        update device_log
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
+            <if test="deviceName != null and deviceName != ''">device_name = #{deviceName},</if>
+            <if test="content != null and content != ''">content = #{content},</if>
+            <if test="status != null and status != ''">status = #{status},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="remark != null">remark = #{remark},</if>
+        </trim>
+        where device_log_id = #{deviceLogId}
+    </update>
+
+    <delete id="deleteDeviceLogByDeviceLogId" parameterType="Long">
+        delete from device_log where device_log_id = #{deviceLogId}
+    </delete>
+
+    <delete id="deleteDeviceLogByDeviceLogIds" parameterType="String">
+        delete from device_log where device_log_id in
+        <foreach item="deviceLogId" collection="array" open="(" separator="," close=")">
+            #{deviceLogId}
+        </foreach>
+    </delete>
+
+    <delete id="cleanUpDataFromAWeekAgo">
+        delete from device_log where DATE(create_time)  &lt;= DATE(DATE_SUB(NOW(),INTERVAL 7 DAY));
+    </delete>
+</mapper>

+ 42 - 0
ruoyi-system/src/main/java/com/ruoyi/system/enums/PLCConnectNameEnum.java

@@ -0,0 +1,42 @@
+package com.ruoyi.system.enums;
+
+public enum PLCConnectNameEnum {
+
+    /**
+     * 一号包装机PLC
+     */
+    PACKING_MACHINE_1("packingMachine_1Plc","一号包装机PLC"),
+
+    /**
+     * 二号包装机PLC
+     */
+    PACKING_MACHINE_2("packingMachine_2Plc","二号包装机PLC"),
+
+    /**
+     * 三号包装机PLC
+     */
+    PACKING_MACHINE_3("packingMachine_3Plc","三号包装机PLC"),
+
+    /**
+     * 叠包机PCL
+     */
+    STACKING_MACHINE("stackingMachinePlc","叠包机PCL");
+
+    private String metadata;
+
+    private String metaName;
+
+    PLCConnectNameEnum(String metadata,String metaName) {
+        this.metadata = metadata;
+        this.metaName = metaName;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+
+    public String getMetaName() {
+        return metaName;
+    }
+
+}

+ 114 - 0
ruoyi-system/src/main/java/com/ruoyi/system/enums/PLCEnum.java

@@ -0,0 +1,114 @@
+package com.ruoyi.system.enums;
+
+public enum PLCEnum {
+
+    /**
+     * 一号包装机下料信号
+     */
+    PACKING_MACHINE_UNLOADING_1("DB5001.1.0"),
+
+    /**
+     * 二号包装机下料信号
+     */
+    PACKING_MACHINE_UNLOADING_2("DB5001.1.0"),
+
+    /**
+     * 三号包装机下料信号
+     */
+    PACKING_MACHINE_UNLOADING_3("DB5001.1.0"),
+
+    /**
+     * 一号包装机上空信号
+     */
+    PACKING_MACHINE_UP_EMPTY_PALLETS_1("DB5001.0.0"),
+
+    /**
+     * 二号包装机上空信号
+     */
+    PACKING_MACHINE_UP_EMPTY_PALLETS_2("DB5001.0.0"),
+
+    /**
+     * 三号包装机上空信号
+     */
+    PACKING_MACHINE_UP_EMPTY_PALLETS_3("DB5001.0.0"),
+
+    /**
+     * 一号包装机下料允许进入信号
+     */
+    PACKING_MACHINE_UNLOADING_ENTER_1("DB5001.1.1"),
+
+    /**
+     * 二号包装机下料允许进入信号
+     */
+    PACKING_MACHINE_UNLOADING_ENTER_2("DB5001.1.1"),
+
+    /**
+     * 三号包装机下料允许进入信号
+     */
+    PACKING_MACHINE_UNLOADING_ENTER_3("DB5001.1.1"),
+
+    /**
+     * 一号包装机上空允许进入信号
+     */
+    PACKING_MACHINE_UP_EMPTY_ENTER_1("DB5001.0.1"),
+
+    /**
+     * 二号包装机上空允许进入信号
+     */
+    PACKING_MACHINE_UP_EMPTY_ENTER_2("DB5001.0.1"),
+
+    /**
+     * 三号包装机上空允许进入信号
+     */
+    PACKING_MACHINE_UP_EMPTY_ENTER_3("DB5001.0.1"),
+
+    /**
+     * 一号包装机下料完成信号
+     */
+    PACKING_MACHINE_UNLOADING_Leave_1("DB5000.1.0"),
+
+    /**
+     * 二号包装机下料完成信号
+     */
+    PACKING_MACHINE_UNLOADING_Leave_2("DB5000.1.0"),
+
+    /**
+     * 三号包装机下料完成信号
+     */
+    PACKING_MACHINE_UNLOADING_Leave_3("DB5000.1.0"),
+
+    /**
+     * 一号包装机上空完成信号
+     */
+    PACKING_MACHINE_UP_EMPTY_Leave_1("DB5000.0.1"),
+
+    /**
+     * 二号包装机上空完成信号
+     */
+    PACKING_MACHINE_UP_EMPTY_Leave_2("DB5000.0.1"),
+
+    /**
+     * 三号包装机上空完成信号
+     */
+    PACKING_MACHINE_UP_EMPTY_Leave_3("DB5000.0.1"),
+
+    /**
+     * 叠包机上料信号
+     */
+    STACKING_MACHINE_FEEDING("DB5001.0.0"),
+
+    /**
+     * 叠包机上料完成信号
+     */
+    STACKING_MACHINE_FEEDING_FINISH("DB5000.0.0");
+
+    private String metadata;
+
+    PLCEnum(String metadata) {
+        this.metadata = metadata;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+}

+ 44 - 0
ruoyi-ui/src/api/ams/log.js

@@ -0,0 +1,44 @@
+import request from '@/utils/request'
+
+// 查询设备日志列表
+export function listLog(query) {
+  return request({
+    url: '/device/log/list',
+    method: 'get',
+    params: query
+  })
+}
+
+// 查询设备日志详细
+export function getLog(deviceLogId) {
+  return request({
+    url: '/device/log/' + deviceLogId,
+    method: 'get'
+  })
+}
+
+// 新增设备日志
+export function addLog(data) {
+  return request({
+    url: '/device/log',
+    method: 'post',
+    data: data
+  })
+}
+
+// 修改设备日志
+export function updateLog(data) {
+  return request({
+    url: '/device/log',
+    method: 'put',
+    data: data
+  })
+}
+
+// 删除设备日志
+export function delLog(deviceLogId) {
+  return request({
+    url: '/device/log/' + deviceLogId,
+    method: 'delete'
+  })
+}

+ 214 - 0
ruoyi-ui/src/views/ams/log/index.vue

@@ -0,0 +1,214 @@
+<template>
+  <div class="app-container">
+    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
+      <el-form-item label="设备名称" prop="deviceName">
+        <el-input
+          v-model="queryParams.deviceName"
+          placeholder="请输入设备名称"
+          clearable
+          size="small"
+          @keyup.enter.native="handleQuery"
+        />
+      </el-form-item>
+      <el-form-item>
+        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
+        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
+      </el-form-item>
+    </el-form>
+
+
+    <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55" align="center" />
+      <el-table-column label="日志编号" align="center" prop="deviceLogId" />
+      <el-table-column label="设备id" align="center" prop="deviceId" />
+      <el-table-column label="设备名称" align="center" prop="deviceName" />
+      <el-table-column label="日志内容" align="center" prop="content" />
+      <el-table-column label="状态" align="center" prop="status" />
+      <el-table-column label="备注" align="center" prop="remark" />
+      <el-table-column label="时间" align="center" prop="createTime" />
+      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
+        <template slot-scope="scope">
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-edit"
+            @click="handleUpdate(scope.row)"
+            v-hasPermi="['system:log:edit']"
+          >修改</el-button>
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-delete"
+            @click="handleDelete(scope.row)"
+            v-hasPermi="['system:log:remove']"
+          >删除</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <pagination
+      v-show="total>0"
+      :total="total"
+      :page.sync="queryParams.pageNum"
+      :limit.sync="queryParams.pageSize"
+      @pagination="getList"
+    />
+  </div>
+</template>
+
+<script>
+import { listLog, getLog, delLog, addLog, updateLog } from "@/api/ams/log";
+
+export default {
+  name: "Log",
+  data() {
+    return {
+      // 遮罩层
+      loading: true,
+      // 选中数组
+      ids: [],
+      // 非单个禁用
+      single: true,
+      // 非多个禁用
+      multiple: true,
+      // 显示搜索条件
+      showSearch: true,
+      // 总条数
+      total: 0,
+      // 设备日志表格数据
+      logList: [],
+      // 弹出层标题
+      title: "",
+      // 是否显示弹出层
+      open: false,
+      // 查询参数
+      queryParams: {
+        pageNum: 1,
+        pageSize: 10,
+        deviceId: null,
+        deviceName: null,
+      },
+      // 表单参数
+      form: {},
+      // 表单校验
+      rules: {
+        deviceId: [
+          { required: true, message: "设备id不能为空", trigger: "blur" }
+        ],
+        deviceName: [
+          { required: true, message: "设备名称不能为空", trigger: "blur" }
+        ],
+        content: [
+          { required: true, message: "日志内容不能为空", trigger: "blur" }
+        ],
+        status: [
+          { required: true, message: "状态不能为空", trigger: "blur" }
+        ],
+      }
+    };
+  },
+  created() {
+    this.getList();
+  },
+  methods: {
+    /** 查询设备日志列表 */
+    getList() {
+      this.loading = true;
+      listLog(this.queryParams).then(response => {
+        this.logList = response.rows;
+        this.total = response.total;
+        this.loading = false;
+      });
+    },
+    // 取消按钮
+    cancel() {
+      this.open = false;
+      this.reset();
+    },
+    // 表单重置
+    reset() {
+      this.form = {
+        deviceLogId: null,
+        deviceId: null,
+        deviceName: null,
+        content: null,
+        status: "0",
+        createBy: null,
+        createTime: null,
+        updateBy: null,
+        updateTime: null,
+        remark: null
+      };
+      this.resetForm("form");
+    },
+    /** 搜索按钮操作 */
+    handleQuery() {
+      this.queryParams.pageNum = 1;
+      this.getList();
+    },
+    /** 重置按钮操作 */
+    resetQuery() {
+      this.resetForm("queryForm");
+      this.handleQuery();
+    },
+    // 多选框选中数据
+    handleSelectionChange(selection) {
+      this.ids = selection.map(item => item.deviceLogId)
+      this.single = selection.length!==1
+      this.multiple = !selection.length
+    },
+    /** 新增按钮操作 */
+    handleAdd() {
+      this.reset();
+      this.open = true;
+      this.title = "添加设备日志";
+    },
+    /** 修改按钮操作 */
+    handleUpdate(row) {
+      this.reset();
+      const deviceLogId = row.deviceLogId || this.ids
+      getLog(deviceLogId).then(response => {
+        this.form = response.data;
+        this.open = true;
+        this.title = "修改设备日志";
+      });
+    },
+    /** 提交按钮 */
+    submitForm() {
+      this.$refs["form"].validate(valid => {
+        if (valid) {
+          if (this.form.deviceLogId != null) {
+            updateLog(this.form).then(response => {
+              this.$modal.msgSuccess("修改成功");
+              this.open = false;
+              this.getList();
+            });
+          } else {
+            addLog(this.form).then(response => {
+              this.$modal.msgSuccess("新增成功");
+              this.open = false;
+              this.getList();
+            });
+          }
+        }
+      });
+    },
+    /** 删除按钮操作 */
+    handleDelete(row) {
+      const deviceLogIds = row.deviceLogId || this.ids;
+      this.$modal.confirm('是否确认删除设备日志编号为"' + deviceLogIds + '"的数据项?').then(function() {
+        return delLog(deviceLogIds);
+      }).then(() => {
+        this.getList();
+        this.$modal.msgSuccess("删除成功");
+      }).catch(() => {});
+    },
+    /** 导出按钮操作 */
+    handleExport() {
+      this.download('system/log/export', {
+        ...this.queryParams
+      }, `log_${new Date().getTime()}.xlsx`)
+    }
+  }
+};
+</script>