Van333
2022-10-26 b54ea64cbb2cf8d613ca1ecf6ed9e5140abb4b9f
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
package api.service;
 
import api.bean.ReqParams;
import api.bean.SinglelampDataEntity;
import api.dao.SinglelampDataDao;
import cn.hutool.core.collection.ListUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * @author van
 * @version 1.0
 * msg:
 * @date 2021/12/16 15:14
 */
@Service("singlelampDataServer")
public class SinglelampDataServer {
 
    @Autowired
    private AccessService accessService;
    @Autowired
    private SinglelampDataDao singlelampDao;
 
    public PageInfo<SinglelampDataEntity> selectList(Long userId, ReqParams reqParams) {
        Long roleId = accessService.getRoleId(userId);
 
        if (roleId == null || roleId == 0) {
            return null;
        }
 
        List<SinglelampDataEntity> list = null;
 
        Integer count = null;
        if (roleId.longValue() == 1) {
            PageHelper.startPage(reqParams.getPage(), reqParams.getLimit());
            list = singlelampDao.selectAll();
        } else if (roleId.longValue() == 2 || roleId.longValue() == 3) {
            count = singlelampDao.countByCompany(userId);
            list = singlelampDao.selectByCompany(1, count, userId);
 
        }
        Integer listLimit = reqParams.getLimit();
        Integer listPage = reqParams.getPage();
 
        if ((listLimit > listPage * listLimit)
            || listLimit < listPage){
            listLimit = count;
        }
 
        List<SinglelampDataEntity> pageList =
                ListUtil.sortByProperty(list,"streetlightId");
 
        List<SinglelampDataEntity> finalList =
                ListUtil.page(listPage-1, listLimit, pageList);
 
        PageInfo<SinglelampDataEntity> page = new PageInfo<>(finalList);
 
 
        page.setStartRow(list.size());
        page.setEndRow(count);
 
        return page;
 
    }
 
    public PageInfo<SinglelampDataEntity> selectByStreetlightId(ReqParams reqParams) {
        PageHelper.startPage(reqParams.getPage(),reqParams.getLimit());
        List<SinglelampDataEntity> list = singlelampDao.selectByStreetlightId(reqParams.getMac());
        PageInfo<SinglelampDataEntity> page = new PageInfo<>(list);
        return page;
    }
 
}