Commit 6a176e90 by 丁伟峰

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

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