@Override public ProductPlanMasterPM convert(boolean withDetail) { ProductPlanMasterPM masterPM = new ProductPlanMasterPM(); org.springframework.beans.BeanUtils.copyProperties(this, masterPM, new String[] {"details"}); Employee executeEmployee = this.getExecuteEmployee(); Employee planEmployee = this.getPlanEmployee(); if (executeEmployee != null) { masterPM.setExecuteEmployeeId(executeEmployee.getId()); masterPM.setExecuteEmployeeName(executeEmployee.getName()); } if (planEmployee != null) { masterPM.setPlanEmployeeId(planEmployee.getId()); masterPM.setPlanEmployeeName(planEmployee.getName()); } if (withDetail) { List<ProductPlanDetail> details = this.getDetails(); int size = details.size(); System.out.println(size); for (int i = 0; i < size; i++) { ProductPlanDetailPM detailpm = new ProductPlanDetailPM(); ProductPlanDetail detail = details.get(i); org.springframework.beans.BeanUtils.copyProperties(detail, detailpm); Product product = detail.getProduct(); detailpm.setProductId(product.getId()); detailpm.setFullName(product.getFullName()); detailpm.setSpecification(product.getSpecification()); detailpm.setColor(product.getColor()); detailpm.setUnit(product.getUnit()); masterPM.getDetails().add(detailpm); } } return masterPM; }
public ProductPlanMaster toDisp(boolean withDetail) { ProductPlanMaster master = null; try { master = (ProductPlanMaster) super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } master.setPlanEmployee( new Employee(this.getPlanEmployee().getId(), this.getPlanEmployee().getName())); master.setExecuteEmployee( new Employee(this.getExecuteEmployee().getId(), this.getExecuteEmployee().getName())); if (withDetail) { List<ProductPlanDetail> details = master.getDetails(); int size = details.size(); for (int i = 0; i < size; i++) { ProductPlanDetail masterdetail = details.get(i); masterdetail.setProductPlanMaster(null); Product product = masterdetail.getProduct(); masterdetail.setProduct( new Product( product.getId(), product.getFullName(), product.getItem(), product.getSpecification(), product.getUnit(), product.getColor())); } } else { master.getDetails().clear(); } return master; }