2021与蓝度共同重构项目,服务端
fix
zhanzhiqin
2022-04-15 2f3d783999935f06228705e75fac26ebf099bf87
fix
已修改10个文件
165 ■■■■ 文件已修改
dao/src/main/java/com/sandu/ximon/dao/domain/LightTask.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/java/com/sandu/ximon/dao/mapper/LightReportDataMapper.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/java/com/sandu/ximon/dao/mapper/LightReportErrorMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/resources/mapper/LightMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/resources/mapper/LightReportDataMapper.xml 65 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/resources/mapper/LightReportErrorMapper.xml 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/resources/mapper/LightTaskMapper.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportDataService.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportErrorService.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/java/com/sandu/ximon/dao/domain/LightTask.java
@@ -4,22 +4,30 @@
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
/**
 * 路灯任务表
 *
 * @TableName light_task
 */
@TableName(value ="light_task")
@TableName(value = "light_task")
@Data
public class LightTask implements Serializable {
    /**
     *
     *
     */
    @TableId(type = IdType.AUTO)
    private Long taskId;
    /**
     * 用户id
     */
    private Long userId;
    /**
     * 客户id
@@ -72,7 +80,7 @@
    private LocalDateTime createTime;
    /**
     *
     *
     */
    private LocalDateTime updateTime;
dao/src/main/java/com/sandu/ximon/dao/mapper/LightReportDataMapper.java
@@ -15,6 +15,7 @@
    /**
     * 获取指定设备吗最新上报的一条数据
     *
     * @param deviceCodeList 指定设备码
     * @return 上报数据
     */
@@ -23,11 +24,22 @@
    /**
     * 获取上报数据列表
     * @param keyword 关键词
     *
     * @param keyword    关键词
     * @param deviceCode 设备码
     * @return 上报数据
     */
    List<LightReportDataBo> listReportData(String keyword, String deviceCode);
    /**
     * 带用户ID查询
     *
     * @param keyword
     * @param deviceCode
     * @param userid
     * @return
     */
    List<LightReportDataBo> listReportDataByUserid(String keyword, String deviceCode, Long userid);
}
dao/src/main/java/com/sandu/ximon/dao/mapper/LightReportErrorMapper.java
@@ -18,7 +18,7 @@
     * @param keyword 关键词
     * @return 故障码列表
     */
    List<LightReportErrorBo> listReportError(String keyword);
    List<LightReportErrorBo> listReportError(String keyword, Long userid);
}
dao/src/main/resources/mapper/LightMapper.xml
@@ -36,7 +36,7 @@
        LEFT JOIN light_task t4 ON t3.task_id = t4.task_id
        <where>
            <if test="clientId != null">
                AND t2.client_id = #{clientId}
                AND (t2.user_id = #{clientId} OR t2.client_id = #{clientId})
            </if>
            <if test="keyword != null and keyword != ''">
                AND (
dao/src/main/resources/mapper/LightReportDataMapper.xml
@@ -5,22 +5,22 @@
<mapper namespace="com.sandu.ximon.dao.mapper.LightReportDataMapper">
    <resultMap id="BaseResultMap" type="com.sandu.ximon.dao.domain.LightReportData">
            <id property="lightReportDataId" column="light_report_data_id" jdbcType="BIGINT"/>
            <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
            <result property="voltage" column="voltage" jdbcType="FLOAT"/>
            <result property="electricCurrent" column="electric_current" jdbcType="FLOAT"/>
            <result property="deviceTemperature" column="device_temperature" jdbcType="FLOAT"/>
            <result property="powerFactor" column="power_factor" jdbcType="FLOAT"/>
            <result property="activePower" column="active_power" jdbcType="FLOAT"/>
            <result property="reactivePower" column="reactive_power" jdbcType="FLOAT"/>
            <result property="lightPercent" column="light_percent" jdbcType="INTEGER"/>
            <result property="light2Percent" column="light2_percent" jdbcType="INTEGER"/>
            <result property="recentlyLightSec" column="recently_light_sec" jdbcType="BIGINT"/>
            <result property="totalLightSec" column="total_light_sec" jdbcType="BIGINT"/>
            <result property="recentlyUsingPower" column="recently_using_power" jdbcType="DOUBLE"/>
            <result property="totalUsingPower" column="total_using_power" jdbcType="DOUBLE"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <id property="lightReportDataId" column="light_report_data_id" jdbcType="BIGINT"/>
        <result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
        <result property="voltage" column="voltage" jdbcType="FLOAT"/>
        <result property="electricCurrent" column="electric_current" jdbcType="FLOAT"/>
        <result property="deviceTemperature" column="device_temperature" jdbcType="FLOAT"/>
        <result property="powerFactor" column="power_factor" jdbcType="FLOAT"/>
        <result property="activePower" column="active_power" jdbcType="FLOAT"/>
        <result property="reactivePower" column="reactive_power" jdbcType="FLOAT"/>
        <result property="lightPercent" column="light_percent" jdbcType="INTEGER"/>
        <result property="light2Percent" column="light2_percent" jdbcType="INTEGER"/>
        <result property="recentlyLightSec" column="recently_light_sec" jdbcType="BIGINT"/>
        <result property="totalLightSec" column="total_light_sec" jdbcType="BIGINT"/>
        <result property="recentlyUsingPower" column="recently_using_power" jdbcType="DOUBLE"/>
        <result property="totalUsingPower" column="total_using_power" jdbcType="DOUBLE"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>
    <resultMap id="listReportData" type="com.sandu.ximon.dao.bo.LightReportDataBo" extends="BaseResultMap">
@@ -46,10 +46,10 @@
    </select>
    <select id="listReportData" resultMap="listReportData">
        SELECT
            t1.* ,t2.pole_name
        t1.* ,t2.pole_name
        FROM
            light_report_data t1
                LEFT JOIN pole t2 USING ( device_code )
        light_report_data t1
        LEFT JOIN pole t2 USING ( device_code )
        <where>
            1 = 1
@@ -66,4 +66,31 @@
        </where>
        ORDER BY t1.light_report_data_id DESC
    </select>
    <select id="listReportDataByUserid" resultType="com.sandu.ximon.dao.bo.LightReportDataBo">
        SELECT
        t1.* ,t2.pole_name
        FROM
        light_report_data t1
        LEFT JOIN pole_binding t2 ON t1.device_code = t2.device_code
        AND t2.device_type = 0
        LEFT JOIN pole t3 ON t3.id = t2.pole_id
        <where>
            1 = 1
            <if test="deviceCode != null and deviceCode != ''">
                AND t1.device_code = #{deviceCode}
            </if>
            <if test="keyword != null and keyword != ''">
                AND (
                t1.device_code LIKE CONCAT('%', #{keyword},'%')
                OR t2.pole_name LIKE CONCAT('%', #{keyword},'%')
                )
            </if>
            <if test="userid != null">
                AND (t3.user_id = #{userid} OR t3.client_id = #{userid})
            </if>
        </where>
        ORDER BY t1.light_report_data_id DESC
    </select>
</mapper>
dao/src/main/resources/mapper/LightReportErrorMapper.xml
@@ -21,7 +21,9 @@
            t2.pole_name
        FROM
            light_report_error t1
                LEFT JOIN pole t2 USING ( device_code )
        LEFT JOIN pole_binding t2 ON t1.device_code = t2.device_code
        AND t2.device_type = 0
        LEFT JOIN pole t3 ON t3.id = t2.pole_id
        <where>
            <if test="keyword != null and keyword != ''">
                AND (
@@ -29,6 +31,9 @@
                OR t2.pole_name LIKE CONCAT('%', #{keyword},'%')
                )
            </if>
            <if test="userid != null">
                AND (t3.user_id = #{userid} OR t3.client_id = #{userid})
            </if>
        </where>
        ORDER BY t1.light_report_error_id DESC
    </select>
dao/src/main/resources/mapper/LightTaskMapper.xml
@@ -7,6 +7,7 @@
    <resultMap id="BaseResultMap" type="com.sandu.ximon.dao.domain.LightTask">
            <id property="taskId" column="task_id" jdbcType="BIGINT"/>
            <result property="clientId" column="client_id" jdbcType="BIGINT"/>
            <result property="userId" column="user_id" jdbcType="BIGINT"/>
            <result property="taskName" column="task_name" jdbcType="VARCHAR"/>
            <result property="pause" column="pause" jdbcType="TINYINT"/>
            <result property="week" column="week" jdbcType="TINYINT"/>
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportDataService.java
@@ -5,15 +5,21 @@
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.file.FileUploadDto;
import com.sandu.common.file.config.FileProperties;
import com.sandu.common.file.impl.AliOssFileServiceImpl;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.ResUtils;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightHeartbeatReportInnerFrame;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.bo.LightReportDataBo;
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.mapper.LightReportDataMapper;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
@@ -23,6 +29,7 @@
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.sql.Wrapper;
import java.util.List;
/**
@@ -68,11 +75,32 @@
     */
    public List<LightReportDataBo> listReportData(int pageNo, int pageSize, String keyword, String deviceCode) {
        PageHelper.startPage(pageNo, pageSize);
        return baseMapper.listReportData(keyword, deviceCode);
        //为null的话是超管
        if (SecurityUtils.getClientId() == null) {
            return baseMapper.listReportData(keyword, deviceCode);
        } else {
            return baseMapper.listReportDataByUserid(keyword, deviceCode, SecurityUtils.getUserId());
        }
    }
    @SneakyThrows
    public String exportList(int pageNo, int pageSize, String keyword, String deviceCode) {
        if (SecurityUtils.getClientId() != null) {
            PoleBinding one = SpringContextHolder.getBean(PoleBindingService.class).getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode)
                    .eq(PoleBinding::getDeviceType, 0));
            if (one == null) {
                throw new BusinessException("未找到绑定关系!");
            } else {
                Pole pole = SpringContextHolder.getBean(PoleService.class).getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getUserId, SecurityUtils.getUserId()).or(w -> {
                    w.eq(Pole::getClientId, SecurityUtils.getUserId());
                }));
                if (pole == null) {
                    throw new BusinessException("绑定关系不正确!");
                }
            }
        }
        PageHelper.startPage(pageNo, pageSize);
        List<LightReportDataBo> list = baseMapper.listReportData(keyword, deviceCode);
@@ -92,8 +120,8 @@
//        String url = file.getPath().replace(properties.getUploadRootPath(), "");
        String url = fileUploadDto.getFileUrl();
        file.delete();
       return url;
        return url;
       // return list;
        // return list;
    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightReportErrorService.java
@@ -4,6 +4,7 @@
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightErrorCodeReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.rrpc.enums.LightErrorEnum;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.bo.LightReportErrorBo;
import com.sandu.ximon.dao.domain.LightReportError;
import com.sandu.ximon.dao.mapper.LightReportErrorMapper;
@@ -26,14 +27,21 @@
    }
    public List<LightReportErrorBo> listReportError(int pageNo, int pageSize, String keyword) {
        PageHelper.startPage(pageNo,pageSize);
        List<LightReportErrorBo> lightReportErrorBos = baseMapper.listReportError(keyword);
        PageHelper.startPage(pageNo, pageSize);
        List<LightReportErrorBo> lightReportErrorBos;
        //为null的话是超管
        if (SecurityUtils.getClientId() == null) {
            lightReportErrorBos = baseMapper.listReportError(keyword, null);
        }else{
            lightReportErrorBos = baseMapper.listReportError(keyword, SecurityUtils.getUserId());
        }
        for (LightReportErrorBo lightReportErrorBo : lightReportErrorBos) {
            Integer errorCode = lightReportErrorBo.getErrorCode();
            StringBuilder sb = new StringBuilder();
            LightErrorEnum[] values = LightErrorEnum.values();
            for (LightErrorEnum value : values) {
                if((value.getCode() & errorCode) > 0){
                if ((value.getCode() & errorCode) > 0) {
                    sb.append(value.getMessage());
                }
            }
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
@@ -161,9 +161,11 @@
        if (StrUtil.isNotBlank(keyword)) {
            wrapper.like(LightTask::getTaskName, keyword);
        }
        Long clientId = SecurityUtils.getClientId();
        if (clientId != null) {
            wrapper.eq(LightTask::getClientId, clientId);
        //不是超管需要筛选
        if (SecurityUtils.getClientId() != null) {
            wrapper.eq(LightTask::getClientId, SecurityUtils.getUserId()).or(w -> {
                w.eq(LightTask::getUserId, SecurityUtils.getUserId());
            });
        }
        PageHelper.startPage(pageNo, pageSize);
@@ -229,8 +231,8 @@
//        }
//        lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getTaskId, taskIdList));
        taskIdList.forEach(
                taskId->{
                    lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId,taskId));
                taskId -> {
                    lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, taskId));
                }
        );