admin
2021-08-02 e89de9319d8f771f8e53cb5f876d06465a580c57
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
package com.yeshi.buwan.service.imp.search;
 
import com.yeshi.buwan.dao.search.SearchSpecialPositionMapDao;
import com.yeshi.buwan.domain.special.SearchSpecial;
import com.yeshi.buwan.domain.special.SearchSpecialPositionMap;
import com.yeshi.buwan.exception.ParamsException;
import com.yeshi.buwan.service.inter.search.SearchSpecialPositionMapService;
import com.yeshi.buwan.service.inter.search.SearchSpecialService;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
 
@Service
public class SearchSpecialPositionMapServiceImpl implements SearchSpecialPositionMapService {
 
    @Resource
    private SearchSpecialPositionMapDao searchSpecialPositionMapDao;
 
    @Resource
    private SearchSpecialService searchSpecialService;
 
 
    @Override
    public SearchSpecialPositionMap add(SearchSpecialPositionMap positionMap) throws ParamsException, Exception {
        if (positionMap == null || positionMap.getPositionId() == null || positionMap.getSpecialId() == null) {
            throw new ParamsException("参数不完整");
        }
 
        if (positionMap.getWeight() == null)
            positionMap.setWeight(1);
 
        if (positionMap.getCreateTime() == null)
            positionMap.setCreateTime(new Date());
 
        if (positionMap.getId() == null) {
            positionMap.setId(SearchSpecialPositionMap.createId(positionMap.getSpecialId(), positionMap.getPositionId()));
        }
 
        return searchSpecialPositionMapDao.save(positionMap);
    }
 
    @Override
    public void updateSelective(SearchSpecialPositionMap positionMap) {
        if (positionMap == null || positionMap.getId() == null) {
            return;
        }
        if (positionMap.getUpdateTime() == null) {
            positionMap.setUpdateTime(new Date());
        }
        searchSpecialPositionMapDao.updateSelective(positionMap);
    }
 
    @Override
    public List<SearchSpecialPositionMap> listByPosition(String positionId, int page, int pageSize) {
        SearchSpecialPositionMapDao.DaoQuery daoQuery = new SearchSpecialPositionMapDao.DaoQuery();
        daoQuery.positionId = positionId;
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        daoQuery.sortList = Arrays.asList(new Sort.Order[]{
                new Sort.Order(Sort.Direction.DESC, "weight")
        });
        return searchSpecialPositionMapDao.list(daoQuery);
    }
 
    @Override
    public List<SearchSpecialPositionMap> listDetailByPosition(String positionId, int page, int pageSize) {
        List<SearchSpecialPositionMap> mapList = listByPosition(positionId, page, pageSize);
        //批量查询ID
        List<String> ids = new ArrayList<>();
        for (SearchSpecialPositionMap map : mapList) {
            ids.add(map.getSpecialId());
        }
        List<SearchSpecial> searchSpecials = searchSpecialService.listByIds(ids);
        Map<String, SearchSpecial> maps = new HashMap<>();
        for (SearchSpecial ss : searchSpecials) {
            maps.put(ss.getId(), ss);
        }
 
        for (SearchSpecialPositionMap map : mapList) {
            map.setSpecial(maps.get(map.getSpecialId()));
        }
        return mapList;
    }
 
    @Override
    public long countByPosition(String positionId) {
        SearchSpecialPositionMapDao.DaoQuery daoQuery = new SearchSpecialPositionMapDao.DaoQuery();
        daoQuery.positionId = positionId;
        return searchSpecialPositionMapDao.count(daoQuery);
    }
 
    @Override
    public List<SearchSpecialPositionMap> listBySpecial(String specialId, int page, int pageSize) {
        SearchSpecialPositionMapDao.DaoQuery daoQuery = new SearchSpecialPositionMapDao.DaoQuery();
        daoQuery.specialId = specialId;
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        daoQuery.sortList = Arrays.asList(new Sort.Order[]{
                new Sort.Order(Sort.Direction.DESC, "weight")
        });
        return searchSpecialPositionMapDao.list(daoQuery);
    }
 
    @Override
    public long countBySpecial(String specialId) {
        SearchSpecialPositionMapDao.DaoQuery daoQuery = new SearchSpecialPositionMapDao.DaoQuery();
        daoQuery.specialId = specialId;
        return searchSpecialPositionMapDao.count(daoQuery);
    }
 
    @Override
    public void delete(String id) {
        searchSpecialPositionMapDao.delete(id);
    }
}