kongdeqiang
2025-04-02 faf27b105f85b5b11e75f2fa041c2f53229794de
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandPlanController.java
@@ -3,12 +3,19 @@
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.common.security.util.SecurityUtils;
import com.by4cloud.platformx.device.constant.MaxSizeContant;
import com.by4cloud.platformx.device.entity.Device;
import com.by4cloud.platformx.device.entity.DeviceDemandPlan;
import com.by4cloud.platformx.device.service.DeviceDemandPlanService;
import com.by4cloud.platformx.device.entity.DeviceDemandSub;
import com.by4cloud.platformx.device.service.*;
import com.by4cloud.platformx.device.util.NumUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import com.by4cloud.platformx.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -19,8 +26,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;
/**
 * 设备需求计划主表
@@ -36,6 +43,10 @@
public class DeviceDemandPlanController {
    private final  DeviceDemandPlanService deviceDemandPlanService;
    private final DeviceDemandTotalService deviceDemandTotalService;
    private final DeviceDemandSubService deviceDemandSubService;
    private final JcMaxSizeService maxSizeService;
    private final DeviceService deviceService;
    /**
     * 分页查询
@@ -43,13 +54,35 @@
     * @param deviceDemandPlan 设备需求计划主表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @Operation(summary = "本单位分页查询" , description = "本单位分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandPlan_view')" )
    public R getDeviceDemandPlanPage(@ParameterObject Page page, @ParameterObject DeviceDemandPlan deviceDemandPlan) {
        LambdaQueryWrapper<DeviceDemandPlan> wrapper = Wrappers.lambdaQuery();
        return R.ok(deviceDemandPlanService.page(page, wrapper));
      wrapper.eq(deviceDemandPlan.getDeclareCompId() !=null,DeviceDemandPlan::getDeclareCompId,deviceDemandPlan.getDeclareCompId());
      wrapper.eq(deviceDemandPlan.getReleasePerson() !=null,DeviceDemandPlan::getReleasePerson,deviceDemandPlan.getReleasePerson());
      wrapper.eq(deviceDemandPlan.getYear() !=null,DeviceDemandPlan::getYear,deviceDemandPlan.getYear());
      wrapper.eq(DeviceDemandPlan::getType2,0);
      wrapper.orderByDesc(DeviceDemandPlan::getCreateTime);
        return R.ok(deviceDemandPlanService.pageByScope(page, wrapper));
    }
   /**
    * 分页查询2
    * @param page 分页对象
    * @param deviceDemandPlan 设备需求计划主表
    * @return
    */
   @Operation(summary = "本单位分页查询" , description = "本单位分页查询" )
   @GetMapping("/page2" )
   public R page2(@ParameterObject Page page, @ParameterObject DeviceDemandPlan deviceDemandPlan) {
      LambdaQueryWrapper<DeviceDemandPlan> wrapper = Wrappers.lambdaQuery();
      wrapper.eq(deviceDemandPlan.getDeclareCompId() !=null,DeviceDemandPlan::getDeclareCompId,deviceDemandPlan.getDeclareCompId());
      wrapper.eq(deviceDemandPlan.getReleasePerson() !=null,DeviceDemandPlan::getReleasePerson,deviceDemandPlan.getReleasePerson());
      wrapper.eq(deviceDemandPlan.getYear() !=null,DeviceDemandPlan::getYear,deviceDemandPlan.getYear());
      wrapper.eq(deviceDemandPlan.getStatus() !=null,DeviceDemandPlan::getStatus,deviceDemandPlan.getStatus());
      wrapper.eq(DeviceDemandPlan::getType2,1);
      return R.ok(deviceDemandPlanService.page(page, wrapper));
   }
    /**
@@ -74,9 +107,89 @@
    @PostMapping
    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandPlan_add')" )
    public R save(@RequestBody DeviceDemandPlan deviceDemandPlan) {
      deviceDemandPlan.setNumber(maxSizeService.nextNo(MaxSizeContant.PLAN_NUM));
      deviceDemandPlan.setType2(0);
        return R.ok(deviceDemandPlanService.save(deviceDemandPlan));
    }
   @Operation(summary = "合并计划提交" , description = "合并计划提交" )
   @GetMapping("/mergePlan" )
   public R mergePlan(String ids) {
      List<DeviceDemandSub> subs = new ArrayList<>();
      DeviceDemandPlan plan = new DeviceDemandPlan();
      deviceDemandPlanService.save(plan);
      Double aa = 0d;
      String name = SecurityUtils.getUser().getName();
      if(StringUtils.isNotBlank(ids)){
         String[] split = ids.split(",");
         for (String s : split) {
            long l = Long.parseLong(s);
            DeviceDemandPlan byId = deviceDemandPlanService.getById(l);
            byId.setPlanId(plan.getId());
            byId.setSendDate(new Date());
            deviceDemandPlanService.updateById(byId);
            plan.setYear(byId.getYear());
            plan.setType(byId.getType());
            aa= NumUtils.addDoubles(aa,byId.getAmount());
            //合并子项
            List<DeviceDemandSub> byPlanId = deviceDemandSubService.getByPlanId(l);
            subs.addAll(byPlanId);
         }
      }
      plan.setAmount(aa);
      plan.setReleasePerson(name);
      plan.setStatus(3);
      plan.setType2(1);
      if(subs.size()>0){
         deviceDemandPlanService.updateById(plan);
         return R.ok("提交成功");
      }else {
         return R.failed("请选择计划提交");
      }
   }
   @Operation(summary = "查看子项详情" , description = "查看子项详情" )
   @GetMapping("/getByMergePlanId/{id}" )
   public R getByMergePlanId(@PathVariable("id" ) Long id) {
      List<DeviceDemandSub> subs = new ArrayList<>();
      QueryWrapper<DeviceDemandPlan> wrapper = new QueryWrapper<>();
      wrapper.lambda()
            .eq(DeviceDemandPlan::getPlanId,id);
      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<Map<String,Object>> resultList = new ArrayList<>();
      for (Map.Entry<Integer, List<DeviceDemandSub>> integerListEntry : subs.stream().collect(Collectors.groupingBy(item -> item.getMonth())).entrySet()) {
         Integer month = integerListEntry.getKey();
         List<Map<String,Object>> mapList = new ArrayList<>();
         for (Map.Entry<Long, List<DeviceDemandSub>> entry : integerListEntry.getValue().stream().collect(Collectors.groupingBy(item -> item.getDeviceId())).entrySet()) {
            Long key = entry.getKey();
            int size = entry.getValue().size();
            Device device = deviceService.getById(key);
            Map<String,Object> map = new HashMap<>();
            map.put("deviceNumber",device.getNumber());
            map.put("name",device.getName());
            map.put("count",size);
            map.put("manu",device.getManu());
            map.put("beforeDate",device.getBeforeDate());
            map.put("depreciation",device.getDepreciation());
            map.put("remindDate",device.getRemindDate());
            mapList.add(map);
         }
         Map<String,Object> map = new HashMap<>();
         map.put("month",month);
         map.put("deviceList",mapList);
         resultList.add(map);
      }
      return R.ok(resultList);
   }
    /**
     * 修改设备需求计划主表
     * @param deviceDemandPlan 设备需求计划主表