fix: 恢复实体类型并处理Boolean转Integer问题
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -2,7 +2,6 @@ package com.example.building.service;
|
||||
|
||||
import com.example.building.entity.CategoryAttribute;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 种类属性服务接口
|
||||
@@ -17,7 +16,7 @@ public interface CategoryAttributeService {
|
||||
/**
|
||||
* 保存属性
|
||||
*/
|
||||
void saveAttributes(String categoryId, List<Map<String, Object>> attrs);
|
||||
void saveAttributes(String categoryId, List<CategoryAttribute> attrs);
|
||||
|
||||
/**
|
||||
* 删除种类的所有属性
|
||||
|
||||
@@ -31,7 +31,7 @@ public class CategoryAttributeServiceImpl implements CategoryAttributeService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveAttributes(String categoryId, List<Map<String, Object>> attrs) {
|
||||
public void saveAttributes(String categoryId, List<CategoryAttribute> attrs) {
|
||||
System.out.println("=== saveAttributes called ===");
|
||||
System.out.println("categoryId: " + categoryId);
|
||||
System.out.println("attrs size: " + (attrs != null ? attrs.size() : 0));
|
||||
@@ -43,26 +43,16 @@ public class CategoryAttributeServiceImpl implements CategoryAttributeService {
|
||||
// 保存新属性
|
||||
if (attrs != null && !attrs.isEmpty()) {
|
||||
for (int i = 0; i < attrs.size(); i++) {
|
||||
Map<String, Object> attrMap = attrs.get(i);
|
||||
CategoryAttribute attr = new CategoryAttribute();
|
||||
CategoryAttribute attr = attrs.get(i);
|
||||
attr.setAttrId(UUID.randomUUID().toString());
|
||||
attr.setCategoryId(categoryId);
|
||||
attr.setSortOrder(i);
|
||||
|
||||
if (attrMap.get("name") != null) {
|
||||
attr.setName(attrMap.get("name").toString());
|
||||
}
|
||||
if (attrMap.get("attrType") != null) {
|
||||
attr.setAttrType(attrMap.get("attrType").toString());
|
||||
}
|
||||
if (attrMap.get("unit") != null) {
|
||||
attr.setUnit(attrMap.get("unit").toString());
|
||||
}
|
||||
if (attrMap.get("required") != null) {
|
||||
attr.setRequired((Boolean) attrMap.get("required"));
|
||||
}
|
||||
if (attrMap.get("formula") != null) {
|
||||
attr.setFormula(attrMap.get("formula").toString());
|
||||
// 处理 required 字段类型(前端可能是 Boolean,后端存 Integer)
|
||||
if (attr.getRequired() != null) {
|
||||
if (attr.getRequired() instanceof Boolean) {
|
||||
attr.setRequired(((Boolean) attr.getRequired()) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(" attr: " + attr.getName() + ", type=" + attr.getAttrType() + ", unit=" + attr.getUnit());
|
||||
|
||||
Reference in New Issue
Block a user