李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.chinaztt.mes.production.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chinaztt.mes.basic.entity.Workstation;
import com.chinaztt.mes.basic.mapper.WorkstationMapper;
import com.chinaztt.mes.basic.util.DictUtils;
import com.chinaztt.mes.production.dto.EmsMachineYieldDTO;
import com.chinaztt.mes.production.dto.EmsWorkshopAndMachineDTO;
import com.chinaztt.mes.production.mapper.ProductOutputMapper;
import com.chinaztt.mes.production.service.EmsHandoverService;
import com.chinaztt.ztt.admin.api.entity.SysDictItem;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @Description:
 * @Author: shz
 * @Date: 2023/4/20 16:22
 */
@Service
@AllArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class EmsHandoverServiceImpl implements EmsHandoverService {
 
    public static final String TIME_MONTH_CODE = "m";
    public static final String TIME_DAY_CODE = "d";
 
    private WorkstationMapper workstationMapper;
 
    private ProductOutputMapper productOutputMapper;
 
 
    @Override
    public EmsWorkshopAndMachineDTO getWorkshopAndMachine() {
        EmsWorkshopAndMachineDTO result = new EmsWorkshopAndMachineDTO();
        List<Workstation> workstations = workstationMapper.selectList(Wrappers.<Workstation>lambdaQuery().isNotNull(Workstation::getWorkCenter));
        if (CollectionUtil.isNotEmpty(workstations)) {
            // 获取字典保存的工作中心信息
            List<SysDictItem> dictItems = workstationMapper.selectDictWorkCenterInfos();
            Map<String, String> workCenterMap = dictItems.stream().collect(Collectors.toMap(SysDictItem::getValue, SysDictItem::getLabel));
 
            Map<String, List<Workstation>> collect = workstations.stream().collect(Collectors.groupingBy(Workstation::getWorkCenter));
            List<EmsWorkshopAndMachineDTO.ShopMachineBasicInfoDataBean> shopMachineBasicInfoDataBeans = new ArrayList<>();
            for (Map.Entry<String, List<Workstation>> entry : collect.entrySet()) {
                EmsWorkshopAndMachineDTO.ShopMachineBasicInfoDataBean basicInfoDataBean = new EmsWorkshopAndMachineDTO.ShopMachineBasicInfoDataBean();
                basicInfoDataBean.setShopCode(entry.getKey());
                basicInfoDataBean.setShopName(workCenterMap.get(entry.getKey()));
 
                List<EmsWorkshopAndMachineDTO.MachineBasicInfoDataBean> machineBasicInfoDataBeans = new ArrayList<>();
                basicInfoDataBean.setMachineBasicInfoDataBeans(machineBasicInfoDataBeans);
 
                for (Workstation workstation : entry.getValue()) {
                    EmsWorkshopAndMachineDTO.MachineBasicInfoDataBean machineBasicInfoDataBean = new EmsWorkshopAndMachineDTO.MachineBasicInfoDataBean();
                    machineBasicInfoDataBean.setMachineCode(workstation.getWorkstationNo());
                    machineBasicInfoDataBean.setMachineName(workstation.getName());
                    machineBasicInfoDataBeans.add(machineBasicInfoDataBean);
                }
                shopMachineBasicInfoDataBeans.add(basicInfoDataBean);
            }
            result.setShopMachineBasicInfoDataBeans(shopMachineBasicInfoDataBeans);
        }
 
        return result;
    }
 
    @Override
    public EmsMachineYieldDTO getMachineYield(String machineCode, String beginDate, String endDate, String timeParticleCode) {
        String sqlDateFormat;
        String showDateFormat;
        if (TIME_MONTH_CODE.equals(timeParticleCode)) {
            beginDate = DateUtil.format(DateUtil.parse(beginDate), "yyyyMM");
            endDate = DateUtil.format(DateUtil.parse(endDate), "yyyyMM");
            sqlDateFormat = "yyyyMM";
            showDateFormat = "'yyyy-MM'";
        } else if (TIME_DAY_CODE.equals(timeParticleCode)) {
            beginDate = DateUtil.format(DateUtil.parse(beginDate), "yyyyMMdd");
            endDate = DateUtil.format(DateUtil.parse(endDate), "yyyyMMdd");
            sqlDateFormat = "yyyyMMdd";
            showDateFormat = "'yyyy-MM-dd'";
        } else {
            throw new RuntimeException("不支持该时间粒度参数");
        }
 
        EmsMachineYieldDTO result = new EmsMachineYieldDTO();
        List<EmsMachineYieldDTO.MachineYieldDetailInfo> machineYieldDetailInfos = productOutputMapper.getEmsMachineYield(machineCode, beginDate, endDate, sqlDateFormat, showDateFormat);
        result.setMachineYieldDetailInfos(machineYieldDetailInfos);
 
        return result;
    }
}