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 selectList(Long userId, ReqParams reqParams) { Long roleId = accessService.getRoleId(userId); if (roleId == null || roleId == 0) { return null; } List 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 pageList = ListUtil.sortByProperty(list,"streetlightId"); List finalList = ListUtil.page(listPage-1, listLimit, pageList); PageInfo page = new PageInfo<>(finalList); page.setStartRow(list.size()); page.setEndRow(count); return page; } public PageInfo selectByStreetlightId(ReqParams reqParams) { PageHelper.startPage(reqParams.getPage(),reqParams.getLimit()); List list = singlelampDao.selectByStreetlightId(reqParams.getMac()); PageInfo page = new PageInfo<>(list); return page; } }