package com.ruoyi.basic.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.basic.dto.SupplyDto; import com.ruoyi.basic.entity.Supply; import com.ruoyi.basic.mapper.SupplyMapper; import com.ruoyi.basic.service.SupplyService; import com.ruoyi.common.utils.bean.BeanUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.util.List; import java.util.Objects; /** *

* 供应商信息表 服务实现类 *

* * @author ruoyi * @since 2025-05-30 */ @Service @RequiredArgsConstructor public class SupplyServiceImpl extends ServiceImpl implements SupplyService { private final SupplyMapper supplyMapper; @Override public IPage selectSupplyList(Page page, SupplyDto supplyDto) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); // 全局模糊搜索字段 if (StringUtils.hasText(supplyDto.getSearchAll())) { String keyword = supplyDto.getSearchAll(); queryWrapper.and(wrapper -> wrapper .like(Supply::getSupplierName, keyword) .or() .like(Supply::getTaxpayerId, keyword) .or() .like(Supply::getBusinessAddress, keyword) ); } else { // 单独条件查询 if (StringUtils.hasText(supplyDto.getSupplierName())) { queryWrapper.like(Supply::getSupplierName, supplyDto.getSupplierName()); } if (StringUtils.hasText(supplyDto.getTaxpayerId())) { queryWrapper.like(Supply::getTaxpayerId, supplyDto.getTaxpayerId()); } if (StringUtils.hasText(supplyDto.getBusinessAddress())) { queryWrapper.like(Supply::getBusinessAddress, supplyDto.getBusinessAddress()); } } // 默认按创建时间倒序排列 queryWrapper.orderByDesc(Supply::getCreateTime); return supplyMapper.selectPage(page, queryWrapper); } @Override public int addOrEditSupply(SupplyDto supplyDto) { Supply supply = new Supply(); BeanUtils.copyProperties(supplyDto, supply); if (supplyDto.getBids().size() != 3) { throw new RuntimeException("请选择经营地址省市区"); } if (supplyDto.getCids().size() != 3) { throw new RuntimeException("请选择联系地址省市区"); } supply.setBProvinceId(supplyDto.getBids().get(0)); supply.setBCityId(supplyDto.getBids().get(1)); supply.setBDistrictId(supplyDto.getBids().get(2)); supply.setCProvinceId(supplyDto.getCids().get(0)); supply.setCCityId(supplyDto.getCids().get(1)); supply.setCDistrictId(supplyDto.getCids().get(2)); if (Objects.isNull(supplyDto.getId())) { return supplyMapper.insert(supply); } else { return supplyMapper.updateById(supply); } } @Override public int delSupplyByIds(Long[] ids) { // 检查参数 if (ids == null || ids.length == 0) { return 0; } // 构造更新条件 UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.in("id", ids) .set("deleted", 1); // 设置 deleted 为 1 表示已删除 // 执行批量逻辑删除 return supplyMapper.update(null, updateWrapper); } @Override public List supplyList() { return supplyMapper.selectList(null); } }