【物料主数据】从HANA获取物料采购属性信息
This commit is contained in:
parent
62ca1a1641
commit
5ffbb9c45d
|
|
@ -453,4 +453,13 @@ public class MaterialMainApi extends BaseApi {
|
|||
public void updateMaterialCurrentTwoYearsUsage() {
|
||||
materialMainService.doQueryCurrentTwoYearsUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动从HANA获取物料的采购属性信息
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("syncMaterialPurchasePropInfo")
|
||||
public void syncMaterialPurchasePropInfo() throws Exception {
|
||||
materialMainService.syncMaterialPurchasePropInfo();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,4 +160,15 @@ public class SaticScheduleTask {
|
|||
public void syncEhrEmployee() {
|
||||
authorityUserService.syncEhrEmployee();
|
||||
}
|
||||
|
||||
/**
|
||||
* 每天凌晨7点从HANA获取物料的采购属性信息
|
||||
* 只针对物料状态material_state为1:激活 2:禁止采购 3:售后专用
|
||||
* * 流程状态:15:已审核 100: 历史正式物料(已审核)
|
||||
*/
|
||||
// @Scheduled(cron = "0 0 7 * * ?")
|
||||
//// @Scheduled(cron = "0 0/2 * * * ? ") // 测试使用,每2分钟
|
||||
// public void syncMaterialPurchasePropInfo() throws Exception {
|
||||
// materialMainService.syncMaterialPurchasePropInfo();
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.nflg.product.material.mapper.master;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.product.material.pojo.entity.MaterialMainAttrEntity;
|
||||
|
||||
/**
|
||||
* 物料主数据-采购属性
|
||||
*/
|
||||
public interface MaterialMainAttrMapper extends BaseMapper<MaterialMainAttrEntity> {
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.nflg.product.material.pojo.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 物料信息附属表
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value = "com-nflg-product-material-pojo-entity-MaterialMainAttrEntity")
|
||||
@TableName(value = "t_material_main_attr")
|
||||
public class MaterialMainAttrEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 行ID 雪花
|
||||
*/
|
||||
@TableId(value = "row_id", type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "行ID 雪花")
|
||||
private Long rowId;
|
||||
|
||||
/**
|
||||
* 物料编码
|
||||
*/
|
||||
@TableField(value = "material_no")
|
||||
@ApiModelProperty(value = "物料编码")
|
||||
private String materialNo;
|
||||
|
||||
@TableField(value = "factory")
|
||||
@ApiModelProperty(value = "工厂")
|
||||
private String factory;
|
||||
|
||||
@TableField(value = "purchase_type")
|
||||
@ApiModelProperty(value = "采购类型")
|
||||
private String purchaseType;
|
||||
|
||||
@TableField(value = "special_purchase_type")
|
||||
@ApiModelProperty(value = "特殊采购类")
|
||||
private String specialPurchaseType;
|
||||
|
||||
@TableField(value = "plan_delivery_time")
|
||||
@ApiModelProperty(value = "计划交货时间(天数)")
|
||||
private String planDeliveryTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(value = "created_by" ,fill = FieldFill.INSERT)
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "created_time",fill = FieldFill.INSERT)
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(value = "updated_by",fill = FieldFill.INSERT_UPDATE)
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private String updatedBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "updated_time",fill = FieldFill.INSERT_UPDATE)
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private LocalDateTime updatedTime;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
|
|
@ -51,5 +51,18 @@ public class SopMaterialInfo {
|
|||
@ApiModelProperty("最后出库时间")
|
||||
private String BUDAT;
|
||||
|
||||
// 采购属性信息 start
|
||||
@ApiModelProperty("工厂")
|
||||
private String WERKS;
|
||||
|
||||
@ApiModelProperty("采购类型")
|
||||
private String BESKZ;
|
||||
|
||||
@ApiModelProperty("特殊采购类")
|
||||
private String SOBSL;
|
||||
|
||||
@ApiModelProperty("计划交货时间")
|
||||
private String PLIFZ;
|
||||
// 采购属性信息 end
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import com.nflg.product.base.core.conmon.util.SessionUtil;
|
|||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.base.core.vo.PageVO;
|
||||
import com.nflg.product.material.constant.*;
|
||||
import com.nflg.product.material.mapper.master.MaterialMainAttrMapper;
|
||||
import com.nflg.product.material.mapper.master.MaterialMainMapper;
|
||||
import com.nflg.product.material.pojo.dto.*;
|
||||
import com.nflg.product.material.pojo.entity.*;
|
||||
|
|
@ -164,6 +165,9 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
|
|||
@Value("${material.home.day:30}")
|
||||
private Integer homeDay;
|
||||
|
||||
@Resource
|
||||
private MaterialMainAttrMapper materialMainAttrMapper;
|
||||
|
||||
/**
|
||||
* 分页查询所有数据
|
||||
*
|
||||
|
|
@ -1944,6 +1948,26 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
|
|||
return sopMaterialInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取HANA物料采购属性信息
|
||||
* @param materialNos
|
||||
* @return
|
||||
*/
|
||||
public List<SopMaterialInfo> getSapPurchasePropInfo(List<String> materialNos) throws Exception {
|
||||
String materialNoSnippet = CollUtil.join(materialNos, "','");
|
||||
materialNoSnippet = "'".concat(materialNoSnippet).concat("'");
|
||||
String sql = " select matnr,werks,BESKZ, SOBSL, PLIFZ from \"STG_ECC\".\"MARC\" where MATNR in ( ";
|
||||
sql = sql.concat(materialNoSnippet).concat(" ) ");
|
||||
sql = sql.concat(" and werks = '1010' ");
|
||||
|
||||
log.info("获取HANA采购属性信息");
|
||||
PreparedStatement preparedStatement = sopConnection.prepareStatement(sql);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
List<SopMaterialInfo> sopMaterialInfos = resultSetToBean(resultSet, SopMaterialInfo.class);
|
||||
|
||||
return sopMaterialInfos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resultSet
|
||||
* @return
|
||||
|
|
@ -2939,4 +2963,88 @@ public class MaterialMainService extends ServiceImpl<MaterialMainMapper, Materia
|
|||
}
|
||||
return rlist;
|
||||
}
|
||||
|
||||
public void syncMaterialPurchasePropInfo() {
|
||||
log.info("获取采购属性信息开始");
|
||||
long startTime = System.currentTimeMillis();
|
||||
MaterialMainQuery query = new MaterialMainQuery();
|
||||
query.setMaterialStates(Arrays.asList(1, 2, 3));
|
||||
query.setFirstMaterialCategoryCode("10");
|
||||
query.setPage(1L).setPageSize(1000L);
|
||||
query.setMaterialClass(0); // 接口用途:0:物料查看
|
||||
|
||||
int pageCount = this.downExcelGetListPages(query) + 1;
|
||||
|
||||
for (int i = 1; i <= pageCount; i++) {
|
||||
query.setPage((long) i);
|
||||
List<Map<String, Object>> result = this.getBaseMapper().getListDataMap(query, (query.getPage() - 1) * query.getPageSize(), query.getPageSize());
|
||||
|
||||
if (result == null || result.size() <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sapInfoService.materialPurchasePropInfoTask(result);
|
||||
List<MaterialMainAttrEntity> mResult = Convert.convert(new TypeReference<List<MaterialMainAttrEntity>>() {
|
||||
}, result);
|
||||
if (mResult == null || mResult.size() <= 0) {
|
||||
continue;
|
||||
}
|
||||
// 过滤掉几个字段都没有值的数据,降低数据库的负担
|
||||
List<MaterialMainAttrEntity> filterList = mResult.stream()
|
||||
.filter(item -> Objects.nonNull(item.getPurchaseType()) || Objects.nonNull(item.getSpecialPurchaseType()) || Objects.nonNull(item.getPlanDeliveryTime()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isEmpty(filterList)) {
|
||||
continue;
|
||||
}
|
||||
this.updateMaterialPropInfo(filterList);
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("获取采购属性信息结束,耗时(ms): {}", (endTime - startTime));
|
||||
|
||||
}
|
||||
|
||||
private void updateMaterialPropInfo(List<MaterialMainAttrEntity> filterList) {
|
||||
if (CollUtil.isEmpty(filterList)) {
|
||||
return;
|
||||
}
|
||||
List<MaterialMainAttrEntity> existsList = materialMainAttrMapper.selectList(null);
|
||||
if (CollUtil.isNotEmpty(existsList)) {
|
||||
for (MaterialMainAttrEntity materialMainAttrEntity : filterList) {
|
||||
try {
|
||||
List<MaterialMainAttrEntity> sameList = existsList.stream().filter(item -> item.getMaterialNo().equals(materialMainAttrEntity.getMaterialNo())
|
||||
&& item.getFactory().equals(materialMainAttrEntity.getFactory())).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(sameList)) {
|
||||
MaterialMainAttrEntity update = sameList.get(0);
|
||||
update.setPurchaseType(materialMainAttrEntity.getPurchaseType());
|
||||
update.setSpecialPurchaseType(materialMainAttrEntity.getSpecialPurchaseType());
|
||||
update.setPlanDeliveryTime(materialMainAttrEntity.getPlanDeliveryTime());
|
||||
materialMainAttrMapper.updateById(materialMainAttrEntity);
|
||||
} else {
|
||||
this.saveMaterialMainAttr(materialMainAttrEntity);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("物料编号:" + materialMainAttrEntity.getMaterialNo() + "修改采购属性信息异常", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (MaterialMainAttrEntity materialMainAttrEntity : filterList) {
|
||||
try {
|
||||
this.saveMaterialMainAttr(materialMainAttrEntity);
|
||||
} catch (Exception e) {
|
||||
log.error("物料编号:" + materialMainAttrEntity.getMaterialNo() + "修改采购属性信息异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveMaterialMainAttr(MaterialMainAttrEntity materialMainAttrEntity) {
|
||||
MaterialMainAttrEntity save = new MaterialMainAttrEntity();
|
||||
save.setRowId(IdWorker.getId());
|
||||
save.setMaterialNo(materialMainAttrEntity.getMaterialNo());
|
||||
save.setFactory(materialMainAttrEntity.getFactory());
|
||||
save.setPurchaseType(materialMainAttrEntity.getPurchaseType());
|
||||
save.setSpecialPurchaseType(materialMainAttrEntity.getSpecialPurchaseType());
|
||||
save.setPlanDeliveryTime(materialMainAttrEntity.getPlanDeliveryTime());
|
||||
materialMainAttrMapper.insert(save);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,4 +152,34 @@ public class SapInfoService {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void materialPurchasePropInfoTask(List<Map<String, Object>> result) {
|
||||
CompletableFuture<Void> task = CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
initSapPurPropInfo(result);
|
||||
} catch (Exception e) {
|
||||
System.out.println("获取sap采购属性错误".concat(e.getMessage()));
|
||||
}
|
||||
}, futureTaskPool);
|
||||
task.join();
|
||||
}
|
||||
|
||||
private void initSapPurPropInfo(List<Map<String, Object>> data) throws Exception {
|
||||
List<String> materialNos = data.stream().map(u -> u.get("materialNo").toString()).collect(Collectors.toList());
|
||||
List<SopMaterialInfo> sapMaterialList = materialMainService.getSapPurchasePropInfo(handlerToSapMaterialNo(materialNos));
|
||||
if (sapMaterialList != null && sapMaterialList.size() > 0) {
|
||||
Map<String, SopMaterialInfo> sapMaterialMp = sapMaterialList.stream().collect(Collectors.toMap(SopMaterialInfo::getMATNR, user -> user, (oldValue, newValue) -> newValue));
|
||||
data.forEach(m -> {
|
||||
if (sapMaterialMp.containsKey(handlerMaterialNoToSapMaterialNo(m.get("materialNo").toString()))) {
|
||||
SopMaterialInfo sapMaterialInfo = sapMaterialMp.get(handlerMaterialNoToSapMaterialNo(m.get("materialNo").toString()));
|
||||
if (sapMaterialInfo != null) {
|
||||
m.put("factory", sapMaterialInfo.getWERKS());
|
||||
m.put("purchaseType", sapMaterialInfo.getBESKZ());
|
||||
m.put("specialPurchaseType", sapMaterialInfo.getSOBSL());
|
||||
m.put("planDeliveryTime", sapMaterialInfo.getPLIFZ());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.product.material.mapper.master.MaterialMainAttrMapper">
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue