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 workstations = workstationMapper.selectList(Wrappers.lambdaQuery().isNotNull(Workstation::getWorkCenter)); if (CollectionUtil.isNotEmpty(workstations)) { // 获取字典保存的工作中心信息 List dictItems = workstationMapper.selectDictWorkCenterInfos(); Map workCenterMap = dictItems.stream().collect(Collectors.toMap(SysDictItem::getValue, SysDictItem::getLabel)); Map> collect = workstations.stream().collect(Collectors.groupingBy(Workstation::getWorkCenter)); List shopMachineBasicInfoDataBeans = new ArrayList<>(); for (Map.Entry> entry : collect.entrySet()) { EmsWorkshopAndMachineDTO.ShopMachineBasicInfoDataBean basicInfoDataBean = new EmsWorkshopAndMachineDTO.ShopMachineBasicInfoDataBean(); basicInfoDataBean.setShopCode(entry.getKey()); basicInfoDataBean.setShopName(workCenterMap.get(entry.getKey())); List 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 machineYieldDetailInfos = productOutputMapper.getEmsMachineYield(machineCode, beginDate, endDate, sqlDateFormat, showDateFormat); result.setMachineYieldDetailInfos(machineYieldDetailInfos); return result; } }