|
@@ -6,6 +6,7 @@ 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.event.PushImplCostEvent;
|
|
@@ -20,6 +21,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
@@ -42,6 +44,9 @@ public class WorkGroupServiceImpl implements WorkGroupService {
|
|
|
private ChuanyunReimbursementDao reimbursementDao;
|
|
|
|
|
|
@Autowired
|
|
|
+ private ChuanyunSelfWorkHourDao selfWorkHourDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private ApplicationContext applicationContext;
|
|
|
|
|
|
|
|
@@ -49,116 +54,115 @@ public class WorkGroupServiceImpl implements WorkGroupService {
|
|
|
* 汇算工作组级别实施费用
|
|
|
*/
|
|
|
@Override
|
|
|
- @Async
|
|
|
public void implCost() {
|
|
|
// 查询立项表中数据
|
|
|
List<ChuanyunBuildProject> buildProjectList = findAll();
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
// 查询组织架构录入
|
|
|
+ final Object monitor = new Object();
|
|
|
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;
|
|
|
+ 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 {
|
|
|
- workGroupResponse = chuanYunManager.findAll(ChuanyunWorkGroupDO.SCHEMA_CODE, Filter.instance(0, 30, true, Filter.AND, m2));
|
|
|
+ projectList = chuanYunManager.findAll(ChuanyunProjectOrganizationStructureDO.SCHEMA_CODE, filter);
|
|
|
} catch (JsonProcessingException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- if (workGroupResponse == null || !workGroupResponse.getSuccessful()) {
|
|
|
+ if (projectList == null || projectList.getReturnData() == null) {
|
|
|
return;
|
|
|
}
|
|
|
- if (workGroupResponse.getReturnData() == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- List<ChuanyunWorkGroupDO> workGroupList = objectMapper.convertValue(workGroupResponse.getReturnData().getBizObjectArray(), new TypeReference<>() {
|
|
|
+ List<ChuanyunProjectOrganizationStructureDO> projectOrganizationStructureList = objectMapper.convertValue(projectList.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;
|
|
|
+ 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 {
|
|
|
- groupProjectResponse = chuanYunManager.findAll(ChuanyunGroupProjectDO.SCHEMA_CODE, instance);
|
|
|
+ workGroupResponse = chuanYunManager.findAll(ChuanyunWorkGroupDO.SCHEMA_CODE, Filter.instance(0, 30, true, Filter.AND, m2));
|
|
|
} catch (JsonProcessingException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- if (!groupProjectResponse.getSuccessful() || groupProjectResponse.getReturnData() == null) {
|
|
|
+ if (workGroupResponse == null || !workGroupResponse.getSuccessful()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (workGroupResponse.getReturnData() == null) {
|
|
|
return;
|
|
|
}
|
|
|
- List<Object> bizObjectArray = groupProjectResponse.getReturnData().getBizObjectArray();
|
|
|
- List<ChuanyunGroupProjectDO> groupProjectDOList = objectMapper.convertValue(bizObjectArray, new TypeReference<>() {
|
|
|
+ List<ChuanyunWorkGroupDO> workGroupList = objectMapper.convertValue(workGroupResponse.getReturnData().getBizObjectArray(), 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;
|
|
|
+ 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 totalReim = reimbursements.stream().map(ChuanyunReimbursementDO::getTotalAmountNotTaxed).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ total = total.add(totalReim);
|
|
|
+ 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);
|
|
|
+
|
|
|
}
|
|
|
- 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();
|
|
|
|
|
|
- }
|
|
|
- // 统计工作组所有的工时
|
|
|
- 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);
|
|
|
+ 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);
|
|
|
}
|
|
|
- } else {
|
|
|
- ChuanyunImplCostDO chuanyunImplCostDO = new ChuanyunImplCostDO();
|
|
|
- chuanyunImplCostDO.setProjectId(projectObjectId);
|
|
|
- chuanyunImplCostDO.setProjectCode(projectCode);
|
|
|
- chuanyunImplCostDO.setWorkGroup(workGroupId);
|
|
|
- chuanyunImplCostDO.setWorkGroupName(chuanyunWorkGroupDO.getWorkGroupName());
|
|
|
- chuanyunImplCostDO.setImplCost(total);
|
|
|
- implCostDao.saveAndFlush(chuanyunImplCostDO);
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// 上传至氚云数据库,发布上传事件
|
|
|
+ log.info("发布工作组实施费用上传事件");
|
|
|
applicationContext.publishEvent(new PushImplCostEvent(this));
|
|
|
|
|
|
|
|
@@ -203,7 +207,6 @@ public class WorkGroupServiceImpl implements WorkGroupService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Async
|
|
|
public void pushToChuanyun() {
|
|
|
|
|
|
List<ChuanyunImplCostDO> all = implCostDao.findAll();
|
|
@@ -229,10 +232,12 @@ public class WorkGroupServiceImpl implements WorkGroupService {
|
|
|
Optional<ChuanyunImplCostDO> implCostOptional = chuanyunImplCostDOList.stream().findFirst();
|
|
|
if (implCostOptional.isPresent()) {
|
|
|
ChuanyunImplCostDO chuanyunImplCostDO = implCostOptional.get();
|
|
|
- if (chuanyunImplCostDO.getImplCost().compareTo(implCostDO.getImplCost()) != 0) {
|
|
|
+ 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());
|
|
|
+ ImplCostUpdateDTO implCostUpdateDTO = new ImplCostUpdateDTO(implCostDO.getImplCost(), implCostDO.getManDay());
|
|
|
try {
|
|
|
String updateStr = objectMapper.writeValueAsString(implCostUpdateDTO);
|
|
|
chuanYunManager.update(ChuanyunImplCostDO.SCHEMA_CODE, chuanyunImplCostDO.getObjectId(), updateStr);
|
|
@@ -266,8 +271,12 @@ public class WorkGroupServiceImpl implements WorkGroupService {
|
|
|
@JsonProperty("F0000004")
|
|
|
private BigDecimal implCost;
|
|
|
|
|
|
- public ImplCostUpdateDTO(BigDecimal implCost) {
|
|
|
+ @JsonProperty("F0000007")
|
|
|
+ private BigDecimal manDay;
|
|
|
+
|
|
|
+ public ImplCostUpdateDTO(BigDecimal implCost, BigDecimal manDay) {
|
|
|
this.implCost = implCost;
|
|
|
+ this.manDay = manDay;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -316,20 +325,22 @@ public class WorkGroupServiceImpl implements WorkGroupService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ChuanyunWorkGroupDO findInHistoryByObjectId(String objectId) {
|
|
|
- ChuanyunFindBizDTO<Object> objectChuanyunFindBizDTO = chuanYunManager.find("D001789f1de93b6cb324bb5a35290e7c59a0ebc", objectId);
|
|
|
+ public ChuanyunHistoryWorkGroupDO findInHistoryByObjectId(String objectId) {
|
|
|
+ ChuanyunFindBizDTO<Object> objectChuanyunFindBizDTO = chuanYunManager.find(ChuanyunHistoryWorkGroupDO.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;
|
|
|
+ ChuanyunHistoryWorkGroupDO chuanyunHistoryWorkGroupDO = objectMapper.convertValue(bizObject, ChuanyunHistoryWorkGroupDO.class);
|
|
|
+ if (chuanyunHistoryWorkGroupDO != null) {
|
|
|
+ return chuanyunHistoryWorkGroupDO;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
log.warn("组织架构查询中无该工作组");
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|