java修改子表 检查日期,更新主表检查日期,并根据周期(月)计算下次检查日期。

子表日期

子表信息

 主表信息

前台代码参考

https://blog.csdn.net/qq_50280782/article/details/117442938

 软件介绍

idea   VScode  springBoot框架    vue+moment

A.运算逻辑 (添加,跟新代码逻辑相同)

1.获取子表中的检查日期

2.获取主表中的检查日期 ,周期,下次检查日期

3.将子表中的检查日期,赋值到(主表)的检查日期

4.通过检查周期/月计算得出,下次检查日期

B.具体操作 

直接上代码(在子表service(逻辑层)操作)

    //引入主表service
    @Autowired
    private TdLimsInstrumentService tdLimsInstrumentService;

    @SneakyThrows
    @Override
    public boolean updateById(TdLimsInstrumentDetectEntity entity){
        int fInspectionCycle=0;
        int y=0;
        int m=0;
        int d=0;
        int momth=0;

        //1.获取维修表(子表)中检查日期
        Date fInspectionDate =entity.getFInspectionDate();
        //2.获取仪器(主)表中的检查日期,周期,下次检查日期
        TdLimsInstrumentEntity tdLimsInstrumentEntity=tdLimsInstrumentService.getById(entity.getFParentId());
        //主表检查日期
        Date fInspectionDatezhu=tdLimsInstrumentEntity.getFInspectionDate();
        //主表周期
        String  fInspectionCycleStr=tdLimsInstrumentEntity.getFInspectionCycle();
        if (fInspectionCycleStr != null && fInspectionCycleStr.length()>0) {
            fInspectionCycle=Integer.parseInt(fInspectionCycleStr,10);
        }
        //主表下次检查日期
        Date fNextInspectionDate=tdLimsInstrumentEntity.getFNextInspectionDate();

        //计算下次检查日期
        if (fInspectionDate!=null&&fInspectionCycle>=0){
            //把检查表(子表)日期赋值给仪器(主表)检查日期
            fInspectionDatezhu=fInspectionDate;
            //使用默认当前时间创建一个日历
            Calendar cal = Calendar.getInstance();
            //将(主表)中检查日期设置到日历中去(方便提取,计算)
            cal.setTime(fInspectionDatezhu);
            //获取,年,月,日,(注意: 月份获取需要  加+1)
            y=cal.get(Calendar.YEAR);
            m=cal.get(Calendar.MONTH)+1;
            d=cal.get(Calendar.DAY_OF_MONTH);
            //  System.out.println("年:"+y+"月:"+m+"日:"+d);
            momth=m+fInspectionCycle;
            if (momth == 0) {//无0月,元月及1月。
                momth=1;
            }
            if ((momth/12)>0) {//大于12个月轮换一年
                y=y+(momth/12);
                momth=momth-12*(momth/12);
            }
            //计算后的检查时间
            String countDateStr=y+"-"+(momth<10?("0"+momth):momth)+"-"+(d<10?("0"+d):d)+"";
            //计算后的日期(String)转换成Date类型的日期(可以不做转换)
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
            Date countDate=sdf.parse(countDateStr);
            //保存到主表检查日期
            tdLimsInstrumentEntity.setFInspectionDate(entity.getFInspectionDate());
            tdLimsInstrumentService.updateById(tdLimsInstrumentEntity);
            //保存到主表下次检查日期
            tdLimsInstrumentEntity.setFNextInspectionDate(countDate);
            tdLimsInstrumentService.updateById(tdLimsInstrumentEntity);
    }


        return super.updateById(entity);
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值