package com.cf.imes.module.executor.service.manage.query;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.cf.imes.framework.common.enums.OrderPackageTypeEnum;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.executor.controller.admin.manage.pack.vo.GroupNameList;
import com.cf.imes.module.executor.controller.admin.manage.pack.vo.PackDetailsReqVO;
import com.cf.imes.module.executor.controller.admin.manage.query.vo.pack.PackageDetailsRespVO;
import com.cf.imes.module.executor.dal.mysql.orderParts.OrderPartsMapper;
import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import jakarta.annotation.Resource;

import java.math.BigDecimal;

import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;


@Service
@Validated
public class ProductionStatusServiceImpl implements ProductionStatusService {
    @Resource
    private OrderPartsMapper orderPartsMapper;

    @Resource
    private PlateMapper orderPlateMapper;

    // 查看包裹详情
    @Override
    public PageResult<PackageDetailsRespVO> queryPackageDetails(PackDetailsReqVO reqVO) {

//        PageDTO<PackageDetailsRespVO> page = new PageDTO<>(reqVO.getPageNo(), reqVO.getPageSize());
//
//        // 查看配件包裹
//        if(reqVO.getType().equals(OrderPackageTypeEnum.PARTS.getType()) || reqVO.getType().equals(OrderPackageTypeEnum.OTHER_ACCESSORIES.getType())){
//
//
//            // 查看配件包裹
//            IPage<PackageDetailsRespVO> packageDetailsRespVOS = orderPartsMapper.selectParts(page,reqVO.getPackageId(),getUserOrganId());
//            if (CollUtil.isEmpty(packageDetailsRespVOS.getRecords())) {
//                return new PageResult<>();
//            }
//
//            packageDetailsRespVOS.getRecords().forEach(f->{
//                f.setNum(f.getCount().stream().reduce(BigDecimal.ZERO, BigDecimal::add));
//
//                f.setCount(null);
//                f.setBodyId(null);
//                f.setRoomId(null);
//                f.setGroupId(null);
//            });
//
//            return new PageResult<>(packageDetailsRespVOS.getRecords(), packageDetailsRespVOS.getTotal());
//
//        }


//        // 查看板材包裹
//        IPage<PackageDetailsRespVO> packageDetailsRespVOS = orderPlateMapper.selectPackPlateList(page,reqVO.getPackageId(),getUserOrganId());
//
//        if (CollUtil.isEmpty(packageDetailsRespVOS.getRecords())) {
//            return new PageResult<>();
//        }
//
//        for (PackageDetailsRespVO plateDetailsRespVO : packageDetailsRespVOS.getRecords()) {
//            String name = "";
//
//            if(!plateDetailsRespVO.getProcessGroupNameList().isEmpty()) {
//                for (GroupNameList groupNameList : plateDetailsRespVO.getProcessGroupNameList()) {
//                    // 去除最后的逗号
//                    name += groupNameList.getName() + ",";
//                }
//                name = name.substring(0, name.length() - 1);
//            }
//
//            plateDetailsRespVO.setProcessGroup(name);
//        }
//
//
//        return new PageResult<>(packageDetailsRespVOS.getRecords(), packageDetailsRespVOS.getTotal());
        return null;
    }
}
