|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import cn.estsh.i3plus.platform.plugin.datasource.DynamicDataSourceProxy
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesEquipment
|
|
|
|
@ -7,9 +8,16 @@ import cn.estsh.i3plus.pojo.mes.dbinterface.MesInterfaceDataMapper
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentRepository
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesProduceSnRepository
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesWorkOrderRepository
|
|
|
|
|
import lombok.Getter
|
|
|
|
|
import lombok.Setter
|
|
|
|
|
import org.slf4j.Logger
|
|
|
|
|
import org.slf4j.LoggerFactory
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
|
|
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
|
|
|
|
|
import org.springframework.util.CollectionUtils
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource
|
|
|
|
|
import java.sql.Connection
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description : 加工记录同步 MES2PISCES
|
|
|
|
@ -31,19 +39,35 @@ class MesProductionRecordToPisces {
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesWorkOrderRepository workOrderRepository;
|
|
|
|
|
|
|
|
|
|
@Resource(name = "piscesDataSource")
|
|
|
|
|
private DynamicDataSourceProxy piscesDataSource;
|
|
|
|
|
|
|
|
|
|
@Resource(name = "mesDataSource")
|
|
|
|
|
private DynamicDataSourceProxy mesDataSource;
|
|
|
|
|
|
|
|
|
|
@Getter
|
|
|
|
|
@Setter
|
|
|
|
|
private Connection mesConn;
|
|
|
|
|
|
|
|
|
|
def filterData(MesInterfaceDataMapper mapper, List<Map<String, Object>> srcData) throws Exception {
|
|
|
|
|
if (srcData == null || srcData.size() == 0) {
|
|
|
|
|
return srcData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> updateList = new ArrayList<>();
|
|
|
|
|
List<Map<String, Object>> destData = new ArrayList<>();
|
|
|
|
|
for (Map<String, Object> rowMap : srcData) {
|
|
|
|
|
|
|
|
|
|
String productSn = String.valueOf(rowMap.get("product_sn"));
|
|
|
|
|
String partNo = String.valueOf(rowMap.get("part_no"));
|
|
|
|
|
|
|
|
|
|
MesProduceSn produceSnDb = getProduceSnDb(mapper.getOrganizeCode(), productSn, partNo);
|
|
|
|
|
if (!Objects.isNull(produceSnDb)) {
|
|
|
|
|
rowMap.put("BARCODE_ID", produceSnDb.getId())
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
|
|
params.put("partNo",rowMap.get("part_no"))
|
|
|
|
|
params.put("productSn",rowMap.get("product_sn"))
|
|
|
|
|
String sql = "select ID from MES.TT_PC_PART_BARCODE where PART_NO = :partNo and BARCODE = :productSn order by GENERATION_TIME desc";
|
|
|
|
|
List<Map<String, Object>> dataMap = queryDataTable(sql,params);
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(dataMap) && dataMap.size() >0) {
|
|
|
|
|
rowMap.put("BARCODE_ID", dataMap.iterator().next().get("ID"))
|
|
|
|
|
updateList.add("update mes_production_record set system_sync_status = 1 where id= "+rowMap.get("id")+" ;")
|
|
|
|
|
}else{
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String workOrderNo = String.valueOf(rowMap.get("work_order_no"));
|
|
|
|
@ -57,10 +81,17 @@ class MesProductionRecordToPisces {
|
|
|
|
|
if (!Objects.isNull(equipmentDb)) {
|
|
|
|
|
rowMap.put("EQUIPMENT_ID", equipmentDb.getEquipId())
|
|
|
|
|
}
|
|
|
|
|
destData.add(rowMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新同步标识
|
|
|
|
|
if(!CollectionUtils.isEmpty(updateList) && updateList.size() > 0){
|
|
|
|
|
this.mesConn = mesDataSource.getWriteConnectionWithoutPool();
|
|
|
|
|
mesDataSource.executeAsBatch(updateList,mesConn)
|
|
|
|
|
mesDataSource.closeConnectionWithoutPoll(this.mesConn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return srcData;
|
|
|
|
|
return destData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getProduceSnDb(String organizeCode, String productSn, String partNo) {
|
|
|
|
@ -85,4 +116,10 @@ class MesProductionRecordToPisces {
|
|
|
|
|
return equipmentDb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Map<String, Object>> queryDataTable(String sql, Map<String, Object> params) {
|
|
|
|
|
NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(piscesDataSource.getDataSource())
|
|
|
|
|
List<Map<String, Object>> dataMap = namedJdbcTemplate.queryForList(sql, params)
|
|
|
|
|
return dataMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|