zoukankan      html  css  js  c++  java
  • 批量更新数据不同状态时 ,1.在更新前检测 2.更新后执行自己的逻辑

      今天在项目中做盘点管理,盘点单据有 编辑->提交->审批->撤销->退回->开盘->盘毕等状态。根据操作对盘点单据会不停的更新其状态。
    一般做法是根据这5.6种状态,编写5,6中ServiceImpl方法 分别去Update。若要是批量操作则会加上for循环,代码块冗余过多。自己便将Update抽离出来。
    抽离出来后,面临这一些问题。就是在有些状态更新操作时,需要做验证(如:退回只能操作审批状态。开盘只能操作审批状态)。这个时候就需要在update之前需
    要判断,
    看其当前状态是否满足条件。
    -------------------------------------------------------------
    批量更新数据不同状态时 ,1.在更新前检测 2.更新后执行自己的逻辑

    此时利用断言型接口
    Predicate<?> 处理【有点象JS中的callback】

    /**
    * 提交盘点单 */ @Override public Result submitInventoryPlan(List<InvlctInventory> entitys) throws FrameExecuteException { return changeEntityStatus(entitys,InventoryStatus.SUBMIT,e->true,"提交成功!"); //若不需要在更新前进行检测 直接return true; } /** * 功能:(编制中)撤销盘点单据 * @param entitys 盘点单实体List */ @Override public Result retreatInventoryPlan(List<InvlctInventory> entitys) throws FrameExecuteException { return changeEntityStatus(entitys,InventoryStatus.EDIT,e->InventoryStatus.SUBMIT.equals(e.getSts()),"撤销成功!"); } /** * 功能:改变盘点单据状态 * @param entitys 盘点单据实体LIst * @param status 要设置成的状态 * @param trueMessage 操作成功后的提示消息 * @return Result */ private Result changeEntityStatus(List<InvlctInventory> entitys,InventoryStatus status,Predicate<InvlctInventory> pre,String trueMessage){ List<InvlctInventory> list = new ArrayList<>(); for (InvlctInventory invlctInventory : entitys) { InvlctInventory entity = get(invlctInventory.getCod()); if(entity!=null){ //检查是否满足 状态更新 if(pre.test(entity)){//回调判断 entity.setSts(status); entity.setEtim(new Date()); update(entity); } }else{ list.add(invlctInventory); } } String message = null; if(list.isEmpty() || list.size()==0){ message = trueMessage; }else{ message = "部分数据不存在,请刷新!"; } return new Result(true,message); }
  • 相关阅读:
    确认端口占用
    [转]自建Syncthing中继服务器(私密传输或造福大众)
    【转】Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置
    【转】搭建和配置Syncthing发现和中继服务器
    【转】Syncthing的安装与使用
    pycrypto安装出错的问题 intmax_t C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.
    Git从库中移除已删除大文件
    词云图
    [转].NET 性能测试工具 -- 事件跟踪器(ETW)
    [转]ANTS Performance Profiler和ANTS Memory Profiler 使用
  • 原文地址:https://www.cnblogs.com/wang-yi/p/10025417.html
Copyright © 2011-2022 走看看