package cn.iocoder.yudao.module.mes.controller.admin.dashboard;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO;
import cn.iocoder.yudao.module.common.dal.mysql.mold.MoldMapper;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
import cn.iocoder.yudao.module.mes.controller.admin.dashboard.vo.*;
import cn.iocoder.yudao.module.mes.controller.admin.dashboard.vo.dashboard.EventStatisticsVO;
import cn.iocoder.yudao.module.mes.controller.admin.dashboard.vo.dashboard.TaskVO;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanRespVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.dvrepair.DvRepairDO;
import cn.iocoder.yudao.module.common.dal.dataobject.moldrepair.MoldRepairDO;
import cn.iocoder.yudao.module.common.dal.dataobject.moldticketmanagement.MoldTicketManagementDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.ticketmanagement.TicketManagementDO;
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.dvrepair.DvRepairMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.plan.PlanMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskMapper;
import cn.iocoder.yudao.module.mes.service.deviceledger.DeviceLedgerService;
import cn.iocoder.yudao.module.mes.service.devicetype.DeviceTypeService;
import cn.iocoder.yudao.module.mes.service.dvrepair.DvRepairService;
import cn.iocoder.yudao.module.erp.service.mold.MoldService;
import cn.iocoder.yudao.module.mes.service.moldrepair.MoldRepairService;
import cn.iocoder.yudao.module.mes.service.moldticketmanagement.MoldTicketManagementService;
import cn.iocoder.yudao.module.mes.service.organization.OrganizationService;
import cn.iocoder.yudao.module.mes.service.plan.PlanService;
import cn.iocoder.yudao.module.mes.service.ticketmanagement.TicketManagementService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;

@Tag(name = "管理后台 - 首页")
@RestController
@RequestMapping("/mes/dashboard")
@Validated
public class DashboardController {


    @Resource
    private PlanService planService;

    @Resource
    private ErpProductService productService;

    @Resource
    private OrganizationService organizationService;

    @Resource
    private DvRepairService dvRepairService;

    @Resource
    private DvRepairMapper dvRepairMapper;

    @Resource
    private MoldRepairService moldRepairService;

    @Resource
    private DeviceLedgerService deviceLedgerService;

    @Resource
    private MoldService moldService;

    @Resource
    private TicketManagementService ticketManagementService;

    @Resource
    private MoldTicketManagementService moldTicketManagementService;

    @Resource
    private PlanMapper planMapper;

    @Resource
    private TaskMapper taskMapper;

    @Resource
    private DeviceLedgerMapper deviceLedgerMapper;

    @Resource
    private MoldMapper moldMapper;

    @Resource
    private MoldBrandService moldBrandService;



    @Resource
    private DeviceTypeService deviceTypeService;

    @Resource
    private DeviceMapper deviceMapper;

    @GetMapping("/getProduction")
    @Operation(summary = "获得整体生产概况")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<TaskRespVO> getProduction(@Valid TaskReqVO taskReqVO) {
        TaskRespVO taskRespVO  = new TaskRespVO();
        List<TaskRespVO.Item> taskItems = new ArrayList<>();
        List<TaskRespVO.Item> planItems = new ArrayList<>();
        // 生产任务总数
        TaskRespVO.Item item = new TaskRespVO.Item();
        item.setKey("1");
        item.setLabel("生产任务总数");
        item.setValue(taskMapper.selectCount(new LambdaQueryWrapperX<TaskDO>()
                .betweenIfPresent(TaskDO::getCreateTime, taskReqVO.getStartTime()))); // 创建时间
        taskItems.add(item);
        // 未开工任务数
        item = new TaskRespVO.Item();
        item.setKey("2");
        item.setLabel("未开工任务数");
        Collection<Long> count1 = new ArrayList<>();
        count1.add(1L);
        count1.add(2L);
        count1.add(3L);
        item.setValue(taskMapper.selectCount(new LambdaQueryWrapperX<TaskDO>()
                .in(TaskDO::getStatus, count1)
                .betweenIfPresent(TaskDO::getOrderDate, taskReqVO.getStartTime()))); // 下达时间
        taskItems.add(item);
        // 生产中任务数
        item = new TaskRespVO.Item();
        item.setKey("3");
        item.setLabel("生产中任务数");
        Collection<Long> count2 = new ArrayList<>();
        count2.add(4L);
        item.setValue(taskMapper.selectCount(new LambdaQueryWrapperX<TaskDO>()
                .in(TaskDO::getStatus, count2)
                .betweenIfPresent(TaskDO::getOrderDate, taskReqVO.getStartTime())));
        taskItems.add(item);
        // 完工任务数
        item = new TaskRespVO.Item();
        item.setKey("4");
        item.setLabel("完工任务数");
        Collection<Long> count3 = new ArrayList<>();
        count3.add(5L);
        count3.add(6L);
        item.setValue(taskMapper.selectCount(new LambdaQueryWrapperX<TaskDO>()
                .in(TaskDO::getStatus, count3)
                .betweenIfPresent(TaskDO::getOrderDate, taskReqVO.getStartTime())));
        taskItems.add(item);
        // 生产计划总数
        item = new TaskRespVO.Item();
        item.setKey("5");
        item.setLabel("生产计划单数");
        item.setValue(planMapper.selectCount());
        planItems.add(item);
        // 完成生产数量
        item = new TaskRespVO.Item();
        item.setKey("6");
        item.setLabel("产品计划总数");
        List<PlanDO> planDOList = planMapper.selectList();
        long count = 0L;
        for (PlanDO planDO : planDOList) {
            if (planDO.getPlanNumber() != null) {
                count = count + planDO.getPlanNumber();
            }
        }
        item.setValue(count);
        planItems.add(item);
        // 报工数量
        item = new TaskRespVO.Item();
        item.setKey("7");
        item.setLabel("报工总数");
        long baogong = 0L;
        for (PlanDO planDO : planDOList) {
            if (planDO.getWangongNumber() != null) {
                baogong = baogong + planDO.getWangongNumber();
            }
        }
        item.setValue(baogong);
        planItems.add(item);
        // 未完成生产数量
        item = new TaskRespVO.Item();
        item.setKey("81");
        item.setLabel("产品合格数");
        long pass = 0L;
        for (PlanDO planDO : planDOList) {
            if (planDO.getPassNumber() != null) {
                pass = pass + planDO.getPassNumber();
            }
        }
        item.setValue(pass);
        planItems.add(item);
        // 完工率
        item = new TaskRespVO.Item();
        item.setKey("8");
        item.setLabel("产品不合格数");
        long noPass = 0L;
        for (PlanDO planDO : planDOList) {
            if (planDO.getNoPassNumber() != null) {
                noPass = noPass + planDO.getNoPassNumber();
            }
        }
        item.setValue(noPass);
        planItems.add(item);
        // 合格率
        item = new TaskRespVO.Item();
        item.setKey("9");
        item.setLabel("合格率");
        long passRate = 0;
        if (baogong != 0) {
            passRate = (long) (((double) pass / baogong) * 100);

        }
        item.setValue(passRate);
        planItems.add(item);

        taskRespVO.setTaskItems(taskItems);
        taskRespVO.setPlanItems(planItems);
        return success(taskRespVO);
    }

    @GetMapping("/getPlan")
    @Operation(summary = "获得实时生产进度")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<List<PlanRespVO>> getPlan() {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(1);
        statusList.add(2);
        statusList.add(3);
        statusList.add(4);
//        statusList.add(5);
        statusList.add(6);
        List<PlanDO> planDOList = planService.getPlanByStatus(statusList);
        Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
                convertSet(planDOList, PlanDO::getProductId));
        Map<Long, OrganizationDO> organizationMap = organizationService.getOrganizationVOMap(convertSet(planDOList, PlanDO::getFeedingPipeline));
        return success(BeanUtils.toBean(planDOList, PlanRespVO.class, planRespVO ->{
                    MapUtils.findAndThen(productMap, planRespVO.getProductId(), product -> planRespVO.setProductName(product.getName()));
            MapUtils.findAndThen(organizationMap, planRespVO.getFeedingPipeline(), organization -> planRespVO.setFeedingPipelineName(organization.getName()));
                }));
    }



    @GetMapping("/getDevice")
    @Operation(summary = "获得设备任务")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<List<DeviceRespVO>> getDevice() {
        List<DeviceRespVO> deviceRespVOList = new ArrayList<>();
        DeviceRespVO  deviceRespVO = new DeviceRespVO();
        // 设备维修
        deviceRespVO.setKey("1");
        deviceRespVO.setLabel("维修");
        deviceRespVO.setValue(dvRepairService.getRepairListCountByRepairStatus());
        deviceRespVO.setLevel("mini-danger");
        deviceRespVOList.add(deviceRespVO);
        // 设备点检
        deviceRespVO = new DeviceRespVO();
        deviceRespVO.setKey("2");
        deviceRespVO.setLabel("点检");
        deviceRespVO.setValue(ticketManagementService.getDianjianListCountByJobStatus());
        deviceRespVO.setLevel("mini-normal");
        deviceRespVOList.add(deviceRespVO);
        // 设备保养
        deviceRespVO = new DeviceRespVO();
        deviceRespVO.setKey("3");
        deviceRespVO.setLabel("保养");
        deviceRespVO.setValue(ticketManagementService.getBaoyangListCountByJobStatus());
        deviceRespVO.setLevel("mini-total");
        deviceRespVOList.add(deviceRespVO);
        return success(deviceRespVOList);
    }

    @GetMapping("/getMold")
    @Operation(summary = "获得模具任务")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<List<MoldRespVO>> getMold() {
        List<MoldRespVO> moldRespVOList = new ArrayList<>();
        MoldRespVO  moldRespVO = new MoldRespVO();
        // 设备维修
        moldRespVO.setKey("1");
        moldRespVO.setLabel("维修");
        moldRespVO.setValue(moldRepairService.getRepairListCountByRepairStatus());
        moldRespVO.setLevel("mini-danger");
        moldRespVOList.add(moldRespVO);
        // 设备点检
        moldRespVO = new MoldRespVO();
        moldRespVO.setKey("2");
        moldRespVO.setLabel("点检");
        moldRespVO.setValue(moldTicketManagementService.getDianjianListCountByJobStatus());
        moldRespVO.setLevel("mini-normal");
        moldRespVOList.add(moldRespVO);
        // 设备保养
        moldRespVO = new MoldRespVO();
        moldRespVO.setKey("3");
        moldRespVO.setLabel("保养");
        moldRespVO.setValue(moldTicketManagementService.getBaoyangListCountByJobStatus());
        moldRespVO.setLevel("mini-total");
        moldRespVOList.add(moldRespVO);
        return success(moldRespVOList);
    }

    @GetMapping("/getTodoList")
    @Operation(summary = "获得待办任务")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<List<TodoRespVO>> getTodoList() {
        List<TodoRespVO> todoRespVOList = new ArrayList<>();
        // 设备维修
        List<DvRepairDO> dvRepairDOList = dvRepairService.getDvRepairDOListByStatus();
        for (DvRepairDO dvRepairDO : dvRepairDOList) {
            TodoRespVO  todoRespVO = new TodoRespVO();
            todoRespVO.setCode(dvRepairDO.getRepairCode());
            todoRespVO.setName(dvRepairDO.getRepairName());
            todoRespVO.setType("设备维修");
            todoRespVO.setDeviceName(deviceLedgerService.getDeviceLedger(dvRepairDO.getDeviceId()).getDeviceName());
            todoRespVO.setCreateTime(dvRepairDO.getCreateTime());
            todoRespVOList.add(todoRespVO);
        }
        // 设备保养 点检

        List<TicketManagementDO> ticketManagementDOList = ticketManagementService.getListByJobStatus();
        for (TicketManagementDO  ticketManagementDO : ticketManagementDOList) {
            TodoRespVO  todoRespVO = new TodoRespVO();
            todoRespVO.setCode(ticketManagementDO.getPlanNo());
            todoRespVO.setName(ticketManagementDO.getConfigName());
            if (ticketManagementDO.getPlanType() == 2) {
                todoRespVO.setType("设备保养");
            } else {
                todoRespVO.setType("设备点检");
            }
            todoRespVO.setDeviceName(ticketManagementDO.getDeviceName());
            todoRespVO.setCreateTime(ticketManagementDO.getCreateTime());
            todoRespVOList.add(todoRespVO);
        }
        // 模具维修
        List<MoldRepairDO> moldRepairDOList = moldRepairService.getMoldRepairDOListByStatus();
        for (MoldRepairDO  moldRepairDO : moldRepairDOList) {
            TodoRespVO  todoRespVO = new TodoRespVO();
            todoRespVO.setCode(moldRepairDO.getRepairCode());
            todoRespVO.setName(moldRepairDO.getRepairName());
            todoRespVO.setType("模具维修");
            todoRespVO.setDeviceName( moldRepairDO.getMoldId() != null && moldService.getMold(moldRepairDO.getMoldId()) != null
                    ? moldService.getMold(moldRepairDO.getMoldId()).getName()
                    : "未知设备");
            todoRespVO.setCreateTime(moldRepairDO.getCreateTime());
            todoRespVOList.add(todoRespVO);

        }
        // 模具保养 点检
        List<MoldTicketManagementDO> moldTicketManagementDOList = moldTicketManagementService.getListByJobStatus();
        for (MoldTicketManagementDO  moldTicketManagementDO : moldTicketManagementDOList) {
            TodoRespVO  todoRespVO = new TodoRespVO();
            todoRespVO.setCode(moldTicketManagementDO.getPlanNo());
            todoRespVO.setName(moldTicketManagementDO.getConfigName());
            if (moldTicketManagementDO.getPlanType() == 2) {
                todoRespVO.setType("模具保养");
            } else {
                todoRespVO.setType("模具点检");
            }
            todoRespVO.setDeviceName(moldTicketManagementDO.getMoldName());
            todoRespVO.setCreateTime(moldTicketManagementDO.getCreateTime());
            todoRespVOList.add(todoRespVO);
        }
       return success(todoRespVOList);
    }

    @GetMapping("/getDeviceRepairLineOptions")
    @Operation(summary = "获得设备维修数量统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<DeviceRepairLineOptionsVO> getDeviceRepairLineOptions() {
        DeviceRepairLineOptionsVO deviceRepairLineOptionsVO =  new DeviceRepairLineOptionsVO();
        // 计算6个月前的日期
        LocalDateTime sixMonthsAgo = LocalDateTime.now()
                .withDayOfMonth(1)  // 取当月第一天
                .withHour(0)
                .withMinute(0)
                .withSecond(0)
                .minusMonths(5);  // 注意：这里是5，因为要包含当前月

        List<Map<String, Object>> result = dvRepairMapper.selectMaps(
                new QueryWrapper<DvRepairDO>()
                        .select(
                                "DATE_FORMAT(require_date, '%Y-%m') as month",
                                "COUNT(*) as count"
                        )
                        .ge("require_date", sixMonthsAgo)
                        .groupBy("DATE_FORMAT(require_date, '%Y-%m')")
                        .orderByDesc("month")
        );
        List<String> months = new ArrayList<>();
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");

        // 往前推5个月（包含当前月共6个月）
        for (int i = 5; i >= 0; i--) {
            LocalDate date = currentDate.minusMonths(i);
            String month = date.format(formatter);
            months.add(month);
        }
        deviceRepairLineOptionsVO.setXAxis(months);
        // 匹配并获取数据
        List<Integer> matchedCounts = new ArrayList<>();

        for (String month : months) {
            Integer count = 0;  // 默认值
            // 在result中查找匹配的月份
            for (Map<String, Object> map : result) {
                String resultMonth = (String) map.get("month");
                if (month.equals(resultMonth)) {
                    Object countObj = map.get("count");
                    if (countObj instanceof Number) {
                        count = ((Number) countObj).intValue();
                    }
                    break;  // 找到后跳出内层循环
                }
            }
            matchedCounts.add(count);
        }
        deviceRepairLineOptionsVO.setSeries(matchedCounts);
        return success(deviceRepairLineOptionsVO);
    }

    @GetMapping("/getDeviceTypePieOptions")
    @Operation(summary = "获得设备分类统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<List<DeviceTypePieOptionsVO>> getDeviceTypePieOptions() {
        List<DeviceTypePieOptionsVO> deviceTypePieOptionsVOList = new ArrayList<>();
        QueryWrapper<DeviceLedgerDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("device_type as deviceType", "COUNT(*) as count")
                .groupBy("device_type")
                .orderByDesc("count")
                .last("LIMIT 5");
        List<Map<String, Object>> result = deviceLedgerMapper.selectMaps(queryWrapper);
        for (Map<String, Object> map : result) {
            DeviceTypePieOptionsVO vo = new DeviceTypePieOptionsVO();
            // 手动设置属性
            vo.setName(deviceTypeService.getDeviceType(((Number) map.get("deviceType")).longValue()).getName());
            vo.setValue(Integer.parseInt(map.get("count").toString()));
            deviceTypePieOptionsVOList.add(vo);

        }
        return success(deviceTypePieOptionsVOList);
    }

    @GetMapping("/getMoldTypeBarOptions")
    @Operation(summary = "获得模具分类分布统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<DeviceRepairLineOptionsVO> getMoldTypeBarOptions() {
        DeviceRepairLineOptionsVO deviceRepairLineOptionsVO = new DeviceRepairLineOptionsVO();
        QueryWrapper<MoldDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("brand_id as brandId", "COUNT(*) as count")
                .groupBy("brand_id")
                .orderByDesc("count")
                .last("LIMIT 5");
        List<Map<String, Object>> result = moldMapper.selectMaps(queryWrapper);
        List<String> xAxis = new ArrayList<>();
        List<Integer> series = new ArrayList<>();
        for (Map<String, Object> map : result) {
            DeviceTypePieOptionsVO vo = new DeviceTypePieOptionsVO();
            // 手动设置属性
            xAxis.add(moldBrandService.getMoldBrand(((Number) map.get("brandId")).longValue()).getName());
            series.add(Integer.parseInt(map.get("count").toString()));
        }
        deviceRepairLineOptionsVO.setXAxis(xAxis);
        deviceRepairLineOptionsVO.setSeries(series);
        return success(deviceRepairLineOptionsVO);
    }



    @GetMapping("/getTaskStatistics")
    @Operation(summary = "获得各设备统计个数")
    @Parameter(name = "orgId", description = "产线组织Id")
    @PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
    public CommonResult<EventStatisticsVO> getTaskStatistics(@RequestParam(name = "orgId") Long orgId) {

        EventStatisticsVO vo  = new EventStatisticsVO();
        //设备点检
        ticketManagementService.selectCountDeviceInspection(vo );
        //设备保养
        ticketManagementService.selectCountDeviceMaintenance(vo );
        //设备维修
        dvRepairService.selectCountDeviceRepair(vo );
        //模具点检
        moldTicketManagementService.selectCountMoldInspection(vo );
        //模具保养
        moldTicketManagementService.selectCountMoldMaintenance(vo );
        //模具维修
        moldRepairService.selectCountMoldRepair(vo );

        // 计算占比
        int total = vo.getDeviceInspection()
                + vo.getDeviceMaintenance()
                + vo.getDeviceRepair()
                + vo.getMoldInspection()
                + vo.getMoldMaintenance()
                + vo.getMoldRepair();

        if (total > 0) {
            vo.setDeviceInspectionProportion(calcPercent(vo.getDeviceInspection(), total));
            vo.setDeviceMaintenanceProportion(calcPercent(vo.getDeviceMaintenance(), total));
            vo.setDeviceRepairProportion(calcPercent(vo.getDeviceRepair(), total));

            vo.setMoldInspectionProportion(calcPercent(vo.getMoldInspection(), total));
            vo.setMoldMaintenanceProportion(calcPercent(vo.getMoldMaintenance(), total));
            vo.setMoldRepairProportion(calcPercent(vo.getMoldRepair(), total));
        } else {
            // 防止除 0
            vo.setDeviceInspectionProportion("0%");
            vo.setDeviceMaintenanceProportion("0%");
            vo.setDeviceRepairProportion("0%");
            vo.setMoldInspectionProportion("0%");
            vo.setMoldMaintenanceProportion("0%");
            vo.setMoldRepairProportion("0%");
        }

        return success(vo);
    }

    /**
     * 计算百分比，保留整数
     */
    private String calcPercent(int value, int total) {
        if (total <= 0) {
            return "0%";
        }
        int percent = (int) Math.round(value * 100.0 / total);
        return percent + "%";
    }



    @GetMapping("/getAllTaskList")
    @Operation(summary = "获得所有任务")
    @Parameter(name = "orgId", description = "产线组织Id")
    @PreAuthorize("@ss.hasPermission('mes:bom:query')")
    public CommonResult<List<TaskVO>> getAllTaskList(@RequestParam(name = "orgId") Long orgId) {
        List<TaskVO> taskVOList = new ArrayList<>();

        // 设备保养 点检
        List<TicketManagementDO> ticketManagementDOList = ticketManagementService.getList();
        for (TicketManagementDO  ticketManagementDO : ticketManagementDOList) {
            TaskVO  taskVO = new TaskVO();
            taskVO.setCode(ticketManagementDO.getPlanNo());
            taskVO.setName(ticketManagementDO.getConfigName());
            if (ticketManagementDO.getPlanType() == 2) {
                taskVO.setType("设备保养");
            } else {
                taskVO.setType("设备点检");
            }
            taskVO.setFinishStatus(ticketManagementDO.getJobStatus());
            taskVO.setResultStatus(ticketManagementDO.getJobResult());
            taskVOList.add(taskVO);
        }

        // 设备维修
        List<DvRepairDO> dvRepairDOList = dvRepairService.getList();
        for (DvRepairDO dvRepairDO : dvRepairDOList) {
            TaskVO  taskVO = new TaskVO();
            taskVO.setCode(dvRepairDO.getRepairCode());
            taskVO.setName(dvRepairDO.getRepairName());
            taskVO.setType("设备维修");
            taskVO.setFinishStatus(String.valueOf(dvRepairDO.getStatus()));
            taskVO.setResultStatus(dvRepairDO.getRepairStatus());
            taskVOList.add(taskVO);
        }

        // 模具保养 点检
        List<MoldTicketManagementDO> moldTicketManagementDOList = moldTicketManagementService.getList();
        for (MoldTicketManagementDO  moldTicketManagementDO : moldTicketManagementDOList) {
            TaskVO  taskVO  = new TaskVO();
            taskVO.setCode(moldTicketManagementDO.getPlanNo());
            taskVO.setName(moldTicketManagementDO.getConfigName());
            if (moldTicketManagementDO.getPlanType() == 2) {
                taskVO.setType("模具保养");
            } else {
                taskVO.setType("模具点检");
            }
            taskVO.setFinishStatus(String.valueOf(moldTicketManagementDO.getJobStatus()));
            taskVO.setResultStatus(moldTicketManagementDO.getJobResult());
            taskVOList.add(taskVO);
        }

        // 模具维修
        List<MoldRepairDO> moldRepairDOList = moldRepairService.getList();
        for (MoldRepairDO  moldRepairDO : moldRepairDOList) {
            TaskVO  taskVO = new TaskVO();
            taskVO.setCode(moldRepairDO.getRepairCode());
            taskVO.setName(moldRepairDO.getRepairName());
            taskVO.setType("模具维修");
            taskVO.setFinishStatus(String.valueOf(moldRepairDO.getStatus()));
            taskVO.setResultStatus(moldRepairDO.getRepairStatus());
            taskVOList.add(taskVO);
        }

        return success(taskVOList);
    }
}
