生产线班次分时统计

tags/yfai-mes-ext-v1.0
王杰 2 years ago
parent 35ffbaaa1c
commit 94616b4a08

@ -61,9 +61,9 @@ public interface IJxTimeSegmentStatisticsService {
MesTimeSegmentStatistics checkTimeCompareToDataList(List<MesTimeSegmentStatistics> timeSegmentStatisticsList, MesTimeSegmentStatistics timeSegmentStatistics); MesTimeSegmentStatistics checkTimeCompareToDataList(List<MesTimeSegmentStatistics> timeSegmentStatisticsList, MesTimeSegmentStatistics timeSegmentStatistics);
/** /**
* *
*/ */
String getTimeLength(String startTime, String endTime, String today); Boolean checkTimeLengthIsValid(MesTimeSegmentStatistics timeSegmentStatistics, String today);
/** /**
* *

@ -51,7 +51,6 @@ public class JxTimeSegmentStatisticsService implements IJxTimeSegmentStatisticsS
public void insertTimeSegmentStatistics(MesTimeSegmentStatistics timeSegmentStatistics){ public void insertTimeSegmentStatistics(MesTimeSegmentStatistics timeSegmentStatistics){
List<MesTimeSegmentStatistics> timeSegmentStatisticsList = getTimeSegmentStatisticsList(timeSegmentStatistics.getOrganizeCode(), timeSegmentStatistics.getWorkCenterCode(), timeSegmentStatistics.getShiftCode()); List<MesTimeSegmentStatistics> timeSegmentStatisticsList = getTimeSegmentStatisticsList(timeSegmentStatistics.getOrganizeCode(), timeSegmentStatistics.getWorkCenterCode(), timeSegmentStatistics.getShiftCode());
checkTimeIsValid(timeSegmentStatisticsList, timeSegmentStatistics); checkTimeIsValid(timeSegmentStatisticsList, timeSegmentStatistics);
timeSegmentStatistics.setTimeLength(getTimeLength(timeSegmentStatistics.getStartTime(), timeSegmentStatistics.getEndTime(), TimeTool.getToday()));
timeSegmentStatistics.setTimeSegmentCode(getTimeSegmentCode(timeSegmentStatistics)); timeSegmentStatistics.setTimeSegmentCode(getTimeSegmentCode(timeSegmentStatistics));
timeSegmentStatistics.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue()); timeSegmentStatistics.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
ConvertBean.serviceModelInitialize(timeSegmentStatistics, timeSegmentStatistics.getCreateUser()); ConvertBean.serviceModelInitialize(timeSegmentStatistics, timeSegmentStatistics.getCreateUser());
@ -75,44 +74,23 @@ public class JxTimeSegmentStatisticsService implements IJxTimeSegmentStatisticsS
timeSegmentStatisticsDb.setShiftCode(timeSegmentStatistics.getShiftCode()); timeSegmentStatisticsDb.setShiftCode(timeSegmentStatistics.getShiftCode());
timeSegmentStatisticsDb.setStartTime(timeSegmentStatistics.getStartTime()); timeSegmentStatisticsDb.setStartTime(timeSegmentStatistics.getStartTime());
timeSegmentStatisticsDb.setEndTime(timeSegmentStatistics.getEndTime()); timeSegmentStatisticsDb.setEndTime(timeSegmentStatistics.getEndTime());
timeSegmentStatisticsDb.setTimeLength(getTimeLength(timeSegmentStatisticsDb.getStartTime(), timeSegmentStatisticsDb.getEndTime(), TimeTool.getToday())); timeSegmentStatisticsDb.setTimeLength(timeSegmentStatistics.getTimeLength());
timeSegmentStatisticsDb.setTimeSegmentCode(getTimeSegmentCode(timeSegmentStatisticsDb)); timeSegmentStatisticsDb.setTimeSegmentCode(getTimeSegmentCode(timeSegmentStatisticsDb));
timeSegmentStatisticsDb.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue()); timeSegmentStatisticsDb.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
ConvertBean.serviceModelUpdate(timeSegmentStatisticsDb, timeSegmentStatistics.getModifyUser()); ConvertBean.serviceModelUpdate(timeSegmentStatisticsDb, timeSegmentStatistics.getModifyUser());
timeSegmentStatisticsRepository.save(timeSegmentStatisticsDb); timeSegmentStatisticsRepository.save(timeSegmentStatisticsDb);
} }
private void checkTimeIsValid(List<MesTimeSegmentStatistics> timeSegmentStatisticsList, MesTimeSegmentStatistics timeSegmentStatistics) { @Override
if (!checkTimeFormat(timeSegmentStatistics.getStartTime())) public Boolean checkTimeLengthIsValid(MesTimeSegmentStatistics timeSegmentStatistics, String today) {
throw ImppExceptionBuilder.newInstance() Integer timeLengthMax = getTimeLength(timeSegmentStatistics.getStartTime(), timeSegmentStatistics.getEndTime(), today);
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) try {
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) if (!StringUtils.isEmpty(timeSegmentStatistics.getTimeLength()) && Integer.valueOf(timeSegmentStatistics.getTimeLength()).compareTo(timeLengthMax) > 0) return false;
.setErrorDetail("开始时间[%s]格式错误,请检查时间格式[%s]!", timeSegmentStatistics.getStartTime(), MesExtConstWords.TIME_TRUNCATE_SECOND_FORMAT) } catch (NumberFormatException e) {
.build(); return false;
if (!checkTimeFormat(timeSegmentStatistics.getEndTime())) }
throw ImppExceptionBuilder.newInstance() if (StringUtils.isEmpty(timeSegmentStatistics.getTimeLength())) timeSegmentStatistics.setTimeLength(timeLengthMax.toString());
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) return true;
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("结束时间[%s]格式错误,请检查时间格式[%s]!", timeSegmentStatistics.getEndTime(), MesExtConstWords.TIME_TRUNCATE_SECOND_FORMAT)
.build();
if (!checkTimeStartBeforeEnd(timeSegmentStatistics.getStartTime(), timeSegmentStatistics.getEndTime()))
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("开始时间[%s]必须小于结束时间[%s]!", timeSegmentStatistics.getStartTime(), timeSegmentStatistics.getEndTime())
.build();
String startTime = timeSegmentStatistics.getStartTime();
String endTime = timeSegmentStatistics.getEndTime();
timeSegmentStatistics.setStartTime(startTime + MesExtConstWords.APPEND_SECONDS);
timeSegmentStatistics.setEndTime(endTime + MesExtConstWords.APPEND_SECONDS);
MesTimeSegmentStatistics item = checkTimeCompareToDataList(timeSegmentStatisticsList, timeSegmentStatistics);
if (null != item)
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("开始时间[%s]结束时间[%s]与已维护的生产线[%s]班次代码[%s]配置的开始时间[%s]结束时间[%s]存在时间重叠!",
startTime, endTime, item.getWorkCenterCode(), item.getShiftCode(), item.getStartTime(), item.getEndTime())
.build();
} }
@Override @Override
@ -133,19 +111,6 @@ public class JxTimeSegmentStatisticsService implements IJxTimeSegmentStatisticsS
} }
@Override @Override
public String getTimeLength(String startTime, String endTime, String today) {
try {
return String.valueOf(TimeTool.getSecoundsBetweenTime(1, getTimeAppendToday(today, startTime), getTimeAppendToday(today, endTime)));
} catch (ParseException e) {
return null;
}
}
private String getTimeAppendToday(String today, String time) {
return new StringJoiner(MesExtConstWords.ONE_SPACE).add(today).add(time).toString();
}
@Override
public String getTimeSegmentCode(MesTimeSegmentStatistics timeSegmentStatistics) { public String getTimeSegmentCode(MesTimeSegmentStatistics timeSegmentStatistics) {
return new StringJoiner(MesExtConstWords.COLON).add(timeSegmentStatistics.getWorkCenterCode()).add(timeSegmentStatistics.getShiftCode()).add(timeSegmentStatistics.getStartTime().substring(0, 5)).toString().replaceAll(MesExtConstWords.COLON, MesExtConstWords.EMPTY); return new StringJoiner(MesExtConstWords.COLON).add(timeSegmentStatistics.getWorkCenterCode()).add(timeSegmentStatistics.getShiftCode()).add(timeSegmentStatistics.getStartTime().substring(0, 5)).toString().replaceAll(MesExtConstWords.COLON, MesExtConstWords.EMPTY);
} }
@ -159,6 +124,13 @@ public class JxTimeSegmentStatisticsService implements IJxTimeSegmentStatisticsS
@Override @Override
public void deleteByIds(Long[] ids, String userName) { updateStatusByIds(ids, userName, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), false); } public void deleteByIds(Long[] ids, String userName) { updateStatusByIds(ids, userName, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), false); }
@Override
public List<MesTimeSegmentStatistics> getTimeSegmentStatisticsList(String organizeCode, String workCenterCode, String shiftCode) {
return timeSegmentStatisticsRepository.findByProperty(
new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID, MesExtConstWords.WORK_CENTER_CODE, MesExtConstWords.SHIFT_CODE},
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workCenterCode, shiftCode});
}
private void updateStatusByIds(Long[] ids, String userName, int status, Boolean flag) { private void updateStatusByIds(Long[] ids, String userName, int status, Boolean flag) {
for (Long id : ids) { for (Long id : ids) {
MesTimeSegmentStatistics timeSegmentStatistics = timeSegmentStatisticsRepository.getById(id); MesTimeSegmentStatistics timeSegmentStatistics = timeSegmentStatisticsRepository.getById(id);
@ -173,11 +145,56 @@ public class JxTimeSegmentStatisticsService implements IJxTimeSegmentStatisticsS
} }
} }
@Override private void checkTimeIsValid(List<MesTimeSegmentStatistics> timeSegmentStatisticsList, MesTimeSegmentStatistics timeSegmentStatistics) {
public List<MesTimeSegmentStatistics> getTimeSegmentStatisticsList(String organizeCode, String workCenterCode, String shiftCode) { if (!checkTimeFormat(timeSegmentStatistics.getStartTime()))
return timeSegmentStatisticsRepository.findByProperty( throw ImppExceptionBuilder.newInstance()
new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID, MesExtConstWords.WORK_CENTER_CODE, MesExtConstWords.SHIFT_CODE}, .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), workCenterCode, shiftCode}); .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("开始时间[%s]格式错误,请检查时间格式[%s]!", timeSegmentStatistics.getStartTime(), MesExtConstWords.TIME_TRUNCATE_SECOND_FORMAT)
.build();
if (!checkTimeFormat(timeSegmentStatistics.getEndTime()))
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("结束时间[%s]格式错误,请检查时间格式[%s]!", timeSegmentStatistics.getEndTime(), MesExtConstWords.TIME_TRUNCATE_SECOND_FORMAT)
.build();
if (!checkTimeStartBeforeEnd(timeSegmentStatistics.getStartTime(), timeSegmentStatistics.getEndTime()))
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("开始时间[%s]必须小于结束时间[%s]!", timeSegmentStatistics.getStartTime(), timeSegmentStatistics.getEndTime())
.build();
String startTime = timeSegmentStatistics.getStartTime();
String endTime = timeSegmentStatistics.getEndTime();
timeSegmentStatistics.setStartTime(startTime + MesExtConstWords.APPEND_SECONDS);
timeSegmentStatistics.setEndTime(endTime + MesExtConstWords.APPEND_SECONDS);
MesTimeSegmentStatistics item = checkTimeCompareToDataList(timeSegmentStatisticsList, timeSegmentStatistics);
if (null != item)
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("开始时间[%s]结束时间[%s]与已维护的生产线[%s]班次代码[%s]配置的开始时间[%s]结束时间[%s]存在时间重叠!",
startTime, endTime, item.getWorkCenterCode(), item.getShiftCode(), item.getStartTime(), item.getEndTime())
.build();
if (!checkTimeLengthIsValid(timeSegmentStatistics, TimeTool.getToday()))
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("实际工作时间长度[%s]不能大于开始时间[%s]与结束时间[%s]的分钟差!", timeSegmentStatistics.getTimeLength(), timeSegmentStatistics.getStartTime(), timeSegmentStatistics.getEndTime())
.build();
}
private Integer getTimeLength(String startTime, String endTime, String today) {
try {
return TimeTool.getSecoundsBetweenTime(2, getTimeAppendToday(today, startTime), getTimeAppendToday(today, endTime));
} catch (ParseException e) {
return 0;
}
}
private String getTimeAppendToday(String today, String time) {
return new StringJoiner(MesExtConstWords.ONE_SPACE).add(today).add(time).toString();
} }
} }

@ -10,6 +10,7 @@ import cn.estsh.i3plus.ext.mes.pojo.repository.MesTimeSegmentStatisticsRepositor
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords; import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil; import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.mes.apiservice.util.MesCommonUtil; import cn.estsh.i3plus.mes.apiservice.util.MesCommonUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.TimeTool; import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.repository.MesWorkCenterRepository; import cn.estsh.i3plus.pojo.mes.repository.MesWorkCenterRepository;
@ -104,6 +105,8 @@ public class JxTimeSegmentStatisticsExcelService implements IExcelImportExtServi
workCenterCodeEntityMap = null; workCenterCodeEntityMap = null;
} }
String today = TimeTool.getToday();
//从excel表的第5行数据开始导入getFirstRowNum是从0行开始读取 //从excel表的第5行数据开始导入getFirstRowNum是从0行开始读取
for (int i = (sheetAt.getFirstRowNum() + 4); i < totalNumberOfRows; i ++) { for (int i = (sheetAt.getFirstRowNum() + 4); i < totalNumberOfRows; i ++) {
Row row = sheetAt.getRow(i); Row row = sheetAt.getRow(i);
@ -145,6 +148,12 @@ public class JxTimeSegmentStatisticsExcelService implements IExcelImportExtServi
} catch (Exception e) { } catch (Exception e) {
} }
String timeLength = null;
try {
timeLength = new DataFormatter().formatCellValue(row.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK));
} catch (Exception e) {
}
if (CollectionUtils.isEmpty(workCenterCodeEntityMap) || !workCenterCodeEntityMap.containsKey(workCenterCode)) { if (CollectionUtils.isEmpty(workCenterCodeEntityMap) || !workCenterCodeEntityMap.containsKey(workCenterCode)) {
errorNum ++; errorNum ++;
cellNum += "A;"; cellNum += "A;";
@ -184,17 +193,35 @@ public class JxTimeSegmentStatisticsExcelService implements IExcelImportExtServi
errorInfo += "第C+D列数据错误,开始时间必须小于结束时间;"; errorInfo += "第C+D列数据错误,开始时间必须小于结束时间;";
} }
if (!StringUtils.isEmpty(timeLength)) {
try {
Integer.valueOf(timeLength);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
if (errorNum == 0) { if (errorNum == 0) {
String key = new StringJoiner(MesExtConstWords.AND).add(workCenterCode).add(shiftCode).toString();
MesTimeSegmentStatistics timeSegmentStatistics = new MesTimeSegmentStatistics(); MesTimeSegmentStatistics timeSegmentStatistics = new MesTimeSegmentStatistics();
timeSegmentStatistics.setStartTime(startTime + MesExtConstWords.APPEND_SECONDS);
timeSegmentStatistics.setEndTime(endTime + MesExtConstWords.APPEND_SECONDS);
timeSegmentStatistics.setTimeLength(timeLength);
Boolean boo = timeSegmentStatisticsService.checkTimeLengthIsValid(timeSegmentStatistics, today);
if (!boo) {
errorNum ++;
cellNum += "E;";
errorInfo += "第E列数据错误,不能大于开始时间与结束时间的分钟差;";
}
if (!boo) break;
timeSegmentStatistics.setOrganizeCode(organizeCode); timeSegmentStatistics.setOrganizeCode(organizeCode);
timeSegmentStatistics.setWorkCenterCode(workCenterCode); timeSegmentStatistics.setWorkCenterCode(workCenterCode);
timeSegmentStatistics.setShiftCode(shiftCode); timeSegmentStatistics.setShiftCode(shiftCode);
timeSegmentStatistics.setStartTime(startTime + MesExtConstWords.APPEND_SECONDS);
timeSegmentStatistics.setEndTime(endTime + MesExtConstWords.APPEND_SECONDS);
timeSegmentStatistics.setOrderByParam(String.valueOf(rowNum)); timeSegmentStatistics.setOrderByParam(String.valueOf(rowNum));
String key = new StringJoiner(MesExtConstWords.AND).add(workCenterCode).add(shiftCode).toString();
MesTimeSegmentStatistics item = timeSegmentStatisticsService.checkTimeCompareToDataList(CollectionUtils.isEmpty(dataDbMap) ? null : dataDbMap.get(key), timeSegmentStatistics); MesTimeSegmentStatistics item = timeSegmentStatisticsService.checkTimeCompareToDataList(CollectionUtils.isEmpty(dataDbMap) ? null : dataDbMap.get(key), timeSegmentStatistics);
if (null != item) { if (null != item) {
errorNum ++; errorNum ++;
@ -248,18 +275,10 @@ public class JxTimeSegmentStatisticsExcelService implements IExcelImportExtServi
if (null != excelImportResultExtModel) { if (null != excelImportResultExtModel) {
List<MesTimeSegmentStatistics> excelList = excelImportResultExtModel.getExcelList(); List<MesTimeSegmentStatistics> excelList = excelImportResultExtModel.getExcelList();
if (!CollectionUtils.isEmpty(excelList)) { if (!CollectionUtils.isEmpty(excelList)) {
String time = TimeTool.getNowTime(true);
String today = time.substring(0, 10);
for (MesTimeSegmentStatistics timeSegmentStatistics : excelList) { for (MesTimeSegmentStatistics timeSegmentStatistics : excelList) {
timeSegmentStatistics.setTimeLength(timeSegmentStatisticsService.getTimeLength(timeSegmentStatistics.getStartTime(), timeSegmentStatistics.getEndTime(), today)); timeSegmentStatistics.setTimeSegmentCode(timeSegmentStatisticsService.getTimeSegmentCode(timeSegmentStatistics));
timeSegmentStatistics.setWorkCenterCode(timeSegmentStatisticsService.getTimeSegmentCode(timeSegmentStatistics));
timeSegmentStatistics.setCreateDatetime(time);
timeSegmentStatistics.setModifyDatetime(time);
timeSegmentStatistics.setCreateUser(userName);
timeSegmentStatistics.setModifyUser(userName);
timeSegmentStatistics.setIsValid(CommonEnumUtil.IS_VAILD.VAILD.getValue());
timeSegmentStatistics.setIsDeleted(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
timeSegmentStatistics.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue()); timeSegmentStatistics.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
ConvertBean.serviceModelInitialize(timeSegmentStatistics, userName);
timeSegmentStatisticsRepository.insert(timeSegmentStatistics); timeSegmentStatisticsRepository.insert(timeSegmentStatistics);
} }
} }

Loading…
Cancel
Save