forked from I3-YF/i3plus-mes-pcn-yfai
漏信号 优化
parent
bb2a3f1092
commit
49549429cb
@ -0,0 +1,17 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.dao;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesEquipVariableCollectContext;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentVariable;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IMesEquipmentLogDao {
|
||||||
|
|
||||||
|
@ApiOperation(value = "根据设备ID, 变量类型查询设备日志表")
|
||||||
|
List<MesEquipVariableCollectContext> queryMesEquipmentLog(List<MesEquipmentVariable> equipmentVariableList, String organizeCode, Integer equipId, Integer variableType);
|
||||||
|
|
||||||
|
@ApiOperation(value = "根据设备ID, 设备LOG表ID集合修改设备日志表的数据状态")
|
||||||
|
void updateEquipVariableStatus(String organizeCode, Integer equipId, List<Long> equipmentLogIdList, Integer equipVariableStatus);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.daoimpl;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.dao.IMesEquipmentLogDao;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesEquipVariableCollectContext;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
||||||
|
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentVariable;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description : MES物料信息Dao
|
||||||
|
* @Reference :
|
||||||
|
* @Author : xiangming.liao
|
||||||
|
* @CreateDate : 2020-02-21
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class MesEquipmentLogDao implements IMesEquipmentLogDao {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MesEquipVariableCollectContext> queryMesEquipmentLog(List<MesEquipmentVariable> equipmentVariableList, String organizeCode, Integer equipId, Integer variableType) {
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(equipmentVariableList) || StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(equipId) || StringUtils.isEmpty(variableType)) return null;
|
||||||
|
|
||||||
|
StringBuffer builder = new StringBuffer();
|
||||||
|
|
||||||
|
builder.append(" select e.equip_variable_id, e.equip_variable_value, e.equip_variable_status, e.quality, e.modify_date_time, e.id ");
|
||||||
|
builder.append(" from mes_equipment_log_");
|
||||||
|
builder.append(equipId);
|
||||||
|
builder.append(" e where e.organize_code = :organizeCode and e.variable_type = :variableType ");
|
||||||
|
|
||||||
|
Query query = entityManager.createNativeQuery(builder.toString());
|
||||||
|
query.setParameter(MesPcnExtConstWords.ORGANIZE_CODE, organizeCode);
|
||||||
|
query.setParameter(MesPcnExtConstWords.VARIABLE_TYPE, variableType);
|
||||||
|
List list = query.getResultList();
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(list)) return null;
|
||||||
|
|
||||||
|
List<Long> equipVariableIdList = equipmentVariableList.stream().filter(o -> null != o).map(MesEquipmentVariable::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<MesEquipVariableCollectContext> equipVariableCollectContextList = generateEquipVariableCollectContextList(equipmentVariableList);
|
||||||
|
|
||||||
|
for (Object equipmentLog : list) {
|
||||||
|
|
||||||
|
if (null == equipmentLog) continue;
|
||||||
|
|
||||||
|
Object[] equipmentLogArr = (Object[]) equipmentLog;
|
||||||
|
|
||||||
|
if (null == equipmentLogArr || equipmentLogArr.length != 6 || equipVariableIdList.contains(equipmentLogArr[0])) continue;
|
||||||
|
|
||||||
|
equipVariableCollectContextList.stream().filter(o -> (null != o && o.getEquipVariableId().compareTo((Long) equipmentLogArr[0]) == 0)).findFirst().get().copyValue(equipmentLogArr[1], equipmentLogArr[2], equipmentLogArr[3], equipmentLogArr[4], equipmentLogArr[5]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return equipVariableCollectContextList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEquipVariableStatus(String organizeCode, Integer equipId, List<Long> equipmentLogIdList, Integer equipVariableStatus) {
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(equipId) || CollectionUtils.isEmpty(equipmentLogIdList)) return;
|
||||||
|
|
||||||
|
StringBuffer builder = new StringBuffer();
|
||||||
|
|
||||||
|
for (int i = 0; i < equipmentLogIdList.size(); i ++) {
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(equipmentLogIdList.get(i))) continue;
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(builder)) builder.append(MesPcnExtConstWords.SEMICOLON);
|
||||||
|
builder.append(" update mes_equipment_log_");
|
||||||
|
builder.append(equipId);
|
||||||
|
builder.append(" set equip_variable_status = :equipVariableStatus where id = :id_");
|
||||||
|
builder.append(i);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Query update = entityManager.createNativeQuery(builder.toString());
|
||||||
|
|
||||||
|
for (int i = 0; i < equipmentLogIdList.size(); i ++) {
|
||||||
|
if (StringUtils.isEmpty(equipmentLogIdList.get(i))) continue;
|
||||||
|
update.setParameter(String.format("id_%s", i), equipVariableStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
update.executeUpdate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MesEquipVariableCollectContext> generateEquipVariableCollectContextList(List<MesEquipmentVariable> equipmentVariableList) {
|
||||||
|
List<MesEquipVariableCollectContext> equipVariableCollectContextList = new ArrayList<>();
|
||||||
|
equipmentVariableList.stream().filter(o -> null != o).forEach(o -> {
|
||||||
|
MesEquipVariableCollectContext equipVariableCollectContext = new MesEquipVariableCollectContext(o.getId());
|
||||||
|
BeanUtils.copyProperties(o, equipVariableCollectContext);
|
||||||
|
equipVariableCollectContextList.add(equipVariableCollectContext);
|
||||||
|
});
|
||||||
|
return equipVariableCollectContextList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue