|
@@ -0,0 +1,335 @@
|
|
|
+package com.galaxis.manatee.service.impl;
|
|
|
+
|
|
|
+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.entity.chuanyun.data.object.*;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.dto.*;
|
|
|
+import com.galaxis.manatee.event.PushImplCostEvent;
|
|
|
+import com.galaxis.manatee.exception.BigSizeException;
|
|
|
+import com.galaxis.manatee.manager.ChuanYunManager;
|
|
|
+import com.galaxis.manatee.service.WorkGroupService;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 工作组相关操作
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class WorkGroupServiceImpl implements WorkGroupService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ChuanYunManager chuanYunManager;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ChuanyunImplCostDao implCostDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ChuanyunReimbursementDao reimbursementDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplicationContext applicationContext;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 汇算工作组级别实施费用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void implCost() {
|
|
|
+ // 查询立项表中数据
|
|
|
+ List<ChuanyunBuildProject> buildProjectList = findAll();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ // 查询组织架构录入
|
|
|
+ buildProjectList.parallelStream().forEach(chuanyunBuildProject -> {
|
|
|
+ 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");
|
|
|
+ for (String userId : userIdList) {
|
|
|
+ // 查询用户在该项目的报销单
|
|
|
+ List<ChuanyunReimbursementDO> reimbursements = reimbursementDao.findAllByGroupProjectIdAndReimburseUserIdAndStatusIn(chuanyunGroupProjectDO.getObjectId(), userId, List.of(1, 2));
|
|
|
+ BigDecimal totalReim = reimbursements.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ total = total.add(totalReim);
|
|
|
+ /*Filter f = Filter.instance(0, 10, true, Filter.AND, List.of("F0000093_2," + chuanyunGroupProjectDO.getObjectId(), "F0000001_2," + userId));
|
|
|
+ ChuanyunFindAllBizDTO<Object> reimbursementResponse = null;
|
|
|
+ try {
|
|
|
+ reimbursementResponse = chuanYunManager.findAll(ChuanyunReimbursementDO.SCHEMA_CODE, f);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (!reimbursementResponse.getSuccessful() || reimbursementResponse.getReturnData() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<ChuanyunReimbursementDO> reimbursementDOList = objectMapper.convertValue(reimbursementResponse.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ });
|
|
|
+ BigDecimal totalReim = reimbursementDOList.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ total = total.add(totalReim);*/
|
|
|
+
|
|
|
+ }
|
|
|
+ // 统计工作组所有的工时
|
|
|
+ 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();
|
|
|
+ if (Objects.isNull(oldImplCost) || oldImplCost.compareTo(total) != 0) {
|
|
|
+ old.setImplCost(total);
|
|
|
+ implCostDao.save(old);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ChuanyunImplCostDO chuanyunImplCostDO = new ChuanyunImplCostDO();
|
|
|
+ chuanyunImplCostDO.setProjectId(projectObjectId);
|
|
|
+ chuanyunImplCostDO.setProjectCode(projectCode);
|
|
|
+ chuanyunImplCostDO.setWorkGroup(workGroupId);
|
|
|
+ chuanyunImplCostDO.setWorkGroupName(chuanyunWorkGroupDO.getWorkGroupName());
|
|
|
+ chuanyunImplCostDO.setImplCost(total);
|
|
|
+ implCostDao.saveAndFlush(chuanyunImplCostDO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 上传至氚云数据库,发布上传事件
|
|
|
+ applicationContext.publishEvent(new PushImplCostEvent(this));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ChuanyunBuildProject> findAll() {
|
|
|
+ ArrayList<ChuanyunBuildProject> buildProjects = new ArrayList<>();
|
|
|
+ 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();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ List<ChuanyunBuildProject> bpList = objectMapper.convertValue(bizObjectArray, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ buildProjects.addAll(bpList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return buildProjects;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void pushToChuanyun() {
|
|
|
+
|
|
|
+ List<ChuanyunImplCostDO> all = implCostDao.findAll();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ all.forEach(implCostDO -> {
|
|
|
+ String projectId = implCostDO.getProjectId();
|
|
|
+ String projectCode = implCostDO.getProjectCode();
|
|
|
+ String workGroup = implCostDO.getWorkGroup();
|
|
|
+ List<String> m = List.of("F0000001_2," + projectId, "F0000002_2," + projectCode, "F0000006_2," + workGroup);
|
|
|
+ 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 (chuanyunImplCostDO.getImplCost().compareTo(implCostDO.getImplCost()) != 0) {
|
|
|
+ // 工作组实施费用发生变化
|
|
|
+ log.info("更新项目工作组实施费用");
|
|
|
+ ImplCostUpdateDTO implCostUpdateDTO = new ImplCostUpdateDTO(implCostDO.getImplCost());
|
|
|
+ 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("上传项目工作组实施费用完成");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ static class ImplCostUpdateDTO {
|
|
|
+ @JsonProperty("F0000004")
|
|
|
+ private BigDecimal implCost;
|
|
|
+
|
|
|
+ public ImplCostUpdateDTO(BigDecimal implCost) {
|
|
|
+ this.implCost = implCost;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChuanyunWorkGroupDO findByObjectId(String objectId) {
|
|
|
+ ChuanyunFindBizDTO<Object> objectChuanyunFindBizDTO = chuanYunManager.find(ChuanyunWorkGroupDO.SCHEMA_CODE, objectId);
|
|
|
+ if (!Objects.isNull(objectChuanyunFindBizDTO)) {
|
|
|
+ ChuanyunFindBizReturnData<Object> returnData = objectChuanyunFindBizDTO.getReturnData();
|
|
|
+ if (objectChuanyunFindBizDTO.getSuccessful() && !Objects.isNull(returnData)) {
|
|
|
+ Object bizObject = returnData.getBizObject();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ ChuanyunWorkGroupDO chuanyunWorkGroupDO = objectMapper.convertValue(bizObject, ChuanyunWorkGroupDO.class);
|
|
|
+ if (chuanyunWorkGroupDO != null) {
|
|
|
+ return chuanyunWorkGroupDO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.warn("无该工作组");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ChuanyunWorkGroupDO> findByParentObjectId(String parentObjectId) {
|
|
|
+ List<String> m = List.of("parentObjectId_2," + parentObjectId);
|
|
|
+ Filter filter = Filter.instance(0, 50, true, Filter.AND, m);
|
|
|
+ ChuanyunFindAllBizDTO<Object> response = null;
|
|
|
+ try {
|
|
|
+ response = chuanYunManager.findAll(ChuanyunWorkGroupDO.SCHEMA_CODE, filter);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (!Objects.isNull(response)) {
|
|
|
+ ChuanyunFindAllBizReturnData<Object> returnData = response.getReturnData();
|
|
|
+ if (response.getSuccessful() && !Objects.isNull(returnData)) {
|
|
|
+ List<Object> bizObjectArray = returnData.getBizObjectArray();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ List<ChuanyunWorkGroupDO> workGroupList = objectMapper.convertValue(bizObjectArray, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ if (!workGroupList.isEmpty()) {
|
|
|
+ return workGroupList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.warn("无该工作组");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChuanyunWorkGroupDO findInHistoryByObjectId(String objectId) {
|
|
|
+ ChuanyunFindBizDTO<Object> objectChuanyunFindBizDTO = chuanYunManager.find("D001789f1de93b6cb324bb5a35290e7c59a0ebc", objectId);
|
|
|
+ if (!Objects.isNull(objectChuanyunFindBizDTO)) {
|
|
|
+ ChuanyunFindBizReturnData<Object> returnData = objectChuanyunFindBizDTO.getReturnData();
|
|
|
+ if (objectChuanyunFindBizDTO.getSuccessful() && !Objects.isNull(returnData)) {
|
|
|
+ Object bizObject = returnData.getBizObject();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ ChuanyunWorkGroupDO chuanyunWorkGroupDO = objectMapper.convertValue(bizObject, ChuanyunWorkGroupDO.class);
|
|
|
+ if (chuanyunWorkGroupDO != null) {
|
|
|
+ return chuanyunWorkGroupDO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.warn("组织架构查询中无该工作组");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|