ExtStoreServiceImpl.java
3.22 KB
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
package com.diligrp.rider.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.diligrp.rider.common.exception.BizException;
import com.diligrp.rider.entity.ExtStore;
import com.diligrp.rider.mapper.ExtStoreMapper;
import com.diligrp.rider.service.ExtStoreService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@RequiredArgsConstructor
public class ExtStoreServiceImpl implements ExtStoreService {
private final ExtStoreMapper extStoreMapper;
@Override
public ExtStore syncStore(String appKey, ExtStore store) {
store.setAppKey(appKey);
long now = System.currentTimeMillis() / 1000;
// 根据 appKey + outStoreId 判断是新增还是更新
ExtStore existing = extStoreMapper.selectOne(new LambdaQueryWrapper<ExtStore>()
.eq(ExtStore::getAppKey, appKey)
.eq(ExtStore::getOutStoreId, store.getOutStoreId())
.last("LIMIT 1"));
if (existing == null) {
store.setStatus(store.getStatus() != null ? store.getStatus() : 1);
store.setCreateTime(now);
store.setUpdateTime(now);
extStoreMapper.insert(store);
} else {
store.setId(existing.getId());
store.setUpdateTime(now);
extStoreMapper.updateById(store);
}
return extStoreMapper.selectById(store.getId());
}
@Override
public List<ExtStore> listByApp(String appKey) {
return extStoreMapper.selectList(new LambdaQueryWrapper<ExtStore>()
.eq(ExtStore::getAppKey, appKey)
.eq(ExtStore::getStatus, 1)
.orderByDesc(ExtStore::getId));
}
@Override
public ExtStore getById(Long id, String appKey) {
ExtStore store = extStoreMapper.selectById(id);
if (store == null) throw new BizException("门店不存在");
if (appKey != null && !appKey.equals(store.getAppKey())) throw new BizException("无权访问该门店");
return store;
}
@Override
public void setStatus(Long id, String appKey, int status) {
ExtStore store = getById(id, appKey);
extStoreMapper.update(null, new LambdaUpdateWrapper<ExtStore>()
.eq(ExtStore::getId, id)
.set(ExtStore::getStatus, status)
.set(ExtStore::getUpdateTime, System.currentTimeMillis() / 1000));
}
@Override
public void delete(Long id, String appKey) {
getById(id, appKey);
extStoreMapper.deleteById(id);
}
// 平台管理端:不限 appKey 查看所有门店
@Override
public List<ExtStore> listAll(String appKey, Long cityId, int page) {
LambdaQueryWrapper<ExtStore> wrapper = new LambdaQueryWrapper<ExtStore>()
.orderByDesc(ExtStore::getId);
if (appKey != null && !appKey.isBlank()) wrapper.eq(ExtStore::getAppKey, appKey);
if (cityId != null && cityId > 0) wrapper.eq(ExtStore::getCityId, cityId);
int offset = (page - 1) * 20;
wrapper.last("LIMIT " + offset + ",20");
return extStoreMapper.selectList(wrapper);
}
}