From efd6a955d5fa558f9bd04005cf83118279cc10a1 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期二, 22 七月 2025 09:37:07 +0800
Subject: [PATCH] art: 设备台账-设备选择接口

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java |   87 +++++++++++++++++++++++++++++++++++++++----
 1 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
index 1c0803f..c9b3516 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
@@ -18,6 +18,7 @@
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.TranslateDictTextUtils;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.eam.dto.EamEquipmentDto;
 import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.entity.EamEquipmentExtend;
 import org.jeecg.modules.eam.request.EamEquipmentQuery;
@@ -25,13 +26,16 @@
 import org.jeecg.modules.eam.service.IEamEquipmentService;
 import org.jeecg.modules.eam.vo.EamEquipmentTree;
 import org.jeecg.modules.eam.vo.EquipmentSearchResult;
-//import org.jeecg.modules.mdc.entity.MdcEquipment;
-//import org.jeecg.modules.mdc.service.IMdcEquipmentService;
+import org.jeecg.modules.system.entity.BaseFactory;
+import org.jeecg.modules.system.entity.EamBaseRepairDepart;
+import org.jeecg.modules.system.service.IBaseFactoryService;
+import org.jeecg.modules.system.service.IEamBaseRepairDepartService;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -41,6 +45,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -70,7 +75,10 @@
     private ObjectMapper objectMapper;
     @Autowired
     private TranslateDictTextUtils translateDictTextUtils;
-
+    @Autowired
+    private IBaseFactoryService baseFactoryService;
+    @Autowired
+    private IEamBaseRepairDepartService eamBaseRepairDepartService;
     /**
      * 鍒嗛〉鍒楄〃鏌ヨ
      *
@@ -211,18 +219,36 @@
     public ModelAndView exportXls(HttpServletRequest request,EamEquipmentQuery eamEquipment) {
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         List<EamEquipment> equipmentList=eamEquipmentService.exportList(eamEquipment);
+        List<EamEquipmentDto> eamEquipmentDtos=new ArrayList<>();
         String selections = request.getParameter("selections");
         if (oConvertUtils.isNotEmpty(selections)) {
             List<String> selectionList = Arrays.asList(selections.split(","));
             equipmentList = equipmentList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
         }
-
+        equipmentList.forEach(item -> {
+            EamEquipmentDto eamEquipmentDto = new EamEquipmentDto();
+            BeanUtils.copyProperties(item,eamEquipmentDto);
+            if (eamEquipmentDto.getFactoryOrgCode().length()==12){
+                eamEquipmentDto.setFactoryOrgCode(
+                        baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getZxfactoryOrgCode())
+                        +"/"+baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getGqfactoryOrgCode())+"/"+
+                                baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getFactoryOrgCode()));
+            }else {
+                eamEquipmentDto.setFactoryOrgCode(
+                        baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getZxfactoryOrgCode())
+                                +"/"+ baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getFactoryOrgCode()));
+            }
+            if (eamEquipmentDto.getEquipmentWeight()!=null){
+                eamEquipmentDto.setEquipmentWeightStr(eamEquipmentDto.getEquipmentWeight().toEngineeringString());
+            }
+            eamEquipmentDtos.add(eamEquipmentDto);
+        });
         // Step.3 AutoPoi 瀵煎嚭Excel
         ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
         mv.addObject(NormalExcelConstants.FILE_NAME, "璁惧鍙拌处"); //姝ゅ璁剧疆鐨刦ilename鏃犳晥 ,鍓嶇浼氶噸鏇存柊璁剧疆涓�涓�
-        mv.addObject(NormalExcelConstants.CLASS, EamEquipment.class);
+        mv.addObject(NormalExcelConstants.CLASS, EamEquipmentDto.class);
         mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("璁惧鍙拌处" + "鎶ヨ〃", "瀵煎嚭浜�:" + sysUser.getRealname(), "璁惧鍙拌处"));
-        mv.addObject(NormalExcelConstants.DATA_LIST, equipmentList);
+        mv.addObject(NormalExcelConstants.DATA_LIST, eamEquipmentDtos);
         return mv;
 
     }
@@ -268,12 +294,29 @@
                         sb.append(String.format("璁惧缂栫爜[%s]宸插瓨鍦紝鏃犳硶閲嶅瀵煎叆\n\r", eamEquipment.getEquipmentCode()));
                         continue;
                     }
+                    BaseFactory baseFactory=baseFactoryService.searchCenterByKeyWord(eamEquipment.getFactoryOrgCode());
+                    if(baseFactory==null){
+                        sb.append(String.format("EAM涓績淇℃伅[%s]涓嶅瓨鍦紝鏃犳硶瀵煎叆\n\r", eamEquipment.getFactoryOrgCode()));
+                        continue;
+                    }else {
+                        eamEquipment.setFactoryOrgCode(baseFactory.getOrgCode());
+                    }
+                    EamBaseRepairDepart eamBaseRepairDepart=eamBaseRepairDepartService.searchCenterByKeyWord(eamEquipment.getRepairDepartOrgCode());
+                    if(eamBaseRepairDepart==null){
+                        sb.append(String.format("缁翠慨鐝粍淇℃伅[%s]涓嶅瓨鍦紝鏃犳硶瀵煎叆\n\r", eamEquipment.getRepairDepartOrgCode()));
+                        continue;
+                    }else {
+                        eamEquipment.setRepairDepartOrgCode(eamBaseRepairDepart.getOrgCode());
+                    }
                     EamEquipment equipment = eamEquipmentService.saveEquipment(eamEquipment);
                     if (equipment == null) {
                         //淇濆瓨澶辫触锛岃烦杩囨湰娆″惊鐜�
                         sb.append(String.format("璁惧缂栫爜[%s]淇濆瓨澶辫触锛屾棤娉曞鍏n\r", eamEquipment.getEquipmentCode()));
                         continue;
                     }
+                    EamEquipmentExtend eamEquipmentExtend=new EamEquipmentExtend();
+                    BeanUtils.copyProperties(eamEquipmentExtend,equipment);
+                    eamEquipmentExtendService.save(eamEquipmentExtend);
                 }
                 log.info("娑堣�楁椂闂�" + (System.currentTimeMillis() - start) + "姣");
                 //update-end-author:taoyan date:20190528 for:鎵归噺鎻掑叆鏁版嵁
@@ -316,6 +359,20 @@
         return result;
     }
 
+    @ApiOperation(value = "璁惧琛�-閫氳繃EAM涓績ids鑾峰彇璁惧鏍�", notes = "璁惧琛�-閫氳繃EAM涓績ids鑾峰彇璁惧鏍�")
+    @GetMapping(value = "/loadTreeListByEamCenterIds")
+    public Result<List<EamEquipmentTree>> loadTreeListByEamCenterIds(@RequestParam(name = "ids", required = true) String ids) {
+        Result<List<EamEquipmentTree>> result = new Result<>();
+        try {
+            List<EamEquipmentTree> mdcEquipmentTreeList = eamEquipmentService.loadTreeListByEamCenterIds(ids);
+            result.setSuccess(true);
+            result.setResult(mdcEquipmentTreeList);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+        return result;
+    }
+
     /**
      * 妫�绱㈣澶�
      * @param keyword 鏌ヨ鍏抽敭璇� 璁惧缂栧彿锛岃澶囧悕绉版ā绯婂尮閰�
@@ -327,9 +384,21 @@
     @GetMapping(value = "/asyncLoadEquipment")
     public Result<?> asyncLoadEquipment(@RequestParam(name="keyword",required = false) String keyword,
                                         @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
-                                        @RequestParam(name="id",required = false) String id) {
-        List<EquipmentSearchResult> resultList = eamEquipmentService.asyncLoadEquipment(keyword, pageSize, id);
-        return Result.ok(resultList);
+                                        @RequestParam(name="id",required = false) String id,
+                                        @RequestParam(name="factoryOrgCode",required = false) String factoryOrgCode) {
+        List<EquipmentSearchResult> resultList = eamEquipmentService.asyncLoadEquipment(keyword, pageSize, id, factoryOrgCode);
+        List<JSONObject> items = new ArrayList<>();
+        try {
+            for(EquipmentSearchResult vo : resultList) {
+                String json = objectMapper.writeValueAsString(vo);
+                JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
+                translateDictTextUtils.translateField("factoryOrgCode", vo.getFactoryOrgCode(), item, "eam_base_factory,factory_name,org_code");
+                items.add(item);
+            }
+            return Result.OK(items);
+        }catch (Exception e) {
+            return Result.error("鏁版嵁杞瘧澶辫触锛�");
+        }
     }
 
 }

--
Gitblit v1.9.3