// 保存 @Validations( requiredStrings = { @RequiredStringValidator(fieldName = "goodsType.name", message = "类型名称不允许为空!") }) @InputConfig(resultName = "error") public String save() { if (brandList != null) { goodsType.setBrandSet(new HashSet<Brand>(brandList)); } else { goodsType.setBrandSet(null); } if (goodsParameterList != null) { for (Iterator<GoodsParameter> iterator = goodsParameterList.iterator(); iterator.hasNext(); ) { GoodsParameter goodsParameter = iterator.next(); if (goodsParameter == null || StringUtils.isEmpty(goodsParameter.getName())) { iterator.remove(); } } } goodsType.setGoodsParameterList(goodsParameterList); goodsTypeService.save(goodsType); if (goodsAttributeList != null) { for (GoodsAttribute goodsAttribute : goodsAttributeList) { if (StringUtils.isEmpty(goodsAttribute.getName()) || goodsAttribute.getAttributeType() == null || (goodsAttribute.getAttributeType() == AttributeType.filter && StringUtils.isEmpty(goodsAttribute.getOptionText()))) { continue; } Integer unusedPropertyIndex = goodsAttributeService.getUnusedPropertyIndex(goodsType); if (unusedPropertyIndex != null) { goodsAttribute.setGoodsType(goodsType); goodsAttribute.setPropertyIndex(unusedPropertyIndex); goodsAttributeService.save(goodsAttribute); } } } cacheService.flushGoodsListPageCache(getRequest()); redirectUrl = "goods_type!list.action"; return SUCCESS; }
// 更新 @InputConfig(resultName = "error") public String update() { if (brandList != null) { goodsType.setBrandSet(new HashSet<Brand>(brandList)); } else { goodsType.setBrandSet(null); } if (goodsParameterList != null) { for (Iterator<GoodsParameter> iterator = goodsParameterList.iterator(); iterator.hasNext(); ) { GoodsParameter goodsParameter = iterator.next(); if (goodsParameter == null || StringUtils.isEmpty(goodsParameter.getName())) { iterator.remove(); } } } goodsType.setGoodsParameterList(goodsParameterList); GoodsType persistent = goodsTypeService.load(id); if (goodsAttributeList != null) { Set<GoodsAttribute> persistentGoodsAttributeSet = persistent.getGoodsAttributeSet(); for (GoodsAttribute persistentGoodsAttribute : persistentGoodsAttributeSet) { if (!goodsAttributeList.contains(persistentGoodsAttribute)) { goodsAttributeService.delete(persistentGoodsAttribute); } } for (GoodsAttribute goodsAttribute : goodsAttributeList) { if (goodsAttribute == null || StringUtils.isEmpty(goodsAttribute.getName()) || goodsAttribute.getAttributeType() == null || (goodsAttribute.getAttributeType() == AttributeType.filter && StringUtils.isEmpty(goodsAttribute.getOptionText()))) { continue; } if (StringUtils.isNotEmpty(goodsAttribute.getId())) { GoodsAttribute persistentGoodsAttribute = goodsAttributeService.load(goodsAttribute.getId()); BeanUtils.copyProperties( goodsAttribute, persistentGoodsAttribute, new String[] {"id", "createDate", "modifyDate", "goodsType", "propertyIndex"}); goodsAttributeService.update(persistentGoodsAttribute); } else { Integer unusedPropertyIndex = goodsAttributeService.getUnusedPropertyIndex(persistent); if (unusedPropertyIndex != null) { goodsAttribute.setGoodsType(persistent); goodsAttribute.setPropertyIndex(unusedPropertyIndex); goodsAttributeService.save(goodsAttribute); } } } } else { Set<GoodsAttribute> persistentGoodsAttributeSet = persistent.getGoodsAttributeSet(); for (GoodsAttribute persistentGoodsAttribute : persistentGoodsAttributeSet) { goodsAttributeService.delete(persistentGoodsAttribute); } } BeanUtils.copyProperties( goodsType, persistent, new String[] {"id", "createDate", "modifyDate", "goodsAttributeSet", "goodsSet"}); goodsTypeService.update(persistent); cacheService.flushGoodsListPageCache(getRequest()); redirectUrl = "goods_type!list.action"; return SUCCESS; }