Administrator
6 days ago 17e7cde3be486d840887de6ecb9a8b05486e19aa
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
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.mall.dto.CountryDeliveryDto;
import cc.mrbird.febs.mall.entity.MallCountryDelivery;
import cc.mrbird.febs.mall.mapper.MallCountryDeliveryMapper;
import cc.mrbird.febs.mall.service.IMallCountryDeliveryService;
import cc.mrbird.febs.mall.vo.AdminMallNewsInfoVo;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.List;
 
/**
 * 国家运费配置 Service 实现
 *
 * @author auto-generated
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MallCountryDeliveryServiceImpl implements IMallCountryDeliveryService {
 
    private final MallCountryDeliveryMapper mallCountryDeliveryMapper;
 
    @Override
    public FebsResponse list() {
        List<MallCountryDelivery> list = mallCountryDeliveryMapper.selectList(
                Wrappers.lambdaQuery(MallCountryDelivery.class)
                        .orderByAsc(MallCountryDelivery::getCountryCode)
        );
        return new FebsResponse().success().data(list);
    }
 
    @Override
    public IPage<MallCountryDelivery> countryDeliveryList(MallCountryDelivery dto, QueryRequest request) {
        Page<MallCountryDelivery> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<MallCountryDelivery> pages = mallCountryDeliveryMapper.getCountryDeliveryListInPage(page, dto);
        return pages;
    }
 
    @Override
    public FebsResponse saveOrUpdate(CountryDeliveryDto dto) {
        MallCountryDelivery entity = new MallCountryDelivery();
        entity.setCountryCode(dto.getCountryCode().toUpperCase());
        entity.setCountryName(dto.getCountryName());
        entity.setShippingFee(dto.getShippingFee());
        entity.setStatus(dto.getStatus() != null ? dto.getStatus() : 1);
        entity.setRemark(dto.getRemark());
 
        if (dto.getId() != null) {
            // 更新
            entity.setId(dto.getId());
            mallCountryDeliveryMapper.updateById(entity);
            log.info("更新国家运费配置: countryCode={}, fee={}", entity.getCountryCode(), entity.getShippingFee());
        } else {
            // 新增前检查编码是否重复
            MallCountryDelivery exist = mallCountryDeliveryMapper.selectOne(
                    Wrappers.lambdaQuery(MallCountryDelivery.class)
                            .eq(MallCountryDelivery::getCountryCode, entity.getCountryCode())
            );
            if (exist != null) {
                return new FebsResponse().fail().message("国家编码 " + entity.getCountryCode() + " 已存在");
            }
            mallCountryDeliveryMapper.insert(entity);
            log.info("新增国家运费配置: countryCode={}, fee={}", entity.getCountryCode(), entity.getShippingFee());
        }
        return new FebsResponse().success().message("保存成功");
    }
 
    @Override
    public FebsResponse delete(Long id) {
        mallCountryDeliveryMapper.deleteById(id);
        return new FebsResponse().success().message("删除成功");
    }
 
    @Override
    public FebsResponse getShippingFeeByCountryCode(String countryCode) {
        if (StrUtil.isBlank(countryCode)) {
            return new FebsResponse().fail().message("国家编码不能为空");
        }
 
        MallCountryDelivery delivery = mallCountryDeliveryMapper.selectOne(
                Wrappers.lambdaQuery(MallCountryDelivery.class)
                        .eq(MallCountryDelivery::getCountryCode, countryCode.toUpperCase())
                        .eq(MallCountryDelivery::getStatus, 1)
        );
 
        if (delivery == null) {
            // 没有配置则返回默认运费 0(可根据业务调整)
            return new FebsResponse().success().data(BigDecimal.ZERO);
        }
 
        return new FebsResponse().success().data(delivery.getShippingFee());
    }
}