package cn.iocoder.yudao.module.mes.api.task; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.mes.api.task.dto.MesProWorkHourSummaryReqDTO; import cn.iocoder.yudao.module.mes.api.task.dto.MesProWorkHourSummaryRespDTO; import cn.iocoder.yudao.module.mes.dal.mysql.pro.task.MesProTaskMapper; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * MES 生产任务 API 实现类 * * @author 超级管理员 */ @Service @Validated public class MesProTaskApiImpl implements MesProTaskApi { @Resource private MesProTaskMapper taskMapper; @Override public List getTeamWorkHourSummary(MesProWorkHourSummaryReqDTO reqDTO) { List> rows = taskMapper.selectWorkHourSummary( reqDTO == null ? null : reqDTO.getStartTime(), reqDTO == null ? null : reqDTO.getEndTime()); List list = new ArrayList<>(rows.size()); for (Map row : rows) { MesProWorkHourSummaryRespDTO dto = new MesProWorkHourSummaryRespDTO(); dto.setTeamId(numberToLong(row.get("team_id"))); dto.setTeamName(StrUtil.toStringOrNull(row.get("team_name"))); dto.setTaskCount(numberToInt(row.get("task_count"))); dto.setTotalDuration(numberToInt(row.get("total_duration"))); int totalDuration = dto.getTotalDuration() == null ? 0 : dto.getTotalDuration(); dto.setWorkHours(BigDecimal.valueOf(totalDuration * 8L)); list.add(dto); } return list; } private Long numberToLong(Object value) { return value instanceof Number ? ((Number) value).longValue() : null; } private Integer numberToInt(Object value) { return value instanceof Number ? ((Number) value).intValue() : null; } }