@Override public List<Map<String, Object>> loadItemUnit(String id) { List<TScItemPriceEntity> priceEntityList = this.findHql( "from TScItemPriceEntity where itemID = ? and unitType <> '0003'", new Object[] {id}); List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); for (TScItemPriceEntity entity : priceEntityList) { Map<String, Object> param = new HashMap<String, Object>(); Boolean isAdd = true; param.put("id", entity.getId()); param.put( "text", entity.getMeasureunitToIcItemEntity() == null ? "" : entity.getMeasureunitToIcItemEntity().getName()); result.add(param); } return result; }
public void updateMain( TScIcitemEntity tScIcitem, List<TScItemPriceEntity> tScItemPriceList, List<TScItemPhotoEntity> tScItemPhotoList) { // 保存主表信息 this.saveOrUpdate(tScIcitem); // =================================================================================== // 获取参数 Object id0 = tScIcitem.getId(); Object id1 = tScIcitem.getId(); // =================================================================================== // 1.查询出数据库的明细数据-单位价格表 String hql0 = "from TScItemPriceEntity where 1 = 1 AND priceToIcItem.id = ? "; List<TScItemPriceEntity> tScItemPriceOldList = this.findHql(hql0, id0); // 2.筛选更新明细数据-单位价格表 for (TScItemPriceEntity oldE : tScItemPriceOldList) { boolean isUpdate = false; for (TScItemPriceEntity sendE : tScItemPriceList) { if (StringUtils.isNotEmpty(sendE.getUnitID())) { TScMeasureunitToIcItemEntity entity = this.get(TScMeasureunitToIcItemEntity.class, sendE.getUnitID()); // 持久化 entity.setId(sendE.getUnitID()); sendE.setMeasureunitToIcItemEntity(entity); } // 需要更新的明细数据-单位价格表 if (oldE.getId().equals(sendE.getId())) { try { // 计数单位 if (!oldE.getMeasureunitToIcItemEntity().getId().equals(sendE.getUnitID())) { TScCountEntity countEntity = new TScCountEntity(); countEntity.setType(Globals.COUNT_UPDATE_TYPE); countEntity.setOldId(oldE.getMeasureunitToIcItemEntity().getId()); // 原先的单位 countEntity.setNewId(sendE.getUnitID()); // 更改后的单位 tScMeasureunitService.updateMeasureunitCount(countEntity); } // if(sendE.getDefaultCG() == null){ // sendE.setDefaultCG(0); // } // if(sendE.getDefaultXS() == null){ // sendE.setDefaultXS(0); // } // if(sendE.getDefaultCK() ==null){ // sendE.setDefaultCK(0); // } // if(sendE.getDefaultSC() == null){ // sendE.setDefaultSC(0); // } // MyBeanUtils.copyBeanNotNull2Bean(sendE, oldE); MyBeanUtils.copyBean2Bean(oldE, sendE); oldE.setPriceToIcItem(tScIcitem); this.saveOrUpdate(oldE); } catch (Exception e) { e.printStackTrace(); throw new BusinessException(e.getMessage()); } isUpdate = true; break; } } if (!isUpdate) { // 计数单位 TScCountEntity countEntity = new TScCountEntity(); countEntity.setType(Globals.COUNT_DEL_TYPE); countEntity.setOldId(oldE.getMeasureunitToIcItemEntity().getId()); // 原先的单位 tScMeasureunitService.updateMeasureunitCount(countEntity); // 如果数据库存在的明细,前台没有传递过来则是删除-单位价格表 super.delete(oldE); } } // 3.持久化新增的数据-单位价格表 for (TScItemPriceEntity tScItemPrice : tScItemPriceList) { if (oConvertUtils.isEmpty(tScItemPrice.getId())) { // 计数单位 TScCountEntity countEntity = new TScCountEntity(); countEntity.setType(Globals.COUNT_ADD_TYPE); countEntity.setOldId(tScItemPrice.getUnitID()); // 原先的单位 tScMeasureunitService.updateMeasureunitCount(countEntity); if (StringUtils.isNotEmpty(tScItemPrice.getUnitID())) { TScMeasureunitToIcItemEntity entity = this.get(TScMeasureunitToIcItemEntity.class, tScItemPrice.getUnitID()); entity.setId(tScItemPrice.getUnitID()); tScItemPrice.setMeasureunitToIcItemEntity(entity); } // 外键设置 // tScItemPrice.setItemID(tScIcitem.getId()); tScItemPrice.setPriceToIcItem(tScIcitem); this.save(tScItemPrice); } } // =================================================================================== // 1.查询出数据库的明细数据-商品图片表 String hql1 = "from TScItemPhotoEntity where 1 = 1 AND iTEMID = ? "; List<TScItemPhotoEntity> tScItemPhotoOldList = this.findHql(hql1, id1); // 2.筛选更新明细数据-商品图片表 for (TScItemPhotoEntity oldE : tScItemPhotoOldList) { boolean isUpdate = false; for (TScItemPhotoEntity sendE : tScItemPhotoList) { // 需要更新的明细数据-商品图片表 if (oldE.getId().equals(sendE.getId())) { try { MyBeanUtils.copyBeanNotNull2Bean(sendE, oldE); this.saveOrUpdate(oldE); } catch (Exception e) { e.printStackTrace(); throw new BusinessException(e.getMessage()); } isUpdate = true; break; } } if (!isUpdate) { // 如果数据库存在的明细,前台没有传递过来则是删除-商品图片表 super.delete(oldE); } } // 3.持久化新增的数据-商品图片表 for (TScItemPhotoEntity tScItemPhoto : tScItemPhotoList) { if (oConvertUtils.isEmpty(tScItemPhoto.getId())) { // 外键设置 tScItemPhoto.setItemID(tScIcitem.getId()); this.save(tScItemPhoto); } } // 执行更新操作配置的sql增强 this.doUpdateSql(tScIcitem); }
/** * @param id * @return */ @Override public AjaxJson getItemInfoById(String id, String tranType, String stockId, String batchNo) { AjaxJson j = new AjaxJson(); Map<String, Object> attributes = new HashMap<String, Object>(); TScIcitemEntity icitemEntity = this.getEntity(TScIcitemEntity.class, id); // 配置默认仓库 if (null != icitemEntity.getStockForIcitemEntity()) { attributes.put("stockId", icitemEntity.getStockForIcitemEntity().getId()); attributes.put("stockName", icitemEntity.getStockForIcitemEntity().getName()); } else { attributes.put("stockId", ""); attributes.put("stockName", ""); } List<TScItemPriceEntity> priceEntityList = this.findHql("from TScItemPriceEntity where itemID = ?", new Object[] {id}); for (TScItemPriceEntity price : priceEntityList) { if ("51".equals(tranType)) { if (null != price.getDefaultCG() && 1 == price.getDefaultCG()) { attributes.put("unitId", price.getId()); attributes.put( "unitName", price.getMeasureunitToIcItemEntity() == null ? "" : price.getMeasureunitToIcItemEntity().getName()); attributes.put("cofficient", price.getCoefficient()); attributes.put("barCode", price.getBarCode()); // 采购限价 attributes.put("cgLimitPrice", price.getCgLimitPrice()); // 销货限价 attributes.put("xsLimitPrice", price.getXsLimitPrice()); } } else if ("52".equals(tranType) || "53".equals(tranType)) { if (null != price.getDefaultCK() && 1 == price.getDefaultCK()) { attributes.put("unitId", price.getId()); attributes.put( "unitName", price.getMeasureunitToIcItemEntity() == null ? "" : price.getMeasureunitToIcItemEntity().getName()); attributes.put("cofficient", price.getCoefficient()); attributes.put("barCode", price.getBarCode()); // 限购单价 attributes.put("cgLimitPrice", price.getCgLimitPrice()); // 销货限价 attributes.put("xsLimitPrice", price.getXsLimitPrice()); } } else if ("1504".equals(tranType) || "353".equals(tranType)) { if (null != price.getDefaultCK() && 1 == price.getDefaultCK()) { attributes.put( "unitName", price.getMeasureunitToIcItemEntity() == null ? "" : price.getMeasureunitToIcItemEntity().getName()); // 单位名称 attributes.put("barCode", price.getBarCode()); // 条形码 attributes.put("unitID", price.getId()); // 单位 attributes.put("basicUnitID", price.getId()); // 基本单位 attributes.put("coefficient", price.getCoefficient()); // 换算率 } } else if ("103".equals(tranType) || "1506".equals(tranType)) { if (null != price.getDefaultXS() && 1 == price.getDefaultXS()) { attributes.put("unitId", price.getId()); if (null != price.getMeasureunitToIcItemEntity()) { attributes.put( "unitName", price.getMeasureunitToIcItemEntity() == null ? "" : price.getMeasureunitToIcItemEntity().getName()); } attributes.put("cofficient", price.getCoefficient()); attributes.put("barCode", price.getBarCode()); // 限购单价 attributes.put("cgLimitPrice", price.getCgLimitPrice()); // 销货限价 attributes.put("xsLimitPrice", price.getXsLimitPrice()); } } // 辅助单位 if ("0003".equals(price.getUnitType())) { attributes.put("secUnitId", price.getId()); attributes.put("secCoefficient", price.getCoefficient()); } // 基本单位 else if ("0001".equals(price.getUnitType())) { attributes.put("basicUnitId", price.getId()); attributes.put("basicCoefficient", price.getCoefficient()); } } attributes.put("id", id); if (StringUtils.isNotEmpty(stockId)) { // 获取库存基本信息; List<TScIcInventoryEntity> inventoryEntity = this.findHql( "from TScIcInventoryEntity where itemId = ? and stockId = ?", new Object[] {id, stockId}); // 若存在库存数据,则判断是否存在批号数据,若不存在,则取库存数量为商品限量,若存在,则取该批号的库存数量作为商品限量 if (inventoryEntity.size() > 0) { if (StringUtils.isEmpty(batchNo)) { attributes.put("invQty", inventoryEntity.get(0).getBasicQty()); } else { List<TScIcInventoryBatchnoEntity> batchnoEntityList = this.findHql( "from TScIcInventoryBatchnoEntity where itemId = ? and stockId=? and batchNo = ?", new Object[] {id, stockId, batchNo}); if (batchnoEntityList.size() > 0) { attributes.put("invQty", batchnoEntityList.get(0).getBasicQty()); } else { attributes.put("invQty", inventoryEntity.get(0).getBasicQty()); } } } else { attributes.put("invQty", 0); } } else { attributes.put("invQty", 0); } j.setAttributes(attributes); return j; }