diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java index a6c14ad5..a0babae5 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java @@ -433,4 +433,31 @@ public class ExcelUtil { return IdUtil.fastSimpleUUID() + "_" + filename + ".xlsx"; } + + /** + * 动态表头导出 + * + * @param data 数据列表 + * @param head 表头列表 + * @param sheetName sheet名 + * @param response 响应 + */ + public static void exportExcelWithDynamicHead(List> data, List> head, String sheetName, HttpServletResponse response) { + try { + resetResponse(sheetName, response); + ServletOutputStream os = response.getOutputStream(); + EasyExcel.write(os) + .head(head) + .autoCloseStream(false) + // 自动适配 + .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) + // 大数值自动转换 防止失真 + .registerConverter(new ExcelBigNumberConvert()) + .sheet(sheetName) + .doWrite(data); + } catch (IOException e) { + throw new RuntimeException("导出Excel异常"); + } + } + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdPlanInfoController.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdPlanInfoController.java index 178bd975..bc394721 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdPlanInfoController.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/controller/ProdPlanInfoController.java @@ -221,4 +221,12 @@ public class ProdPlanInfoController extends BaseController { public boolean triggerEvent(@PathVariable Long planId, @RequestParam PlanEventEnum event) { return prodPlanInfoService.sendEvent(planId, event); } + + +// @SaCheckPermission("mes:planInfo:export") +// @Log(title = "生产计划监控", businessType = BusinessType.EXPORT) + @PostMapping("/exportMonitor") + public void exportMonitor(ProdPlanInfoBo bo, HttpServletResponse response) { + prodPlanInfoService.exportMonitor(bo, response); + } } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdPlanInfoService.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdPlanInfoService.java index 2dcaa966..812da7d8 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdPlanInfoService.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/IProdPlanInfoService.java @@ -1,11 +1,12 @@ package org.dromara.mes.service; +import jakarta.servlet.http.HttpServletResponse; +import org.dromara.common.mybatis.core.page.PageQuery; +import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.mes.domain.bo.ProdPlanInfoBo; import org.dromara.mes.domain.vo.MesProductPlanEditVo; import org.dromara.mes.domain.vo.PlanMonitorVo; import org.dromara.mes.domain.vo.ProdPlanInfoVo; -import org.dromara.mes.domain.bo.ProdPlanInfoBo; -import org.dromara.common.mybatis.core.page.TableDataInfo; -import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.mes.enums.PlanEventEnum; import java.util.Collection; @@ -112,4 +113,14 @@ public interface IProdPlanInfoService { public boolean sendEvent(Long planId, PlanEventEnum event); + + + /** + * 导出生产计划监控列表 + * @param bo 查询条件 + * @param response response + */ + void exportMonitor(ProdPlanInfoBo bo, HttpServletResponse response); + + } diff --git a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java index 14788eca..e203851f 100644 --- a/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java +++ b/ruoyi-modules/hwmom-mes/src/main/java/org/dromara/mes/service/impl/ProdPlanInfoServiceImpl.java @@ -3,12 +3,14 @@ package org.dromara.mes.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.wrapper.MPJLambdaWrapper; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.dromara.common.constant.DatabaseConstants; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.uuid.Seq; +import org.dromara.common.excel.utils.ExcelUtil; import org.dromara.common.mapper.DynamicBaseSqlMapper; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -17,29 +19,27 @@ import org.dromara.mes.domain.bo.ProdPlanInfoBo; import org.dromara.mes.domain.vo.MesProductPlanEditVo; import org.dromara.mes.domain.vo.PlanMonitorVo; import org.dromara.mes.domain.vo.ProdPlanInfoVo; +import org.dromara.mes.domain.vo.ShiftGroupVo; import org.dromara.mes.enums.PlanEventEnum; import org.dromara.mes.enums.PlanStatusEnum; import org.dromara.mes.mapper.ProdPlanInfoMapper; import org.dromara.mes.service.IProdPlanInfoService; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.ObjectUtils; - -import java.util.Collection; -import java.util.List; -import java.util.Map; - import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; import org.springframework.statemachine.StateMachine; import org.springframework.statemachine.config.StateMachineFactory; -import org.springframework.stereotype.Service; import org.springframework.statemachine.support.DefaultStateMachineContext; -import org.springframework.statemachine.StateMachine; -import org.springframework.statemachine.service.StateMachineService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; +import org.dromara.common.core.service.DictService; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; /** * 生产工单信息Service业务层处理 @@ -57,6 +57,8 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { private final DynamicBaseSqlMapper dynamicBaseSqlMapper; + private final DictService dictService;//字典服务服务 + @Autowired private StateMachineFactory stateMachineFactory; @@ -367,8 +369,6 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { - - private PlanEventEnum determineEvent(PlanStatusEnum currentStatus, PlanStatusEnum targetStatus) { // 根据当前状态和目标状态确定需要触发的事件 if (currentStatus == PlanStatusEnum.CREATED && targetStatus == PlanStatusEnum.PLANNED) { @@ -422,4 +422,69 @@ public class ProdPlanInfoServiceImpl implements IProdPlanInfoService { return sm; } + + /** + * 导出生产计划监控列表 + * @param bo 查询条件 + * @param response response + */ + @Override + public void exportMonitor(ProdPlanInfoBo bo, HttpServletResponse response) { + List list = queryMoritorList(bo); + // 获取所有班次 + List shiftNames = list.stream() + .flatMap(machine -> machine.getShifts().stream()) + .map(ShiftGroupVo::getShiftName) + .distinct() + .sorted() + .collect(Collectors.toList()); + + // 构建动态表头 + List> head = new ArrayList<>(); + head.add(Arrays.asList("机台")); + head.add(Arrays.asList("物料名称")); + head.add(Arrays.asList("计划产量")); + head.add(Arrays.asList("实际产量")); + head.add(Arrays.asList("差异")); + head.add(Arrays.asList("计划开始时间")); + head.add(Arrays.asList("计划结束时间")); + for (String shiftName : shiftNames) { + head.add(Arrays.asList(shiftName)); + } + head.add(Arrays.asList("状态")); + + // 构建数据 + List> data = new ArrayList<>(); + for (PlanMonitorVo machine : list) { + for (ShiftGroupVo shift : machine.getShifts()) { + for (ProdPlanInfoVo plan : shift.getPlans()) { + List row = new ArrayList<>(); + row.add(machine.getMachineName()); + row.add(plan.getMaterialName()); + row.add(plan.getPlanAmount()); + row.add(plan.getCompleteAmount()); + BigDecimal difference = (plan.getPlanAmount() == null ? BigDecimal.ZERO : plan.getPlanAmount()) + .subtract(plan.getCompleteAmount() == null ? BigDecimal.ZERO : plan.getCompleteAmount()); + row.add(difference); + row.add(plan.getPlanBeginTime()); + row.add(plan.getPlanEndTime()); + + for (String shiftName : shiftNames) { + if (shiftName.equals(shift.getShiftName())) { + row.add(plan.getPlanAmount()); + } else { + row.add(""); + } + } + // 工单计划状态(0未下发 1已下发 2已开始 3已完成 4已撤回) 使用字典mes_plan_status + String statusLabel = dictService.getDictLabel("mes_plan_status", plan.getPlanStatus(), ","); + row.add(statusLabel); + data.add(row); + } + } + } + ExcelUtil.exportExcelWithDynamicHead(data, head, "生产计划监控", response); + } + + }