From 3519b2bf0f97d5017f97447b6eafc2b4bd9487c4 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期六, 27 一月 2024 14:01:55 +0800 Subject: [PATCH] 设备管理添加导出按钮 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcEquipmentController.java | 62 +++++++++++++++++++++++++++++-- 1 files changed, 58 insertions(+), 4 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 b3bcf11..c76195d 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,6 +1,7 @@ package org.jeecg.modules.mdc.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +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; @@ -10,9 +11,11 @@ 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.query.QueryGenerator; import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.mdc.dto.MdcEquipmentDto; import org.jeecg.modules.mdc.entity.MdcEquipment; import org.jeecg.modules.mdc.entity.MdcEquipmentMonitor; @@ -23,6 +26,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; @@ -67,13 +73,13 @@ @AutoLog(value = "璁惧琛�-鍒嗛〉鍒楄〃鏌ヨ") @ApiOperation(value = "璁惧琛�-鍒嗛〉鍒楄〃鏌ヨ", notes = "璁惧琛�-鍒嗛〉鍒楄〃鏌ヨ") @GetMapping(value = "/list") - public Result<IPage<MdcEquipment>> queryPageList(MdcEquipment mdcEquipment, + public Result<IPage<MdcEquipment>> queryPageList(MdcEquipmentVo mdcEquipment, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { - QueryWrapper<MdcEquipment> queryWrapper = QueryGenerator.initQueryWrapper(mdcEquipment, req.getParameterMap()); + //QueryWrapper<MdcEquipment> queryWrapper = QueryGenerator.initQueryWrapper(mdcEquipment, req.getParameterMap()); Page<MdcEquipment> page = new Page<MdcEquipment>(pageNo, pageSize); - IPage<MdcEquipment> pageList = mdcEquipmentService.page(page, queryWrapper); + IPage<MdcEquipment> pageList = mdcEquipmentService.pageList(page, mdcEquipment, req); //鎵归噺鏌ヨ璁惧鐨勬墍灞為儴闂ㄥ拰浜х嚎 //step.1 鍏堟嬁鍒板叏閮ㄧ殑 equipmentIds @@ -232,6 +238,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("娣诲姞鎴愬姛锛�"); @@ -423,7 +430,23 @@ */ @RequestMapping(value = "/exportXls") public ModelAndView exportXls(HttpServletRequest request, MdcEquipment mdcEquipment) { - return super.exportXls(request, mdcEquipment, MdcEquipment.class, "璁惧琛�"); + // Step.1 缁勮鏌ヨ鏉′欢 + QueryWrapper<MdcEquipment> queryWrapper = QueryGenerator.initQueryWrapper(mdcEquipment, request.getParameterMap()); + //Step.2 AutoPoi 瀵煎嚭Excel + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + String selections = request.getParameter("selections"); + if (!oConvertUtils.isEmpty(selections)) { + queryWrapper.in("id", selections.split(",")); + } + List<MdcEquipment> pageList = mdcEquipmentService.list(queryWrapper); + 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; } /** @@ -469,4 +492,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