|
|
|
@ -0,0 +1,92 @@
|
|
|
|
|
import cn.estsh.i3plus.platform.plugin.datasource.DynamicDataSourceProxy
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.dbinterface.MesInterfaceDataMapper
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesWorkOrderToSapRepository
|
|
|
|
|
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 javax.annotation.Resource
|
|
|
|
|
import java.sql.Connection
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description : MES发送SAP生产工单数据
|
|
|
|
|
* @Reference :
|
|
|
|
|
* @Author : junsheng.li
|
|
|
|
|
* @CreateDate 2024/5/12 15:43
|
|
|
|
|
* @Modify:
|
|
|
|
|
* */
|
|
|
|
|
class mesWorkOrderToSap {
|
|
|
|
|
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(mesWorkOrderToSap.class)
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesWorkOrderToSapRepository mesWorkOrderToSapRDao;
|
|
|
|
|
|
|
|
|
|
@Resource(name = "yfasDataSource")
|
|
|
|
|
private DynamicDataSourceProxy yfasDataSource;
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
}
|
|
|
|
|
Map<String,Map<String, Object>> destMapData = new HashMap<>();
|
|
|
|
|
LOGGER.info("-------- filterData Start MES发送SAP生产工单数据 ---------------")
|
|
|
|
|
List<String> updateSqlList = new ArrayList<>();
|
|
|
|
|
//过滤相同物料,结束时间的数据
|
|
|
|
|
for (Map<String, Object> rowMap : srcData) {
|
|
|
|
|
String partNo = String.valueOf(rowMap.get("plmat"));
|
|
|
|
|
String organizeCode = String.valueOf(rowMap.get("organize_code"));
|
|
|
|
|
String endData = String.valueOf(rowMap.get("pedtr"));
|
|
|
|
|
String key = organizeCode+partNo+endData;
|
|
|
|
|
if(!destMapData.containsKey(key)){
|
|
|
|
|
destMapData.put(key,rowMap)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//汇总
|
|
|
|
|
List<Map<String, Object>> destData = new ArrayList<>();
|
|
|
|
|
for (Map<String, Object> rowMap : destMapData.values()) {
|
|
|
|
|
String partNo = String.valueOf(rowMap.get("plmat"));
|
|
|
|
|
String organizeCode = String.valueOf(rowMap.get("organize_code"));
|
|
|
|
|
String endData = String.valueOf(rowMap.get("pedtr"));
|
|
|
|
|
String qty = String.valueOf(rowMap.get("gsmng"));
|
|
|
|
|
Map<String, Object> sqlParams = new HashMap<>(4)
|
|
|
|
|
sqlParams.put("organizeCode",organizeCode);
|
|
|
|
|
sqlParams.put("plmat", partNo);
|
|
|
|
|
sqlParams.put("pedtr", endData);
|
|
|
|
|
sqlParams.put("gsmng", qty);
|
|
|
|
|
StringBuffer sql = new StringBuffer("select * from mes_plan_order where " +
|
|
|
|
|
" PLWRK=:organizeCode and plmat=:plmat and pedtr=:pedtr and gsmng = :gsmng");
|
|
|
|
|
List<Map<String, Object>> resultMap = this.queryDataTable(sql.toString(), sqlParams)
|
|
|
|
|
if (resultMap.size() > 0) {
|
|
|
|
|
LOGGER.info("--------mesWorkOrderToSapRDao.updateByHqlWhere ---------------")
|
|
|
|
|
updateSqlList.add("update mes_work_order_to_sap set system_sync_status = 1, " +
|
|
|
|
|
"modify_user = 'MES发送SAP生产工单' where organize_code= '"+organizeCode+"' and plmat= '"+partNo+"' and pedtr='"+endData+"'");
|
|
|
|
|
}else{
|
|
|
|
|
destData.add(rowMap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//更新同步标识
|
|
|
|
|
this.mesConn = mesDataSource.getWriteConnectionWithoutPool();
|
|
|
|
|
mesDataSource.executeAsBatch(updateSqlList,mesConn)
|
|
|
|
|
mesDataSource.closeConnectionWithoutPoll(this.mesConn)
|
|
|
|
|
return destData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Map<String, Object>> queryDataTable(String sql, Map<String, Object> params) {
|
|
|
|
|
NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(yfasDataSource.getDataSource())
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> dataMap = namedJdbcTemplate.queryForList(sql, params)
|
|
|
|
|
|
|
|
|
|
return dataMap;
|
|
|
|
|
}
|
|
|
|
|
}
|