2021与蓝度共同重构项目,服务端
liuhaonan
2022-11-04 e55c8b0a92eb9715edd90c31dfd4de51a47b588b
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportDataService.java
@@ -18,9 +18,11 @@
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.admin.utils.RedisUtils;
import com.sandu.ximon.dao.bo.LightReportDataBo;
import com.sandu.ximon.dao.domain.Light;
import com.sandu.ximon.dao.domain.LightReportData;
import com.sandu.ximon.dao.domain.Pole;
import com.sandu.ximon.dao.domain.PoleBinding;
import com.sandu.ximon.dao.enums.OrderByEnums;
import com.sandu.ximon.dao.mapper.LightReportDataMapper;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
@@ -94,11 +96,36 @@
     * @param keyword    关键词
     * @param deviceCode 设备码
     */
    public CommonPage listReportData(int pageNo, int pageSize, String keyword, String deviceCode) {
    public CommonPage listReportData(int pageNo, int pageSize, String keyword, String deviceCode, Integer order, Integer seq) {
        List<LightReportDataBo> lightReportDataBos = new ArrayList<>(pageSize);
        CommonPage<String> stringCommonPage = SpringContextHolder.getBean(LightService.class).listDeviceCode(pageNo, pageSize, keyword, deviceCode);
        //排序字段
        String orderByResult = "t1.create_time";
        //正序、倒叙
        String orderBySeq = OrderByEnums.ASC.getCode();
        if (order != null) {
            switch (order) {
                case 1:
                    orderByResult = OrderByEnums.LIGHT_DATA_CREATE_TIME.getCode();
                    break;
                default:
            }
        }
        if (seq != null) {
            switch (seq) {
                case 1:
                    orderBySeq = " ASC";
                    break;
                case 2:
                    orderBySeq = " DESC";
                    break;
                default:
                    break;
            }
        }
        //排序方式
        String orderBy = orderByResult + " " + orderBySeq;
        CommonPage<String> stringCommonPage = SpringContextHolder.getBean(LightService.class).listDeviceCode(pageNo, pageSize, keyword, deviceCode, orderBy);
        List<String> macList = stringCommonPage.getList();
        if (CollUtil.isEmpty(macList)) {
            return new CommonPage();
@@ -215,8 +242,20 @@
        if (macCode.isEmpty()) {
            throw new BusinessException("mac不能为空");
        }
        Light light = SpringContextHolder.getBean(LightService.class)
                .getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, macCode));
        if (light == null) {
            throw new BusinessException("系统中不存在该单灯");
        }
        PageHelper.startPage(conditionVO.getPageNo(), conditionVO.getPageSize());
        List<LightReportData> list = list(Wrappers.lambdaQuery(LightReportData.class).eq(LightReportData::getDeviceCode, macCode));
        list.forEach(
                lightReportData -> {
                    lightReportData.setCreateTime(lightReportData.getCreateTime1().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                    lightReportData.setUpdateTime(lightReportData.getUpdateTime1().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                }
        );
        return list;
    }
}