From 2dbbb96508c58c296d9f15f364fd343c66c941a1 Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期三, 21 十月 2026 15:14:20 +0800
Subject: [PATCH] feat(芯导): 新增库存盘点/库存时间设置/设备远程监控/审批流程定义等模块

---
 src/main/java/com/ruoyi/approve/enums/ApproveType.java                               |    5 
 src/main/java/com/ruoyi/procurementrecord/pojo/StockTimeSetting.java                 |   42 +++++
 src/main/java/com/ruoyi/procurementrecord/pojo/StockTaking.java                      |   64 ++++++++
 src/main/java/com/ruoyi/envaccess/mapper/EnvDeviceCommandMapper.java                 |    9 +
 src/main/java/com/ruoyi/procurementrecord/controller/StockTimeSettingController.java |   58 +++++++
 src/main/java/com/ruoyi/envaccess/controller/EnvDeviceCommandController.java         |  131 ++++++++++++++++
 src/main/java/com/ruoyi/envaccess/pojo/EnvDeviceCommand.java                         |   52 ++++++
 src/main/java/com/ruoyi/procurementrecord/mapper/StockTakingMapper.java              |    9 +
 src/main/java/com/ruoyi/procurementrecord/mapper/StockTimeSettingMapper.java         |    9 +
 src/main/java/com/ruoyi/procurementrecord/controller/StockTakingController.java      |   71 ++++++++
 10 files changed, 448 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/ruoyi/approve/enums/ApproveType.java b/src/main/java/com/ruoyi/approve/enums/ApproveType.java
index af84828..6d87157 100644
--- a/src/main/java/com/ruoyi/approve/enums/ApproveType.java
+++ b/src/main/java/com/ruoyi/approve/enums/ApproveType.java
@@ -4,12 +4,13 @@
 
 public enum ApproveType {
     FREE_COLLABORATION(1, "鑷敱鍗忓悓瀹℃壒"),
-    LEAVE(2, "璇峰亣绠$悊"),
+    LEAVE(2, "璇峰亣瀹℃壒"),
     SALES_CONTRACT(3, "閿�鍞鎵�"),
     REIMBURSEMENT(4, "鎶ラ攢瀹℃壒"),
     PURCHASE_PLAN(5, "閲囪喘瀹℃壒"),
     QUOTATION(6, "鎶ヤ环瀹℃壒"),
-    OUTBOUND(7, "鍑哄簱瀹℃壒");
+    OUTBOUND(7, "鍑哄簱瀹℃壒"),
+    CONTRACT(8, "鍚堝悓瀹℃壒");
 
     private final int code;
     private final String label;
diff --git a/src/main/java/com/ruoyi/envaccess/controller/EnvDeviceCommandController.java b/src/main/java/com/ruoyi/envaccess/controller/EnvDeviceCommandController.java
new file mode 100644
index 0000000..096a7fa
--- /dev/null
+++ b/src/main/java/com/ruoyi/envaccess/controller/EnvDeviceCommandController.java
@@ -0,0 +1,131 @@
+package com.ruoyi.envaccess.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.device.mapper.DeviceDefectRecordMapper;
+import com.ruoyi.device.mapper.DeviceLedgerMapper;
+import com.ruoyi.device.pojo.DeviceDefectRecord;
+import com.ruoyi.device.pojo.DeviceLedger;
+import com.ruoyi.envaccess.mapper.EnvDeviceCommandMapper;
+import com.ruoyi.envaccess.pojo.EnvDeviceCommand;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import io.swagger.annotations.Api;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 璁惧杩滅▼鐩戞帶锛氬紓甯告姤璀� + 杩滅▼鍚仠鎺у埗锛堟棤纭欢锛屾寚浠よ褰� + 鐘舵�佹ā鎷燂級
+ */
+@RestController
+@RequestMapping("/environmentAccess/deviceCommand")
+@Api(tags = "鐜繚闂ㄧ-璁惧杩滅▼鐩戞帶")
+public class EnvDeviceCommandController {
+
+    @Autowired
+    private EnvDeviceCommandMapper envDeviceCommandMapper;
+
+    @Autowired
+    private DeviceLedgerMapper deviceLedgerMapper;
+
+    @Autowired
+    private DeviceDefectRecordMapper deviceDefectRecordMapper;
+
+    /** 璁惧鍒楄〃锛堣繙绋嬫帶鍒跺璞★級 */
+    @GetMapping("/deviceList")
+    public AjaxResult deviceList() {
+        List<DeviceLedger> list = deviceLedgerMapper.selectList(null);
+        if (list != null && list.size() > 200) list = list.subList(0, 200);
+        return AjaxResult.success(list);
+    }
+
+    /** 寮傚父鎶ヨ鍒楄〃锛堟潵婧愶細璁惧鏁呴殰璁板綍锛� */
+    @GetMapping("/alarmList")
+    public AjaxResult alarmList() {
+        LambdaQueryWrapper<DeviceDefectRecord> w = new LambdaQueryWrapper<>();
+        w.orderByDesc(DeviceDefectRecord::getId);
+        w.last("limit 100");
+        List<DeviceDefectRecord> defects = deviceDefectRecordMapper.selectList(w);
+        List<Map<String, Object>> result = new ArrayList<>();
+        Map<Long, String> deviceNameMap = new HashMap<>();
+        try {
+            List<DeviceLedger> ledgers = deviceLedgerMapper.selectList(null);
+            if (ledgers != null) {
+                for (DeviceLedger d : ledgers) {
+                    deviceNameMap.put(d.getId(), d.getDeviceName());
+                }
+            }
+        } catch (Exception ignored) {
+        }
+        if (defects != null) {
+            for (DeviceDefectRecord d : defects) {
+                Map<String, Object> m = new HashMap<>();
+                m.put("id", d.getId());
+                m.put("deviceLedgerId", d.getDeviceLedgerId());
+                m.put("deviceName", deviceNameMap.get(d.getDeviceLedgerId()));
+                m.put("defectDescription", d.getDefectDescription());
+                m.put("status", d.getStatus());
+                m.put("eliminateTime", d.getEliminateTime());
+                m.put("createTime", d.getCreateTime());
+                boolean handled = d.getEliminateTime() != null;
+                m.put("handled", handled);
+                result.add(m);
+            }
+        }
+        return AjaxResult.success(result);
+    }
+
+    /** 鎸囦护璁板綍鍒嗛〉 */
+    @GetMapping("/listPage")
+    public AjaxResult listPage(Page page, EnvDeviceCommand query) {
+        LambdaQueryWrapper<EnvDeviceCommand> w = new LambdaQueryWrapper<>();
+        if (query != null) {
+            if (query.getDeviceName() != null && !query.getDeviceName().isEmpty()) {
+                w.like(EnvDeviceCommand::getDeviceName, query.getDeviceName());
+            }
+            if (query.getCommandType() != null && !query.getCommandType().isEmpty()) {
+                w.eq(EnvDeviceCommand::getCommandType, query.getCommandType());
+            }
+        }
+        w.orderByDesc(EnvDeviceCommand::getId);
+        return AjaxResult.success(envDeviceCommandMapper.selectPage(page, w));
+    }
+
+    /** 涓嬪彂杩滅▼鍚仠鎸囦护锛堟ā鎷熸墽琛岋紝璁板綍鎸囦护涓庡洖鎵э級 */
+    @PostMapping("/send")
+    public AjaxResult send(@RequestBody EnvDeviceCommand command) {
+        if (command == null || command.getDeviceLedgerId() == null) {
+            return AjaxResult.error("璇烽�夋嫨璁惧");
+        }
+        if (command.getDeviceName() == null || command.getDeviceName().isEmpty()) {
+            try {
+                DeviceLedger ledger = deviceLedgerMapper.selectById(command.getDeviceLedgerId());
+                if (ledger != null) command.setDeviceName(ledger.getDeviceName());
+            } catch (Exception ignored) {
+            }
+        }
+        String type = command.getCommandType() == null ? "start" : command.getCommandType();
+        command.setCommandType(type);
+        command.setCommandStatus("success");
+        command.setCommandTime(LocalDateTime.now());
+        command.setCreateTime(LocalDateTime.now());
+        command.setUpdateTime(LocalDateTime.now());
+        command.setResultMsg(("start".equals(type) ? "鍚姩" : "鍋滄") + "鎸囦护妯℃嫙鎵ц鎴愬姛锛堟湭鎺ュ叆鐪熷疄璁惧锛屼粎璁板綍鎸囦护锛�");
+        try {
+            command.setOperator(SecurityUtils.getLoginUser().getUser().getNickName());
+        } catch (Exception ignored) {
+        }
+        try {
+            command.setTenantId(SecurityUtils.getLoginUser().getTenantId());
+        } catch (Exception ignored) {
+        }
+        envDeviceCommandMapper.insert(command);
+        return AjaxResult.success(command.getResultMsg());
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/envaccess/mapper/EnvDeviceCommandMapper.java b/src/main/java/com/ruoyi/envaccess/mapper/EnvDeviceCommandMapper.java
new file mode 100644
index 0000000..fbc6b07
--- /dev/null
+++ b/src/main/java/com/ruoyi/envaccess/mapper/EnvDeviceCommandMapper.java
@@ -0,0 +1,9 @@
+package com.ruoyi.envaccess.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.envaccess.pojo.EnvDeviceCommand;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface EnvDeviceCommandMapper extends BaseMapper<EnvDeviceCommand> {
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/envaccess/pojo/EnvDeviceCommand.java b/src/main/java/com/ruoyi/envaccess/pojo/EnvDeviceCommand.java
new file mode 100644
index 0000000..59a52fe
--- /dev/null
+++ b/src/main/java/com/ruoyi/envaccess/pojo/EnvDeviceCommand.java
@@ -0,0 +1,52 @@
+package com.ruoyi.envaccess.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Data
+@TableName("env_device_command")
+public class EnvDeviceCommand {
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    @ApiModelProperty("璁惧鍙拌处id")
+    private Long deviceLedgerId;
+
+    @ApiModelProperty("璁惧鍚嶇О")
+    private String deviceName;
+
+    @ApiModelProperty("鎸囦护绫诲瀷 start=鍚姩 stop=鍋滄")
+    private String commandType;
+
+    @ApiModelProperty("鎸囦护鐘舵�� pending=涓嬪彂涓� success=鎴愬姛 failed=澶辫触")
+    private String commandStatus;
+
+    @ApiModelProperty("鎿嶄綔浜�")
+    private String operator;
+
+    @ApiModelProperty("涓嬪彂鏃堕棿")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime commandTime;
+
+    @ApiModelProperty("鎵ц缁撴灉")
+    private String resultMsg;
+
+    private String remark;
+
+    private Long tenantId;
+
+    private Long createUser;
+
+    private LocalDateTime createTime;
+
+    private Long updateUser;
+
+    private LocalDateTime updateTime;
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/procurementrecord/controller/StockTakingController.java b/src/main/java/com/ruoyi/procurementrecord/controller/StockTakingController.java
new file mode 100644
index 0000000..3be7f78
--- /dev/null
+++ b/src/main/java/com/ruoyi/procurementrecord/controller/StockTakingController.java
@@ -0,0 +1,71 @@
+package com.ruoyi.procurementrecord.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.procurementrecord.mapper.StockTakingMapper;
+import com.ruoyi.procurementrecord.pojo.StockTaking;
+import io.swagger.annotations.Api;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.time.LocalDateTime;
+import java.util.Arrays;
+
+@RestController
+@RequestMapping("/stockTaking")
+@Api(tags = "浠撳偍鐗╂祦-搴撳瓨鐩樼偣")
+public class StockTakingController {
+
+    @Autowired
+    private StockTakingMapper stockTakingMapper;
+
+    @GetMapping("/listPage")
+    public AjaxResult listPage(Page page, StockTaking q) {
+        LambdaQueryWrapper<StockTaking> w = new LambdaQueryWrapper<>();
+        if (q != null) {
+            if (q.getProductCategory() != null && !q.getProductCategory().isEmpty()) {
+                w.like(StockTaking::getProductCategory, q.getProductCategory());
+            }
+            if (q.getSpecificationModel() != null && !q.getSpecificationModel().isEmpty()) {
+                w.like(StockTaking::getSpecificationModel, q.getSpecificationModel());
+            }
+        }
+        w.orderByDesc(StockTaking::getId);
+        return AjaxResult.success(stockTakingMapper.selectPage(page, w));
+    }
+
+    @PostMapping
+    public AjaxResult add(@RequestBody StockTaking o) {
+        if (o.getBookNum() != null && o.getActualNum() != null) {
+            o.setDiffNum(o.getActualNum().subtract(o.getBookNum()));
+        }
+        fillTenant(o);
+        o.setCreateTime(LocalDateTime.now());
+        o.setUpdateTime(LocalDateTime.now());
+        return AjaxResult.success(stockTakingMapper.insert(o) > 0);
+    }
+
+    @PutMapping
+    public AjaxResult edit(@RequestBody StockTaking o) {
+        if (o.getBookNum() != null && o.getActualNum() != null) {
+            o.setDiffNum(o.getActualNum().subtract(o.getBookNum()));
+        }
+        o.setUpdateTime(LocalDateTime.now());
+        return AjaxResult.success(stockTakingMapper.updateById(o) > 0);
+    }
+
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids) {
+        return AjaxResult.success(stockTakingMapper.deleteBatchIds(Arrays.asList(ids)) > 0);
+    }
+
+    private void fillTenant(StockTaking o) {
+        if (o.getTenantId() == null) {
+            try {
+                o.setTenantId(com.ruoyi.common.utils.SecurityUtils.getLoginUser().getTenantId());
+            } catch (Exception ignored) {
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/procurementrecord/controller/StockTimeSettingController.java b/src/main/java/com/ruoyi/procurementrecord/controller/StockTimeSettingController.java
new file mode 100644
index 0000000..313fca5
--- /dev/null
+++ b/src/main/java/com/ruoyi/procurementrecord/controller/StockTimeSettingController.java
@@ -0,0 +1,58 @@
+package com.ruoyi.procurementrecord.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.procurementrecord.mapper.StockTimeSettingMapper;
+import com.ruoyi.procurementrecord.pojo.StockTimeSetting;
+import io.swagger.annotations.Api;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.time.LocalDateTime;
+import java.util.Arrays;
+import java.util.List;
+
+@RestController
+@RequestMapping("/stockTimeSetting")
+@Api(tags = "浠撳偍鐗╂祦-搴撳瓨鏃堕棿璁剧疆")
+public class StockTimeSettingController {
+
+    @Autowired
+    private StockTimeSettingMapper stockTimeSettingMapper;
+
+    @GetMapping("/list")
+    public AjaxResult list() {
+        LambdaQueryWrapper<StockTimeSetting> w = new LambdaQueryWrapper<>();
+        w.orderByDesc(StockTimeSetting::getId);
+        List<StockTimeSetting> list = stockTimeSettingMapper.selectList(w);
+        return AjaxResult.success(list);
+    }
+
+    @PostMapping
+    public AjaxResult add(@RequestBody StockTimeSetting o) {
+        fillTenant(o);
+        o.setCreateTime(LocalDateTime.now());
+        o.setUpdateTime(LocalDateTime.now());
+        return AjaxResult.success(stockTimeSettingMapper.insert(o) > 0);
+    }
+
+    @PutMapping
+    public AjaxResult edit(@RequestBody StockTimeSetting o) {
+        o.setUpdateTime(LocalDateTime.now());
+        return AjaxResult.success(stockTimeSettingMapper.updateById(o) > 0);
+    }
+
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids) {
+        return AjaxResult.success(stockTimeSettingMapper.deleteBatchIds(Arrays.asList(ids)) > 0);
+    }
+
+    private void fillTenant(StockTimeSetting o) {
+        if (o.getTenantId() == null) {
+            try {
+                o.setTenantId(com.ruoyi.common.utils.SecurityUtils.getLoginUser().getTenantId());
+            } catch (Exception ignored) {
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/procurementrecord/mapper/StockTakingMapper.java b/src/main/java/com/ruoyi/procurementrecord/mapper/StockTakingMapper.java
new file mode 100644
index 0000000..534052b
--- /dev/null
+++ b/src/main/java/com/ruoyi/procurementrecord/mapper/StockTakingMapper.java
@@ -0,0 +1,9 @@
+package com.ruoyi.procurementrecord.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.procurementrecord.pojo.StockTaking;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface StockTakingMapper extends BaseMapper<StockTaking> {
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/procurementrecord/mapper/StockTimeSettingMapper.java b/src/main/java/com/ruoyi/procurementrecord/mapper/StockTimeSettingMapper.java
new file mode 100644
index 0000000..0bbe9a5
--- /dev/null
+++ b/src/main/java/com/ruoyi/procurementrecord/mapper/StockTimeSettingMapper.java
@@ -0,0 +1,9 @@
+package com.ruoyi.procurementrecord.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.procurementrecord.pojo.StockTimeSetting;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface StockTimeSettingMapper extends BaseMapper<StockTimeSetting> {
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/procurementrecord/pojo/StockTaking.java b/src/main/java/com/ruoyi/procurementrecord/pojo/StockTaking.java
new file mode 100644
index 0000000..e91e8bd
--- /dev/null
+++ b/src/main/java/com/ruoyi/procurementrecord/pojo/StockTaking.java
@@ -0,0 +1,64 @@
+package com.ruoyi.procurementrecord.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+@Data
+@TableName("stock_taking")
+public class StockTaking {
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    @ApiModelProperty("鐩樼偣鍗曞彿")
+    private String code;
+
+    @ApiModelProperty("搴撳瓨璁板綍id")
+    private Integer customStorageId;
+
+    @ApiModelProperty("鎵规鍙�")
+    private String inboundBatches;
+
+    @ApiModelProperty("浜у搧澶х被")
+    private String productCategory;
+
+    @ApiModelProperty("瑙勬牸鍨嬪彿")
+    private String specificationModel;
+
+    @ApiModelProperty("鍗曚綅")
+    private String unit;
+
+    @ApiModelProperty("璐﹂潰鏁伴噺")
+    private BigDecimal bookNum;
+
+    @ApiModelProperty("瀹炵洏鏁伴噺")
+    private BigDecimal actualNum;
+
+    @ApiModelProperty("宸紓鏁伴噺")
+    private BigDecimal diffNum;
+
+    @ApiModelProperty("鐩樼偣鏃ユ湡")
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private LocalDate takingDate;
+
+    @ApiModelProperty("鐩樼偣浜�")
+    private String takingUser;
+
+    @ApiModelProperty("澶囨敞")
+    private String remark;
+
+    private Long createUser;
+    private LocalDateTime createTime;
+    private Long updateUser;
+    private LocalDateTime updateTime;
+    @com.baomidou.mybatisplus.annotation.TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT)
+    private Long tenantId;
+}
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/procurementrecord/pojo/StockTimeSetting.java b/src/main/java/com/ruoyi/procurementrecord/pojo/StockTimeSetting.java
new file mode 100644
index 0000000..bdddabb
--- /dev/null
+++ b/src/main/java/com/ruoyi/procurementrecord/pojo/StockTimeSetting.java
@@ -0,0 +1,42 @@
+package com.ruoyi.procurementrecord.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+@Data
+@TableName("stock_time_setting")
+public class StockTimeSetting {
+
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    @ApiModelProperty("棰勮妫�娴嬫椂闂�(HH:mm)")
+    private String warningCheckTime;
+
+    @ApiModelProperty("鐩樼偣鍛ㄦ湡(鏃�/鍛�/鏈�)")
+    private String stockTakingCycle;
+
+    @ApiModelProperty("鍛ㄨ浆鐜囬璀﹀ぉ鏁�")
+    private Integer turnoverWarnDays;
+
+    @ApiModelProperty("姣忔湀鑷姩鐩樼偣鏃�")
+    private Integer autoTakingDay;
+
+    @ApiModelProperty("鏄惁鍚敤")
+    private Integer enabled;
+
+    @ApiModelProperty("澶囨敞")
+    private String remark;
+
+    private Long createUser;
+    private LocalDateTime createTime;
+    private Long updateUser;
+    private LocalDateTime updateTime;
+    @com.baomidou.mybatisplus.annotation.TableField(fill = com.baomidou.mybatisplus.annotation.FieldFill.INSERT)
+    private Long tenantId;
+}
\ No newline at end of file

--
Gitblit v1.9.3