package com.cf.imes.module.system.api.process;


import com.cf.imes.framework.common.enums.ProcessProcessingTypeEnum;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.module.system.api.process.dto.ProcessDTO;
import com.cf.imes.module.system.dal.dataobject.process.ProcessDO;
import com.cf.imes.module.system.dal.mysql.process.ProcessMapper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

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

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class ProcessApiImpl implements ProcessApi {



    @Resource
    private ProcessMapper processMapper;




    @Override
    public BigDecimal getProcess(Long processId) {

        ProcessDO processDO = processMapper.selectByType(processId,getUserOrganId());


        return processDO == null ? BigDecimal.ZERO : processDO.getPieceRate();
    }



    @Override
    public List<ProcessDTO> getUserProcess(Long userId) {

        List<ProcessDO> processDOS = processMapper.selectProcessList(getUserOrganId(), userId)
                .stream()
                .filter(f-> Objects.equals(f.getType(),ProcessProcessingTypeEnum.CUTTINGMATERIALS.getNumber()))
                .toList();

        return BeanUtils.toBean(processDOS,ProcessDTO.class);
    }


}
