|
|
@@ -18,6 +18,7 @@ package org.springblade.client.vehicle.controller;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
@@ -25,22 +26,29 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
+import org.springblade.client.entity.VehicleBrand;
|
|
|
+import org.springblade.client.entity.VehicleModel;
|
|
|
import org.springblade.client.entity.VehicleSeries;
|
|
|
-import org.springblade.client.excel.VehicleBrandExcel;
|
|
|
import org.springblade.client.excel.VehicleSeriesExcel;
|
|
|
+import org.springblade.client.feign.IRedisClient;
|
|
|
import org.springblade.client.vo.VehicleSeriesVO;
|
|
|
import org.springblade.core.excel.util.ExcelUtil;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.tenant.annotation.TenantIgnore;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springblade.client.vehicle.service.IVehicleSeriesService;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 车辆车系 控制器
|
|
|
@@ -52,9 +60,12 @@ import java.util.List;
|
|
|
@AllArgsConstructor
|
|
|
@RequestMapping("/vehicleSeries")
|
|
|
@Api(value = "车辆车系", tags = "车辆车系接口")
|
|
|
+@TenantIgnore//忽略租户
|
|
|
public class VehicleSeriesController extends BladeController {
|
|
|
|
|
|
private final IVehicleSeriesService vehicleSeriesService;
|
|
|
+ private final IRedisClient redisClient;//redis缓存处理
|
|
|
+ private final RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
/**
|
|
|
* 详情
|
|
|
@@ -74,7 +85,33 @@ public class VehicleSeriesController extends BladeController {
|
|
|
@ApiOperationSupport(order = 2)
|
|
|
@ApiOperation(value = "分页", notes = "传入vehicleSeries")
|
|
|
public R<IPage<VehicleSeries>> list(VehicleSeries vehicleSeries, Query query) {
|
|
|
- IPage<VehicleSeries> pages = vehicleSeriesService.page(Condition.getPage(query), Condition.getQueryWrapper(vehicleSeries));
|
|
|
+ LambdaQueryWrapper<VehicleSeries> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(VehicleSeries::getIsDeleted, 0)
|
|
|
+ .eq(ObjectUtils.isNotEmpty(vehicleSeries.getCreateUser()), VehicleSeries::getCreateUser, vehicleSeries.getCreateUser())
|
|
|
+ .eq(ObjectUtils.isNotEmpty(vehicleSeries.getUpdateUser()), VehicleSeries::getUpdateUser, vehicleSeries.getUpdateUser());
|
|
|
+ IPage<VehicleSeries> pages = vehicleSeriesService.page(Condition.getPage(query), lambdaQueryWrapper);
|
|
|
+
|
|
|
+ redisClient.basicData("all");
|
|
|
+ List<User> userList = castToList(redisTemplate.opsForValue().get("user"), User.class);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(pages.getRecords())){
|
|
|
+ pages.getRecords().stream().forEach(item ->{
|
|
|
+ if (item.getCreateUser() != null){
|
|
|
+ User user = userList.stream().filter(e -> e.getId().equals(item.getCreateUser())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isNotEmpty(user)){
|
|
|
+ item.setCreateUserName(user.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.getUpdateUser() != null){
|
|
|
+ User info = userList.stream().filter(e -> e.getId().equals(item.getUpdateUser())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtil.isNotEmpty(info)){
|
|
|
+ item.setUpdateUserName(info.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
return R.data(pages);
|
|
|
}
|
|
|
|
|
|
@@ -153,12 +190,60 @@ public class VehicleSeriesController extends BladeController {
|
|
|
@GetMapping("/brandList")
|
|
|
@ApiOperationSupport(order = 10)
|
|
|
@ApiOperation(value = "根据品牌id查询车系", notes = "传入vehicleSeries")
|
|
|
- public R<List<VehicleSeries>> brandList(VehicleSeries vehicleSeries) {
|
|
|
+ public R<List<Map<String, Object>>> brandList(VehicleSeries vehicleSeries) {
|
|
|
LambdaQueryWrapper<VehicleSeries> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWrapper.eq(VehicleSeries::getIsDeleted, 0)
|
|
|
.eq(VehicleSeries::getBrandId, vehicleSeries.getBrandId());
|
|
|
List<VehicleSeries> list = vehicleSeriesService.list(lambdaQueryWrapper);
|
|
|
- return R.data(list);
|
|
|
+
|
|
|
+ //根据厂商去重
|
|
|
+ List<VehicleSeries> manufacturerList = new ArrayList<>();
|
|
|
+ if (ObjectUtil.isNotEmpty(list)){
|
|
|
+ manufacturerList = list.stream().collect(Collectors.collectingAndThen(
|
|
|
+ Collectors.toCollection(() -> new TreeSet<>(
|
|
|
+ Comparator.comparing(VehicleSeries::getManufacturerId))), ArrayList::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+ //根据厂商获得车系
|
|
|
+ if (ObjectUtil.isNotEmpty(manufacturerList)){
|
|
|
+ manufacturerList.forEach(series -> {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<VehicleSeries> lambdaMap = new LambdaQueryWrapper<>();
|
|
|
+ lambdaMap.eq(VehicleSeries::getIsDeleted, 0)
|
|
|
+ .eq(VehicleSeries::getBrandId, vehicleSeries.getBrandId())
|
|
|
+ .eq(VehicleSeries::getManufacturerId, series.getManufacturerId());
|
|
|
+ List<VehicleSeries> seriesList = vehicleSeriesService.list(lambdaMap);
|
|
|
+
|
|
|
+ map.put("name",series.getManufacturerName());
|
|
|
+ map.put(series.getManufacturerName(), seriesList);
|
|
|
+ mapList.add(map);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.data(mapList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 将Object转换成List类型
|
|
|
+ *
|
|
|
+ * @param obj Object对象
|
|
|
+ * @param clazz 数据类型
|
|
|
+ * @param <T> 泛型类型
|
|
|
+ * @return List类型
|
|
|
+ */
|
|
|
+ public static <T> List<T> castToList(Object obj, Class<T> clazz) {
|
|
|
+ List<T> resList = new ArrayList<>();
|
|
|
+ // 如果不是List<?>对象,是没有办法转换的
|
|
|
+ if (obj instanceof List<?>) {
|
|
|
+ for (Object o : (List<?>) obj) {
|
|
|
+ // 将对应的元素进行类型转换
|
|
|
+ resList.add(clazz.cast(o));
|
|
|
+ }
|
|
|
+ return resList;
|
|
|
+ }
|
|
|
+ return resList;
|
|
|
+ }
|
|
|
}
|