From 2f8e70ad2884d2b6b7443dfae0af11ae9cfc8b99 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期五, 28 二月 2025 17:44:10 +0800 Subject: [PATCH] bug修改 --- manage/src/main/java/com/jilongda/manage/service/impl/TModelServiceImpl.java | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 92 insertions(+), 0 deletions(-) diff --git a/manage/src/main/java/com/jilongda/manage/service/impl/TModelServiceImpl.java b/manage/src/main/java/com/jilongda/manage/service/impl/TModelServiceImpl.java index d348641..5219d73 100644 --- a/manage/src/main/java/com/jilongda/manage/service/impl/TModelServiceImpl.java +++ b/manage/src/main/java/com/jilongda/manage/service/impl/TModelServiceImpl.java @@ -1,10 +1,28 @@ package com.jilongda.manage.service.impl; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.jilongda.common.basic.PageInfo; +import com.jilongda.manage.mapper.TBrandMapper; +import com.jilongda.manage.mapper.TMaterialMapper; +import com.jilongda.manage.mapper.TSupplierMapper; +import com.jilongda.manage.model.TBrand; +import com.jilongda.manage.model.TMaterial; import com.jilongda.manage.model.TModel; import com.jilongda.manage.mapper.TModelMapper; +import com.jilongda.manage.model.TSupplier; +import com.jilongda.manage.query.TModelQuery; import com.jilongda.manage.service.TModelService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.jilongda.manage.vo.TBrandVO; +import com.jilongda.manage.vo.TModelVO; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; /** * <p> @@ -17,4 +35,78 @@ @Service public class TModelServiceImpl extends ServiceImpl<TModelMapper, TModel> implements TModelService { + @Autowired + private TBrandMapper brandMapper; + @Autowired + private TSupplierMapper supplierMapper; + @Autowired + private TMaterialMapper materialMapper; + + @Override + public Boolean upAndDown(String name, Integer status) { + List<TModel> models = this.baseMapper.selectList(Wrappers.lambdaQuery(TModel.class) + .eq(TModel::getName,name)); + models.stream().filter(Objects::nonNull).forEach(model -> model.setStatus(status)); + return this.updateBatchById(models); + } + + @Override + public Boolean upAndDownColor(String name, String color, Integer status) { + TModel model = this.baseMapper.selectOne(Wrappers.lambdaQuery(TModel.class) + .eq(TModel::getName,name) + .eq(TModel::getColor,color) + .last("LIMIT1 ")); + if (Objects.nonNull(model)){ + model.setStatus(status); + return this.updateById(model); + } + return false; + } + + @Override + public PageInfo<TModelVO> pageList(TModelQuery query) { + PageInfo<TModelVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); + List<TModelVO> list = this.baseMapper.pageList(query,pageInfo); + if(!CollectionUtils.isEmpty(list)){ + List<Integer> brandIds = list.stream().map(TModel::getBrandId).collect(Collectors.toList()); + List<Integer> supplierIds= list.stream().map(TModel::getSupplierId).collect(Collectors.toList()); + List<Integer> materialIds= list.stream().map(TModel::getMaterialId).collect(Collectors.toList()); + List<TBrand> tBrands = new ArrayList<>(); + if(!CollectionUtils.isEmpty(brandIds)){ + tBrands = brandMapper.selectList(Wrappers.lambdaQuery(TBrand.class) + .in(TBrand::getId, brandIds)); + } + List<TSupplier> tSuppliers = new ArrayList<>(); + if(!CollectionUtils.isEmpty(supplierIds)){ + tSuppliers = supplierMapper.selectList(Wrappers.lambdaQuery(TSupplier.class) + .in(TSupplier::getId, supplierIds)); + } + List<TMaterial> materials = new ArrayList<>(); + if(!CollectionUtils.isEmpty(materialIds)){ + materials = materialMapper.selectList(Wrappers.lambdaQuery(TMaterial.class) + .in(TMaterial::getId, materialIds)); + } + for (TModelVO modelVO : list) { + TBrand tBrand = tBrands.stream().filter(brand -> brand.getId().equals(modelVO.getBrandId())).findFirst().orElse(null); + if(Objects.nonNull(tBrand)){ + modelVO.setBrandName(tBrand.getName()); + } + TSupplier tSupplier = tSuppliers.stream().filter(supplier -> supplier.getId().equals(modelVO.getSupplierId())).findFirst().orElse(null); + if(Objects.nonNull(tSupplier)){ + modelVO.setSupplierName(tSupplier.getName()); + } + TMaterial tMaterial = materials.stream().filter(material -> material.getId().equals(modelVO.getMaterialId())).findFirst().orElse(null); + if(Objects.nonNull(tMaterial)){ + modelVO.setMaterialName(tMaterial.getName()); + } + // 查询型号的色号 + List<TModel> colorList = this.list(Wrappers.lambdaQuery(TModel.class) + .eq(TModel::getName,modelVO.getName())); + String color = colorList.stream().map(TModel::getColor).collect(Collectors.joining(",")); + modelVO.setColor(color); + } + } + pageInfo.setRecords(list); + return pageInfo; + } } -- Gitblit v1.7.1