kongdeqiang
2025-03-27 6f9623981926d78ce8ccd80bce55ad631bd2c76b
fix: 计划合并提交
5个文件已修改
1个文件已添加
411 ■■■■■ 已修改文件
platformx-device-api/src/main/java/com/by4cloud/platformx/device/entity/DeviceDemandPlan.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandPlanController.java 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandTotalController.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/DeviceDemandSubService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/impl/DeviceDemandSubServiceImpl.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/util/NumUtils.java 259 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
platformx-device-api/src/main/java/com/by4cloud/platformx/device/entity/DeviceDemandPlan.java
@@ -22,6 +22,10 @@
@Entity
@Table(appliesTo = "device_demand_plan", comment = "设备需求计划主表")
public class DeviceDemandPlan extends BaseModel<DeviceDemandPlan> {
    @Schema(description = "合并计划id")
    @Column(columnDefinition="long comment '合并计划id'")
    private Long planId;
    @Schema(description = "编码")
    @Column(columnDefinition="VARCHAR(64) comment '编码'")
    private String number;
@@ -31,12 +35,16 @@
    @Schema(description = "联系人")
    @Column(columnDefinition="VARCHAR(64) comment '联系人'")
    private String contacts;
    @Schema(description = "申报状态 0申请中,1二级单位审核拒绝  2二级单位审核通过 3集团审核拒绝 4集团审核通过")
    @Schema(description = "申报状态 0申请中,1二级单位审核拒绝  2二级单位审核通过 3待集团批准 4集团审核拒绝 5集团审核通过")
    @Column(columnDefinition="int comment '申报状态'")
    private Integer status;
    @Schema(description = "申报类型")
    @Column(columnDefinition="int comment '申报类型'")
    private Integer type;
    @Schema(description = "提交类型")
    @Column(columnDefinition="int comment '提交类型 0矿提交 1子单位提交'")
    private Integer type2;
    @Schema(description = "申报公司id")
    @Column(columnDefinition="long comment '申报公司id'")
    private Long declareCompId;
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandPlanController.java
@@ -3,14 +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.service.JcMaxSizeService;
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;
@@ -21,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;
/**
 * 设备需求计划主表
@@ -38,7 +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;
    /**
     * 分页查询
@@ -54,6 +62,23 @@
        wrapper.eq(deviceDemandPlan.getReleasePerson() !=null,DeviceDemandPlan::getReleasePerson,deviceDemandPlan.getReleasePerson());
        wrapper.eq(deviceDemandPlan.getYear() !=null,DeviceDemandPlan::getYear,deviceDemandPlan.getYear());
        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::getType2,1);
        return R.ok(deviceDemandPlanService.page(page, wrapper));
    }
@@ -80,9 +105,88 @@
    @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 设备需求计划主表
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandTotalController.java
@@ -64,7 +64,6 @@
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        DeviceDemandTotal demandTotal = deviceDemandTotalService.getById(id);
        QueryWrapper<DeviceDemandSub> wrapper = new QueryWrapper<>();
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/DeviceDemandSubService.java
@@ -3,6 +3,10 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.by4cloud.platformx.device.entity.DeviceDemandSub;
import java.util.List;
public interface DeviceDemandSubService extends IService<DeviceDemandSub> {
    List<DeviceDemandSub> getByPlanId(Long planId);
}
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/service/impl/DeviceDemandSubServiceImpl.java
@@ -1,10 +1,18 @@
package com.by4cloud.platformx.device.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by4cloud.platformx.device.entity.DeviceDemandSub;
import com.by4cloud.platformx.device.entity.DeviceDemandTotal;
import com.by4cloud.platformx.device.mapper.DeviceDemandSubMapper;
import com.by4cloud.platformx.device.mapper.DeviceDemandTotalMapper;
import com.by4cloud.platformx.device.service.DeviceDemandSubService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 设备需求计划设备子表
 *
@@ -12,5 +20,22 @@
 * @date 2025-03-05 15:40:29
 */
@Service
@AllArgsConstructor
public class DeviceDemandSubServiceImpl extends ServiceImpl<DeviceDemandSubMapper, DeviceDemandSub> implements DeviceDemandSubService {
    private DeviceDemandTotalMapper totalMapper;
    @Override
    public List<DeviceDemandSub> getByPlanId(Long planId) {
        QueryWrapper<DeviceDemandTotal> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(DeviceDemandTotal::getPlanId,planId);
        List<DeviceDemandTotal> deviceDemandTotals = totalMapper.selectList(wrapper);
        List<Long> collect = deviceDemandTotals.stream().map(DeviceDemandTotal::getId).collect(Collectors.toList());
        QueryWrapper<DeviceDemandSub> subwrapper = new QueryWrapper<>();
        subwrapper.lambda()
                .in(DeviceDemandSub::getTotalId,collect);
        List<DeviceDemandSub> subs = list(subwrapper);
        return subs;
    }
}
platformx-device-biz/src/main/java/com/by4cloud/platformx/device/util/NumUtils.java
New file
@@ -0,0 +1,259 @@
package com.by4cloud.platformx.device.util;
import java.math.BigDecimal;
/**
 * @author xfei
 * @date 2022/5/27下午8:26
 */
public class NumUtils {
    /**
     * 精确小数
     * @param f 小数
     * @param length 精确位数
     * @return
     */
    public static Float accurateFloat(Float f,int length){
        BigDecimal b = new BigDecimal(f.toString());
        f = b.setScale(length,BigDecimal.ROUND_HALF_UP).floatValue();
        return f;
    }
    public static Float accurateFloat(Float f){
        return accurateFloat(f,3);
    }
    public static Double accurateFloat(Double f,int length){
        BigDecimal b = new BigDecimal(f.toString());
        f = b.setScale(length,BigDecimal.ROUND_HALF_UP).doubleValue();
        return f;
    }
    public static Double accurateFloat(Double f){
        return accurateFloat(f,3);
    }
    public static Double accurateDouble(Double f,int length){
        if(f==null){
            f=0d;
        }
        BigDecimal b2 = new BigDecimal(f.toString());
        f = b2.setScale(length,BigDecimal.ROUND_HALF_UP).doubleValue();
        return f;
    }
    public static Double accurateDouble(Double f){
        return accurateDouble(f,3);
    }
    /**
     * 加
     * @param a
     * @param b
     * @return
     */
    public static Double addDouble(Double a,Double b){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.add(bb);
        aa = aa.setScale(2,BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    public static Double addDoubles(Double ... a){
        Double result = 0d;
        for (Double d :a){
            result =addDouble(result,d);
        }
        return result;
    }
    public static Double addDoubles(int len,Double ... a){
        Double result = 0d;
        for (Double d :a){
            result =addDouble(result,d,len);
        }
        return result;
    }
    /**
     * 减
     * @param a
     * @param b
     * @return
     */
    public static Double subtractDouble(Double a,Double b){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.subtract(bb);
        aa = aa.setScale(2,BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    /**
     * 减 只舍不入
     * @param a
     * @param b
     * @return
     */
    public static Double subtractDoubleDown(Double a,Double b){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.subtract(bb);
        aa = aa.setScale(2,BigDecimal.ROUND_DOWN);
        return aa.doubleValue();
    }
    /**
     * 乘
     * @param a
     * @param b
     * @return
     */
    public static Double multiplyDouble(Double a,Double b){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.multiply(bb);
        aa = aa.setScale(2,BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    /**
     * 乘 只舍不入
     * @param a
     * @param b
     * @return
     */
    public static Double multiplyDoubleDown(Double a,Double b){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.multiply(bb);
        aa = aa.setScale(2,BigDecimal.ROUND_DOWN);
        return aa.doubleValue();
    }
    /**
     * 除
     * 除法
     * @param a
     * @param b
     * @return
     */
    public static Double divideDouble(Double a,Double b){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.divide(bb);
        aa = aa.setScale(2,BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    public static Double divideDoubleUp(Double a,Double b){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.divide(bb,BigDecimal.ROUND_HALF_UP);
        aa = aa.setScale(2,BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    /**
     * 除
     * 除法
     * @param a
     * @param b
     * @return
     */
    public static Double divideDoubleDown(Double a,Double b){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.divide(bb);
        aa = aa.setScale(2,BigDecimal.ROUND_DOWN);
        return aa.doubleValue();
    }
    /**
     * 加
     * @param a
     * @param b
     * @return
     */
    public static Double addDouble(Double a,Double b,int len){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.add(bb);
        aa = aa.setScale(len,BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    /**
     * 减
     * @param a
     * @param b
     * @return
     */
    public static Double subtractDouble(Double a,Double b,int len){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.subtract(bb);
        aa = aa.setScale(len,BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    /**
     * 乘
     * @param a
     * @param b
     * @return
     */
    public static Double multiplyDouble(Double a,Double b,int len){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.multiply(bb);
        aa = aa.setScale(len,BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    /**
     * 除
     * @param a
     * @param b
     * @return
     */
    public static Double divideDouble(Double a,Double b,int len){
        if (a==null)a=0d;
        if (b==null)b=0d;
        BigDecimal aa = new BigDecimal(a+"");
        BigDecimal bb = new BigDecimal(b+"");
        aa = aa.divide(bb,len, BigDecimal.ROUND_HALF_UP);
        return aa.doubleValue();
    }
    public static Double floatToD(Float f){
        if (f==null){
            return new Double(0);
        }
        return new Double(f);
    }
    public static void main(String[] args) {
//        System.out.println(NumUtils.accurateDouble(60.1575,3));
        System.out.println(NumUtils.addDoubles(6.1234d,6.1234d,4.33d));
    }
}