Commit ad24ae80 by 丁伟峰

增加了品牌商、产品服务类别接口

1 parent 9218eb4f
......@@ -76,7 +76,10 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
......
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;
}
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.ProductCategoryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProductCategoryDao extends JpaRepository<ProductCategoryEntity, Long> {
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
public class BrandDTO {
private List<String> brands;
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class CategoryDTO {
private Long id;
private String value;
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
public class ItemDTO {
private String brand;
private List<CategoryDTO> categories;
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import java.util.List;
@Data
public class ItemsDTO {
private List<ItemDTO> items;
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@Entity
@Data
@Table(name="product_category")
public class ProductCategoryEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
/**
* 小组id
*/
@Column(name="product_service_id")
private Long productServiceId;
/**
* 品牌
*/
@Column(name="brand")
private String brand;
/**
* 产品类别
*/
@Column(name="type")
private String type;
/**
* 服务类型
*/
@Column(name="skill")
private String skill;
/**
* 所需工时(分钟)
*/
@Column(name="take_time")
private Integer takeTime;
/**
* 所需人数
*/
@Column(name="take_engineer")
private Integer takeEngineer;
/**
* 是否需要低压电工证
*/
@Column(name="low_electrician_cert")
private int lowElectricianCert;
/**
* 是否需要燃气证
*/
@Column(name="gas_cert")
private int gasCert;
/**
* 图层标签
*/
@Column(name="tag")
private String tag;
/**
* 备注
*/
@Column(name="memo")
private String memo;
/**
* 创建时间
*/
@Column(name="create_time")
private Date createTime;
/**
* 更新时间
*/
@Column(name="update_time")
private Date updateTime;
public ProductCategoryEntity() {
}
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dto.BrandDTO;
public interface ProductService {
Result<?> getProductCategoryList();
Result<BrandDTO> getAllBrand();
}
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.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.*;
@Service
public class ProductServiceImpl implements ProductService {
@Autowired
private ProductCategoryDao productCategoryDao;
private static final String[] BRANDS = {"博世/西门子", "GGN"};
public Result<BrandDTO> getAllBrand() {
return Result.success(new BrandDTO().setBrands(new ArrayList<>(Arrays.asList(BRANDS))));
}
@Override
public Result<?> getProductCategoryList() {
Map<String, ItemDTO> itemsMap = 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);
} else {
ItemDTO itemDto = new ItemDTO();
itemDto.setBrand(brand);
List<CategoryDTO> categoryDTOS = new ArrayList<>();
categoryDTOS.add(categoryDto);
itemDto.setCategories(categoryDTOS);
itemsMap.put(brand, itemDto);
}
}
ItemsDTO items = new ItemsDTO();
items.setItems((List<ItemDTO>) itemsMap.values());
return Result.success(items);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!