From 724f8ec3bbcf9da50f304f57d8bc9a60ad75ad0a Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期三, 27 八月 2025 18:29:32 +0800
Subject: [PATCH] 修改计算百分比位置

---
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
index 20b1c9b..00ce4ee 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
@@ -15,6 +15,7 @@
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
 import org.jeecg.modules.eam.constant.*;
+import org.jeecg.modules.eam.dto.EchartsDto;
 import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.entity.EamEquipmentExtend;
 import org.jeecg.modules.eam.mapper.EamEquipmentMapper;
@@ -37,6 +38,9 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -186,7 +190,7 @@
                 queryWrapper.like("e.asset_status", eamEquipment.getAssetStatus());
             }
             if (StringUtils.isNotBlank(eamEquipment.getTechnologyStatus())) {
-                queryWrapper.like("e.technology_status", eamEquipment.getTechnologyStatus());
+                queryWrapper.like("ext.technology_status", eamEquipment.getTechnologyStatus());
             }
             if (StringUtils.isNotBlank(eamEquipment.getOperationSystem())) {
                 queryWrapper.like("e.operation_system", eamEquipment.getOperationSystem());
@@ -367,7 +371,7 @@
                 queryWrapper.like("e.asset_status", eamEquipment.getAssetStatus());
             }
             if (StringUtils.isNotBlank(eamEquipment.getTechnologyStatus())) {
-                queryWrapper.like("e.technology_status", eamEquipment.getTechnologyStatus());
+                queryWrapper.like("ext.technology_status", eamEquipment.getTechnologyStatus());
             }
             if (StringUtils.isNotBlank(eamEquipment.getOperationSystem())) {
                 queryWrapper.like("e.operation_system", eamEquipment.getOperationSystem());
@@ -428,6 +432,57 @@
     }
 
     /**
+     * 璁惧绠$悊棣栭〉-鎶�鏈姸鎬�
+     * @return
+     */
+    @Override
+    public List<EchartsDto> echartsList(){
+        List<EchartsDto> echartsDtoList = new ArrayList<>();
+        QueryWrapper<EamEquipment> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("e.del_flag", CommonConstant.DEL_FLAG_0);
+        //鐢ㄦ埛鏁版嵁鏉冮檺
+        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        if (sysUser == null) {
+            return echartsDtoList;
+        }
+        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
+            //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧
+            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
+            queryWrapper.in("e.equipment_code", equipArr);
+        } else {
+            //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶�
+            List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
+                    list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
+            if(!CollectionUtils.isEmpty(baseFactoryUserList)){
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
+                queryWrapper.in("e.factory_org_code", factoryCode);
+            }else {
+                return echartsDtoList;
+            }
+        }
+        List<String> ids=this.baseMapper.queryList(queryWrapper).stream().map(EamEquipment::getId).collect(Collectors.toList());
+        echartsDtoList= this.baseMapper.echartsList(ids);
+        // 鐩存帴浣跨敤for寰幆澶勭悊鏁版嵁
+        for (EchartsDto dto : echartsDtoList) {
+            if (dto.getTotal() != null && !"0".equals(dto.getTotal())) {
+                try {
+                    int value = Integer.parseInt(dto.getValue());
+                    int total = Integer.parseInt(dto.getTotal());
+                    double percentage = (value * 100.0) / total;
+                    DecimalFormat df = new DecimalFormat("0.00");
+                    dto.setPercentage(df.format(percentage) + "%");
+                } catch (NumberFormatException e) {
+                    dto.setPercentage("0.00%");
+                }
+            } else {
+                dto.setPercentage("0.00%");
+            }
+        }
+        return echartsDtoList;
+    }
+
+    /**
      * 鑾峰彇鎵�鏈夌殑浜х嚎id锛堝寘鍚墍鏈変笂绾э級
      */
     private void getAllProductionIds(List<MdcProduction> productionList, String productionId, List<String> allProductionIds) {

--
Gitblit v1.9.3