|
@@ -0,0 +1,121 @@
|
|
|
+package com.galaxis.manatee.Test.zzx;
|
|
|
+
|
|
|
+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.galaxis.manatee.capsule.dto.PageDTO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunPurCostDO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.dto.ChuanyunPurCostDTO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.dto.ChuanyunSaveDTO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.dto.Filter;
|
|
|
+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.junit.jupiter.api.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@SpringBootTest
|
|
|
+public class ProjectTest4 {
|
|
|
+ @Autowired
|
|
|
+ private ClawFeign clawFeign;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ChuanYunManager chuanYunManager;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void test1(){
|
|
|
+ log.info("开始更新项目物料成本");
|
|
|
+ var objectMapper = new ObjectMapper();
|
|
|
+ var page = 1;
|
|
|
+ var size = 20;
|
|
|
+ var flag = true;
|
|
|
+ while (flag) {
|
|
|
+ Map<String, String> map = new HashMap<>(1);
|
|
|
+ map.put("page", String.valueOf(page));
|
|
|
+ map.put("size", String.valueOf(size));
|
|
|
+ //获取物料成本
|
|
|
+ PageDTO<ChuanyunPurCostDTO> pageInfo = clawFeign.findChuanyunPurCost(map);
|
|
|
+ if (page <= pageInfo.getTotalPages()) {
|
|
|
+ page += 1;
|
|
|
+ } else {
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ List<ChuanyunPurCostDTO> list = pageInfo.getContent();
|
|
|
+ list.forEach(chuanyunPurCostDTO -> {
|
|
|
+ try {
|
|
|
+ if (chuanyunPurCostDTO != null) {
|
|
|
+ PurCostDTO purCostDTO = new PurCostDTO(chuanyunPurCostDTO);
|
|
|
+ var purcostString = objectMapper.writeValueAsString(purCostDTO);
|
|
|
+ ChuanyunSaveDTO chuanyunSaveDTO;
|
|
|
+ //根据项目号判断是否存在
|
|
|
+ List<String> macthers = new ArrayList<>();
|
|
|
+ macthers.add("F0000001_2," + chuanyunPurCostDTO.getProjectcode());
|
|
|
+ var filter = Filter.instance(0, 1, true, "And", macthers);
|
|
|
+ var chuanyunFindAllResponse = chuanYunManager.findAll(ChuanyunPurCostDO.SCHEMA_CODE, filter);
|
|
|
+ if (chuanyunFindAllResponse.getReturnData() == null) {
|
|
|
+ //新增
|
|
|
+ chuanyunSaveDTO = chuanYunManager.save(ChuanyunPurCostDO.SCHEMA_CODE, purcostString, true);
|
|
|
+ } else {
|
|
|
+ List<ChuanyunPurCostDO> result = objectMapper.convertValue(chuanyunFindAllResponse.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ ChuanyunPurCostDO chuanyunPurCostDO = result.get(0);
|
|
|
+ //更新
|
|
|
+ chuanyunSaveDTO = chuanYunManager.update(ChuanyunPurCostDO.SCHEMA_CODE, chuanyunPurCostDO.getObjectId(), purcostString);
|
|
|
+ }
|
|
|
+ if (chuanyunSaveDTO.getSuccessful()) {
|
|
|
+ log.info("更新项目物料成本成功");
|
|
|
+ } else {
|
|
|
+ log.warn("更新项目物料成本失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (JsonProcessingException | BigSizeException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ class PurCostDTO {
|
|
|
+ @JsonProperty("F0000001")
|
|
|
+ private String projectcode;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 采购成本
|
|
|
+ */
|
|
|
+ @JsonProperty("F0000002")
|
|
|
+ private BigDecimal purcost;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 领料成本
|
|
|
+ */
|
|
|
+ @JsonProperty("F0000003")
|
|
|
+ private BigDecimal issuedcost;
|
|
|
+
|
|
|
+ public PurCostDTO(ChuanyunPurCostDTO chuanyunPurCostDTO) {
|
|
|
+ if (null != chuanyunPurCostDTO) {
|
|
|
+ if (null != chuanyunPurCostDTO.getProjectcode()) {
|
|
|
+ this.projectcode = chuanyunPurCostDTO.getProjectcode();
|
|
|
+ }
|
|
|
+ if (null != chuanyunPurCostDTO.getPurcost()) {
|
|
|
+ this.purcost = chuanyunPurCostDTO.getPurcost();
|
|
|
+ }
|
|
|
+ if (null != chuanyunPurCostDTO.getIssuedcost()) {
|
|
|
+ this.issuedcost = chuanyunPurCostDTO.getIssuedcost();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|