fix: 修复种类属性保存时List无泛型导致MyBatis报错
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,6 +2,7 @@ package com.example.building.service;
|
||||
|
||||
import com.example.building.entity.CategoryAttribute;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 种类属性服务接口
|
||||
@@ -16,7 +17,7 @@ public interface CategoryAttributeService {
|
||||
/**
|
||||
* 保存属性
|
||||
*/
|
||||
void saveAttributes(String categoryId, List<CategoryAttribute> attrs);
|
||||
void saveAttributes(String categoryId, List<Map<String, Object>> attrs);
|
||||
|
||||
/**
|
||||
* 删除种类的所有属性
|
||||
|
||||
@@ -8,7 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -29,13 +31,10 @@ public class CategoryAttributeServiceImpl implements CategoryAttributeService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveAttributes(String categoryId, List<CategoryAttribute> attrs) {
|
||||
public void saveAttributes(String categoryId, List<Map<String, Object>> attrs) {
|
||||
System.out.println("=== saveAttributes called ===");
|
||||
System.out.println("categoryId: " + categoryId);
|
||||
System.out.println("attrs size: " + (attrs != null ? attrs.size() : 0));
|
||||
if (attrs != null) {
|
||||
attrs.forEach(a -> System.out.println(" attr: " + a.getName() + ", type=" + a.getAttrType() + ", unit=" + a.getUnit()));
|
||||
}
|
||||
|
||||
// 删除旧属性
|
||||
categoryAttributeMapper.delete(new LambdaQueryWrapper<CategoryAttribute>()
|
||||
@@ -44,10 +43,29 @@ public class CategoryAttributeServiceImpl implements CategoryAttributeService {
|
||||
// 保存新属性
|
||||
if (attrs != null && !attrs.isEmpty()) {
|
||||
for (int i = 0; i < attrs.size(); i++) {
|
||||
CategoryAttribute attr = attrs.get(i);
|
||||
Map<String, Object> attrMap = attrs.get(i);
|
||||
CategoryAttribute attr = new CategoryAttribute();
|
||||
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());
|
||||
}
|
||||
|
||||
System.out.println(" attr: " + attr.getName() + ", type=" + attr.getAttrType() + ", unit=" + attr.getUnit());
|
||||
categoryAttributeMapper.insert(attr);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user