Commit 3c4ac354 by wangli

新增获取服务列表接口

1 parent 2ebef9b4
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.ProductCategoryService;
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("/pea-order")
public class ProductCategoryController {
@Autowired
private ProductCategoryService productCategoryService;
@GetMapping("/product/category")
public Result<?> getProductCategory() {
Result<?> res = null;
try {
res = productCategoryService.getProductCategory();
} catch (BusinessException e) {
Result.failed(e.getMessage());
}
return res;
}
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.ProductCategory;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ProductCategory2Dao extends BaseMapper<ProductCategory> {
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import java.util.List;
@Data
public class ProductCategoryResp {
private List<ProductCategory> categories;
@Data
public static class ProductCategory {
private String brand;
private String type;
private String skill;
private String categoryId;
}
}
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
@Data
public class ProductCategory {
private Integer id;
private String productCategoryId;
private String brand;
private String type;
private String skill;
private Integer takeTime;
private Integer takeEngineer;
private Integer lowElectricianCert;
private Integer gasCert;
private String tag;
private String memo;
}
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.Result;
public interface ProductCategoryService {
Result<?> getProductCategory();
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.ProductCategory2Dao;
import com.alibaba.cloud.integration.order.dto.ProductCategoryResp;
import com.alibaba.cloud.integration.order.entity.ProductCategory;
import com.alibaba.cloud.integration.order.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class ProductCategoryServiceImpl implements ProductCategoryService {
@Autowired
private ProductCategory2Dao productCategory2Dao;
@Transactional
@Override
public Result<?> getProductCategory() {
// 查询所有记录
List<ProductCategory> records= productCategory2Dao.selectList(null);
// 排序brand+type+skill
Comparator<ProductCategory> byBrand = Comparator.comparing(ProductCategory::getBrand);
Comparator<ProductCategory> byType = Comparator.comparing(ProductCategory::getType);
Comparator<ProductCategory> bySkill = Comparator.comparing(ProductCategory::getSkill);
Comparator<ProductCategory> comp = byBrand.thenComparing(byType).thenComparing(bySkill);
List<ProductCategory> results = records.stream().sorted(comp).collect(Collectors.toList());
ProductCategoryResp res = new ProductCategoryResp();
List<ProductCategoryResp.ProductCategory> categories = new ArrayList<>();
for (ProductCategory p: results) {
ProductCategoryResp.ProductCategory item = new ProductCategoryResp.ProductCategory();
item.setBrand(p.getBrand());
item.setType(p.getType());
item.setSkill(p.getSkill());
item.setCategoryId(p.getProductCategoryId());
categories.add(item);
}
res.setCategories(categories);
return Result.success(res);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!