xin
2025-05-30 347909bae241fff128b628ea6d12992d7e5b4b10
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.oying.modules.pc.store.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.oying.modules.pc.store.domain.Store;
import com.oying.modules.pc.store.domain.dto.StoreQueryCriteria;
import com.oying.modules.pc.store.mapper.StoreMapper;
import com.oying.modules.pc.store.service.StoreService;
import com.oying.utils.PageResult;
import com.oying.utils.PageUtil;
import com.oying.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;
 
/**
 * 店铺Service业务层处理
 *
 * @author lzp
 * @date 2025-04-22
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements StoreService {
 
    private final StoreMapper storeMapper;
 
    @Override
    public PageResult<Store> queryByPage(StoreQueryCriteria criteria) {
        Page<Store> page = new Page<>(criteria.getPage(), criteria.getSize());
        return PageUtil.toPage(storeMapper.selectStoreList(criteria, page));
    }
 
    @Override
    public List<Store> queryAll(StoreQueryCriteria criteria) {
        return storeMapper.selectStoreList(criteria);
    }
 
    @Override
    public Store getMerchantStore(Long merchantId) {
        return storeMapper.selectStoreByMerchantId(merchantId);
    }
 
    @Override
    public boolean create(Store store) {
        // store.setStoreId(StoreIdGenerator.getId());
        store.setCreateBy(SecurityUtils.getCurrentUserId());
        store.setCreateTime(ZonedDateTime.now());
        return save(store);
    }
 
    @Override
    public boolean updateLogo(Long storeId, String logo) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId).set(Store::getLogoImageId, logo);
        return update(wrapper);
    }
 
    @Override
    public boolean updateName(Long storeId, String storeName) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getStoreName, storeName);
        return update(wrapper);
    }
 
    @Override
    public boolean updateDescription(Long storeId, String description) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getDescription, description);
        return update(wrapper);
    }
 
    @Override
    public boolean updateContactPhone(Long storeId, String contactPhone) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getContactPhone, contactPhone);
        return update(wrapper);
    }
 
    @Override
    public boolean updateAddress(Long storeId, String address) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getAddress, address);
        return update(wrapper);
    }
 
    @Override
    public boolean updateLocation(Long storeId, Double longitude, Double latitude) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getLongitude, longitude)
                .set(Store::getLatitude, latitude);
        return update(wrapper);
    }
 
    @Override
    public boolean updateRadius(Long storeId, Integer radius) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getRadius, radius);
        return update(wrapper);
    }
 
    @Override
    public boolean updatePlatformCategory(Long storeId, Long platformCategory) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getPlatformCategoryId, platformCategory);
        return update(wrapper);
    }
 
    @Override
    public boolean updateBusinessHours(Long storeId, LocalTime openTime, LocalTime endTime) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getOpenTime, openTime)
                .set(Store::getCloseTime, endTime);
        return update(wrapper);
    }
 
    @Override
    public boolean updateDeliveryMinimum(Long storeId, BigDecimal deliveryMinimum) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getDeliveryMinimum, deliveryMinimum);
        return update(wrapper);
    }
 
    @Override
    public boolean updateDeliveryFee(Long storeId, BigDecimal deliveryFee) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getDeliveryFee, deliveryFee);
        return update(wrapper);
    }
 
    @Override
    public boolean updateStatus(Long storeId, Integer status) {
        LambdaUpdateWrapper<Store> wrapper = this.createLambdaUpdateWrapper(storeId)
                .set(Store::getStatus, status);
        return update(wrapper);
    }
 
    @Override
    public boolean existsByIdAndMerchantId(Long storeId, Long merchantId) {
        if (storeId == null || merchantId == null) {
            return false;
        }
        Store store = getById(storeId);
        return Optional.ofNullable(store).map(i -> merchantId.equals(i.getMerchantId())).orElse(false);
    }
 
    private LambdaUpdateWrapper<Store> createLambdaUpdateWrapper(Long storeId) {
        return new LambdaUpdateWrapper<Store>()
                .eq(Store::getStoreId, storeId)
                .set(Store::getUpdateBy, SecurityUtils.getCurrentUserId());
    }
}