实战:第三章:更新数据只能是下月修改,当月不能修改

第一种:可以利用缓存,commissionMerchantsBean是传入的参数对象

               //将合作对象更改后,应该在下个月份才生效
                //根据merchants_id查询tst_commission_merchants表获取import_partner_employee_id
                CommissionMerchantsBean merchantsBean = commissionDaoC.getCommissionMerchants(commissionMerchantsBean);
                //获取缓存中的生效时间
                String effectTimeImport = RedisUtils.getKey("effectTimeImport:" + commissionMerchants.getCommission_merchants_id());
                String effectTimeRelation = RedisUtils.getKey("effectTimeRelation:" + commissionMerchants.getCommission_merchants_id());
                if(tst.project.utils.StringUtils.isEmpty(effectTimeImport)){
                    //如果为空,设置缓存
                    RedisUtils.setKey("effectTimeImport:" + commissionMerchants.getCommission_merchants_id(),String.valueOf(TimeUtils.dateToStr(nextMonthStartTimes,"yyyy-MM")));
                }
                //重新获取
                String effectTimeImport2 = RedisUtils.getKey("effectTimeImport:" + commissionMerchants.getCommission_merchants_id());
                //导入的生效日期不等于当月的则将传入的import_partner_employee_id设置为库中原来的数据
                if(effectTimeImport2.compareTo(TimeUtils.dateToStr(new Date(),"yyyy-MM")) != 0){
                    //如果不为空,且缓存中的日期是几个月前的设置下月为生效日期
                    RedisUtils.setKey("effectTimeImport:" + commissionMerchants.getCommission_merchants_id(),String.valueOf(TimeUtils.dateToStr(nextMonthStartTimes,"yyyy-MM")));
                    //设置导入合作对象员工id为原来的数据
                    String importPartnerEmployeeId = merchantsBean.getImport_partner_employee_id();
                    commissionMerchantsBean.setImport_partner_employee_id(importPartnerEmployeeId);
                }
                if(tst.project.utils.StringUtils.isEmpty(effectTimeRelation)){
                    //如果为空,设置缓存
                    RedisUtils.setKey("effectTimeRelation:" + commissionMerchants.getCommission_merchants_id(),String.valueOf(TimeUtils.dateToStr(nextMonthStartTimes,"yyyy-MM")));
                }
                //重新获取
                String effectTimeRelation2 = RedisUtils.getKey("effectTimeRelation:" + commissionMerchants.getCommission_merchants_id());
                //关联的生效日期不等于当月的则将传入的relation_partner_employee_id设置为库中原来的数据
                if(effectTimeRelation2.compareTo(TimeUtils.dateToStr(new Date(),"yyyy-MM")) != 0){
                    //如果不为空,且缓存中的日期是几个月前的设置下月为生效日期
                    RedisUtils.setKey("effectTimeRelation:" + commissionMerchants.getCommission_merchants_id(),String.valueOf(TimeUtils.dateToStr(nextMonthStartTimes,"yyyy-MM")));
                    //设置关联合作对象员工id为原来的数据
                    String relationPartnerEmployeeId = merchantsBean.getRelation_partner_employee_id();
                    commissionMerchantsBean.setRelation_partner_employee_id(relationPartnerEmployeeId);
                }
                //设置生效时间为下个月
                int num=commissionDaoC.updateCommissionMerchants(commissionMerchantsBean);
                if(num<=0){
                    throw new AppException("更新失败!");
                }

第二种:可以利用定时任务

第三种:可以使用信息队列