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(0, 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;
|
}
|
|
}
|