7 changed files with 284 additions and 0 deletions
-
40src/main/java/com/spring/modules/part/dao/PartCatalogDao.java
-
55src/main/java/com/spring/modules/part/dao/impl/PartCatalogDaoImpl.java
-
81src/main/java/com/spring/modules/part/entity/IfsPartCatalog.java
-
18src/main/java/com/spring/modules/part/service/PartService.java
-
63src/main/java/com/spring/modules/part/service/impl/PartServiceImpl.java
-
26src/main/java/com/spring/modules/part/task/PartRelatedTask.java
-
1src/main/resources/application-dev.yml
@ -0,0 +1,40 @@ |
|||||
|
package com.spring.modules.part.dao; |
||||
|
|
||||
|
import com.spring.modules.part.entity.IfsPartCatalog; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @description: 物料件的dao |
||||
|
* @author LR |
||||
|
* @date 2024/9/23 10:21 |
||||
|
* @version 1.0 |
||||
|
*/ |
||||
|
public interface PartCatalogDao { |
||||
|
|
||||
|
/** |
||||
|
* @description: 查询最大的版本号 |
||||
|
* @author LR |
||||
|
* @date 2024/9/23 10:27 |
||||
|
* @version 1.0 |
||||
|
*/ |
||||
|
String getMaxIfsRowVersion(); |
||||
|
|
||||
|
/** |
||||
|
* @description: 清空缓存表 |
||||
|
* @author LR |
||||
|
* @date 2024/9/23 10:39 |
||||
|
* @version 1.0 |
||||
|
*/ |
||||
|
void truncatePartCatalogCacheTable(); |
||||
|
|
||||
|
/** |
||||
|
* @description: 批量保存到数据库 |
||||
|
* @author LR |
||||
|
* @date 2024/9/23 10:36 |
||||
|
* @version 1.0 |
||||
|
*/ |
||||
|
void batchInsertPartCatalogs(List<IfsPartCatalog> ifsPartCatalogs); |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,55 @@ |
|||||
|
package com.spring.modules.part.dao.impl; |
||||
|
|
||||
|
import com.spring.modules.part.dao.PartCatalogDao; |
||||
|
import com.spring.modules.part.entity.IfsPartCatalog; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; |
||||
|
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils; |
||||
|
import org.springframework.stereotype.Repository; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @description: 物料件的dao实现 |
||||
|
* @author LR |
||||
|
* @date 2024/9/23 10:22 |
||||
|
* @version 1.0 |
||||
|
*/ |
||||
|
@Repository |
||||
|
public class PartCatalogDaoImpl implements PartCatalogDao { |
||||
|
|
||||
|
@Autowired |
||||
|
private NamedParameterJdbcTemplate parameterJdbcTemplate; |
||||
|
|
||||
|
@Override |
||||
|
public String getMaxIfsRowVersion() { |
||||
|
StringBuilder sql = new StringBuilder(); |
||||
|
Map<String, Object> paramMap = new HashMap<String, Object>(); |
||||
|
sql.append("SELECT MAX(ifs_row_version) ifsRowVersion FROM part_catalog"); |
||||
|
//查询结果集 |
||||
|
List<String> resultList = parameterJdbcTemplate.query(sql.toString(), paramMap, (rs, rowNum) -> rs.getString("ifsRowVersion")); |
||||
|
//判断结果集 |
||||
|
if(resultList.size() > 0) { |
||||
|
return resultList.get(0); |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void truncatePartCatalogCacheTable() { |
||||
|
StringBuilder sql = new StringBuilder(); |
||||
|
Map<String, Object> paramMap = new HashMap<String, Object>(); |
||||
|
sql.append("TRUNCATE TABLE part_catalog_cache"); |
||||
|
parameterJdbcTemplate.update(sql.toString(), paramMap); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void batchInsertPartCatalogs(List<IfsPartCatalog> ifsPartCatalogs) { |
||||
|
StringBuilder sql = new StringBuilder(); |
||||
|
sql.append("INSERT INTO part_catalog_cache(part_no, part_desc, ifs_row_id, ifs_row_version, status)"); |
||||
|
sql.append(" VALUES(:partNo, :partDesc, :ifsRowId, :ifsRowVersion, :status)"); |
||||
|
parameterJdbcTemplate.batchUpdate(sql.toString(), SqlParameterSourceUtils.createBatch(ifsPartCatalogs.toArray())); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
package com.spring.modules.part.entity; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @ClassName: PartIfsCatalog |
||||
|
* @Description:物料目录 |
||||
|
* @author: LR |
||||
|
* @date: 2023年12月22日 上午10:14:06 |
||||
|
* @Copyright: |
||||
|
*/ |
||||
|
public class IfsPartCatalog { |
||||
|
private int id;// |
||||
|
private String contract;// |
||||
|
private String partNo;// |
||||
|
private String partDesc;// |
||||
|
private String ifsRowId; |
||||
|
private String ifsRowVersion; |
||||
|
private int status;// 状态 |
||||
|
|
||||
|
public IfsPartCatalog() { |
||||
|
super(); |
||||
|
} |
||||
|
|
||||
|
public int getId() { |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
public void setId(int id) { |
||||
|
this.id = id; |
||||
|
} |
||||
|
|
||||
|
public String getContract() { |
||||
|
return contract; |
||||
|
} |
||||
|
|
||||
|
public void setContract(String contract) { |
||||
|
this.contract = contract; |
||||
|
} |
||||
|
|
||||
|
public String getPartNo() { |
||||
|
return partNo; |
||||
|
} |
||||
|
|
||||
|
public void setPartNo(String partNo) { |
||||
|
this.partNo = partNo; |
||||
|
} |
||||
|
|
||||
|
public String getPartDesc() { |
||||
|
return partDesc; |
||||
|
} |
||||
|
|
||||
|
public void setPartDesc(String partDesc) { |
||||
|
this.partDesc = partDesc; |
||||
|
} |
||||
|
|
||||
|
public String getIfsRowId() { |
||||
|
return ifsRowId; |
||||
|
} |
||||
|
|
||||
|
public void setIfsRowId(String ifsRowId) { |
||||
|
this.ifsRowId = ifsRowId; |
||||
|
} |
||||
|
|
||||
|
public String getIfsRowVersion() { |
||||
|
return ifsRowVersion; |
||||
|
} |
||||
|
|
||||
|
public void setIfsRowVersion(String ifsRowVersion) { |
||||
|
this.ifsRowVersion = ifsRowVersion; |
||||
|
} |
||||
|
|
||||
|
public int getStatus() { |
||||
|
return status; |
||||
|
} |
||||
|
|
||||
|
public void setStatus(int status) { |
||||
|
this.status = status; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.spring.modules.part.service; |
||||
|
|
||||
|
/** |
||||
|
* @description: 物料件接口 |
||||
|
* @author LR |
||||
|
* @date 2024/9/23 10:13 |
||||
|
* @version 1.0 |
||||
|
*/ |
||||
|
public interface PartService { |
||||
|
|
||||
|
/** |
||||
|
* @description: 刷新物料件的方法 |
||||
|
* @author LR |
||||
|
* @date 2024/9/23 10:15 |
||||
|
* @version 1.0 |
||||
|
*/ |
||||
|
void syncPartCatalogToPlm(); |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
package com.spring.modules.part.service.impl; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.spring.modules.base.utils.HttpClientUtil; |
||||
|
import com.spring.modules.base.utils.ResponseData; |
||||
|
import com.spring.modules.part.dao.PartCatalogDao; |
||||
|
import com.spring.modules.part.entity.IfsPartCatalog; |
||||
|
import com.spring.modules.part.service.PartService; |
||||
|
import com.spring.modules.report.dao.ProcedureDao; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Service |
||||
|
public class PartServiceImpl implements PartService { |
||||
|
|
||||
|
@Autowired |
||||
|
private PartCatalogDao partCatalogDao; |
||||
|
@Autowired |
||||
|
private ProcedureDao procedureDao; |
||||
|
|
||||
|
@Value("${ifs-api.api-url}") |
||||
|
private String apiUrl; |
||||
|
|
||||
|
@Override |
||||
|
public void syncPartCatalogToPlm() { |
||||
|
//查询最大的版本号 |
||||
|
String ifsRowVersion = partCatalogDao.getMaxIfsRowVersion(); |
||||
|
IfsPartCatalog searchData = new IfsPartCatalog(); |
||||
|
searchData.setIfsRowVersion(ifsRowVersion); |
||||
|
|
||||
|
// 调用接口获得IFS数据 |
||||
|
String getIfsLocationsURL = apiUrl + "/base/ifs/getIfsPartCatalogs"; |
||||
|
ResponseData ifsResponse = HttpClientUtil.doPostByRawWithPLM(getIfsLocationsURL, searchData); |
||||
|
if (!"200".equals(ifsResponse.getCode())) { |
||||
|
throw new RuntimeException("同步物料件异常:" + ifsResponse.getMsg()); |
||||
|
} |
||||
|
String ifsObj = String.valueOf(ifsResponse.getObj()); |
||||
|
List<IfsPartCatalog> ifsPartCatalogs = JSON.parseArray(ifsObj, IfsPartCatalog.class); |
||||
|
//清空缓存表 |
||||
|
partCatalogDao.truncatePartCatalogCacheTable(); |
||||
|
//数据批量保存到缓存的数据表 |
||||
|
partCatalogDao.batchInsertPartCatalogs(ifsPartCatalogs); |
||||
|
//调用存储过程 刷新物料件的数据 |
||||
|
this.refreshPlmPartCatalogs(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @description: 调用存储过程刷新ifs的物料件的数据 |
||||
|
* @author LR |
||||
|
* @date 2024/9/23 10:46 |
||||
|
* @version 1.0 |
||||
|
*/ |
||||
|
public void refreshPlmPartCatalogs() { |
||||
|
List<Object> params = new ArrayList<>(); |
||||
|
//调用存储过程 |
||||
|
procedureDao.execProduceData("refreshPlmPartCatalogs", params); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue