chenhj
2 天以前 a770364a2323290fdf9e3247b47475a12452f401
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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;
 
/**
 * <p>
 * 供应商信息表 服务实现类
 * </p>
 *
 * @author ruoyi
 * @since 2025-05-30
 */
@Service
@RequiredArgsConstructor
public class SupplyServiceImpl extends ServiceImpl<SupplyMapper, Supply> implements SupplyService {
 
    private final SupplyMapper supplyMapper;
 
    @Override
    public IPage<Supply> selectSupplyList(Page page, SupplyDto supplyDto) {
        LambdaQueryWrapper<Supply> 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<Supply> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids)
                .set("deleted", 1);  // 设置 deleted 为 1 表示已删除
        // 执行批量逻辑删除
        return supplyMapper.update(null, updateWrapper);
    }
 
    @Override
    public List<Supply> supplyList() {
        return supplyMapper.selectList(null);
    }
}