From 848e5624f3a814763e81db5d79d8f0761c5bb4f1 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期四, 01 二月 2024 10:25:40 +0800
Subject: [PATCH] 设备管理按照车间筛选和导出

---
 lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java |   62 ++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java
index 31fb7bc..20bcf7a 100644
--- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java
+++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java
@@ -1,5 +1,6 @@
 package org.jeecg.modules.mdc.controller;
 
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
@@ -9,6 +10,7 @@
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.mdc.dto.MdcEquipmentDto;
@@ -21,6 +23,9 @@
 import org.jeecg.modules.mdc.vo.MdcEquipmentVo;
 import org.jeecg.modules.system.model.DepartIdModel;
 import org.jeecg.modules.system.model.ProductionIdModel;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.ModelAndView;
 
@@ -230,6 +235,7 @@
         Result<MdcEquipment> result = new Result<>();
         String selectedDeparts = mdcEquipment.getSelectedDeparts();
         String selectedProduction = mdcEquipment.getSelectedProduction();
+        mdcEquipment.setEquipmentStatus(CommonConstant.STATUS_NORMAL);
         try {
             mdcEquipmentService.saveMdcEquipment(mdcEquipment, selectedDeparts, selectedProduction);
             result.success("娣诲姞鎴愬姛锛�");
@@ -420,8 +426,29 @@
      * @param mdcEquipment
      */
     @RequestMapping(value = "/exportXls")
-    public ModelAndView exportXls(HttpServletRequest request, MdcEquipment mdcEquipment) {
-        return super.exportXls(request, mdcEquipment, MdcEquipment.class, "璁惧琛�");
+    public ModelAndView exportXls(HttpServletRequest request, MdcEquipmentVo mdcEquipment) {
+        // Step.1 缁勮鏌ヨ鏉′欢
+        //QueryWrapper<MdcEquipment> queryWrapper = QueryGenerator.initQueryWrapper(mdcEquipment, request.getParameterMap());
+        //Step.2 AutoPoi 瀵煎嚭Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<MdcEquipment> pageList = mdcEquipmentService.exportXlsList(mdcEquipment);
+        List<String> equipmentIds = pageList.stream().map(MdcEquipment::getId).collect(Collectors.toList());
+        if (!equipmentIds.isEmpty()) {
+            Map<String, String> equDepNames = mdcEquipmentService.getDepNamesByEquipmentIds(equipmentIds);
+            Map<String, String> equProNames = mdcEquipmentService.getProNamesByEquipmentIds(equipmentIds);
+            pageList.forEach(item -> {
+                item.setOrgCodeTxt(equDepNames.get(item.getId()));
+                item.setProductionName(equProNames.get(item.getId()));
+            });
+        }
+        mv.addObject(NormalExcelConstants.FILE_NAME, "璁惧鍒楄〃");
+        mv.addObject(NormalExcelConstants.CLASS, MdcEquipment.class);
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        ExportParams exportParams = new ExportParams("璁惧鍒楄〃鏁版嵁", "瀵煎嚭浜�:" + user.getRealname(), "瀵煎嚭淇℃伅");
+//        exportParams.setImageBasePath(upLoadPath);
+        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
     }
 
     /**
@@ -467,4 +494,35 @@
         MdcEquipment mdcEquipment = mdcEquipmentService.getEquipmentByDepPid(pid, userId);
         return Result.OK(mdcEquipment);
     }
+
+    /**
+     * 鎵嬪姩涓婃姤璁惧寮傚父鍙婅鏄�
+     * @return
+     */
+    @AutoLog(value = "璁惧琛�-鎵嬪姩涓婃姤璁惧寮傚父鍙婅鏄�")
+    @ApiOperation(value = "璁惧琛�-鎵嬪姩涓婃姤璁惧寮傚父鍙婅鏄�", notes = "璁惧琛�-鎵嬪姩涓婃姤璁惧寮傚父鍙婅鏄�")
+    @GetMapping("/updateEquipmentStatus")
+    public Result<?> updateEquipmentStatus(@RequestParam(name = "id", required = true) String id) {
+        Result result = new Result<>();
+        try {
+            MdcEquipment mdcEquipment1 = mdcEquipmentService.getById(id);
+            if (mdcEquipment1 == null) {
+                result.error500("鏈壘鍒板搴斿疄浣�");
+            } else {
+                LambdaUpdateWrapper<MdcEquipment> updateWrapper = new LambdaUpdateWrapper<MdcEquipment>();
+                updateWrapper.eq(MdcEquipment::getId, id);
+                if (CommonConstant.STATUS_NORMAL.equals(mdcEquipment1.getEquipmentStatus())) {
+                    updateWrapper.set(MdcEquipment::getEquipmentStatus, CommonConstant.STATUS_DISABLE);
+                } else {
+                    updateWrapper.set(MdcEquipment::getEquipmentStatus, CommonConstant.STATUS_NORMAL);
+                }
+                mdcEquipmentService.update(updateWrapper);
+                result.success("鍙嶉鎴愬姛!");
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("鎿嶄綔澶辫触");
+        }
+        return Result.OK("鍙嶉鎴愬姛锛�");
+    }
 }

--
Gitblit v1.9.3