子表日期
子表信息
主表信息
前台代码参考
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);
}