修改bug
This commit is contained in:
@ -5,10 +5,13 @@ import cn.hutool.core.io.FileUtil;
|
|||||||
import cn.hutool.core.util.IdcardUtil;
|
import cn.hutool.core.util.IdcardUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.common.core.constant.HttpStatus;
|
||||||
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.utils.IdCardEncryptorUtil;
|
import org.dromara.common.utils.IdCardEncryptorUtil;
|
||||||
import org.dromara.contractor.domain.SubConstructionUser;
|
import org.dromara.contractor.domain.SubConstructionUser;
|
||||||
import org.dromara.contractor.service.ISubConstructionUserService;
|
import org.dromara.contractor.service.ISubConstructionUserService;
|
||||||
@ -19,7 +22,12 @@ import org.dromara.facility.service.IFacMatrixService;
|
|||||||
import org.dromara.facility.service.IFacPhotovoltaicPanelPartsService;
|
import org.dromara.facility.service.IFacPhotovoltaicPanelPartsService;
|
||||||
import org.dromara.facility.service.IFacPhotovoltaicPanelService;
|
import org.dromara.facility.service.IFacPhotovoltaicPanelService;
|
||||||
import org.dromara.manager.recognizermanager.vo.RecognizeConvertCoordinateResult;
|
import org.dromara.manager.recognizermanager.vo.RecognizeConvertCoordinateResult;
|
||||||
|
import org.dromara.out.domain.OutConstructionValue;
|
||||||
|
import org.dromara.out.domain.OutConstructionValueRange;
|
||||||
|
import org.dromara.out.service.IOutConstructionValueRangeService;
|
||||||
|
import org.dromara.out.service.IOutConstructionValueService;
|
||||||
import org.dromara.progress.domain.PgsProgressCategory;
|
import org.dromara.progress.domain.PgsProgressCategory;
|
||||||
|
import org.dromara.progress.domain.PgsProgressPlanDetail;
|
||||||
import org.dromara.progress.domain.dto.progresscategory.PgsProgressCategoryCreateReq;
|
import org.dromara.progress.domain.dto.progresscategory.PgsProgressCategoryCreateReq;
|
||||||
import org.dromara.progress.service.IPgsProgressCategoryService;
|
import org.dromara.progress.service.IPgsProgressCategoryService;
|
||||||
import org.dromara.progress.service.IPgsProgressCategoryTemplateService;
|
import org.dromara.progress.service.IPgsProgressCategoryTemplateService;
|
||||||
@ -34,10 +42,10 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
import java.time.DayOfWeek;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Date;
|
import java.time.temporal.TemporalAdjusters;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -87,6 +95,13 @@ public class DemoTest {
|
|||||||
@Resource
|
@Resource
|
||||||
private IFacPhotovoltaicPanelService photovoltaicPanelService;
|
private IFacPhotovoltaicPanelService photovoltaicPanelService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IOutConstructionValueRangeService constructionValueRangeService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IOutConstructionValueService constructionValueService;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConstructionValue() {
|
void testConstructionValue() {
|
||||||
/* LocalDate today = LocalDate.now();
|
/* LocalDate today = LocalDate.now();
|
||||||
@ -98,17 +113,172 @@ public class DemoTest {
|
|||||||
LocalDate lastSunday = lastMonday.plusDays(6);
|
LocalDate lastSunday = lastMonday.plusDays(6);
|
||||||
log.info("执行定时任务:同步 {}至{} 计划详情到施工产值", lastMonday, lastSunday);
|
log.info("执行定时任务:同步 {}至{} 计划详情到施工产值", lastMonday, lastSunday);
|
||||||
Boolean synced = progressPlanDetailService.syncPlanDetail2ConstructionValue(lastMonday, lastSunday, null);*/
|
Boolean synced = progressPlanDetailService.syncPlanDetail2ConstructionValue(lastMonday, lastSunday, null);*/
|
||||||
|
LocalDate start = LocalDate.of(2024, 1, 1); // 起始时间(2024-01-01)
|
||||||
|
LocalDate end = LocalDate.of(2025, 9, 15); // 截止时间(2025-09-15)
|
||||||
|
|
||||||
LocalDate today = LocalDate.of(2025, 9, 16);
|
// 如果起始不是周一,调整到当周的周一
|
||||||
LocalDate localDate = today.minusDays(1);
|
if (start.getDayOfWeek() != DayOfWeek.MONDAY) {
|
||||||
|
start = start.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!start.isAfter(end)) {
|
||||||
|
LocalDate monday = start;
|
||||||
|
LocalDate sunday = start.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
||||||
|
|
||||||
|
// 输出本周的周一和周日
|
||||||
|
System.out.println(monday + " ~ " + sunday);
|
||||||
|
log.info("执行定时任务:同步 {}至{} 计划详情到施工产值", monday, sunday);
|
||||||
|
// Boolean synced = progressPlanDetailService.syncPlanDetail2ConstructionValue(start, now, null);
|
||||||
|
// 获取范围时间内的计划详情
|
||||||
|
List<PgsProgressPlanDetail> planDetailList = progressPlanDetailService.lambdaQuery()
|
||||||
|
.ge(PgsProgressPlanDetail::getDate, monday)
|
||||||
|
.le(PgsProgressPlanDetail::getDate, sunday)
|
||||||
|
.ne(PgsProgressPlanDetail::getFinishedNumber, BigDecimal.ZERO)
|
||||||
|
.eq(PgsProgressPlanDetail::getStatus, "1")
|
||||||
|
.list();
|
||||||
|
if (CollUtil.isEmpty(planDetailList)) {
|
||||||
|
// 下一周
|
||||||
|
start = start.plusWeeks(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 获取进度类别
|
||||||
|
List<Long> categoryIds = planDetailList.stream()
|
||||||
|
.map(PgsProgressPlanDetail::getProgressCategoryId)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
List<PgsProgressCategory> categoryList = progressCategoryService.lambdaQuery()
|
||||||
|
.in(CollUtil.isNotEmpty(categoryIds), PgsProgressCategory::getId, categoryIds)
|
||||||
|
.list();
|
||||||
|
Map<Long, PgsProgressCategory> categoryMap = categoryList.stream()
|
||||||
|
.collect(
|
||||||
|
Collectors.toMap(PgsProgressCategory::getId,
|
||||||
|
Function.identity(),
|
||||||
|
(v1, v2) -> v1)
|
||||||
|
);
|
||||||
|
// 为每一个项目创建一个施工产值范围
|
||||||
|
Set<Long> projectIds = planDetailList.stream()
|
||||||
|
.map(PgsProgressPlanDetail::getProjectId).collect(Collectors.toSet());
|
||||||
|
// 获取所有父级项目
|
||||||
|
List<BusProject> projectList = projectService.listByIds(projectIds);
|
||||||
|
List<Long> allProjectIds = projectList
|
||||||
|
.stream().map(project -> {
|
||||||
|
if (project.getPId() != 0L) {
|
||||||
|
return project.getPId();
|
||||||
|
} else {
|
||||||
|
return project.getId();
|
||||||
|
}
|
||||||
|
}).distinct().toList();
|
||||||
|
// 根据项目区分
|
||||||
|
Map<Long, List<PgsProgressPlanDetail>> detailMap = planDetailList.stream()
|
||||||
|
.collect(Collectors.groupingBy(PgsProgressPlanDetail::getProjectId));
|
||||||
|
List<OutConstructionValue> saveList = new ArrayList<>();
|
||||||
|
List<PgsProgressPlanDetail> allUpdateList = new ArrayList<>();
|
||||||
|
List<OutConstructionValueRange> ranges = allProjectIds.stream().map(id -> {
|
||||||
|
OutConstructionValueRange range = new OutConstructionValueRange();
|
||||||
|
long rangeId = IdWorker.getId(range);
|
||||||
|
range.setId(rangeId);
|
||||||
|
range.setProjectId(id);
|
||||||
|
range.setStartDate(monday);
|
||||||
|
range.setEndDate(sunday);
|
||||||
|
// 获取所有子项目
|
||||||
|
List<Long> subProject = new ArrayList<>(projectList.stream()
|
||||||
|
.filter(project -> Objects.equals(project.getPId(), id))
|
||||||
|
.map(BusProject::getId)
|
||||||
|
.distinct()
|
||||||
|
.toList());
|
||||||
|
subProject.add(id);
|
||||||
|
List<PgsProgressPlanDetail> detailList = new ArrayList<>();
|
||||||
|
for (Long p : subProject) {
|
||||||
|
List<PgsProgressPlanDetail> details = detailMap.getOrDefault(p, List.of());
|
||||||
|
detailList.addAll(details);
|
||||||
|
}
|
||||||
|
if (CollUtil.isEmpty(detailList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BigDecimal allConstructionValue = BigDecimal.ZERO;
|
||||||
|
BigDecimal allOwnerValue = BigDecimal.ZERO;
|
||||||
|
List<PgsProgressPlanDetail> updateList = new ArrayList<>();
|
||||||
|
for (PgsProgressPlanDetail planDetail : detailList) {
|
||||||
|
OutConstructionValue value = new OutConstructionValue();
|
||||||
|
Long progressCategoryId = planDetail.getProgressCategoryId();
|
||||||
|
PgsProgressCategory category = categoryMap.get(progressCategoryId);
|
||||||
|
if (category == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
value.setProjectId(id);
|
||||||
|
value.setRangeId(rangeId);
|
||||||
|
value.setMatrixId(category.getMatrixId());
|
||||||
|
value.setProgressCategoryId(progressCategoryId);
|
||||||
|
value.setDetailId(planDetail.getId());
|
||||||
|
BigDecimal finishedNumber = planDetail.getFinishedNumber();
|
||||||
|
BigDecimal aiFill = planDetail.getAiFill();
|
||||||
|
// 如果完成数量为0, 则不保存
|
||||||
|
if (finishedNumber.compareTo(BigDecimal.ZERO) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
value.setArtificialNum(finishedNumber.subtract(aiFill).intValue());
|
||||||
|
value.setUavNum(aiFill.intValue());
|
||||||
|
value.setPlanNum(planDetail.getPlanNumber().intValue());
|
||||||
|
value.setReportDate(planDetail.getDate());
|
||||||
|
value.setPlanDate(planDetail.getDate());
|
||||||
|
// 计算产值
|
||||||
|
BigDecimal constructionPrice = category.getConstructionPrice();
|
||||||
|
BigDecimal ownerPrice = category.getOwnerPrice();
|
||||||
|
BigDecimal constructionValue = constructionPrice.multiply(finishedNumber).setScale(4, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal ownerValue = ownerPrice.multiply(finishedNumber).setScale(4, RoundingMode.HALF_UP);
|
||||||
|
value.setOutValue(constructionValue);
|
||||||
|
value.setOwnerValue(ownerValue);
|
||||||
|
// 统计总产值
|
||||||
|
allConstructionValue = allConstructionValue.add(constructionValue).setScale(4, RoundingMode.HALF_UP);
|
||||||
|
allOwnerValue = allOwnerValue.add(ownerValue).setScale(4, RoundingMode.HALF_UP);
|
||||||
|
// 添加需要修改状态的计划详情
|
||||||
|
PgsProgressPlanDetail update = new PgsProgressPlanDetail();
|
||||||
|
update.setId(planDetail.getId());
|
||||||
|
update.setStatus("2");
|
||||||
|
updateList.add(update);
|
||||||
|
saveList.add(value);
|
||||||
|
}
|
||||||
|
range.setOutValue(allConstructionValue);
|
||||||
|
range.setOwnerValue(allOwnerValue);
|
||||||
|
// 如果产值都为0,则不保存
|
||||||
|
if (allConstructionValue.compareTo(BigDecimal.ZERO) == 0 && allOwnerValue.compareTo(BigDecimal.ZERO) == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
allUpdateList.addAll(updateList);
|
||||||
|
return range;
|
||||||
|
}).filter(Objects::nonNull).toList();
|
||||||
|
// 保存数据
|
||||||
|
if (CollUtil.isNotEmpty(ranges)) {
|
||||||
|
boolean saveBatch = constructionValueRangeService.saveBatch(ranges);
|
||||||
|
if (!saveBatch) {
|
||||||
|
throw new ServiceException("同步计划详情到施工产值失败,数据库异常", HttpStatus.ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(saveList)) {
|
||||||
|
boolean saved = constructionValueService.saveBatch(saveList);
|
||||||
|
if (!saved) {
|
||||||
|
throw new ServiceException("同步计划详情到施工产值失败,数据库异常", HttpStatus.ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollUtil.isNotEmpty(allUpdateList)) {
|
||||||
|
boolean updateBatch = progressPlanDetailService.updateBatchById(allUpdateList);
|
||||||
|
if (!updateBatch) {
|
||||||
|
throw new ServiceException("同步计划详情到施工产值失败,数据库异常", HttpStatus.ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// 下一周
|
||||||
|
start = start.plusWeeks(1);
|
||||||
|
}
|
||||||
|
/* LocalDate today = LocalDate.of(2025, 9, 16);
|
||||||
|
LocalDate localDate = today.minusDays(1);*/
|
||||||
/* // 找到本周一
|
/* // 找到本周一
|
||||||
LocalDate thisMonday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
LocalDate thisMonday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
||||||
// 上周一 = 本周一 - 1 周
|
// 上周一 = 本周一 - 1 周
|
||||||
LocalDate lastMonday = thisMonday.minusWeeks(1);
|
LocalDate lastMonday = thisMonday.minusWeeks(1);
|
||||||
// 上周日 = 上周一 + 6 天
|
// 上周日 = 上周一 + 6 天
|
||||||
LocalDate lastSunday = lastMonday.plusDays(6);*/
|
LocalDate lastSunday = lastMonday.plusDays(6);*/
|
||||||
log.info("执行定时任务:同步 {}至{} 计划详情到施工产值", localDate, localDate);
|
|
||||||
Boolean synced = progressPlanDetailService.syncPlanDetail2ConstructionValue(localDate, localDate, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -175,6 +175,17 @@ public class OutConstructionValueRangeServiceImpl extends ServiceImpl<OutConstru
|
|||||||
OutConstructionValueRange byId = this.getById(Convert.toLong(processEvent.getBusinessId()));
|
OutConstructionValueRange byId = this.getById(Convert.toLong(processEvent.getBusinessId()));
|
||||||
byId.setAuditStatus(processEvent.getStatus());
|
byId.setAuditStatus(processEvent.getStatus());
|
||||||
if (processEvent.getSubmit()) {
|
if (processEvent.getSubmit()) {
|
||||||
|
// 设置确认数量默认值
|
||||||
|
List<OutConstructionValue> valueList = constructionValueService.lambdaQuery()
|
||||||
|
.eq(OutConstructionValue::getRangeId, byId.getId())
|
||||||
|
.list();
|
||||||
|
List<OutConstructionValue> list = valueList.stream()
|
||||||
|
.filter(value -> value.getConfirmNum() == null || value.getConfirmNum() == 0)
|
||||||
|
.peek(value -> value.setConfirmNum(value.getArtificialNum() != null ? value.getArtificialNum() : value.getUavNum()))
|
||||||
|
.toList();
|
||||||
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
|
constructionValueService.updateBatchById(list);
|
||||||
|
}
|
||||||
byId.setAuditStatus(BusinessStatusEnum.WAITING.getStatus());
|
byId.setAuditStatus(BusinessStatusEnum.WAITING.getStatus());
|
||||||
}
|
}
|
||||||
// 如果为完成状态,则锁定对应进度计划详情
|
// 如果为完成状态,则锁定对应进度计划详情
|
||||||
|
|||||||
@ -965,7 +965,7 @@ public class PgsProgressPlanDetailServiceImpl extends ServiceImpl<PgsProgressPla
|
|||||||
value.setArtificialNum(finishedNumber.subtract(aiFill).intValue());
|
value.setArtificialNum(finishedNumber.subtract(aiFill).intValue());
|
||||||
value.setUavNum(aiFill.intValue());
|
value.setUavNum(aiFill.intValue());
|
||||||
value.setPlanNum(planDetail.getPlanNumber().intValue());
|
value.setPlanNum(planDetail.getPlanNumber().intValue());
|
||||||
value.setReportDate(now.minusDays(1));
|
value.setReportDate(planDetail.getDate());
|
||||||
value.setPlanDate(planDetail.getDate());
|
value.setPlanDate(planDetail.getDate());
|
||||||
// 计算产值
|
// 计算产值
|
||||||
BigDecimal constructionPrice = category.getConstructionPrice();
|
BigDecimal constructionPrice = category.getConstructionPrice();
|
||||||
@ -1042,7 +1042,7 @@ public class PgsProgressPlanDetailServiceImpl extends ServiceImpl<PgsProgressPla
|
|||||||
value.setArtificialNum(finishedNumber.subtract(aiFill).intValue());
|
value.setArtificialNum(finishedNumber.subtract(aiFill).intValue());
|
||||||
value.setUavNum(aiFill.intValue());
|
value.setUavNum(aiFill.intValue());
|
||||||
value.setPlanNum(planDetail.getPlanNumber().intValue());
|
value.setPlanNum(planDetail.getPlanNumber().intValue());
|
||||||
value.setReportDate(now.minusDays(1));
|
value.setReportDate(planDetail.getDate());
|
||||||
value.setPlanDate(planDetail.getDate());
|
value.setPlanDate(planDetail.getDate());
|
||||||
// 计算产值
|
// 计算产值
|
||||||
BigDecimal constructionPrice = category.getConstructionPrice();
|
BigDecimal constructionPrice = category.getConstructionPrice();
|
||||||
|
|||||||
Reference in New Issue
Block a user