46281 PCN-按工位统计产量信息

uat-temp-wj-chongqingdaqu-prod-temp-control-order-qty
王杰 3 months ago
parent bb93d155e3
commit ea0d8b0188

@ -35,6 +35,9 @@ public interface IMesProdShiftRecordService {
@ApiOperation(value = "查询最新的开班记录")
MesProdShiftRecord getProdShiftRecordOpenStatus(String organizeCode, String workCenterCode);
@ApiOperation(value = "查询最新的开班记录")
MesProdShiftRecord getProdShiftRecordCdtDesc(String organizeCode, String workCenterCode);
@ApiOperation(value = "封装展示组件班组班次内容")
List<StationKvBean> getProdShiftData(MesProdShiftRecord record);

@ -30,4 +30,10 @@ public interface IMesShiftService {
@ApiOperation(value = "根据当前时间计算实际整天班次的时间")
Map<String, String> calcAllDayShiftTimeMapByCurTime(String organizeCode, String workCenterCode);
@ApiOperation(value = "根据当前时间计算当前班次的时间")
Map<String, String> calcCurShiftTimeMapByCurTime(String organizeCode, String workCenterCode);
@ApiOperation(value = "计算天数")
String calcDay(String day, int amount);
}

@ -225,12 +225,17 @@ public class MesProdShiftRecordServiceImpl implements IMesProdShiftRecordService
@Override
public MesProdShiftRecord getProdShiftRecordOpenStatus(String organizeCode, String workCenterCode) {
MesProdShiftRecord prodShiftRecord = getProdShiftRecordCdtDesc(organizeCode, workCenterCode);
if (prodShiftRecord != null && !StringUtils.isEmpty(prodShiftRecord.getWorkStatus()) && prodShiftRecord.getWorkStatus().compareTo(MesExtEnumUtil.WORK_STATUS.START.getValue()) == 0) return prodShiftRecord;
return null;
}
@Override
public MesProdShiftRecord getProdShiftRecordCdtDesc(String organizeCode, String workCenterCode) {
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(workCenterCode, "workCenterCode", packBean);
DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{MesPcnExtConstWords.CREATE_DATE_TIME}, packBean);
MesProdShiftRecord prodShiftRecord = mesProdShiftRecordRDao.getByProperty(packBean);
if (prodShiftRecord != null && !StringUtils.isEmpty(prodShiftRecord.getWorkStatus()) && prodShiftRecord.getWorkStatus().compareTo(MesExtEnumUtil.WORK_STATUS.START.getValue()) == 0) return prodShiftRecord;
return null;
return mesProdShiftRecordRDao.getByProperty(packBean);
}
//封装展示组件班组班次内容

@ -106,7 +106,8 @@ public class MesShiftServiceImpl implements IMesShiftService {
}
//计算天数
private String calcDay(String day, int amount) {
@Override
public String calcDay(String day, int amount) {
try {
DateFormat sdf = new SimpleDateFormat(MesPcnExtConstWords.DATE_FORMAT_SEPARATOR);
return TimeTool.timeCalc(sdf.parse(day), Calendar.DATE, amount, MesPcnExtConstWords.DATE_FORMAT_SEPARATOR);
@ -147,4 +148,32 @@ public class MesShiftServiceImpl implements IMesShiftService {
return shiftTimeMap;
}
//根据当前时间计算当前班次的时间
@Override
public Map<String, String> calcCurShiftTimeMapByCurTime(String organizeCode, String workCenterCode) {
//根据生产线查询关联的班次集合, 根据班次代码正序
List<MesShift> shiftList = queryMesShift(organizeCode, workCenterCode);
if (CollectionUtils.isEmpty(shiftList)) return null;
String nowTime = TimeTool.getNowTime(true);
String today = nowTime.substring(0, 10);
String time = nowTime.substring(11);
Optional<MesShift> shiftOptional = shiftList.stream().filter(o -> (null != o
&& !StringUtils.isEmpty(o.getStartTime()) && !StringUtils.isEmpty(o.getEndTime()) && o.getStartTime().compareTo(time) <= 0 && o.getEndTime().compareTo(time) >= 0)).findFirst();
if (null == shiftOptional || !shiftOptional.isPresent()) return null;
//当天早班的开始时间
String todayStartTime = today + MesPcnExtConstWords.ONE_SPACE + shiftList.get(0).getStartTime();
//实际开班时间 比 当天早班的开始时间 小的情况下, 代表的是前一天的班次
if (nowTime.compareTo(todayStartTime) < 0) {
String yesterday = calcDay(today, -1);
return calcShiftTime(shiftOptional.get().getStartTime(), shiftOptional.get().getEndTime(), yesterday);
} else {
//当天的班次
return calcShiftTime(shiftOptional.get().getStartTime(), shiftOptional.get().getEndTime(), today);
}
}
}

@ -0,0 +1,190 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.station.function;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesProdShiftRecordService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesShiftService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionCustomContextStepService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesProductionPartSheetModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseSwsService;
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.function.IFsmModuleFunctionService;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
import cn.estsh.i3plus.pojo.mes.model.ButtonDynamicModel;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
import cn.estsh.i3plus.pojo.mes.repository.MesProductionRecordRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description : Sheet
**/
@Service
public class MesFunctionProductionPartSheetService extends BaseSwsService implements IFsmModuleFunctionService {
@Autowired
private IMesProductionCustomContextStepService productionCustomContextStepService;
@Autowired
private IMesShiftService shiftService;
@Autowired
private IMesProdShiftRecordService prodShiftRecordService;
@Autowired
private MesProductionRecordRepository productionRecordRepository;
@Override
public Object doCustomApiDispatch(StationRequestBean reqBean, StationResultBean resultBean, ButtonDynamicModel buttonDynamicModel) {
//页面渲染数据集
Map<String, Object> resultMap = new HashMap<>();
//验证参数
Map<String, String> paramMap = null;
try {
paramMap = StringUtils.isEmpty(buttonDynamicModel.getFunctionValue()) ? null : JSONObject.parseObject(buttonDynamicModel.getFunctionValue(), Map.class);
} catch (Exception e) {
}
String startTime = !CollectionUtils.isEmpty(paramMap) && !StringUtils.isEmpty(paramMap.get(MesPcnExtConstWords.START_TIME)) ? paramMap.get(MesPcnExtConstWords.START_TIME) : null;
String endTime = !CollectionUtils.isEmpty(paramMap) && !StringUtils.isEmpty(paramMap.get(MesPcnExtConstWords.END_TIME)) ? paramMap.get(MesPcnExtConstWords.END_TIME) : null;
if (StringUtils.isEmpty(startTime) || StringUtils.isEmpty(endTime)) {
//根据当前时间计算当前班次的时间
Map<String, String> shiftTimeMap = shiftService.calcCurShiftTimeMapByCurTime(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode());
if (!CollectionUtils.isEmpty(shiftTimeMap)) {
startTime = shiftTimeMap.get(MesPcnExtConstWords.START_TIME);
endTime = shiftTimeMap.get(MesPcnExtConstWords.END_TIME);
} else {
String today = TimeTool.getToday();
startTime = today + MesPcnExtConstWords.DATE_FORMAT_APPEND_0;
endTime = shiftService.calcDay(today, 1) + MesPcnExtConstWords.DATE_FORMAT_APPEND_0;
}
//返回客户端作为默认条件
resultMap.put(MesPcnExtConstWords.START_TIME, startTime);
resultMap.put(MesPcnExtConstWords.END_TIME, endTime);
}
Boolean checkTime;
try {
checkTime = TimeTool.getSecoundsBetweenTime(1, startTime, endTime) <= 86400;
} catch (ParseException e) {
checkTime = false;
}
if (!checkTime) return packResultMap(resultMap, "时间查询条件限制一天!");
//返回客户端作为查询条件
Map<Integer, String> reportStatusMap = new HashMap<>();
reportStatusMap.put(REPORT_STATUS.REPORT.getValue(), REPORT_STATUS.REPORT.getDescription());
reportStatusMap.put(REPORT_STATUS.UN_REPORT.getValue(), REPORT_STATUS.UN_REPORT.getDescription());
resultMap.put(MesPcnExtConstWords.REPORT_STATUS, reportStatusMap);
String partNo = !CollectionUtils.isEmpty(paramMap) && !StringUtils.isEmpty(paramMap.get(MesPcnExtConstWords.PART_NO)) ? paramMap.get(MesPcnExtConstWords.PART_NO) : null;
//查询加工记录数据
DdlPackBean packBean = DdlPackBean.getDdlPackBean(reqBean.getOrganizeCode());
DdlPreparedPack.timeBuilder(startTime, endTime, MesPcnExtConstWords.COMPLETE_DATE_TIME, packBean, false);
DdlPreparedPack.getStringEqualPack(reqBean.getWorkCenterCode(), MesPcnExtConstWords.WORK_CENTER_CODE, packBean);
DdlPreparedPack.getStringEqualPack(reqBean.getWorkCellCode(), MesPcnExtConstWords.WORK_CELL_CODE, packBean);
DdlPreparedPack.getStringEqualPack(partNo, MesPcnExtConstWords.PART_NO, packBean);
List<MesProductionRecord> productionRecordList = productionRecordRepository.findByHqlWhere(packBean);
if (CollectionUtils.isEmpty(productionRecordList)) return resultMap;
Integer reportStatus = !CollectionUtils.isEmpty(paramMap) && !StringUtils.isEmpty(paramMap.get(MesPcnExtConstWords.REPORT_STATUS)) ? Integer.valueOf(paramMap.get(MesPcnExtConstWords.REPORT_STATUS)) : null;
//搜集需要汇报的加工记录
List<MesProductionRecord> productionRecordList2Report = (StringUtils.isEmpty(reportStatus) || reportStatus.compareTo(REPORT_STATUS.REPORT.getValue()) == 0)
? productionRecordList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPartNo()) && o.getReportStatus().compareTo(MesExtEnumUtil.REPORT_STATUS.REPORT_STATUS_30.getValue()) != 0)).collect(Collectors.toList()) : null;
//搜集无需汇报的加工记录
List<MesProductionRecord> productionRecordList2NoReport = (StringUtils.isEmpty(reportStatus) || reportStatus.compareTo(REPORT_STATUS.UN_REPORT.getValue()) == 0)
? productionRecordList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPartNo()) && o.getReportStatus().compareTo(MesExtEnumUtil.REPORT_STATUS.REPORT_STATUS_30.getValue()) == 0)).collect(Collectors.toList()) : null;
List<MesProductionPartSheetModel> resultList = new ArrayList<>();
if (!CollectionUtils.isEmpty(productionRecordList2Report)) backResultList(resultList, productionRecordList2Report, REPORT_STATUS.REPORT);
if (!CollectionUtils.isEmpty(productionRecordList2NoReport)) backResultList(resultList, productionRecordList2NoReport, REPORT_STATUS.UN_REPORT);
if (!CollectionUtils.isEmpty(resultList)) {
resultList = resultList.stream().filter(o -> null != o).sorted(Comparator.comparing(MesProductionPartSheetModel::getPartNo).thenComparing(MesProductionPartSheetModel::getReportSatus)).collect(Collectors.toList());
resultMap.put(MesPcnExtConstWords.DATA, resultList);
}
return resultMap;
}
private void backResultList(List<MesProductionPartSheetModel> resultList, List<MesProductionRecord> productionRecordList, REPORT_STATUS reportStatus) {
Map<String, List<MesProductionRecord>> prMap = productionRecordList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesProductionRecord::getPartNo));
for (Map.Entry<String, List<MesProductionRecord>> entry : prMap.entrySet()) {
if (null == entry) continue;
MesProductionRecord item = entry.getValue().get(0);
MesProductionPartSheetModel result = new MesProductionPartSheetModel();
result.setWorkCenterCode(item.getWorkCenterCode());
result.setWorkCellCode(item.getWorkCellCode());
result.setPartNo(item.getPartNo());
result.setPartName(item.getPartName());
result.setQty(new Double(entry.getValue().size()));
result.setReportSatus(reportStatus.getValue());
result.setReportSatusName(reportStatus.getDescription());
resultList.add(result);
}
}
//返回提示信息
private Map<String, Object> packResultMap(Map<String, Object> resultMap, String message) {
resultMap.put(MesPcnExtConstWords.MESSAGE, message);
return resultMap;
}
//业务操作
enum REPORT_STATUS {
REPORT(20, "需要汇报"),
UN_REPORT(30, "无需汇报");
private int value;
private String description;
REPORT_STATUS(int value, String description) {
this.value = value;
this.description = description;
}
public int getValue() {
return value;
}
public String getDescription() {
return description;
}
public static String valueOfDescription(int val) {
if (StringUtils.isEmpty(val)) return null;
String tmp = null;
for (int i = 0; i < values().length; i++) {
if (val == values()[i].value) {
tmp = values()[i].description;
}
}
return tmp;
}
}
}

@ -0,0 +1,34 @@
package cn.estsh.i3plus.ext.mes.pcn.pojo.model;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import java.io.Serializable;
@Data
public class MesProductionPartSheetModel implements Serializable {
private static final long serialVersionUID = -1692026621022774956L;
@ApiParam("生产线代码")
private String workCenterCode;
@ApiParam("工位代码")
private String workCellCode;
@ApiParam("零件号")
private String partNo;
@ApiParam("零件名称")
private String partName;
@ApiParam("加工数量")
private Double qty;
@ApiParam("汇报状态(reportSatus!=30[需要汇报],reportSatus=30[无需汇报])")
private Integer reportSatus;
@ApiParam("汇报状态")
private String reportSatusName;
}
Loading…
Cancel
Save