xiaoyi
20 小时以前 4e8dc8cd84e3d3d4099d9cf0ed866dbd7e8ed9aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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<MesProWorkHourSummaryRespDTO> getTeamWorkHourSummary(MesProWorkHourSummaryReqDTO reqDTO) {
        List<Map<String, Object>> rows = taskMapper.selectWorkHourSummary(
                reqDTO == null ? null : reqDTO.getStartTime(),
                reqDTO == null ? null : reqDTO.getEndTime());
        List<MesProWorkHourSummaryRespDTO> list = new ArrayList<>(rows.size());
        for (Map<String, Object> 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;
    }
 
}