Commit 599fad70 authored by 覃振观's avatar 覃振观 👶

2222

parent b97106ee
...@@ -112,18 +112,71 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -112,18 +112,71 @@ public class ProductApplicationImpl implements ProductApplication {
} }
} }
resultMap.put("selectedBrand", convertToMap(Brand.class, "brandName", "brandId", brands));
Map<Object, Object> selectedBrand = convertToMap(Brand.class, "brandName", brands); resultMap.put("selectedFactory", convertToMap(Factory.class, "factoryName", "factoryId", factorys));
Map<Object, Object> selectedFactory = convertToMap(Factory.class, "factoryName", factorys); resultMap.put("selectedColor", convertToMap(Color.class, "colorName", "colorId", colors));
Map<Object, Object> selectedColor = convertToMap(Color.class, "colorId", colors); resultMap.put("selectedCategory", convertToMap(ProductCategory.class, "productCategoryId",
Map<Object, Object> selectedProductCategory = convertToMap(ProductCategory.class, "productCategoryId", categorys); "productCategoryName", categorys));
resultMap.put("selectedBrand", selectedBrand);
resultMap.put("selectedFactory", selectedFactory);
resultMap.put("selectedColor", selectedColor);
resultMap.put("selectedProductCategory", selectedProductCategory);
return resultMap; return resultMap;
} }
/**
* description
* @param clazz Bean
* @param displayProperty 需要显示的属性
* @param valueProperty 连接的属性
* @param list 需要转换的 List
* @return java.util.Map<java.lang.Object, java.lang.Object>
* @author qinzhenguan
* @create: 2023/12/1 16:09
*/
public Map<Object, Object> convertToMap(Class<?> clazz, String displayProperty, String valueProperty,
List<?> list) {
Set<String> set = new HashSet();
set.add(displayProperty);
set.add(valueProperty);
if(checkClassesAndProperties(clazz, set, list.size())) {
ObjectMapper mapper = new ObjectMapper();
List<Map<String, Object>> mapList = mapper.convertValue(list, List.class);
return mapList.stream().collect(Collectors.toMap(map -> map.get(displayProperty), map -> map.get(valueProperty),
(oldV, newV) -> oldV));
}
return null;
}
/**
* description 只检查传入属性是否合法
* @param clazz Bean
* @param set 需要检查的 Propertys
* @param listSize 需要检查的 ListSize
* @return java.lang.Boolean true of false
* @author qinzhenguan
* @create: 2023/12/1 15:58
*/
public Boolean checkClassesAndProperties(Class<?> clazz, Set<String> set, int listSize) {
if(listSize == 0) {
System.err.println("[checkClassesAndProperties] : List< "+clazz.getName()+" > 需要转换的列表没有元素。请检查~!");
return false;
}
Field[] fields = clazz.getDeclaredFields();
Method[] methods = clazz.getDeclaredMethods();
for(String item : set) {
Field field = Arrays.stream(fields).filter(f -> item.equals(f.getName())).findFirst().orElse(null);
if(field == null) {
System.err.println("[checkClassesAndProperties] : " + clazz.getName() + " 无法找到 : " + item + " " +
"该属性。请检查~!");
return false;
}
Method method = Arrays.stream(methods)
.filter(m -> m.getName().toLowerCase().contains("get" + item.toLowerCase())).findFirst().orElse(null);
if (method == null) {
System.err.println("[checkClassesAndProperties] : " + item + " 该属性无法找到构造方法。请检查~!");
return false;
}
}
return true;
}
/** /**
* description 转换成 Map 不需要转换为实体 * description 转换成 Map 不需要转换为实体
* @param clazz Bean * @param clazz Bean
...@@ -138,11 +191,11 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -138,11 +191,11 @@ public class ProductApplicationImpl implements ProductApplication {
} }
/** /**
* description 转换成 Map * description 转换成 Map 保留映射
* @param clazz Bean * @param clazz Bean
* @param propertyName 连接的 property * @param propertyName 连接的 property
* @param list 需要转换的 List * @param list 需要转换的 List
* @param isBean 是否需要转换为实体 * @param isBean 是否需要转换为实体 (当前应用不需要返回实体)
* @return java.util.Map<java.lang.Object, java.lang.Object> * @return java.util.Map<java.lang.Object, java.lang.Object>
* @author qinzhenguan * @author qinzhenguan
* @create: 2023/11/29 11:34 * @create: 2023/11/29 11:34
...@@ -181,7 +234,7 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -181,7 +234,7 @@ public class ProductApplicationImpl implements ProductApplication {
} }
/** /**
* description 检查传入参数是否合法 * description 检查传入参数是否合法 并返回构造方法
* *
* @param clazz Bean * @param clazz Bean
* @param propertyName property * @param propertyName property
......
package com.huigou.topsun.product.controller; package com.huigou.topsun.product.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huigou.cache.DictUtil;
import com.huigou.topsun.base.coderule.domain.model.CodeRuleKind; import com.huigou.topsun.base.coderule.domain.model.CodeRuleKind;
import com.huigou.topsun.product.domain.Product; import com.huigou.topsun.product.domain.Product;
import com.huigou.topsun.product.application.ProductApplication; import com.huigou.topsun.product.application.ProductApplication;
...@@ -59,18 +62,42 @@ public class ProductController extends CommonController { ...@@ -59,18 +62,42 @@ public class ProductController extends CommonController {
} }
public String forwardProduct() { public String forwardProduct() {
this.putAttribute("ruleKindList", CodeRuleKind.getMap()); // 通过此方法可以查看系统配置的 字典 的数据结构
DictUtil.getDictionaryList("technologyType");
Map<String, Object> map4 = new HashMap<>();
map4.put("六六六", "666");
map4.put("七七七", "777");
map4.put("八八八", "888");
this.putAttribute("selectedCategory", map4);
return forward("product"); return forward("product");
} }
public String forwardProductDetail() { public String forwardProductDetail() {
ObjectMapper mapper = new ObjectMapper();
SDO sdo = this.getSDO(); SDO sdo = this.getSDO();
String productId = sdo.getString("productId"); Map param = null;
HashMap<String, Object> map = new HashMap<>(); try {
map.put("productId", productId); param = mapper.readValue(sdo.getString("data"), Map.class);
Map<String, Object> map2 = productService.queryDetailAll(Integer.parseInt(productId)); } catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Map<String, Object> map = productService.queryDetailAll(Integer.parseInt(param.get("productId") + ""));
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.putAll(mapper.convertValue(map.get("detail"), Map.class));
resultMap.putAll(param);
//字典
DictUtil.getDictionaryList("technologyType");
// this.putAttribute("selectedCategory", map.get("selectedCategory"));
Map<String, Object> map4 = new HashMap<>();
map4.put("code", "666");
map4.put("name", "777");
map4.put("value", "888");
this.putAttribute("selectedCategory", map4);
return forward("productDetail", map); return forward("productDetail", resultMap);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment