Browse Source

修改设备成本导入

yusm 6 months ago
parent
commit
21d0b7b473

+ 7 - 5
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DeviceCostServiceImpl.java

@@ -150,8 +150,10 @@ public class DeviceCostServiceImpl extends ServiceImpl<DeviceCostMapper, DeviceC
                 }
                 boolean NoExists = false;
                 for (int i = 0; i < 3; i++) {
-                    if (row.getCell(i) != null) {
+                    if (i!=2&&row.getCell(i) != null) {
                         row.getCell(i).setCellType(CellType.STRING);
+                    }else {
+                        row.getCell(i).setCellType(CellType.NUMERIC);
                     }
                 }
                 if (row.getCell(0) == null) {
@@ -168,8 +170,8 @@ public class DeviceCostServiceImpl extends ServiceImpl<DeviceCostMapper, DeviceC
                 }
                 String deviceCode = row.getCell(0)==null?null:row.getCell(0).getStringCellValue();
                 String deviceName = row.getCell(1)==null?null:row.getCell(1).getStringCellValue();
-                String monthCost = row.getCell(2)==null?null:row.getCell(2).getStringCellValue();
-                if (StringUtils.isNotEmpty(deviceCode)&&StringUtils.isNotEmpty(deviceName)&&StringUtils.isNotEmpty(monthCost)){
+                Double monthCost = row.getCell(2)==null?null:row.getCell(2).getNumericCellValue();
+                if (StringUtils.isNotEmpty(deviceCode)&&StringUtils.isNotEmpty(deviceName)&&monthCost!=null){
                     for (Device device : deviceList) {
                         if (deviceCode.equals(device.getDeviceCode())){
                             NoExists=true;
@@ -184,13 +186,13 @@ public class DeviceCostServiceImpl extends ServiceImpl<DeviceCostMapper, DeviceC
                                 msg.setError("第"+dataIndex+"行设备名称不匹配");
                                 return msg;
                             }
-                            if (BigDecimal.valueOf(Long.parseLong(monthCost)).compareTo(BigDecimal.ZERO)<0){
+                            if (BigDecimal.valueOf(monthCost).compareTo(BigDecimal.ZERO)<0){
                                 msg.setError("第"+dataIndex+"行当月成本为负数");
                                 return msg;
                             }
                             DeviceCost deviceCost = new DeviceCost();
                             deviceCost.setDeviceId(device.getId());
-                            deviceCost.setMonthCost(BigDecimal.valueOf(Double.parseDouble(monthCost)));
+                            deviceCost.setMonthCost(BigDecimal.valueOf(monthCost));
                             deviceCost.setYmonth(ymonthStr);
 
                             if (!deviceCostArrayList.isEmpty()){

+ 6 - 5
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DeviceLogServiceImpl.java

@@ -21,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.Duration;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -162,8 +163,8 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
 
                 Duration duration = Duration.between(group[0], group[1]);
                 double hours = duration.toMinutes() / 60.0; // 转换为小时
-                // 四舍五入保留位小数
-                hours = Math.round(hours * 10.0) / 10.0;
+                // 四舍五入保留位小数
+                hours = new BigDecimal(hours).setScale(2, RoundingMode.HALF_UP).doubleValue();
                 String createDate = group[0].format(formatterDate);
                 System.out.println("开始时间: " + formatStart + ", 结束时间: " + formatEnd+",时间差:"+hours+",日期:"+createDate);
             }
@@ -175,7 +176,7 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
                 Duration duration = Duration.between(deviceLog.getStartTime(), deviceLog.getEndTime());
                 double hours = duration.toMinutes() / 60.0; // 转换为小时
                 // 四舍五入保留一位小数
-                hours = Math.round(hours * 10.0) / 10.0;
+                hours = new BigDecimal(hours).setScale(2, RoundingMode.HALF_UP).doubleValue();
 
                 deviceLogMapper.update(null,new UpdateWrapper<DeviceLog>()
                         .set("start_time",deviceLog.getStartTime())
@@ -197,7 +198,7 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
                         Duration duration = Duration.between(groupedTimes.get(i)[0], groupedTimes.get(i)[1]);
                         double hours = duration.toMinutes() / 60.0; // 转换为小时
                         // 四舍五入保留一位小数
-                        hours = Math.round(hours * 10.0) / 10.0;
+                        hours = new BigDecimal(hours).setScale(2, RoundingMode.HALF_UP).doubleValue();
                         String createDate = groupedTimes.get(i)[0].format(formatterDate);
 
                         deviceLog.setStartTime(LocalDateTime.parse(formatStart, formatter));
@@ -219,7 +220,7 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
                         Duration duration = Duration.between(groupedTimes.get(i)[0], groupedTimes.get(i)[1]);
                         double hours = duration.toMinutes() / 60.0; // 转换为小时
                         // 四舍五入保留一位小数
-                        hours = Math.round(hours * 10.0) / 10.0;
+                        hours = new BigDecimal(hours).setScale(2, RoundingMode.HALF_UP).doubleValue();
                         String createDate = groupedTimes.get(i)[0].format(formatterDate);
 
                         DeviceLog deviceLogNew = new DeviceLog();