zoukankan      html  css  js  c++  java
  • jQueryrocket

    订单分箱需求,我把它简化为如下模型:

     一张表实现,实现分箱的效果,总结一下做个小demo。

    package com.kaspar.order.model;
    
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
    
    import org.hibernate.annotations.GenericGenerator;
    
    @Entity
    @Table(name = "Orders")
    public class Order implements Serializable {
    
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(generator = "orderid")
        @GenericGenerator(name = "orderid", strategy = "native")
        private int orderid;
        private String ordernum;
        public String getOrdernum() {
            return ordernum;
        }
    
        public void setOrdernum(String ordernum) {
            this.ordernum = ordernum;
        }
    
        @Column(length = 100, name = "item")
        private String item;
        private String box;
        private String quality;
    
    
        public int getOrderid() {
            return orderid;
        }
    
        public void setOrderid(int orderid) {
            this.orderid = orderid;
        }
    
        public String getItem() {
            return item;
        }
    
        public void setItem(String item) {
            this.item = item;
        }
    
        public String getBox() {
            return box;
        }
    
        public void setBox(String box) {
            this.box = box;
        }
    
        public String getQuality() {
            return quality;
        }
    
        public void setQuality(String quality) {
            this.quality = quality;
        }
        public Order() {
    
        }
    
        public Order(String ordernum,String item, String box, String quality) {
            this.ordernum = ordernum;
            this.item = item;
            this.box = box;
            this.quality = quality;
        }
    }
    View Code
    public class fenxiangbyorder {
        private ArrayList<Order> getList(){
            ArrayList<Order> list = new ArrayList<Order>();
            Order b1 = new Order();
            Order b2 = new Order();
            Order b3 = new Order();
            
            b1.setOrderid(1);
            b2.setOrderid(2);
            b3.setOrderid(3);
            
            b1.setBox("1");
            b2.setBox("4");
            b3.setBox("1");
            
            b1.setItem("1");
            b2.setItem("2");
            b3.setItem("3");
            
            b1.setOrdernum("WR20191213001");
            b2.setOrdernum("WR20191213001");
            b3.setOrdernum("WR20191213001");
            
            b1.setQuality("75");
            b2.setQuality("36");
            b3.setQuality("23");
            list .add(b1);
            list .add(b2);
            list .add(b3);
            
            return list;
        }
        
        public  Map<String, Object> getOrder2(){
            Map<String, Object>    map = new HashMap<String, Object>();
            List<Order> listresult =getList();//三个bean对象
            ArrayList<Order> listBox = new ArrayList<Order>();
             Integer  num1=1;
             for (int i = 0; i <  listresult.size(); i++) { //根据条目遍历,因为这个和条目一致直接拿来用了
                 Order box = (Order) listresult.get(i);
                 int boxNum = Integer.valueOf(box.getBox());
                 for (int k = 0; k < boxNum; k++) {  //根据箱子数量遍历
                     Order Order1 = new Order();
                     Order1 = box;
                     System.out.println("dayin第一遍"+num1);
                     Order1.setOrderid(num1);
                     System.out.println(Order1);
                     num1=num1+1;
                     listBox.add(Order1);
                }
            }
            map.put("result", listBox);
            return map;
        }
        public static void main(String[] args) {
            fenxiangbyorder a = new fenxiangbyorder();
            Map<String, Object> ss = a.getOrder2();
            System.out.println("---------------------------------");
            System.out.println(ss);
        }
    }
    View Code

    数据就直接在里面取,实际业务直接从持久层拿就欧克。

     到这里结束,一共六箱。关于设置箱号这里有点补充。

    原因就是引用类型变量的赋值只复制对象的引用,而不复制对象本身;而将一个值类型赋给另一个值类型变量时, 将复制包含的值。我的实体bean自然是引用类型,所以我在for循环赋值的时候,实体类添加但对象一直都是相同的, bt.setValues将之 前的赋值更新成。新的赋值然后再添加一-次就会出现上面的结果。

  • 相关阅读:
    Java异常的优势与缺陷,及其处理原则
    Kettle 4.2源码分析第四讲--KettleJob机制与Database插件简介(含讲解PPT)
    Kettle 4.2源码分析第三讲--Kettle 转换机制transformation介绍
    Kettle 4.2源码分析第二讲--Kettle插件结构体系简介
    Kettle 4.2源码分析第一讲--Kettle 简介
    pytorch one hot 的转换
    SQLSERVER类似于lastindexof的语句
    自定义省市选择器 微信小程序多列选择器
    王者荣耀伽罗壁纸
    微信小程序实现淡入淡出效果(页面跳转)
  • 原文地址:https://www.cnblogs.com/kaspar/p/12011836.html
Copyright © 2011-2022 走看看