From 3ff2a2c1789d692a64a43e9f7e70ca5b3578b0a8 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期四, 21 五月 2026 15:01:22 +0800
Subject: [PATCH] feat(home): 添加生产看板功能并优化订单查询性能

---
 src/main/java/com/ruoyi/device/service/impl/DeviceLedgerServiceImpl.java |   49 ++++++++++++++++++++++---------------------------
 1 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/src/main/java/com/ruoyi/device/service/impl/DeviceLedgerServiceImpl.java b/src/main/java/com/ruoyi/device/service/impl/DeviceLedgerServiceImpl.java
index 31c2f0e..2b9c9be 100644
--- a/src/main/java/com/ruoyi/device/service/impl/DeviceLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/device/service/impl/DeviceLedgerServiceImpl.java
@@ -2,9 +2,9 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -13,31 +13,29 @@
 import com.ruoyi.device.mapper.DeviceLedgerMapper;
 import com.ruoyi.device.pojo.DeviceLedger;
 import com.ruoyi.device.service.IDeviceLedgerService;
-import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.framework.web.domain.R;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysUserMapper;
-import lombok.AllArgsConstructor;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.time.ZoneOffset;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
 @Service
-@AllArgsConstructor
+@RequiredArgsConstructor
 @Slf4j
 public class DeviceLedgerServiceImpl  extends ServiceImpl<DeviceLedgerMapper, DeviceLedger> implements IDeviceLedgerService {
 
-    @Autowired
-    private DeviceLedgerMapper deviceLedgerMapper;
-    @Autowired
-    private SysUserMapper sysUserMapper;
+    private final DeviceLedgerMapper deviceLedgerMapper;
+    private final SysUserMapper sysUserMapper;
 
     @Override
     public IPage<DeviceLedgerDto> queryPage(Page page, DeviceLedgerDto deviceLedger) {
@@ -46,33 +44,25 @@
     }
 
     @Override
-    public AjaxResult saveDeviceLedger(DeviceLedger deviceLedger) {
+    public R<?> saveDeviceLedger(DeviceLedger deviceLedger) {
         LambdaQueryWrapper<DeviceLedger> deviceLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>();
-        deviceLedgerLambdaQueryWrapper.eq(DeviceLedger::getDeviceModel,deviceLedger.getDeviceModel());
+        deviceLedgerLambdaQueryWrapper.eq(DeviceLedger::getDeviceName,deviceLedger.getDeviceName());
         if (this.count(deviceLedgerLambdaQueryWrapper) > 0) {
-            return AjaxResult.error("璁惧鍨嬪彿宸插瓨鍦�");
+            return R.fail("璁惧鍚嶇О宸插瓨鍦�");
         }
         boolean save = this.save(deviceLedger);
         if (save){
-            return AjaxResult.success();
+            return R.ok();
         }
-        return AjaxResult.error();
+        return R.fail();
     }
 
     @Override
-    public AjaxResult updateDeviceLedger(DeviceLedger deviceLedger) {
-        if (ObjectUtils.isNotNull(deviceLedger.getStartRuntimeTime()) && ObjectUtils.isNotNull(deviceLedger.getEndRuntimeTime())){
-            //璁$畻杩愯鏃堕暱
-            long start = deviceLedger.getStartRuntimeTime().toEpochSecond(ZoneOffset.UTC) * 1000;
-            long end = deviceLedger.getEndRuntimeTime().toEpochSecond(ZoneOffset.UTC) * 1000;
-            long diffMillis = Math.abs(end - start);
-            double time = diffMillis / (1000.0 * 60 * 60);// 姣 -> 绉� -> 鍒嗛挓 -> 灏忔椂
-            deviceLedger.setRuntimeDuration(time+"h");
-        }
+    public R<?> updateDeviceLedger(DeviceLedger deviceLedger) {
         if (this.updateById(deviceLedger)) {
-            return AjaxResult.success();
+            return R.ok();
         }
-        return AjaxResult.error();
+        return R.fail();
     }
 
     @Override
@@ -122,6 +112,11 @@
                 deviceLedger.setCreateUser(SecurityUtils.getUserId().intValue());
             }
             BeanUtils.copyProperties(c,deviceLedger);
+            // 閫氳繃鍚◣鍗曚环銆佹暟閲忋�佺◣鐜囪绠楀惈绋庢�讳环锛屼笉鍚◣鎬讳环
+            deviceLedger.setTaxIncludingPriceTotal(c.getTaxIncludingPriceUnit());
+            deviceLedger.setNumber(BigDecimal.ONE);
+            deviceLedger.setPlanRuntimeTime(DateUtils.toLocalDate(c.getPlanRuntimeTime()));
+            deviceLedger.setUnTaxIncludingPriceTotal(deviceLedger.getTaxIncludingPriceTotal().divide(BigDecimal.ONE.add(c.getTaxRate()),2, RoundingMode.HALF_UP));
             deviceLedgerMapper.insert(deviceLedger);
         });
 

--
Gitblit v1.9.3