yb
昨天 ec33a83aa39eedaf39675d4ef7be5f133f556846
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentMagnificationServiceImpl.java
@@ -8,8 +8,12 @@
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.mdc.dto.*;
import org.jeecg.modules.mdc.entity.*;
import org.jeecg.modules.mdc.dto.MdcEquProDto;
import org.jeecg.modules.mdc.dto.MdcEquipmentMagnificationDto;
import org.jeecg.modules.mdc.entity.Equipment;
import org.jeecg.modules.mdc.entity.MdcDriveTypeParamConfig;
import org.jeecg.modules.mdc.entity.MdcEquipmentMagnification;
import org.jeecg.modules.mdc.entity.MdcEquipmentRunningSection;
import org.jeecg.modules.mdc.mapper.MdcEquipmentMagnificationMapper;
import org.jeecg.modules.mdc.service.*;
import org.jeecg.modules.mdc.util.DateUtils;
@@ -17,7 +21,6 @@
import org.jeecg.modules.mdc.vo.MdcMagnificationEquipmentVo;
import org.jeecg.modules.mdc.vo.MdcMagnificationVo;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
@@ -31,6 +34,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class MdcEquipmentMagnificationServiceImpl extends ServiceImpl<MdcEquipmentMagnificationMapper, MdcEquipmentMagnification> implements IMdcEquipmentMagnificationService {
@@ -54,12 +58,15 @@
    @Override
    public void savesEquipmentMagnifications(String dateTime) {
        List<MdcEquipmentMagnification> magnifications = new ArrayList<>();
        List<Equipment> equipmentList = equipmentService.list();
        Map<String,List<MdcDriveTypeParamConfig>> map = new HashMap<>();
        Date now =  DateUtils.plusTime(DateUtils.getNow(), -1);
        //主轴倍率
        //进给倍率
       /* Equipment e = equipmentService.getById("12345678");
        List<Equipment> equipmentList = new ArrayList<>();
        equipmentList.add(e);*/
        if (org.apache.commons.lang.StringUtils.isNotBlank(dateTime)) {
        if (StringUtils.isNotBlank(dateTime)) {
            try {
                Date initDate = DateUtils.toDate(dateTime, "yyyyMMdd");
                String date = DateUtils.format(initDate,DateUtils.STR_DATE);
@@ -69,23 +76,30 @@
            } catch (Exception ee) {
                log.error("参数格式不对", ee);
            }
        }
        List<Equipment> equipmentList = equipmentService.list();
        Map<String,List<MdcDriveTypeParamConfig>> map = new HashMap<>();
        Date now =  DateUtils.plusTime(DateUtils.getNow(), -1);
        for (Equipment equipment : equipmentList) {
            Date start = null;
            List<String> dates = new ArrayList<>();
            //查询最后一条记录
            MdcEquipmentMagnification mdcMagnification = super.baseMapper.getMaxStaticsData(equipment.getEquipmentid());
            if (mdcMagnification == null) {
                start = DateUtils.plusTime(DateUtils.getNow(), -20);
            if (StringUtils.isNotBlank(dateTime)) {
                Date initDate = DateUtils.toDate(dateTime, "yyyyMMdd");
                String date = DateUtils.format(initDate,DateUtils.STR_DATE);
                dates.add(date);
            } else {
                start = DateUtils.toDate(mdcMagnification.getTheDate(),DateUtils.STR_DATE );
                if (now.toString().equals(start.toString())) {
                    continue;
                MdcEquipmentMagnification mdcMagnification = super.baseMapper.getMaxStaticsData(equipment.getEquipmentid());
                if (mdcMagnification == null) {
                    start = DateUtils.plusTime(DateUtils.getNow(), -20);
                } else {
                    start = DateUtils.toDate(mdcMagnification.getTheDate(),DateUtils.STR_DATE );
                    if (now.toString().equals(start.toString())) {
                        continue;
                    }
                }
                dates = DateUtils.getDatesStringList(start,now);
            }
            List<String> dates = DateUtils.getDatesStringList(start,now);
            List<MdcDriveTypeParamConfig> list = new ArrayList<>();
            if (!map.containsKey(equipment.getDrivetype())) {
                MdcDriveTypeParamConfig config1 = mdcDriveTypeParamConfigService.getEnglishName(spindlebeilv,equipment.getDrivetype());
@@ -123,8 +137,6 @@
        if (!magnifications.isEmpty() && magnifications.size() > 0) {
            saveBatch(magnifications);
        }
        //数据保存
        return;
    }
    @Override
@@ -329,19 +341,48 @@
        avg.setEquipmentName("平均值");
        avg.setEquipmentType("平均值");
        //计算平均值
        avg.setMdcBeilvVoList(null);
        avg.setMdcBeilvVoList(calculateOpenAverage(result.getMdcMagnificationVos()));
        result.getMdcMagnificationVos().add(avg);
        return result;
    }
    /**
     * 计算平均值
     *
     * @param mdcMagnificationVos
     * @return
     */
    private List<MdcEquipmentMagnificationDto> calculateOpenAverage(List<MdcMagnificationEquipmentVo> mdcMagnificationVos) {
        List<MdcEquipmentMagnificationDto> result = new ArrayList<>();
        List<MdcEquipmentMagnificationDto> dataList = new ArrayList<>();
        for (MdcMagnificationEquipmentVo mdcMagnificationEquipmentVo : mdcMagnificationVos) {
            dataList.addAll(mdcMagnificationEquipmentVo.getMdcBeilvVoList());
        }
        dataList.parallelStream().collect(Collectors.groupingBy(MdcEquipmentMagnificationDto::getTheDate, Collectors.toList()))
                .forEach((theDate, mert) -> {
                    mert.stream().reduce((a, b) -> new MdcEquipmentMagnificationDto(
                            a.getTheDate(),
                            a.getFeedbeilv().add(b.getFeedbeilv()),
                            a.getSpindlebeilv().add(b.getSpindlebeilv()))).ifPresent(result::add);
                });
        for (MdcEquipmentMagnificationDto mdcEquipmentMagnificationDto : result) {
            mdcEquipmentMagnificationDto.setFeedbeilv(mdcEquipmentMagnificationDto.getFeedbeilv().divide(new BigDecimal(mdcMagnificationVos.size()), 2, RoundingMode.HALF_UP));
            mdcEquipmentMagnificationDto.setSpindlebeilv(mdcEquipmentMagnificationDto.getSpindlebeilv().divide(new BigDecimal(mdcMagnificationVos.size()), 2, RoundingMode.HALF_UP));
        }
        result.sort(Comparator.comparing(MdcEquipmentMagnificationDto::getTheDate));
        return result;
    }
    private MdcEquipmentMagnificationDto setDataList(List<MdcEquipmentMagnificationDto> list,String date,String equipmentId,MdcEquipmentMagnificationDto mdcMagnificationDto) {
        MdcEquipmentMagnificationDto result = new MdcEquipmentMagnificationDto();
        result.setTheDate(date);
        if (list != null && list.size() > 0) {
            for (MdcEquipmentMagnificationDto mdcEquipmentMagnificationDto : list) {
                if (date.equals(mdcEquipmentMagnificationDto.getTheDate()) && mdcEquipmentMagnificationDto.getEquipmentId().equals(equipmentId)) {
                    result.setEquipmentId(equipmentId);
                    result.setSpindlebeilv(mdcEquipmentMagnificationDto.getSpindlebeilv());
                    result.setFeedbeilv(mdcEquipmentMagnificationDto.getFeedbeilv());
                    result.setTheDate(date);
                }
            }
        } else {