From b0fd64098134466414d22af52baa823245839070 Mon Sep 17 00:00:00 2001 From: kongdeqiang <123456> Date: 星期一, 31 三月 2025 16:48:18 +0800 Subject: [PATCH] fix: 年度投资计划接口 --- platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/InvestmentPlanController.java | 77 ++++++++++++++++++++++++++++++++++---- 1 files changed, 69 insertions(+), 8 deletions(-) diff --git a/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/InvestmentPlanController.java b/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/InvestmentPlanController.java index 24d7d1b..ce63b93 100644 --- a/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/InvestmentPlanController.java +++ b/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/InvestmentPlanController.java @@ -3,18 +3,17 @@ import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.by4cloud.platformx.common.core.util.R; import com.by4cloud.platformx.common.log.annotation.SysLog; import com.by4cloud.platformx.device.constant.MaxSizeContant; -import com.by4cloud.platformx.device.entity.DeviceDemandPlan; -import com.by4cloud.platformx.device.entity.InvestmentPlan; -import com.by4cloud.platformx.device.service.DeviceDemandPlanService; -import com.by4cloud.platformx.device.service.InvestmentPlanService; -import com.by4cloud.platformx.device.service.JcMaxSizeService; +import com.by4cloud.platformx.device.entity.*; +import com.by4cloud.platformx.device.service.*; import com.by4cloud.platformx.device.util.NumUtils; +import com.github.yulichang.adapter.base.ITableInfoAdapter; import org.springframework.security.access.prepost.PreAuthorize; import com.by4cloud.platformx.common.excel.annotation.ResponseExcel; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -25,8 +24,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Objects; +import java.util.*; +import java.util.stream.Collectors; /** * 骞村害鎶曡祫璁″垝涓昏〃 @@ -42,8 +41,11 @@ public class InvestmentPlanController { private final InvestmentPlanService investmentPlanService; + private final InvestmentPlanItemService investmentPlanItemService; private final DeviceDemandPlanService deviceDemandPlanService; + private final DeviceDemandSubService deviceDemandSubService; private final JcMaxSizeService maxSizeService; + private final DeviceService deviceService; /** * 鍒嗛〉鏌ヨ @@ -72,7 +74,25 @@ @GetMapping("/{id}" ) @PreAuthorize("@pms.hasPermission('device_investmentPlan_view')" ) public R getById(@PathVariable("id" ) Long id) { - return R.ok(investmentPlanService.getById(id)); + Map<String,Object> map = new HashMap<>(); + InvestmentPlan plan = investmentPlanService.getById(id); + QueryWrapper<InvestmentPlanItem> wrapper = new QueryWrapper<>(); + wrapper.lambda() + .eq(InvestmentPlanItem::getPlanId,plan.getId()) + .orderByAsc(InvestmentPlanItem::getMonth); + List<InvestmentPlanItem> list = investmentPlanItemService.list(wrapper); + List<Map<String,Object>> resultList = new ArrayList<>(); + for (Map.Entry<Integer, List<InvestmentPlanItem>> listEntry : list.stream().collect(Collectors.groupingBy(item -> item.getMonth())).entrySet()) { + Integer month = listEntry.getKey(); + List<InvestmentPlanItem> value = listEntry.getValue(); + Map<String,Object> entry = new HashMap<>(); + entry.put("month",month); + entry.put("value",value); + resultList.add(entry); + } + map.put("plan",plan); + map.put("items",resultList); + return R.ok(map); } /** @@ -85,9 +105,50 @@ @PostMapping @PreAuthorize("@pms.hasPermission('device_investmentPlan_add')" ) public R save(@RequestBody InvestmentPlan investmentPlan) { + List<DeviceDemandSub> subs = new ArrayList<>(); investmentPlan.setNumber(maxSizeService.nextNo(MaxSizeContant.TZPLAN_NUM)); investmentPlanService.save(investmentPlan); + String planIds = investmentPlan.getPlanIds(); + String[] split = planIds.split(","); + for (String s : split) { + DeviceDemandPlan demandPlan = deviceDemandPlanService.getById(Long.parseLong(s)); + QueryWrapper<DeviceDemandPlan> wrapper = new QueryWrapper<>(); + wrapper.lambda() + .eq(DeviceDemandPlan::getPlanId,demandPlan.getId()); + List<DeviceDemandPlan> list = deviceDemandPlanService.list(wrapper); + List<Long> collect = list.stream().map(DeviceDemandPlan::getId).collect(Collectors.toList()); + for (Long l : collect) { + //鍚堝苟瀛愰」 + List<DeviceDemandSub> byPlanId = deviceDemandSubService.getByPlanId(l); + subs.addAll(byPlanId); + } + } + List<InvestmentPlanItem> items = new ArrayList<>(); + for (Map.Entry<Integer, List<DeviceDemandSub>> integerListEntry : subs.stream().collect(Collectors.groupingBy(item -> item.getMonth())).entrySet()) { + Integer month = integerListEntry.getKey(); + List<DeviceDemandSub> subList = integerListEntry.getValue(); + for (Map.Entry<Long, List<DeviceDemandSub>> deviceEntry : subList.stream().collect(Collectors.groupingBy(item -> item.getDeviceId())).entrySet()) { + Long deviceId = deviceEntry.getKey(); + List<DeviceDemandSub> value = deviceEntry.getValue(); + double total = value.stream().mapToDouble(DeviceDemandSub::getPrice).sum(); + + Device device = deviceService.getById(deviceId); + InvestmentPlanItem item = new InvestmentPlanItem(); + item.setYear(value.get(0).getYear()); + item.setPlanId(investmentPlan.getId()); + item.setMonth(month); + item.setDeviceId(deviceId); + item.setNumber(device.getNumber()); + item.setSpecification(device.getSpecification()); + item.setNum(value.size()); + item.setUnit(device.getUnit()); + item.setPrice(device.getPrice()); + item.setAmount(total); + items.add(item); + } + } + investmentPlanItemService.saveBatch(items); return R.ok(); } -- Gitblit v1.9.1