Commit 6a176e90 by 丁伟峰

将品牌商、产品服务、优先级、tag等创建订单总是需要的小数据,打包为一个接口予以实现

1 parent ad24ae80
......@@ -20,11 +20,9 @@ import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.service.OrderService;
import com.alibaba.cloud.integration.order.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* @author TrevorLink
......@@ -36,6 +34,9 @@ public class OrderController {
@Autowired
private OrderService orderService;
@Autowired
private ProductService productService;
@PostMapping("/create")
public Result<?> createOrder(@RequestParam("userId") String userId,
@RequestParam("commodityCode") String commodityCode,
......@@ -50,4 +51,15 @@ public class OrderController {
return res;
}
@GetMapping("/service/parameter")
public Result<?> getParameter(){
Result<?> res = null;
try {
res = productService.getProductCategoryList();
}
catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
}
package com.alibaba.cloud.integration.order.controller;
import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/order/service")
public class ProductController {
@Autowired
ProductService productService;
@GetMapping("/category")
public Result<?> getProductCategory(){
Result<?> res = null;
try {
res = productService.getProductCategoryList();
}
catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
@GetMapping("/brand")
public Result<?> brand(){
Result<?> res = null;
try {
res = productService.getAllBrand();
}
catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
}
......@@ -8,5 +8,7 @@ import java.util.List;
@Data
@Accessors(chain = true)
public class BrandDTO {
private List<String> brands;
private String label;
private String value;
private List<KeyValueDTO> categories;
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import java.util.List;
@Data
public class ItemsDTO {
private List<ItemDTO> items;
}
......@@ -5,7 +5,7 @@ import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class CategoryDTO {
private Long id;
public class KeyValueDTO {
private String value;
private String label;
}
......@@ -7,8 +7,8 @@ import java.util.List;
@Data
@Accessors(chain = true)
public class ItemDTO {
private String brand;
private List<CategoryDTO> categories;
public class ParameterRespDTO {
private List<BrandDTO> brands;
private List<KeyValueDTO> priorities;
private List<KeyValueDTO> standardTags;
}
......@@ -5,6 +5,4 @@ import com.alibaba.cloud.integration.order.dto.BrandDTO;
public interface ProductService {
Result<?> getProductCategoryList();
Result<BrandDTO> getAllBrand();
}
......@@ -3,15 +3,17 @@ package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.ProductCategoryDao;
import com.alibaba.cloud.integration.order.dto.BrandDTO;
import com.alibaba.cloud.integration.order.dto.CategoryDTO;
import com.alibaba.cloud.integration.order.dto.ItemDTO;
import com.alibaba.cloud.integration.order.dto.ItemsDTO;
import com.alibaba.cloud.integration.order.dto.KeyValueDTO;
import com.alibaba.cloud.integration.order.dto.ParameterRespDTO;
import com.alibaba.cloud.integration.order.entity.ProductCategoryEntity;
import com.alibaba.cloud.integration.order.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ProductServiceImpl implements ProductService {
......@@ -19,34 +21,35 @@ public class ProductServiceImpl implements ProductService {
@Autowired
private ProductCategoryDao productCategoryDao;
private static final String[] BRANDS = {"博世/西门子", "GGN"};
private List<KeyValueDTO> getPriorities() {
return null;
}
public Result<BrandDTO> getAllBrand() {
return Result.success(new BrandDTO().setBrands(new ArrayList<>(Arrays.asList(BRANDS))));
private List<KeyValueDTO> getStandardTags() {
return null;
}
@Override
public Result<?> getProductCategoryList() {
Map<String, ItemDTO> itemsMap = new HashMap<>();
private List<BrandDTO> getBrands() {
Map<String, BrandDTO> brandMap = new HashMap<>();
for (ProductCategoryEntity e : productCategoryDao.findAll()) {
String brand = e.getBrand();
String value = String.format("%s-%s", e.getType(), e.getSkill());
CategoryDTO categoryDto = new CategoryDTO().setId(e.getProductServiceId()).setValue(value);
if (itemsMap.containsKey(brand)) {
ItemDTO itemDto = itemsMap.get(brand);
itemDto.getCategories().add(categoryDto);
String text = String.format("%s-%s", e.getType(), e.getSkill());
KeyValueDTO categoryDto = new KeyValueDTO().setLabel(text).setValue(e.getProductServiceId().toString());
if (brandMap.containsKey(brand)) {
brandMap.get(brand).getCategories().add(categoryDto);
} else {
ItemDTO itemDto = new ItemDTO();
itemDto.setBrand(brand);
List<CategoryDTO> categoryDTOS = new ArrayList<>();
categoryDTOS.add(categoryDto);
itemDto.setCategories(categoryDTOS);
itemsMap.put(brand, itemDto);
BrandDTO brandDTO = new BrandDTO().setLabel(brand).setValue(brand).setCategories(new ArrayList<>());
brandDTO.getCategories().add(categoryDto);
brandMap.put(brand, brandDTO);
}
}
ItemsDTO items = new ItemsDTO();
items.setItems((List<ItemDTO>) itemsMap.values());
return Result.success(items);
return (List<BrandDTO>) brandMap.values();
}
@Override
public Result<?> getProductCategoryList() {
ParameterRespDTO parameterDTO =
new ParameterRespDTO().setBrands(getBrands()).setPriorities(getPriorities()).setStandardTags(getStandardTags());
return Result.success(parameterDTO);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!