|
@@ -0,0 +1,608 @@
|
|
|
+package com.galaxis.manatee.Test;
|
|
|
+
|
|
|
+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.dao.ChuanyunImplCostDao;
|
|
|
+import com.galaxis.manatee.dao.ChuanyunReimbursementDao;
|
|
|
+import com.galaxis.manatee.dao.ChuanyunSelfWorkHourDao;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.data.object.*;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.dto.*;
|
|
|
+import com.galaxis.manatee.exception.BigSizeException;
|
|
|
+import com.galaxis.manatee.manager.ChuanYunManager;
|
|
|
+import com.galaxis.manatee.service.WorkGroupService;
|
|
|
+import com.galaxis.manatee.task.ChuanyunFinancialScheduledTask;
|
|
|
+import com.galaxis.manatee.task.U9InfoTask;
|
|
|
+import com.galaxis.manatee.util.CollectionsUtils;
|
|
|
+import com.galaxis.manatee.util.TimeUtil;
|
|
|
+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.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@SpringBootTest
|
|
|
+public class WorkGroupTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkGroupService workGroupService;
|
|
|
+ @Autowired
|
|
|
+ private ChuanYunManager chuanYunManager;
|
|
|
+ @Autowired
|
|
|
+ private ChuanyunFinancialScheduledTask financialScheduledTask;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ChuanyunImplCostDao implCostDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ChuanyunReimbursementDao reimbursementDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ChuanyunSelfWorkHourDao selfWorkHourDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private U9InfoTask infoTask;
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void findTest() {
|
|
|
+ boolean flag = true;
|
|
|
+ List<String> m = List.of("status_2,1", "F0000003_2,D21389");
|
|
|
+ Filter filter = Filter.instance(0, 10, true, Filter.AND, m);
|
|
|
+ ChuanyunFindAllBizDTO<ChuanyunBuildProject> buildResponse = null;
|
|
|
+ try {
|
|
|
+ buildResponse = chuanYunManager.findAll(ChuanyunBuildProject.SCHEMA_CODE, filter);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (buildResponse == null || !buildResponse.getSuccessful()) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ ChuanyunFindAllBizReturnData<ChuanyunBuildProject> returnData = buildResponse.getReturnData();
|
|
|
+ if (returnData == null) {
|
|
|
+ flag = false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ChuanyunBuildProject> bizObjectArray = returnData.getBizObjectArray();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ List<ChuanyunBuildProject> bpList = objectMapper.convertValue(bizObjectArray, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void findTest1() {
|
|
|
+ List<String> m = List.of("status_2,1", "F0000003_2,D21389");
|
|
|
+ Filter f = Filter.instance(0, 10, true, Filter.AND, m);
|
|
|
+
|
|
|
+ ChuanyunFindAllBizDTO<Object> chuanyunFindAllResponse = null;
|
|
|
+ try {
|
|
|
+ chuanyunFindAllResponse = chuanYunManager.findAll(ChuanyunBuildProject.SCHEMA_CODE, f);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //保存
|
|
|
+ List<Object> buildBizObjectArray = chuanyunFindAllResponse.getReturnData().getBizObjectArray();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ List<ChuanyunBuildProject> bpList = objectMapper.convertValue(buildBizObjectArray, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ final Object monitor = new Object();
|
|
|
+ bpList.forEach(chuanyunBuildProject -> {
|
|
|
+ synchronized (monitor) {
|
|
|
+ String buildProjectId = chuanyunBuildProject.getObjectId();
|
|
|
+ List<String> m1 = List.of("F0000001_2," + buildProjectId);
|
|
|
+ Filter filter = Filter.instance(0, 10, true, Filter.AND, m1);
|
|
|
+ ChuanyunFindAllBizDTO<Object> projectList = null;
|
|
|
+ try {
|
|
|
+ projectList = chuanYunManager.findAll(ChuanyunProjectOrganizationStructureDO.SCHEMA_CODE, filter);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (projectList == null || projectList.getReturnData() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ChuanyunProjectOrganizationStructureDO> projectOrganizationStructureList = objectMapper.convertValue(projectList.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ List<String> parentIdList = projectOrganizationStructureList.stream().map(BasicDO::getObjectId).toList();
|
|
|
+ parentIdList.forEach(parentId -> {
|
|
|
+ // 查询工作组信息
|
|
|
+ List<String> m2 = List.of("parentObjectId_2," + parentId);
|
|
|
+ ChuanyunFindAllBizDTO<Object> workGroupResponse = null;
|
|
|
+ try {
|
|
|
+ workGroupResponse = chuanYunManager.findAll(ChuanyunWorkGroupDO.SCHEMA_CODE, Filter.instance(0, 30, true, Filter.AND, m2));
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (workGroupResponse == null || !workGroupResponse.getSuccessful()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (workGroupResponse.getReturnData() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ChuanyunWorkGroupDO> workGroupList = objectMapper.convertValue(workGroupResponse.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ workGroupList.forEach(chuanyunWorkGroupDO -> {
|
|
|
+ // 查询该项目在总表中的记录
|
|
|
+ List<String> m3 = List.of("F0000075_5,异常", "F0000002_2," + chuanyunBuildProject.getProjectCode());
|
|
|
+ Filter instance = Filter.instance(0, 50, true, Filter.AND, m3);
|
|
|
+ ChuanyunFindAllBizDTO<Object> groupProjectResponse = null;
|
|
|
+ try {
|
|
|
+ groupProjectResponse = chuanYunManager.findAll(ChuanyunGroupProjectDO.SCHEMA_CODE, instance);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (!groupProjectResponse.getSuccessful() || groupProjectResponse.getReturnData() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Object> bizObjectArray = groupProjectResponse.getReturnData().getBizObjectArray();
|
|
|
+ List<ChuanyunGroupProjectDO> groupProjectDOList = objectMapper.convertValue(bizObjectArray, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ Optional<ChuanyunGroupProjectDO> groupProjectDO = groupProjectDOList.stream().findFirst();
|
|
|
+ if (groupProjectDO.isPresent()) {
|
|
|
+ ChuanyunGroupProjectDO chuanyunGroupProjectDO = groupProjectDO.get();
|
|
|
+ List<String> userIdList = chuanyunWorkGroupDO.getSubWorkGroupMemberObject().stream().map(BasicSubDO::getObjectId).toList();
|
|
|
+ // 查询报销单
|
|
|
+ BigDecimal total = new BigDecimal("0.00");
|
|
|
+ BigDecimal totalManDay = new BigDecimal("0.000");
|
|
|
+ // 查询项目工作组人天
|
|
|
+ for (String userId : userIdList) {
|
|
|
+ // 查询用户在该项目的报销单
|
|
|
+ List<ChuanyunReimbursementDO> reimbursements = reimbursementDao.findAllByGroupProjectIdAndReimburseUserIdAndStatusIn(chuanyunGroupProjectDO.getObjectId(), userId, List.of(1, 2));
|
|
|
+ BigDecimal totalReimburse = reimbursements.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ total = total.add(totalReimburse);
|
|
|
+ List<ChuanyunSelfWorkHourDO> workHours = selfWorkHourDao.findAllByProjectIdAndUserIdAndStatusIn(chuanyunGroupProjectDO.getObjectId(), userId, List.of("1", "2"));
|
|
|
+ BigDecimal totalWorkHour = workHours.stream().map(ChuanyunSelfWorkHourDO::getStandardWorkHour).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ // 人天
|
|
|
+ BigDecimal manDay = totalWorkHour.divide(BigDecimal.valueOf(8), 3, RoundingMode.UP);
|
|
|
+ totalManDay = totalManDay.add(manDay);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 统计工作组所有的工时
|
|
|
+ String projectObjectId = chuanyunGroupProjectDO.getObjectId();
|
|
|
+ String projectCode = chuanyunGroupProjectDO.getProjectCode();
|
|
|
+ String workGroupId = chuanyunWorkGroupDO.getObjectId();
|
|
|
+
|
|
|
+ ChuanyunImplCostDO old = implCostDao.findByProjectIdAndProjectCodeAndWorkGroup(projectObjectId, projectCode, workGroupId);
|
|
|
+ if (!Objects.isNull(old)) {
|
|
|
+ BigDecimal oldImplCost = old.getImplCost();
|
|
|
+ BigDecimal oldManDay = old.getManDay();
|
|
|
+ if (Objects.isNull(oldImplCost) || Objects.isNull(oldManDay) || oldImplCost.compareTo(total) != 0 || oldManDay.compareTo(totalManDay) != 0) {
|
|
|
+ old.setImplCost(total);
|
|
|
+ old.setManDay(totalManDay);
|
|
|
+ implCostDao.save(old);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ChuanyunImplCostDO chuanyunImplCostDO = new ChuanyunImplCostDO();
|
|
|
+ chuanyunImplCostDO.setProjectId(projectObjectId);
|
|
|
+ chuanyunImplCostDO.setProjectCode(projectCode);
|
|
|
+ chuanyunImplCostDO.setWorkGroup(workGroupId);
|
|
|
+ chuanyunImplCostDO.setWorkGroupName(chuanyunWorkGroupDO.getWorkGroupName());
|
|
|
+ chuanyunImplCostDO.setImplCost(total);
|
|
|
+ chuanyunImplCostDO.setManDay(totalManDay);
|
|
|
+ implCostDao.saveAndFlush(chuanyunImplCostDO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void findOneTest() {
|
|
|
+
|
|
|
+ ChuanyunFindBizDTO<Object> buildResponse = null;
|
|
|
+
|
|
|
+ buildResponse = chuanYunManager.find(ChuanyunBuildProject.SCHEMA_CODE, "9cdcf0d7-c8db-41b5-a03c-4caf2a2eb1f8");
|
|
|
+
|
|
|
+ if (buildResponse == null || !buildResponse.getSuccessful()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ChuanyunFindBizReturnData<Object> returnData = buildResponse.getReturnData();
|
|
|
+
|
|
|
+ Object bizObject = returnData.getBizObject();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ ChuanyunBuildProject chuanyunBuildProject = objectMapper.convertValue(bizObject, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void reimburseTest() {
|
|
|
+ workGroupService.implCost();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void pushToChuanyun() {
|
|
|
+ workGroupService.pushToChuanyun();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test1() {
|
|
|
+ infoTask.saveLaborCostWgTest();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void workGroupMonthTest() {
|
|
|
+ // 查询立项表中数据
|
|
|
+ List<ChuanyunBuildProject> buildProjectList = findAll();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ // 查询组织架构录入
|
|
|
+ final Object monitor = new Object();
|
|
|
+ buildProjectList.parallelStream().forEach(chuanyunBuildProject -> {
|
|
|
+ synchronized (monitor) {
|
|
|
+ String buildProjectId = chuanyunBuildProject.getObjectId();
|
|
|
+ List<String> m1 = List.of("F0000001_2," + buildProjectId);
|
|
|
+ Filter filter = Filter.instance(0, 10, true, Filter.AND, m1);
|
|
|
+ ChuanyunFindAllBizDTO<Object> projectList = null;
|
|
|
+ try {
|
|
|
+ projectList = chuanYunManager.findAll(ChuanyunProjectOrganizationStructureDO.SCHEMA_CODE, filter);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (projectList == null || projectList.getReturnData() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ChuanyunProjectOrganizationStructureDO> projectOrganizationStructureList = objectMapper.convertValue(projectList.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ List<String> parentIdList = projectOrganizationStructureList.stream().map(BasicDO::getObjectId).toList();
|
|
|
+ parentIdList.forEach(parentId -> {
|
|
|
+ // 查询工作组信息
|
|
|
+ List<String> m2 = List.of("parentObjectId_2," + parentId);
|
|
|
+ ChuanyunFindAllBizDTO<Object> workGroupResponse = null;
|
|
|
+ try {
|
|
|
+ workGroupResponse = chuanYunManager.findAll(ChuanyunWorkGroupDO.SCHEMA_CODE, Filter.instance(0, 30, true, Filter.AND, m2));
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (workGroupResponse == null || !workGroupResponse.getSuccessful()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (workGroupResponse.getReturnData() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<ChuanyunWorkGroupDO> workGroupList = objectMapper.convertValue(workGroupResponse.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ workGroupList.forEach(chuanyunWorkGroupDO -> {
|
|
|
+ // 查询该项目在总表中的记录
|
|
|
+ List<String> m3 = List.of("F0000075_5,异常", "F0000002_2," + chuanyunBuildProject.getProjectCode());
|
|
|
+ Filter instance = Filter.instance(0, 50, true, Filter.AND, m3);
|
|
|
+ ChuanyunFindAllBizDTO<Object> groupProjectResponse = null;
|
|
|
+ try {
|
|
|
+ groupProjectResponse = chuanYunManager.findAll(ChuanyunGroupProjectDO.SCHEMA_CODE, instance);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (!groupProjectResponse.getSuccessful() || groupProjectResponse.getReturnData() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Object> bizObjectArray = groupProjectResponse.getReturnData().getBizObjectArray();
|
|
|
+ List<ChuanyunGroupProjectDO> groupProjectDOList = objectMapper.convertValue(bizObjectArray, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ Optional<ChuanyunGroupProjectDO> groupProjectDO = groupProjectDOList.stream().findFirst();
|
|
|
+ if (groupProjectDO.isPresent()) {
|
|
|
+ ChuanyunGroupProjectDO chuanyunGroupProjectDO = groupProjectDO.get();
|
|
|
+ List<String> userIdList = chuanyunWorkGroupDO.getSubWorkGroupMemberObject().stream().map(BasicSubDO::getObjectId).toList();
|
|
|
+ // 查询报销单
|
|
|
+ // 查询项目工作组人天
|
|
|
+ Map<LocalDate, List<ChuanyunReimbursementDO>> reimbursementMap = new HashMap<>();
|
|
|
+ Map<LocalDate, List<ChuanyunSelfWorkHourDO>> workHoursMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (String userId : userIdList) {
|
|
|
+ // 查询用户在该项目的报销单
|
|
|
+ List<ChuanyunReimbursementDO> reimbursements = reimbursementDao.findAllByGroupProjectIdAndReimburseUserIdAndStatusIn(chuanyunGroupProjectDO.getObjectId(), userId, List.of(1, 2));
|
|
|
+ // 报销单按日期分组
|
|
|
+ Map<LocalDate, List<ChuanyunReimbursementDO>> map1 = reimbursements.stream().collect(Collectors.groupingBy(chuanyunReimbursementDO -> LocalDate.of(chuanyunReimbursementDO.getBusinessDate().getYear(), chuanyunReimbursementDO.getBusinessDate().getMonthValue(), 1)));
|
|
|
+ map1.forEach((localDate, chuanyunReimbursementDOS) -> {
|
|
|
+ boolean containsKey = reimbursementMap.containsKey(localDate);
|
|
|
+ if (containsKey) {
|
|
|
+ // 表示已经存在该key
|
|
|
+ List<ChuanyunReimbursementDO> reimbursementDOList = reimbursementMap.get(localDate);
|
|
|
+ reimbursementDOList.addAll(chuanyunReimbursementDOS);
|
|
|
+ reimbursementMap.put(localDate, reimbursementDOList);
|
|
|
+ } else {
|
|
|
+ reimbursementMap.put(localDate, chuanyunReimbursementDOS);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<ChuanyunSelfWorkHourDO> workHours = selfWorkHourDao.findAllByProjectIdAndUserIdAndStatusIn(chuanyunGroupProjectDO.getObjectId(), userId, List.of("1", "2"));
|
|
|
+ Map<LocalDate, List<ChuanyunSelfWorkHourDO>> map2 = workHours.stream().collect(Collectors.groupingBy(chuanyunSelfWorkHourDO -> LocalDate.of(chuanyunSelfWorkHourDO.getDayLogDate().getYear(), chuanyunSelfWorkHourDO.getDayLogDate().getMonthValue(), 1)));
|
|
|
+ map2.forEach((localDate, chuanyunSelfWorkHourDOS) -> {
|
|
|
+ boolean containsKey = workHoursMap.containsKey(localDate);
|
|
|
+ if (containsKey) {
|
|
|
+ // 表示已经存在该key
|
|
|
+ List<ChuanyunSelfWorkHourDO> selfWorkHours = workHoursMap.get(localDate);
|
|
|
+ selfWorkHours.addAll(chuanyunSelfWorkHourDOS);
|
|
|
+ workHoursMap.put(localDate, selfWorkHours);
|
|
|
+ } else {
|
|
|
+ workHoursMap.put(localDate, chuanyunSelfWorkHourDOS);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<LocalDate> localDates = reimbursementMap.keySet();
|
|
|
+ Set<LocalDate> localDates1 = workHoursMap.keySet();
|
|
|
+ Set<LocalDate> mergeCollections = CollectionsUtils.mergeCollections(localDates, localDates1);
|
|
|
+
|
|
|
+ mergeCollections.forEach(localDate -> {
|
|
|
+ BigDecimal totalReimbursement;
|
|
|
+ BigDecimal totalManDay;
|
|
|
+ List<ChuanyunReimbursementDO> reimbursements = reimbursementMap.getOrDefault(localDate, Collections.emptyList());
|
|
|
+ if (reimbursements.isEmpty()) {
|
|
|
+ totalReimbursement = new BigDecimal("0.00");
|
|
|
+ } else {
|
|
|
+ totalReimbursement = reimbursements.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ List<ChuanyunSelfWorkHourDO> selfWorkHours = workHoursMap.getOrDefault(localDate, Collections.emptyList());
|
|
|
+ if (selfWorkHours.isEmpty()) {
|
|
|
+ totalManDay = new BigDecimal("0.00");
|
|
|
+ } else {
|
|
|
+ BigDecimal totalWorkHours = selfWorkHours.stream().map(ChuanyunSelfWorkHourDO::getStandardWorkHour).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ totalManDay = totalWorkHours.divide(BigDecimal.valueOf(8), 3, RoundingMode.UP);
|
|
|
+ }
|
|
|
+ // 统计工作组所有的工时
|
|
|
+ String projectObjectId = chuanyunGroupProjectDO.getObjectId();
|
|
|
+ String projectCode = chuanyunGroupProjectDO.getProjectCode();
|
|
|
+ String workGroupId = chuanyunWorkGroupDO.getObjectId();
|
|
|
+
|
|
|
+ ChuanyunImplCostDO old = implCostDao.findByProjectIdAndProjectCodeAndWorkGroupAndLocalDate(projectObjectId, projectCode, workGroupId, localDate.atStartOfDay());
|
|
|
+ if (!Objects.isNull(old)) {
|
|
|
+ BigDecimal oldImplCost = old.getImplCost();
|
|
|
+ BigDecimal oldManDay = old.getManDay();
|
|
|
+ if (Objects.isNull(old.getLocalDate())) {
|
|
|
+ old.setLocalDate(localDate.atStartOfDay());
|
|
|
+ }
|
|
|
+ if (Objects.isNull(oldImplCost) || Objects.isNull(oldManDay) || oldImplCost.compareTo(totalReimbursement) != 0 || oldManDay.compareTo(totalManDay) != 0) {
|
|
|
+ old.setImplCost(totalReimbursement);
|
|
|
+ old.setManDay(totalManDay);
|
|
|
+ implCostDao.saveAndFlush(old);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ChuanyunImplCostDO chuanyunImplCostDO = new ChuanyunImplCostDO();
|
|
|
+ chuanyunImplCostDO.setProjectId(projectObjectId);
|
|
|
+ chuanyunImplCostDO.setProjectCode(projectCode);
|
|
|
+ chuanyunImplCostDO.setLocalDate(localDate.atStartOfDay());
|
|
|
+ chuanyunImplCostDO.setWorkGroup(workGroupId);
|
|
|
+ chuanyunImplCostDO.setWorkGroupName(chuanyunWorkGroupDO.getWorkGroupName());
|
|
|
+ chuanyunImplCostDO.setImplCost(totalReimbursement);
|
|
|
+ chuanyunImplCostDO.setManDay(totalManDay);
|
|
|
+ implCostDao.saveAndFlush(chuanyunImplCostDO);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void pushToChuanyunTest() {
|
|
|
+ List<ChuanyunImplCostDO> all = implCostDao.findAll();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ all.forEach(implCostDO -> {
|
|
|
+ String projectId = implCostDO.getProjectId();
|
|
|
+ String projectCode = implCostDO.getProjectCode();
|
|
|
+ String workGroup = implCostDO.getWorkGroup();
|
|
|
+ LocalDateTime localDate = implCostDO.getLocalDate();
|
|
|
+ List<String> m = List.of("F0000001_2," + projectId, "F0000002_2," + projectCode, "F0000006_2," + workGroup, "F0000008_2," + localDate);
|
|
|
+ Filter filter = Filter.instance(0, 10, true, Filter.AND, m);
|
|
|
+ ChuanyunFindAllBizDTO<Object> implCostResponse = null;
|
|
|
+ try {
|
|
|
+ implCostResponse = chuanYunManager.findAll(ChuanyunImplCostDO.SCHEMA_CODE, filter);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ assert implCostResponse != null;
|
|
|
+ if (implCostResponse.getSuccessful()) {
|
|
|
+ ChuanyunFindAllBizReturnData<Object> returnData = implCostResponse.getReturnData();
|
|
|
+ if (returnData != null && returnData.getBizObjectArray() != null) {
|
|
|
+ List<ChuanyunImplCostDO> chuanyunImplCostDOList = objectMapper.convertValue(returnData.getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ Optional<ChuanyunImplCostDO> implCostOptional = chuanyunImplCostDOList.stream().findFirst();
|
|
|
+ if (implCostOptional.isPresent()) {
|
|
|
+ ChuanyunImplCostDO chuanyunImplCostDO = implCostOptional.get();
|
|
|
+ if (Objects.isNull(chuanyunImplCostDO.getImplCost()) || Objects.isNull(chuanyunImplCostDO.getManDay()) ||
|
|
|
+ chuanyunImplCostDO.getImplCost().compareTo(implCostDO.getImplCost()) != 0 ||
|
|
|
+ chuanyunImplCostDO.getManDay().compareTo(implCostDO.getManDay()) != 0) {
|
|
|
+ // 工作组实施费用发生变化
|
|
|
+ log.info("更新项目工作组实施费用");
|
|
|
+ ImplCostUpdateDTO implCostUpdateDTO = new ImplCostUpdateDTO(implCostDO.getImplCost(), implCostDO.getManDay());
|
|
|
+ try {
|
|
|
+ String updateStr = objectMapper.writeValueAsString(implCostUpdateDTO);
|
|
|
+ chuanYunManager.update(ChuanyunImplCostDO.SCHEMA_CODE, chuanyunImplCostDO.getObjectId(), updateStr);
|
|
|
+ } catch (JsonProcessingException | BigSizeException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 直接保存
|
|
|
+ try {
|
|
|
+ String implCostStr = objectMapper.writeValueAsString(implCostDO);
|
|
|
+ chuanYunManager.save(ChuanyunImplCostDO.SCHEMA_CODE, implCostStr, true);
|
|
|
+ } catch (JsonProcessingException | BigSizeException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ log.info("上传项目工作组实施费用完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void delImplCostTest() {
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ boolean flag = true;
|
|
|
+ int start = 0;
|
|
|
+ int pageSize = 200;
|
|
|
+ while (flag) {
|
|
|
+ Filter filter = Filter.instance(start, start + pageSize, true);
|
|
|
+ ChuanyunFindAllBizDTO<Object> delAll = null;
|
|
|
+ try {
|
|
|
+ delAll = chuanYunManager.findAll(ChuanyunImplCostDO.SCHEMA_CODE, filter);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (Objects.isNull(delAll) || delAll.getReturnData() == null || delAll.getReturnData().getBizObjectArray() == null) {
|
|
|
+ flag = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (delAll.getReturnData().getTotalCount() >= start + pageSize) {
|
|
|
+ start += pageSize;
|
|
|
+ } else {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Object> bizObjectArray = delAll.getReturnData().getBizObjectArray();
|
|
|
+ List<ChuanyunImplCostDO> ic = objectMapper.convertValue(bizObjectArray, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ ic.forEach(chuanyunImplCostDO -> {
|
|
|
+ ChuanyunSaveDTO delete = chuanYunManager.delete(ChuanyunImplCostDO.SCHEMA_CODE, chuanyunImplCostDO.getObjectId());
|
|
|
+ log.info("删除: {}", delete.getSuccessful());
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ static class ImplCostUpdateDTO {
|
|
|
+ @JsonProperty("F0000004")
|
|
|
+ private BigDecimal implCost;
|
|
|
+
|
|
|
+ @JsonProperty("F0000007")
|
|
|
+ private BigDecimal manDay;
|
|
|
+
|
|
|
+ public ImplCostUpdateDTO(BigDecimal implCost, BigDecimal manDay) {
|
|
|
+ this.implCost = implCost;
|
|
|
+ this.manDay = manDay;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<ChuanyunBuildProject> findAll() {
|
|
|
+ ArrayList<ChuanyunBuildProject> buildProjects = new ArrayList<>();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ int start = 0;
|
|
|
+ long totalCount = 0L;
|
|
|
+ boolean flag = true;
|
|
|
+ int pageSize = 100;
|
|
|
+ while (flag) {
|
|
|
+ try {
|
|
|
+ //从氚云查询数据
|
|
|
+ List<String> m = List.of("status_2,1");
|
|
|
+ var filter = Filter.instance(start, start + pageSize, true, Filter.AND, m);
|
|
|
+ var chuanyunFindAllResponse = chuanYunManager.findAll(ChuanyunBuildProject.SCHEMA_CODE, filter);
|
|
|
+ if (chuanyunFindAllResponse.getReturnData() == null || chuanyunFindAllResponse.getReturnData().getBizObjectArray() == null) {
|
|
|
+ flag = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (chuanyunFindAllResponse.getReturnData().getTotalCount() >= start + pageSize) {
|
|
|
+ start += pageSize;
|
|
|
+ } else {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ //获取项目总数
|
|
|
+ totalCount = chuanyunFindAllResponse.getReturnData().getTotalCount();
|
|
|
+ //保存
|
|
|
+ List<Object> bizObjectArray = chuanyunFindAllResponse.getReturnData().getBizObjectArray();
|
|
|
+ List<ChuanyunBuildProject> bpList = objectMapper.convertValue(bizObjectArray, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ buildProjects.addAll(bpList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return buildProjects;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void LocalDateTimeTest() {
|
|
|
+ LocalDateTime localDateTime = LocalDate.now().atStartOfDay();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testFind() throws JsonProcessingException {
|
|
|
+ List<String> matchers = new ArrayList<>();
|
|
|
+ matchers.add("F0000005_2," + "AS20042");
|
|
|
+ matchers.add("F0000002_2," + TimeUtil.formatDateTime(LocalDateTime.of(2020, 5, 1, 0, 0, 0)));
|
|
|
+ matchers.add("F0000018_2," + "浙江凯乐士科技有限公司/项目交付/项目实施(集成项目交付)/项目实施/系统售后");
|
|
|
+ var filter = Filter.instance(0, 1, true, "And", matchers);
|
|
|
+ var chuanyunFindAllResponse = chuanYunManager.findAll(ChuanyunMonthLaborCostWgDO.SCHEMA_CODE, filter);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void deleteAll() {
|
|
|
+ var objectMapper = new ObjectMapper();
|
|
|
+ var start = 0;
|
|
|
+ var totalCount = 0L;
|
|
|
+ var flag = true;
|
|
|
+ var pageSize = 100;
|
|
|
+
|
|
|
+ while (flag) {
|
|
|
+
|
|
|
+ //从氚云查询数据
|
|
|
+ var filter = Filter.instance(start, start + pageSize, true);
|
|
|
+ ChuanyunFindAllBizDTO<Object> chuanyunFindAllResponse = null;
|
|
|
+ try {
|
|
|
+ chuanyunFindAllResponse = chuanYunManager.findAll(ChuanyunMonthLaborCostWgDO.SCHEMA_CODE, filter);
|
|
|
+ if (chuanyunFindAllResponse.getReturnData() == null) {
|
|
|
+ flag = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (chuanyunFindAllResponse.getReturnData().getTotalCount() >= start + pageSize) {
|
|
|
+ start += pageSize;
|
|
|
+ } else {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ChuanyunMonthLaborCostWgDO> result = objectMapper.convertValue(chuanyunFindAllResponse.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ if (result.size() > 0) {
|
|
|
+ result.forEach(chuanyunMonthLaborCostWgDO -> chuanYunManager.delete(ChuanyunMonthLaborCostWgDO.SCHEMA_CODE, chuanyunMonthLaborCostWgDO.getObjectId()));
|
|
|
+ }
|
|
|
+ log.info("完成");
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void implCostTest() {
|
|
|
+ workGroupService.implAllCost();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void push() {
|
|
|
+ workGroupService.pushToChuanyun();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|