Browse Source

1.修改同步设备零部件

WoNiu 4 years ago
parent
commit
e4dce236d5

+ 2 - 2
src/main/java/com/galaxis/manatee/entity/chuanyun/data/object/ChuanyunMaterialDO.java

@@ -2,7 +2,7 @@ package com.galaxis.manatee.entity.chuanyun.data.object;
 
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
-import com.galaxis.capsule.dto.MaterialDTO;
+import com.galaxis.manatee.entity.chuanyun.dto.MaterialDTO;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.extern.slf4j.Slf4j;
@@ -89,7 +89,7 @@ public class ChuanyunMaterialDO extends BasicDO{
         BeanUtils.copyProperties(materialDTO, chuanyunMaterialDO);
         chuanyunMaterialDO.setObjectId(UUID.randomUUID().toString());
         chuanyunMaterialDO.setTitle(materialDTO.getName());
-        chuanyunMaterialDO.setName(materialDTO.getName()+"\t"+materialDTO.getCode());
+        chuanyunMaterialDO.setName(materialDTO.getName()+"\t"+materialDTO.getMaterialPrimaryKey().getCode());
         return chuanyunMaterialDO;
     }
 }

+ 40 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/dto/MaterialDTO.java

@@ -0,0 +1,40 @@
+package com.galaxis.manatee.entity.chuanyun.dto;
+
+import lombok.Data;
+
+import javax.persistence.EmbeddedId;
+
+@Data
+public class MaterialDTO {
+
+
+    @EmbeddedId
+    private MaterialPrimaryKey materialPrimaryKey;
+
+    /**
+     * 品名
+     */
+    private String name;
+
+    /**
+     * 名称(标签)
+     */
+    private String label;
+
+    /**
+     * 品牌
+     */
+    private String brand;
+
+    /**
+     * 库存分类
+     */
+    private String type;
+
+    /**
+     * 形态属性
+     */
+    private String property;
+
+
+}

+ 18 - 0
src/main/java/com/galaxis/manatee/entity/chuanyun/dto/MaterialPrimaryKey.java

@@ -0,0 +1,18 @@
+package com.galaxis.manatee.entity.chuanyun.dto;
+
+import lombok.Data;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import java.io.Serializable;
+
+@Embeddable
+@Data
+public class MaterialPrimaryKey implements Serializable {
+
+    private String code;
+
+    private String version;
+
+    private String organizationCode;
+}

+ 1 - 0
src/main/java/com/galaxis/manatee/manager/ClawFeign.java

@@ -5,6 +5,7 @@ import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunProjectCashFlowDO
 import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunPurCostDO;
 import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunReimbursementDO;
 import com.galaxis.manatee.entity.chuanyun.dto.*;
+import com.galaxis.manatee.entity.chuanyun.dto.MaterialDTO;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.GetMapping;

+ 88 - 20
src/main/java/com/galaxis/manatee/task/ChuanyunScheduledTask.java

@@ -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();
+                }
+            }
+        }
+    }
 }