|
@@ -1,12 +1,12 @@
|
|
|
package com.galaxis.manatee.task;
|
|
|
|
|
|
+import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
import com.galaxis.capsule.bo.ChuanyunObject;
|
|
|
-import com.galaxis.capsule.dto.MaterialDTO;
|
|
|
import com.galaxis.manatee.constant.ChuanYunConstant;
|
|
|
import com.galaxis.manatee.constant.DingTalkConstant;
|
|
|
import com.galaxis.manatee.constant.StringConstant;
|
|
@@ -15,8 +15,10 @@ import com.galaxis.manatee.entity.chuanyun.data.object.*;
|
|
|
import com.galaxis.manatee.entity.chuanyun.dto.*;
|
|
|
import com.galaxis.manatee.entity.chuanyun.bo.MaterialResendBO;
|
|
|
import com.galaxis.manatee.entity.ding.DingTalkProcessInstance;
|
|
|
+import com.galaxis.manatee.exception.BigSizeException;
|
|
|
import com.galaxis.manatee.manager.ChuanYunManager;
|
|
|
import com.galaxis.manatee.manager.ClawFeign;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.domain.Example;
|
|
|
import org.springframework.data.domain.Page;
|
|
@@ -57,6 +59,7 @@ public class ChuanyunScheduledTask {
|
|
|
@Scheduled(fixedDelay = 3600000L)
|
|
|
private void getDataFromChuanyun(){
|
|
|
//获取项目数据
|
|
|
+// materialInformationSync();
|
|
|
getProjectInformationFromChuanyun();
|
|
|
}
|
|
|
|
|
@@ -120,7 +123,7 @@ public class ChuanyunScheduledTask {
|
|
|
List<ChuanyunMaterialDO> chuanyunMaterialList=new ArrayList<>();
|
|
|
//遍历获取的数据,如果系统中已经存在就不进行保存
|
|
|
result.getContent().forEach(materialDTO -> {
|
|
|
- List<ChuanyunMaterialDO> list=chuanyunMaterialDao.findAllByCode(materialDTO.getCode());
|
|
|
+ List<ChuanyunMaterialDO> list=chuanyunMaterialDao.findAllByCode(materialDTO.getMaterialPrimaryKey().getCode());
|
|
|
if(list.size()==0){
|
|
|
ChuanyunMaterialDO chuanyunMaterialDO=ChuanyunMaterialDO.fromMaterialDTO(materialDTO);
|
|
|
chuanyunMaterialList.add(chuanyunMaterialDO);
|
|
@@ -133,7 +136,8 @@ public class ChuanyunScheduledTask {
|
|
|
parameters.put("page",Integer.toString(page));
|
|
|
log.info("共"+totalPage+"页,当前第"+page+"页,更新了"+chuanyunMaterialList.size()+"条数据");
|
|
|
//将更新的的物料信息同步到氚云
|
|
|
- getMaterialFromU9(toSave);
|
|
|
+ getMaterialFromU9(result.getContent());
|
|
|
+
|
|
|
}
|
|
|
log.info("更新U9物料数据结束,共更新数据"+totalAmount);
|
|
|
}
|
|
@@ -142,24 +146,34 @@ public class ChuanyunScheduledTask {
|
|
|
* 用于将需要更新的数据同步到氚云
|
|
|
* @param toSave 待保存的数据集合
|
|
|
*/
|
|
|
- private void getMaterialFromU9(List<ChuanyunMaterialDO> toSave){
|
|
|
+ private void getMaterialFromU9(List<MaterialDTO> toSave){
|
|
|
ObjectMapper objectMapper=new ObjectMapper();
|
|
|
- List<String> toSaveString=new ArrayList<>();
|
|
|
- toSave.forEach(chuanyunMaterialDO -> {
|
|
|
- try {
|
|
|
- toSaveString.add(objectMapper.writeValueAsString(chuanyunMaterialDO));
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- log.info(chuanyunMaterialDO+"");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- });
|
|
|
- //将新增加的数据更新到氚云
|
|
|
- try{
|
|
|
- chuanYunManager.saveAll(ChuanyunMaterialDO.SCHEMA_CODE,toSaveString,true);
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- log.info("物料信息更新到氚云"+toSave.size());
|
|
|
+ toSave.forEach(materialDTO -> {
|
|
|
+ try {
|
|
|
+ EquipmentMaterialDTO equipmentMaterialDTO = new EquipmentMaterialDTO(materialDTO);
|
|
|
+ var materialString = objectMapper.writeValueAsString(equipmentMaterialDTO);
|
|
|
+ List<String> projectmatchers = new ArrayList<>();
|
|
|
+ projectmatchers.add("F0000002_2,"+materialDTO.getMaterialPrimaryKey().getCode());
|
|
|
+ if (!StringUtils.isEmpty(materialDTO.getMaterialPrimaryKey().getVersion())){
|
|
|
+ projectmatchers.add("F0000010_2,"+materialDTO.getMaterialPrimaryKey().getVersion());
|
|
|
+ }
|
|
|
+ var projectfilter= Filter.instance(0,Integer.MAX_VALUE,true,"And",projectmatchers);
|
|
|
+ var chuanyunFindAllResponse = chuanYunManager.findAll(ChuanyunMaterialDO.SCHEMA_CODE,projectfilter);
|
|
|
+ ChuanyunSaveDTO chuanyunSaveDTO;
|
|
|
+ if (chuanyunFindAllResponse.getReturnData()!=null){
|
|
|
+ List<ChuanyunSaleContractDO> result=objectMapper.convertValue(chuanyunFindAllResponse.getReturnData().getBizObjectArray(), new TypeReference<>(){});
|
|
|
+ chuanyunSaveDTO=chuanYunManager.delete(ChuanyunMaterialDO.SCHEMA_CODE,result.get(0).getObjectId());
|
|
|
+ }
|
|
|
+ chuanyunSaveDTO =chuanYunManager.save(ChuanyunMaterialDO.SCHEMA_CODE,materialString,true);
|
|
|
+ if (chuanyunSaveDTO.getSuccessful()){
|
|
|
+ log.info("设备零部件更新成功");
|
|
|
+ }else {
|
|
|
+ log.info("设备零部件更新失败");
|
|
|
+ }
|
|
|
+ } catch (JsonProcessingException | BigSizeException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -278,4 +292,58 @@ public class ChuanyunScheduledTask {
|
|
|
currentPage++;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Data
|
|
|
+ class EquipmentMaterialDTO{
|
|
|
+
|
|
|
+ @JsonProperty(value = "F0000002")
|
|
|
+ private String code;
|
|
|
+
|
|
|
+ @JsonProperty(value = "F0000001")
|
|
|
+ private String title;
|
|
|
+
|
|
|
+ @JsonProperty(value = "F0000007")
|
|
|
+ private String label;
|
|
|
+
|
|
|
+ @JsonProperty(value = "F0000008")
|
|
|
+ private String model;
|
|
|
+
|
|
|
+ @JsonProperty(value = "F0000009")
|
|
|
+ private String brand;
|
|
|
+
|
|
|
+ @JsonProperty(value = "F0000010")
|
|
|
+ private String version;
|
|
|
+
|
|
|
+ @JsonProperty(value = "F0000005")
|
|
|
+ private String type;
|
|
|
+
|
|
|
+ @JsonProperty(value = "F0000006")
|
|
|
+ private String property;
|
|
|
+
|
|
|
+ public EquipmentMaterialDTO(MaterialDTO materialDTO){
|
|
|
+ if (materialDTO!=null){
|
|
|
+ if (materialDTO.getMaterialPrimaryKey().getCode()!=null){
|
|
|
+ this.code=materialDTO.getMaterialPrimaryKey().getCode();
|
|
|
+ }
|
|
|
+ if (materialDTO.getMaterialPrimaryKey().getVersion()!=null){
|
|
|
+ this.version=materialDTO.getMaterialPrimaryKey().getVersion();
|
|
|
+ }
|
|
|
+ if (materialDTO.getName()!=null){
|
|
|
+ this.title=materialDTO.getName();
|
|
|
+ }
|
|
|
+ if (materialDTO.getBrand()!=null){
|
|
|
+ this.brand=materialDTO.getBrand();
|
|
|
+ }
|
|
|
+ if (materialDTO.getLabel()!=null){
|
|
|
+ this.label=materialDTO.getLabel();
|
|
|
+ }
|
|
|
+ if (materialDTO.getType()!=null){
|
|
|
+ this.type=materialDTO.getType();
|
|
|
+ }
|
|
|
+ if (materialDTO.getProperty()!=null){
|
|
|
+ this.property=materialDTO.getProperty();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|