package com.fjhx.mes.service.production.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.common.enums.CodingRuleEnum;
import com.fjhx.common.enums.PushBusinessTypeEnum;
import com.fjhx.common.service.coding.CodingRuleService;
import com.fjhx.customer.service.customer.CustomerService;
import com.fjhx.item.entity.product.po.ProductInfo;
import com.fjhx.item.service.product.ProductInfoService;
import com.fjhx.mes.entity.applicable.po.ApplicableProducts;
import com.fjhx.mes.entity.production.dto.ProductionTaskDetailDto;
import com.fjhx.mes.entity.production.dto.ProductionTaskDto;
import com.fjhx.mes.entity.production.dto.ProductionTaskSelectDto;
import com.fjhx.mes.entity.production.po.*;
import com.fjhx.mes.entity.production.vo.ProductionTaskDetailVo;
import com.fjhx.mes.entity.production.vo.ProductionTaskVo;
import com.fjhx.mes.entity.task.po.TaskProgress;
import com.fjhx.mes.entity.technology.po.Technology;
import com.fjhx.mes.entity.technology.po.TechnologyProcessLine;
import com.fjhx.mes.entity.work.po.WorkOrder;
import com.fjhx.mes.entity.work.po.WorkOrderBom;
import com.fjhx.mes.entity.work.po.WorkOrderProcessLine;
import com.fjhx.mes.entity.work.po.WorkOrderProductionProcesses;
import com.fjhx.mes.mapper.production.ProductionTaskMapper;
import com.fjhx.mes.service.applicable.ApplicableProductsService;
import com.fjhx.mes.service.production.*;
import com.fjhx.mes.service.task.TaskProgressService;
import com.fjhx.mes.service.technology.TechnologyProcessLineService;
import com.fjhx.mes.service.technology.TechnologyService;
import com.fjhx.mes.service.work.WorkOrderBomService;
import com.fjhx.mes.service.work.WorkOrderProcessLineService;
import com.fjhx.mes.service.work.WorkOrderProductionProcessesService;
import com.fjhx.mes.service.work.WorkOrderService;
import com.fjhx.socket.core.PushTypeEnum;
import com.fjhx.socket.core.WebSocketPush;
import com.fjhx.wms.entity.stock.emums.StockWaitType;
import com.fjhx.wms.entity.stock.po.Stock;
import com.fjhx.wms.entity.stock.po.StockFrozen;
import com.fjhx.wms.entity.stock.po.StockWait;
import com.fjhx.wms.entity.stock.po.StockWaitDetails;
import com.fjhx.wms.service.stock.StockFrozenService;
import com.fjhx.wms.service.stock.StockService;
import com.fjhx.wms.service.stock.StockWaitDetailsService;
import com.fjhx.wms.service.stock.StockWaitService;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.ruoyi.common.utils.wrapper.SqlField;
import com.ruoyi.system.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;


/**
 * <p>
 * 生产任务 服务实现类
 * </p>
 *
 * @author
 * @since 2023-03-30
 */
@Service
public class ProductionTaskServiceImpl extends ServiceImpl<ProductionTaskMapper, ProductionTask> implements ProductionTaskService {
    @Autowired
    private ProductInfoService productInfoService;
    @Autowired
    private ProductionPlanService productionPlanService;
    @Autowired
    private WorkOrderService workOrderService;
    @Autowired
    private StockWaitService stockWaitService;
    @Autowired
    private StockWaitDetailsService stockWaitDetailsService;
    @Autowired
    private WorkOrderBomService workOrderBomService;
    @Autowired
    private WorkOrderProductionProcessesService workOrderProductionProcessesService;
    @Autowired
    private TechnologyService technologyService;
    @Autowired
    private ApplicableProductsService applicableProductsService;
    @Autowired
    private ProductionTaskDetailService productionTaskDetailService;
    @Autowired
    private ProductionProcessesService productionProcessesService;
    @Autowired
    private ProductionTaskDetailRecordService productionTaskDetailRecordService;
    @Autowired
    private ProductionTaskProcessesDetailService productionTaskProcessesDetailService;
    @Autowired
    private StockService stockService;
    @Autowired
    private StockFrozenService stockFrozenService;
    @Autowired
    private CodingRuleService codingRuleService;
    @Autowired
    private CustomerService customerService;
    @Autowired
    private TechnologyProcessLineService technologyProcessLineService;
    @Autowired
    private WorkOrderProcessLineService workOrderProcessLineService;
    @Autowired
    private TaskProgressService taskProgressServices;

    @Override
    public Page<ProductionTaskVo> getPage(ProductionTaskSelectDto dto) {
        IWrapper<ProductionTask> wrapper = getWrapper();
        wrapper.orderByDesc("pt", ProductionTask::getId);
        if (ObjectUtil.isNotEmpty(dto.getKeyword())) {
            wrapper.keyword(dto.getKeyword(),
                    new SqlField("pt", ProductionTaskVo::getCode),
                    new SqlField("pt", ProductionTaskVo::getQuantity),
                    new SqlField("pt", ProductionTaskVo::getDueDate),
                    new SqlField("pi.`name`"),
                    new SqlField("pp.`code`")
            );
        }
        Page<ProductionTaskVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        List<ProductionTaskVo> records = page.getRecords();

        //赋值负责人名字
        UserUtil.assignmentNickName(records, ProductionTask::getPersonLiableId, ProductionTaskVo::setPersonLiableName);

        //赋值客户名称
        customerService.attributeAssign(records, ProductionTaskVo::getCustomerId, (item, customer) -> {
            item.setCustomerName(customer.getName());
        });
        return page;
    }

    @Override
    public ProductionTaskVo detail(Long id) {
        ProductionTaskVo productionTaskVo = baseMapper.detail(id);
        ProductInfo productInfo = productInfoService.getById(productionTaskVo.getProductId());
        if (ObjectUtil.isNotEmpty(productInfo)) {
            productionTaskVo.setProductName(productInfo.getName());
            productionTaskVo.setProductSpec(productInfo.getSpec());
        }
        Map<Long, String> nickNameMapByIds = UserUtil.getNickNameMapByIds(Arrays.asList(productionTaskVo.getPersonLiableId()));
        if (ObjectUtil.isNotEmpty(nickNameMapByIds)) {
            productionTaskVo.setPersonLiableName(nickNameMapByIds.get(productionTaskVo.getPersonLiableId()));
        }
        return productionTaskVo;
    }

    @DSTransactional
    @Override
    public synchronized void add(ProductionTaskDto productionTaskDto) {
        Long productionPlanId = productionTaskDto.getProductionPlanId();
        ProductionPlan productionPlan = productionPlanService.getById(productionPlanId);

        //检查待排程数量防止并发
        List<ProductionTask> productionTaskList = this.list(q -> q.eq(ProductionTask::getProductionPlanId, productionTaskDto.getProductionPlanId()));
        BigDecimal taskCount = productionTaskList.stream().map(ProductionTask::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);
        if (taskCount.add(productionTaskDto.getQuantity()).compareTo(productionPlan.getQuantity()) > 0) {
            throw new ServiceException("任务数量大于计划数量，请检查!");
        }

//        productionTaskDto.setCode(CodeEnum.PRODUCTION_TASK.getCode());
        productionTaskDto.setCode(codingRuleService.createCode(CodingRuleEnum.JXST_PRODUCTION_TASK.getKey(), null));
        this.save(productionTaskDto);
        //更新生产计划状态为进行中
        productionPlan.setStatus(1);
        productionPlanService.updateById(productionPlan);

        //根据工单是否是定制工单 创建BOM待出库数据
        WorkOrder workOrder = workOrderService.getById(productionPlan.getWorkOrderId());
        if (ObjectUtil.isEmpty(workOrder)) {
            throw new ServiceException("查询不到该任务的工单信息");
        }

        List<WorkOrderBom> bomDetailList = workOrderBomService.list(q -> q.eq(WorkOrderBom::getWorkOrderId, workOrder.getId()));
//        List<BomDetail> bomDetailList = new ArrayList<>();
//        if ("1".equals(workOrder.getIsCustomized())) {
//            List<WorkOrderBom> workOrderBomList = workOrderBomService.list(q -> q.eq(WorkOrderBom::getWorkOrderId, workOrder.getId()));
//            if (ObjectUtil.isEmpty(workOrderBomList)) {
//                throw new ServiceException("该工单为定制工单 未配置定制BOM");
//            }
//            bomDetailList = BeanUtil.copyToList(workOrderBomList, BomDetail.class);
//        } else {
//            //查询BOM信息
//            BomInfo bomInfo = bomInfoService.getOne(q -> q.eq(BomInfo::getProductId, workOrder.getProductId()).eq(BomInfo::getCurrentVersion, 1));
//            if (ObjectUtil.isEmpty(bomInfo)) {
//                throw new ServiceException("查询不到产品的BOM信息");
//            }
//            bomDetailList = bomDetailService.list(q -> q.eq(BomDetail::getBomInfoId, bomInfo.getId()));
//            if (ObjectUtil.isEmpty(bomDetailList)) {
//                throw new ServiceException("查询不到BOM明细");
//            }
//        }
        //创建待出库信息
        StockWait stockWait = new StockWait();
        stockWait.setBusinessId(productionTaskDto.getId());
        stockWait.setType(2);//出库
        stockWait.setStatus(0);//待出库
        stockWait.setBusinessType(StockWaitType.PRODUCTION_TASK_OUT.getDetailType());//生产任务出库
        stockWait.setBusinessCode(productionTaskDto.getCode());
        stockWait.setBusinessId(productionTaskDto.getId());
        stockWait.setWorkOrderId(workOrder.getId());
        stockWaitService.save(stockWait);
        //创建待出库明细
        List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
        for (WorkOrderBom bomDetail : bomDetailList) {
            //计算数量
            BigDecimal multiply = bomDetail.getQuantity().multiply(productionTaskDto.getQuantity());
            //创建待出库明细
            StockWaitDetails stockWaitDetails = new StockWaitDetails();
            stockWaitDetails.setStockWaitId(stockWait.getId());
            stockWaitDetails.setProductId(bomDetail.getProductId());
            stockWaitDetails.setQuantity(multiply);
            stockWaitDetails.setReceiptQuantity(BigDecimal.ZERO);
            stockWaitDetailsList.add(stockWaitDetails);
        }
        stockWaitDetailsService.saveBatch(stockWaitDetailsList);


        //根据BOM明细冻结库存
        List<Long> productIds = bomDetailList.stream().map(WorkOrderBom::getProductId).collect(Collectors.toList());
        Map<Long, List<Stock>> productMap = new HashMap<>();
        if (ObjectUtil.isNotEmpty(productIds)) {
            productMap = stockService.mapKGroup(Stock::getProductId, q -> q.in(Stock::getProductId, productIds));
        }
        List<Long> errProductIdList = new ArrayList();
        for (WorkOrderBom bomDetail : bomDetailList) {
            Long productId = bomDetail.getProductId();
            //计算总数量 需要的物料数量*工单生产数量
            BigDecimal multiply = bomDetail.getQuantity().multiply(productionTaskDto.getQuantity());
            //添加冻结库存
            List<Stock> stocks = productMap.get(productId);
            if (ObjectUtil.isEmpty(stocks)) {
                //物料不存在添加到异常列表
                errProductIdList.add(productId);
            } else {
                //计算库存是否充足（可用库存 - 冻结库存 - 所需的数量）是否大等于0
                BigDecimal quantity = stocks.stream().map(Stock::getQuantity).reduce(BigDecimal.ZERO, BigDecimal::add);

                StockFrozen stockFrozen = stockFrozenService.getOne(q -> q.eq(StockFrozen::getProductId, bomDetail.getProductId()));
                if (ObjectUtil.isEmpty(stockFrozen)) {
                    stockFrozen = new StockFrozen();
                    stockFrozen.setProductId(bomDetail.getProductId());
                    stockFrozen.setFrozenQuantity(BigDecimal.ZERO);
                    stockFrozenService.save(stockFrozen);
                }
                BigDecimal subtract = quantity.subtract(stockFrozen.getFrozenQuantity()).subtract(multiply);
                if (subtract.compareTo(BigDecimal.ZERO) < 0) {
                    //物料不足添加到异常列表
                    errProductIdList.add(productId);
                }

                //更新冻结库存
                Long stockFrozenId = stockFrozen.getId();
                stockFrozenService.update(q -> q
                        .eq(StockFrozen::getId, stockFrozenId)
                        .setSql("frozen_quantity = frozen_quantity + " + multiply)
                );
            }
        }

        //判断库存是否充足
        if (errProductIdList.size() > 0) {
            List<String> productNames = productInfoService.listObject(ProductInfo::getName, q -> q
                    .in(ObjectUtil.isNotEmpty(errProductIdList), ProductInfo::getId, errProductIdList)
            );
            String collect = productNames.stream().collect(Collectors.joining("，"));
            throw new ServiceException(String.format("以下物料库存不足 %s", collect));
        }

    }

    @Override
    public void edit(ProductionTaskDto productionTaskDto) {
        this.updateById(productionTaskDto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

    @Override
    public List<ProductionTaskVo> myListByIds(List<Long> ids) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.in("pt.id", ids);
        return baseMapper.myListByIds(queryWrapper);
    }

    @DSTransactional
    @Override
    public void addByJxst(ProductionTaskDto productionTaskDto) {
        add(productionTaskDto);
        //获取生产计划信息
        ProductionPlan productionPlan = productionPlanService.getById(productionTaskDto.getProductionPlanId());
        if (ObjectUtil.isEmpty(productionPlan)) {
            throw new ServiceException("查询不到该任务的生产计划信息");
        }
        //获取工单信息
        WorkOrder workOrder = workOrderService.getById(productionPlan.getWorkOrderId());
        if (ObjectUtil.isEmpty(workOrder)) {
            throw new ServiceException("查询不到该任务的工单信息");
        }


        //获取当前工序列表
        List<Long> processList;
        //判断是否为定制 获取工序信息
        Long productionProcessesId;
        Long nextProductionProcessesId = null;
        if ("1".equals(workOrder.getIsCustomized())) {
            List<WorkOrderProductionProcesses> workOrderProductionProcesses = workOrderProductionProcessesService.list(q -> q
                    .eq(WorkOrderProductionProcesses::getWorkOrderId, workOrder.getId())
                    .orderByAsc(WorkOrderProductionProcesses::getSort));
            if (ObjectUtil.isEmpty(workOrderProductionProcesses)) {
                throw new ServiceException("定制工单 工序列表为空");
            }
            productionProcessesId = workOrderProductionProcesses.get(0).getId();
            //赋值下一工序id
            if (workOrderProductionProcesses.size() > 1) {
                nextProductionProcessesId = workOrderProductionProcesses.get(1).getId();
            }

            //获取开始节点下的节点为当前工序
            processList = workOrderProcessLineService.listObject(WorkOrderProcessLine::getTargetProcessesId,q -> q
                    .eq(WorkOrderProcessLine::getWorkOrderId, workOrder.getId())
                    .eq(WorkOrderProcessLine::getSourceProcessesId,1)
            );

        } else {
            ApplicableProducts applicableProducts = applicableProductsService.getOne(q -> q.eq(ApplicableProducts::getProductId, workOrder.getProductId()));
            if (ObjectUtil.isEmpty(applicableProducts)) {
                throw new ServiceException("未找到适用于该产品的工艺信息");
            }
            Technology technology = technologyService.getById(applicableProducts.getTechnologyId());
            if (ObjectUtil.isEmpty(technology)) {
                throw new ServiceException("工艺信息不存在");
            }

            //获取开始节点下的节点为当前工序
            processList = technologyProcessLineService.listObject(TechnologyProcessLine::getTargetProcessesId,q -> q
                    .eq(TechnologyProcessLine::getTechnologyId, technology.getId())
                    .eq(TechnologyProcessLine::getSourceProcessesId,1)
            );

            String processRoute = technology.getProcessRoute();
            if (ObjectUtil.isEmpty(processRoute)) {
                throw new ServiceException("工艺线路为空");
            }
            String[] split = processRoute.split(",");
            productionProcessesId = Long.valueOf(split[0]);
            //赋值下一工序id
            if (split.length > 1) {
                nextProductionProcessesId = Long.valueOf(split[1]);
            }
        }
        //创建任务明细
        List<ProductionTaskDetail> productionTaskDetailList = new ArrayList<>();
        List<ProductionTaskDetailRecord> productionTaskDetailRecordList = new ArrayList<>();
        for (int i = 0; i < productionTaskDto.getQuantity().intValue(); i++) {
            ProductionTaskDetail productionTaskDetail = new ProductionTaskDetail();
            productionTaskDetail.setId(IdWorker.getId());
            productionTaskDetail.setProductionTaskId(productionTaskDto.getId());//任务id
            productionTaskDetail.setFinishStatus(0);//默认状态未完工
            productionTaskDetail.setProductId(workOrder.getProductId());//产品id

//            //赋值当前工序和下一工序
//            productionTaskDetail.setProductionProcessesId(productionProcessesId);//第一个工序id
//            productionTaskDetail.setNextProductionProcessesId(nextProductionProcessesId);//第二个工序id

            //生成SN
            productionTaskDetail.setProductSn(String.format("%s-%03d", productionTaskDto.getCode(), i + 1));

            //任务一创建 负责人为空 并直接在流转中 用于抢单
//            productionTaskDetail.setPersonLiableId(productionTaskDto.getPersonLiableId());//负责人ID
//            productionTaskDetail.setCirculationStatus(1);//流转中
//
//            productionTaskDetail.setProcessesStatus(0);

            //冗余id
            productionTaskDetail.setWorkOrderId(workOrder.getId());
            productionTaskDetail.setContractDetailsId(workOrder.getContractDetailsId());

            productionTaskDetailList.add(productionTaskDetail);
        }
        productionTaskDetailService.saveBatch(productionTaskDetailList);
        productionTaskDetailRecordService.saveBatch(productionTaskDetailRecordList);

        //根据工艺路线生成生产信息
        List<TaskProgress> taskProgressList = new ArrayList<>();
        for (ProductionTaskDetail productionTaskDetail : productionTaskDetailList) {
            //创建生产过程信息
            if(ObjectUtil.isEmpty(processList)){
                //完工入库
                ProductionTaskDetailDto productionTaskDetailDto = BeanUtil.copyProperties(productionTaskDetail, ProductionTaskDetailDto.class);
                productionTaskDetailService.productStorage(productionTaskDetailDto);
            }
            //创建生产信息
            for (Long processId : processList) {
                TaskProgress taskProgress = new TaskProgress();
                taskProgress.setProductionTaskDetailId(productionTaskDetail.getId());
                taskProgress.setProcessesId(processId);
                taskProgress.setStatus(0);
                taskProgressList.add(taskProgress);
            }
        }
        taskProgressServices.saveBatch(taskProgressList);


        //添加任务对每一个工序的用户绑定
        List<ProductionTaskProcessesDetail> productionTaskProcessesDetailList = new ArrayList<>();
        JSONObject taskProcessesUserJson = JSONObject.parseObject(productionTaskDto.getTaskProcessesUser());
        List<WorkOrderProductionProcesses> productionProcessesList = workOrderService.getProductionProcessesList(workOrder);
        for (WorkOrderProductionProcesses workOrderProductionProcesses : productionProcessesList) {
            Long processesId = workOrderProductionProcesses.getId();
            List<Long> userIds = taskProcessesUserJson.getList(processesId.toString(), Long.class);
            if (ObjectUtil.isEmpty(userIds)) {
                throw new ServiceException(String.format("工序 %s 未配置用户", workOrderProductionProcesses.getName()));
            }
            for (Long userId : userIds) {
                ProductionTaskProcessesDetail productionTaskProcessesDetail = new ProductionTaskProcessesDetail();
                productionTaskProcessesDetail.setProductionTaskId(productionTaskDto.getId());
                productionTaskProcessesDetail.setProductionProcessesId(processesId);
                productionTaskProcessesDetail.setUserId(userId);
                productionTaskProcessesDetailList.add(productionTaskProcessesDetail);
            }
        }
        productionTaskProcessesDetailService.saveBatch(productionTaskProcessesDetailList);

        //推送消息给第一个工序的用户有单可以抢了
        WorkOrderProductionProcesses workOrderProductionProcesses = productionProcessesList.get(0);
        List<Long> userIds = taskProcessesUserJson.getList(workOrderProductionProcesses.getId().toString(), Long.class);
        WebSocketPush.byUsers(PushTypeEnum.MESSAGE, userIds, "您有新的任务可接收！", PushBusinessTypeEnum.NEW_TASK.getType());
    }

    @Override
    public ProductionTaskVo detailByJxst(Long id) {
        ProductionTaskVo detail = detail(id);
        //赋值待排程数
        Long productionPlanId = detail.getProductionPlanId();
        ProductionPlan productionPlan = productionPlanService.getById(productionPlanId);
        List<ProductionTask> list1 = list(q -> q.eq(ProductionTask::getProductionPlanId, productionPlan.getId()));
        BigDecimal remainingQuantity = productionPlan.getQuantity().subtract(BigDecimal.valueOf(list1.size()));
        detail.setRemainingQuantity(remainingQuantity);
        detail.setProductionPlanCode(productionPlan.getCode());

        List<ProductionTaskDetail> list = productionTaskDetailService.list(q -> q.eq(ProductionTaskDetail::getProductionTaskId, id));
        List<ProductionTaskDetailVo> productionTaskDetailVos = BeanUtil.copyToList(list, ProductionTaskDetailVo.class);
        //赋值当前工序名称
        WorkOrder workOrder = workOrderService.getById(productionPlan.getWorkOrderId());
        //判断是否是定制工单 获取指定工序
        if ("1".equals(workOrder.getIsCustomized())) {
            //获取定制工序
            Map<Long, String> gxmap = workOrderProductionProcessesService.mapKV(WorkOrderProductionProcesses::getId, WorkOrderProductionProcesses::getName, q -> q.eq(WorkOrderProductionProcesses::getWorkOrderId, workOrder.getId()));
            if (ObjectUtil.isNotEmpty(gxmap)) {
                for (ProductionTaskDetailVo productionTaskDetail : productionTaskDetailVos) {
                    String gxname = gxmap.get(productionTaskDetail.getProductionProcessesId());
                    productionTaskDetail.setProductionProcessesName(gxname);
                }
            }
        } else {
            //获取基本工序
            ApplicableProducts applicableProducts = applicableProductsService.getOne(q -> q.eq(ApplicableProducts::getProductId, workOrder.getProductId()));
            if (ObjectUtil.isNotEmpty(applicableProducts)) {
                Technology technology = technologyService.getById(applicableProducts.getTechnologyId());
                if (ObjectUtil.isNotEmpty(technology)) {
                    String processRoute = technology.getProcessRoute();
                    if (ObjectUtil.isNotEmpty(processRoute)) {
                        String[] split = processRoute.split(",");
                        Map<Long, String> gxmap = productionProcessesService.mapKV(ProductionProcesses::getId, ProductionProcesses::getName, q -> q.in(ProductionProcesses::getId, split));
                        for (ProductionTaskDetailVo productionTaskDetail : productionTaskDetailVos) {
                            String gxname = gxmap.get(productionTaskDetail.getProductionProcessesId());
                            productionTaskDetail.setProductionProcessesName(gxname);
                        }
                    }
                }
            }
        }
        //赋值累计耗时
        for (ProductionTaskDetailVo productionTaskDetail : productionTaskDetailVos) {
            long diff = new Date().getTime() - productionTaskDetail.getCreateTime().getTime();
            DecimalFormat decimalFormat = new DecimalFormat("#0.00");
            String formattedResult = decimalFormat.format(diff / 60.0 / 60.0 / 1000.0);
            productionTaskDetail.setCumulativeTime(formattedResult);

            //判断是否完工
            if (productionTaskDetail.getFinishStatus() == 1) {
                productionTaskDetail.setProductionProcessesName("已完成");
            }
        }
        detail.setProductionTaskDetailList(productionTaskDetailVos);
        return detail;
    }

}
