java 枚举应用实例

 /**
     * 出入库类型枚举
     */
    public enum viewField {
        qianshouruQuantity(1, null), // 1.签收入库
        tuihuoruQuantity(2, 7), // 2.退货入库
        shangyangruQuantity(3, 10),// 3.上样入库
        xiayangruQuantity(3, 11),// 4.下样入库
        diaoboruQuantity(3, 12),//5.调拨入库
        panyingruQuantity(2, 13),//6.盘盈入库
        qitaruQuantity(2, 22),//7.其它入库/期初调整
        lingshouchuQuantity(9, 1),//8.零售出库
        dianshangchuQuantity(9, 2),//9.电商出库
        shangyangchuQuantity(9, 3),//10.上样出库
        xiayangchuQuantity(9, 4),//11.下样出库
        diaobochuQuantity(9, 5),//12.调拨出库
        pankuichuQuantity(1, 6),//13.盘亏出库
        qitachuQuantity(1, 14);//14.其他出库

        private Integer billType; // 枚举value字段
        private Integer outinType; // 枚举value字段

        viewField(Integer billType, Integer outinType) { // 构造初始化赋值
            this.billType = billType;
            this.outinType = outinType;
        }

        public Integer getBillType() {
            return billType;
        }

        public void setBillType(Integer billType) {
            this.billType = billType;
        }

        public Integer getOutinType() {
            return outinType;
        }

        public void setOutinType(Integer outinType) {
            this.outinType = outinType;
        }

        public static viewField getViewField(String viewField) {
            try {
                return valueOf(viewField);
            } catch (Exception e) {
                throw new RuntimeException("查询出入库参数错误:" + viewField);
            }
        }
    }

使用枚举

列:
String field="qianshouruQuantity";//签收查看

Map map = new HashMap();
        map.put("beginDate", entity.getBeginDate());
        List<ProductSummaryViewResultEntity> retList = null;
   
        ViewField viewField = ViewField.getViewField(field);
        switch (viewField) {
            case qianshouruQuantity:
                //1.签收查看
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
               
                break;
            case tuihuoruQuantity:
                //2.退货入库
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
                
                break;
            case shangyangruQuantity:
                //3.上样入库
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
                
                break;
            case xiayangruQuantity:
                //4.下样入库
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
            
                break;
            case diaoboruQuantity:
                //5.调拨入库
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
                
                break;
            case panyingruQuantity:
                //6.盘点调整
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
                
                break;
            case qitaruQuantity:
                //7.其它入库-其它入库/期初调整
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
               
                break;
            case lingshouchuQuantity:
                //零售出库
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
               
                break;
            case dianshangchuQuantity:
                //电商任务
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
                retList = productSummaryMapper.getOutinStorageDetailList(map);
                break;
            case shangyangchuQuantity:
                //上样出库
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
               
                break;
            case xiayangchuQuantity:
                //下样出库
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
                //获取下样出库对应的下样入库类型
                ViewField viewFieldOther2 = ProductSummaryService.ViewField.xiayangruQuantity;
                map.put("billTypeOther", viewFieldOther2.billType);
                map.put("outinTypeOther", viewFieldOther2.outinType);
                
                break;

            case pankuichuQuantity:
                //其它出库-盘点调整
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
               
                break;
            case qitachuQuantity:
                //其它出库/借出
                map.put("billType", viewField.billType);
                map.put("outinType", viewField.outinType);
              
                break;
            default:
                throw new ServiceException("没有对应的出入库详情:" + entity.getViewField());
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值