admin
2021-01-27 92f1d85ddc449ce7452f9d52f8b081e6b69c720b
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
package com.yeshi.fanli.service.impl.config;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import com.yeshi.fanli.entity.SystemEnum;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.goods.HotSearchMapper;
import com.yeshi.fanli.entity.bus.search.HotSearch;
import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.HotSearchService;
import com.yeshi.fanli.service.inter.config.SuperHotSearchService;
 
@Service
public class HotSearchServiceImpl implements HotSearchService {
    
    @Resource
    private HotSearchMapper hotSearchMapper;
    
    @Resource
    private BusinessSystemService businessSystemService;
    
    @Resource
    private SuperHotSearchService superHotSearchService;
    
 
    public void addHotSearch(HotSearch hotSearch) {
        hotSearch.setCreatetime(java.lang.System.currentTimeMillis());
        hotSearchMapper.insert(hotSearch);
    }
 
    public void deleteHotSearch(long[] hsids) {
        for (long hsid : hsids) {
            
            // superHotSearchService.deleteSuper(id, systemId) 
            
            hotSearchMapper.deleteByPrimaryKey(hsid);
        }
    }
 
    public void updateHotSearch(HotSearch hotSearch) {
        HotSearch updateSearch = new HotSearch(hotSearch.getId());
        updateSearch.setName(hotSearch.getName());
        updateSearch.setOrderby(hotSearch.getOrderby());
        updateSearch.setUseType(hotSearch.getUseType());
        hotSearchMapper.updateByPrimaryKeySelective(updateSearch);
    }
 
 
    
    @Override
    public List<HotSearch> listQuery(int start, int count, String key, Long systemId, Integer useType, SystemEnum system) throws Exception {
        
        List<HotSearch> listObj = hotSearchMapper.listQuery(start, count, key, systemId, useType,system);
 
        if (listObj == null || listObj.size() == 0) {
            return null;
        }
        
        List<Long> listId = new ArrayList<>();
        for (HotSearch hotSearch : listObj) {
            listId.add(hotSearch.getId());
        }
        
        
        List<BusinessSystem> systemList = businessSystemService.getBusinessSystems();
        
        List<SuperHotSearch> listSuper = superHotSearchService.listSuperHotSearch(listId);
        
        if (listSuper == null || listSuper.size() == 0) {
            for (HotSearch hotSearch : listObj) {
                hotSearch.setSystemList(systemList);
            }
        } else {
            for (HotSearch hotSearch : listObj) {
                Long id = hotSearch.getId();
                List<BusinessSystem> newList = new ArrayList<BusinessSystem>();
            
                // 是否有关联系统选项
                for (BusinessSystem dsystem : systemList) {
                    BusinessSystem newsystem = new BusinessSystem();
 
                    try {
                        PropertyUtils.copyProperties(newsystem, dsystem);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
 
                    if (listSuper != null && listSuper.size() > 0) {
 
                        Long superSystemId = newsystem.getId();
 
                        for (SuperHotSearch superHotSearch : listSuper) {
                            HotSearch search = superHotSearch.getHotSearch();
                            BusinessSystem s = superHotSearch.getSystem();
 
                            // 当前专题 、当前系统
                            if (search != null && system != null && id == search.getId() && superSystemId == s.getId()) {
                                newsystem.setCheck(1);
                                break;
                            }
                        }
                    }
 
                    if (newsystem.getCheck() != 1) {
                        newsystem.setCheck(0);
                    }
                    newList.add(newsystem);
                }
                hotSearch.setSystemList(newList);
            }
        }
 
        return listObj;
    }
    
    @Override
    public int countList(String key, Long systemId, Integer useType, SystemEnum system) {
        return hotSearchMapper.countQuery(key, systemId, useType,system);
    }
 
    
    @Override
    @Cacheable(value = "crgCache", key = "'getHotSearchCache-' + #useType+'-'+#system")
    public List<HotSearch> getHotSearchCache(Integer useType, SystemEnum system) {
        return hotSearchMapper.getHotSearchList(useType,system);
    }
 
    
    
}